Search in sources :

Example 16 with Entry

use of io.fabric8.maven.docker.config.CopyConfiguration.Entry in project fabric8 by jboss-fuse.

the class FeatureConfigInstaller method installFeatureConfigs.

void installFeatureConfigs(Feature feature) throws IOException, InvalidSyntaxException {
    for (Config config : feature.getConfigurations()) {
        Properties props = config.getProperties();
        String[] split = parsePid(config.getName());
        // see http://felix.apache.org/documentation/subprojects/apache-felix-file-install.html#configurations
        String pid = split[0];
        String subname = split[1];
        Configuration cfg = findExistingConfiguration(configAdmin, pid, subname);
        if (cfg == null) {
            Dictionary<String, String> cfgProps = convertToDict(props);
            cfg = createConfiguration(configAdmin, pid, subname);
            String key = createConfigurationKey(pid, subname);
            cfgProps.put(CONFIG_KEY, key);
            cfg.update(cfgProps);
        } else if (config.isAppend()) {
            Dictionary<String, Object> properties = cfg.getProperties();
            // Ignore already managed configurations
            String fabricManagedPid = (String) properties.get(FABRIC_ZOOKEEPER_PID);
            if (Strings.isNotBlank(fabricManagedPid)) {
                continue;
            }
            for (Enumeration<String> propKeys = properties.keys(); propKeys.hasMoreElements(); ) {
                String key = propKeys.nextElement();
                // remove existing entry, since it's about appending.
                if (props.containsKey(key)) {
                    props.remove(key);
                }
            }
            if (props.size() > 0) {
                // convert props to dictionary
                Dictionary<String, String> cfgProps = convertToDict(props);
                cfg.update(cfgProps);
            }
        }
    }
    for (ConfigFile configFile : feature.getConfigurationFiles()) {
        installConfigurationFile(configFile.getLocation(), configFile.getFinalname(), configFile.isOverride());
    }
}
Also used : Dictionary(java.util.Dictionary) Enumeration(java.util.Enumeration) Configuration(org.osgi.service.cm.Configuration) ConfigFile(io.fabric8.agent.model.ConfigFile) Config(io.fabric8.agent.model.Config) Properties(java.util.Properties)

Example 17 with Entry

use of io.fabric8.maven.docker.config.CopyConfiguration.Entry in project fabric8 by jboss-fuse.

the class ComponentConfigurer method configure.

@Override
public <T> Map<String, ?> configure(final Map<String, ?> configuration, T target, String... ignorePrefix) throws Exception {
    assertValid();
    Map<String, Object> result = new HashMap<>();
    final PropertiesProvider runtimeProperties = new PropertiesProvider() {

        @Override
        public Object getProperty(String key) {
            return bundleContext.getProperty(key);
        }

        @Override
        public Object getRequiredProperty(String key) {
            String value = bundleContext.getProperty(key);
            IllegalStateAssertion.assertNotNull(value, "Cannot obtain property: " + key);
            return value;
        }

        @Override
        public Object getProperty(String key, Object defaultValue) {
            String value = bundleContext.getProperty(key);
            return value != null ? value : defaultValue;
        }
    };
    final PropertiesProvider configurationProvider = new MapPropertiesProvider((Map<String, Object>) configuration);
    final PropertiesProvider[] propertiesProviders = new PropertiesProvider[] { configurationProvider, runtimeProperties };
    PropertiesProvider provider = new SubstitutionPropertiesProvider(propertiesProviders);
    for (Map.Entry<String, ?> entry : configuration.entrySet()) {
        String key = entry.getKey();
        Object value = provider.getProperty(key);
        result.put(key, value);
    }
    ConfigInjection.applyConfiguration(result, target, ignorePrefix);
    return result;
}
Also used : MapPropertiesProvider(io.fabric8.api.gravia.MapPropertiesProvider) PropertiesProvider(io.fabric8.api.gravia.PropertiesProvider) SubstitutionPropertiesProvider(io.fabric8.api.gravia.SubstitutionPropertiesProvider) SubstitutionPropertiesProvider(io.fabric8.api.gravia.SubstitutionPropertiesProvider) MapPropertiesProvider(io.fabric8.api.gravia.MapPropertiesProvider) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 18 with Entry

use of io.fabric8.maven.docker.config.CopyConfiguration.Entry 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 19 with Entry

use of io.fabric8.maven.docker.config.CopyConfiguration.Entry 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 20 with Entry

use of io.fabric8.maven.docker.config.CopyConfiguration.Entry in project fabric8 by jboss-fuse.

the class SshAutoScalerTest method assertMaximumContainerCountNotExceeded.

/**
 * lets assert that no host has more than its maximum number of containers
 */
public static void assertMaximumContainerCountNotExceeded(FabricRequirements requirements, Map<String, CountingMap> hostToProfileCounts) {
    for (Map.Entry<String, CountingMap> entry : hostToProfileCounts.entrySet()) {
        String hostName = entry.getKey();
        CountingMap counts = entry.getValue();
        int total = counts.total();
        SshConfiguration sshConfiguration = requirements.getSshConfiguration();
        assertNotNull("Should have a sshConfiguration!", sshConfiguration);
        SshHostConfiguration hostConfiguration = sshConfiguration.getHost(hostName);
        assertNotNull("Should have a hosts configuration for host " + hostName, hostConfiguration);
        Integer maximumContainerCount = hostConfiguration.getMaximumContainerCount();
        if (maximumContainerCount != null) {
            assertTrue("Host " + hostName + " has a maximum container count of " + maximumContainerCount + " but was " + total, total <= maximumContainerCount);
        }
    }
}
Also used : CountingMap(io.fabric8.utils.CountingMap) SshConfiguration(io.fabric8.api.SshConfiguration) SshHostConfiguration(io.fabric8.api.SshHostConfiguration) CountingMap(io.fabric8.utils.CountingMap) Map(java.util.Map)

Aggregations

Map (java.util.Map)89 HashMap (java.util.HashMap)57 IOException (java.io.IOException)31 File (java.io.File)30 ArrayList (java.util.ArrayList)26 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)16 List (java.util.List)14 Properties (java.util.Properties)14 HashSet (java.util.HashSet)10 Entry (io.fabric8.maven.docker.config.CopyConfiguration.Entry)9 ZipFile (org.apache.commons.compress.archivers.zip.ZipFile)9 Test (org.junit.Test)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 LinkedHashMap (java.util.LinkedHashMap)8 TreeMap (java.util.TreeMap)8 Resource (io.fabric8.kubernetes.client.dsl.Resource)7 FileInputStream (java.io.FileInputStream)7 Set (java.util.Set)7 Profile (io.fabric8.api.Profile)6 ProfileService (io.fabric8.api.ProfileService)5