use of io.fabric8.api.CreateContainerMetadata in project fabric8 by jboss-fuse.
the class ContainerCreateOpenshiftAction method displayContainers.
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());
}
}
}
use of io.fabric8.api.CreateContainerMetadata in project fabric8 by jboss-fuse.
the class MQCreateAction method doExecute.
@Override
protected Object doExecute() throws Exception {
MQBrokerConfigDTO dto = createDTO();
Profile profile = MQManager.createOrUpdateProfile(dto, fabricService, runtimeProperties);
if (profile == null) {
return null;
}
String profileId = profile.getId();
System.out.println("MQ profile " + profileId + " ready");
// assign profile to existing containers
if (assign != null) {
String[] assignContainers = assign.split(",");
MQManager.assignProfileToContainers(fabricService, profile, assignContainers);
}
// create containers
if (create != null) {
String[] createContainers = create.split(",");
List<CreateContainerBasicOptions.Builder> builderList = MQManager.createContainerBuilders(dto, fabricService, "child", profileId, dto.version(), createContainers);
for (CreateContainerBasicOptions.Builder builder : builderList) {
CreateContainerMetadata[] metadatas;
try {
if (builder instanceof CreateChildContainerOptions.Builder) {
CreateChildContainerOptions.Builder childBuilder = (CreateChildContainerOptions.Builder) builder;
builder = childBuilder.jmxUser(username).jmxPassword(password);
}
metadatas = fabricService.createContainers(builder.build());
// check if there was a FabricAuthenticationException as failure then we can try again
if (metadatas != null) {
for (CreateContainerMetadata meta : metadatas) {
if (meta.getFailure() != null && meta.getFailure() instanceof FabricAuthenticationException) {
throw (FabricAuthenticationException) meta.getFailure();
}
}
}
ShellUtils.storeFabricCredentials(session, username, password);
} catch (FabricAuthenticationException fae) {
// If authentication fails, prompts for credentials and try again.
if (builder instanceof CreateChildContainerOptions.Builder) {
CreateChildContainerOptions.Builder childBuilder = (CreateChildContainerOptions.Builder) builder;
promptForJmxCredentialsIfNeeded();
metadatas = fabricService.createContainers(childBuilder.jmxUser(username).jmxPassword(password).build());
ShellUtils.storeFabricCredentials(session, username, password);
}
}
}
}
return null;
}
use of io.fabric8.api.CreateContainerMetadata in project fabric8 by jboss-fuse.
the class FabricServiceImpl method getProvider.
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;
}
use of io.fabric8.api.CreateContainerMetadata in project fabric8 by jboss-fuse.
the class ZkDataStoreImpl method createContainerConfig.
@Override
public void createContainerConfig(CreateContainerMetadata metadata) {
assertValid();
try {
CreateContainerOptions options = metadata.getCreateOptions();
String containerId = metadata.getContainerName();
// String parent = options.getParent();
// String versionId = options.getVersion() != null ? options.getVersion() : getDefaultVersion();
// Set<String> profileIds = options.getProfiles();
// if (profileIds == null || profileIds.isEmpty()) {
// profileIds = new LinkedHashSet<String>();
// profileIds.add("default");
// }
// StringBuilder sb = new StringBuilder();
// for (String profileId : profileIds) {
// if (sb.length() > 0) {
// sb.append(" ");
// }
// sb.append(profileId);
// }
//
// setData(curator.get(), ZkPath.CONFIG_CONTAINER.getPath(containerId), versionId);
// setData(curator.get(), ZkPath.CONFIG_VERSIONS_CONTAINER.getPath(versionId, containerId), sb.toString());
// setData(curator.get(), ZkPath.CONTAINER_PARENT.getPath(containerId), parent);
setContainerMetadata(metadata);
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);
}
// If no resolver specified but a resolver is already present in the registry, use the registry value
String resolver = metadata.getOverridenResolver() != null ? metadata.getOverridenResolver() : options.getResolver();
if (resolver == null && exists(curator.get(), ZkPath.CONTAINER_RESOLVER.getPath(containerId)) != null) {
resolver = getStringData(curator.get(), ZkPath.CONTAINER_RESOLVER.getPath(containerId));
} else if (options.getResolver() != null) {
// Use the resolver specified in the options and do nothing.
} else if (exists(curator.get(), ZkPath.POLICIES.getPath(ZkDefs.RESOLVER)) != null) {
// If there is a globlal resolver specified use it.
resolver = getStringData(curator.get(), ZkPath.POLICIES.getPath(ZkDefs.RESOLVER));
} else {
// Fallback to the default resolver
resolver = ZkDefs.DEFAULT_RESOLVER;
}
// Set the resolver if not already set
setData(curator.get(), ZkPath.CONTAINER_RESOLVER.getPath(containerId), resolver);
} catch (Exception e) {
throw FabricException.launderThrowable(e);
}
}
use of io.fabric8.api.CreateContainerMetadata in project fabric8 by jboss-fuse.
the class FabricManager method createContainers.
@Override
public Map<String, String> createContainers(Map<String, Object> options) {
if (LOG.isDebugEnabled()) {
LOG.debug("Creating containers from JSON data: " + options);
}
String providerType = (String) options.get("providerType");
if (providerType == null) {
throw new RuntimeException("No providerType provided");
}
CreateContainerBasicOptions.Builder builder = null;
ContainerProvider provider = fabricService.getValidProviders().get(providerType);
if (provider == null) {
throw new RuntimeException("Can't find valid provider of type: " + providerType);
}
Class<?> clazz = provider.getOptionsType();
try {
builder = (CreateContainerBasicOptions.Builder) clazz.getMethod("builder").invoke(null);
} catch (Exception e) {
LOG.warn("Failed to find builder type", e);
}
if (builder == null) {
throw new RuntimeException("Unknown provider type : " + providerType);
}
ObjectMapper mapper = getObjectMapper();
builder = mapper.convertValue(options, builder.getClass());
builder.zookeeperPassword(fabricService.getZookeeperPassword());
builder.zookeeperUrl(fabricService.getZookeeperUrl());
Object profileObject = options.get("profiles");
if (profileObject != null) {
List profiles = mapper.convertValue(profileObject, List.class);
builder.profiles(profiles);
}
if (builder.getProxyUri() == null) {
builder.proxyUri(fabricService.getMavenRepoURI());
}
CreateContainerOptions build = builder.build();
if (LOG.isDebugEnabled()) {
LOG.debug("Created container options: " + build + " with profiles " + build.getProfiles());
}
CreateContainerMetadata<?>[] metadatas = fabricService.createContainers(build);
Map<String, String> rc = new LinkedHashMap<String, String>();
for (CreateContainerMetadata<?> metadata : metadatas) {
if (!metadata.isSuccess()) {
LOG.error("Failed to create container {}: ", metadata.getContainerName(), metadata.getFailure());
rc.put(metadata.getContainerName(), metadata.getFailure().getMessage());
}
}
return rc;
}
Aggregations