org.jclouds.ContextBuilder Java Examples

The following examples show how to use org.jclouds.ContextBuilder. 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: DetachVolume.java    From jclouds-examples with Apache License 2.0 6 votes vote down vote up
public DetachVolume(String username, String apiKey) {
   // The provider configures jclouds To use the Rackspace Cloud (US)
   // To use the Rackspace Cloud (UK) set the system property or default value to "rackspace-cloudservers-uk"
   String provider = System.getProperty("provider.cs", "rackspace-cloudservers-us");

   Iterable<Module> modules = ImmutableSet.<Module> of(new SshjSshClientModule());

   ComputeServiceContext context = ContextBuilder.newBuilder(provider)
         .credentials(username, apiKey)
         .modules(modules)
         .buildView(ComputeServiceContext.class);
   computeService = context.getComputeService();
   NovaApi novaApi = context.unwrapApi(NovaApi.class);
   serverApi = novaApi.getServerApi(REGION);
   volumeAttachmentApi = novaApi.getVolumeAttachmentApi(REGION).get();

   cinderApi = ContextBuilder.newBuilder(PROVIDER)
         .credentials(username, apiKey)
         .buildApi(CinderApi.class);
   volumeApi = cinderApi.getVolumeApi(REGION);
}
 
Example #2
Source File: DeleteAll.java    From jclouds-examples with Apache License 2.0 6 votes vote down vote up
private void deleteQueues() throws IOException {
   MarconiApi marconiApi = ContextBuilder.newBuilder(System.getProperty("provider.cq", "rackspace-cloudqueues-us"))
         .credentials(username, apiKey)
         .buildApi(MarconiApi.class);
   UUID uuid = UUID.randomUUID(); // any UUID can be used to list all queues

   for (String region : marconiApi.getConfiguredRegions()) {
      try {
         System.out.format("Delete Queues in %s%n", region);
         QueueApi queueApi = marconiApi.getQueueApi(region, uuid);

         for (Queue queue : queueApi.list(false).concat()) {
            System.out.format("  %s%n", queue.getName());
            queueApi.delete(queue.getName());
         }
      } catch (Exception e) {
         e.printStackTrace();
      }
   }

   Closeables.close(marconiApi, true);
}
 
Example #3
Source File: DeleteAll.java    From jclouds-examples with Apache License 2.0 6 votes vote down vote up
private void deleteLoadBalancers() throws IOException {
   CloudLoadBalancersApi clbApi = ContextBuilder.newBuilder(System.getProperty("provider.clb", "rackspace-cloudloadbalancers-us"))
         .credentials(username, apiKey)
         .buildApi(CloudLoadBalancersApi.class);

   for (String region : clbApi.getConfiguredRegions()) {
      try {
         System.out.format("Delete Load Balancers in %s%n", region);
         LoadBalancerApi lbApi = clbApi.getLoadBalancerApi(region);

         for (LoadBalancer loadBalancer : lbApi.list().concat()) {
            System.out.format("  %s%n", loadBalancer.getName());
            lbApi.delete(loadBalancer.getId());
         }
      } catch (Exception e) {
         e.printStackTrace();
      }
   }

   Closeables.close(clbApi, true);
}
 
Example #4
Source File: CloudFilesManager.java    From blueflood with Apache License 2.0 6 votes vote down vote up
public synchronized boolean hasNewFiles() {
    // see if there are any files since lastMarker.
    BlobStoreContext ctx = ContextBuilder.newBuilder(provider)
            .credentials(user, key)
            .overrides(new Properties() {{
                setProperty(LocationConstants.PROPERTY_ZONE, zone);
            }})
            .buildView(BlobStoreContext.class);
    
    BlobStore store = ctx.getBlobStore();
    ListContainerOptions options = new ListContainerOptions().maxResults(batchSize).afterMarker(lastMarker);
    PageSet<? extends StorageMetadata> pages = store.list(container, options);
    
    log.debug("Saw {} new files since {}", pages.size() == batchSize ? "many" : Integer.toString(pages.size()), lastMarker);
    boolean emptiness = getBlobsWithinRange(pages).isEmpty();

    if(emptiness) {
        log.warn("No file found within range {}", new Range(START_TIME, STOP_TIME));
    } else {
        log.debug("New files found within range {}", new Range(START_TIME, STOP_TIME));
    }

    return !emptiness;
}
 
