mirror of https://github.com/apache/jclouds.git
allow cdn lookup to fail while in beta
This commit is contained in:
parent
8d517f9f51
commit
075c0c8e5e
|
@ -36,6 +36,7 @@ import com.google.common.cache.LoadingCache;
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class PublicUriForObjectInfo implements Function<ObjectInfo, URI> {
|
public class PublicUriForObjectInfo implements Function<ObjectInfo, URI> {
|
||||||
|
|
||||||
private final LoadingCache<String, URI> cdnContainer;
|
private final LoadingCache<String, URI> cdnContainer;
|
||||||
private final Provider<UriBuilder> uriBuilders;
|
private final Provider<UriBuilder> uriBuilders;
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,8 @@ package org.jclouds.hpcloud.object.storage.blobstore.config;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.hpcloud.object.storage.HPCloudObjectStorageClient;
|
import org.jclouds.hpcloud.object.storage.HPCloudObjectStorageClient;
|
||||||
|
@ -28,11 +30,14 @@ import org.jclouds.hpcloud.object.storage.blobstore.HPCloudObjectStorageAsyncBlo
|
||||||
import org.jclouds.hpcloud.object.storage.blobstore.HPCloudObjectStorageBlobStore;
|
import org.jclouds.hpcloud.object.storage.blobstore.HPCloudObjectStorageBlobStore;
|
||||||
import org.jclouds.hpcloud.object.storage.blobstore.functions.HPCloudObjectStorageObjectToBlobMetadata;
|
import org.jclouds.hpcloud.object.storage.blobstore.functions.HPCloudObjectStorageObjectToBlobMetadata;
|
||||||
import org.jclouds.hpcloud.object.storage.domain.ContainerCDNMetadata;
|
import org.jclouds.hpcloud.object.storage.domain.ContainerCDNMetadata;
|
||||||
|
import org.jclouds.http.HttpResponseException;
|
||||||
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.openstack.swift.blobstore.SwiftAsyncBlobStore;
|
import org.jclouds.openstack.swift.blobstore.SwiftAsyncBlobStore;
|
||||||
import org.jclouds.openstack.swift.blobstore.SwiftBlobStore;
|
import org.jclouds.openstack.swift.blobstore.SwiftBlobStore;
|
||||||
import org.jclouds.openstack.swift.blobstore.config.SwiftBlobStoreContextModule;
|
import org.jclouds.openstack.swift.blobstore.config.SwiftBlobStoreContextModule;
|
||||||
import org.jclouds.openstack.swift.blobstore.functions.ObjectToBlobMetadata;
|
import org.jclouds.openstack.swift.blobstore.functions.ObjectToBlobMetadata;
|
||||||
|
|
||||||
|
import com.google.common.annotations.Beta;
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.common.cache.CacheBuilder;
|
||||||
import com.google.common.cache.CacheLoader;
|
import com.google.common.cache.CacheLoader;
|
||||||
import com.google.common.cache.LoadingCache;
|
import com.google.common.cache.LoadingCache;
|
||||||
|
@ -44,21 +49,41 @@ import com.google.inject.Provides;
|
||||||
*/
|
*/
|
||||||
public class HPCloudObjectStorageBlobStoreContextModule extends SwiftBlobStoreContextModule {
|
public class HPCloudObjectStorageBlobStoreContextModule extends SwiftBlobStoreContextModule {
|
||||||
|
|
||||||
@Provides
|
@Beta
|
||||||
@Singleton
|
@Singleton
|
||||||
protected LoadingCache<String, URI> cdnContainer(final HPCloudObjectStorageClient client) {
|
public static final class GetCDNMetadata extends CacheLoader<String, URI> {
|
||||||
return CacheBuilder.newBuilder().expireAfterWrite(30, TimeUnit.SECONDS).build(new CacheLoader<String, URI>() {
|
@Resource
|
||||||
@Override
|
protected Logger logger = Logger.NULL;
|
||||||
public URI load(String container) {
|
|
||||||
|
private final HPCloudObjectStorageClient client;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public GetCDNMetadata(HPCloudObjectStorageClient client) {
|
||||||
|
this.client = client;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public URI load(String container) {
|
||||||
|
try {
|
||||||
ContainerCDNMetadata md = client.getCDNMetadata(container);
|
ContainerCDNMetadata md = client.getCDNMetadata(container);
|
||||||
return md != null ? md.getCDNUri() : null;
|
return md != null ? md.getCDNUri() : null;
|
||||||
|
} catch (HttpResponseException e) {
|
||||||
|
// TODO: this is due to beta status
|
||||||
|
logger.trace("couldn't get cdn metadata for %s: %s", container, e.getMessage());
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "getCDNMetadata()";
|
return "getCDNMetadata()";
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
protected LoadingCache<String, URI> cdnContainer(GetCDNMetadata loader) {
|
||||||
|
return CacheBuilder.newBuilder().expireAfterWrite(30, TimeUnit.SECONDS).build(loader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue