Search in sources :

Example 21 with PatchingResult

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");
}
Also used : PatchingResult(org.jboss.as.patching.tool.PatchingResult) TestUtils.randomString(org.jboss.as.patching.runner.TestUtils.randomString) IoUtils.newFile(org.jboss.as.patching.IoUtils.newFile) TestUtils.createPatchXMLFile(org.jboss.as.patching.runner.TestUtils.createPatchXMLFile) File(java.io.File) TestUtils.createZippedPatchFile(org.jboss.as.patching.runner.TestUtils.createZippedPatchFile) ContentModification(org.jboss.as.patching.metadata.ContentModification) Patch(org.jboss.as.patching.metadata.Patch) DirectoryStructure(org.jboss.as.patching.DirectoryStructure) Test(org.junit.Test)

Example 22 with PatchingResult

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());
}
Also used : PatchingResult(org.jboss.as.patching.tool.PatchingResult) TestUtils.randomString(org.jboss.as.patching.runner.TestUtils.randomString) IoUtils.newFile(org.jboss.as.patching.IoUtils.newFile) TestUtils.createPatchXMLFile(org.jboss.as.patching.runner.TestUtils.createPatchXMLFile) File(java.io.File) TestUtils.createZippedPatchFile(org.jboss.as.patching.runner.TestUtils.createZippedPatchFile) ContentModification(org.jboss.as.patching.metadata.ContentModification) Patch(org.jboss.as.patching.metadata.Patch) DirectoryStructure(org.jboss.as.patching.DirectoryStructure) Test(org.junit.Test)

Example 23 with PatchingResult

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));
    }
}
Also used : PatchingResult(org.jboss.as.patching.tool.PatchingResult) TestUtils.randomString(org.jboss.as.patching.runner.TestUtils.randomString) IoUtils.newFile(org.jboss.as.patching.IoUtils.newFile) TestUtils.createPatchXMLFile(org.jboss.as.patching.runner.TestUtils.createPatchXMLFile) File(java.io.File) TestUtils.createZippedPatchFile(org.jboss.as.patching.runner.TestUtils.createZippedPatchFile) ContentModification(org.jboss.as.patching.metadata.ContentModification) Patch(org.jboss.as.patching.metadata.Patch) DirectoryStructure(org.jboss.as.patching.DirectoryStructure) Test(org.junit.Test)

Example 24 with PatchingResult

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 {
    // 
    }
}
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 25 with PatchingResult

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 {
    // 
    }
}
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)

Aggregations

PatchingResult (org.jboss.as.patching.tool.PatchingResult)37 File (java.io.File)31 Test (org.junit.Test)27 TestUtils.createPatchXMLFile (org.jboss.as.patching.runner.TestUtils.createPatchXMLFile)25 TestUtils.createZippedPatchFile (org.jboss.as.patching.runner.TestUtils.createZippedPatchFile)25 Patch (org.jboss.as.patching.metadata.Patch)24 TestUtils.randomString (org.jboss.as.patching.runner.TestUtils.randomString)23 ContentModification (org.jboss.as.patching.metadata.ContentModification)20 InstalledIdentity (org.jboss.as.patching.installation.InstalledIdentity)17 IoUtils.newFile (org.jboss.as.patching.IoUtils.newFile)13 HashUtils.hashFile (org.jboss.as.patching.HashUtils.hashFile)12 PatchingException (org.jboss.as.patching.PatchingException)9 PatchTool (org.jboss.as.patching.tool.PatchTool)8 IOException (java.io.IOException)5 DirectoryStructure (org.jboss.as.patching.DirectoryStructure)5 Identity (org.jboss.as.patching.installation.Identity)5 InstallationManager (org.jboss.as.patching.installation.InstallationManager)4 OperationContext (org.jboss.as.controller.OperationContext)3 ContentVerificationPolicy (org.jboss.as.patching.tool.ContentVerificationPolicy)3 ModelNode (org.jboss.dmr.ModelNode)3