Search in sources :

Example 21 with ComputeServiceContext

use of org.jclouds.compute.ComputeServiceContext in project iobserve-analysis by research-iobserve.

the class AbstractActionScript method getComputeServiceForContainer.

/**
 * Returns a compute service client to use for further queries to the cloud provider.
 *
 * @param container
 *            the resource container for which to get the compute service
 * @return the corresponding compute service
 */
protected ComputeService getComputeServiceForContainer(final ResourceContainerCloud container) {
    final CloudProvider provider = container.getInstanceType().getProvider();
    final ComputeServiceContext context = ContextBuilder.newBuilder(provider.getName()).credentials(provider.getIdentity(), provider.getCredential()).modules(// NOCS
    ImmutableSet.<Module>of(new SLF4JLoggingModule(), new SshjSshClientModule())).buildView(ComputeServiceContext.class);
    final ComputeService client = context.getComputeService();
    return client;
}
Also used : SLF4JLoggingModule(org.jclouds.logging.slf4j.config.SLF4JLoggingModule) CloudProvider(org.palladiosimulator.pcm.cloud.pcmcloud.cloudprofile.CloudProvider) SshjSshClientModule(org.jclouds.sshj.config.SshjSshClientModule) ComputeServiceContext(org.jclouds.compute.ComputeServiceContext) Module(com.google.inject.Module) SLF4JLoggingModule(org.jclouds.logging.slf4j.config.SLF4JLoggingModule) SshjSshClientModule(org.jclouds.sshj.config.SshjSshClientModule) ComputeService(org.jclouds.compute.ComputeService)

Example 22 with ComputeServiceContext

use of org.jclouds.compute.ComputeServiceContext in project whirr by apache.

the class ByonClusterController method runScriptOnNodesMatching.

public Map<? extends NodeMetadata, ExecResponse> runScriptOnNodesMatching(final ClusterSpec spec, Predicate<NodeMetadata> condition, final Statement statement) throws IOException, RunScriptOnNodesException {
    ComputeServiceContext computeServiceContext = getCompute().apply(spec);
    ComputeService computeService = computeServiceContext.getComputeService();
    Cluster cluster = getClusterStateStore(spec).load();
    RunScriptOptions options = RunScriptOptions.Builder.runAsRoot(false).wrapInInitScript(false);
    return computeService.runScriptOnNodesMatching(Predicates.<NodeMetadata>and(condition, runningIn(cluster)), statement, options);
}
Also used : RunScriptOptions(org.jclouds.compute.options.RunScriptOptions) ComputeServiceContext(org.jclouds.compute.ComputeServiceContext) ComputeService(org.jclouds.compute.ComputeService)

Example 23 with ComputeServiceContext

use of org.jclouds.compute.ComputeServiceContext in project whirr by apache.

the class BootstrapClusterActionTest method testSubroleInvoked.

