Search in sources :

Example 1 with ProvisioningRuntime

use of org.jboss.galleon.runtime.ProvisioningRuntime in project galleon by wildfly.

the class FeatureContainers method buildFullRuntime.

private static ProvisioningRuntime buildFullRuntime(FPID fpid, PmSession pmSession) throws ProvisioningException {
    FeaturePackConfig config = FeaturePackConfig.forLocation(fpid.getLocation());
    ProvisioningConfig provisioning = ProvisioningConfig.builder().addFeaturePackDep(config).build();
    ProvisioningRuntime runtime = ProvisioningRuntimeBuilder.newInstance(pmSession.getMessageWriter(false)).initLayout(pmSession.getLayoutFactory(), provisioning).build();
    return runtime;
}
Also used : ProvisioningConfig(org.jboss.galleon.config.ProvisioningConfig) ProvisioningRuntime(org.jboss.galleon.runtime.ProvisioningRuntime) FeaturePackConfig(org.jboss.galleon.config.FeaturePackConfig)

Example 2 with ProvisioningRuntime

use of org.jboss.galleon.runtime.ProvisioningRuntime in project galleon by wildfly.

the class ProvisioningManager method doProvision.

private void doProvision(ProvisioningLayout<FeaturePackRuntimeBuilder> layout, FsDiff fsDiff, boolean undo) throws ProvisioningException {
    final boolean freshInstall = PathsUtils.isNewHome(home);
    try (ProvisioningRuntime runtime = getRuntimeInternal(layout, fsDiff, freshInstall)) {
        runtime.provision();
        if (recordState) {
            if (runtime.getProvisioningConfig().hasFeaturePackDeps()) {
                persistHashes(runtime);
            }
            if (undo) {
                final Map<String, Boolean> undoTasks = StateHistoryUtils.readUndoTasks(home, log);
                if (!undoTasks.isEmpty()) {
                    final Path staged = runtime.getStagedDir();
                    for (Map.Entry<String, Boolean> entry : undoTasks.entrySet()) {
                        final Path stagedPath = staged.resolve(entry.getKey());
                        if (entry.getValue()) {
                            final Path homePath = home.resolve(entry.getKey());
                            if (Files.exists(homePath)) {
                                try {
                                    IoUtils.copy(homePath, stagedPath);
                                } catch (IOException e) {
                                    throw new ProvisioningException(Errors.copyFile(homePath, stagedPath), e);
                                }
                            }
                        } else {
                            IoUtils.recursiveDelete(stagedPath);
                        }
                    }
                }
            }
        }
        Map<String, Boolean> undoTasks = Collections.emptyMap();
        if (fsDiff != null && !fsDiff.isEmpty()) {
            undoTasks = FsDiff.replay(fsDiff, runtime.getStagedDir(), log);
        }
        if (freshInstall) {
            return;
        }
        log.verbose("Moving the provisioned installation from the staged directory to %s", home);
        final Path stagedDir = runtime.getStagedDir();
        // copy from the staged to the target installation directory
        if (Files.exists(home)) {
            if (recordState) {
                if (undo) {
                    StateHistoryUtils.removeLastUndoConfig(home, stagedDir, log);
                } else {
                    StateHistoryUtils.addNewUndoConfig(home, stagedDir, undoTasks, log);
                }
                IoUtils.recursiveDelete(home);
            } else if (Files.exists(PathsUtils.getProvisionedStateDir(home))) {
                try (DirectoryStream<Path> stream = Files.newDirectoryStream(home)) {
                    for (Path p : stream) {
                        if (p.getFileName().toString().equals(Constants.PROVISIONED_STATE_DIR)) {
                            continue;
                        }
                        IoUtils.recursiveDelete(p);
                    }
                } catch (IOException e) {
                    throw new ProvisioningException(Errors.readDirectory(home), e);
                }
            } else {
                IoUtils.recursiveDelete(home);
            }
        }
        try {
            IoUtils.copy(stagedDir, home);
        } catch (IOException e) {
            throw new ProvisioningException(Errors.copyFile(stagedDir, home));
        }
    } finally {
        this.provisioningConfig = null;
    }
}
Also used : Path(java.nio.file.Path) ProvisioningRuntime(org.jboss.galleon.runtime.ProvisioningRuntime) DirectoryStream(java.nio.file.DirectoryStream) IOException(java.io.IOException) Map(java.util.Map)