Example #5
Source File: CreateServerWithKeyPair.java    From jclouds-examples with Apache License 2.0 6 votes vote down vote up
public CreateServerWithKeyPair(String username, String apiKey) {
   Iterable<Module> modules = ImmutableSet.<Module> of(new SshjSshClientModule());

   // These properties control how often jclouds polls for a status update
   Properties overrides = new Properties();
   overrides.setProperty(POLL_INITIAL_PERIOD, POLL_PERIOD_TWENTY_SECONDS);
   overrides.setProperty(POLL_MAX_PERIOD, POLL_PERIOD_TWENTY_SECONDS);

   ComputeServiceContext context = ContextBuilder.newBuilder(PROVIDER)
         .credentials(username, apiKey)
         .overrides(overrides)
         .modules(modules)
         .buildView(ComputeServiceContext.class);

   computeService = context.getComputeService();
   novaApi = context.unwrapApi(NovaApi.class);
}
 
Example #6
Source File: CloudServersPublish.java    From jclouds-examples with Apache License 2.0 6 votes vote down vote up
public CloudServersPublish(List<String> args) {
   String username = args.get(0);
   String apiKey = args.get(1);
   numServers = args.size() == 3 ? Integer.valueOf(args.get(2)) : 1;

   Iterable<Module> modules = ImmutableSet.<Module> of(new SshjSshClientModule());

   // These properties control how often jclouds polls for a status update
   Properties overrides = new Properties();
   overrides.setProperty(POLL_INITIAL_PERIOD, POLL_PERIOD_TWENTY_SECONDS);
   overrides.setProperty(POLL_MAX_PERIOD, POLL_PERIOD_TWENTY_SECONDS);

   ComputeServiceContext context = ContextBuilder.newBuilder(PROVIDER)
         .credentials(username, apiKey)
         .overrides(overrides)
         .modules(modules)
         .buildView(ComputeServiceContext.class);
   computeService = context.getComputeService();
}
 
Example #7
Source File: ComputeServiceBuilderUtil.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
public static ComputeService buildDefaultComputeService(IaasProvider iaasProvider) {

        Properties properties = new Properties();

        // load properties
        for (Map.Entry<String, String> entry : iaasProvider.getProperties().entrySet()) {
            properties.put(entry.getKey(), entry.getValue());
        }

        // set modules
        Iterable<Module> modules =
                ImmutableSet.<Module>of(new SshjSshClientModule(), new SLF4JLoggingModule(),
                        new EnterpriseConfigurationModule());

        // build context
        ContextBuilder builder =
                ContextBuilder.newBuilder(iaasProvider.getProvider())
                        .credentials(iaasProvider.getIdentity(), iaasProvider.getCredential()).modules(modules)
                        .overrides(properties);

        return builder.buildView(ComputeServiceContext.class).getComputeService();
    }
 
