Skip to content

Commit

Permalink
Merge pull request #221 from aloubyansky/skip-state-persistence
Browse files Browse the repository at this point in the history
[GAL-240] an option to not record provisioning state in .galleon dir
  • Loading branch information
aloubyansky authored Feb 1, 2019
2 parents ad45671 + 43922c0 commit 85aff9f
Show file tree
Hide file tree
Showing 17 changed files with 402 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,14 @@ protected void runCommand(PmCommandInvocation session, Map<String, String> optio
model,
config, loc).build(), options);
}
if (!loc.hasBuild()) {
loc = getManager(session).getProvisioningConfig().getFeaturePackDep(loc.getProducer()).getLocation();
}
session.println("Feature pack installed.");
StateInfoUtil.printFeaturePack(session,
session.getPmSession().getExposedLocation(manager.getInstallationHome(), loc));
if(manager.isRecordState()) {
if (!loc.hasBuild()) {
loc = manager.getProvisioningConfig().getFeaturePackDep(loc.getProducer()).getLocation();
}
StateInfoUtil.printFeaturePack(session,
session.getPmSession().getExposedLocation(manager.getInstallationHome(), loc));
}
} catch (ProvisioningException | IOException ex) {
throw new CommandExecutionException(session.getPmSession(), CliErrors.installFailed(), ex);
}
Expand Down
99 changes: 78 additions & 21 deletions core/src/main/java/org/jboss/galleon/ProvisioningManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public static class Builder extends UniverseResolverBuilder<Builder> {
private MessageWriter messageWriter;
private UniverseResolver resolver;
private boolean logTime;
private boolean recordState = true;

private Builder() {
}
Expand Down Expand Up @@ -129,6 +130,11 @@ public Builder setLogTime(boolean logTime) {
return this;
}

public Builder setRecordState(boolean recordState) {
this.recordState = recordState;
return this;
}

public ProvisioningManager build() throws ProvisioningException {
return new ProvisioningManager(this);
}
Expand All @@ -151,6 +157,7 @@ public static Builder builder() {
private ProvisioningLayoutFactory layoutFactory;
private boolean closeLayoutFactory;
private ProvisioningConfig provisioningConfig;
private boolean recordState;

private ProvisioningManager(Builder builder) throws ProvisioningException {
PathsUtils.assertInstallationDir(builder.installationHome);
Expand All @@ -165,6 +172,7 @@ private ProvisioningManager(Builder builder) throws ProvisioningException {
universeResolver = builder.getUniverseResolver();
}
this.logTime = builder.logTime;
this.recordState = builder.recordState;
}

/**
Expand Down Expand Up @@ -207,6 +215,19 @@ public void setLogTime(boolean logTime) {
this.logTime = logTime;
}

/**
* Whether provisioning state will be recorded after (re-)provisioning.
*
* @return true if the provisioning state is recorded after provisioning, otherwise false
*/
public boolean isRecordState() {
return recordState;
}

public void setRecordState(boolean recordState) {
this.recordState = recordState;
}

/**
* Add named universe spec to the provisioning configuration
*
Expand Down Expand Up @@ -619,7 +640,8 @@ private ProvisioningRuntime getRuntimeInternal(ProvisioningLayout<FeaturePackRun
.initRtLayout(layout)
.setEncoding(encoding)
.setLogTime(logTime)
.setFsDiff(fsDiff);
.setFsDiff(fsDiff)
.setRecordState(recordState);
if(setStagedDir) {
rtBuilder.setStagedDir(home);
}
Expand All @@ -630,26 +652,28 @@ private void doProvision(ProvisioningLayout<FeaturePackRuntimeBuilder> layout, F
final boolean freshInstall = PathsUtils.isNewHome(home);
try (ProvisioningRuntime runtime = getRuntimeInternal(layout, fsDiff, freshInstall)) {
runtime.provision();
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);
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);
}
} else {
IoUtils.recursiveDelete(stagedPath);
}
}
}
Expand All @@ -658,8 +682,41 @@ private void doProvision(ProvisioningLayout<FeaturePackRuntimeBuilder> layout, F
if (fsDiff != null && !fsDiff.isEmpty()) {
undoTasks = FsDiff.replay(fsDiff, runtime.getStagedDir(), log);
}
if(!freshInstall) {
PathsUtils.replaceDist(runtime.getStagedDir(), home, undo, undoTasks, 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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2018 Red Hat, Inc. and/or its affiliates
* Copyright 2016-2019 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2018 Red Hat, Inc. and/or its affiliates
* Copyright 2016-2019 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -383,8 +383,13 @@ public String toString() {
}
buf.append(fpl.toString());
if(!patches.isEmpty()) {
buf.append(" patches=");
StringUtils.append(buf, patches);
StringUtils.append(buf.append(" patches="), patches);
}
if(!excludedPackages.isEmpty()) {
StringUtils.append(buf.append(" excludedPackages="), excludedPackages);
}
if(!includedPackages.isEmpty()) {
StringUtils.append(buf.append(" includedPackages="), includedPackages.values());
}
append(buf);
return buf.append(']').toString();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2018 Red Hat, Inc. and/or its affiliates
* Copyright 2016-2019 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -27,6 +27,7 @@
import org.jboss.galleon.universe.FeaturePackLocation.ProducerSpec;
import org.jboss.galleon.universe.UniverseSpec;
import org.jboss.galleon.util.CollectionUtils;
import org.jboss.galleon.util.StringUtils;

/**
*
Expand Down Expand Up @@ -203,4 +204,24 @@ public boolean equals(Object obj) {
return false;
return true;
}

protected void append(StringBuilder buf) {
if(defaultUniverse != null) {
buf.append("default-universe=").append(defaultUniverse);
}
if(!universeSpecs.isEmpty()) {
if(defaultUniverse != null) {
buf.append(' ');
}
buf.append("universes=[");
StringUtils.append(buf, universeSpecs.entrySet());
buf.append("] ");
}
if(!transitiveDeps.isEmpty()) {
StringUtils.append(buf.append("transitive="), transitiveDeps.values());
buf.append(' ');
}
StringUtils.append(buf, fpDeps.values());
super.append(buf);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2018 Red Hat, Inc. and/or its affiliates
* Copyright 2016-2019 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -61,4 +61,9 @@ public boolean equals(Object obj) {
return false;
return true;
}

@Override
public String toString() {
return name;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2018 Red Hat, Inc. and/or its affiliates
* Copyright 2016-2019 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -176,28 +176,11 @@ public boolean equals(Object obj) {
@Override
public String toString() {
final StringBuilder buf = new StringBuilder().append('[');
if(defaultUniverse != null) {
buf.append("default-universe=").append(defaultUniverse);
}
if(!universeSpecs.isEmpty()) {
if(defaultUniverse != null) {
buf.append(' ');
}
buf.append("universes=[");
StringUtils.append(buf, universeSpecs.entrySet());
buf.append("] ");
}
append(buf);
if(!options.isEmpty()) {
buf.append("options=");
StringUtils.append(buf, options.entrySet());
}
if(!transitiveDeps.isEmpty()) {
buf.append("transitive=");
StringUtils.append(buf, transitiveDeps.values());
buf.append(' ');
}
StringUtils.append(buf, fpDeps.values());
append(buf);
return buf.append(']').toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class ProvisioningRuntime implements FeaturePackSet<FeaturePackRuntime>,
private final ProvisioningLayout<FeaturePackRuntime> layout;
private final MessageWriter messageWriter;
private Boolean emptyStagedDir;
private final boolean recordState;
private List<ProvisionedConfig> configs = Collections.emptyList();

ProvisioningRuntime(final ProvisioningRuntimeBuilder builder, final MessageWriter messageWriter) throws ProvisioningException {
Expand Down Expand Up @@ -99,6 +100,7 @@ public FeaturePackRuntime transform(FeaturePackRuntimeBuilder other) throws Prov
throw e;
}

this.recordState = builder.recordState;
this.messageWriter = messageWriter;
}

Expand Down Expand Up @@ -306,18 +308,20 @@ public void visitPlugin(InstallPlugin plugin) throws ProvisioningException {
}
}, InstallPlugin.class);

// save the config
try {
ProvisioningXmlWriter.getInstance().write(config, PathsUtils.getProvisioningXml(stagedDir));
} catch (XMLStreamException | IOException e) {
throw new FeaturePackInstallException(Errors.writeFile(PathsUtils.getProvisioningXml(stagedDir)), e);
}
if(recordState) {
// save the config
try {
ProvisioningXmlWriter.getInstance().write(config, PathsUtils.getProvisioningXml(stagedDir));
} catch (XMLStreamException | IOException e) {
throw new FeaturePackInstallException(Errors.writeFile(PathsUtils.getProvisioningXml(stagedDir)), e);
}

// save the provisioned state
try {
ProvisionedStateXmlWriter.getInstance().write(this, PathsUtils.getProvisionedStateXml(stagedDir));
} catch (XMLStreamException | IOException e) {
throw new FeaturePackInstallException(Errors.writeFile(PathsUtils.getProvisionedStateXml(stagedDir)), e);
// save the provisioned state
try {
ProvisionedStateXmlWriter.getInstance().write(this, PathsUtils.getProvisionedStateXml(stagedDir));
} catch (XMLStreamException | IOException e) {
throw new FeaturePackInstallException(Errors.writeFile(PathsUtils.getProvisionedStateXml(stagedDir)), e);
}
}

emptyStagedDir = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public static ProvisioningRuntimeBuilder newInstance(final MessageWriter message
ProvisioningConfig config;
ProvisioningLayout<FeaturePackRuntimeBuilder> layout;
Path stagedDir;
boolean recordState;
FsDiff fsDiff;
private final MessageWriter messageWriter;

Expand Down Expand Up @@ -153,6 +154,11 @@ public ProvisioningRuntimeBuilder setStagedDir(Path p) {
return this;
}

public ProvisioningRuntimeBuilder setRecordState(boolean recordState) {
this.recordState = recordState;
return this;
}

public ProvisioningRuntime build() throws ProvisioningException {
try {
return doBuild();
Expand Down
Loading

0 comments on commit 85aff9f

Please sign in to comment.