Example 3 with ProvisioningRuntime

use of org.jboss.galleon.runtime.ProvisioningRuntime 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 4 with ProvisioningRuntime

use of org.jboss.galleon.runtime.ProvisioningRuntime in project galleon by wildfly.

the class StateProvisionCommand method getDynamicOptions.

@Override
protected List<AbstractDynamicCommand.DynamicOption> getDynamicOptions(State state) throws Exception {
    if (state == null) {
        return Collections.emptyList();
    }
    List<AbstractDynamicCommand.DynamicOption> options = new ArrayList<>();
    ProvisioningRuntime rt = state.getRuntime();
    Set<ProvisioningOption> opts = getPluginOptions(rt);
    for (ProvisioningOption opt : opts) {
        AbstractDynamicCommand.DynamicOption dynOption = new AbstractDynamicCommand.DynamicOption(opt.getName(), opt.isRequired());
        options.add(dynOption);
    }
    return options;
}
Also used : ProvisioningRuntime(org.jboss.galleon.runtime.ProvisioningRuntime) ArrayList(java.util.ArrayList) ProvisioningOption(org.jboss.galleon.ProvisioningOption) AbstractDynamicCommand(org.jboss.galleon.cli.cmd.AbstractDynamicCommand)

Example 5 with ProvisioningRuntime

use of org.jboss.galleon.runtime.ProvisioningRuntime in project galleon by wildfly.

the class GetInfoCommand method displayOptionalPackages.

private boolean displayOptionalPackages(PmCommandInvocation commandInvocation, ProvisioningLayout<FeaturePackLayout> pLayout) throws ProvisioningException, IOException {
    try (ProvisioningRuntime rt = ProvisioningRuntimeBuilder.newInstance(commandInvocation.getPmSession().getMessageWriter(false)).initRtLayout(pLayout.transform(ProvisioningRuntimeBuilder.FP_RT_FACTORY)).build()) {
        FeatureContainer container = FeatureContainers.fromProvisioningRuntime(commandInvocation.getPmSession(), rt);
        String str = StateInfoUtil.buildOptionalPackages(commandInvocation.getPmSession(), container, pLayout);
        if (str != null) {
            commandInvocation.print(str);
        }
        return str != null;
    }
}
Also used : ProvisioningRuntime(org.jboss.galleon.runtime.ProvisioningRuntime) FeatureContainer(org.jboss.galleon.cli.model.FeatureContainer)

Aggregations

ProvisioningRuntime (org.jboss.galleon.runtime.ProvisioningRuntime)9 ProvisioningConfig (org.jboss.galleon.config.ProvisioningConfig)4 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 FeatureContainer (org.jboss.galleon.cli.model.FeatureContainer)2 ProvisionedConfig (org.jboss.galleon.state.ProvisionedConfig)2 IOException (java.io.IOException)1 DirectoryStream (java.nio.file.DirectoryStream)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 ProvisioningManager (org.jboss.galleon.ProvisioningManager)1 ProvisioningOption (org.jboss.galleon.ProvisioningOption)1 CommandExecutionException (org.jboss.galleon.cli.CommandExecutionException)1 AbstractDynamicCommand (org.jboss.galleon.cli.cmd.AbstractDynamicCommand)1 ConfigInfo (org.jboss.galleon.cli.model.ConfigInfo)1 ConfigId (org.jboss.galleon.config.ConfigId)1 ConfigModel (org.jboss.galleon.config.ConfigModel)1 FeaturePackConfig (org.jboss.galleon.config.FeaturePackConfig)1 FsDiff (org.jboss.galleon.diff.FsDiff)1