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);
}
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);
}
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);
}
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();
}
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();
}
Aggregations