Search in sources :

Example 1 with ProvisionedConfig

use of org.jboss.galleon.state.ProvisionedConfig in project galleon by wildfly.

the class PersistChangesTestBase method provisionedState.

@Override
protected ProvisionedState provisionedState() throws ProvisioningException {
    final ProvisionedState.Builder builder = ProvisionedState.builder();
    final FPID[] fpids = provisionedFpids();
    if (fpids != null && fpids.length > 0) {
        for (FPID fpid : fpids) {
            builder.addFeaturePack(ProvisionedFeaturePack.forFPID(fpid));
        }
        final ProvisionedConfig[] configs = provisionedConfigModels();
        if (configs != null && configs.length > 0) {
            for (ProvisionedConfig config : configs) {
                builder.addConfig(config);
            }
        }
    }
    return builder.build();
}
Also used : FPID(org.jboss.galleon.universe.FeaturePackLocation.FPID) ProvisionedState(org.jboss.galleon.state.ProvisionedState) ProvisionedConfig(org.jboss.galleon.state.ProvisionedConfig)

Example 2 with ProvisionedConfig

use of org.jboss.galleon.state.ProvisionedConfig in project galleon by wildfly.

the class TestConfigsPersistingPlugin method postInstall.

@Override
public void postInstall(ProvisioningRuntime runtime) throws ProvisioningException {
    final Path configsDir = runtime.getStagedDir().resolve(Constants.CONFIGS);
    for (ProvisionedConfig config : runtime.getConfigs()) {
        Path configPath = configsDir;
        if (config.getModel() != null) {
            configPath = configPath.resolve(config.getModel());
        }
        configPath = configPath.resolve(config.getName());
        try {
            ProvisionedConfigXmlWriter.getInstance().write(config, configPath);
        } catch (Exception e) {
            throw new ProvisioningException("Failed to persist config " + new ConfigId(config.getModel(), config.getName()), e);
        }
    }
}
Also used : Path(java.nio.file.Path) ProvisioningException(org.jboss.galleon.ProvisioningException) ConfigId(org.jboss.galleon.config.ConfigId) ProvisionedConfig(org.jboss.galleon.state.ProvisionedConfig) ProvisioningException(org.jboss.galleon.ProvisioningException)

Example 3 with ProvisionedConfig

use of org.jboss.galleon.state.ProvisionedConfig in project galleon by wildfly.

the class FeatureContainers method populateFeatureContainer.