Example #8
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 #9
Source File: AreWeConsistentYetTest.java    From are-we-consistent-yet with Apache License 2.0 6 votes vote down vote up
@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 #10
Source File: JCloudsConnector.java    From cloudml with GNU Lesser General Public License v3.0 6 votes vote down vote up
public JCloudsConnector(String provider,String login,String secretKey){
    journal.log(Level.INFO, ">> Connecting to "+provider+" ...");
    Properties overrides = new Properties();
    if(provider.equals("aws-ec2")){
        // choose only amazon images that are ebs-backed
        //overrides.setProperty(AWSEC2Constants.PROPERTY_EC2_AMI_OWNERS,"107378836295");
        overrides.setProperty(AWSEC2Constants.PROPERTY_EC2_AMI_QUERY,
                "owner-id=137112412989,107378836295,099720109477;state=available;image-type=machine;root-device-type=ebs");
    }
    overrides.setProperty(PROPERTY_CONNECTION_TIMEOUT, 0 + "");
    overrides.setProperty(PROPERTY_SO_TIMEOUT, 0 + "");
    overrides.setProperty(PROPERTY_REQUEST_TIMEOUT, 0 + "");
    overrides.setProperty(PROPERTY_RETRY_DELAY_START, 0 + "");
    Iterable<Module> modules = ImmutableSet.<Module> of(
            new SshjSshClientModule(),
            new NullLoggingModule());
    ContextBuilder builder = ContextBuilder.newBuilder(provider).credentials(login, secretKey).modules(modules).overrides(overrides);
    journal.log(Level.INFO, ">> Authenticating ...");
    computeContext=builder.buildView(ComputeServiceContext.class);
    ec2api=builder.buildApi(EC2Api.class);
    //loadBalancerCtx=builder.buildView(LoadBalancerServiceContext.class);

    compute=computeContext.getComputeService();
    this.provider = provider;
}
 
Example #11
Source File: BlobStoreManagedLedgerOffloader.java    From pulsar with Apache License 2.0 6 votes vote down vote up
private static Pair<BlobStoreLocation, BlobStore> createBlobStore(String driver,
                                                                  String region,
                                                                  String endpoint,
                                                                  Supplier<Credentials> credentials,
                                                                  int maxBlockSize) {
    Properties overrides = new Properties();
    // This property controls the number of parts being uploaded in parallel.
    overrides.setProperty("jclouds.mpu.parallel.degree", "1");
    overrides.setProperty("jclouds.mpu.parts.size", Integer.toString(maxBlockSize));
    overrides.setProperty(Constants.PROPERTY_SO_TIMEOUT, "25000");
    overrides.setProperty(Constants.PROPERTY_MAX_RETRIES, Integer.toString(100));

    ApiRegistry.registerApi(new S3ApiMetadata());
    ProviderRegistry.registerProvider(new AWSS3ProviderMetadata());
    ProviderRegistry.registerProvider(new GoogleCloudStorageProviderMetadata());

    ContextBuilder contextBuilder = ContextBuilder.newBuilder(driver);
    contextBuilder.credentialsSupplier(credentials);

    if (isS3Driver(driver) && !Strings.isNullOrEmpty(endpoint)) {
        contextBuilder.endpoint(endpoint);
        overrides.setProperty(S3Constants.PROPERTY_S3_VIRTUAL_HOST_BUCKETS, "false");
    }
    contextBuilder.overrides(overrides);
    BlobStoreContext context = contextBuilder.buildView(BlobStoreContext.class);
    BlobStore blobStore = context.getBlobStore();

    log.info("Connect to blobstore : driver: {}, region: {}, endpoint: {}",
        driver, region, endpoint);
    return Pair.of(
        BlobStoreLocation.of(region, endpoint),
        blobStore);
}
 
Example #12
Source File: ImportCollectionIT.java    From usergrid with Apache License 2.0 6 votes vote down vote up
/**
 * Delete the configured s3 bucket.
 */
public void deleteBucket() {

    logger.debug("\n\nDelete bucket\n");

    String accessId = System.getProperty(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR);
    String secretKey = System.getProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR);

    Properties overrides = new Properties();
    overrides.setProperty("s3" + ".identity", accessId);
    overrides.setProperty("s3" + ".credential", secretKey);

    final Iterable<? extends Module> MODULES = ImmutableSet
        .of(new JavaUrlHttpCommandExecutorServiceModule(),
            new Log4JLoggingModule(),
            new NettyPayloadModule());

    BlobStoreContext context =
        ContextBuilder.newBuilder("s3").credentials(accessId, secretKey).modules(MODULES)
            .overrides(overrides).buildView(BlobStoreContext.class);

    BlobStore blobStore = context.getBlobStore();
    blobStore.deleteContainer( bucketName );
}
 
