use of io.fabric8.api.CreateContainerMetadata in project fabric8 by jboss-fuse.
the class SshContainerProvider method start.
@Override
public void start(Container container) {
CreateContainerMetadata metadata = container.getMetadata();
if (!(metadata instanceof CreateSshContainerMetadata)) {
throw new IllegalStateException("Container doesn't have valid create container metadata type");
} else {
CreateSshContainerMetadata sshContainerMetadata = (CreateSshContainerMetadata) metadata;
CreateSshContainerOptions options = sshContainerMetadata.getCreateOptions();
Session session = null;
try {
String script = buildStartScript(container.getId(), options);
session = createSession(options);
runScriptOnHost(session, script);
} catch (Throwable t) {
LOGGER.error("Failed to start container: " + container.getId(), t);
throw new FabricException(t);
} finally {
if (session != null) {
session.disconnect();
}
}
}
}
use of io.fabric8.api.CreateContainerMetadata in project fabric8 by jboss-fuse.
the class SshContainerProvider method destroy.
@Override
public void destroy(Container container) {
CreateContainerMetadata metadata = container.getMetadata();
if (!(metadata instanceof CreateSshContainerMetadata)) {
throw new IllegalStateException("Container doesn't have valid create container metadata type");
} else {
CreateSshContainerMetadata sshContainerMetadata = (CreateSshContainerMetadata) metadata;
CreateSshContainerOptions options = sshContainerMetadata.getCreateOptions();
Session session = null;
String prevProvisionResult = container.getProvisionResult();
try {
String script = buildUninstallScript(container.getId(), options);
session = createSession(options);
container.setProvisionResult(Container.PROVISION_DELETING);
runScriptOnHost(session, script);
} catch (Throwable t) {
LOGGER.error("Failed to stop container: " + container.getId(), t);
throw new FabricException(t);
} finally {
if (session != null) {
session.disconnect();
}
}
}
}
use of io.fabric8.api.CreateContainerMetadata in project fabric8 by jboss-fuse.
the class SshContainerProvider method stop.
@Override
public void stop(Container container) {
CreateContainerMetadata metadata = container.getMetadata();
if (!(metadata instanceof CreateSshContainerMetadata)) {
throw new IllegalStateException("Container doesn't have valid create container metadata type");
} else {
CreateSshContainerMetadata sshContainerMetadata = (CreateSshContainerMetadata) metadata;
CreateSshContainerOptions options = sshContainerMetadata.getCreateOptions();
Session session = null;
try {
String script = buildStopScript(container.getId(), options);
session = createSession(options);
container.setProvisionResult(Container.PROVISION_STOPPING);
runScriptOnHost(session, script);
container.setProvisionResult(Container.PROVISION_STOPPED);
} catch (Throwable t) {
LOGGER.error("Failed to stop container: " + container.getId(), t);
throw new FabricException(t);
} finally {
if (session != null) {
session.disconnect();
}
}
}
}
use of io.fabric8.api.CreateContainerMetadata in project fabric8 by jboss-fuse.
the class ContainerCreateCloud method doExecute.
@Override
protected Object doExecute() throws Exception {
// validate input before creating containers
preCreateContainer(name);
FabricValidations.validateProfileNames(profiles);
if (isEnsembleServer && newUserPassword == null) {
newUserPassword = zookeeperPassword != null ? zookeeperPassword : fabricService.getZookeeperPassword();
}
CreateJCloudsContainerOptions.Builder builder = CreateJCloudsContainerOptions.builder().name(name).bindAddress(bindAddress).resolver(resolver).manualIp(manualIp).ensembleServer(isEnsembleServer).credential(credential).group(group).hardwareId(hardwareId).identity(identity).osFamily(osFamily).osVersion(osVersion).imageId(imageId).instanceType(instanceType).locationId(locationId).number(number).nodeOptions(CloudUtils.parseProviderOptions(options)).owner(owner).adminAccess(!disableAdminAccess).publicKeyFile(publicKeyFile).contextName(contextName).providerName(providerName).apiName(apiName).user(user).password(password).proxyUri(proxyUri != null ? proxyUri : fabricService.getMavenRepoURI()).zookeeperUrl(fabricService.getZookeeperUrl()).zookeeperPassword(isEnsembleServer && zookeeperPassword != null ? zookeeperPassword : fabricService.getZookeeperPassword()).jvmOpts(jvmOpts).environmentalVariable(environmentalVariables).version(version).withUser(newUser, newUserPassword, newUserRole).profiles(getProfileNames()).dataStoreProperties(getDataStoreProperties()).uploadDistribution(!distributionUploadDisable);
if (path != null && !path.isEmpty()) {
builder.path(path);
}
CreateContainerMetadata[] metadatas = fabricService.createContainers(builder.build(), new PrintStreamCreationStateListener(System.out));
if (isEnsembleServer && metadatas != null && metadatas.length > 0 && metadatas[0].isSuccess()) {
ShellUtils.storeZookeeperPassword(session, metadatas[0].getCreateOptions().getZookeeperPassword());
}
// display containers
displayContainers(metadatas);
return null;
}
use of io.fabric8.api.CreateContainerMetadata in project fabric8 by jboss-fuse.
the class CreateSshContainerTest method testSshContainerProvider.
@Test
public void testSshContainerProvider() throws Throwable {
Assume.assumeTrue(isReady());
System.out.println(executeCommand("fabric:create -n --wait-for-provisioning"));
// System.out.println(executeCommand("shell:info"));
// System.out.println(executeCommand("fabric:info"));
// System.out.println(executeCommand("fabric:profile-list"));
ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(bundleContext, FabricService.class);
try {
FabricService fabricService = fabricProxy.getService();
CreateContainerOptions options = CreateSshContainerOptions.builder().name("ssh1").host(host).port(Integer.parseInt(port)).username(username).password(password).build();
CreateContainerMetadata[] metadata = fabricService.createContainers(options);
assertNotNull(metadata);
assertEquals(1, metadata.length);
if (metadata[0].getFailure() != null) {
throw metadata[0].getFailure();
}
assertTrue("Expected successful creation of remote ssh container", metadata[0].isSuccess());
assertNotNull("Expected successful creation of remote ssh container", metadata[0].getContainer());
Provision.containersStatus(Arrays.asList(metadata[0].getContainer()), "success", PROVISION_TIMEOUT);
System.out.println(executeCommand("fabric:container-list -v"));
System.out.println(executeCommand("fabric:container-resolver-list"));
Container ssh1 = fabricService.getContainer("ssh1");
assertTrue(ssh1.isAlive());
createAndAssertChildContainer(fabricService, "ssh2", "ssh1", "default");
// Stop & Start Remote Child
Container ssh2 = fabricService.getContainer("ssh2");
ssh2.stop();
assertFalse(ssh2.isAlive());
ssh2.start();
Provision.containersStatus(Arrays.asList(ssh2), "success", PROVISION_TIMEOUT);
assertTrue(ssh2.isAlive());
ssh2.stop();
// Try stopping and starting the remote container.
ssh1.stop();
assertFalse(ssh1.isAlive());
System.out.println(executeCommand("fabric:container-list -v"));
ssh1.start();
Provision.containersStatus(Arrays.asList(ssh1), "success", PROVISION_TIMEOUT);
System.out.println(executeCommand("fabric:container-list -v"));
assertTrue(ssh1.isAlive());
} finally {
fabricProxy.close();
}
}
Aggregations