Search in sources :

Example 1 with PatchTool

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);
    }
}
Also used : PatchingException(org.jboss.as.patching.PatchingException) InstallationManager(org.jboss.as.patching.installation.InstallationManager) PatchingResult(org.jboss.as.patching.tool.PatchingResult) PatchTool(org.jboss.as.patching.tool.PatchTool) IOException(java.io.IOException) File(java.io.File) Test(org.junit.Test)

Example 2 with PatchTool

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);
}
Also used : InstallationManager(org.jboss.as.patching.installation.InstallationManager) PatchingResult(org.jboss.as.patching.tool.PatchingResult) PatchTool(org.jboss.as.patching.tool.PatchTool) File(java.io.File) Test(org.junit.Test)

Example 3 with PatchTool

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;
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchingException(org.jboss.as.patching.PatchingException) PatchingResult(org.jboss.as.patching.tool.PatchingResult) InstallationManagerImpl(org.jboss.as.patching.installation.InstallationManagerImpl) PatchTool(org.jboss.as.patching.tool.PatchTool) IOException(java.io.IOException) Patch(org.jboss.as.patching.metadata.Patch) File(java.io.File)

Example 4 with PatchTool

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;
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchingException(org.jboss.as.patching.PatchingException) PatchingResult(org.jboss.as.patching.tool.PatchingResult) PatchTool(org.jboss.as.patching.tool.PatchTool) IOException(java.io.IOException) TestUtils.randomString(org.jboss.as.patching.runner.TestUtils.randomString) Patch(org.jboss.as.patching.metadata.Patch) File(java.io.File)

Example 5 with PatchTool

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();
    }
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) PatchingException(org.jboss.as.patching.PatchingException) InputStream(java.io.InputStream) InstallationManager(org.jboss.as.patching.installation.InstallationManager) PatchingResult(org.jboss.as.patching.tool.PatchingResult) PatchTool(org.jboss.as.patching.tool.PatchTool) ContentVerificationPolicy(org.jboss.as.patching.tool.ContentVerificationPolicy) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

PatchTool (org.jboss.as.patching.tool.PatchTool)9 PatchingException (org.jboss.as.patching.PatchingException)8 PatchingResult (org.jboss.as.patching.tool.PatchingResult)8 File (java.io.File)6 InstallationManager (org.jboss.as.patching.installation.InstallationManager)5 IOException (java.io.IOException)4 Test (org.junit.Test)4 OperationContext (org.jboss.as.controller.OperationContext)3 InstalledIdentity (org.jboss.as.patching.installation.InstalledIdentity)3 ContentVerificationPolicy (org.jboss.as.patching.tool.ContentVerificationPolicy)3 ModelNode (org.jboss.dmr.ModelNode)3 Patch (org.jboss.as.patching.metadata.Patch)2 TestUtils.randomString (org.jboss.as.patching.runner.TestUtils.randomString)2 InputStream (java.io.InputStream)1 InstallationManagerImpl (org.jboss.as.patching.installation.InstallationManagerImpl)1 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)1