protected static CreateDockerContainerMetadata getContainerMetadata(Container container) { CreateContainerMetadata<?> value = container.getMetadata(); if (value instanceof CreateDockerContainerMetadata) { return (CreateDockerContainerMetadata)value; } else { return null; } }
protected static CreateOpenshiftContainerMetadata getContainerMetadata(Container container) { CreateContainerMetadata<?> value = container.getMetadata(); if (value instanceof CreateOpenshiftContainerMetadata) { return (CreateOpenshiftContainerMetadata)value; } else { return null; } }
private CreateContainerMetadata<?> getContainerMetaData(String id) { Container container = fabricService.getContainer(id); return container.getMetadata(); }
void applyUpdatedCredentials(Container container) { if (user != null || password != null) { CreateContainerMetadata<?> metadata = container.getMetadata(); if (metadata != null) { metadata.updateCredentials(user, password); dataStore.setContainerMetadata(container.getMetadata()); } } }
@Override public boolean apply(Container container) { if (container != null && container.getMetadata() != null && container.getMetadata().getCreateOptions() != null && container.getMetadata().getCreateOptions().getProviderType().equals("jclouds")) { return true; } else return false; } }
private CreateJCloudsContainerMetadata getContainerCloudMetadata(String name) { if (!Strings.isNullOrEmpty(targetContainerName) && getCurator().getZookeeperClient().isConnected() && fabricService != null) { Container targetContainer = fabricService.getContainer(targetContainerName); if (targetContainer != null && targetContainer.getMetadata() != null) { CreateContainerMetadata metadata = targetContainer.getMetadata(); if (CreateJCloudsContainerMetadata.class.isAssignableFrom(metadata.getClass())) { return (CreateJCloudsContainerMetadata) metadata; } } } return null; }
/** * Returns true if the given container is a java or process child container */ public static boolean isJavaOrProcessContainer(FabricService fabric, Container container) { if (container != null) { CreateContainerMetadata<?> metadata = container.getMetadata(); if (metadata != null) { CreateContainerOptions createOptions = metadata.getCreateOptions(); if (createOptions instanceof CreateContainerBasicOptions) { return isJavaOrProcessContainer(fabric, (CreateContainerBasicOptions) createOptions); } } } return false; }
private ContainerProvider getProvider(Container container, boolean returnNull) { CreateContainerMetadata metadata = container.getMetadata(); String type = metadata != null ? metadata.getCreateOptions().getProviderType() : null; if (type == null) { if (returnNull) { return null; } throw new UnsupportedOperationException("Container " + container.getId() + " has not been created using Fabric"); } ContainerProvider provider = getProvider(type); if (provider == null) { if (returnNull) { return null; } throw new UnsupportedOperationException("Container provider " + type + " not supported"); } return provider; }
@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 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(); } } } }
@Override public void destroy(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(); String nodeId = jCloudsContainerMetadata.getNodeId(); ComputeService computeService = getOrCreateComputeService(options); computeService.destroyNode(nodeId); } }
CreateContainerMetadata<?> metadata = containerInstance.getMetadata(); if(metadata == null){
@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(); } } } }
@Override /** * Returns configured jvmOpts only for (local and remote) Karaf containers. */ public String getJvmOpts(String containerName) { String result = ""; Container container = fabricService.getContainer(containerName); CreateContainerBasicMetadata metadata = (CreateContainerBasicMetadata) container.getMetadata(); if(metadata == null){ return "Inapplicable"; } switch( metadata.getCreateOptions().getProviderType()){ case "child": case "ssh": CreateContainerOptions createOptions = metadata.getCreateOptions(); result = createOptions.getJvmOpts(); break; default: result = "Inapplicable"; } return result; }
@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); } } }
@Override public void stop(Container container) { assertValid(); CreateContainerMetadata metadata = container.getMetadata(); if (!(metadata instanceof CreateJCloudsContainerMetadata)) { throw new IllegalStateException("Container doesn't have valid create container metadata type");
/** * Returns the {@link ContainerTemplate} of the parent of the specified child {@link Container}. */ private ContainerTemplate getContainerTemplateForChild(Container container) { CreateChildContainerOptions options = (CreateChildContainerOptions) container.getMetadata().getCreateOptions(); String username = AuthenticationUtils.retrieveJaasUser(); String password = AuthenticationUtils.retrieveJaasPassword(); if (username != null && password != null) { options = (CreateChildContainerOptions) options.updateCredentials(username, password); } return new ContainerTemplate(container.getParent(), options.getJmxUser(), options.getJmxPassword(), false); }