Example #13
Source File: ImportServiceIT.java    From usergrid with Apache License 2.0 6 votes vote down vote up
public void deleteBucket() {

        String accessId = System.getProperty( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR );
        String secretKey = System.getProperty( SDKGlobalConfiguration.SECRET_KEY_ENV_VAR );

        Properties overrides = new Properties();
        overrides.setProperty( "s3" + ".identity", accessId );
        overrides.setProperty( "s3" + ".credential", secretKey );

        Blob bo = null;
        BlobStore blobStore = null;
        final Iterable<? extends Module> MODULES = ImmutableSet
                .of(new JavaUrlHttpCommandExecutorServiceModule(), new Log4JLoggingModule(),
                        new NettyPayloadModule());

        BlobStoreContext context =
                ContextBuilder.newBuilder("s3").credentials( accessId, secretKey ).modules( MODULES )
                        .overrides( overrides ).buildView( BlobStoreContext.class );

        blobStore = context.getBlobStore();
        blobStore.deleteContainer( bucketName );
    }
 
Example #14
Source File: S3ProxyImpl.java    From pravega with Apache License 2.0 6 votes vote down vote up
public S3ProxyImpl(String endpoint, S3Config s3Config) {
    URI uri = URI.create(endpoint);

    Properties properties = new Properties();
    properties.setProperty("s3proxy.authorization", "none");
    properties.setProperty("s3proxy.endpoint", endpoint);
    properties.setProperty("jclouds.provider", "filesystem");
    properties.setProperty("jclouds.filesystem.basedir", "/tmp/s3proxy");

    ContextBuilder builder = ContextBuilder
            .newBuilder("filesystem")
            .credentials("x", "x")
            .modules(ImmutableList.<Module>of(new SLF4JLoggingModule()))
            .overrides(properties);
    BlobStoreContext context = builder.build(BlobStoreContext.class);
    BlobStore blobStore = context.getBlobStore();
    s3Proxy = S3Proxy.builder().awsAuthentication(AuthenticationType.AWS_V2_OR_V4, "x", "x")
                     .endpoint(uri)
                     .keyStore("", "")
                     .blobStore(blobStore)
                     .ignoreUnknownHeaders(true)
                     .build();
    client = new S3JerseyCopyPartClient(s3Config);
}
 
Example #15
Source File: Utils.java    From jclouds-examples with Apache License 2.0 6 votes vote down vote up
public static ComputeServiceContext getComputeApiFromCarinaDirectory(String path) throws IOException {
   // docker.ps1 contains the endpoint
   String endpoint = "https://" +
         Files.readFirstLine(new File(joinPath(path, "docker.ps1")),
               Charset.forName("UTF-8")).split("=")[1].replace("\"", "").substring(6);

   // enable logging and sshj
   Iterable<Module> modules = ImmutableSet.<Module> of(new SLF4JLoggingModule(), new SshjSshClientModule());
   Properties overrides = new Properties();

   // disable certificate checking for Carina
   overrides.setProperty("jclouds.trust-all-certs", "true");

   return ContextBuilder.newBuilder("docker")
         .credentials(joinPath(path, "cert.pem"), joinPath(path, "key.pem"))
         .modules(modules)
         .overrides(overrides)
         .endpoint(endpoint)
         .buildView(ComputeServiceContext.class);
}
 
Example #16
Source File: CreateService.java    From jclouds-examples with Apache License 2.0 5 votes vote down vote up
public CreateService(String username, String apiKey) {
   cdnApi = ContextBuilder.newBuilder(PROVIDER)
         .credentials(username, apiKey)
         .buildApi(PoppyApi.class);

   serviceApi = cdnApi.getServiceApi();
   flavorApi = cdnApi.getFlavorApi();
}
 
