Search in sources :

Example 16 with ProvisioningConfig

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

the class ProvisioningManager method persistChanges.

/**
 * Merge user changes recognized by the provisioning plug-ins (such as
 * changes to the configuration files) into the provisioning configuration
 * file describing the state of the installation).
 *
 * @return true if some changes have been persisted, false otherwise.
 * @throws ProvisioningException  in case the merge fails
 */
public boolean persistChanges() throws ProvisioningException {
    final ProvisioningDiffProvider diffProvider = getDiffMergedConfig();
    if (diffProvider == null) {
        return false;
    }
    final ProvisioningConfig mergedConfig = diffProvider.getMergedConfig();
    if (mergedConfig.equals(getProvisioningConfig())) {
        return false;
    }
    try (ProvisioningLayout<FeaturePackRuntimeBuilder> layout = getLayoutFactory().newConfigLayout(mergedConfig, ProvisioningRuntimeBuilder.FP_RT_FACTORY, false)) {
        doProvision(layout, diffProvider.getFsDiff(), false);
    }
    return true;
}
Also used : ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) FeaturePackRuntimeBuilder(org.jboss.galleon.runtime.FeaturePackRuntimeBuilder) ProvisioningDiffProvider(org.jboss.galleon.diff.ProvisioningDiffProvider)

Example 17 with ProvisioningConfig

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

the class State method buildNewConfig.

private ProvisioningConfig buildNewConfig(PmSession pmSession) throws ProvisioningException, IOException {
    ProvisioningConfig tmp = builder.build();
    if (runtime != null) {
        runtime.close();
    }
    runtime = ProvisioningRuntimeBuilder.newInstance(pmSession.getMessageWriter(false)).initLayout(pmSession.getLayoutFactory(), tmp).build();
    try {
        Set<FeaturePackLocation.FPID> dependencies = new HashSet<>();
        for (FeaturePackRuntime rt : runtime.getFeaturePacks()) {
            dependencies.add(rt.getFPID());
        }
        FeatureContainer tmpContainer = FeatureContainers.fromProvisioningRuntime(pmSession, runtime);
        // Need to have in sync the current with the full.
        // If fullConainer creation is a failure, the container will be not updated.
        Map<String, FeatureContainer> tmpDeps = new HashMap<>();
        if (container != null) {
            tmpDeps.putAll(container.getFullDependencies());
        }
        buildDependencies(pmSession, dependencies, tmpDeps);
        container = tmpContainer;
        container.setEdit(true);
        container.setFullDependencies(tmpDeps);
    } catch (ProvisioningException ex) {
        runtime.close();
        throw ex;
    }
    return tmp;
}
Also used : ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) HashMap(java.util.HashMap) ProvisioningException(org.jboss.galleon.ProvisioningException) FeaturePackRuntime(org.jboss.galleon.runtime.FeaturePackRuntime) FeatureContainer(org.jboss.galleon.cli.model.FeatureContainer) HashSet(java.util.HashSet)

Example 18 with ProvisioningConfig

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

the class State method pushState.

private ProvisioningConfig pushState(Action action, PmSession pmSession) throws IOException, ProvisioningException {
    action.doAction(config, builder);
    try {
        ProvisioningConfig newConfig = buildNewConfig(pmSession);
        stack.push(action);
        return newConfig;
    } catch (Exception ex) {
        // ex.printStackTrace();
        try {
            action.undoAction(builder);
        } catch (Exception ex2) {
            ex.addSuppressed(ex2);
        }
        throw ex;
    }
}
Also used : ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) IOException(java.io.IOException) ProvisioningException(org.jboss.galleon.ProvisioningException)

Example 19 with ProvisioningConfig

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

the class ProvisioningLayout method apply.

