Search in sources :

Example 36 with Config

use of io.fabric8.kubernetes.api.model.Config in project fabric8 by jboss-fuse.

the class DeployToProfileMojoTest method shouldExpandAnyPlaceholder.

@Test
public void shouldExpandAnyPlaceholder() throws IOException, J4pException, MalformedObjectNameException, MojoExecutionException {
    // Given
    File root = new File("src/test/fabric8");
    File config = new File(root, "pid.properties");
    // When
    mojo.uploadProfileConfigFile(jolokiaClient, deployResults, root, config);
    String decodedConfig = decodeSentConfig();
    // Then
    assertTrue(decodedConfig.contains("artifactId = " + "fabric8-maven-plugin"));
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) Files.writeToFile(io.fabric8.common.util.Files.writeToFile) File(java.io.File) Test(org.junit.Test)

Example 37 with Config

use of io.fabric8.kubernetes.api.model.Config in project fabric8 by jboss-fuse.

the class DeployToProfileMojoTest method shouldExpandProjectVersionPlaceholder.

@Test
public void shouldExpandProjectVersionPlaceholder() throws IOException, J4pException, MalformedObjectNameException, MojoExecutionException {
    // Given
    File config = new File(root, randomUUID().toString());
    String property = "project = " + PLACEHOLDER_PROJECT_VERSION;
    writeToFile(config, property.getBytes());
    // When
    mojo.uploadProfileConfigFile(jolokiaClient, deployResults, root, config);
    String decodedConfig = decodeSentConfig();
    // Then
    assertEquals("project = " + FABRIC_VERSION, decodedConfig);
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) Files.writeToFile(io.fabric8.common.util.Files.writeToFile) File(java.io.File) Test(org.junit.Test)

Example 38 with Config

use of io.fabric8.kubernetes.api.model.Config in project fabric8 by jboss-fuse.

the class FabricServiceImpl method setConfigurationValue.

@Override
public void setConfigurationValue(String versionId, String profileId, String pid, String key, String value) {
    assertValid();
    Version version = profileService.get().getRequiredVersion(versionId);
    Profile profile = version.getRequiredProfile(profileId);
    ProfileBuilder builder = ProfileBuilder.Factory.createFrom(profile);
    Map<String, String> config = builder.getConfiguration(pid);
    config.put(key, value);
    builder.addConfiguration(pid, config);
    profileService.get().updateProfile(builder.getProfile());
}
Also used : Version(io.fabric8.api.Version) ProfileBuilder(io.fabric8.api.ProfileBuilder) Profile(io.fabric8.api.Profile)

Example 39 with Config

use of io.fabric8.kubernetes.api.model.Config in project fabric8 by jboss-fuse.

the class FabricServiceImpl method getZookeeperInfo.

// FIXME public access on the impl
public String getZookeeperInfo(String name) {
    assertValid();
    String zooKeeperUrl = null;
    // Also this is required for the integration with the IDE.
    try {
        if (curator.get().getZookeeperClient().isConnected()) {
            Version defaultVersion = getDefaultVersion();
            if (defaultVersion != null) {
                Profile profile = defaultVersion.getRequiredProfile("default");
                if (profile != null) {
                    Map<String, String> zookeeperConfig = profile.getConfiguration(Constants.ZOOKEEPER_CLIENT_PID);
                    if (zookeeperConfig != null) {
                        zooKeeperUrl = getSubstitutedData(curator.get(), zookeeperConfig.get(name));
                    }
                }
            }
        }
    } catch (Exception e) {
    // Ignore it.
    }
    if (zooKeeperUrl == null) {
        try {
            Configuration config = configAdmin.get().getConfiguration(Constants.ZOOKEEPER_CLIENT_PID, null);
            zooKeeperUrl = (String) config.getProperties().get(name);
        } catch (Exception e) {
        // Ignore it.
        }
    }
    return zooKeeperUrl;
}
Also used : BootstrapConfiguration(io.fabric8.zookeeper.bootstrap.BootstrapConfiguration) Configuration(org.osgi.service.cm.Configuration) Version(io.fabric8.api.Version) Profile(io.fabric8.api.Profile) ProfileDependencyException(io.fabric8.api.ProfileDependencyException) EncryptionOperationNotPossibleException(org.jasypt.exceptions.EncryptionOperationNotPossibleException) FabricException(io.fabric8.api.FabricException) IOException(java.io.IOException)

Example 40 with Config

use of io.fabric8.kubernetes.api.model.Config 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)

Aggregations

Test (org.junit.Test)106 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)37 HashMap (java.util.HashMap)34 IOException (java.io.IOException)32 ResourceConfig (io.fabric8.maven.core.config.ResourceConfig)28 File (java.io.File)26 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)24 Map (java.util.Map)24 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)23 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)21 Expectations (mockit.Expectations)20 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)17 ArrayList (java.util.ArrayList)17 VolumeConfig (io.fabric8.maven.core.config.VolumeConfig)15 AbstractConfigHandlerTest (io.fabric8.maven.docker.config.handler.AbstractConfigHandlerTest)15 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)14 AuthConfig (io.fabric8.maven.docker.access.AuthConfig)13 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)12 Before (org.junit.Before)12 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)11