use of org.jboss.as.patching.tool.PatchingResult in project wildfly-core by wildfly.
the class AddOnTestCase method patchAndRollbackAddOn.
@Test
public void patchAndRollbackAddOn() throws Exception {
// start from a base installation
// add an add-on
String addOnName = randomString();
installAddOn(env.getModuleRoot(), addOnName);
InstalledIdentity installedIdentity = loadInstalledIdentity();
PatchableTarget.TargetInfo identityInfo = installedIdentity.getIdentity().loadTargetInfo();
assertEquals(BASE, identityInfo.getCumulativePatchID());
assertTrue(identityInfo.getPatchIDs().isEmpty());
// build a one-off patch for the add-on with 1 added module
// and 1 added 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 patchResult = executePatch(zippedPatch);
assertPatchHasBeenApplied(patchResult, patch);
// reload the installed identity
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 layerDirStructure = patchedInstalledIdentity.getAddOns().iterator().next().loadTargetInfo().getDirectoryStructure();
File modulesPatchDir = layerDirStructure.getModulePatchDirectory(addOnPatchID);
assertDirExists(modulesPatchDir);
assertDefinedModule(modulesPatchDir, moduleName, moduleAdded.getItem().getContentHash());
// rollback the patch
PatchingResult rollbackResult = rollback(patchID);
assertPatchHasBeenRolledBack(rollbackResult, patch, identityInfo);
assertFileDoesNotExist(env.getInstalledImage().getJbossHome(), "bin", "my-new-standalone.sh");
}
use of org.jboss.as.patching.tool.PatchingResult in project wildfly-core by wildfly.
the class BaseLayerTestCase method patchBase.
@Test
public void patchBase() throws Exception {
InstalledIdentity installedIdentity = loadInstalledIdentity();
// build a one-off patch for the base 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, BASE, 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 = InstalledIdentity.load(env.getInstalledImage().getJbossHome(), productConfig, env.getInstalledImage().getModulesDir());
assertInstallationIsPatched(patch, patchedInstalledIdentity.getIdentity().loadTargetInfo());
assertFileExists(env.getInstalledImage().getJbossHome(), "bin", fileAdded.getItem().getName());
if (ROOT_LOGGER.isDebugEnabled()) {
System.out.println("installation =>>");
tree(env.getInstalledImage().getJbossHome());
}
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 LayerTestCase method patchAndRollbackLayer.
@Test
public void patchAndRollbackLayer() throws Exception {
// add a layer
String layerName = randomString();
installLayers(layerName);
InstalledIdentity installedIdentity = loadInstalledIdentity();
PatchableTarget.TargetInfo identityInfo = installedIdentity.getIdentity().loadTargetInfo();
assertEquals(BASE, identityInfo.getCumulativePatchID());
assertTrue(identityInfo.getPatchIDs().isEmpty());
// build a one-off patch for the layer with 1 added module
// and 1 added 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);
Identity identityBeforePatch = loadInstalledIdentity().getIdentity();
// apply patch
PatchingResult patchResult = executePatch(zippedPatch);
assertPatchHasBeenApplied(patchResult, patch);
// reload the installed identity
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 layerDirStructure = patchedInstalledIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure();
File modulesPatchDir = layerDirStructure.getModulePatchDirectory(layerPatchId);
assertDirExists(modulesPatchDir);
assertDefinedModule(modulesPatchDir, moduleName, moduleAdded.getItem().getContentHash());
// rollback the patch
PatchingResult rollbackResult = rollback(patchID);
assertPatchHasBeenRolledBack(rollbackResult, identityBeforePatch);
// reload the rolled back installed identity
InstalledIdentity rolledBackInstalledIdentity = InstalledIdentity.load(env.getInstalledImage().getJbossHome(), productConfig, env.getInstalledImage().getModulesDir());
PatchingAssert.assertFileDoesNotExist(env.getInstalledImage().getJbossHome(), "bin", fileAdded.getItem().getName());
if (File.separatorChar != '\\') {
assertDirDoesNotExist(rolledBackInstalledIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(layerPatchId));
}
}
use of org.jboss.as.patching.tool.PatchingResult in project wildfly-core by wildfly.
the class LocalPatchRollbackHandler method execute.
@Override
protected void execute(final OperationContext context, final ModelNode operation, final InstallationManager installationManager, final String patchStream) throws OperationFailedException {
if (installationManager.requiresRestart()) {
throw PatchLogger.ROOT_LOGGER.serverRequiresRestart();
}
final String patchId = PatchResourceDefinition.PATCH_ID.resolveModelAttribute(context, operation).asString();
final boolean rollbackTo = PatchResourceDefinition.ROLLBACK_TO.resolveModelAttribute(context, operation).asBoolean();
final boolean restoreConfiguration = PatchResourceDefinition.RESET_CONFIGURATION.resolveModelAttribute(context, operation).asBoolean();
final PatchTool runner = PatchTool.Factory.create(installationManager);
final ContentVerificationPolicy policy = PatchTool.Factory.create(operation);
try {
// Rollback
final PatchingResult result = runner.rollback(patchStream, patchId, policy, rollbackTo, restoreConfiguration);
installationManager.restartRequired();
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();
} finally {
//
}
}
use of org.jboss.as.patching.tool.PatchingResult in project wildfly-core by wildfly.
the class LocalPatchRollbackLastHandler method execute.
@Override
protected void execute(final OperationContext context, final ModelNode operation, final InstallationManager installationManager, final String patchStream) throws OperationFailedException {
if (installationManager.requiresRestart()) {
throw PatchLogger.ROOT_LOGGER.serverRequiresRestart();
}
final boolean resetConfiguration = PatchResourceDefinition.RESET_CONFIGURATION.resolveModelAttribute(context, operation).asBoolean();
final PatchTool runner = PatchTool.Factory.create(installationManager);
final ContentVerificationPolicy policy = PatchTool.Factory.create(operation);
try {
// Rollback
final PatchingResult result = runner.rollbackLast(patchStream, policy, resetConfiguration);
installationManager.restartRequired();
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();
} finally {
//
}
}
Aggregations