use of io.fabric8.service.jclouds.CreateJCloudsContainerOptions in project fabric8 by jboss-fuse.
the class JcloudsContainerProvider method destroy.
@Override
public void destroy(Container container) {
assertValid();
CreateContainerMetadata metadata = container.getMetadata();
if (!(metadata instanceof CreateJCloudsContainerMetadata)) {
throw new IllegalStateException("Container doesn't have valid create container metadata type");
} else {
container.setProvisionResult(Container.PROVISION_DELETING);
CreateJCloudsContainerMetadata jCloudsContainerMetadata = (CreateJCloudsContainerMetadata) metadata;
CreateJCloudsContainerOptions options = jCloudsContainerMetadata.getCreateOptions();
String nodeId = jCloudsContainerMetadata.getNodeId();
ComputeService computeService = getOrCreateComputeService(options);
computeService.destroyNode(nodeId);
}
}
use of io.fabric8.service.jclouds.CreateJCloudsContainerOptions in project fabric8 by jboss-fuse.
the class JcloudsContainerProvider method stop.
@Override
public void stop(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();
try {
ComputeService computeService = getOrCreateComputeService(options);
String nodeId = jCloudsContainerMetadata.getNodeId();
Optional<RunScriptOptions> runScriptOptions = ToRunScriptOptions.withComputeService(computeService).apply(jCloudsContainerMetadata);
String script = buildStopScript(container.getId(), options);
ExecResponse response;
container.setProvisionResult(Container.PROVISION_STOPPING);
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) {
container.setProvisionResult(Container.PROVISION_STOPPED);
jCloudsContainerMetadata.setFailure(t);
}
}
}
use of io.fabric8.service.jclouds.CreateJCloudsContainerOptions in project fabric8 by jboss-fuse.
the class JcloudsContainerProvider method create.
@Override
public CreateJCloudsContainerMetadata create(CreateJCloudsContainerOptions input, CreationStateListener listener) throws MalformedURLException, RunNodesException, URISyntaxException, InterruptedException {
assertValid();
CreateJCloudsContainerOptions options = input.updateComputeService(getOrCreateComputeService(input));
listener.onStateChange("Looking up for compute service.");
ComputeService computeService = getOrCreateComputeService(options);
if (computeService == null) {
throw new IllegalStateException("Compute service could not be found or created.");
}
Template template = ToTemplate.apply(options);
listener.onStateChange(String.format(OVERVIEW_FORMAT, 1, options.getContextName()));
try {
Set<? extends NodeMetadata> metadata = computeService.createNodesInGroup(options.getGroup(), 1, template);
if (metadata == null || metadata.size() != 1) {
throw new IllegalStateException("JClouds created " + metadata.size() + " containers instead of 1");
}
NodeMetadata nodeMetadata = metadata.iterator().next();
switch(nodeMetadata.getStatus()) {
case RUNNING:
listener.onStateChange(String.format(NODE_CREATED_FORMAT, nodeMetadata.getName()));
break;
default:
listener.onStateChange(String.format(NODE_ERROR_FORMAT, nodeMetadata.getStatus()));
}
CloudContainerInstallationTask installationTask = new CloudContainerInstallationTask(options.getName(), nodeMetadata, options, computeService, firewallManagerFactory.get(), template.getOptions(), listener);
return installationTask.install();
} catch (Throwable ex) {
CreateJCloudsContainerMetadata failureMetadata = new CreateJCloudsContainerMetadata();
failureMetadata.setCreateOptions(options);
failureMetadata.setFailure(ex);
return failureMetadata;
}
}
use of io.fabric8.service.jclouds.CreateJCloudsContainerOptions 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);
}
}
}
use of io.fabric8.service.jclouds.CreateJCloudsContainerOptions 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;
}
}
Aggregations