Example #17
Source File: DeleteServerVlanAndNetworkDomain.java    From jclouds-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args)
{
    /*
     * Build an instance of the Dimension DataCloud Control Provider using the endpoint provided.
     * Typically the endpoint will be of the form https://api-GEO.dimensiondata.com/caas
     * We also need to provide authenticate details, a username and password.
     *
     * Internally the Dimension Data CloudControl Provider will use the org.jclouds.dimensiondata.cloudcontrol.features.AccountApi
     * to lookup the organization identifier so that it is used as part of the requests.
     *
     */
    String endpoint = args[0];
    String username = args[1];
    String password = args[2];

    try (ApiContext<DimensionDataCloudControlApi> ctx = ContextBuilder.newBuilder(DIMENSIONDATA_CLOUDCONTROL_PROVIDER)
            .endpoint(endpoint)
            .credentials(username, password)
            .modules(ImmutableSet.of(new SLF4JLoggingModule()))
            .build())
    {
        DimensionDataCloudControlApi api = ctx.getApi();

        /*
         * Referencing the asset created in org.jclouds.examples.dimensiondata.cloudcontrol.DeployNetworkDomainVlanAndServer
         */
        final String networkDomainName = "jclouds-example";
        String networkDomainId = getNetworkDomainId(api, networkDomainName);
        final String serverName = "jclouds-server";
        final String vlanName = "jclouds-example-vlan";

        deleteServer(api, serverName);
        deleteVlan(api, vlanName, networkDomainId);
        deleteNetworkDomain(api, networkDomainId);
        deleteTagKey(api, "jclouds");
    }
}
 
Example #18
Source File: UpdateService.java    From jclouds-examples with Apache License 2.0 5 votes vote down vote up
public UpdateService(String username, String apiKey) {
   cdnApi = ContextBuilder.newBuilder(PROVIDER)
         .credentials(username, apiKey)
         .buildApi(PoppyApi.class);

   serviceApi = cdnApi.getServiceApi();
}
 
Example #19
Source File: JCloudsBlobStoreIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
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 #20
Source File: GCEIaas.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
private Operation waitGCEOperationDone(Operation operation) {
    IaasProvider iaasInfo = getIaasProvider();
    Injector injector = ContextBuilder.newBuilder(iaasInfo.getProvider())
            .credentials(iaasInfo.getIdentity(), iaasInfo.getCredential())
            .buildInjector();
    Predicate<AtomicReference<Operation>> zoneOperationDonePredicate =
            injector.getInstance(Key.get(new TypeLiteral<Predicate<AtomicReference<Operation>>>() {
            }, Names.named("zone")));
    AtomicReference<Operation> operationReference = Atomics.newReference(operation);
    retry(zoneOperationDonePredicate, MAX_WAIT_TIME, 1, SECONDS).apply(operationReference);

    return operationReference.get();
}
 
Example #21
Source File: BaseAWSEC2ApiMockTest.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
protected ContextBuilder builder(Properties overrides) {
   MockWebServer defaultServer = regionToServers.get(DEFAULT_REGION);
   overrides.setProperty(Constants.PROPERTY_MAX_RETRIES, "1");
   overrides.setProperty(ComputeServiceProperties.TIMEOUT_CLEANUP_INCIDENTAL_RESOURCES, "0");
   return ContextBuilder.newBuilder(new AWSEC2ProviderMetadata())
         .credentials(ACCESS_KEY, SECRET_KEY)
         .endpoint(defaultServer.getUrl("").toString())
         .overrides(overrides)
         .modules(modules);
}
 
