Search in sources :

Example 21 with ContentModification

use of org.jboss.as.patching.metadata.ContentModification in project wildfly-core by wildfly.

the class PatchMergeUnitTestCase method createRollbackInfo.

static RollbackInfo createRollbackInfo(String id, byte[] oih, byte[] oth, byte[] rih, byte[] rth) {
    // 
    final MiscContentItem oi = new MiscContentItem(name, path, oih);
    final MiscContentItem ri = new MiscContentItem(name, path, rih);
    // 
    final Patch o = createPatch(id, Patch.PatchType.ONE_OFF, new ContentModification(oi, oth, ModificationType.MODIFY));
    final Patch r = createPatch(id, Patch.PatchType.ONE_OFF, new ContentModification(ri, rth, ModificationType.MODIFY));
    // 
    return new RollbackInfo(o, r);
}
Also used : MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem) Patch(org.jboss.as.patching.metadata.Patch) ContentModification(org.jboss.as.patching.metadata.ContentModification)

Example 22 with ContentModification

use of org.jboss.as.patching.metadata.ContentModification in project wildfly-core by wildfly.

the class PatchMergeUnitTestCase method testSimple.

@Test
public void testSimple() throws Exception {
    // content-item 'two' replacing 'one'
    final RollbackInfo patch01 = createRollbackInfo("patch01", two, one);
    // content-item 'three' replacing 'two'
    final RollbackInfo patch02 = createRollbackInfo("patch02", three, two);
    // [patch-two, patch-one]
    final ContentTaskDefinitions defs = process(patch02, patch01);
    Assert.assertEquals(1, defs.size());
    final PatchingTasks.ContentTaskDefinition def = defs.get(new Location(new MiscContentItem(name, path, one)));
    Assert.assertNotNull(def);
    Assert.assertFalse(def.hasConflicts());
    // We want to restore one (from the backup)
    Assert.assertEquals(one, def.getTarget().getItem().getContentHash());
    // The original target was two
    Assert.assertEquals(two, def.getTarget().getTargetHash());
    // The current content however is three
    Assert.assertEquals(three, def.getLatest().getTargetHash());
    // And originally replaced two
    Assert.assertEquals(two, def.getLatest().getItem().getContentHash());
    // The resulting operation should replace 'three' with 'one'
    final ContentModification modification = PatchingTaskDescription.resolveDefinition(def);
    Assert.assertEquals(one, modification.getItem().getContentHash());
    Assert.assertEquals(three, modification.getTargetHash());
}
Also used : MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem) ContentModification(org.jboss.as.patching.metadata.ContentModification) Test(org.junit.Test)

Example 23 with ContentModification

use of org.jboss.as.patching.metadata.ContentModification in project wildfly-core by wildfly.

the class ContentConflictsUnitTestCase method testApply.

/**
 * Tests content conflicts reporting in the CLI during patch application.
 *
 * The test creates 2 misc files, 2 modules and 2 bundles and a patch
 * which updates all of them. Before the patch is applied, one file,
 * one module and one bundle are modified on the disk. The patch is
 * expected to fail and the failure description should contain the
 * info about the conflicting content items.
 *
 * @throws Exception
 */
