use of io.fabric8.api.CreateContainerMetadata in project fabric8 by jboss-fuse.
the class FabricManager method changeCreateOptionsField.
@Override
public void changeCreateOptionsField(String containerId, String field, Object value) {
CreateContainerMetadata<? extends CreateContainerOptions> metadata = getContainerMetaData(containerId);
if (metadata == null) {
return;
}
CreateContainerOptions options = metadata.getCreateOptions();
if (options == null) {
return;
}
ObjectMapper mapper = getObjectMapper();
JsonNode optionsJson = mapper.convertValue(options, JsonNode.class);
JsonNode valueJson = mapper.convertValue(value, JsonNode.class);
((ObjectNode) optionsJson).put(field, valueJson);
Object builder = null;
try {
builder = options.getClass().getMethod("builder").invoke(null);
} catch (Exception e) {
LOG.warn("Failed to get builder when setting " + field + " on container " + containerId, e);
throw new RuntimeException("Failed to get builder when setting " + field + " on container " + containerId, e);
}
builder = mapper.convertValue(optionsJson, builder.getClass());
CreateContainerOptions newOptions = null;
try {
newOptions = (CreateContainerOptions) builder.getClass().getMethod("build").invoke(builder);
} catch (Exception e) {
LOG.warn("Failed to build CreatecontainerOptions when setting " + field + " on container " + containerId, e);
throw new RuntimeException("Failed to build CreatecontainerOptions when setting " + field + " on container " + containerId, e);
}
metadata.setCreateOptions(newOptions);
if (LOG.isDebugEnabled()) {
LOG.debug("Create container metadata: " + metadata);
}
fabricService.adapt(DataStore.class).setContainerMetadata(metadata);
}
use of io.fabric8.api.CreateContainerMetadata 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.api.CreateContainerMetadata 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));
}
}
}
}
use of io.fabric8.api.CreateContainerMetadata in project fabric8 by jboss-fuse.
the class CreateContainerTask method call.
@Override
public Set<ContainerProxy> call() throws Exception {
Set<ContainerProxy> containers = new HashSet<ContainerProxy>();
FabricService fabricService = fabricServiceProxy.getService();
CreateContainerMetadata[] allMetadata = fabricService.createContainers(options);
if (allMetadata != null && allMetadata.length > 0) {
for (CreateContainerMetadata metadata : allMetadata) {
Container container = metadata.getContainer();
containers.add(ContainerProxy.wrap(container, fabricServiceProxy));
if (!metadata.isSuccess()) {
throw new FabricException("Failed to create container.", metadata.getFailure());
}
}
}
return containers;
}
use of io.fabric8.api.CreateContainerMetadata in project fabric8 by jboss-fuse.
the class FabricTestSupport method createChildContainer.
private Container createChildContainer(FabricService fabricService, String name, String parent, String profileName, String jvmOpts) throws Exception {
Thread.sleep(DEFAULT_WAIT);
Container parentContainer = fabricService.getContainer(parent);
Assert.assertNotNull(parentContainer);
CreateChildContainerOptions.Builder builder = CreateChildContainerOptions.builder().name(name).parent(parent).zookeeperPassword(fabricService.getZookeeperPassword()).jmxUser("admin").jmxPassword("admin");
if (jvmOpts != null) {
builder.jvmOpts(jvmOpts);
} else {
builder.jvmOpts("-Xms512m -Xmx1024m -Djava.net.preferIPv4Stack=true -Dpatching.disabled=true -Djava.security.egd=file:/dev/./urandom");
}
CreateContainerMetadata[] metadata = fabricService.createContainers(builder.build());
if (metadata.length > 0) {
if (metadata[0].getFailure() != null) {
throw new Exception("Error creating child container:" + name, metadata[0].getFailure());
}
Container container = metadata[0].getContainer();
Version version = fabricService.getRequiredDefaultVersion();
Profile profile = version.getRequiredProfile(profileName);
Assert.assertNotNull("Expected to find profile with name:" + profileName, profile);
container.setProfiles(new Profile[] { profile });
Provision.containersStatus(Arrays.asList(container), "success", PROVISION_TIMEOUT);
return container;
}
throw new Exception("Could container not created");
}
Aggregations