@Test
@SuppressWarnings("unchecked")
public void testSubroleInvoked() throws Exception {
    CompositeConfiguration config = new CompositeConfiguration();
    if (System.getProperty("config") != null) {
        config.addConfiguration(new PropertiesConfiguration(System.getProperty("config")));
    }
    Configuration conf = new PropertiesConfiguration();
    conf.addProperty("whirr.service-name", "test-service");
    conf.addProperty("whirr.cluster-name", "test-cluster");
    conf.addProperty("whirr.instance-templates", "1 puppet:module::manifest+something-else");
    conf.addProperty("whirr.provider", "ec2");
    config.addConfiguration(conf);
    ClusterSpec clusterSpec = ClusterSpec.withTemporaryKeys(conf);
    Set<String> nn = new HashSet<String>();
    nn.add("puppet:module::manifest");
    nn.add("something-else");
    TestNodeStarterFactory nodeStarterFactory = null;
    ClusterActionHandlerFactory puppetHandlerFactory = mock(ClusterActionHandlerFactory.class);
    ClusterActionHandler handler = mock(ClusterActionHandler.class);
    when(puppetHandlerFactory.getRolePrefix()).thenReturn("puppet:");
    when(puppetHandlerFactory.create("module::manifest")).thenReturn(handler);
    when(handler.getRole()).thenReturn("something-else");
    LoadingCache<String, ClusterActionHandler> handlerMap = new HandlerMapFactory().create(ImmutableSet.of(puppetHandlerFactory), ImmutableSet.of(handler));
    Function<ClusterSpec, ComputeServiceContext> getCompute = mock(Function.class);
    ComputeServiceContext serviceContext = mock(ComputeServiceContext.class);
    ComputeService computeService = mock(ComputeService.class);
    TemplateBuilder templateBuilder = mock(TemplateBuilder.class);
    Template template = mock(Template.class);
    TemplateOptions templateOptions = mock(TemplateOptions.class);
    when(getCompute.apply(clusterSpec)).thenReturn(serviceContext);
    when(serviceContext.getComputeService()).thenReturn(computeService);
    when(computeService.getContext()).thenReturn(serviceContext);
    when(serviceContext.getBackendType()).thenReturn(TypeToken.class.cast(TypeToken.of(Context.class)));
    when(computeService.templateBuilder()).thenReturn(templateBuilder);
    when(templateBuilder.from((TemplateBuilderSpec) any())).thenReturn(templateBuilder);
    when(templateBuilder.options((TemplateOptions) any())).thenReturn(templateBuilder);
    when(templateBuilder.build()).thenReturn(template);
    when(template.getOptions()).thenReturn(templateOptions);
    Map<Set<String>, Stack<Integer>> reaction = Maps.newHashMap();
    Stack<Integer> nnStack = new Stack<Integer>();
    nnStack.push(new Integer(1));
    reaction.put(nn, nnStack);
    nodeStarterFactory = new TestNodeStarterFactory(reaction);
    BootstrapClusterAction bootstrapper = new BootstrapClusterAction(getCompute, handlerMap, nodeStarterFactory);
    bootstrapper.execute(clusterSpec, null);
    if (nodeStarterFactory != null) {
        nodeStarterFactory.validateCompletion();
    }
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) HashSet(java.util.HashSet) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) Configuration(org.apache.commons.configuration.Configuration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) TemplateBuilder(org.jclouds.compute.domain.TemplateBuilder) TemplateOptions(org.jclouds.compute.options.TemplateOptions) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) HandlerMapFactory(org.apache.whirr.HandlerMapFactory) Template(org.jclouds.compute.domain.Template) ClusterActionHandlerFactory(org.apache.whirr.service.ClusterActionHandlerFactory) HashSet(java.util.HashSet) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) ComputeServiceContext(org.jclouds.compute.ComputeServiceContext) ClusterSpec(org.apache.whirr.ClusterSpec) ComputeService(org.jclouds.compute.ComputeService) Stack(java.util.Stack) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClusterActionHandler(org.apache.whirr.service.ClusterActionHandler) TypeToken(com.google.common.reflect.TypeToken) Test(org.junit.Test)

Example 24 with ComputeServiceContext

use of org.jclouds.compute.ComputeServiceContext in project whirr by apache.

the class BootstrapClusterActionTest method testSubroleNotSupported.

@SuppressWarnings("unchecked")
@Test(expected = IllegalArgumentException.class)
public /**
 * test is the same as previous (SubroleInvoked) except it knows puppet, not puppet:, as the role;
 * the colon in the role def'n is the indication it accepts subroles,
 * so this should throw IllegalArgument when we refer to puppet:module...
 */
