Search in sources :

Example 96 with Patch

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

the class RemotePatchInfoUnitTestCase method createOneOff.

protected File createOneOff(File oneOffDir, String oneOffId, String patchElementId, File moduleDir, ProductConfig productConfig) throws Exception {
    // patch misc file
    final ContentModification miscFileAdded = ContentModificationUtils.addMisc(oneOffDir, oneOffId, "Hello World!", "miscDir", "test-file");
    // patch module
    final ContentModification moduleModified = ContentModificationUtils.modifyModule(oneOffDir, patchElementId, moduleDir, "new resource in the module");
    final Patch oneOff = PatchBuilder.create().setPatchId(oneOffId).setDescription(descriptionFor(oneOffId)).setLink("http://test.one").oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().addContentModification(miscFileAdded).oneOffPatchElement(patchElementId, "base", false).setDescription(descriptionFor(patchElementId)).addContentModification(moduleModified).getParent().build();
    createPatchXMLFile(oneOffDir, oneOff);
    return PatchingTestUtil.createZippedPatchFile(oneOffDir, oneOffId);
}
Also used : ContentModification(org.jboss.as.patching.metadata.ContentModification) Patch(org.jboss.as.patching.metadata.Patch)

Example 97 with Patch

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

the class MergedCpWithSubmoduleTestCase method createTopModuleMainSlotUpdateCp2.

private File createTopModuleMainSlotUpdateCp2(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 topModuleModified;
    {
        final File topModulePath = IoUtils.newFile(tempDir, currentCpId, currentLayerPatchId, Constants.MODULES, topModuleName.replace('.', File.separatorChar), "main");
        final Module topModule = new Module.Builder(topModuleName).resourceRoot(cp1ResourceItem1).resourceRoot(cp1ResourceItem2).resourceRoot(cp2ResourceItem1).build();
        final byte[] currentTopModuleHash = HashUtils.hashFile(topModulePath);
        assert currentTopModuleHash != null;
        topModuleModified = ContentModificationUtils.modifyModule(cpPatchDir, layerPatchId, currentTopModuleHash, topModule);
    }
    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(topModuleModified).addContentModification(versionModuleModified).getParent().build();
    createPatchXMLFile(cpPatchDir, cpPatch);
    return createZippedPatchFile(cpPatchDir, cpId, targetDir);
}
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) 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 98 with Patch

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

the class MergedCpWithSubmoduleTestCase method createSubmoduleUpdateCp2.