private static void populateFeatureContainer(FeatureContainer fp, PmSession session, ProvisioningRuntime runtime, boolean allSpecs) throws ProvisioningException, IOException {
    // Need a Map of FeaturePack to resolve external packages/
    Map<String, FeaturePackRuntime> gavs = new HashMap<>();
    for (FeaturePackRuntime rt : runtime.getFeaturePacks()) {
        gavs.put(Identity.buildOrigin(rt.getFPID().getProducer()), rt);
    }
    List<CliPlugin> cliPlugins = new ArrayList<>();
    FeaturePackPluginVisitor<CliPlugin> visitor = new FeaturePackPluginVisitor<CliPlugin>() {

        @Override
        public void visitPlugin(CliPlugin plugin) throws ProvisioningException {
            cliPlugins.add(plugin);
        }
    };
    runtime.getLayout().visitPlugins(visitor, CliPlugin.class);
    CliPlugin plugin = cliPlugins.isEmpty() ? null : cliPlugins.get(0);
    PackageGroupsBuilder pkgBuilder = new PackageGroupsBuilder();
    FeatureSpecsBuilder specsBuilder = new FeatureSpecsBuilder();
    String optionalOption = runtime.getProvisioningConfig().getOption(ProvisioningOption.OPTIONAL_PACKAGES.getName());
    if (optionalOption == null) {
        optionalOption = Constants.ALL;
    }
    boolean includeOptional = false;
    boolean includePassive = false;
    boolean checkPassive = false;
    if (optionalOption.equals(Constants.ALL)) {
        includePassive = true;
        includeOptional = true;
    } else {
        if (optionalOption.equals(Constants.NONE)) {
            // No optional included.
            includeOptional = false;
            includePassive = false;
        } else {
            if (optionalOption.equals(Constants.PASSIVE)) {
                // Include passives that have dependencies present.
                includeOptional = false;
                includePassive = true;
                checkPassive = true;
            } else {
                if (optionalOption.equals(Constants.PASSIVE_PLUS)) {
                    // Include passives that have dependencies present and optionals
                    includeOptional = true;
                    includePassive = true;
                    checkPassive = true;
                } else {
                    throw new ProvisioningException("Not recognized value for " + Constants.OPTIONAL_PACKAGES);
                }
            }
        }
    }
    boolean includeOptionalF = includeOptional;
    boolean includePassiveF = includePassive;
    Map<String, Map<String, PackageRuntime>> allPackages = new HashMap<>();
    for (FeaturePackRuntime rt : runtime.getFeaturePacks()) {
        fp.addLayers(rt.loadLayers());
        pkgBuilder.resetRoots();
        allPackages.put(rt.getFPID().getProducer().toString(), new HashMap<>());
        for (PackageRuntime pkg : rt.getPackages()) {
            if (checkPassive && pkg.isPassive() && !pkg.isPassiveIncluded()) {
                // exclude passives that don't match.
                continue;
            }
            allPackages.get(rt.getFPID().getProducer().toString()).put(pkg.getName(), pkg);
            pkgBuilder.buildGroups(new PackageInfo(pkg, Identity.fromChannel(rt.getFPID().getProducer(), pkg.getName()), plugin), new PackageGroupsBuilder.PackageInfoBuilder() {

                @Override
                public PackageInfo build(Identity identity, PackageInfo parent) {
                    try {
                        // Packages that have no origin, doesn't mean that they are local.
                        // It depends on the way FP dependencies have an origin or not.
                        // If a FP dependency has no origin, the "local" package could be
                        // located in this dependency.
                        FeaturePackRuntime currentRuntime = parent.getFeaturePackRuntime();
                        Identity resolvedIdentity = null;
                        PackageRuntime p = null;
                        if (identity.getOrigin().equals(Identity.EMPTY)) {
                            // First local to the parent package.
                            p = currentRuntime.getPackage(identity.getName());
                            if (p == null) {
                                // Then lookup dependencies with no origin.
                                for (FeaturePackConfig fpdep : currentRuntime.getSpec().getFeaturePackDeps()) {
                                    if (currentRuntime.getSpec().originOf(fpdep.getLocation().getProducer()) == null) {
                                        FeaturePackRuntime depRuntime = gavs.get(Identity.buildOrigin(fpdep.getLocation().getProducer()));
                                        p = depRuntime.getPackage(identity.getName());
                                        if (p != null) {
                                            resolvedIdentity = Identity.fromChannel(fpdep.getLocation().getProducer(), identity.getName());
                                            break;
                                        }
                                    }
                                }
                            } else {
                                resolvedIdentity = Identity.fromChannel(currentRuntime.getFPID().getProducer(), identity.getName());
                            }
                        } else {
                            // Could be a free text, maps that to ga. Only ga are exposed as origin for now.
                            // XXX JFDENISE, TODO, we could expose actual origin but would require to expose the mapping.
                            FeaturePackRuntime extRt = gavs.get(identity.getOrigin());
                            if (extRt == null) {
                                FeaturePackConfig fpdep = currentRuntime.getSpec().getFeaturePackDep(identity.getOrigin());
                                if (fpdep != null) {
                                    resolvedIdentity = Identity.fromChannel(fpdep.getLocation().getProducer(), identity.getName());
                                    extRt = gavs.get(resolvedIdentity.getOrigin());
                                }
                            } else {
                                resolvedIdentity = identity;
                            }
                            if (extRt != null) {
                                p = extRt.getPackage(identity.getName());
                            }
                        }
                        if (p == null) {
                            // Optional package that has been excluded
                            return null;
                        }
                        return new PackageInfo(p, resolvedIdentity, plugin);
                    } catch (IOException | ProvisioningException e) {
                        throw new RuntimeException(e);
                    }
                }
            });
        }
        fp.setPackagesRoot(Identity.buildOrigin(rt.getFPID().getProducer()), pkgBuilder.getPackagesRoot());
        // Attach the full set, this targets the container dependency that expose them all.
        if (allSpecs) {
            Group specsRoot = specsBuilder.buildTree(runtime.getLayout(), session, rt.getFPID(), fp.getFPID(), pkgBuilder.getPackages(), allSpecs, null);
            fp.setFeatureSpecRoot(Identity.buildOrigin(rt.getFPID().getProducer()), specsRoot);
        }
    }
    fp.setAllPackages(pkgBuilder.getPackages());
    Map<ProducerSpec, Set<ResolvedSpecId>> actualSet = new HashMap<>();
    Map<ResolvedSpecId, List<FeatureInfo>> features = new HashMap<>();
    for (ProvisionedConfig c : runtime.getConfigs()) {
        ConfigInfo config = new ConfigInfo(c.getModel(), c.getName(), c.getLayers());
        fp.addFinalConfig(config);
        FeatureGroupsBuilder grpBuilder = new FeatureGroupsBuilder();
        c.handle(new ProvisionedConfigHandler() {

            @Override
            public void nextFeature(ProvisionedFeature feature) throws ProvisioningException {
                FeaturePackRuntime rt = runtime.getFeaturePack(feature.getSpecId().getProducer());
                FeatureSpec featureSpec = rt.getFeatureSpec(feature.getSpecId().getName());
                ProducerSpec producer = feature.getSpecId().getProducer();
                for (PackageDependencySpec spec : featureSpec.getLocalPackageDeps()) {
                    PackageRuntime pkg = allPackages.get(producer.toString()).get(spec.getName());
                    if (pkg != null) {
                        if (includePassiveF && pkg.isPassive()) {
                            fp.addPassivePackage(producer.toString(), feature.getSpecId().getName(), spec.getName());
                        } else {
                            if (includeOptionalF && pkg.isOptional()) {
                                fp.addOptionalPackage(producer.toString(), feature.getSpecId().getName(), spec.getName());
                            }
                        }
                    }
                }
                if (featureSpec.hasExternalPackageDeps()) {
                    for (String origin : featureSpec.getPackageOrigins()) {
                        for (PackageDependencySpec spec : featureSpec.getExternalPackageDeps(origin)) {
                            PackageRuntime pkg = allPackages.get(origin).get(spec.getName());
                            if (pkg != null) {
                                if (includePassiveF && pkg.isPassive()) {
                                    fp.addPassivePackage(origin, feature.getSpecId().getName(), spec.getName());
                                } else if (includeOptionalF && pkg.isOptional()) {
                                    fp.addOptionalPackage(origin, feature.getSpecId().getName(), spec.getName());
                                }
                            }
                        }
                    }
                }
                Set<ResolvedSpecId> set = actualSet.get(feature.getSpecId().getProducer());
                if (set == null) {
                    set = new HashSet<>();
                    actualSet.put(feature.getSpecId().getProducer(), set);
                }
                set.add(feature.getSpecId());
                String fullSpecName = feature.getSpecId().getName();
                List<String> path = new ArrayList<>();
                Group parent = grpBuilder.buildFeatureGroups(fullSpecName, feature.getId(), path);
                FeatureInfo featInfo = new FeatureInfo(config, feature, path, fp.getFPID());
                List<FeatureInfo> lst = features.get(feature.getSpecId());
                if (lst == null) {
                    lst = new ArrayList<>();
                    features.put(feature.getSpecId(), lst);
                }
                lst.add(featInfo);
                parent.setFeature(featInfo);
                // Specs have already been computed first place.
                if (allSpecs) {
                    FeatureSpecInfo spec = specsBuilder.getAllSpecs().get(feature.getSpecId());
                    featInfo.attachSpecInfo(spec);
                    parent.setFeature(featInfo);
                }
            }
        });
        config.setFeatureGroupRoot(grpBuilder.getRoot());
    }
    // Handle packages that are not directly referenced from a feature.
    for (Entry<String, Map<String, PackageRuntime>> packageEntry : allPackages.entrySet()) {
        String producer = packageEntry.getKey();
        Set<String> allOptionals = new HashSet<>();
        Set<String> allPassives = new HashSet<>();
        Map<String, Set<String>> optionals = fp.getOptionalPackages().get(producer);
        if (optionals != null) {
            for (Set<String> vals : optionals.values()) {
                allOptionals.addAll(vals);
            }
        }
        Map<String, Set<String>> passives = fp.getPassivePackages().get(producer);
        if (passives != null) {
            for (Set<String> vals : passives.values()) {
                allPassives.addAll(vals);
            }
        }
        Map<String, PackageRuntime> packages = packageEntry.getValue();
        for (Entry<String, PackageRuntime> entry : packages.entrySet()) {
            String name = entry.getKey();
            PackageRuntime pkg = entry.getValue();
            if (!allOptionals.contains(name) && !allPassives.contains(name)) {
                if (includePassiveF && pkg.isPassive()) {
                    fp.addOrphanPassivePackage(producer, name);
                } else if (includeOptionalF && pkg.isOptional()) {
                    fp.addOrphanOptionalPackage(producer, name);
                }
            }
        }
    }
    if (!allSpecs) {
        // packages and feature-specs.
        for (Entry<ProducerSpec, Set<ResolvedSpecId>> entry : actualSet.entrySet()) {
            Group specsRoot = specsBuilder.buildTree(runtime.getLayout(), session, entry.getKey().getLocation().getFPID(), fp.getFPID(), pkgBuilder.getPackages(), false, entry.getValue());
            for (ResolvedSpecId rs : entry.getValue()) {
                List<FeatureInfo> lst = features.get(rs);
                for (FeatureInfo fi : lst) {
                    fi.attachSpecInfo(specsBuilder.getAllSpecs().get(rs));
                }
            }
            fp.setFeatureSpecRoot(Identity.buildOrigin(entry.getKey()), specsRoot);
        }
    }
    fp.seAllFeatureSpecs(specsBuilder.getAllSpecs());
    fp.setAllFeatures(features);
}
Also used : FeatureSpec(org.jboss.galleon.spec.FeatureSpec) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PackageRuntime(org.jboss.galleon.runtime.PackageRuntime) CliPlugin(org.jboss.galleon.plugin.CliPlugin) ProvisionedConfigHandler(org.jboss.galleon.plugin.ProvisionedConfigHandler) ProvisionedFeature(org.jboss.galleon.state.ProvisionedFeature) ResolvedSpecId(org.jboss.galleon.runtime.ResolvedSpecId) ProvisioningException(org.jboss.galleon.ProvisioningException) ArrayList(java.util.ArrayList) List(java.util.List) PackageDependencySpec(org.jboss.galleon.spec.PackageDependencySpec) ProvisionedConfig(org.jboss.galleon.state.ProvisionedConfig) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig) HashSet(java.util.HashSet) ProducerSpec(org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec) FeaturePackPluginVisitor(org.jboss.galleon.layout.FeaturePackPluginVisitor) FeaturePackRuntime(org.jboss.galleon.runtime.FeaturePackRuntime) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with ProvisionedConfig

