Java Code Examples for org.jclouds.compute.ComputeServiceContext#getComputeService()

The following examples show how to use org.jclouds.compute.ComputeServiceContext#getComputeService() . 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: 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 2
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 3
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 4
Source File: CreateVolumeAndAttach.java    From jclouds-examples with Apache License 2.0 6 votes vote down vote up
public CreateVolumeAndAttach(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");

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

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

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

   cinderApi = ContextBuilder.newBuilder(PROVIDER)
         .credentials(username, apiKey)
         .buildApi(CinderApi.class);
   volumeApi = cinderApi.getVolumeApi(REGION);
}
 
Example 5
Source File: CloudDistributedTLCJob.java    From tlaplus with MIT License 5 votes vote down vote up
private static void destroyNodes(final ComputeServiceContext ctx, final String groupname) {
	// Destroy all workers identified by the given group
	final ComputeService computeService = ctx.getComputeService();
	if (computeService != null) {
		Set<? extends NodeMetadata> destroyed = computeService
				.destroyNodesMatching(
						Predicates.<NodeMetadata> and(not(TERMINATED),
								inGroup(groupname)));
		System.out.printf("<< destroyed nodes %s%n", destroyed);
	}
}
 
Example 6
Source File: NovaContext.java    From karamel with Apache License 2.0 5 votes vote down vote up
public NovaContext(NovaCredentials credentials, ContextBuilder builder) {
  this.novaCredentials = credentials;
  ComputeServiceContext context = builder.credentials(credentials.getAccountName(),credentials.getAccountPass())
          .endpoint(credentials.getEndpoint())
          .buildView(ComputeServiceContext.class);
  this.computeService = context.getComputeService();
  this.novaApi = computeService.getContext().unwrapApi(NovaApi.class);
  this.securityGroupApi = novaApi.getSecurityGroupApi(credentials.getRegion()).get();
  this.keyPairApi = novaApi.getKeyPairApi(credentials.getRegion()).get();
}
 
Example 7
Source File: GceContext.java    From karamel with Apache License 2.0 5 votes vote down vote up
public GceContext(Credentials credentials) {
  ComputeServiceContext context = ContextBuilder.newBuilder("google-compute-engine")
      .modules(Arrays.asList(
              new SshjSshClientModule(),
              new EnterpriseConfigurationModule(),
              new SLF4JLoggingModule()))
      .credentials(credentials.identity, credentials.credential)
      .buildView(ComputeServiceContext.class);
  computeService = context.getComputeService();
  gceApi = context.unwrapApi(GoogleComputeEngineApi.class);
  fireWallApi = gceApi.firewalls();
  networkApi = gceApi.networks();
  routeApi = gceApi.routes();
  this.credentials = credentials;
}
 
Example 8
Source File: Ec2Context.java    From karamel with Apache License 2.0 5 votes vote down vote up
public Ec2Context(Ec2Credentials credentials) {
  this.credentials = credentials;
  Properties properties = new Properties();
  long scriptTimeout = TimeUnit.MILLISECONDS.convert(50, TimeUnit.MINUTES);
  properties.setProperty(TIMEOUT_SCRIPT_COMPLETE, scriptTimeout + "");
  properties.setProperty(TIMEOUT_PORT_OPEN, scriptTimeout + "");
  properties.setProperty(PROPERTY_CONNECTION_TIMEOUT, scriptTimeout + "");
  properties.setProperty(PROPERTY_EC2_AMI_QUERY, "owner-id=137112412989;state=available;image-type=machine");
  properties.setProperty(PROPERTY_EC2_CC_AMI_QUERY, "");
  properties.setProperty(Constants.PROPERTY_MAX_RETRIES, Settings.JCLOUDS_PROPERTY_MAX_RETRIES + "");
  properties.setProperty(Constants.PROPERTY_RETRY_DELAY_START, Settings.JCLOUDS_PROPERTY_RETRY_DELAY_START + "");

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

  ContextBuilder build = ContextBuilder.newBuilder("aws-ec2")
      .credentials(credentials.getAccessKey(), credentials.getSecretKey())
      .modules(modules)
      .overrides(properties);
  ComputeServiceContext context = build.buildView(ComputeServiceContext.class);
  this.computeService = (AWSEC2ComputeService) context.getComputeService();
  this.ec2api = computeService.getContext().unwrapApi(EC2Api.class);
  this.securityGroupApi = ec2api.getSecurityGroupApi().get();
  this.keypairApi = (AWSKeyPairApi) ec2api.getKeyPairApi().get();

  vmBatchSize = Settings.AWS_VM_BATCH_SIZE();
}
 
Example 9
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 10
Source File: JCloudsHandler.java    From roboconf-platform with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a JCloud context.
 * @param targetProperties the target properties
 * @return a non-null object
 * @throws TargetException if the target properties are invalid
 */
ComputeService jcloudContext( Map<String,String> targetProperties ) throws TargetException {

	validate( targetProperties );
	ComputeServiceContext context = ContextBuilder
			.newBuilder( targetProperties.get( PROVIDER_ID ))
			.endpoint( targetProperties.get( ENDPOINT ))
			.credentials( targetProperties.get( IDENTITY ), targetProperties.get( CREDENTIAL ))
			.buildView( ComputeServiceContext.class );

	return context.getComputeService();
}
 
Example 11
Source File: CreateServer.java    From jclouds-examples with Apache License 2.0 5 votes vote down vote up
public CreateServer(String username, String apiKey) {
   // 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)
         .buildView(ComputeServiceContext.class);
   computeService = context.getComputeService();
}
 
Example 12
Source File: ServerMetadata.java    From jclouds-examples with Apache License 2.0 5 votes vote down vote up
public ServerMetadata(String username, String apiKey) {
   ComputeServiceContext context = ContextBuilder.newBuilder(PROVIDER)
         .credentials(username, apiKey)
         .buildView(ComputeServiceContext.class);
   computeService = context.getComputeService();
   NovaApi novaApi = context.unwrapApi(NovaApi.class);
   serverApi = novaApi.getServerApi(REGION);
}
 
Example 13
Source File: ListServersWithFiltering.java    From jclouds-examples with Apache License 2.0 5 votes vote down vote up
public ListServersWithFiltering(String username, String apiKey) {
   ComputeServiceContext context = ContextBuilder.newBuilder(PROVIDER)
         .credentials(username, apiKey)
         .buildView(ComputeServiceContext.class);
   computeService = context.getComputeService();

}
 
Example 14
Source File: DeleteServer.java    From jclouds-examples with Apache License 2.0 5 votes vote down vote up
public DeleteServer(String username, String apiKey) {
   // These properties control how often jclouds polls for a status udpate
   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)
         .buildView(ComputeServiceContext.class);
   computeService = context.getComputeService();
}