@Test
public void testApply() throws Exception {
    final File binDir = createInstalledImage(env, "consoleSlot", productConfig.getProductName(), productConfig.getProductVersion());
    // build a one-off patch for the base installation
    // with 1 updated file
    String patchID = randomString();
    File patchDir = mkdir(tempDir, patchID);
    // create a module for the conflict
    File baseModuleDir = newFile(env.getInstalledImage().getModulesDir(), SYSTEM, LAYERS, BASE);
    String moduleConflictName = "module-conflict";
    File moduleConflictDir = createModule0(baseModuleDir, moduleConflictName);
    // create the patch with the updated module
    ContentModification moduleConflictModified = ContentModificationUtils.modifyModule(patchDir, patchID, moduleConflictDir, "new resource in the module");
    // create a module to be updated w/o a conflict
    String moduleNoConflictName = "module-no-conflict";
    File moduleNoConflictDir = createModule0(baseModuleDir, moduleNoConflictName);
    // create the patch with the updated module
    ContentModification moduleNoConflictModified = ContentModificationUtils.modifyModule(patchDir, patchID, moduleNoConflictDir, "new resource in the module");
    // create a file for the conflict
    String fileConflictName = "file-conflict.txt";
    File conflictFile = touch(binDir, fileConflictName);
    dump(conflictFile, "original script to run standalone AS7");
    // patch the file
    ContentModification fileConflictModified = ContentModificationUtils.modifyMisc(patchDir, patchID, "updated script", conflictFile, "bin", fileConflictName);
    // create a file for the conflict
    String fileNoConflictName = "file-no-conflict.txt";
    File noConflictFile = touch(binDir, fileNoConflictName);
    dump(noConflictFile, "original script to run standalone AS7");
    // patch the file
    ContentModification fileNoConflictModified = ContentModificationUtils.modifyMisc(patchDir, patchID, "updated script", noConflictFile, "bin", fileNoConflictName);
    // TestUtils.tree(env.getInstalledImage().getJbossHome());
    Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().addContentModification(fileConflictModified).addContentModification(fileNoConflictModified).oneOffPatchElement(patchID, "base", false).addContentModification(moduleConflictModified).addContentModification(moduleNoConflictModified).getParent().build();
    // create the patch
    createPatchXMLFile(patchDir, patch, false);
    File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
    // create a conflict for the file
    dump(conflictFile, "conflicting change");
    // create a conflict for the module
    createModule0(baseModuleDir, moduleConflictName, "oops");
    // apply the patch using the cli
    CommandContext ctx = CommandContextFactory.getInstance().newCommandContext();
    try {
        ctx.handle("patch apply " + zippedPatch.getAbsolutePath() + " --distribution=" + env.getInstalledImage().getJbossHome());
        fail("Conflicts expected.");
    } catch (CommandLineException e) {
        // e.printStackTrace();
        final int relativeIndex = env.getInstalledImage().getJbossHome().getAbsolutePath().length() + 1;
        assertConflicts(e, moduleConflictName + ":main", conflictFile.getAbsolutePath().substring(relativeIndex));
    } finally {
        ctx.terminateSession();
    }
}
Also used : CommandContext(org.jboss.as.cli.CommandContext) 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) CommandLineException(org.jboss.as.cli.CommandLineException) Test(org.junit.Test)

Example 24 with ContentModification

use of org.jboss.as.patching.metadata.ContentModification in project wildfly-core by wildfly.

the class ContentConflictsUnitTestCase method testRollback.

/**
 * Tests content conflicts reporting in the CLI during patch rollback.
 *
 * The test creates 2 misc files, 2 modules and 2 bundles and a patch
 * which updates all of them. The patch is applied. Then one file,
 * one module and one bundle are modified on the disk. The patch is
 * rolled back then which is expected to fail and the failure description
 * should contain the info about the conflicting content items.
 *
 * @throws Exception
 */