Example #22
Source File: AbstractComputeServiceRegistry.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
public ComputeService get() {
    // Synchronizing to avoid deadlock from sun.reflect.annotation.AnnotationType.
    // See https://github.com/brooklyncentral/brooklyn/issues/974
    synchronized (createComputeServicesMutex) {
        ComputeServiceContext computeServiceContext = ContextBuilder.newBuilder(provider)
                .modules(modules)
                .credentialsSupplier(AbstractComputeServiceRegistry.this.makeCredentials(conf))
                .overrides(properties)
                .build(ComputeServiceContext.class);
        return computeServiceContext.getComputeService();
    }
}
 
Example #23
Source File: ImportCollectionIT.java    From usergrid with Apache License 2.0 5 votes vote down vote up
private static void deleteBucketsWithPrefix() {

        logger.debug("\n\nDelete buckets with prefix {}\n", bucketPrefix );

        String accessId = System.getProperty(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR);
        String secretKey = System.getProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR);

        Properties overrides = new Properties();
        overrides.setProperty("s3" + ".identity", accessId);
        overrides.setProperty("s3" + ".credential", secretKey);

        final Iterable<? extends Module> MODULES = ImmutableSet
            .of(new JavaUrlHttpCommandExecutorServiceModule(),
                new Log4JLoggingModule(),
                new NettyPayloadModule());

        BlobStoreContext context =
            ContextBuilder.newBuilder("s3").credentials(accessId, secretKey).modules(MODULES)
                .overrides(overrides).buildView(BlobStoreContext.class);

        BlobStore blobStore = context.getBlobStore();
        final PageSet<? extends StorageMetadata> blobStoreList = blobStore.list();

        for ( Object o : blobStoreList.toArray() ) {
            StorageMetadata s = (StorageMetadata)o;

            if ( s.getName().startsWith( bucketPrefix )) {
                try {
                    blobStore.deleteContainer(s.getName());
                } catch ( ContainerNotFoundException cnfe ) {
                    logger.warn("Attempted to delete bucket {} but it is already deleted", cnfe );
                }
                logger.debug("Deleted bucket {}", s.getName());
            }
        }
    }
 
Example #24
Source File: CreateTenantAndUser.java    From jclouds-examples with Apache License 2.0 5 votes vote down vote up
public CreateTenantAndUser(String endpoint, String tenantName, String userName, String password) {
   System.out.format("%s%n", this.getClass().getName());

   Iterable<Module> modules = ImmutableSet.<Module>of(new SLF4JLoggingModule());

   String provider = "openstack-keystone";
   String identity = tenantName + ":"  + userName;

   keystoneApi = ContextBuilder.newBuilder(provider)
         .endpoint(endpoint)
         .credentials(identity, password)
         .modules(modules)
         .buildApi(KeystoneApi.class);
}
 
Example #25
Source File: ImportResourceIT.java    From usergrid with Apache License 2.0 5 votes vote down vote up
private static void deleteBucketsWithPrefix() {

        logger.debug("\n\nDelete buckets with prefix {}\n", bucketPrefix);

        String accessId = System.getProperty( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR );
        String secretKey = System.getProperty( SDKGlobalConfiguration.SECRET_KEY_ENV_VAR );

        Properties overrides = new Properties();
        overrides.setProperty("s3" + ".identity", accessId);
        overrides.setProperty("s3" + ".credential", secretKey);

        final Iterable<? extends Module> MODULES = ImmutableSet
            .of(new JavaUrlHttpCommandExecutorServiceModule(),
                new Log4JLoggingModule(),
                new NettyPayloadModule());

        BlobStoreContext context =
            ContextBuilder.newBuilder("s3").credentials(accessId, secretKey).modules(MODULES)
                .overrides(overrides ).buildView(BlobStoreContext.class);

        BlobStore blobStore = context.getBlobStore();
        final PageSet<? extends StorageMetadata> blobStoreList = blobStore.list();

        for (Object o : blobStoreList.toArray()) {
            StorageMetadata s = (StorageMetadata) o;

            if (s.getName().startsWith(bucketPrefix)) {
                try {
                    blobStore.deleteContainer(s.getName());
                } catch (ContainerNotFoundException cnfe) {
                    logger.warn("Attempted to delete bucket {} but it is already deleted", cnfe);
                }
                logger.debug("Deleted bucket {}", s.getName());
            }
        }
    }
 
