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