@Test
public void testRollback() throws Exception {
    final File binDir = createInstalledImage(env, "consoleSlot", productConfig.getProductName(), productConfig.getProductVersion());
    // build a one-off patch for the base installation
    // with 1 updated file
    String patchID = randomString();
    String patchElementId = randomString();
    File patchDir = mkdir(tempDir, patchID);
    // create a module for the conflict
    File baseModuleDir = newFile(env.getInstalledImage().getModulesDir(), SYSTEM, LAYERS, BASE);
    String moduleConflictName = "module-conflict";
    File moduleConflictDir = createModule0(baseModuleDir, moduleConflictName);
    // create the patch with the updated module
    ContentModification moduleConflictModified = ContentModificationUtils.modifyModule(patchDir, patchElementId, moduleConflictDir, "new resource in the module");
    // create a module to be updated w/o a conflict
    String moduleNoConflictName = "module-no-conflict";
    File moduleNoConflictDir = createModule0(baseModuleDir, moduleNoConflictName);
    // create the patch with the updated module
    ContentModification moduleNoConflictModified = ContentModificationUtils.modifyModule(patchDir, patchElementId, moduleNoConflictDir, "new resource in the module");
    // create a file for the conflict
    String fileConflictName = "file-conflict.txt";
    File conflictFile = touch(binDir, fileConflictName);
    dump(conflictFile, "original script to run standalone AS7");
    // patch the file
    ContentModification fileConflictModified = ContentModificationUtils.modifyMisc(patchDir, patchID, "updated script", conflictFile, "bin", fileConflictName);
    // create a file for the conflict
    String fileNoConflictName = "file-no-conflict.txt";
    File noConflictFile = touch(binDir, fileNoConflictName);
    dump(noConflictFile, "original script to run standalone AS7");
    // patch the file
    ContentModification fileNoConflictModified = ContentModificationUtils.modifyMisc(patchDir, patchID, "updated script", noConflictFile, "bin", fileNoConflictName);
    // TestUtils.tree(env.getInstalledImage().getJbossHome());
    Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().addContentModification(fileConflictModified).addContentModification(fileNoConflictModified).oneOffPatchElement(patchElementId, "base", false).addContentModification(moduleConflictModified).addContentModification(moduleNoConflictModified).getParent().build();
    // create the patch
    createPatchXMLFile(patchDir, patch, false);
    File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
    // apply the patch using the cli
    CommandContext ctx = CommandContextFactory.getInstance().newCommandContext();
    try {
        ctx.handle("patch apply " + zippedPatch.getAbsolutePath() + " --distribution=" + env.getInstalledImage().getJbossHome());
    } catch (CommandLineException e) {
        ctx.terminateSession();
        fail("Failed to apply the patch: " + e);
    }
    // create a conflict for the file
    dump(conflictFile, "conflicting change");
    // create a conflict for the module
    createModule0(baseModuleDir, moduleConflictName, "oops");
    try {
        ctx.handle("patch rollback --patch-id=" + patchID + " --distribution=" + env.getInstalledImage().getJbossHome() + " --reset-configuration=false");
        fail("Conflicts expected");
    } catch (CommandLineException e) {
        final int relativeIndex = env.getInstalledImage().getJbossHome().getAbsolutePath().length() + 1;
        // TODO modules and bundles are not checked at the moment
        assertConflicts(e, moduleConflictName + ":main", conflictFile.getAbsolutePath().substring(relativeIndex));
    // assertConflicts(e, conflictFile.getAbsolutePath().substring(relativeIndex));
    } finally {
        ctx.terminateSession();
    }
}
Also used : CommandContext(org.jboss.as.cli.CommandContext) 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) CommandLineException(org.jboss.as.cli.CommandLineException) Test(org.junit.Test)

Example 25 with ContentModification

use of org.jboss.as.patching.metadata.ContentModification in project wildfly-core by wildfly.

the class ResetConfigurationUnitTestCase method testResetConfigurationTrue.

/**
 * Applies a patch, modifies standalone, appclient and domain xml config and rolls back the patch
 * with --reset-configuration=true
 * The expected result is:
 * - the modified config files are replaced with the original configuration files;
 * - the restored-configuration dir is not created in any of the configuration dirs
 * .
 * @throws Exception
 */
