Search in sources :

Example 21 with Module

use of org.jboss.as.test.patching.util.module.Module in project wildfly-core by wildfly.

the class AgeOutHistoryUnitTestCase method testOneOffsOnly.

@Test
public void testOneOffsOnly() throws Exception {
    Module module = new Module.Builder("module-test").miscFile(new ResourceItem("resource-test", ("module resource").getBytes(StandardCharsets.UTF_8))).build();
    File moduleDir = module.writeToDisk(new File(MODULES_PATH));
    byte[] targetHash = HashUtils.hashFile(moduleDir);
    targetHash = applyOneOff("oneoff1", targetHash);
    targetHash = applyOneOff("oneoff2", targetHash);
    controller.start();
    try {
        client = createClient();
        assertPatched(client, new String[] { "oneoff2", "oneoff1" }, new boolean[] { false, false }, new boolean[] { false, false });
        assertRollbackList(client, new String[] { "oneoff2", "oneoff1" }, new boolean[] { false, false }, new boolean[] { false, false });
        ageoutHistory(client);
        assertPatched(client, new String[] { "oneoff2", "oneoff1" }, new boolean[] { false, false }, new boolean[] { false, false });
        assertRollbackList(client, new String[] { "oneoff2", "oneoff1" }, new boolean[] { false, false }, new boolean[] { false, false });
    } finally {
        controller.stop();
    }
}
Also used : PatchBuilder(org.jboss.as.patching.metadata.PatchBuilder) Module(org.jboss.as.test.patching.util.module.Module) IoUtils.newFile(org.jboss.as.patching.IoUtils.newFile) PatchingTestUtil.createZippedPatchFile(org.jboss.as.test.patching.PatchingTestUtil.createZippedPatchFile) File(java.io.File) PatchingTestUtil.createPatchXMLFile(org.jboss.as.test.patching.PatchingTestUtil.createPatchXMLFile) Test(org.junit.Test)

Example 22 with Module

use of org.jboss.as.test.patching.util.module.Module in project wildfly-core by wildfly.

the class AgeOutHistoryUnitTestCase method testOneCP.

@Test
public void testOneCP() throws Exception {
    Module module = new Module.Builder("module-test").miscFile(new ResourceItem("resource-test", ("module resource").getBytes(StandardCharsets.UTF_8))).build();
    File moduleDir = module.writeToDisk(new File(MODULES_PATH));
    byte[] targetHash = HashUtils.hashFile(moduleDir);
    targetHash = applyCP("cp1", targetHash);
    controller.start();
    try {
        client = createClient();
        assertPatched(client, new String[] { "cp1" }, new boolean[] { true }, new boolean[] { false });
        assertRollbackList(client, new String[] { "cp1" }, new boolean[] { true }, new boolean[] { false });
        ageoutHistory(client);
        assertPatched(client, new String[] { "cp1" }, new boolean[] { true }, new boolean[] { false });
        assertRollbackList(client, new String[] { "cp1" }, new boolean[] { true }, new boolean[] { false });
    } finally {
        controller.stop();
    }
}
Also used : PatchBuilder(org.jboss.as.patching.metadata.PatchBuilder) Module(org.jboss.as.test.patching.util.module.Module) IoUtils.newFile(org.jboss.as.patching.IoUtils.newFile) PatchingTestUtil.createZippedPatchFile(org.jboss.as.test.patching.PatchingTestUtil.createZippedPatchFile) File(java.io.File) PatchingTestUtil.createPatchXMLFile(org.jboss.as.test.patching.PatchingTestUtil.createPatchXMLFile) Test(org.junit.Test)

Example 23 with Module

use of org.jboss.as.test.patching.util.module.Module in project wildfly-core by wildfly.

the class AgeOutHistoryUnitTestCase method applyPatch.

