Search in sources :

Example 6 with PatchTool

use of org.jboss.as.patching.tool.PatchTool 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 {
    // 
    }
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) PatchingException(org.jboss.as.patching.PatchingException) PatchingResult(org.jboss.as.patching.tool.PatchingResult) PatchTool(org.jboss.as.patching.tool.PatchTool) ContentVerificationPolicy(org.jboss.as.patching.tool.ContentVerificationPolicy) ModelNode(org.jboss.dmr.ModelNode)

Example 7 with PatchTool

use of org.jboss.as.patching.tool.PatchTool 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 {
    // 
    }
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) PatchingException(org.jboss.as.patching.PatchingException) PatchingResult(org.jboss.as.patching.tool.PatchingResult) PatchTool(org.jboss.as.patching.tool.PatchTool) ContentVerificationPolicy(org.jboss.as.patching.tool.ContentVerificationPolicy) ModelNode(org.jboss.dmr.ModelNode)

Example 8 with PatchTool

use of org.jboss.as.patching.tool.PatchTool in project wildfly-core by wildfly.

the class PatchBundleUnitTestCase method testConflicts.

@Test
public void testConflicts() throws Exception {
    final PatchingTestBuilder builder = createDefaultBuilder();
    final byte[] standaloneHash = new byte[20];
    final byte[] configHash = new byte[20];
    final byte[] existingHash = new byte[20];
    // Create a file
    final File existing = builder.getFile(FILE_EXISTING);
    touch(existing);
    dump(existing, randomString());
    final PatchingTestStepBuilder cp1 = builder.createStepBuilder();
    cp1.setPatchId("cp1").upgradeIdentity(PRODUCT_VERSION, PRODUCT_VERSION).addFileWithRandomContent(standaloneHash, FILE_ONE);
    final PatchingTestStepBuilder cp2 = builder.createStepBuilder();
    cp2.setPatchId("cp2").upgradeIdentity(PRODUCT_VERSION, PRODUCT_VERSION).addFileWithRandomContent(configHash, FILE_TWO);
    final PatchingTestStepBuilder cp3 = builder.createStepBuilder();
    cp3.setPatchId("cp3").upgradeIdentity(PRODUCT_VERSION, PRODUCT_VERSION).addFileWithRandomContent(existingHash, FILE_EXISTING);
    final File multiPatch = prepare(builder.getRoot(), cp1, cp2, cp3);
    // Create the patch tool and apply the patch
    InstallationManager mgr = loadInstallationManager();
    final PatchTool patchTool = PatchTool.Factory.create(mgr);
    try {
        patchTool.applyPatch(multiPatch, ContentVerificationPolicy.STRICT);
        Assert.fail();
    } catch (PatchingException e) {
    // ok
    }
    Assert.assertFalse(builder.hasFile(FILE_ONE));
    Assert.assertFalse(builder.hasFile(FILE_TWO));
}
Also used : PatchingException(org.jboss.as.patching.PatchingException) InstallationManager(org.jboss.as.patching.installation.InstallationManager) PatchTool(org.jboss.as.patching.tool.PatchTool) File(java.io.File) Test(org.junit.Test)

Example 9 with PatchTool

use of org.jboss.as.patching.tool.PatchTool in project wildfly-core by wildfly.

the class PatchBundleUnitTestCase method testMultiInstall.

@Test
public void testMultiInstall() 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
    // 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), cp5.build(), mgr);
    } catch (IOException e) {
        throw new PatchingException(e);
    }
    mgr = loadInstallationManager();
    final InstalledIdentity installedIdentity = mgr.getDefaultIdentity();
    Assert.assertEquals(Arrays.asList(new String[] { "CP1", "CP2", "CP3", "CP4", "CP5" }), installedIdentity.getAllInstalledPatches());
    PatchStepAssertions.assertModule("base-CP3", installedIdentity.getLayer("base"), "org.jboss.test", "main");
    PatchStepAssertions.assertModule("base-CP3", installedIdentity.getLayer("base"), "org.jboss.test.four", "main");
    PatchStepAssertions.assertModule("layer-1-CP2", installedIdentity.getLayer("layer-1"), "org.jboss.test.two", "main");
    PatchStepAssertions.assertModule("layer-1-CP2", installedIdentity.getLayer("layer-1"), "org.jboss.test.five", "main");
    PatchStepAssertions.assertModule("layer-2-CP2", installedIdentity.getLayer("layer-2"), "org.jboss.test.three", "main");
    PatchStepAssertions.assertModule("layer-2-CP2", installedIdentity.getLayer("layer-2"), "org.jboss.test.six", "main");
    rollback(cp5);
    mgr = loadInstallationManager();
    PatchStepAssertions.assertModule("base-CP2", installedIdentity.getLayer("base"), "org.jboss.test", "main");
    PatchStepAssertions.assertModule("base-CP2", installedIdentity.getLayer("base"), "org.jboss.test.four", "main");
    rollback(cp4);
    rollback(cp3);
    rollback(cp2);
    rollback(cp1);
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) 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) TestUtils.randomString(org.jboss.as.patching.runner.TestUtils.randomString) File(java.io.File) Test(org.junit.Test)

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