Search in sources :

Example 11 with Module

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

the class CumulativePatchingScenariosTestCase method createCumulativePatch.

private File createCumulativePatch(String patchID, String asVersion, final String targetAsVersion) 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));
    // 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);
    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().addContentModification(jbossModulesModification).build();
    createPatchXMLFile(cpPatchDir, cpPatch);
    return createZippedPatchFile(cpPatchDir, patchID);
}
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.createZippedPatchFile(org.jboss.as.test.patching.PatchingTestUtil.createZippedPatchFile) File(java.io.File) PatchingTestUtil.createPatchXMLFile(org.jboss.as.test.patching.PatchingTestUtil.createPatchXMLFile) PatchingTestUtil.readFile(org.jboss.as.test.patching.PatchingTestUtil.readFile) ContentModification(org.jboss.as.patching.metadata.ContentModification) Patch(org.jboss.as.patching.metadata.Patch)

Example 12 with Module

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

the class CumulativePatchingScenariosTestCase method createOneOffPatchAddingAModule.

private File createOneOffPatchAddingAModule(String patchID, String asVersion) throws Exception {
    String layerPatchID = randomString();
    File oneOffPatchDir = 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();
    ContentModification moduleAdded = ContentModificationUtils.addModule(oneOffPatchDir, layerPatchID, newModule);
    Patch oneOffPatch = PatchBuilder.create().setPatchId(patchID).setDescription("A one-off patch adding a new module.").oneOffPatchIdentity(PRODUCT, asVersion).getParent().oneOffPatchElement(layerPatchID, "base", false).setDescription("New module for the base layer").addContentModification(moduleAdded).getParent().build();
    createPatchXMLFile(oneOffPatchDir, oneOffPatch);
    return createZippedPatchFile(oneOffPatchDir, patchID);
}
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.createZippedPatchFile(org.jboss.as.test.patching.PatchingTestUtil.createZippedPatchFile) File(java.io.File) PatchingTestUtil.createPatchXMLFile(org.jboss.as.test.patching.PatchingTestUtil.createPatchXMLFile) PatchingTestUtil.readFile(org.jboss.as.test.patching.PatchingTestUtil.readFile) ContentModification(org.jboss.as.patching.metadata.ContentModification) Patch(org.jboss.as.patching.metadata.Patch)

Example 13 with Module

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

the class CumulativePatchingScenariosTestCase method createSecondCumulativePatch.

private File createSecondCumulativePatch(String patchID, String asVersion, final String currentPatch, final String targetAsVersion) throws Exception {
    String layerPatchID = "layer" + patchID;
    File cpPatchDir = mkdir(tempDir, patchID);
    // 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;
    final String originalVersionModulePath = MODULES_PATH + FILE_SEPARATOR + Constants.OVERLAYS + FILE_SEPARATOR + currentLayerPatchID + FILE_SEPARATOR + versionModuleName.replace(".", FILE_SEPARATOR) + FILE_SEPARATOR + ProductInfo.getVersionModuleSlot();
    byte[] patchedAsVersionHash = HashUtils.hashFile(new File(originalVersionModulePath));
    assert patchedAsVersionHash != null;
    ContentModification versionModuleModified = ContentModificationUtils.modifyModule(cpPatchDir, layerPatchID, patchedAsVersionHash, modifiedModule);
    ProductConfig productConfig = new ProductConfig(PRODUCT, asVersion, "main");
    Patch cpPatch = PatchBuilder.create().setPatchId(patchID).setDescription("A cp patch.").upgradeIdentity(productConfig.getProductName(), productConfig.getProductVersion(), targetAsVersion).getParent().upgradeElement(layerPatchID, "base", false).addContentModification(versionModuleModified).getParent().build();
    createPatchXMLFile(cpPatchDir, cpPatch);
    return createZippedPatchFile(cpPatchDir, patchID);
}
Also used : 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) PatchingTestUtil.readFile(org.jboss.as.test.patching.PatchingTestUtil.readFile) ContentModification(org.jboss.as.patching.metadata.ContentModification) Patch(org.jboss.as.patching.metadata.Patch)

Example 14 with Module

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

the class MergedCpWithSubmoduleTestCase method createAllUpdatedCp2.

