BlobStore blobStore = context.getBlobStore(); if ( blobStore.createContainerInLocation(null, bucketName) ) { logger.info( "Created bucket {}", bucketName ); BlobStore blobStore = context.getBlobStore(); BlobBuilder blobBuilder = blobStore.blobBuilder( filename ) .payload( ephemeral ) .contentMD5(Files.hash( ephemeral, Hashing.md5() )) .contentType("application/json"); Blob blob = blobBuilder.build(); final String uploadedFile = blobStore.putBlob( bucketName, blob, PutOptions.Builder.multipart() );
@Override protected void after() { logger.debug("S3 proxy is stopping"); try { s3Proxy.stop(); BlobStore blobStore = blobStoreContext.getBlobStore(); for (StorageMetadata metadata : blobStore.list()) { blobStore.deleteContainer(metadata.getName()); } blobStoreContext.close(); } catch (Exception e) { throw new RuntimeException("Unable to stop S3 proxy", e); } FileUtils.deleteQuietly(blobStoreLocation); logger.debug("S3 proxy has stopped"); }
private static String getBlobStoreType(BlobStore blobStore) { return blobStore.getContext().unwrap().getProviderMetadata().getId(); }
@Test public void testSignRemoveUrl() throws Exception { 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().signRemoveBlob(container, name); assertEquals(request.getFilters().size(), 0); view.utils().http().invoke(request); assert !view.getBlobStore().blobExists(container, name); } finally { returnContainer(container); } } }
@Test public void testSignPutBlobWithTime() throws Exception { BlobStore signPutBloblWithTime = requestsSendResponses(init()); Blob blob = signPutBloblWithTime.blobBuilder(name).payload(text).contentType("text/plain").build(); HttpRequest compare = putBlobWithTime(); compare.setPayload(blob.getPayload()); assertEquals(signPutBloblWithTime.getContext().getSigner().signPutBlob(container, blob, 3l /* seconds */), compare); }
@Override public void save(Cluster cluster) throws IOException { BlobStore store = context.getBlobStore(); Blob blob = store.blobBuilder(blobName).payload(serialize(cluster)).build(); store.putBlob(container, blob); LOG.info("Saved cluster state to '{}' ", context.getSigner() .signGetBlob(container, blobName).getEndpoint().toString()); }
@Test public void testSignGetBlobWithOptions() { BlobStore getBlobWithOptions = requestsSendResponses(init()); assertEquals(getBlobWithOptions.getContext().getSigner().signGetBlob(container, name, options), getBlobWithOptions()); }
@Test(groups = { "integration", "live" }) public void testPutTwiceIsOkAndDoesntOverwrite() throws InterruptedException { String containerName = getContainerName(); try { view.getBlobStore().createContainerInLocation(null, containerName); Blob blob = view.getBlobStore().blobBuilder("hello").payload(TEST_STRING).build(); view.getBlobStore().putBlob(containerName, blob); view.getBlobStore().createContainerInLocation(null, containerName); assertEquals(view.getBlobStore().countBlobs(containerName), 1); } finally { returnContainer(containerName); } }
@Test public void testSignPutBlob() throws Exception { BlobStore signPutBlob = requestsSendResponses(init()); Blob blob = signPutBlob.blobBuilder("name").forSigning().contentLength(2l).contentMD5(new byte[] { 0, 2, 4, 8 }) .contentType("text/plain").expires(new Date(1000)).build(); HttpRequest compare = putBlob(); compare.setPayload(blob.getPayload()); assertEquals(signPutBlob.getContext().getSigner().signPutBlob(container, blob), compare); }
@Test(groups = "live") public void testSetGetContainerMetadata() throws InterruptedException { CommonSwiftClient swift = view.utils().injector().getInstance(CommonSwiftClient.class); String containerName = getContainerName(); assertTrue(swift.createContainer(containerName)); ImmutableMap<String, String> metadata = ImmutableMap.<String, String> of( "key1", "value1", "key2", "value2"); assertTrue(swift.setContainerMetadata(containerName, metadata)); ContainerMetadata containerMetadata = swift.getContainerMetadata(containerName); assertEquals(containerMetadata.getMetadata().get("key1"), "value1"); assertEquals(containerMetadata.getMetadata().get("key2"), "value2"); }
@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"); assert metadata.getPublicUri() != null : metadata; assertEquals(Strings2.toStringAndClose(view.utils().http().get(metadata.getPublicUri())), TEST_STRING); } finally { // this container is now public, so we can't reuse it directly recycleContainer(containerName); } }
@Test(groups = { "integration", "live" }) public void testDuplicateCreateContainer() { BlobStore blobStore = view.getBlobStore(); Location location = null; String container = "container"; boolean created; created = blobStore.createContainerInLocation(location, container); assertTrue(created); created = blobStore.createContainerInLocation(location, container); assertFalse(created); } }
@Test(groups = { "integration", "live" }) public void testListContainerMaxResults() throws InterruptedException { String containerName = getContainerName(); try { addAlphabetUnderRoot(containerName); PageSet<? extends StorageMetadata> container = view.getBlobStore().list(containerName, maxResults(5)); assertEquals(container.size(), 5); assert container.getNextMarker() != null; } finally { returnContainer(containerName); } }
@Test(groups = { "integration", "live" }) public void deleteObjectNoContainer() { try { view.getBlobStore().removeBlob("donb", "test"); } catch (HttpResponseException e) { assertEquals(e.getResponse().getStatusCode(), 404); } catch (ContainerNotFoundException e) { } }
@Test(expectedExceptions = { ContainerNotFoundException.class }) public void testListAllForUnknownContainerFromTransientBlobStoreEagerly() throws Exception { ListContainerOptions containerOptions = ListContainerOptions.NONE; ListAllOptions listAllOptions = ListAllOptions.Builder.eager(true); BlobStoreContext context = blobStoreContext(); try { BlobStore blobStore = context.getBlobStore(); BlobStores.listAll(blobStore, "wrongcontainer", containerOptions, listAllOptions); } finally { context.close(); } }
@Test(groups = { "integration", "live" }) public void testMultipartUploadSinglePartMultiRegional() throws Exception { String containerName = "jclouds-multiregional"; BucketTemplate template = new BucketTemplate() .name(containerName) .location(Location.US) .storageClass(StorageClass.COLDLINE); GoogleCloudStorageApi api = view.unwrapApi(GoogleCloudStorageApi.class); api.getBucketApi().createBucket(PROJECT_NUMBER, template); String blobName = "multiregional-blobname"; try { long length = 32 * 1024L; ByteSource byteSource = TestUtils.randomByteSource().slice(0, length); Blob blob = view.getBlobStore().blobBuilder(blobName) .payload(byteSource) .contentLength(length) .build(); view.getBlobStore().putBlob(containerName, blob, new PutOptions().multipart(true)); } finally { view.getBlobStore().removeBlob(containerName, blobName); api.getBucketApi().deleteBucket(containerName); } } }
public void testCreateListDestroyContainer() throws IOException { context.getBlobStore().createContainerInLocation(null, testContainerName); context.getBlobStore().list(testContainerName); PageSet<? extends StorageMetadata> ps = context.getBlobStore().list(); assertHasItemNamed(ps, testContainerName); Blob b = context.getBlobStore().blobBuilder("my-blob-1").payload(Streams.newInputStreamWithContents("hello world")).build(); context.getBlobStore().putBlob(testContainerName, b); Blob b2 = context.getBlobStore().getBlob(testContainerName, "my-blob-1"); Assert.assertEquals(Streams.readFullyStringAndClose(b2.getPayload().openStream()), "hello world"); context.getBlobStore().deleteContainer(testContainerName); }
public void testPutWithReducedRedundancyStorage() throws InterruptedException { String containerName = getContainerName(); try { String blobName = "test-rrs"; BlobStore blobStore = view.getBlobStore(); blobStore.createContainerInLocation(null, containerName); Blob blob = blobStore.blobBuilder(blobName).payload("something").build(); blobStore.putBlob(containerName, blob, storageClass(StorageClass.REDUCED_REDUNDANCY)); S3Client s3Client = S3Client.class.cast(view.unwrap(AWSS3ApiMetadata.CONTEXT_TOKEN).getApi()); ListBucketResponse response = s3Client.listBucket(containerName, withPrefix(blobName)); ObjectMetadata metadata = response.iterator().next(); assertEquals(metadata.getStorageClass(), StorageClass.REDUCED_REDUNDANCY); } finally { returnContainer(containerName); } }
ApiMetadata apiMetadata = context.unwrap().getProviderMetadata().getApiMetadata(); blobStore = context.getBlobStore(); location = Iterables.getFirst(blobStore.listAssignableLocations(), null); blobStore.createContainerInLocation(location, containerName); String blobName = "test"; ByteSource payload = ByteSource.wrap("testdata".getBytes(Charsets.UTF_8)); S3Client api = context.unwrapApi(S3Client.class); object = api.headObject(containerName, blobName); } else if (apiMetadata instanceof SwiftApiMetadata) { SwiftApi api = context.unwrapApi(SwiftApi.class); object = api.getObjectApi(location.getId(), containerName).getWithoutBody(blobName); } else if (apiMetadata instanceof AzureBlobApiMetadata) { AzureBlobClient api = context.unwrapApi(AzureBlobClient.class); object = api.getBlobProperties(containerName, blobName); } else if (apiMetadata instanceof AtmosApiMetadata) { AtmosClient api = context.unwrapApi(AtmosClient.class); object = api.headFile(containerName + "/" + blobName); } else if (apiMetadata instanceof GoogleCloudStorageApiMetadata) { GoogleCloudStorageApi api = context.unwrapApi(GoogleCloudStorageApi.class); object = api.getObjectApi().getObject(containerName, blobName); blobStore.deleteContainer(containerName); context.close();
.prepareOutputFileName(organization.getName(), "applications"); blobStore = context.getBlobStore(); if (!blobStore.blobExists(bucketName, expectedFileName)) { blobStore.deleteContainer(bucketName); Assert.fail("Blob does not exist: " + expectedFileName); Blob bo = blobStore.getBlob(bucketName, expectedFileName); Long numOfFiles = blobStore.countBlobs(bucketName);