public void apply(ProvisioningPlan plan, Map<String, String> pluginOptions) throws ProvisioningException {
    if (plan.isEmpty()) {
        return;
    }
    final ProvisioningConfig.Builder configBuilder = ProvisioningConfig.builder(config);
    if (plan.hasUpdates()) {
        Map<ProducerSpec, FeaturePackUpdatePlan> updates = plan.getUpdateMap();
        Set<ProducerSpec> processed = new HashSet<>(updates.size());
        for (FeaturePackConfig fpConfig : config.getFeaturePackDeps()) {
            final ProducerSpec producer = fpConfig.getLocation().getProducer();
            final FeaturePackUpdatePlan fpPlan = updates.get(producer);
            if (fpPlan != null && !fpPlan.isEmpty()) {
                if (!fpPlan.getInstalledLocation().equals(fpConfig.getLocation())) {
                    throw new ProvisioningException("Location in the update plan " + fpPlan.getInstalledLocation() + " does not match the installed location " + fpConfig.getLocation());
                }
                final FeaturePackConfig.Builder fpBuilder = FeaturePackConfig.builder(fpPlan.getNewLocation()).init(fpConfig);
                if (fpPlan.hasNewPatches()) {
                    for (FPID patchId : fpPlan.getNewPatches()) {
                        fpBuilder.addPatch(patchId);
                    }
                }
                configBuilder.updateFeaturePackDep(fpBuilder.build());
                processed.add(producer);
            }
        }
        for (FeaturePackConfig fpConfig : config.getTransitiveDeps()) {
            final ProducerSpec producer = fpConfig.getLocation().getProducer();
            final FeaturePackUpdatePlan fpPlan = updates.get(producer);
            if (fpPlan != null && !fpPlan.isEmpty()) {
                if (fpConfig.getLocation().getBuild() != null && !fpPlan.getInstalledLocation().equals(fpConfig.getLocation())) {
                    throw new ProvisioningException("Update plan build " + fpPlan.getInstalledLocation() + " does not match the installed build " + fpConfig.getLocation());
                }
                final FeaturePackConfig.Builder fpBuilder = FeaturePackConfig.transitiveBuilder(fpPlan.getNewLocation()).init(fpConfig);
                if (fpPlan.hasNewPatches()) {
                    for (FPID patchId : fpPlan.getNewPatches()) {
                        fpBuilder.addPatch(patchId);
                    }
                }
                configBuilder.updateFeaturePackDep(fpBuilder.build());
                processed.add(producer);
            }
        }
        if (processed.size() < updates.size()) {
            for (Map.Entry<ProducerSpec, FeaturePackUpdatePlan> entry : updates.entrySet()) {
                if (processed.contains(entry.getKey())) {
                    continue;
                }
                final FeaturePackUpdatePlan update = entry.getValue();
                final FeaturePackConfig.Builder fpBuilder = FeaturePackConfig.transitiveBuilder(update.getNewLocation());
                if (update.hasNewPatches()) {
                    for (FPID patchId : update.getNewPatches()) {
                        fpBuilder.addPatch(patchId);
                    }
                }
                configBuilder.addFeaturePackDep(fpBuilder.build());
            }
        }
    }
    if (plan.hasInstall()) {
        for (FeaturePackConfig fpConfig : plan.getInstall()) {
            install(fpConfig, configBuilder);
        }
    }
    if (plan.hasUninstall()) {
        for (ProducerSpec producer : plan.getUninstall()) {
            uninstall(producer.getLocation().getFPID(), configBuilder);
        }
    }
    final ProvisioningConfig config = configBuilder.build();
    initBuiltInOptions(config, pluginOptions);
    rebuild(config, true);
    initPluginOptions(pluginOptions, plan.hasUninstall());
}
Also used : FPID(org.jboss.galleon.universe.FeaturePackLocation.FPID) ProducerSpec(org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec) ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) ProvisioningException(org.jboss.galleon.ProvisioningException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig)

Example 20 with ProvisioningConfig

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

the class GetInfoCommand method runCommand.

