Search in sources :

Example 11 with PatchingResult

use of org.jboss.as.patching.tool.PatchingResult 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 12 with PatchingResult

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

the class ConfigurationBackupTestCase method checkApplyPatchAndRollbackRestoresBackupConfiguration.

private void checkApplyPatchAndRollbackRestoresBackupConfiguration(File patchDir, Patch patch) throws Exception {
    createPatchXMLFile(patchDir, patch);
    File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
    Identity identityBeforePatch = loadInstalledIdentity().getIdentity();
    PatchingResult result = executePatch(zippedPatch);
    assertPatchHasBeenApplied(result, patch);
    // check the AS7 config files have been backed up
    File backupAppclientXmlFile = assertFileExists(env.getInstalledImage().getPatchHistoryDir(patch.getPatchId()), "configuration", "appclient", "appclient.xml");
    assertFileContent(originalAppClientHash, backupAppclientXmlFile);
    File backupStandaloneXmlFile = assertFileExists(env.getInstalledImage().getPatchHistoryDir(patch.getPatchId()), "configuration", "standalone", "standalone.xml");
    assertFileContent(originalStandaloneHash, backupStandaloneXmlFile);
    File backupDomainXmlFile = assertFileExists(env.getInstalledImage().getPatchHistoryDir(patch.getPatchId()), "configuration", "domain", "domain.xml");
    assertFileContent(originalDomainHash, backupDomainXmlFile);
    // let's change the standalone.xml file
    dump(standaloneXmlFile, "<updated standalone configuration with changes from the added module>");
    byte[] updatedStandaloneXmlFile = hashFile(standaloneXmlFile);
    tree(tempDir);
    PatchingResult rollbackResult = rollback(patch.getPatchId());
    assertPatchHasBeenRolledBack(rollbackResult, identityBeforePatch);
    File rolledBackStandaloneXmlFile = assertFileExists(env.getInstalledImage().getStandaloneDir(), "configuration", "standalone.xml");
    assertEquals("updated content was " + bytesToHexString(updatedStandaloneXmlFile), bytesToHexString(originalStandaloneHash), bytesToHexString(hashFile(rolledBackStandaloneXmlFile)));
}
Also used : PatchingResult(org.jboss.as.patching.tool.PatchingResult) Identity(org.jboss.as.patching.installation.Identity) InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) TestUtils.createPatchXMLFile(org.jboss.as.patching.runner.TestUtils.createPatchXMLFile) HashUtils.hashFile(org.jboss.as.patching.HashUtils.hashFile) File(java.io.File) TestUtils.createZippedPatchFile(org.jboss.as.patching.runner.TestUtils.createZippedPatchFile)

Example 13 with PatchingResult

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

the class ModuleTaskTestCase method testUpdateModule.

@Test
public void testUpdateModule() throws Exception {
    String moduleName = randomString();
    // create an empty module in the AS7 installation base layer
    File baseModuleDir = newFile(env.getInstalledImage().getModulesDir(), SYSTEM, LAYERS, BASE);
    File moduleDir = createModule0(baseModuleDir, moduleName);
    // build a one-off patch for the base installation
    // with 1 module updated
    String patchID = randomString();
    String baseLayerPatchID = randomString();
    File patchDir = mkdir(tempDir, patchID);
    // create the patch with the updated module
    ContentModification moduleModified = ContentModificationUtils.modifyModule(patchDir, baseLayerPatchID, moduleDir, "new resource in the module");
    Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().oneOffPatchElement(baseLayerPatchID, BASE, false).addContentModification(moduleModified).getParent().build();
    createPatchXMLFile(patchDir, patch);
    File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
    PatchingResult result = executePatch(zippedPatch);
    assertPatchHasBeenApplied(result, patch);
    tree(env.getInstalledImage().getJbossHome());
    InstalledIdentity installedIdentity = loadInstalledIdentity();
    File modulesPatchDir = installedIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(baseLayerPatchID);
    assertDirExists(modulesPatchDir);
    // check that the defined module is the updated one
    assertDefinedModule(modulesPatchDir, moduleName, moduleModified.getItem().getContentHash());
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) 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) Test(org.junit.Test)

Example 14 with PatchingResult

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

the class RemoveModifiedFileTaskTestCase method testRemovedModifiedFileWithOVERRIDE_ALL.

@Test
public void testRemovedModifiedFileWithOVERRIDE_ALL() throws Exception {
    PatchingResult result = runner.applyPatch(zippedPatch, ContentVerificationPolicy.OVERRIDE_ALL);
    assertPatchHasBeenApplied(result, patch);
    // / file has been removed from the AS7 installation
    // and it's the new one
    assertFileDoesNotExist(removedFile);
    // the existing file has been backed up
    File backupFile = assertFileExists(env.getInstalledImage().getPatchHistoryDir(patch.getPatchId()), "misc", "bin", removedFile.getName());
    assertArrayEquals(expectedModifiedHash, hashFile(backupFile));
}
Also used : PatchingResult(org.jboss.as.patching.tool.PatchingResult) TestUtils.createPatchXMLFile(org.jboss.as.patching.runner.TestUtils.createPatchXMLFile) HashUtils.hashFile(org.jboss.as.patching.HashUtils.hashFile) File(java.io.File) TestUtils.createZippedPatchFile(org.jboss.as.patching.runner.TestUtils.createZippedPatchFile) Test(org.junit.Test)

Example 15 with PatchingResult

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

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