Search in sources :

Example 6 with CreateJCloudsContainerMetadata

use of io.fabric8.service.jclouds.CreateJCloudsContainerMetadata in project fabric8 by jboss-fuse.

the class JcloudsContainerProvider method start.

@Override
public void start(Container container) {
    assertValid();
    CreateContainerMetadata metadata = container.getMetadata();
    if (!(metadata instanceof CreateJCloudsContainerMetadata)) {
        throw new IllegalStateException("Container doesn't have valid create container metadata type");
    } else {
        CreateJCloudsContainerMetadata jCloudsContainerMetadata = (CreateJCloudsContainerMetadata) metadata;
        CreateJCloudsContainerOptions options = jCloudsContainerMetadata.getCreateOptions();
        ComputeService computeService = getOrCreateComputeService(options);
        try {
            String nodeId = jCloudsContainerMetadata.getNodeId();
            Optional<RunScriptOptions> runScriptOptions = ToRunScriptOptions.withComputeService(computeService).apply(jCloudsContainerMetadata);
            String script = buildStartScript(container.getId(), options);
            ExecResponse response;
            if (runScriptOptions.isPresent()) {
                response = computeService.runScriptOnNode(nodeId, script, runScriptOptions.get());
            } else {
                response = computeService.runScriptOnNode(nodeId, script);
            }
            if (response == null) {
                jCloudsContainerMetadata.setFailure(new Exception("No response received for fabric install script."));
            } else if (response.getOutput() != null && response.getOutput().contains(ContainerProviderUtils.FAILURE_PREFIX)) {
                jCloudsContainerMetadata.setFailure(new Exception(ContainerProviderUtils.parseScriptFailure(response.getOutput())));
            }
        } catch (Throwable t) {
            jCloudsContainerMetadata.setFailure(t);
        }
    }
}
Also used : RunScriptOptions(org.jclouds.compute.options.RunScriptOptions) ToRunScriptOptions(io.fabric8.service.jclouds.functions.ToRunScriptOptions) ExecResponse(org.jclouds.compute.domain.ExecResponse) CreateContainerMetadata(io.fabric8.api.CreateContainerMetadata) ComputeService(org.jclouds.compute.ComputeService) URISyntaxException(java.net.URISyntaxException) RunNodesException(org.jclouds.compute.RunNodesException) MalformedURLException(java.net.MalformedURLException)

Example 7 with CreateJCloudsContainerMetadata

use of io.fabric8.service.jclouds.CreateJCloudsContainerMetadata 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 8 with CreateJCloudsContainerMetadata

use of io.fabric8.service.jclouds.CreateJCloudsContainerMetadata in project fabric8 by jboss-fuse.

the class ToRunScriptOptions method apply.

public Optional<RunScriptOptions> apply(CreateJCloudsContainerMetadata containerMetadata) {
    CreateJCloudsContainerOptions options = containerMetadata.getCreateOptions();
    NodeMetadata nodeMetadata = computeService.getNodeMetadata(containerMetadata.getNodeId());
    LoginCredentials credentials = nodeMetadata.getCredentials();
    LoginCredentials.Builder loginBuilder;
    if (options.getUser() != null) {
        if (credentials == null) {
            loginBuilder = LoginCredentials.builder();
        } else {
            loginBuilder = credentials.toBuilder();
        }
        if (options.getPassword() != null) {
            credentials = loginBuilder.user(options.getUser()).password(options.getPassword()).build();
        } else {
            credentials = loginBuilder.user(options.getUser()).build();
        }
    }
    if (credentials != null) {
        return Optional.of(RunScriptOptions.Builder.overrideLoginCredentials(credentials).runAsRoot(false));
    } else {
        return Optional.absent();
    }
}
Also used : NodeMetadata(org.jclouds.compute.domain.NodeMetadata) LoginCredentials(org.jclouds.domain.LoginCredentials) CreateJCloudsContainerOptions(io.fabric8.service.jclouds.CreateJCloudsContainerOptions)

Example 9 with CreateJCloudsContainerMetadata

use of io.fabric8.service.jclouds.CreateJCloudsContainerMetadata in project fabric8 by jboss-fuse.

the class ContainerCreateCloud method displayContainers.

protected void displayContainers(CreateContainerMetadata[] metadatas) {
    if (isEnsembleServer) {
        System.out.println(String.format(ENSEMBLE_SERVER_DISPLAY_FORMAT, ENSEMBLE_SERVER_OUTPUT_HEADERS));
    } else {
        System.out.println(String.format(DISPLAY_FORMAT, OUTPUT_HEADERS));
    }
    if (metadatas != null && metadatas.length > 0) {
        for (CreateContainerMetadata ccm : metadatas) {
            String status = "success";
            if (ccm.getFailure() != null) {
                status = ccm.getFailure().getMessage();
            }
            String containerName = ccm.getContainerName() != null ? ccm.getContainerName() : "";
            String nodeId = "";
            Set<String> publicAddresses = null;
            if (ccm instanceof CreateJCloudsContainerMetadata) {
                CreateJCloudsContainerMetadata metadata = (CreateJCloudsContainerMetadata) ccm;
                nodeId = metadata.getNodeId() != null ? metadata.getNodeId() : "";
                publicAddresses = metadata.getPublicAddresses();
            }
            if (isEnsembleServer) {
                System.out.println(String.format(ENSEMBLE_SERVER_DISPLAY_FORMAT, nodeId, containerName, ccm.getCreateOptions().getZookeeperPassword(), publicAddresses, status));
            } else {
                System.out.println(String.format(DISPLAY_FORMAT, nodeId, containerName, publicAddresses, status));
            }
        }
    }
}
Also used : CreateJCloudsContainerMetadata(io.fabric8.service.jclouds.CreateJCloudsContainerMetadata) CreateContainerMetadata(io.fabric8.api.CreateContainerMetadata)

Aggregations

ComputeService (org.jclouds.compute.ComputeService)6 CreateContainerMetadata (io.fabric8.api.CreateContainerMetadata)4 CreateJCloudsContainerMetadata (io.fabric8.service.jclouds.CreateJCloudsContainerMetadata)3 ExecResponse (org.jclouds.compute.domain.ExecResponse)3 NodeMetadata (org.jclouds.compute.domain.NodeMetadata)3 CreateJCloudsContainerOptions (io.fabric8.service.jclouds.CreateJCloudsContainerOptions)2 FirewallManager (io.fabric8.service.jclouds.firewall.FirewallManager)2 Rule (io.fabric8.service.jclouds.firewall.Rule)2 ToRunScriptOptions (io.fabric8.service.jclouds.functions.ToRunScriptOptions)2 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2 RunNodesException (org.jclouds.compute.RunNodesException)2 RunScriptOptions (org.jclouds.compute.options.RunScriptOptions)2 LoginCredentials (org.jclouds.domain.LoginCredentials)2 FirewallNotSupportedOnProviderException (io.fabric8.service.jclouds.firewall.FirewallNotSupportedOnProviderException)1 ToTemplate (io.fabric8.service.jclouds.functions.ToTemplate)1 IOException (java.io.IOException)1 URL (java.net.URL)1 HashSet (java.util.HashSet)1 Properties (java.util.Properties)1