metadata.setCreateOptions(options); metadata.setContainerName(containerName); String script = buildInstallAndStartScript(containerName, options); LOGGER.debug("Running script on host {}:\n{}", host, script); Session session = null; if (!srcFile.exists()) { try { zipDirectory(srcFile, System.getProperty("karaf.home", ".")); } catch (Exception e) { LOGGER.debug("Could not zip up current distro to use as base for new SSH container. Will try downloading via Maven instead.", e);
@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 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); runScriptOnHost(session, script); container.setProvisionResult(Container.PROVISION_STOPPED); } catch (Throwable t) { LOGGER.error("Failed to stop container: " + container.getId(), t); } finally { if (session != null) { session.disconnect(); } } } }
extractZipIntoDirectory(sb, options.getProxyUri(), "io.fabric8", "fabric8-karaf", FabricConstants.FABRIC_VERSION, fallbackRepositories); sb.append("run cd `").append(FIRST_FABRIC_DIRECTORY).append("`\n"); sb.append("run mkdir -p ").append(systemDistPath).append("\n"); appendFile(sb, "etc/system.properties", lines); replacePropertyValue(sb, "etc/system.properties", "karaf.name", name); String dataStoreFile = "etc/" + Constants.DATASTORE_PID + ".cfg"; for (Map.Entry<String, String> entry : options.getDataStoreProperties().entrySet()) { String key = entry.getKey(); String value = entry.getValue(); replacePropertyValue(sb, dataStoreFile, key, value); uncomment_line(sb, dataStoreFile, key); replacePropertyValue(sb, "etc/org.apache.karaf.shell.cfg", "sshPort" , "$SSH_PORT" ); replacePropertyValue(sb, "etc/org.apache.karaf.shell.cfg", "sshHost" , "$BIND_ADDRESS"); replacePropertyValue(sb, "etc/org.apache.karaf.management.cfg", "rmiRegistryPort", "$RMI_REGISTRY_PORT"); replacePropertyValue(sb, "etc/org.apache.karaf.management.cfg", "rmiServerPort", "$RMI_SERVER_PORT"); replacePropertyValue(sb, "etc/org.apache.karaf.management.cfg", "rmiServerHost" , "$BIND_ADDRESS"); replacePropertyValue(sb, "etc/org.apache.karaf.management.cfg", "rmiRegistryHost" , "$BIND_ADDRESS"); replacePropertyValue(sb, "etc/org.ops4j.pax.web.cfg", "org.osgi.service.http.port", "$HTTP_PORT"); replaceLineInFile(sb, "etc/jetty.xml", String.valueOf(DEFAULT_HTTP_PORT), "$HTTP_PORT"); appendFile(sb, "etc/system.properties", Arrays.asList(ZkDefs.MINIMUM_PORT + "=" + options.getMinimumPort())); appendFile(sb, "etc/system.properties", Arrays.asList(ZkDefs.MAXIMUM_PORT + "=" + options.getMaximumPort())); appendFile(sb, "etc/system.properties", Arrays.asList("\n")); Object type = syspropEntry.getKey(); Object value = syspropEntry.getValue();
String script = buildInstallAndStartScript(containerName, options); listener.onStateChange(String.format("Installing fabric agent on container %s. It may take a while...", containerName)); ExecResponse response = null; if (!srcFile.exists()) { try { zipDirectory(srcFile, System.getProperty("karaf.home", ".")); } catch (Exception e) { LOGGER.debug("Could not zip up current distro to use as base for new SSH container. Will try downloading via Maven instead.", e); jCloudsContainerMetadata.setFailure(new Exception(ContainerProviderUtils.parseScriptFailure(response.getOutput()))); String overridenResolverValue = ContainerProviderUtils.parseResolverOverride(response.getOutput()); if (overridenResolverValue != null) { jCloudsContainerMetadata.setOverridenResolver(overridenResolverValue);
@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); } } }
String nodeId = jCloudsContainerMetadata.getNodeId(); Optional<RunScriptOptions> runScriptOptions = ToRunScriptOptions.withComputeService(computeService).apply(jCloudsContainerMetadata); String script = buildStopScript(container.getId(), options); ExecResponse response; 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())));
@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; try { String script = buildUninstallScript(container.getId(), options); session = createSession(options); runScriptOnHost(session, script); } catch (Throwable t) { LOGGER.error("Failed to stop container: " + container.getId(), t); } finally { if (session != null) { session.disconnect(); } } } }