Search in sources :

Example 26 with ContentModification

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

the class ResetConfigurationUnitTestCase method testResetConfigurationFalse.

/**
 * Applies a patch, modifies standalone, appclient and domain xml config and rolls back the patch
 * with --reset-configuration=false
 * The expected result is:
 * - the modified config files remain as-is;
 * - in each configuration dir a new restored-configuration dir is created with the original,
 *   unmodified configuration files.
 *
 * @throws Exception
 */
@Test
public void testResetConfigurationFalse() 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[] updatedStandaloneXmlHash = hashFile(standaloneXmlFile);
    dump(appClientXmlFile, "<updated app client configuration with changes from the added module>");
    byte[] updatedAppClientXmlHash = hashFile(appClientXmlFile);
    dump(domainXmlFile, "<updated domain configuration with changes from the added module>");
    byte[] updatedDomainXmlHash = hashFile(domainXmlFile);
    try {
        ctx.handle("patch rollback --reset-configuration=false --distribution=" + env.getInstalledImage().getJbossHome());
    } finally {
        ctx.terminateSession();
    }
    // TestUtils.tree(env.getInstalledImage().getJbossHome());
    assertRestoredConfig(env.getInstalledImage().getStandaloneDir(), "standalone.xml", updatedStandaloneXmlHash, originalStandaloneHash);
    assertRestoredConfig(env.getInstalledImage().getAppClientDir(), "appclient.xml", updatedAppClientXmlHash, originalAppClientHash);
    assertRestoredConfig(env.getInstalledImage().getDomainDir(), "domain.xml", updatedDomainXmlHash, originalDomainHash);
}
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)

Example 27 with ContentModification

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

the class MergingPatchContentTestCase method prepareCP3.

private void prepareCP3(final InstalledIdentity installedIdentity) throws IOException, Exception {
    final String cp3ID = "CP3";
    final File cp3Dir = mkdir(tempDir, cp3ID);
    cp3StandaloneModified = ContentModificationUtils.modifyMisc(cp3Dir, cp3ID, "updated by cp3", standaloneSh, "bin", standaloneSh.getName());
    cp3BaseModuleModified = ContentModificationUtils.modifyModule(cp3Dir, baseCP3ID, moduleName, cp2BaseModuleModified.getItem().getContentHash(), "cp3 content");
    // cp3BaseModule2Added = ContentModificationUtils.addModule(cp3Dir, baseCP3ID, moduleName + "2"); the patchgen tool
    // would generate an update instead
    final File absentModuleXml = IoUtils.newFile(installedIdentity.getLayer("base").loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(baseCP2ID), "org", "jboss", "test2", "main", "module.xml");
    cp3BaseModule2Added = ContentModificationUtils.modifyModule(cp3Dir, baseCP3ID, moduleName + "2", HashUtils.hashFile(absentModuleXml), "cp3 content");
    final ContentModification cp3AddedByCP1RemovedByCP3Removed = ContentModificationUtils.removeMisc(addedByCP1RemovedByCP3, "bin", addedByCP1RemovedByCP3.getName());
    cp3 = PatchBuilder.create().setPatchId(cp3ID).setDescription(randomString()).upgradeIdentity(installedIdentity.getIdentity().getName(), productConfig.getProductVersion() + "_CP2", productConfig.getProductVersion() + "_CP3").getParent().upgradeElement(baseCP3ID, BASE, false).addContentModification(cp3BaseModuleModified).addContentModification(cp3BaseModule2Added).getParent().addContentModification(cp3StandaloneModified).addContentModification(cp3AddedByCP1RemovedByCP3Removed).build();
    createPatchXMLFile(cp3Dir, cp3);
    cp3Zip = createZippedPatchFile(cp3Dir, cp3ID);
}
Also used : 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)

Example 28 with ContentModification

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

the class MergingPatchContentTestCase method prepareCP1.

