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;
}
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;
}
}
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;
}
}
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;
}
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;
}
}
Aggregations