private File createAllUpdatedCp2(String cpId, String asVersion, final String currentCpId, final String targetAsVersion, File targetDir) throws Exception {
    final String layerPatchId = "layer" + cpId;
    File cpPatchDir = mkdir(tempDir, cpId);
    // 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" + currentCpId;
    final File originalVersionModulePath = IoUtils.newFile(tempDir, currentCpId, currentLayerPatchId, Constants.MODULES, versionModuleName.replace('.', File.separatorChar), ProductInfo.getVersionModuleSlot());
    byte[] patchedAsVersionHash = HashUtils.hashFile(originalVersionModulePath);
    assert patchedAsVersionHash != null;
    ContentModification versionModuleModified = ContentModificationUtils.modifyModule(cpPatchDir, layerPatchId, patchedAsVersionHash, modifiedModule);
    final ResourceItem cp2ResourceItem1 = new ResourceItem("testFile3", "content1".getBytes());
    final ContentModification subModuleModified;
    {
        final File subModulePath = IoUtils.newFile(tempDir, currentCpId, currentLayerPatchId, Constants.MODULES, subModuleName.replace('.', File.separatorChar), "main");
        final Module subModule = new Module.Builder(subModuleName).resourceRoot(cp1ResourceItem1).resourceRoot(cp1ResourceItem2).resourceRoot(cp2ResourceItem1).build();
        final byte[] currentSubmoduleHash = HashUtils.hashFile(subModulePath);
        assert currentSubmoduleHash != null;
        subModuleModified = ContentModificationUtils.modifyModule(cpPatchDir, layerPatchId, currentSubmoduleHash, subModule);
    }
    final ContentModification topModule41Modified;
    {
        final File topModulePath = IoUtils.newFile(tempDir, currentCpId, currentLayerPatchId, Constants.MODULES, topModuleName.replace('.', File.separatorChar), "slot41");
        final Module topModule41 = new Module.Builder(topModuleName).slot("slot41").resourceRoot(cp1ResourceItem1).resourceRoot(cp1ResourceItem2).resourceRoot(cp2ResourceItem1).build();
        final byte[] currentTopModuleHash = HashUtils.hashFile(topModulePath);
        assert currentTopModuleHash != null;
        topModule41Modified = ContentModificationUtils.modifyModule(cpPatchDir, layerPatchId, currentTopModuleHash, topModule41);
    }
    final ContentModification topModuleMainModified;
    {
        final File topModulePath = IoUtils.newFile(tempDir, currentCpId, currentLayerPatchId, Constants.MODULES, topModuleName.replace('.', File.separatorChar), "main");
        final Module topModuleMain = new Module.Builder(topModuleName).slot("main").resourceRoot(cp1ResourceItem1).resourceRoot(cp1ResourceItem2).resourceRoot(cp2ResourceItem1).build();
        final byte[] currentTopModuleHash = HashUtils.hashFile(topModulePath);
        assert currentTopModuleHash != null;
        topModuleMainModified = ContentModificationUtils.modifyModule(cpPatchDir, layerPatchId, currentTopModuleHash, topModuleMain);
    }
    ProductConfig productConfig = new ProductConfig(PRODUCT, asVersion, "main");
    Patch cpPatch = PatchBuilder.create().setPatchId(cpId).setDescription("A cp patch.").upgradeIdentity(productConfig.getProductName(), productConfig.getProductVersion(), targetAsVersion).getParent().upgradeElement(layerPatchId, "base", false).addContentModification(topModuleMainModified).addContentModification(topModule41Modified).addContentModification(subModuleModified).addContentModification(versionModuleModified).getParent().build();
    createPatchXMLFile(cpPatchDir, cpPatch);
    return createZippedPatchFile(cpPatchDir, cpId, targetDir);
}
Also used : 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) 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 15 with Module

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

the class MergedCpWithSubmoduleTestCase method createCp1.

private File createCp1(String cpId, String asVersion, final String targetAsVersion, File targetDir) throws Exception {
    final String cp1LayerPatchId = "layer" + cpId;
    File cpPatchDir = mkdir(tempDir, cpId);
    cp1ResourceItem1 = new ResourceItem("testFile1", "content1".getBytes());
    cp1ResourceItem2 = new ResourceItem("testFile2", "content2".getBytes());
    final Module topModuleMain = new Module.Builder(topModuleName).resourceRoot(cp1ResourceItem1).resourceRoot(cp1ResourceItem2).build();
    final Module topModule41 = new Module.Builder(topModuleName).slot("slot41").resourceRoot(cp1ResourceItem1).resourceRoot(cp1ResourceItem2).build();
    final Module subModule = new Module.Builder(subModuleName).resourceRoot(cp1ResourceItem1).resourceRoot(cp1ResourceItem2).build();
    // Create the version module
    final String versionModuleName = ProductInfo.getVersionModule();
    cp1Slot = ProductInfo.getVersionModuleSlot();
    final String originalVersionModulePath = MODULES_PATH + FILE_SEPARATOR + versionModuleName.replace(".", FILE_SEPARATOR) + FILE_SEPARATOR + cp1Slot;
    final Module modifiedModule = PatchingTestUtil.createVersionModule(targetAsVersion);
    final ContentModification topModuleMainAdded = ContentModificationUtils.addModule(cpPatchDir, cp1LayerPatchId, topModuleMain);
    final ContentModification topModule41Added = ContentModificationUtils.addModule(cpPatchDir, cp1LayerPatchId, topModule41);
    final ContentModification subModuleAdded = ContentModificationUtils.addModule(cpPatchDir, cp1LayerPatchId, subModule);
    ContentModification versionModuleModified = ContentModificationUtils.modifyModule(cpPatchDir, cp1LayerPatchId, HashUtils.hashFile(new File(originalVersionModulePath)), modifiedModule);
    Patch cpPatch = PatchBuilder.create().setPatchId(cpId).setDescription("A cp patch.").upgradeIdentity(PRODUCT, asVersion, targetAsVersion).getParent().upgradeElement(cp1LayerPatchId, "base", false).addContentModification(subModuleAdded).addContentModification(topModuleMainAdded).addContentModification(topModule41Added).addContentModification(versionModuleModified).getParent().build();
    createPatchXMLFile(cpPatchDir, cpPatch);
    return createZippedPatchFile(cpPatchDir, cpId, targetDir);
}
Also used : PatchBuilder(org.jboss.as.patching.metadata.PatchBuilder) PatchingTestUtil.randomString(org.jboss.as.test.patching.PatchingTestUtil.randomString) Module(org.jboss.as.test.patching.util.module.Module) 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)

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