Java Code Examples for org.jclouds.blobstore.BlobStore#createContainerInLocation()
The following examples show how to use
org.jclouds.blobstore.BlobStore#createContainerInLocation() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AreWeConsistentYetTest.java From are-we-consistent-yet with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { ContextBuilder builder = ContextBuilder .newBuilder("transient") .credentials("identity", "credential") .modules(ImmutableList.<Module>of(new SLF4JLoggingModule())); context = builder.build(BlobStoreContext.class); contextRead = builder.build(BlobStoreContext.class); BlobStore blobStore = context.getBlobStore(); BlobStore blobStoreRead = contextRead.getBlobStore(); String containerName = "container-name"; Location location = null; blobStore.createContainerInLocation(location, containerName); blobStoreRead.createContainerInLocation(location, containerName); awcyStrong = new AreWeConsistentYet(blobStore, blobStore, containerName, ITERATIONS, OBJECT_SIZE); awcyEventual = new AreWeConsistentYet(blobStore, blobStoreRead, containerName, ITERATIONS, OBJECT_SIZE); }
Example 2
Source File: MainApp.java From jclouds-examples with Apache License 2.0 | 6 votes |
private static void multipartUploadExample(BlobStore blobstore) throws IOException { // Create a container String containerName = "jclouds_multipartUploadExample_" + UUID.randomUUID().toString(); blobstore.createContainerInLocation(null, containerName); // Create a vault // Create a blob ByteSource payload = buildData(16 * MiB); Blob blob = blobstore.blobBuilder("ignored") // The blob name is ignored in Glacier .payload(payload) .contentLength(payload.size()) .build(); // Create the PutOptions PutOptions options = PutOptions.Builder.multipart(true); // Put the blob in the container blobstore.putBlob(containerName, blob, options); System.out.println("The blob has been uploaded"); }
Example 3
Source File: MainApp.java From jclouds-examples with Apache License 2.0 | 5 votes |
private static void putAndRetrieveBlobExample(BlobStore blobstore) throws IOException { // Create a container String containerName = "jclouds_putAndRetrieveBlobExample_" + UUID.randomUUID().toString(); blobstore.createContainerInLocation(null, containerName); // Create a vault // Create a blob ByteSource payload = ByteSource.wrap("data".getBytes(Charsets.UTF_8)); Blob blob = blobstore.blobBuilder("ignored") // The blob name is ignored in Glacier .payload(payload) .contentLength(payload.size()) .build(); // Put the blob in the container String blobId = blobstore.putBlob(containerName, blob); // Retrieve the blob Blob result = blobstore.getBlob(containerName, blobId); // Print the result InputStream is = result.getPayload().openStream(); try { String data = CharStreams.toString(new InputStreamReader(is, Charsets.UTF_8)); System.out.println("The retrieved payload is: " + data); } finally { is.close(); } }
Example 4
Source File: JCloudsBlobStoreIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
private BlobStore getBlobStore() { BlobStore blobStore = ContextBuilder.newBuilder("transient") .credentials("id", "credential") .buildView(BlobStoreContext.class) .getBlobStore(); blobStore.createContainerInLocation(null, CONTAINER_NAME); blobStore.createContainerInLocation(null, CONTAINER_NAME_WITH_DIR); return blobStore; }
Example 5
Source File: JCloudsEntityStoreMixin.java From attic-polygene-java with Apache License 2.0 | 4 votes |
@Override public void activateService() throws Exception { configuration.refresh(); String provider = configuration.get().provider().get(); String identifier = configuration.get().identifier().get(); String credentials = configuration.get().credential().get(); String endpoint = configuration.get().endpoint().get(); Map<String, String> properties = configuration.get().properties().get(); container = configuration.get().container().get(); if( provider != null ) { checkArgument( contains( allKeys, provider ), "provider %s not in supported list: %s", provider, allKeys ); } else { provider = "transient"; } if( container == null ) { container = "polygene-entities"; } storeContext = ContextBuilder.newBuilder( provider ) .endpoint( endpoint == null ? "" : endpoint ) .credentials( identifier, credentials ) .overrides( asProperties( properties ) ) .buildView( BlobStoreContext.class ); BlobStore blobStore = storeContext.getBlobStore(); if( !blobStore.containerExists( container ) ) { if( !blobStore.createContainerInLocation( null, container ) ) { throw new EntityStoreException( "Unable to create JClouds Blob Container, cannot continue." ); } else { LOGGER.debug( "Created new container: {}", container ); } } LOGGER.info( "Activated using {} cloud provider [id:{}]", provider, identifier ); }
Example 6
Source File: S3ProxyHandler.java From s3proxy with Apache License 2.0 | 4 votes |
private static void handleContainerCreate(HttpServletRequest request, HttpServletResponse response, InputStream is, BlobStore blobStore, String containerName) throws IOException, S3Exception { if (containerName.isEmpty()) { throw new S3Exception(S3ErrorCode.METHOD_NOT_ALLOWED); } String contentLengthString = request.getHeader( HttpHeaders.CONTENT_LENGTH); if (contentLengthString != null) { long contentLength; try { contentLength = Long.parseLong(contentLengthString); } catch (NumberFormatException nfe) { throw new S3Exception(S3ErrorCode.INVALID_ARGUMENT, nfe); } if (contentLength < 0) { throw new S3Exception(S3ErrorCode.INVALID_ARGUMENT); } } String locationString; try (PushbackInputStream pis = new PushbackInputStream(is)) { int ch = pis.read(); if (ch == -1) { // handle empty bodies locationString = null; } else { pis.unread(ch); CreateBucketRequest cbr = new XmlMapper().readValue( pis, CreateBucketRequest.class); locationString = cbr.locationConstraint; } } Location location = null; if (locationString != null) { for (Location loc : blobStore.listAssignableLocations()) { if (loc.getId().equalsIgnoreCase(locationString)) { location = loc; break; } } if (location == null) { throw new S3Exception(S3ErrorCode.INVALID_LOCATION_CONSTRAINT); } } logger.debug("Creating bucket with location: {}", location); CreateContainerOptions options = new CreateContainerOptions(); String acl = request.getHeader(AwsHttpHeaders.ACL); if ("public-read".equalsIgnoreCase(acl)) { options.publicRead(); } boolean created; try { created = blobStore.createContainerInLocation(location, containerName, options); } catch (AuthorizationException ae) { if (ae.getCause() instanceof AccessDeniedException) { throw new S3Exception(S3ErrorCode.ACCESS_DENIED, "Could not create bucket", ae); } throw new S3Exception(S3ErrorCode.BUCKET_ALREADY_EXISTS, ae); } if (!created) { throw new S3Exception(S3ErrorCode.BUCKET_ALREADY_OWNED_BY_YOU, S3ErrorCode.BUCKET_ALREADY_OWNED_BY_YOU.getMessage(), null, ImmutableMap.of("BucketName", containerName)); } response.addHeader(HttpHeaders.LOCATION, "/" + containerName); }
Example 7
Source File: AreWeConsistentYet.java From are-we-consistent-yet with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws Exception { Options options = new Options(); CmdLineParser parser = new CmdLineParser(options); try { parser.parseArgument(args); } catch (CmdLineException cle) { PrintStream err = System.err; err.println("are-we-consistent-yet version " + AreWeConsistentYet.class.getPackage() .getImplementationVersion()); err.println("Usage: are-we-consistent-yet" + " --container-name NAME --properties FILE [options...]"); parser.printUsage(err); System.exit(1); } Properties properties = new Properties(); try (InputStream is = new FileInputStream(options.propertiesFile)) { properties.load(is); } Properties propertiesRead = (Properties) properties.clone(); if (options.readerEndpoint != null) { propertiesRead.setProperty(Constants.PROPERTY_ENDPOINT, options.readerEndpoint); } try (BlobStoreContext context = blobStoreContextFromProperties( properties); BlobStoreContext contextRead = blobStoreContextFromProperties( propertiesRead)) { BlobStore blobStore = context.getBlobStore(); BlobStore blobStoreRead = contextRead.getBlobStore(); Location location = null; if (options.location != null) { for (Location loc : blobStore.listAssignableLocations()) { if (loc.getId().equalsIgnoreCase(options.location)) { location = loc; break; } } if (location == null) { throw new Exception("Could not find location: " + options.location); } } blobStore.createContainerInLocation(location, options.containerName); AreWeConsistentYet test = new AreWeConsistentYet( blobStore, blobStoreRead, options.containerName, options.iterations, options.objectSize); PrintStream out = System.out; out.println("eventual consistency count with " + options.iterations + " iterations: "); out.println("read after create: " + test.readAfterCreate()); out.println("read after delete: " + test.readAfterDelete()); out.println("read after overwrite: " + test.readAfterOverwrite()); out.println("list after create: " + test.listAfterCreate()); out.println("list after delete: " + test.listAfterDelete()); blobStore.deleteContainer(options.containerName); } }