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