Search in sources :

Example 16 with ConfigModel

use of org.jboss.galleon.config.ConfigModel in project galleon by wildfly.

the class ProvisioningDiffProvider method getMergedConfig.

public ProvisioningConfig getMergedConfig() throws ProvisioningException {
    if (mergedConfig != null) {
        return mergedConfig;
    }
    if (!hasConfigChanges()) {
        mergedConfig = provisionedConfig;
        return provisionedConfig;
    }
    final ProvisioningConfig.Builder configBuilder = initProvisioningConfig();
    final Collection<ConfigModel> definedConfigs = provisionedConfig.getDefinedConfigs();
    if (!definedConfigs.isEmpty()) {
        for (ConfigModel originalConfig : definedConfigs) {
            final ConfigModel updatedConfig = updatedConfigs.remove(originalConfig.getId());
            if (updatedConfig != null) {
                configBuilder.addConfig(updatedConfig);
                continue;
            }
            if (removedConfigs.contains(originalConfig.getId())) {
                continue;
            }
            configBuilder.addConfig(originalConfig);
        }
    }
    if (!updatedConfigs.isEmpty()) {
        for (ConfigModel updatedConfig : updatedConfigs.values()) {
            configBuilder.addConfig(updatedConfig);
        }
    }
    if (!addedConfigs.isEmpty()) {
        for (ConfigModel addedConfig : addedConfigs.values()) {
            configBuilder.addConfig(addedConfig);
        }
    }
    if (!removedConfigs.isEmpty()) {
        List<ProvisionedConfig> baseConfigs = null;
        for (ConfigId configId : removedConfigs) {
            if (provisionedConfig.hasDefinedConfig(configId)) {
                if (baseConfigs == null) {
                    final ProvisioningConfig.Builder baseBuilder = initProvisioningConfig();
                    for (ProvisionedConfig config : provisionedState.getConfigs()) {
                        final ConfigId provisionedId = new ConfigId(config.getModel(), config.getName());
                        if (!provisionedConfig.hasDefinedConfig(provisionedId)) {
                            baseBuilder.excludeDefaultConfig(provisionedId);
                        }
                    }
                    try (ProvisioningRuntime baseRt = ProvisioningRuntimeBuilder.newInstance(log).initLayout(layout.getFactory(), baseBuilder.build()).build()) {
                        baseConfigs = baseRt.getConfigs();
                    }
                }
                if (getProvisionedConfig(baseConfigs, configId.getModel(), configId.getName()) != null) {
                    if (provisionedConfig.isInheritConfigs(true)) {
                        if (!provisionedConfig.isConfigModelExcluded(configId)) {
                            configBuilder.excludeDefaultConfig(configId);
                        }
                    } else if (provisionedConfig.isConfigModelIncluded(configId)) {
                        configBuilder.excludeDefaultConfig(configId);
                    }
                }
            } else if (provisionedConfig.isInheritConfigs(true)) {
                if (!provisionedConfig.isConfigModelExcluded(configId)) {
                    configBuilder.excludeDefaultConfig(configId);
                }
            } else if (provisionedConfig.isConfigModelIncluded(configId)) {
                configBuilder.excludeDefaultConfig(configId);
            }
        }
    }
    mergedConfig = configBuilder.build();
    return mergedConfig;
}
Also used : ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) ConfigModel(org.jboss.galleon.config.ConfigModel) ProvisioningRuntime(org.jboss.galleon.runtime.ProvisioningRuntime) ConfigId(org.jboss.galleon.config.ConfigId) ProvisionedConfig(org.jboss.galleon.state.ProvisionedConfig)

Example 17 with ConfigModel

use of org.jboss.galleon.config.ConfigModel in project galleon by wildfly.

the class ProvisioningDiffProvider method addConfig.