protected byte[] applyPatch(String patchID, byte[] targetHash, boolean cp) throws Exception {
    String moduleName = "module-test";
    String patchElementId = randomString();
    File patchDir = mkdir(tempDir, patchID);
    Module module = new Module.Builder(moduleName).miscFile(new ResourceItem("resource-test", ("resource patch " + patchID).getBytes(StandardCharsets.UTF_8))).build();
    // create the patch with the updated module
    ContentModification moduleModified = ContentModificationUtils.modifyModule(patchDir, patchElementId, targetHash, module);
    PatchBuilder patchBuilder = PatchBuilder.create().setPatchId(patchID).setDescription(randomString());
    if (cp) {
        patchBuilder = patchBuilder.upgradeIdentity(productConfig.getProductName(), productConfig.getProductVersion(), PatchingTestUtil.AS_VERSION + "_CP" + patchID).getParent().upgradeElement(patchElementId, "base", false).addContentModification(moduleModified).getParent();
    } else {
        patchBuilder = patchBuilder.oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().oneOffPatchElement(patchElementId, "base", false).addContentModification(moduleModified).getParent();
    }
    Patch patch = patchBuilder.build();
    // create the patch
    createPatchXMLFile(patchDir, patch);
    File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
    // apply the patch and check if server is in restart-required mode
    controller.start();
    try {
        Assert.assertTrue("Patch should be accepted", CliUtilsForPatching.applyPatch(zippedPatch.getAbsolutePath()));
        Assert.assertTrue("server should be in restart-required mode", CliUtilsForPatching.doesServerRequireRestart());
        if (cp) {
            productConfig = new ProductConfig(PatchingTestUtil.PRODUCT, PatchingTestUtil.AS_VERSION + "_CP" + patchID, "main");
        }
    } finally {
        controller.stop();
    }
    return moduleModified.getItem().getContentHash();
}
Also used : PatchBuilder(org.jboss.as.patching.metadata.PatchBuilder) PatchBuilder(org.jboss.as.patching.metadata.PatchBuilder) ProductConfig(org.jboss.as.version.ProductConfig) PatchingTestUtil.randomString(org.jboss.as.test.patching.PatchingTestUtil.randomString) Module(org.jboss.as.test.patching.util.module.Module) IoUtils.newFile(org.jboss.as.patching.IoUtils.newFile) PatchingTestUtil.createZippedPatchFile(org.jboss.as.test.patching.PatchingTestUtil.createZippedPatchFile) File(java.io.File) PatchingTestUtil.createPatchXMLFile(org.jboss.as.test.patching.PatchingTestUtil.createPatchXMLFile) ContentModification(org.jboss.as.patching.metadata.ContentModification) Patch(org.jboss.as.patching.metadata.Patch)

Example 24 with Module

use of org.jboss.as.test.patching.util.module.Module in project wildfly-core by wildfly.

the class PatchBundleTestCase method createNextCumulativePatchModyfyingJbossModules.

private File createNextCumulativePatchModyfyingJbossModules(String patchID, String asVersion, final String currentPatch, final String targetAsVersion, File targetDir) throws Exception {
    String layerPatchID = "layer" + patchID;
    File cpPatchDir = mkdir(tempDir, patchID);
    // Also see if we can update jboss-modules
    final File installation = new File(AS_DISTRIBUTION);
    final File patchDir = new File(cpPatchDir, patchID);
    final ContentModification jbossModulesModification = PatchingTestUtil.updateModulesJar(installation, patchDir);
    // Create the version module
    final String versionModuleName = ProductInfo.getVersionModule();
    final Module modifiedModule = PatchingTestUtil.createVersionModule(targetAsVersion);
    // Calculate the target hash of the currently active module
    final String currentLayerPatchID = "layer" + currentPatch;
    File originalVersionModulePath = new File(tempDir, currentPatch);
    originalVersionModulePath = new File(originalVersionModulePath, currentLayerPatchID);
    originalVersionModulePath = new File(originalVersionModulePath, Constants.MODULES);
    originalVersionModulePath = newFile(originalVersionModulePath, versionModuleName.split("\\."));
    originalVersionModulePath = new File(originalVersionModulePath, ProductInfo.getVersionModuleSlot());
    byte[] patchedAsVersionHash = HashUtils.hashFile(originalVersionModulePath);
    assert patchedAsVersionHash != null;
    ContentModification versionModuleModified = ContentModificationUtils.modifyModule(cpPatchDir, layerPatchID, patchedAsVersionHash, modifiedModule);
    Patch cpPatch = PatchBuilder.create().setPatchId(patchID).setDescription("A cp patch.").upgradeIdentity(PRODUCT, asVersion, targetAsVersion).getParent().upgradeElement(layerPatchID, "base", false).addContentModification(versionModuleModified).getParent().addContentModification(jbossModulesModification).build();
    createPatchXMLFile(cpPatchDir, cpPatch);
    return createZippedPatchFile(cpPatchDir, patchID, targetDir);
}
Also used : PatchingTestUtil.randomString(org.jboss.as.test.patching.PatchingTestUtil.randomString) Module(org.jboss.as.test.patching.util.module.Module) IoUtils.newFile(org.jboss.as.patching.IoUtils.newFile) PatchingTestUtil.createPatchBundleXMLFile(org.jboss.as.test.patching.PatchingTestUtil.createPatchBundleXMLFile) PatchingTestUtil.createZippedPatchFile(org.jboss.as.test.patching.PatchingTestUtil.createZippedPatchFile) File(java.io.File) PatchingTestUtil.createPatchXMLFile(org.jboss.as.test.patching.PatchingTestUtil.createPatchXMLFile) ContentModification(org.jboss.as.patching.metadata.ContentModification) Patch(org.jboss.as.patching.metadata.Patch) BundledPatch(org.jboss.as.patching.metadata.BundledPatch)

