use of org.jboss.as.patching.tool.PatchTool in project wildfly-core by wildfly.
the class PatchBundleUnitTestCase method testSkipInstalled.
@Test
public void testSkipInstalled() throws Exception {
final PatchingTestBuilder builder = createDefaultBuilder("layer-2", "layer-1", "base");
final byte[] moduleHashOne = new byte[20];
final byte[] moduleHashTwo = new byte[20];
final byte[] moduleHashThree = new byte[20];
final PatchingTestStepBuilder cp1 = builder.createStepBuilder();
cp1.setPatchId("CP1").upgradeIdentity(PRODUCT_VERSION, PRODUCT_VERSION).upgradeElement("base-CP1", "base", false).addModuleWithRandomContent("org.jboss.test", moduleHashOne);
final PatchingTestStepBuilder cp2 = builder.createStepBuilder();
cp2.setPatchId("CP2").upgradeIdentity(PRODUCT_VERSION, PRODUCT_VERSION).upgradeElement("layer-1-CP1", "layer-1", false).addModuleWithRandomContent("org.jboss.test.two", moduleHashTwo);
final PatchingTestStepBuilder cp3 = builder.createStepBuilder();
cp3.setPatchId("CP3").upgradeIdentity(PRODUCT_VERSION, PRODUCT_VERSION).upgradeElement("layer-2-CP1", "layer-2", false).removeModule("org.jboss.test.three", "main", moduleHashThree);
apply(cp1);
apply(cp2);
// Prepare multi patch
final File multiPatch = prepare(builder.getRoot(), cp1, cp2, cp3);
// Create the patch tool and apply the patch
// Get installation manager instance for the unit test
InstallationManager mgr = updateInstallationManager();
final PatchTool patchTool = PatchTool.Factory.create(mgr);
final PatchingResult result = patchTool.applyPatch(multiPatch, ContentVerificationPolicy.STRICT);
result.commit();
try {
PatchStepAssertions.APPLY.after(builder.getFile(JBOSS_INSTALLATION), cp3.build(), mgr);
} catch (IOException e) {
throw new PatchingException(e);
}
}
use of org.jboss.as.patching.tool.PatchTool in project wildfly-core by wildfly.
the class PatchBundleUnitTestCase method testRevert.
@Test
public void testRevert() throws Exception {
final PatchingTestBuilder builder = createDefaultBuilder("layer-2", "layer-1", "base");
final byte[] moduleHashOne = new byte[20];
final byte[] moduleHashTwo = new byte[20];
final byte[] moduleHashThree = new byte[20];
final byte[] moduleHashFour = new byte[20];
final byte[] moduleHashFive = new byte[20];
final byte[] moduleHashSix = new byte[20];
final PatchingTestStepBuilder cp1 = builder.createStepBuilder();
cp1.setPatchId("CP1").upgradeIdentity(PRODUCT_VERSION, PRODUCT_VERSION).upgradeElement("base-CP1", "base", false).addModuleWithRandomContent("org.jboss.test", moduleHashOne);
final PatchingTestStepBuilder cp2 = builder.createStepBuilder();
cp2.setPatchId("CP2").upgradeIdentity(PRODUCT_VERSION, PRODUCT_VERSION).upgradeElement("layer-1-CP1", "layer-1", false).addModuleWithRandomContent("org.jboss.test.two", moduleHashTwo);
final PatchingTestStepBuilder cp3 = builder.createStepBuilder();
cp3.setPatchId("CP3").upgradeIdentity(PRODUCT_VERSION, PRODUCT_VERSION).upgradeElement("layer-2-CP1", "layer-2", false).removeModule("org.jboss.test.three", "main", moduleHashThree);
final PatchingTestStepBuilder cp4 = builder.createStepBuilder();
cp4.setPatchId("CP4").upgradeIdentity(PRODUCT_VERSION, PRODUCT_VERSION).upgradeElement("base-CP2", "base", false).addModuleWithRandomContent("org.jboss.test.four", moduleHashFour);
final PatchingTestStepBuilder cp5 = builder.createStepBuilder();
cp5.setPatchId("CP5").upgradeIdentity(PRODUCT_VERSION, PRODUCT_VERSION).upgradeElement("base-CP3", "base", false).updateModuleWithRandomContent("org.jboss.test.four", moduleHashFour, null).getParent().upgradeElement("layer-1-CP2", "layer-1", false).addModuleWithRandomContent("org.jboss.test.five", moduleHashFive).getParent().upgradeElement("layer-2-CP2", "layer-2", false).addModuleWithRandomContent("org.jboss.test.six", moduleHashSix);
final File multiPatch = prepare(builder.getRoot(), cp1, cp2, cp3, cp4, cp5);
// Create the patch tool and apply the patch
InstallationManager mgr = loadInstallationManager();
final PatchTool patchTool = PatchTool.Factory.create(mgr);
final PatchingResult result = patchTool.applyPatch(multiPatch, ContentVerificationPolicy.STRICT);
result.rollback();
mgr = loadInstallationManager();
checkNotApplied(builder.getRoot(), mgr, cp1, cp2, cp3, cp4, cp5);
}
use of org.jboss.as.patching.tool.PatchTool in project wildfly-core by wildfly.
the class AbstractPatchingTest method apply.
protected PatchingResult apply(final PatchingTestStepBuilder builder, final ContentVerificationPolicy verificationPolicy, final PatchStepAssertions assertions) throws PatchingException {
final Patch patch = builder.build();
final File installation = new File(tempDir, JBOSS_INSTALLATION);
try {
assertions.before(installation, patch, installationManager);
} catch (IOException e) {
throw new PatchingException(e);
}
// Write patch
writePatch(builder.getPatchDir(), patch);
// Create the patch tool and apply the patch
final PatchTool patchTool = PatchTool.Factory.create(installationManager);
final PatchingResult result = patchTool.applyPatch(builder.getPatchDir(), verificationPolicy);
result.commit();
final InstalledIdentity identity = ((InstallationManagerImpl) installationManager).getInstalledIdentity(patch.getIdentity().getName(), null);
Assert.assertTrue(identity.getAllInstalledPatches().contains(patch.getPatchId()));
try {
assertions.after(installation, patch, installationManager);
} catch (IOException e) {
throw new PatchingException(e);
}
return result;
}
use of org.jboss.as.patching.tool.PatchTool in project wildfly-core by wildfly.
the class AbstractPatchingTest method rollback.
protected PatchingResult rollback(final PatchingTestStepBuilder builder, final ContentVerificationPolicy verificationPolicy, final PatchStepAssertions assertions, boolean rollbackTo) throws PatchingException {
final Patch patch = builder.build();
final File installation = new File(tempDir, JBOSS_INSTALLATION);
try {
assertions.before(installation, patch, installationManager);
} catch (IOException e) {
throw new PatchingException(e);
}
final String patchId = patch.getPatchId();
final PatchTool patchTool = PatchTool.Factory.create(installationManager);
final PatchingResult result = patchTool.rollback(patchId, verificationPolicy, rollbackTo, false);
result.commit();
final InstalledIdentity identity = installationManager.getInstalledIdentity(patch.getIdentity().getName(), null);
Assert.assertFalse(identity.getAllInstalledPatches().contains(patch.getPatchId()));
try {
assertions.after(installation, patch, installationManager);
} catch (IOException e) {
throw new PatchingException(e);
}
return result;
}
use of org.jboss.as.patching.tool.PatchTool 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();
}
}
Aggregations