use of org.jboss.galleon.state.ProvisionedConfig in project galleon by wildfly.

the class GetInfoCommand method displayConfigs.

private boolean displayConfigs(PmCommandInvocation commandInvocation, ProvisioningLayout<FeaturePackLayout> pLayout) throws ProvisioningException, IOException {
    Map<String, List<ConfigInfo>> configs = new HashMap<>();
    try (ProvisioningRuntime rt = ProvisioningRuntimeBuilder.newInstance(commandInvocation.getPmSession().getMessageWriter(false)).initRtLayout(pLayout.transform(ProvisioningRuntimeBuilder.FP_RT_FACTORY)).build()) {
        for (ProvisionedConfig m : rt.getConfigs()) {
            String model = m.getModel();
            List<ConfigInfo> names = configs.get(model);
            if (names == null) {
                names = new ArrayList<>();
                configs.put(model, names);
            }
            if (m.getName() != null) {
                names.add(new ConfigInfo(model, m.getName(), m.getLayers()));
            }
        }
        String str = StateInfoUtil.buildConfigs(configs, pLayout);
        if (str != null) {
            commandInvocation.print(str);
        }
        return str != null;
    }
}
Also used : HashMap(java.util.HashMap) ProvisioningRuntime(org.jboss.galleon.runtime.ProvisioningRuntime) ArrayList(java.util.ArrayList) List(java.util.List) ProvisionedConfig(org.jboss.galleon.state.ProvisionedConfig) ConfigInfo(org.jboss.galleon.cli.model.ConfigInfo)

Example 5 with ProvisionedConfig

use of org.jboss.galleon.state.ProvisionedConfig 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)

Aggregations

ProvisionedConfig (org.jboss.galleon.state.ProvisionedConfig)7 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 ProvisioningException (org.jboss.galleon.ProvisioningException)2 ConfigId (org.jboss.galleon.config.ConfigId)2 ProvisioningRuntime (org.jboss.galleon.runtime.ProvisioningRuntime)2 Path (java.nio.file.Path)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 ConfigInfo (org.jboss.galleon.cli.model.ConfigInfo)1 ConfigModel (org.jboss.galleon.config.ConfigModel)1 FeaturePackConfig (org.jboss.galleon.config.FeaturePackConfig)1 ProvisioningConfig (org.jboss.galleon.config.ProvisioningConfig)1 FeaturePackPluginVisitor (org.jboss.galleon.layout.FeaturePackPluginVisitor)1 CliPlugin (org.jboss.galleon.plugin.CliPlugin)1 ProvisionedConfigHandler (org.jboss.galleon.plugin.ProvisionedConfigHandler)1 FeaturePackRuntime (org.jboss.galleon.runtime.FeaturePackRuntime)1 PackageRuntime (org.jboss.galleon.runtime.PackageRuntime)1