Search in sources :

Example 1 with InstallationManager

use of org.jboss.as.patching.installation.InstallationManager 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 InstallationManager

use of org.jboss.as.patching.installation.InstallationManager 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 InstallationManager

use of org.jboss.as.patching.installation.InstallationManager 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)

Example 4 with InstallationManager

use of org.jboss.as.patching.installation.InstallationManager 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 5 with InstallationManager

use of org.jboss.as.patching.installation.InstallationManager 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

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