use of io.fabric8.api.CreateContainerOptions 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.CreateContainerOptions in project fabric8 by jboss-fuse.
the class FabricServiceImpl method validateProfileDependencies.
protected void validateProfileDependencies(CreateContainerOptions options) {
Map<String, Map<String, String>> profileDependencies = Profiles.getOverlayFactoryConfigurations(this, options.getProfiles(), options.getVersion(), ProfileDependencyConfig.PROFILE_DEPENDENCY_CONFIG_PID);
Set<Map.Entry<String, Map<String, String>>> entries = profileDependencies.entrySet();
for (Map.Entry<String, Map<String, String>> entry : entries) {
String configName = entry.getKey();
Map<String, String> exportConfig = entry.getValue();
if (exportConfig != null && !exportConfig.isEmpty()) {
ProfileDependencyConfig config = new ProfileDependencyConfig();
try {
configurer.configure(exportConfig, config);
} catch (Exception e) {
throw new FabricException("Failed to load configuration for " + configName + " of " + config + " due to: " + e, e);
}
// Ensure dependent container exists
if (ProfileDependencyKind.ZOOKEEPER_SERVICE.equals(config.getKind())) {
try {
List<String> children = getChildren(this.curator.get(), config.getZookeeperPath());
if (children == null || children.isEmpty()) {
throw new ProfileDependencyException(options.getProfiles(), config.getProfileWildcards(), config.getProfileTags(), config.getSummary());
}
boolean dependencyFound = false;
Iterator<String> childIterator = children.iterator();
while (!dependencyFound && childIterator.hasNext()) {
String containerName = childIterator.next();
Container container = this.getContainer(containerName);
Profile[] profiles = container.getProfiles();
int profileCount = 0;
while (!dependencyFound && profileCount < profiles.length) {
Profile profile = profiles[profileCount];
if (config.getProfileWildcards() != null) {
for (String profileWildcard : config.getProfileWildcards()) {
if (profile.getId().contains(profileWildcard)) {
dependencyFound = true;
break;
}
}
}
if (!dependencyFound && config.getProfileTags() != null) {
List<String> profileTags = profile.getTags();
int foundTags = 0;
for (String configProfileTag : config.getProfileTags()) {
if (profileTags.contains(configProfileTag)) {
foundTags++;
}
}
if (foundTags == config.getProfileTags().length) {
dependencyFound = true;
}
}
}
}
if (!dependencyFound) {
throw new ProfileDependencyException(options.getProfiles(), config.getProfileWildcards(), config.getProfileTags(), config.getSummary());
}
} catch (Exception e) {
throw new ProfileDependencyException(options.getProfiles(), config.getProfileWildcards(), config.getProfileTags(), config.getSummary(), e);
}
}
}
}
}
use of io.fabric8.api.CreateContainerOptions in project fabric8 by jboss-fuse.
the class FabricManager method getJvmOpts.
@Override
public /**
* Returns configured jvmOpts only for (local and remote) Karaf containers.
*/
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;
}
use of io.fabric8.api.CreateContainerOptions 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;
}
use of io.fabric8.api.CreateContainerOptions in project fabric8 by jboss-fuse.
the class FabricManager method containerCreateOptionsType.
@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();
}
}
Aggregations