Search in sources :

Example 1 with CreateContainerOptions

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);
    }
}
Also used : CreateContainerOptions(io.fabric8.api.CreateContainerOptions) Map(java.util.Map) FabricException(io.fabric8.api.FabricException) InvalidClassException(java.io.InvalidClassException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException)

Example 2 with CreateContainerOptions

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);
                }
            }
        }
    }
}
Also used : ProfileDependencyException(io.fabric8.api.ProfileDependencyException) FabricException(io.fabric8.api.FabricException) ProfileDependencyException(io.fabric8.api.ProfileDependencyException) EncryptionOperationNotPossibleException(org.jasypt.exceptions.EncryptionOperationNotPossibleException) FabricException(io.fabric8.api.FabricException) IOException(java.io.IOException) Profile(io.fabric8.api.Profile) Entry(java.util.Map.Entry) Container(io.fabric8.api.Container) ProfileDependencyConfig(io.fabric8.internal.ProfileDependencyConfig) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Example 3 with CreateContainerOptions

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;
}
Also used : Container(io.fabric8.api.Container) CreateContainerOptions(io.fabric8.api.CreateContainerOptions) CreateContainerBasicMetadata(io.fabric8.api.CreateContainerBasicMetadata)

Example 4 with CreateContainerOptions

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;
}
Also used : ContainerProvider(io.fabric8.api.ContainerProvider) CreateContainerMetadata(io.fabric8.api.CreateContainerMetadata) CreateContainerOptions(io.fabric8.api.CreateContainerOptions) MalformedObjectNameException(javax.management.MalformedObjectNameException) FabricException(io.fabric8.api.FabricException) MalformedURLException(java.net.MalformedURLException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) ArrayList(java.util.ArrayList) CreateContainerBasicOptions(io.fabric8.api.CreateContainerBasicOptions) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 5 with CreateContainerOptions

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();
    }
}
Also used : CreateContainerOptions(io.fabric8.api.CreateContainerOptions)

Aggregations

CreateContainerOptions (io.fabric8.api.CreateContainerOptions)7 FabricException (io.fabric8.api.FabricException)5 IOException (java.io.IOException)5 Container (io.fabric8.api.Container)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 CreateContainerMetadata (io.fabric8.api.CreateContainerMetadata)3 Map (java.util.Map)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ContainerProvider (io.fabric8.api.ContainerProvider)2 CreateContainerBasicMetadata (io.fabric8.api.CreateContainerBasicMetadata)2 CreateContainerBasicOptions (io.fabric8.api.CreateContainerBasicOptions)2 FabricService (io.fabric8.api.FabricService)2 ProfileDependencyException (io.fabric8.api.ProfileDependencyException)2 MalformedURLException (java.net.MalformedURLException)2 HashMap (java.util.HashMap)2 SortedMap (java.util.SortedMap)2 TreeMap (java.util.TreeMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 MalformedObjectNameException (javax.management.MalformedObjectNameException)2 EncryptionOperationNotPossibleException (org.jasypt.exceptions.EncryptionOperationNotPossibleException)2