Search in sources :

Example 31 with ComputeService

use of org.jclouds.compute.ComputeService in project fabric8 by jboss-fuse.

the class CloudFirewallEdit method findTargetComputeService.

/**
 * Finds the {@link ComputeService} to use based on the provider option or the target {@link Container} metadata.
 * @return
 */
private ComputeService findTargetComputeService() {
    if (!Strings.isNullOrEmpty(targetContainerName) && getCurator().getZookeeperClient().isConnected()) {
        CreateJCloudsContainerMetadata metadata = getContainerCloudMetadata(targetContainerName);
        if (metadata != null) {
            CreateJCloudsContainerOptions options = metadata.getCreateOptions();
            contextName = options.getContextName();
        }
    }
    if (!Strings.isNullOrEmpty(contextName)) {
        for (ComputeService computeService : computeServices) {
            if (computeService.getContext().unwrap().getName().equals(contextName)) {
                return computeService;
            }
        }
    }
    if (computeServices == null || computeServices.size() == 0) {
        System.out.println("No compute services are available.");
        return null;
    } else if (computeServices != null && computeServices.size() == 0) {
        return computeServices.get(0);
    } else {
        System.out.println("Multiple cloud provider service available. Please select one using the --provider option.");
        return null;
    }
}
Also used : CreateJCloudsContainerMetadata(io.fabric8.service.jclouds.CreateJCloudsContainerMetadata) CreateJCloudsContainerOptions(io.fabric8.service.jclouds.CreateJCloudsContainerOptions) ComputeService(org.jclouds.compute.ComputeService)

Example 32 with ComputeService

use of org.jclouds.compute.ComputeService in project fabric8 by jboss-fuse.

the class ToTemplate method apply.

public static Template apply(CreateJCloudsContainerOptions options) {
    ComputeService service = options.getComputeService();
    TemplateOptions templateOptions = service.templateOptions();
    TemplateBuilder builder = service.templateBuilder().any();
    applyInstanceType(builder, options);
    applyImageType(builder, options);
    applyLocation(builder, options);
    applyProviderSpecificOptions(templateOptions, options);
    Optional<AdminAccess> adminAccess = ToAdminAccess.apply(options);
    if (adminAccess.isPresent()) {
        templateOptions.runScript(adminAccess.get());
    }
    builder = builder.options(templateOptions);
    return builder.build();
}
Also used : TemplateBuilder(org.jclouds.compute.domain.TemplateBuilder) AdminAccess(org.jclouds.scriptbuilder.statements.login.AdminAccess) TemplateOptions(org.jclouds.compute.options.TemplateOptions) ComputeService(org.jclouds.compute.ComputeService)

Example 33 with ComputeService

use of org.jclouds.compute.ComputeService in project fabric8 by jboss-fuse.

the class CloudUtils method waitForComputeService.

/**
 * Returns the compute service when it becomes registered to the OSGi service registry.
 *
 * @param name
 * @return
 */
public static synchronized ComputeService waitForComputeService(BundleContext bundleContext, String name) {
    ComputeService computeService = null;
    try {
        for (int r = 0; r < 6; r++) {
            ServiceReference[] references = bundleContext.getAllServiceReferences(ComputeService.class.getName(), "(" + Constants.NAME + "=" + name + ")");
            if (references != null && references.length > 0) {
                computeService = (ComputeService) bundleContext.getService(references[0]);
                return computeService;
            }
            Thread.sleep(10000L);
        }
    } catch (Exception e) {
        LOGGER.error("Error while waiting for service.", e);
    }
    return computeService;
}
Also used : ComputeService(org.jclouds.compute.ComputeService) IOException(java.io.IOException) ServiceReference(org.osgi.framework.ServiceReference)

Example 34 with ComputeService

use of org.jclouds.compute.ComputeService in project fabric8 by jboss-fuse.

the class ComputeRegistryImpl method list.

@Override
public List<ComputeService> list() {
    assertValid();
    List<ComputeService> list = new ArrayList<ComputeService>();
    for (Map.Entry<String, DynamicReference<ComputeService>> entry : computeServices.entrySet()) {
        ComputeService computeService = entry.getValue().getIfPresent();
        if (computeService != null) {
            list.add(computeService);
        }
    }
    return list;
}
Also used : DynamicReference(io.fabric8.api.DynamicReference) ArrayList(java.util.ArrayList) ComputeService(org.jclouds.compute.ComputeService) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

Example 35 with ComputeService

use of org.jclouds.compute.ComputeService 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)

Aggregations

ComputeService (org.jclouds.compute.ComputeService)44 ComputeServiceContext (org.jclouds.compute.ComputeServiceContext)13 NodeMetadata (org.jclouds.compute.domain.NodeMetadata)13 Template (org.jclouds.compute.domain.Template)13 TemplateBuilder (org.jclouds.compute.domain.TemplateBuilder)13 ResourceContainerCloud (org.palladiosimulator.pcm.cloud.pcmcloud.resourceenvironmentcloud.ResourceContainerCloud)10 ResourceContainer (org.palladiosimulator.pcm.resourceenvironment.ResourceContainer)10 RunNodesException (org.jclouds.compute.RunNodesException)8 IOException (java.io.IOException)7 ClusterSpec (org.apache.whirr.ClusterSpec)7 TemplateOptions (org.jclouds.compute.options.TemplateOptions)7 Set (java.util.Set)6 Test (org.junit.Test)6 ClusterActionHandler (org.apache.whirr.service.ClusterActionHandler)5 Statement (org.jclouds.scriptbuilder.domain.Statement)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