Example #26
Source File: OpenstackIaasHandler.java    From roboconf-platform with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a JCloud context for Swift.
 * @param targetProperties the target properties
 * @return a non-null object
 * @throws TargetException if the target properties are invalid
 */
static SwiftApi swiftApi( Map<String,String> targetProperties ) throws TargetException {

	validate( targetProperties );
	return ContextBuilder
			.newBuilder( PROVIDER_SWIFT )
			.endpoint( targetProperties.get( API_URL ))
			.credentials( identity( targetProperties ), targetProperties.get( PASSWORD ))
			.buildApi( SwiftApi.class );
}
 
Example #27
Source File: OpenstackIaasHandler.java    From roboconf-platform with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a JCloud context for Nova.
 * @param targetProperties the target properties
 * @return a non-null object
 * @throws TargetException if the target properties are invalid
 */
static NovaApi novaApi( Map<String,String> targetProperties ) throws TargetException {

	validate( targetProperties );
	return ContextBuilder
			.newBuilder( PROVIDER_NOVA )
			.endpoint( targetProperties.get( API_URL ))
			.credentials( identity( targetProperties ), targetProperties.get( PASSWORD ))
			.buildApi( NovaApi.class );
}
 
Example #28
Source File: ObjectStoreFileStorageFactoryBean.java    From multiapps-controller with Apache License 2.0 5 votes vote down vote up
private BlobStoreContext getBlobStoreContext() {
    BlobStoreContext blobStoreContext;
    ObjectStoreServiceInfo serviceInfo = getServiceInfo();
    if (serviceInfo == null) {
        return null;
    }
    ContextBuilder contextBuilder = ContextBuilder.newBuilder(serviceInfo.getProvider())
                                                  .credentials(serviceInfo.getIdentity(), serviceInfo.getCredential());
    if (serviceInfo.getEndpoint() != null) {
        contextBuilder.endpoint(serviceInfo.getEndpoint());
    }
    blobStoreContext = contextBuilder.buildView(BlobStoreContext.class);
    return blobStoreContext;
}
 
Example #29
Source File: OpenStackConnector.java    From cloudml with GNU Lesser General Public License v3.0 5 votes vote down vote up
public OpenStackConnector(String endPoint,String provider,String login,String secretKey){
    this.endpoint=endPoint;
    journal.log(Level.INFO, ">> Connecting to "+provider+" ...");
    Iterable<Module> modules = ImmutableSet.<Module> of(
            new SshjSshClientModule(),
            new NullLoggingModule());
    ContextBuilder builder = ContextBuilder.newBuilder(provider)
            .endpoint(endPoint)
            .credentials(login, secretKey)
            .modules(modules);
    journal.log(Level.INFO, ">> Authenticating ...");
    computeContext=builder.buildView(ComputeServiceContext.class);
    novaComputeService= computeContext.getComputeService();
    serverApi=builder.buildApi(NovaApi.class);
}
 
Example #30
Source File: Logging.java    From jclouds-examples with Apache License 2.0 5 votes vote down vote up
public Logging(String username, String apiKey) {
   // The provider configures jclouds To use the Rackspace Cloud (US)
   // To use the Rackspace Cloud (UK) set the system property or default value to "rackspace-cloudservers-uk"
   String provider = System.getProperty("provider.cs", "rackspace-cloudservers-us");

   // This module is responsible for enabling logging
   Iterable<Module> modules = ImmutableSet.<Module> of(new SLF4JLoggingModule());

   nova = ContextBuilder.newBuilder(provider)
         .credentials(username, apiKey)
         .modules(modules) // don't forget to add the modules to your context!
         .buildApi(NovaApi.class);
}