protected void displayContainers(CreateContainerMetadata[] metadatas) { List<CreateContainerMetadata> success = new ArrayList<CreateContainerMetadata>(); List<CreateContainerMetadata> failures = new ArrayList<CreateContainerMetadata>(); for (CreateContainerMetadata metadata : metadatas) { (metadata.isSuccess() ? success : failures).add(metadata); } if (success.size() > 0) { System.out.println("The following containers have been created successfully:"); for (CreateContainerMetadata m : success) { System.out.println("\t" + m.toString()); } } if (failures.size() > 0) { System.out.println("The following containers have failed:"); for (CreateContainerMetadata m : failures) { System.out.println("\t" + m.getContainerName() + ": " + m.getFailure().getMessage()); } } }
protected void displayContainers(CreateContainerMetadata[] metadatas) { if (isEnsembleServer) { System.out.println(String.format(ENSEMBLE_SERVER_DISPLAY_FORMAT, ENSEMBLE_SERVER_OUTPUT_HEADERS)); } else { System.out.println(String.format(DISPLAY_FORMAT, OUTPUT_HEADERS)); } if (metadatas != null && metadatas.length > 0) { for (CreateContainerMetadata ccm : metadatas) { String status = "success"; if (ccm.getFailure() != null) { status = ccm.getFailure().getMessage(); } String containerName = ccm.getContainerName() != null ? ccm.getContainerName() : ""; String nodeId = ""; Set<String> publicAddresses = null; if (ccm instanceof CreateJCloudsContainerMetadata) { CreateJCloudsContainerMetadata metadata = (CreateJCloudsContainerMetadata) ccm; nodeId = metadata.getNodeId() != null ? metadata.getNodeId() : ""; publicAddresses = metadata.getPublicAddresses(); } if (isEnsembleServer) { System.out.println(String.format(ENSEMBLE_SERVER_DISPLAY_FORMAT, nodeId, containerName, ccm.getCreateOptions().getZookeeperPassword(), publicAddresses, status)); } else { System.out.println(String.format(DISPLAY_FORMAT, nodeId, containerName, publicAddresses, status)); } } } }
@Override public Set<Container> call() throws Exception { Set<Container> containers = new HashSet<Container>(); CreateContainerMetadata[] allMetadata = fabricService.createContainers(optionsBuilder.build()); if (allMetadata != null && allMetadata.length > 0) { for (CreateContainerMetadata metadata : allMetadata) { Container container = metadata.getContainer(); containers.add(container); if (!metadata.isSuccess()) { throw new FabricException("Failed to create container." , metadata.getFailure()); } } } return containers; } }
if (metadata.isSuccess()) { Container parent = containerOptions.getParent() != null ? getContainer(containerOptions.getParent()) : null; dataStore.get().createContainerConfig(metadata); ContainerImpl container = new ContainerImpl(parent, metadata.getContainerName(), FabricServiceImpl.this); metadata.setContainer(container); LOGGER.info("The container " + metadata.getContainerName() + " has been successfully created"); } else { LOGGER.warn("The creation of the container " + metadata.getContainerName() + " has failed", metadata.getFailure()); dataStore.get().deleteContainer(fabricService, containerOptions.getName());
if (isEnsembleServer && metadatas != null && metadatas.length > 0 && metadatas[0].isSuccess()) { ShellUtils.storeZookeeperPassword(session, metadatas[0].getCreateOptions().getZookeeperPassword());
assertValid(); try { CreateContainerOptions options = metadata.getCreateOptions(); String containerId = metadata.getContainerName(); Map<String, String> configuration = metadata.getContainerConfiguration(); for (Map.Entry<String, String> entry : configuration.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); setData(curator.get(), ZkPath.CONTAINER_ENTRY.getPath(metadata.getContainerName(), key), value); String resolver = metadata.getOverridenResolver() != null ? metadata.getOverridenResolver() : options.getResolver();
@Override public String containerCreateOptionsType(String id) { CreateContainerMetadata<?> metadata = getContainerMetaData(id); if (metadata == null) { return null; } CreateContainerOptions options = metadata.getCreateOptions(); if (options == null) { return null; } else { return options.getClass().getName(); } }
protected void rethrowAuthenticationErrors(CreateContainerMetadata[] metadata) { FabricAuthenticationException rethrow = null; for (CreateContainerMetadata md : metadata) { if (md.getFailure() instanceof FabricAuthenticationException) { rethrow = (FabricAuthenticationException) md.getFailure(); } else { return; } } if (rethrow != null) { throw rethrow; } }
return; CreateContainerOptions options = metadata.getCreateOptions(); if (options == null) { return; throw new RuntimeException("Failed to build CreatecontainerOptions when setting " + field + " on container " + containerId, e); metadata.setCreateOptions(newOptions);
@Override public void setContainerMetadata(CreateContainerMetadata metadata) { assertValid(); //We encode the metadata so that they are more friendly to import/export. try { setData(curator.get(), ZkPath.CONTAINER_METADATA.getPath(metadata.getContainerName()), Base64Encoder.encode(ObjectUtils.toBytes(metadata))); } catch (Exception e) { throw FabricException.launderThrowable(e); } }
if (isEnsembleServer && metadatas != null && metadatas.length > 0 && metadatas[0].isSuccess()) { ShellUtils.storeZookeeperPassword(session, metadatas[0].getCreateOptions().getZookeeperPassword()); if (session != null) {
@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; } }
protected void rethrowAuthenticationErrors(CreateContainerMetadata[] metadata) { FabricAuthenticationException rethrow = null; for (CreateContainerMetadata md : metadata) { if (md.getFailure() instanceof FabricAuthenticationException) { rethrow = (FabricAuthenticationException) md.getFailure(); } else { return; } } if (rethrow != null) { throw rethrow; } }
protected void displayContainers(CreateContainerMetadata[] metadatas) { List<CreateContainerMetadata> success = new ArrayList<CreateContainerMetadata>(); List<CreateContainerMetadata> failures = new ArrayList<CreateContainerMetadata>(); for (CreateContainerMetadata metadata : metadatas) { (metadata.isSuccess() ? success : failures).add(metadata); } if (success.size() > 0) { System.out.println("The following containers have been created successfully:"); for (CreateContainerMetadata m : success) { System.out.println("\t" + m.toString()); } } if (failures.size() > 0) { System.out.println("The following containers have failed:"); for (CreateContainerMetadata m : failures) { System.out.println("\t" + m.getContainerName() + ": " + m.getFailure().getMessage()); } } }
@Override public Set<Container> call() throws Exception { Set<Container> containers = new HashSet<Container>(); CreateContainerMetadata[] allMetadata = fabricService.createContainers(optionsBuilder.build()); if (allMetadata != null && allMetadata.length > 0) { for (CreateContainerMetadata metadata : allMetadata) { Container container = metadata.getContainer(); containers.add(container); if (!metadata.isSuccess()) { throw new FabricException("Failed to create container." , metadata.getFailure()); } } } return containers; } }
if (isEnsembleServer && metadatas != null && metadatas.length > 0 && metadatas[0].isSuccess()) { ShellUtils.storeZookeeperPassword(session, metadatas[0].getCreateOptions().getZookeeperPassword());
/** * 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; }
if (meta.getFailure() != null && meta.getFailure() instanceof FabricAuthenticationException) { throw (FabricAuthenticationException) meta.getFailure();
protected void displayContainers(CreateContainerMetadata[] metadatas) { List<CreateContainerMetadata> success = new ArrayList<CreateContainerMetadata>(); List<CreateContainerMetadata> failures = new ArrayList<CreateContainerMetadata>(); for (CreateContainerMetadata metadata : metadatas) { (metadata.isSuccess() ? success : failures).add(metadata); } if (success.size() > 0) { System.out.println("The following containers have been created successfully:"); for (CreateContainerMetadata m : success) { System.out.println("\t" + m.toString()); } } if (failures.size() > 0) { System.out.println("The following containers have failed:"); for (CreateContainerMetadata m : failures) { System.out.println("\t" + m.getContainerName() + ": " + m.getFailure().getMessage()); } } }
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; }