Example 25 with Module

use of org.jboss.as.test.patching.util.module.Module in project wildfly-core by wildfly.

the class PatchBundleTestCase method createCumulativePatchAddingARandomModule.

private File createCumulativePatchAddingARandomModule(String patchID, String asVersion, final String targetAsVersion, File targetDir) throws Exception {
    String layerPatchID = "layer" + patchID;
    File cpPatchDir = mkdir(tempDir, patchID);
    final String moduleName = "org.wildfly.test." + randomString();
    final ResourceItem resourceItem1 = new ResourceItem("testFile1", "content1".getBytes(StandardCharsets.UTF_8));
    final ResourceItem resourceItem2 = new ResourceItem("testFile2", "content2".getBytes(StandardCharsets.UTF_8));
    Module newModule = new Module.Builder(moduleName).miscFile(resourceItem1).miscFile(resourceItem2).build();
    // Create the version module
    final String versionModuleName = ProductInfo.getVersionModule();
    final String slot = ProductInfo.getVersionModuleSlot();
    final String originalVersionModulePath = MODULES_PATH + FILE_SEPARATOR + versionModuleName.replace(".", FILE_SEPARATOR) + FILE_SEPARATOR + slot;
    final Module modifiedModule = PatchingTestUtil.createVersionModule(targetAsVersion);
    ContentModification moduleAdded = ContentModificationUtils.addModule(cpPatchDir, layerPatchID, newModule);
    ContentModification versionModuleModified = ContentModificationUtils.modifyModule(cpPatchDir, layerPatchID, HashUtils.hashFile(new File(originalVersionModulePath)), modifiedModule);
    Patch cpPatch = PatchBuilder.create().setPatchId(patchID).setDescription("A cp patch.").upgradeIdentity(PRODUCT, asVersion, targetAsVersion).getParent().upgradeElement(layerPatchID, "base", false).addContentModification(moduleAdded).addContentModification(versionModuleModified).getParent().build();
    createPatchXMLFile(cpPatchDir, cpPatch);
    return createZippedPatchFile(cpPatchDir, patchID, targetDir);
}
Also used : PatchingTestUtil.randomString(org.jboss.as.test.patching.PatchingTestUtil.randomString) Module(org.jboss.as.test.patching.util.module.Module) IoUtils.newFile(org.jboss.as.patching.IoUtils.newFile) PatchingTestUtil.createPatchBundleXMLFile(org.jboss.as.test.patching.PatchingTestUtil.createPatchBundleXMLFile) PatchingTestUtil.createZippedPatchFile(org.jboss.as.test.patching.PatchingTestUtil.createZippedPatchFile) File(java.io.File) PatchingTestUtil.createPatchXMLFile(org.jboss.as.test.patching.PatchingTestUtil.createPatchXMLFile) ContentModification(org.jboss.as.patching.metadata.ContentModification) Patch(org.jboss.as.patching.metadata.Patch) BundledPatch(org.jboss.as.patching.metadata.BundledPatch)

Aggregations

File (java.io.File)39 Module (org.jboss.as.test.patching.util.module.Module)39 PatchingTestUtil.createPatchXMLFile (org.jboss.as.test.patching.PatchingTestUtil.createPatchXMLFile)34 PatchingTestUtil.createZippedPatchFile (org.jboss.as.test.patching.PatchingTestUtil.createZippedPatchFile)34 ContentModification (org.jboss.as.patching.metadata.ContentModification)29 Patch (org.jboss.as.patching.metadata.Patch)29 IoUtils.newFile (org.jboss.as.patching.IoUtils.newFile)28 PatchingTestUtil.randomString (org.jboss.as.test.patching.PatchingTestUtil.randomString)28 Test (org.junit.Test)21 PatchBuilder (org.jboss.as.patching.metadata.PatchBuilder)15 ProductConfig (org.jboss.as.version.ProductConfig)14 PatchingTestUtil.readFile (org.jboss.as.test.patching.PatchingTestUtil.readFile)9 ModelNode (org.jboss.dmr.ModelNode)5 BundledPatch (org.jboss.as.patching.metadata.BundledPatch)3 PatchingTestUtil.createPatchBundleXMLFile (org.jboss.as.test.patching.PatchingTestUtil.createPatchBundleXMLFile)3 CommandContext (org.jboss.as.cli.CommandContext)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Before (org.junit.Before)1