use of org.jboss.as.patching.tool.PatchingResult in project wildfly-core by wildfly.
the class LayerTestCase method patchLayer.
@Test
public void patchLayer() throws Exception {
// add a layer
// randomString();
String layerName = "mylayer";
installLayers(layerName);
InstalledIdentity installedIdentity = loadInstalledIdentity();
// build a one-off patch for the layer with 1 added module
// and 1 add file
String patchID = randomString();
File patchDir = mkdir(tempDir, patchID);
// randomString();
String layerPatchId = "mylayerPatchID";
String moduleName = randomString();
ContentModification moduleAdded = ContentModificationUtils.addModule(patchDir, layerPatchId, moduleName);
ContentModification fileAdded = ContentModificationUtils.addMisc(patchDir, patchID, "new file resource", "bin", "my-new-standalone.sh");
Patch patch = PatchBuilder.create().setPatchId(patchID).oneOffPatchIdentity(installedIdentity.getIdentity().getName(), installedIdentity.getIdentity().getVersion()).getParent().oneOffPatchElement(layerPatchId, layerName, false).addContentModification(moduleAdded).getParent().addContentModification(fileAdded).build();
createPatchXMLFile(patchDir, patch);
File zippedPatch = createZippedPatchFile(patchDir, patchID);
// apply patch
PatchingResult result = executePatch(zippedPatch);
assertPatchHasBeenApplied(result, patch);
InstalledIdentity patchedInstalledIdentity = loadInstalledIdentity();
assertInstallationIsPatched(patch, patchedInstalledIdentity.getIdentity().loadTargetInfo());
assertFileExists(env.getInstalledImage().getJbossHome(), "bin", fileAdded.getItem().getName());
DirectoryStructure layerDirStructure = installedIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure();
File modulesPatchDir = layerDirStructure.getModulePatchDirectory(layerPatchId);
assertDirExists(modulesPatchDir);
assertDefinedModule(modulesPatchDir, moduleName, moduleAdded.getItem().getContentHash());
}
use of org.jboss.as.patching.tool.PatchingResult in project wildfly-core by wildfly.
the class IdentityPatchContext method finalize.
/**
* Finalize the patch.
*
* @param callback the finalize callback
* @return the result
* @throws Exception
*/
protected PatchingResult finalize(final FinalizeCallback callback) throws Exception {
assert state == State.NEW;
final Patch original = callback.getPatch();
final Patch.PatchType patchType = original.getIdentity().getPatchType();
final String patchId;
if (patchType == Patch.PatchType.CUMULATIVE) {
patchId = modification.getCumulativePatchID();
} else {
patchId = original.getPatchId();
}
try {
// The processed patch, based on the recorded changes
final Patch processedPatch = createProcessedPatch(original);
// The rollback containing all the recorded rollback actions
final RollbackPatch rollbackPatch = createRollbackPatch(patchId, patchType);
callback.finishPatch(processedPatch, rollbackPatch, this);
} catch (Exception e) {
if (undoChanges()) {
callback.operationCancelled(this);
}
throw e;
}
state = State.PREPARED;
return new PatchingResult() {
@Override
public String getPatchId() {
return original.getPatchId();
}
@Override
public PatchInfo getPatchInfo() {
return new PatchInfo() {
@Override
public String getVersion() {
return identityEntry.getResultingVersion();
}
@Override
public String getCumulativePatchID() {
return identityEntry.delegate.getModifiedState().getCumulativePatchID();
}
@Override
public List<String> getPatchIDs() {
return identityEntry.delegate.getModifiedState().getPatchIDs();
}
};
}
@Override
public void commit() {
if (state == State.PREPARED) {
complete(modification, callback);
} else {
undoChanges();
throw new IllegalStateException();
}
}
@Override
public void rollback() {
if (undoChanges()) {
try {
callback.operationCancelled(IdentityPatchContext.this);
} finally {
modification.cancel();
}
}
}
};
}
use of org.jboss.as.patching.tool.PatchingResult in project wildfly-core by wildfly.
the class PatchToolImpl method applyPatchBundle.
protected PatchingResult applyPatchBundle(final File workDir, final BundledPatch bundledPatch, final ContentVerificationPolicy contentPolicy) throws PatchingException, IOException {
final List<BundledPatchEntry> patches = bundledPatch.getPatches();
if (patches.isEmpty()) {
throw new PatchingException(PatchLogger.ROOT_LOGGER.patchBundleIsEmpty());
}
PatchingResult result = null;
BundledPatchEntry lastCommittedEntry = null;
final List<BundledPatch.BundledPatchEntry> results = new ArrayList<BundledPatch.BundledPatchEntry>(patches.size());
final List<InstalledIdentity> installedIdentities = manager.getInstalledIdentities();
for (BundledPatchEntry entry : patches) {
// TODO this has to be checked against the specific one targeted by the patch
boolean alreadyApplied = false;
for (InstalledIdentity identity : installedIdentities) {
if (identity.getAllInstalledPatches().contains(entry.getPatchId())) {
alreadyApplied = true;
break;
}
}
if (alreadyApplied) {
continue;
}
if (result != null) {
result.commit();
results.add(0, lastCommittedEntry);
}
final File patch = new File(workDir, entry.getPatchPath());
final FileInputStream is = new FileInputStream(patch);
PatchingResult currentResult = null;
try {
currentResult = applyPatch(workDir, is, contentPolicy);
} catch (PatchingException e) {
// Undo the changes included as part of this patch
for (BundledPatch.BundledPatchEntry committed : results) {
try {
rollback(committed.getPatchId(), contentPolicy, false, false).commit();
} catch (PatchingException oe) {
PatchLogger.ROOT_LOGGER.debugf(oe, "failed to rollback patch '%s'", committed.getPatchId());
}
}
throw e;
} finally {
safeClose(is);
}
if (currentResult != null) {
result = currentResult;
lastCommittedEntry = entry;
}
}
if (result == null) {
throw new PatchingException();
}
return new WrappedMultiInstallPatch(result, contentPolicy, results);
}
use of org.jboss.as.patching.tool.PatchingResult in project wildfly-core by wildfly.
the class LocalPatchOperationStepHandler method executeRuntime.
private void executeRuntime(final OperationContext context, final ModelNode operation) throws OperationFailedException {
// Acquire the lock and check the write permissions for this operation
final ServiceRegistry registry = context.getServiceRegistry(true);
final InstallationManager installationManager = (InstallationManager) registry.getRequiredService(InstallationManagerService.NAME).getValue();
if (installationManager.requiresRestart()) {
throw PatchLogger.ROOT_LOGGER.serverRequiresRestart();
}
try {
final PatchTool runner = PatchTool.Factory.create(installationManager);
final ContentVerificationPolicy policy = PatchTool.Factory.create(operation);
final int index = operation.get(ModelDescriptionConstants.INPUT_STREAM_INDEX).asInt(0);
final InputStream is = context.getAttachmentStream(index);
installationManager.restartRequired();
final PatchingResult result = runner.applyPatch(is, policy);
context.restartRequired();
context.completeStep(new OperationContext.ResultHandler() {
@Override
public void handleResult(OperationContext.ResultAction resultAction, OperationContext context, ModelNode operation) {
if (resultAction == OperationContext.ResultAction.KEEP) {
result.commit();
} else {
installationManager.clearRestartRequired();
context.revertRestartRequired();
result.rollback();
}
}
});
} catch (PatchingException e) {
final ModelNode failureDescription = context.getFailureDescription();
PatchOperationTarget.formatFailedResponse(e, failureDescription);
installationManager.clearRestartRequired();
}
}
use of org.jboss.as.patching.tool.PatchingResult in project wildfly-core by wildfly.
the class AddOnTestCase method patchAddOn.
@Test
public void patchAddOn() throws Exception {
// start from a base installation
// add an add-on
String addOnName = randomString();
installAddOn(env.getModuleRoot(), addOnName);
InstalledIdentity installedIdentity = loadInstalledIdentity();
// build a one-off patch for the add-on with 1 added module
// and 1 add file
String patchID = randomString();
File patchDir = mkdir(tempDir, patchID);
String addOnPatchID = randomString();
String moduleName = randomString();
ContentModification moduleAdded = ContentModificationUtils.addModule(patchDir, addOnPatchID, moduleName);
ContentModification fileAdded = ContentModificationUtils.addMisc(patchDir, patchID, "new file resource", "bin", "my-new-standalone.sh");
Patch patch = PatchBuilder.create().setPatchId(patchID).oneOffPatchIdentity(installedIdentity.getIdentity().getName(), installedIdentity.getIdentity().getVersion()).getParent().oneOffPatchElement(addOnPatchID, addOnName, true).addContentModification(moduleAdded).getParent().addContentModification(fileAdded).build();
createPatchXMLFile(patchDir, patch);
File zippedPatch = createZippedPatchFile(patchDir, patchID);
// apply patch
PatchingResult result = executePatch(zippedPatch);
assertPatchHasBeenApplied(result, patch);
InstalledIdentity patchedInstalledIdentity = InstalledIdentity.load(env.getInstalledImage().getJbossHome(), productConfig, env.getInstalledImage().getModulesDir());
assertInstallationIsPatched(patch, patchedInstalledIdentity.getIdentity().loadTargetInfo());
assertFileExists(env.getInstalledImage().getJbossHome(), "bin", fileAdded.getItem().getName());
DirectoryStructure addOnStructure = installedIdentity.getAddOns().iterator().next().loadTargetInfo().getDirectoryStructure();
File modulesPatchDir = addOnStructure.getModulePatchDirectory(addOnPatchID);
assertDirExists(modulesPatchDir);
assertDefinedModule(modulesPatchDir, moduleName, moduleAdded.getItem().getContentHash());
}
Aggregations