Search in sources :

Example 21 with Configuration

use of io.fabric8.maven.core.model.Configuration 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 22 with Configuration

use of io.fabric8.maven.core.model.Configuration 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 23 with Configuration

use of io.fabric8.maven.core.model.Configuration 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)

Example 24 with Configuration

use of io.fabric8.maven.core.model.Configuration in project fabric8 by jboss-fuse.

the class FabricManager method currentContainerConfigurationFiles.

/**
 * Returns a map of all the current configuration files in the profiles of
 * the current container with the file name as the key and the profile ID as
 * the value
 */
@Override
public Map<String, String> currentContainerConfigurationFiles() {
    String containerName = getCurrentContainerName();
    FabricServiceImpl service = fabricService;
    Container container = service.getContainer(containerName);
    if (container != null) {
        Profile[] profiles = container.getProfiles();
        return Profiles.getConfigurationFileNameMap(profiles);
    }
    return new HashMap<String, String>();
}
Also used : Container(io.fabric8.api.Container) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FabricServiceImpl(io.fabric8.service.FabricServiceImpl) Profile(io.fabric8.api.Profile)

Example 25 with Configuration

use of io.fabric8.maven.core.model.Configuration in project fabric8 by jboss-fuse.

the class MQManager method createConfigDTOs.

public static List<MQBrokerConfigDTO> createConfigDTOs(MQService mqService, Profile profile) {
    List<MQBrokerConfigDTO> answer = new ArrayList<MQBrokerConfigDTO>();
    Map<String, Map<String, String>> configurations = profile.getConfigurations();
    Set<Map.Entry<String, Map<String, String>>> entries = configurations.entrySet();
    for (Map.Entry<String, Map<String, String>> entry : entries) {
        String key = entry.getKey();
        Map<String, String> configuration = entry.getValue();
        if (isBrokerConfigPid(key)) {
            String brokerName = getBrokerNameFromPID(key);
            String profileId = profile.getId();
            MQBrokerConfigDTO dto = new MQBrokerConfigDTO();
            dto.setProfile(profileId);
            dto.setBrokerName(brokerName);
            String version = profile.getVersion();
            dto.setVersion(version);
            List<String> parentIds = profile.getParentIds();
            if (parentIds.size() > 0) {
                dto.setParentProfile(parentIds.get(0));
            }
            if (configuration != null) {
                dto.setData(configuration.get(DATA));
                dto.setConfigUrl(configuration.get(CONFIG_URL));
                dto.setGroup(configuration.get(GROUP));
                dto.setKind(BrokerKind.fromValue(configuration.get(KIND)));
                dto.setMinimumInstances(Maps.integerValue(configuration, MINIMUM_INSTANCES));
                dto.setNetworks(Maps.stringValues(configuration, NETWORKS));
                dto.setNetworksUserName(configuration.get(NETWORK_USER_NAME));
                dto.setNetworksPassword(configuration.get(NETWORK_PASSWORD));
                dto.setReplicas(Maps.integerValue(configuration, REPLICAS));
                for (Map.Entry<String, String> configurationEntry : configuration.entrySet()) {
                    if (configurationEntry.getKey().endsWith("-port")) {
                        dto.getPorts().put(configurationEntry.getKey().substring(0, configurationEntry.getKey().indexOf("-port")), configurationEntry.getValue());
                    }
                }
            }
            answer.add(dto);
        }
    }
    return answer;
}
Also used : MQBrokerConfigDTO(io.fabric8.api.jmx.MQBrokerConfigDTO) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ParallelTest (io.strimzi.test.annotations.ParallelTest)142 Kafka (io.strimzi.api.kafka.model.Kafka)138 KafkaBuilder (io.strimzi.api.kafka.model.KafkaBuilder)132 HashMap (java.util.HashMap)97 IOException (java.io.IOException)86 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)83 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)80 Map (java.util.Map)79 StatefulSet (io.fabric8.kubernetes.api.model.apps.StatefulSet)76 ArrayList (java.util.ArrayList)76 List (java.util.List)70 TopologySpreadConstraint (io.fabric8.kubernetes.api.model.TopologySpreadConstraint)66 GenericKafkaListenerBuilder (io.strimzi.api.kafka.model.listener.arraylistener.GenericKafkaListenerBuilder)66 Matchers.containsString (org.hamcrest.Matchers.containsString)58 Service (io.fabric8.kubernetes.api.model.Service)55 Collectors (java.util.stream.Collectors)55 Container (io.fabric8.kubernetes.api.model.Container)54 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)50 Quantity (io.fabric8.kubernetes.api.model.Quantity)48 File (java.io.File)47