public void addConfig(ProvisionedFeatureDiffCallback featureDiffCallback, ProvisionedConfig config, String... relativePaths) throws ProvisioningException {
    if (featureDiff == null) {
        featureDiff = new FeatureDiff(log);
    }
    featureDiff.reset();
    featureDiff.model = config.getModel();
    featureDiff.name = config.getName();
    featureDiff.diff(featureDiffCallback, config);
    final ConfigModel mergedConfig = featureDiff.getMergedConfig(layout);
    if (mergedConfig == null) {
        log.verbose("%s is meaningless", config.getName());
    } else {
        addedConfigs = CollectionUtils.putLinked(addedConfigs, new ConfigId(config.getModel(), config.getName()), mergedConfig);
    }
    featureDiff.reset();
    suppressPaths(relativePaths);
}
Also used : ConfigModel(org.jboss.galleon.config.ConfigModel) ConfigId(org.jboss.galleon.config.ConfigId)

Example 18 with ConfigModel

use of org.jboss.galleon.config.ConfigModel in project galleon by wildfly.

the class LayersTestCase method test.

@Test
public void test() throws Exception {
    FeaturePackLocation prod1 = newFpl(PRODUCER1, "1", "1.0.0.Final");
    FeaturePackLocation prod2 = newFpl(PRODUCER2, "1", "1.0.0.Final");
    CliTestUtils.installWithLayers(cli, universeSpec, PRODUCER1, "1.0.0.Final");
    CliTestUtils.install(cli, universeSpec, PRODUCER2, "1.0.0.Final");
    cli.execute("find * --layers=layerZ --universe=" + universeSpec);
    assertFalse(cli.getOutput(), cli.getOutput().contains(prod1.toString()));
    cli.execute("find * --layers=layerB --universe=" + universeSpec);
    assertTrue(cli.getOutput(), cli.getOutput().contains(prod1.toString()));
    assertTrue(cli.getOutput(), cli.getOutput().contains("layerB-" + PRODUCER1));
    cli.execute("feature-pack get-info " + prod1 + " --type=layers");
    assertTrue(cli.getOutput(), cli.getOutput().contains("base-" + PRODUCER1));
    assertTrue(cli.getOutput(), cli.getOutput().contains("layerA-" + PRODUCER1));
    assertTrue(cli.getOutput(), cli.getOutput().contains("layerB-" + PRODUCER1));
    assertTrue(cli.getOutput(), cli.getOutput().contains("layerC-" + PRODUCER1));
    cli.execute("feature-pack get-info " + prod1 + " --type=configs");
    assertFalse(cli.getOutput(), cli.getOutput().contains("base-" + PRODUCER1));
    assertFalse(cli.getOutput(), cli.getOutput().contains("layerA-" + PRODUCER1));
    assertTrue(cli.getOutput(), cli.getOutput().contains("layerB-" + PRODUCER1));
    assertFalse(cli.getOutput(), cli.getOutput().contains("layerC-" + PRODUCER1));
    Path path = cli.newDir("prod1", false);
    try {
        cli.execute("install " + prod1 + " --dir=" + path + " --layers=foo");
        throw new Exception("Should have failed");
    } catch (CommandException ex) {
    // XXX OK, expected
    }
    cli.execute("install " + prod1 + " --dir=" + path + " --layers=" + "layerA-" + PRODUCER1 + ",layerC-" + PRODUCER1);
    ProvisioningConfig config = ProvisioningManager.builder().setInstallationHome(path).build().getProvisioningConfig();
    ConfigModel conf = config.getDefinedConfig(new ConfigId("testmodel", "testmodel.xml"));
    assertNotNull(conf);
    assertTrue(conf.getIncludedLayers().size() == 2);
    assertTrue(conf.getIncludedLayers().contains("layerA-" + PRODUCER1));
    assertTrue(conf.getIncludedLayers().contains("layerC-" + PRODUCER1));
    String opt = config.getOption(Constants.OPTIONAL_PACKAGES);
    assertNotNull(opt);
    assertEquals(Constants.PASSIVE_PLUS, opt);
    cli.execute("get-info --dir=" + path + " --type=configs");
    assertTrue(cli.getOutput(), cli.getOutput().contains("layerA-" + PRODUCER1));
    assertTrue(cli.getOutput(), cli.getOutput().contains("layerC-" + PRODUCER1));
    assertFalse(cli.getOutput(), cli.getOutput().contains("base-" + PRODUCER1));
    // Multiple configurations are invalid with layers
    try {
        cli.execute("install " + prod1 + " --dir=" + path + " --config=testmodel/foobar.xml,testmodel/foobar2.xml, --layers=" + "layerB-" + PRODUCER1);
        throw new Exception("should have failed");
    } catch (CommandException ex) {
    // XXX OK expected
    }
    Path path2 = cli.newDir("prod2", false);
    try {
        cli.execute("install " + prod1 + " --dir=" + path2 + " --config=moo/foobar.xml --layers=" + "layerB-" + PRODUCER1);
        throw new Exception("should have failed");
    } catch (CommandException ex) {
    // XXX OK expected
    }
    cli.execute("install " + prod1 + " --dir=" + path2 + " --config=testmodel/foobar.xml --layers=" + "layerB-" + PRODUCER1);
    ProvisioningConfig config2 = ProvisioningManager.builder().setInstallationHome(path2).build().getProvisioningConfig();
    ConfigModel conf2 = config2.getDefinedConfig(new ConfigId("testmodel", "foobar.xml"));
    assertNotNull(conf2);
    assertTrue(conf2.getIncludedLayers().size() == 1);
    assertTrue(conf2.getIncludedLayers().contains("layerB-" + PRODUCER1));
    cli.execute("get-info --dir=" + path2 + " --type=configs");
    assertTrue(cli.getOutput(), cli.getOutput().contains("testmodel"));
    assertTrue(cli.getOutput(), cli.getOutput().contains("foobar.xml"));
    assertTrue(cli.getOutput(), cli.getOutput().contains("layerB-" + PRODUCER1));
    assertFalse(cli.getOutput(), cli.getOutput().contains("layerA-" + PRODUCER1));
    assertFalse(cli.getOutput(), cli.getOutput().contains("layerC-" + PRODUCER1));
    assertFalse(cli.getOutput(), cli.getOutput().contains("base-" + PRODUCER1));
    // Default model and config names
    Path path3 = cli.newDir("prod3", false);
    cli.execute("install " + prod1 + " --dir=" + path3 + " --config=foobar.xml --layers=" + "layerB-" + PRODUCER1);
    cli.execute("get-info --dir=" + path3 + " --type=configs");
    assertTrue(cli.getOutput(), cli.getOutput().contains("testmodel"));
    assertTrue(cli.getOutput(), cli.getOutput().contains("foobar.xml"));
    config = ProvisioningManager.builder().setInstallationHome(path3).build().getProvisioningConfig();
    assertTrue(config.getDefinedConfigs().size() == 1);
    conf = config.getDefinedConfig(new ConfigId("testmodel", "foobar.xml"));
    assertNotNull(conf);
    try {
        cli.execute("install " + prod1 + " --dir=" + path3 + " --config=foomodel/ --layers=" + "layerB-" + PRODUCER1);
        throw new Exception("Should have failed");
    } catch (CommandException ex) {
    // XXX OK, expected
    }
    Path path4 = cli.newDir("prod4", false);
    cli.execute("install " + prod1 + " --dir=" + path4 + " --config=testmodel/ --layers=" + "layerB-" + PRODUCER1);
    cli.execute("get-info --dir=" + path4 + " --type=configs");
    assertTrue(cli.getOutput(), cli.getOutput().contains("testmodel"));
    assertTrue(cli.getOutput(), cli.getOutput().contains("testmodel.xml"));
    config = ProvisioningManager.builder().setInstallationHome(path4).build().getProvisioningConfig();
    assertTrue(config.getDefinedConfigs().size() == 1);
    conf = config.getDefinedConfig(new ConfigId("testmodel", "testmodel.xml"));
    assertNotNull(conf);
    // Install a specified config without layers
    Path path5 = cli.newDir("prod5", false);
    cli.execute("install " + prod1 + " --dir=" + path5);
    cli.execute("get-info --dir=" + path5 + " --type=configs");
    assertTrue(cli.getOutput(), cli.getOutput().contains("config1.xml"));
    assertTrue(cli.getOutput(), cli.getOutput().contains("config2.xml"));
    cli.execute("install " + prod1 + " --dir=" + path5 + " --default-configs=testmodel/config1.xml");
    cli.execute("get-info --dir=" + path5 + " --type=configs");
    assertTrue(cli.getOutput(), cli.getOutput().contains("config1.xml"));
    assertFalse(cli.getOutput(), cli.getOutput().contains("config2.xml"));
    cli.execute("install " + prod1 + " --dir=" + path5 + " --default-configs=testmodel/config1.xml,testmodel/config2.xml");
    cli.execute("get-info --dir=" + path5 + " --type=configs");
    assertTrue(cli.getOutput(), cli.getOutput().contains("config1.xml"));
    assertTrue(cli.getOutput(), cli.getOutput().contains("config2.xml"));
    // Install multiple producers, installing default-config should not erase existing producer.
    Path path6 = cli.newDir("prod6", false);
    cli.execute("install " + prod2 + " --dir=" + path6);
    cli.execute("install " + prod1 + " --dir=" + path6 + " --default-configs=testmodel/config1.xml");
    cli.execute("get-info --dir=" + path6);
    assertTrue(cli.getOutput(), cli.getOutput().contains(PRODUCER1));
    assertTrue(cli.getOutput(), cli.getOutput().contains(PRODUCER2));
    // Install a default-config into empty directory
    Path path7 = cli.newDir("prod7", false);
    cli.execute("install " + prod1 + " --dir=" + path7 + " --default-configs=testmodel/config1.xml");
    cli.execute("get-info --dir=" + path7 + " --type=configs");
    assertTrue(cli.getOutput(), cli.getOutput().contains(PRODUCER1));
    assertTrue(cli.getOutput(), cli.getOutput().contains("config1.xml"));
    // Install layers in multiple steps
    Path path8 = cli.newDir("prod8", false);
    cli.execute("install " + prod1 + " --dir=" + path8 + " --layers=" + "layerA-" + PRODUCER1);
    cli.execute("install " + prod1 + " --dir=" + path8 + " --layers=" + "layerC-" + PRODUCER1);
    ProvisioningConfig config3 = ProvisioningManager.builder().setInstallationHome(path8).build().getProvisioningConfig();
    ConfigModel conf3 = config3.getDefinedConfig(new ConfigId("testmodel", "testmodel.xml"));
    assertNotNull(conf3);
    assertTrue(conf3.getIncludedLayers().size() == 2);
    assertTrue(conf3.getIncludedLayers().contains("layerA-" + PRODUCER1));
    assertTrue(conf3.getIncludedLayers().contains("layerC-" + PRODUCER1));
}
Also used : Path(java.nio.file.Path) ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) ConfigModel(org.jboss.galleon.config.ConfigModel) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation) CommandException(org.aesh.command.CommandException) ConfigId(org.jboss.galleon.config.ConfigId) CommandException(org.aesh.command.CommandException) Test(org.junit.Test)

Aggregations

ConfigModel (org.jboss.galleon.config.ConfigModel)18 ConfigId (org.jboss.galleon.config.ConfigId)12 IOException (java.io.IOException)4 Path (java.nio.file.Path)4 Map (java.util.Map)4 FeaturePackConfig (org.jboss.galleon.config.FeaturePackConfig)4 ProvisioningConfig (org.jboss.galleon.config.ProvisioningConfig)4 ProvisioningDescriptionException (org.jboss.galleon.ProvisioningDescriptionException)3 ProvisioningException (org.jboss.galleon.ProvisioningException)3 BufferedReader (java.io.BufferedReader)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 FeaturePackSpec (org.jboss.galleon.spec.FeaturePackSpec)2 FeaturePackLocation (org.jboss.galleon.universe.FeaturePackLocation)2 Test (org.junit.Test)2 FileVisitResult (java.nio.file.FileVisitResult)1 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1