Search in sources :

Example 11 with CreateContainerMetadata

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();
            }
        }
    }
}
Also used : CreateContainerMetadata(io.fabric8.api.CreateContainerMetadata) FabricException(io.fabric8.api.FabricException) Session(com.jcraft.jsch.Session)

Example 12 with CreateContainerMetadata

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();
            }
        }
    }
}
Also used : CreateContainerMetadata(io.fabric8.api.CreateContainerMetadata) FabricException(io.fabric8.api.FabricException) Session(com.jcraft.jsch.Session)

Example 13 with CreateContainerMetadata

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();
            }
        }
    }
}
Also used : CreateContainerMetadata(io.fabric8.api.CreateContainerMetadata) FabricException(io.fabric8.api.FabricException) Session(com.jcraft.jsch.Session)

Example 14 with CreateContainerMetadata

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;
}
Also used : PrintStreamCreationStateListener(io.fabric8.internal.PrintStreamCreationStateListener) CreateContainerMetadata(io.fabric8.api.CreateContainerMetadata) CreateJCloudsContainerOptions(io.fabric8.service.jclouds.CreateJCloudsContainerOptions)

Example 15 with CreateContainerMetadata

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();
    }
}
Also used : Container(io.fabric8.api.Container) FabricService(io.fabric8.api.FabricService) CreateContainerMetadata(io.fabric8.api.CreateContainerMetadata) CreateContainerOptions(io.fabric8.api.CreateContainerOptions) Test(org.junit.Test)

Aggregations

CreateContainerMetadata (io.fabric8.api.CreateContainerMetadata)22 FabricException (io.fabric8.api.FabricException)10 CreateContainerOptions (io.fabric8.api.CreateContainerOptions)6 Container (io.fabric8.api.Container)5 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 ContainerProvider (io.fabric8.api.ContainerProvider)4 MalformedURLException (java.net.MalformedURLException)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Session (com.jcraft.jsch.Session)3 CreateContainerBasicOptions (io.fabric8.api.CreateContainerBasicOptions)3 FabricService (io.fabric8.api.FabricService)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 CreateChildContainerOptions (io.fabric8.api.CreateChildContainerOptions)2 Profile (io.fabric8.api.Profile)2 ToRunScriptOptions (io.fabric8.service.jclouds.functions.ToRunScriptOptions)2 InvalidClassException (java.io.InvalidClassException)2 URISyntaxException (java.net.URISyntaxException)2