private void prepareCP1(final InstalledIdentity installedIdentity) throws Exception {
    final String cp1ID = "CP1";
    final File cp1Dir = mkdir(tempDir, cp1ID);
    cp1BaseModuleAdded = ContentModificationUtils.addModule(cp1Dir, baseCP1ID, moduleName);
    cp1BaseModule2Added = ContentModificationUtils.addModule(cp1Dir, baseCP1ID, moduleName + 2);
    cp1Layer1ModuleAdded = ContentModificationUtils.addModule(cp1Dir, layer1CP1ID, moduleName);
    cp1Layer2ModuleAdded = ContentModificationUtils.addModule(cp1Dir, layer2CP1ID, moduleName);
    cp1Layer2Module2Added = ContentModificationUtils.addModule(cp1Dir, layer2CP1ID, moduleName + "2");
    cp1StandaloneModified = ContentModificationUtils.modifyMisc(cp1Dir, cp1ID, "updated by cp1", standaloneSh, "bin", standaloneSh.getName());
    cp1AddedByCP1Added = ContentModificationUtils.addMisc(cp1Dir, cp1ID, "added by cp1", "bin", addedByCP1.getName());
    final ContentModification cp1AddedByCP1RemovedByCP3Added = ContentModificationUtils.addMisc(cp1Dir, cp1ID, "added by cp1", "bin", addedByCP1RemovedByCP3.getName());
    cp1 = PatchBuilder.create().setPatchId(cp1ID).setDescription(randomString()).upgradeIdentity(installedIdentity.getIdentity().getName(), installedIdentity.getIdentity().getVersion(), productConfig.getProductVersion() + "_CP1").getParent().upgradeElement(baseCP1ID, BASE, false).addContentModification(cp1BaseModuleAdded).addContentModification(cp1BaseModule2Added).getParent().upgradeElement(layer1CP1ID, "layer1", false).addContentModification(cp1Layer1ModuleAdded).getParent().upgradeElement(layer2CP1ID, "layer2", false).addContentModification(cp1Layer2ModuleAdded).addContentModification(cp1Layer2Module2Added).getParent().addContentModification(cp1StandaloneModified).addContentModification(cp1AddedByCP1Added).addContentModification(cp1AddedByCP1RemovedByCP3Added).build();
    createPatchXMLFile(cp1Dir, cp1);
    cp1Zip = createZippedPatchFile(cp1Dir, cp1ID);
}
Also used : 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)

Example 29 with ContentModification

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

the class LayerTestCase method patchLayer.