private File createSubmoduleUpdateCp2(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 File subModulePath = IoUtils.newFile(tempDir, currentCpId, currentLayerPatchId, Constants.MODULES, subModuleName.replace('.', File.separatorChar), "main");
    final ResourceItem cp2ResourceItem1 = new ResourceItem("testFile3", "content1".getBytes());
    final Module subModule = new Module.Builder(subModuleName).resourceRoot(cp1ResourceItem1).resourceRoot(cp1ResourceItem2).resourceRoot(cp2ResourceItem1).build();
    final byte[] currentSubmoduleHash = HashUtils.hashFile(subModulePath);
    assert currentSubmoduleHash != null;
    final ContentModification subModuleModified = ContentModificationUtils.modifyModule(cpPatchDir, layerPatchId, currentSubmoduleHash, subModule);
    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(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 99 with Patch

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

the class BasicOneOffPatchingScenariosTestCase method testOneOffPatchRollbackTo.

/**
 * Prepare 3 one-offs, apply them and do --rollback-to second patch
 */
@Test
public void testOneOffPatchRollbackTo() throws Exception {
    final String fileContent = "Hello World!";
    // prepare the patch
    String patchID = randomString();
    File oneOffPatchDir = mkdir(tempDir, patchID);
    ContentModification miscFileAdded = ContentModificationUtils.addMisc(oneOffPatchDir, patchID, fileContent, "awesomeDirectory", "awesomeFile");
    ProductConfig productConfig = new ProductConfig(PRODUCT, AS_VERSION, "main");
    Patch oneOffPatch = PatchBuilder.create().setPatchId(patchID).setDescription("A one-off patch adding a misc file.").oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().addContentModification(miscFileAdded).build();
    createPatchXMLFile(oneOffPatchDir, oneOffPatch);
    File zippedPatch = createZippedPatchFile(oneOffPatchDir, patchID);
    // prepare the patch
    String patchID2 = randomString();
    File oneOffPatchDir2 = mkdir(tempDir, patchID2);
    ContentModification miscFileAdded2 = ContentModificationUtils.addMisc(oneOffPatchDir2, patchID2, fileContent, "awesomeDirectory", "awesomeFile2");
    Patch oneOffPatch2 = PatchBuilder.create().setPatchId(patchID2).setDescription("A one-off patch adding a misc file.").oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().addContentModification(miscFileAdded2).build();
    createPatchXMLFile(oneOffPatchDir2, oneOffPatch2);
    File zippedPatch2 = createZippedPatchFile(oneOffPatchDir2, patchID2);
    // prepare the patch
    String patchID3 = randomString();
    File oneOffPatchDir3 = mkdir(tempDir, patchID3);
    ContentModification miscFileAdded3 = ContentModificationUtils.addMisc(oneOffPatchDir3, patchID3, fileContent, "awesomeDirectory", "awesomeFile3");
    Patch oneOffPatch3 = PatchBuilder.create().setPatchId(patchID3).setDescription("A one-off patch adding a misc file.").oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().addContentModification(miscFileAdded3).build();
    createPatchXMLFile(oneOffPatchDir3, oneOffPatch3);
    File zippedPatch3 = createZippedPatchFile(oneOffPatchDir3, patchID3);
    // apply the patch and check if server is in restart-required mode
    controller.start();
    Assert.assertTrue("Patch should be accepted", CliUtilsForPatching.applyPatch(zippedPatch.getAbsolutePath()));
    Assert.assertTrue("server should be in restart-required mode", CliUtilsForPatching.doesServerRequireRestart());
    controller.stop();
    // apply second patch
    controller.start();
    Assert.assertTrue("The patch " + patchID + " should be listed as installed", CliUtilsForPatching.getInstalledPatches().contains(patchID));
    Assert.assertTrue("Patch should be accepted", CliUtilsForPatching.applyPatch(zippedPatch2.getAbsolutePath()));
    Assert.assertTrue("server should be in restart-required mode", CliUtilsForPatching.doesServerRequireRestart());
    controller.stop();
    // apply third patch
    controller.start();
    Assert.assertTrue("The patch " + patchID2 + " should be listed as installed", CliUtilsForPatching.getInstalledPatches().contains(patchID2));
    Assert.assertTrue("Patch should be accepted", CliUtilsForPatching.applyPatch(zippedPatch3.getAbsolutePath()));
    Assert.assertTrue("server should be in restart-required mode", CliUtilsForPatching.doesServerRequireRestart());
    controller.stop();
    // rollback to second patch
    controller.start();
    Assert.assertTrue("The patch " + patchID3 + " should be listed as installed", CliUtilsForPatching.getInstalledPatches().contains(patchID3));
    Assert.assertTrue("Rollback should be accepted", CliUtilsForPatching.rollbackToPatch(patchID2));
    controller.stop();
    // verify that only first patch is installed
    controller.start();
    Assert.assertFalse("The patch " + patchID3 + " should not be listed as installed", CliUtilsForPatching.getInstalledPatches().contains(patchID3));
    Assert.assertFalse("The patch " + patchID2 + " should not be listed as installed", CliUtilsForPatching.getInstalledPatches().contains(patchID2));
    Assert.assertTrue("The patch " + patchID + " should be listed as installed", CliUtilsForPatching.getInstalledPatches().contains(patchID));
    controller.stop();
}
Also used : ProductConfig(org.jboss.as.version.ProductConfig) PatchingTestUtil.randomString(org.jboss.as.test.patching.PatchingTestUtil.randomString) 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) Test(org.junit.Test)

Example 100 with Patch

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

the class BasicOneOffPatchingScenariosTestCase method testOneOffPatchDeletingAMiscFile.

/**
 * Prepare a one-off patch which removes a misc file. Apply it, check that the file was removed.
 * Roll it back, check that the file was restored and reapply patch
 */
@Test
public void testOneOffPatchDeletingAMiscFile() throws Exception {
    // prepare the patch
    String patchID = randomString();
    File oneOffPatchDir = mkdir(tempDir, patchID);
    final String testFilePath = AS_DISTRIBUTION + FILE_SEPARATOR + "README.txt";
    // store original content
    String originalContent = readFile(testFilePath);
    ContentModification miscFileRemoved = ContentModificationUtils.removeMisc(new File(testFilePath), "");
    ProductConfig productConfig = new ProductConfig(PRODUCT, AS_VERSION, "main");
    Patch oneOffPatch = PatchBuilder.create().setPatchId(patchID).setDescription("A one-off patch removing a misc file.").oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().addContentModification(miscFileRemoved).build();
    createPatchXMLFile(oneOffPatchDir, oneOffPatch);
    File zippedPatch = createZippedPatchFile(oneOffPatchDir, patchID);
    // apply the patch and check if server is in restart-required mode
    controller.start();
    Assert.assertTrue("Patch should be accepted", CliUtilsForPatching.applyPatch(zippedPatch.getAbsolutePath()));
    Assert.assertTrue("server should be in restart-required mode", CliUtilsForPatching.doesServerRequireRestart());
    controller.stop();
    // check that patch is installed, file doesn't exist
    controller.start();
    Assert.assertTrue("The patch " + patchID + " should be listed as installed", CliUtilsForPatching.getInstalledPatches().contains(patchID));
    Assert.assertFalse("File " + testFilePath + " should have been deleted", new File(testFilePath).exists());
    // rollback the patch and check if server is in restart-required mode
    Assert.assertTrue("Rollback should be accepted", CliUtilsForPatching.rollbackPatch(patchID));
    Assert.assertTrue("server should be in restart-required mode", CliUtilsForPatching.doesServerRequireRestart());
    controller.stop();
    // check that the patch is uninstalled and file is restored
    controller.start();
    Assert.assertFalse("The patch " + patchID + " NOT should be listed as installed", CliUtilsForPatching.getInstalledPatches().contains(patchID));
    Assert.assertTrue("File + " + testFilePath + " should be restored", new File(testFilePath).exists());
    Assert.assertEquals("Unexpected contents of misc file", originalContent, readFile(testFilePath));
    // reapply patch and check if server is in restart-required mode
    Assert.assertTrue("Patch should be accepted", CliUtilsForPatching.applyPatch(zippedPatch.getAbsolutePath()));
    Assert.assertTrue("server should be in restart-required mode", CliUtilsForPatching.doesServerRequireRestart());
    controller.stop();
    // check that patch is installed, file doesn't exist
    controller.start();
    Assert.assertTrue("The patch " + patchID + " should be listed as installed", CliUtilsForPatching.getInstalledPatches().contains(patchID));
    Assert.assertFalse("File " + testFilePath + " should have been deleted", new File(testFilePath).exists());
    controller.stop();
}
Also used : ProductConfig(org.jboss.as.version.ProductConfig) PatchingTestUtil.randomString(org.jboss.as.test.patching.PatchingTestUtil.randomString) 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) Test(org.junit.Test)

Aggregations

Patch (org.jboss.as.patching.metadata.Patch)110 ContentModification (org.jboss.as.patching.metadata.ContentModification)94 File (java.io.File)93 Test (org.junit.Test)66 IoUtils.newFile (org.jboss.as.patching.IoUtils.newFile)60 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)33 TestUtils.createPatchXMLFile (org.jboss.as.patching.runner.TestUtils.createPatchXMLFile)30 TestUtils.createZippedPatchFile (org.jboss.as.patching.runner.TestUtils.createZippedPatchFile)30 Module (org.jboss.as.test.patching.util.module.Module)29 PatchingResult (org.jboss.as.patching.tool.PatchingResult)24 PatchingTestUtil.readFile (org.jboss.as.test.patching.PatchingTestUtil.readFile)24 InstalledIdentity (org.jboss.as.patching.installation.InstalledIdentity)22 IOException (java.io.IOException)14 PatchBuilder (org.jboss.as.patching.metadata.PatchBuilder)14 PatchElement (org.jboss.as.patching.metadata.PatchElement)13 HashUtils.hashFile (org.jboss.as.patching.HashUtils.hashFile)12