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);
}
}
}
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;
}
}
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();
}
}
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));
}
}
}
}
Aggregations