@Test
public void patchLayer() throws Exception {
    // add a layer
    // randomString();
    String layerName = "mylayer";
    installLayers(layerName);
    InstalledIdentity installedIdentity = loadInstalledIdentity();
    // build a one-off patch for the 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, layerName, 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 = loadInstalledIdentity();
    assertInstallationIsPatched(patch, patchedInstalledIdentity.getIdentity().loadTargetInfo());
    assertFileExists(env.getInstalledImage().getJbossHome(), "bin", fileAdded.getItem().getName());
    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 30 with ContentModification

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

the class IdentityPatchRunner method reenableNotOverridenModules.

void reenableNotOverridenModules(final RollbackPatch patch, IdentityPatchContext context) throws PatchingException, IOException, XMLStreamException {
    assert patch.getIdentity().getPatchType() == Patch.PatchType.CUMULATIVE;
    final Iterator historyIterator = context.getHistory().iterator(patch.getIdentityState().getIdentity().loadTargetInfo());
    if (!historyIterator.hasNext()) {
        return;
    }
    final List<PatchElement> elements = patch.getElements();
    final Map<String, List<PatchElement>> layerPatches = new HashMap<String, List<PatchElement>>(elements.size());
    final Map<String, List<PatchElement>> addonPatches = new HashMap<String, List<PatchElement>>(elements.size());
    for (PatchElement e : elements) {
        if (e.getProvider().isAddOn()) {
            addonPatches.put(e.getProvider().getName(), Collections.<PatchElement>emptyList());
        } else {
            layerPatches.put(e.getProvider().getName(), Collections.<PatchElement>emptyList());
        }
    }
    Patch prevCP = null;
    while (historyIterator.hasNext()) {
        final Entry entry = historyIterator.next();
        if (entry.getType() == PatchType.CUMULATIVE) {
            prevCP = entry.getMetadata();
            break;
        }
        final Patch oneOff = entry.getMetadata();
        for (PatchElement oneOffElement : oneOff.getElements()) {
            final Map<String, List<PatchElement>> providerPatches;
            if (oneOffElement.getProvider().isAddOn()) {
                providerPatches = addonPatches;
            } else {
                providerPatches = layerPatches;
            }
            List<PatchElement> patches = providerPatches.get(oneOffElement.getProvider().getName());
            if (patches != null) {
                switch(patches.size()) {
                    case 0:
                        providerPatches.put(oneOffElement.getProvider().getName(), Collections.singletonList(oneOffElement));
                        break;
                    case 1:
                        patches = new ArrayList<PatchElement>(patches);
                        providerPatches.put(oneOffElement.getProvider().getName(), patches);
                    default:
                        patches.add(oneOffElement);
                }
            }
        }
    }
    Set<ModuleItem> cpElementModules;
    Set<ModuleItem> reenabledModules = Collections.emptySet();
    for (PatchElement e : elements) {
        final List<PatchElement> patches;
        if (e.getProvider().isAddOn()) {
            patches = addonPatches.get(e.getProvider().getName());
        } else {
            patches = layerPatches.get(e.getProvider().getName());
        }
        if (patches.isEmpty()) {
            continue;
        }
        cpElementModules = null;
        final PatchEntry rollbackEntry = context.resolveForElement(e);
        for (PatchElement oneOff : patches) {
            for (ContentModification mod : oneOff.getModifications()) {
                if (mod.getItem().getContentType() != ContentType.MODULE) {
                    continue;
                }
                final ModuleItem module = (ModuleItem) mod.getItem();
                if (rollbackEntry.get(new Location(module)) != null) {
                    continue;
                }
                if (reenabledModules.contains(module)) {
                    continue;
                }
                final File modulePath = PatchContentLoader.getModulePath(rollbackEntry.getDirectoryStructure().getModulePatchDirectory(oneOff.getId()), module);
                rollbackEntry.invalidateRoot(modulePath);
                if (reenabledModules.isEmpty()) {
                    reenabledModules = new HashSet<ModuleItem>();
                }
                reenabledModules.add(module);
                if (prevCP == null) {
                    rollbackEntry.disableBaseModule(module);
                } else {
                    if (cpElementModules == null) {
                        for (PatchElement cpE : prevCP.getElements()) {
                            if (cpE.getProvider().getName().equals(e.getProvider().getName()) && cpE.getProvider().getLayerType().equals(e.getProvider().getLayerType())) {
                                cpElementModules = new HashSet<ModuleItem>(cpE.getModifications().size());
                                for (ContentModification cpMod : cpE.getModifications()) {
                                    if (cpMod.getItem().getContentType() == ContentType.MODULE) {
                                        cpElementModules.add(cpMod.getItem(ModuleItem.class));
                                    }
                                }
                                break;
                            }
                        }
                    }
                    if (cpElementModules != null && !cpElementModules.contains(module)) {
                        rollbackEntry.disableBaseModule(module);
                    }
                }
            }
        }
    }
}
Also used : PatchEntry(org.jboss.as.patching.runner.IdentityPatchContext.PatchEntry) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) PatchElement(org.jboss.as.patching.metadata.PatchElement) ModuleItem(org.jboss.as.patching.metadata.ModuleItem) Entry(org.jboss.as.patching.tool.PatchingHistory.Entry) PatchEntry(org.jboss.as.patching.runner.IdentityPatchContext.PatchEntry) Iterator(org.jboss.as.patching.tool.PatchingHistory.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Patch(org.jboss.as.patching.metadata.Patch) RollbackPatch(org.jboss.as.patching.metadata.RollbackPatch) ContentModification(org.jboss.as.patching.metadata.ContentModification) File(java.io.File)

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