@Test
public void testResetConfigurationTrue() throws Exception {
    final File binDir = createInstalledImage(env, "consoleSlot", productConfig.getProductName(), productConfig.getProductVersion());
    // build a one-off patch for the base installation
    // with 1 updated file
    String patchID = randomString();
    String patchElementId = randomString();
    File patchDir = mkdir(tempDir, patchID);
    // create a file for the conflict
    String fileNoConflictName = "file-no-conflict.txt";
    File noConflictFile = touch(binDir, fileNoConflictName);
    dump(noConflictFile, "original script to run standalone AS7");
    // patch the file
    ContentModification fileNoConflictModified = ContentModificationUtils.modifyMisc(patchDir, patchID, "updated script", noConflictFile, "bin", fileNoConflictName);
    // TestUtils.tree(env.getInstalledImage().getJbossHome());
    Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).upgradeIdentity(productConfig.getProductName(), productConfig.getProductVersion(), productConfig.getProductVersion() + "CP1").getParent().addContentModification(fileNoConflictModified).upgradeElement(patchElementId, "base", false).getParent().build();
    // create the patch
    createPatchXMLFile(patchDir, patch, false);
    File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
    // apply the patch using the cli
    CommandContext ctx = CommandContextFactory.getInstance().newCommandContext();
    try {
        ctx.handle("patch apply " + zippedPatch.getAbsolutePath() + " --distribution=" + env.getInstalledImage().getJbossHome());
    } catch (Exception e) {
        ctx.terminateSession();
        throw e;
    }
    // check the 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);
    assertNotEquals(bytesToHexString(originalStandaloneHash), bytesToHexString(updatedStandaloneXmlFile));
    dump(appClientXmlFile, "<updated app client configuration with changes from the added module>");
    byte[] updatedAppClientXmlHash = hashFile(appClientXmlFile);
    assertNotEquals(bytesToHexString(originalAppClientHash), bytesToHexString(updatedAppClientXmlHash));
    dump(domainXmlFile, "<updated domain configuration with changes from the added module>");
    byte[] updatedDomainXmlHash = hashFile(domainXmlFile);
    assertNotEquals(bytesToHexString(originalDomainHash), bytesToHexString(updatedDomainXmlHash));
    try {
        ctx.handle("patch rollback --reset-configuration=true --distribution=" + env.getInstalledImage().getJbossHome());
    } finally {
        ctx.terminateSession();
    }
    // TestUtils.tree(env.getInstalledImage().getJbossHome());
    File rolledBackStandaloneXmlFile = assertFileExists(env.getInstalledImage().getStandaloneDir(), "configuration", "standalone.xml");
    assertEquals(bytesToHexString(originalStandaloneHash), bytesToHexString(hashFile(rolledBackStandaloneXmlFile)));
    File rolledBackAppClientXmlFile = assertFileExists(env.getInstalledImage().getAppClientDir(), "configuration", "appclient.xml");
    assertEquals(bytesToHexString(originalAppClientHash), bytesToHexString(hashFile(rolledBackAppClientXmlFile)));
    File rolledBackDomainXmlFile = assertFileExists(env.getInstalledImage().getDomainDir(), "configuration", "domain.xml");
    assertEquals(bytesToHexString(originalDomainHash), bytesToHexString(hashFile(rolledBackDomainXmlFile)));
    assertDirDoesNotExist(env.getInstalledImage().getStandaloneDir(), "configuration", "restored-configuration");
    assertDirDoesNotExist(env.getInstalledImage().getAppClientDir(), "configuration", "restored-configuration");
    assertDirDoesNotExist(env.getInstalledImage().getDomainDir(), "configuration", "restored-configuration");
}
Also used : CommandContext(org.jboss.as.cli.CommandContext) HashUtils.bytesToHexString(org.jboss.as.patching.HashUtils.bytesToHexString) TestUtils.randomString(org.jboss.as.patching.runner.TestUtils.randomString) 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) ContentModification(org.jboss.as.patching.metadata.ContentModification) Patch(org.jboss.as.patching.metadata.Patch) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

ContentModification (org.jboss.as.patching.metadata.ContentModification)129 File (java.io.File)100 Patch (org.jboss.as.patching.metadata.Patch)94 Test (org.junit.Test)72 IoUtils.newFile (org.jboss.as.patching.IoUtils.newFile)70 PatchingTestUtil.createPatchXMLFile (org.jboss.as.test.patching.PatchingTestUtil.createPatchXMLFile)55 PatchingTestUtil.createZippedPatchFile (org.jboss.as.test.patching.PatchingTestUtil.createZippedPatchFile)52 PatchingTestUtil.randomString (org.jboss.as.test.patching.PatchingTestUtil.randomString)47 ProductConfig (org.jboss.as.version.ProductConfig)39 TestUtils.randomString (org.jboss.as.patching.runner.TestUtils.randomString)36 TestUtils.createPatchXMLFile (org.jboss.as.patching.runner.TestUtils.createPatchXMLFile)34 TestUtils.createZippedPatchFile (org.jboss.as.patching.runner.TestUtils.createZippedPatchFile)34 Module (org.jboss.as.test.patching.util.module.Module)29 HashUtils.hashFile (org.jboss.as.patching.HashUtils.hashFile)25 PatchingTestUtil.readFile (org.jboss.as.test.patching.PatchingTestUtil.readFile)24 PatchingResult (org.jboss.as.patching.tool.PatchingResult)20 MiscContentItem (org.jboss.as.patching.metadata.MiscContentItem)18 InstalledIdentity (org.jboss.as.patching.installation.InstalledIdentity)17 PatchBuilder (org.jboss.as.patching.metadata.PatchBuilder)16 ContentItem (org.jboss.as.patching.metadata.ContentItem)12