本文整理了Java中org.jclouds.rest.Utils
类的一些代码示例,展示了Utils
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils
类的具体详情如下:
包路径:org.jclouds.rest.Utils
类名称:Utils
暂无
代码示例来源:origin: org.apache.brooklyn/brooklyn-locations-jclouds
private LoadingCache<Credentials, Access> getAuthCache(BlobStoreContext context) {
return context.utils().injector().getInstance(CachePeeker.class).authenticationResponseCache;
}
代码示例来源:origin: gaul/s3proxy
blobStore.getContext().utils().date()
.iso8601DateFormat(creationDate).trim());
代码示例来源:origin: apache/jclouds
@Test(groups = "live")
public void testPublicAccess() throws InterruptedException, MalformedURLException, IOException {
final String containerName = getScratchContainerName();
try {
view.getBlobStore().createContainerInLocation(null, containerName, publicRead());
assertConsistencyAwareContainerExists(containerName);
defaultLocation = Iterables.find(view.getBlobStore().list(), new Predicate<StorageMetadata>() {
@Override
public boolean apply(@Nullable StorageMetadata input) {
return input.getName().equals(containerName);
}
}).getLocation();
view.getBlobStore().putBlob(containerName,
view.getBlobStore().blobBuilder("hello").payload(TEST_STRING).build());
assertConsistencyAwareContainerSize(containerName, 1);
BlobMetadata metadata = view.getBlobStore().blobMetadata(containerName, "hello");
assertNotNull(metadata.getPublicUri(), metadata.toString());
SocketOpen socketOpen = context.utils().injector().getInstance(SocketOpen.class);
Predicate<HostAndPort> socketTester = retry(socketOpen, 60, 5, SECONDS);
int port = metadata.getPublicUri().getPort();
HostAndPort hostAndPort = HostAndPort.fromParts(metadata.getPublicUri().getHost(), port != -1 ? port : 80);
assertTrue(socketTester.apply(hostAndPort), metadata.getPublicUri().toString());
assertEquals(Strings2.toStringAndClose(view.utils().http().get(metadata.getPublicUri())), TEST_STRING);
} finally {
// this container is now public, so we can't reuse it directly
recycleContainerAndAddToPool(containerName);
}
}
代码示例来源:origin: org.apache.jclouds.karaf/commands
/**
* Writes to the {@link org.jclouds.blobstore.domain.Blob} using an InputStream.
*
* @param blobStore
* @param bucket
* @param blobName
* @param blob
* @param options
*/
public void write(BlobStore blobStore, String bucket, String blobName, Blob blob, PutOptions options, boolean signedRequest) throws Exception {
if (blobName.contains("/")) {
String directory = BlobStoreUtils.parseDirectoryFromPath(blobName);
if (!Strings.isNullOrEmpty(directory)) {
blobStore.createDirectory(bucket, directory);
}
}
if (signedRequest) {
BlobStoreContext context = blobStore.getContext();
HttpRequest request = context.getSigner().signPutBlob(bucket, blob);
HttpClient httpClient = context.utils().http();
HttpResponse response = httpClient.invoke(request);
int statusCode = response.getStatusCode();
if (statusCode != 200 && statusCode != 201) {
throw new IOException(response.getStatusLine());
}
} else {
blobStore.putBlob(bucket, blob, options);
}
}
代码示例来源:origin: apache/jclouds
public void signatureV4() {
Supplier<Credentials> accessAndSecretKey = Suppliers.ofInstance(new Credentials(identity, credential));
FormSignerV4 filter = new FormSignerV4(apiVersion, accessAndSecretKey, timestamp, serviceAndRegion);
HttpRequest request = filter.filter(sampleRequest);
assertEquals(api.utils().http().invoke(request).getStatusCode(), 200);
}
代码示例来源:origin: apache/jclouds
@Override
protected void initializeContext() {
super.initializeContext();
resourceDeleted = context.utils().injector().getInstance(Key.get(new TypeLiteral<Predicate<URI>>() {
}, Names.named(TIMEOUT_RESOURCE_DELETED)));
publicIpAvailable = context.utils().injector().getInstance(PublicIpAvailablePredicateFactory.class);
resourceAvailable = context.utils().injector()
.getInstance(Key.get(new TypeLiteral<Predicate<Supplier<Provisionable>>>() {
}));
api = view.unwrapApi(AzureComputeApi.class);
}
代码示例来源:origin: apache/jclouds
public void signatureV4_session() {
SessionCredentials creds = api.getApi().createTemporaryCredentials(durationSeconds(MINUTES.toSeconds(15)));
Supplier<Credentials> sessionToken = Suppliers.<Credentials>ofInstance(creds);
FormSignerV4 filter = new FormSignerV4(apiVersion, sessionToken, timestamp, serviceAndRegion);
HttpRequest request = filter.filter(sampleRequest);
assertEquals(api.utils().http().invoke(request).getStatusCode(), 200);
}
}
代码示例来源:origin: gaul/s3proxy
blobStore.getContext().utils().date()
.iso8601DateFormat(new Date()));
代码示例来源:origin: apache/jclouds
@Override
public void initializeContext() {
super.initializeContext();
resourceDeleted = context.utils().injector().getInstance(Key.get(new TypeLiteral<Predicate<URI>>() {
}, Names.named(TIMEOUT_RESOURCE_DELETED)));
}
代码示例来源:origin: apache/jclouds
@Test(groups = { "integration", "live" })
public void testSetBlobAccess() throws Exception {
BlobStore blobStore = view.getBlobStore();
String containerName = getContainerName();
String blobName = "set-access-blob-name";
try {
addBlobToContainer(containerName, blobName, blobName, MediaType.TEXT_PLAIN);
assertThat(blobStore.getBlobAccess(containerName, blobName)).isEqualTo(BlobAccess.PRIVATE);
blobStore.setBlobAccess(containerName, blobName, BlobAccess.PUBLIC_READ);
assertThat(blobStore.getBlobAccess(containerName, blobName)).isEqualTo(BlobAccess.PUBLIC_READ);
// test that blob is anonymously readable
HttpRequest request = view.getSigner().signGetBlob(containerName, blobName).toBuilder()
.replaceQueryParams(ImmutableMap.<String, String>of()).build();
HttpResponse response = view.utils().http().invoke(request);
assertThat(response.getStatusCode()).isEqualTo(200);
blobStore.setBlobAccess(containerName, blobName, BlobAccess.PRIVATE);
assertThat(blobStore.getBlobAccess(containerName, blobName)).isEqualTo(BlobAccess.PRIVATE);
} finally {
returnContainer(containerName);
}
}
代码示例来源:origin: org.gaul/s3proxy
blobStore.getContext().utils().date()
.iso8601DateFormat(creationDate).trim());
代码示例来源:origin: jclouds/jclouds-labs
private Set<String> getZones() {
final String region = ctx.utils().injector().getInstance(ImplicitRegionIdSupplier.class).get();
final Map<String, Supplier<Set<String>>> regionToZoneMap = ctx.utils().injector()
.getInstance(RegionIdToZoneIdsSupplier.class).get();
return regionToZoneMap.get(region).get();
}
代码示例来源:origin: apache/jclouds
@Test(groups = { "integration", "live" })
public void testSetContainerAccess() throws Exception {
BlobStore blobStore = view.getBlobStore();
String containerName = getContainerName();
try {
assertThat(blobStore.getContainerAccess(containerName)).isEqualTo(ContainerAccess.PRIVATE);
blobStore.setContainerAccess(containerName, ContainerAccess.PUBLIC_READ);
assertThat(blobStore.getContainerAccess(containerName)).isEqualTo(ContainerAccess.PUBLIC_READ);
String blobName = "blob";
blobStore.putBlob(containerName, blobStore.blobBuilder(blobName).payload("").build());
// test that blob is anonymously readable
HttpRequest request = view.getSigner().signGetBlob(containerName, blobName).toBuilder()
.replaceQueryParams(ImmutableMap.<String, String>of()).build();
HttpResponse response = view.utils().http().invoke(request);
assertThat(response.getStatusCode()).isEqualTo(200);
blobStore.setContainerAccess(containerName, ContainerAccess.PRIVATE);
assertThat(blobStore.getContainerAccess(containerName)).isEqualTo(ContainerAccess.PRIVATE);
} finally {
recycleContainerAndAddToPool(containerName);
}
}
代码示例来源:origin: Nextdoor/bender
blobStore.getContext().utils().date()
.iso8601DateFormat(creationDate).trim());
代码示例来源:origin: jclouds/jclouds-labs
private Set<String> getZones() {
final String region = ctx.utils().injector().getInstance(ImplicitRegionIdSupplier.class).get();
final Map<String, Supplier<Set<String>>> regionToZoneMap = ctx.utils().injector()
.getInstance(RegionIdToZoneIdsSupplier.class).get();
return regionToZoneMap.get(region).get();
}
代码示例来源:origin: org.apache.jclouds.karaf/commands
/**
* Returns an InputStream to a {@link org.jclouds.blobstore.domain.Blob}.
*
* @param containerName
* @param blobName
* @return
*/
public InputStream getBlobInputStream(BlobStore blobStore, String containerName, String blobName, boolean signedRequest)
throws Exception {
if (signedRequest) {
BlobStoreContext context = blobStore.getContext();
HttpRequest request = context.getSigner().signGetBlob(containerName, blobName);
HttpClient httpClient = context.utils().http();
HttpResponse response = httpClient.invoke(request);
int statusCode = response.getStatusCode();
if (statusCode != 200) {
throw new IOException(response.getStatusLine());
}
return response.getPayload().openStream();
}
Blob blob = blobStore.getBlob(containerName, blobName);
if (blob == null) {
if (!blobStore.containerExists(containerName)) {
throw new ContainerNotFoundException(containerName, "while getting blob");
}
throw new KeyNotFoundException(containerName, blobName, "while getting blob");
}
return blob.getPayload().openStream();
}
代码示例来源:origin: org.gaul/s3proxy
blobStore.getContext().utils().date()
.iso8601DateFormat(new Date()));
代码示例来源:origin: apache/jclouds
@SuppressWarnings("unchecked")
@Override
protected Optional<Image> findImageWithNameInCache(String name) {
ImageCacheSupplier imageCache = (ImageCacheSupplier) context.utils().injector()
.getInstance(Key.get(new TypeLiteral<Supplier<Set<? extends Image>>>() {
}, Memoized.class));
try {
Field field = imageCache.getClass().getDeclaredField("imageCache");
field.setAccessible(true);
LoadingCache<String, Image> cache = (LoadingCache<String, Image>) field.get(imageCache);
return Optional.fromNullable(getOnlyElement(filter(cache.asMap().values(), new Predicate<Image>() {
@Override
public boolean apply(Image input) {
return imageGroup.equals(input.getName());
}
}), null));
} catch (NoSuchFieldException ex) {
throw Throwables.propagate(ex);
} catch (IllegalAccessException ex) {
throw Throwables.propagate(ex);
}
}
代码示例来源:origin: jclouds/legacy-jclouds
@Test
public void testSignGetUrlWithTime() throws InterruptedException, IOException {
String name = "hello";
String text = "fooooooooooooooooooooooo";
Blob blob = view.getBlobStore().blobBuilder(name).payload(text).contentType("text/plain").build();
String container = getContainerName();
try {
view.getBlobStore().putBlob(container, blob);
assertConsistencyAwareContainerSize(container, 1);
HttpRequest request = view.getSigner().signGetBlob(container, name, 3 /* seconds */);
assertEquals(request.getFilters().size(), 0);
assertEquals(Strings2.toString(view.utils().http().invoke(request).getPayload()), text);
TimeUnit.SECONDS.sleep(4);
try {
Strings2.toString(view.utils().http().invoke(request).getPayload());
fail("Temporary URL did not expire as expected");
} catch (AuthorizationException expected) {
}
} catch (UnsupportedOperationException ignore) {
throw new SkipException("signGetUrl with a time limit is not supported on " + provider);
} finally {
returnContainer(container);
}
}
代码示例来源:origin: Nextdoor/bender
blobStore.getContext().utils().date()
.iso8601DateFormat(new Date()));
内容来源于网络,如有侵权,请联系作者删除!