Java Code Examples for org.jclouds.blobstore.BlobStoreContext#close()

The following examples show how to use org.jclouds.blobstore.BlobStoreContext#close() . 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: MainApp.java    From jclouds-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws IOException {
   if (args.length < 2) {
      throw new IllegalArgumentException("Invalid number of parameters. Syntax is: \"identity\" \"credential\"");
   }

   String identity = args[0];
   String credentials = args[1];

   // Init
   BlobStoreContext context = ContextBuilder.newBuilder("glacier")
         .credentials(identity, credentials)
         .buildView(BlobStoreContext.class);

   try {
      while (chooseOption(context));
   } finally {
      context.close();
   }
}
 
Example 2
Source File: BlobStoreExpiryTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
private Set<Service> getServices(Credentials creds) throws Exception {
    BlobStoreContext tmpContext = BlobStoreContextFactoryImpl.INSTANCE.newBlobStoreContext(location);
    try {
        tmpContext.getBlobStore().list();
        LoadingCache<Credentials, Access> authCache = getAuthCache(tmpContext);
        Access tmpAccess = authCache.get(creds);
        return ImmutableSet.copyOf(tmpAccess);
    } finally {
        tmpContext.close();
    }

}
 
Example 3
Source File: BlobStoreCleaner.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
        LocalManagementContextForTests mgmt = new LocalManagementContextForTests(BrooklynProperties.Factory.newDefault()); 
        JcloudsLocation location = (JcloudsLocation) mgmt.getLocationRegistry().getLocationManaged(locationSpec);
            
        String identity = checkNotNull(location.getConfig(LocationConfigKeys.ACCESS_IDENTITY), "identity must not be null");
        String credential = checkNotNull(location.getConfig(LocationConfigKeys.ACCESS_CREDENTIAL), "credential must not be null");
        String provider = checkNotNull(location.getConfig(LocationConfigKeys.CLOUD_PROVIDER), "provider must not be null");
        String endpoint = location.getConfig(CloudLocationConfig.CLOUD_ENDPOINT);

        BlobStoreContext context = ContextBuilder.newBuilder(provider)
                .credentials(identity, credential)
                .endpoint(endpoint)
                .buildView(BlobStoreContext.class);
        
        PageSet<? extends StorageMetadata> containers = context.getBlobStore().list();
        for (StorageMetadata container: containers) {
            if (container.getName().matches("brooklyn.*-test.*")
                // to kill all containers here
//                || container.getName().matches(".*")
                ) {
                log.info("killing - "+container.getName());
                context.getBlobStore().deleteContainer(container.getName());
            } else {
                log.info("KEEPING - "+container.getName());
            }
        }
        context.close();
    }
 
Example 4
Source File: CloudExplorerSupport.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
protected void doCall(JcloudsLocation loc, String indent) throws Exception {
    BlobStoreContext context = BlobStoreContextFactoryImpl.INSTANCE.newBlobStoreContext(loc);
    try {
        org.jclouds.blobstore.BlobStore blobStore = context.getBlobStore();
        doCall(blobStore, indent);
    } finally {
        context.close();
    }
}