@Override
protected void runCommand(PmCommandInvocation commandInvocation) throws CommandExecutionException {
    if (fpl != null && file != null) {
        throw new CommandExecutionException("File and location can't be both set");
    }
    if (fpl == null && file == null) {
        throw new CommandExecutionException("File or location must be set");
    }
    PmSession session = commandInvocation.getPmSession();
    FeaturePackLayout product = null;
    List<FeaturePackLocation> dependencies = new ArrayList<>();
    ProvisioningConfig provisioning;
    ProvisioningLayout<FeaturePackLayout> layout = null;
    try {
        try {
            if (fpl != null) {
                FeaturePackLocation loc;
                loc = session.getResolvedLocation(null, fpl);
                FeaturePackConfig config = FeaturePackConfig.forLocation(loc);
                provisioning = ProvisioningConfig.builder().addFeaturePackDep(config).build();
                layout = session.getLayoutFactory().newConfigLayout(provisioning);
            } else {
                layout = session.getLayoutFactory().newConfigLayout(file.toPath(), true);
            }
            for (FeaturePackLayout fpLayout : layout.getOrderedFeaturePacks()) {
                boolean isProduct = true;
                for (FeaturePackLayout fpLayout2 : layout.getOrderedFeaturePacks()) {
                    if (fpLayout2.getSpec().hasTransitiveDep(fpLayout.getFPID().getProducer()) || fpLayout2.getSpec().getFeaturePackDep(fpLayout.getFPID().getProducer()) != null) {
                        isProduct = false;
                        break;
                    }
                }
                if (isProduct) {
                    product = fpLayout;
                } else {
                    dependencies.add(session.getExposedLocation(null, fpLayout.getFPID().getLocation()));
                }
            }
        } catch (ProvisioningException ex) {
            throw new CommandExecutionException(commandInvocation.getPmSession(), CliErrors.infoFailed(), ex);
        }
        if (product == null) {
            throw new CommandExecutionException("No feature-pack found");
        }
        commandInvocation.println("");
        StateInfoUtil.printFeaturePack(commandInvocation, session.getExposedLocation(null, product.getFPID().getLocation()));
        try {
            final FPID patchFor = product.getSpec().getPatchFor();
            if (patchFor != null) {
                commandInvocation.println("");
                commandInvocation.println(PATCH_FOR + patchFor);
            }
        } catch (ProvisioningException e) {
            throw new CommandExecutionException(commandInvocation.getPmSession(), CliErrors.infoFailed(), e);
        }
        try {
            if (type != null) {
                commandInvocation.println("");
                switch(type) {
                    case ALL:
                        {
                            if (displayDependencies(commandInvocation, dependencies)) {
                                commandInvocation.println("");
                            }
                            if (displayConfigs(commandInvocation, layout)) {
                                commandInvocation.println("");
                            }
                            if (displayLayers(commandInvocation, layout)) {
                                commandInvocation.println("");
                            }
                            if (displayOptionalPackages(commandInvocation, layout)) {
                                commandInvocation.println("");
                            }
                            displayOptions(commandInvocation, layout);
                            break;
                        }
                    case CONFIGS:
                        {
                            if (!displayConfigs(commandInvocation, layout)) {
                                commandInvocation.println(StateInfoUtil.NO_CONFIGURATIONS);
                            }
                            break;
                        }
                    case DEPENDENCIES:
                        {
                            if (!displayDependencies(commandInvocation, dependencies)) {
                                commandInvocation.println(StateInfoUtil.NO_DEPENDENCIES);
                            }
                            break;
                        }
                    case LAYERS:
                        {
                            if (!displayLayers(commandInvocation, layout)) {
                                commandInvocation.println(StateInfoUtil.NO_LAYERS);
                            }
                            break;
                        }
                    case OPTIONS:
                        {
                            if (!displayOptions(commandInvocation, layout)) {
                                commandInvocation.println(StateInfoUtil.NO_OPTIONS);
                            }
                            break;
                        }
                    case OPTIONAL_PACKAGES:
                        {
                            if (!displayOptionalPackages(commandInvocation, layout)) {
                                commandInvocation.println(StateInfoUtil.NO_OPTIONAL_PACKAGES);
                            }
                            break;
                        }
                    default:
                        {
                            throw new CommandExecutionException(CliErrors.invalidInfoType());
                        }
                }
            }
        } catch (ProvisioningException | IOException ex) {
            throw new CommandExecutionException(commandInvocation.getPmSession(), CliErrors.infoFailed(), ex);
        }
    } finally {
        if (layout != null) {
            layout.close();
        }
    }
}
Also used : FPID(org.jboss.galleon.universe.FeaturePackLocation.FPID) ArrayList(java.util.ArrayList) FeaturePackLocation(org.jboss.galleon.universe.FeaturePackLocation) IOException(java.io.IOException) ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) PmSession(org.jboss.galleon.cli.PmSession) FeaturePackLayout(org.jboss.galleon.layout.FeaturePackLayout) ProvisioningException(org.jboss.galleon.ProvisioningException) CommandExecutionException(org.jboss.galleon.cli.CommandExecutionException) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig)

Aggregations

ProvisioningConfig (org.jboss.galleon.config.ProvisioningConfig)47 Test (org.junit.Test)16 Path (java.nio.file.Path)15 FeaturePackConfig (org.jboss.galleon.config.FeaturePackConfig)12 ProvisioningException (org.jboss.galleon.ProvisioningException)10 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)6 ProvisioningManager (org.jboss.galleon.ProvisioningManager)6 CommandExecutionException (org.jboss.galleon.cli.CommandExecutionException)6 ConfigId (org.jboss.galleon.config.ConfigId)6 FeaturePackLocation (org.jboss.galleon.universe.FeaturePackLocation)6 CommandException (org.aesh.command.CommandException)5 ConfigModel (org.jboss.galleon.config.ConfigModel)5 HashMap (java.util.HashMap)4 FeaturePackLayout (org.jboss.galleon.layout.FeaturePackLayout)4 FeaturePackRuntimeBuilder (org.jboss.galleon.runtime.FeaturePackRuntimeBuilder)4 ProvisioningRuntime (org.jboss.galleon.runtime.ProvisioningRuntime)4 FPID (org.jboss.galleon.universe.FeaturePackLocation.FPID)4 UniverseSpec (org.jboss.galleon.universe.UniverseSpec)4 HashSet (java.util.HashSet)3