Search in sources :

Example 11 with FabricException

use of io.fabric8.api.FabricException in project fabric8 by jboss-fuse.

the class ContainerLifecycleCommandsTest method testStopSomeMatchingContainers.

@Test
public void testStopSomeMatchingContainers() throws Exception {
    containers("c1", "c2");
    ContainerImpl c1 = newContainer("c1");
    expect(this.fabricService.adapt(CuratorFramework.class)).andReturn(this.curatorFramework);
    expect(this.fabricService.getContainers()).andReturn(new Container[] { c1 }).once();
    this.fabricService.stopContainer(c1, false);
    expect(this.fabricService.adapt(CuratorFramework.class)).andReturn(this.curatorFramework);
    expect(this.fabricService.getContainers()).andReturn(new Container[] { c1 }).once();
    replay(this.fabricService, this.commandSession);
    try {
        this.stop.execute(this.commandSession);
        fail("Should throw FabricException");
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage().contains(" c2 "), is(true));
    }
    verify(this.fabricService);
}
Also used : Container(io.fabric8.api.Container) ContainerImpl(io.fabric8.internal.ContainerImpl) Test(org.junit.Test)

Example 12 with FabricException

use of io.fabric8.api.FabricException 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 13 with FabricException

use of io.fabric8.api.FabricException 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 14 with FabricException

use of io.fabric8.api.FabricException in project fabric8 by jboss-fuse.

the class SshContainerProvider method create.

/**
 * Creates an {@link io.fabric8.api.Container} with the given name pointing to the specified zooKeeperUrl.
 */
public CreateSshContainerMetadata create(CreateSshContainerOptions options, CreationStateListener listener) {
    try {
        String path = options.getPath();
        String host = options.getHost();
        String ip = InetAddress.getByName(host).getHostAddress();
        if (host == null) {
            throw new IllegalArgumentException("Host name not specified.");
        }
        int port = options.getPort();
        if (port == -1) {
            port = 22;
        }
        String containerName = options.getName();
        CreateSshContainerMetadata metadata = new CreateSshContainerMetadata();
        metadata.setCreateOptions(options);
        metadata.setContainerName(containerName);
        String script = buildInstallAndStartScript(containerName, options);
        LOGGER.debug("Running script on host {}:\n{}", host, script);
        Session session = null;
        try {
            session = createSession(options);
            if (options.doUploadDistribution()) {
                uploadTo(session, options.getProxyUri().resolve("io/fabric8/fabric8-karaf/" + FabricConstants.FABRIC_VERSION + "/fabric8-karaf-" + FabricConstants.FABRIC_VERSION + ".zip").toURL(), "/tmp/fabric8-karaf-" + FabricConstants.FABRIC_VERSION + ".zip");
            }
            runScriptOnHost(session, script);
        } catch (Throwable ex) {
            metadata.setFailure(ex);
            throw new FabricException(ex);
        } finally {
            if (session != null) {
                session.disconnect();
            }
        }
        return metadata;
    } catch (Exception e) {
        throw FabricException.launderThrowable(e);
    }
}
Also used : FabricException(io.fabric8.api.FabricException) FabricException(io.fabric8.api.FabricException) IOException(java.io.IOException) Session(com.jcraft.jsch.Session)

Example 15 with FabricException

use of io.fabric8.api.FabricException 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)

Aggregations

FabricException (io.fabric8.api.FabricException)29 IOException (java.io.IOException)10 Container (io.fabric8.api.Container)7 CreateContainerMetadata (io.fabric8.api.CreateContainerMetadata)6 Lease (org.apache.curator.framework.recipes.locks.Lease)6 HashSet (java.util.HashSet)5 EncryptionOperationNotPossibleException (org.jasypt.exceptions.EncryptionOperationNotPossibleException)5 Session (com.jcraft.jsch.Session)4 FabricService (io.fabric8.api.FabricService)3 Profile (io.fabric8.api.Profile)3 ProfileDependencyException (io.fabric8.api.ProfileDependencyException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 SortedMap (java.util.SortedMap)3 TreeMap (java.util.TreeMap)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ContainerProvider (io.fabric8.api.ContainerProvider)2 ProfileBuilder (io.fabric8.api.ProfileBuilder)2