@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); } finally { if (session != null) { session.disconnect(); } } } }
@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); } } }