void testSubroleNotSupported() throws Exception {
    CompositeConfiguration config = new CompositeConfiguration();
    if (System.getProperty("config") != null) {
        config.addConfiguration(new PropertiesConfiguration(System.getProperty("config")));
    }
    Configuration conf = new PropertiesConfiguration();
    conf.addProperty("whirr.service-name", "test-service");
    conf.addProperty("whirr.cluster-name", "test-cluster");
    conf.addProperty("whirr.instance-templates", "1 puppet:module::manifest+something-else");
    conf.addProperty("whirr.provider", "ec2");
    config.addConfiguration(conf);
    ClusterSpec clusterSpec = ClusterSpec.withTemporaryKeys(conf);
    Set<String> nn = new HashSet<String>();
    nn.add("puppet:module::manifest");
    nn.add("something-else");
    TestNodeStarterFactory nodeStarterFactory = null;
    ClusterActionHandlerFactory puppetHandlerFactory = mock(ClusterActionHandlerFactory.class);
    ClusterActionHandler handler = mock(ClusterActionHandler.class);
    when(puppetHandlerFactory.getRolePrefix()).thenReturn("puppet");
    when(handler.getRole()).thenReturn("something-else");
    LoadingCache<String, ClusterActionHandler> handlerMap = new HandlerMapFactory().create(ImmutableSet.of(puppetHandlerFactory), ImmutableSet.of(handler));
    Function<ClusterSpec, ComputeServiceContext> getCompute = mock(Function.class);
    ComputeServiceContext serviceContext = mock(ComputeServiceContext.class);
    ComputeService computeService = mock(ComputeService.class);
    TemplateBuilder templateBuilder = mock(TemplateBuilder.class);
    Template template = mock(Template.class);
    when(getCompute.apply(clusterSpec)).thenReturn(serviceContext);
    when(serviceContext.getComputeService()).thenReturn(computeService);
    when(computeService.templateBuilder()).thenReturn(templateBuilder);
    when(templateBuilder.from((TemplateBuilderSpec) any())).thenReturn(templateBuilder);
    when(templateBuilder.options((TemplateOptions) any())).thenReturn(templateBuilder);
    when(templateBuilder.build()).thenReturn(template);
    Map<Set<String>, Stack<Integer>> reaction = Maps.newHashMap();
    Stack<Integer> nnStack = new Stack<Integer>();
    nnStack.push(1);
    reaction.put(nn, nnStack);
    nodeStarterFactory = new TestNodeStarterFactory(reaction);
    BootstrapClusterAction bootstrapper = new BootstrapClusterAction(getCompute, handlerMap, nodeStarterFactory);
    bootstrapper.execute(clusterSpec, null);
    if (nodeStarterFactory != null) {
        nodeStarterFactory.validateCompletion();
    }
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) HashSet(java.util.HashSet) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) Configuration(org.apache.commons.configuration.Configuration) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) CompositeConfiguration(org.apache.commons.configuration.CompositeConfiguration) TemplateBuilder(org.jclouds.compute.domain.TemplateBuilder) ComputeServiceContext(org.jclouds.compute.ComputeServiceContext) ClusterSpec(org.apache.whirr.ClusterSpec) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) ComputeService(org.jclouds.compute.ComputeService) HandlerMapFactory(org.apache.whirr.HandlerMapFactory) Template(org.jclouds.compute.domain.Template) Stack(java.util.Stack) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClusterActionHandler(org.apache.whirr.service.ClusterActionHandler) ClusterActionHandlerFactory(org.apache.whirr.service.ClusterActionHandlerFactory) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 25 with ComputeServiceContext

use of org.jclouds.compute.ComputeServiceContext in project legacy-jclouds-examples by jclouds.

the class DeleteServer method init.

private void init(String[] args) {
    // The provider configures jclouds To use the Rackspace Cloud (US)
    // To use the Rackspace Cloud (UK) set the provider to "rackspace-cloudservers-uk"
    String provider = "rackspace-cloudservers-us";
    String username = args[0];
    String apiKey = args[1];
    // These properties control how often jclouds polls for a status udpate
    Properties overrides = new Properties();
    overrides.setProperty(ComputeServiceProperties.POLL_INITIAL_PERIOD, Constants.POLL_PERIOD_TWENTY_SECONDS);
    overrides.setProperty(ComputeServiceProperties.POLL_MAX_PERIOD, Constants.POLL_PERIOD_TWENTY_SECONDS);
    ComputeServiceContext context = ContextBuilder.newBuilder(provider).credentials(username, apiKey).overrides(overrides).buildView(ComputeServiceContext.class);
    compute = context.getComputeService();
}
Also used : ComputeServiceContext(org.jclouds.compute.ComputeServiceContext) Properties(java.util.Properties) ComputeServiceProperties(org.jclouds.compute.config.ComputeServiceProperties)

Aggregations

ComputeServiceContext (org.jclouds.compute.ComputeServiceContext)31 ComputeService (org.jclouds.compute.ComputeService)13 Module (com.google.inject.Module)9 Template (org.jclouds.compute.domain.Template)9 TemplateBuilder (org.jclouds.compute.domain.TemplateBuilder)9 Properties (java.util.Properties)8 SshjSshClientModule (org.jclouds.sshj.config.SshjSshClientModule)7 ClusterSpec (org.apache.whirr.ClusterSpec)6 NodeMetadata (org.jclouds.compute.domain.NodeMetadata)6 IOException (java.io.IOException)5 Set (java.util.Set)5 SLF4JLoggingModule (org.jclouds.logging.slf4j.config.SLF4JLoggingModule)5 ImmutableSet (com.google.common.collect.ImmutableSet)4 HashSet (java.util.HashSet)4 Stack (java.util.Stack)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 CompositeConfiguration (org.apache.commons.configuration.CompositeConfiguration)4 Configuration (org.apache.commons.configuration.Configuration)4 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)4 InstanceTemplate (org.apache.whirr.InstanceTemplate)4