use of org.jboss.as.test.patching.util.module.Module in project wildfly-core by wildfly.
the class MergedCpWithSubmoduleTestCase method createTopModuleSlotAndSubmoduleUpdateCp2.
private File createTopModuleSlotAndSubmoduleUpdateCp2(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);
}
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(topModule41Modified).addContentModification(subModuleModified).addContentModification(versionModuleModified).getParent().build();
createPatchXMLFile(cpPatchDir, cpPatch);
return createZippedPatchFile(cpPatchDir, cpId, targetDir);
}
use of org.jboss.as.test.patching.util.module.Module in project wildfly-core by wildfly.
the class CPRollingbackOneOffTestCase method testCPOneOffCPOneOff.
/**
* - CP patch updates a module;
* - one-off patch updates the same module;
* - CP updates the same module;
* - one-off patch updates the same module.
*/
@Test
public void testCPOneOffCPOneOff() throws Exception {
// build a one-off patch for the base installation
// with 1 updated file
String patchID = randomString();
File patchDir = mkdir(tempDir, patchID);
final String patchElement1Id = randomString();
// create a module to be updated w/o a conflict
File baseModuleDir = newFile(new File(PatchingTestUtil.AS_DISTRIBUTION), MODULES, SYSTEM, LAYERS, BASE);
String moduleAName = "org.a.module-a";
Module moduleA = new Module.Builder(moduleAName).resourceRoot(new ResourceItem(jarA.getName(), jarABytes)).miscFile(new ResourceItem("resource-a", "resource a in the module".getBytes(StandardCharsets.UTF_8))).build();
File moduleADir = moduleA.writeToDisk(new File(MODULES_PATH));
moduleA = new Module.Builder(moduleAName).miscFile(new ResourceItem("resource-a", "resource cp1".getBytes(StandardCharsets.UTF_8))).build();
// create the patch with the updated module
ContentModification moduleAModified = ContentModificationUtils.modifyModule(patchDir, patchElement1Id, HashUtils.hashFile(moduleADir), moduleA);
Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).upgradeIdentity(productConfig.getProductName(), productConfig.getProductVersion(), productConfig.getProductVersion()).getParent().upgradeElement(patchElement1Id, "base", false).addContentModification(moduleAModified).getParent().build();
// create the patch
createPatchXMLFile(patchDir, patch);
File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
// no patches applied
assertPatchElements(baseModuleDir, null);
applyPatch(zippedPatch);
assertPatchElements(baseModuleDir, new String[] { patchElement1Id }, false);
patchID = randomString();
final String patchElement2Id = randomString();
patchDir = mkdir(tempDir, patchID);
moduleA = new Module.Builder(moduleAName).miscFile(new ResourceItem("resource-a", "resource oneoff1".getBytes(StandardCharsets.UTF_8))).build();
// create the patch with the updated module
moduleAModified = ContentModificationUtils.modifyModule(patchDir, patchElement2Id, moduleAModified.getItem().getContentHash(), moduleA);
patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().oneOffPatchElement(patchElement2Id, "base", false).addContentModification(moduleAModified).getParent().build();
// create the patch
createPatchXMLFile(patchDir, patch);
zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
applyPatch(zippedPatch);
assertPatchElements(baseModuleDir, new String[] { patchElement1Id, patchElement2Id }, false);
patchID = randomString();
final String patchElement3Id = randomString();
patchDir = mkdir(tempDir, patchID);
moduleA = new Module.Builder(moduleAName).miscFile(new ResourceItem("resource-a", "resource oneoff1".getBytes(StandardCharsets.UTF_8))).build();
// create the patch with the updated module
moduleAModified = ContentModificationUtils.modifyModule(patchDir, patchElement3Id, moduleAModified.getItem().getContentHash(), moduleA);
patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).upgradeIdentity(productConfig.getProductName(), productConfig.getProductVersion(), productConfig.getProductVersion()).getParent().upgradeElement(patchElement3Id, "base", false).addContentModification(moduleAModified).getParent().build();
// create the patch
createPatchXMLFile(patchDir, patch);
zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
applyPatch(zippedPatch);
assertPatchElements(baseModuleDir, new String[] { patchElement1Id, patchElement2Id, patchElement3Id }, false);
patchID = randomString();
final String patchElement4Id = randomString();
patchDir = mkdir(tempDir, patchID);
moduleA = new Module.Builder(moduleAName).miscFile(new ResourceItem("resource-a", "resource oneoff2".getBytes(StandardCharsets.UTF_8))).build();
// create the patch with the updated module
moduleAModified = ContentModificationUtils.modifyModule(patchDir, patchElement4Id, moduleAModified.getItem().getContentHash(), moduleA);
patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().oneOffPatchElement(patchElement4Id, "base", false).addContentModification(moduleAModified).getParent().build();
// create the patch
createPatchXMLFile(patchDir, patch);
zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
applyPatch(zippedPatch);
assertPatchElements(baseModuleDir, new String[] { patchElement1Id, patchElement2Id, patchElement3Id, patchElement4Id }, false);
assertControllerStarts();
rollbackLast();
assertPatchElements(baseModuleDir, new String[] { patchElement1Id, patchElement2Id, patchElement3Id }, false);
assertControllerStarts();
rollbackLast();
assertPatchElements(baseModuleDir, new String[] { patchElement1Id, patchElement2Id }, false);
assertControllerStarts();
rollbackLast();
assertPatchElements(baseModuleDir, new String[] { patchElement1Id }, false);
assertControllerStarts();
rollbackLast();
assertPatchElements(baseModuleDir, null);
assertControllerStarts();
}
use of org.jboss.as.test.patching.util.module.Module in project wildfly-core by wildfly.
the class CPRollingbackOneOffTestCase method testCPOneOffCP.
/**
* - CP patch updates a module;
* - one-off patch updates the same module;
* - CP updates another module.
*/
@Test
public void testCPOneOffCP() throws Exception {
// build a one-off patch for the base installation
// with 1 updated file
String patchID = randomString();
File patchDir = mkdir(tempDir, patchID);
final String patchElement1Id = randomString();
// create a module to be updated w/o a conflict
File baseModuleDir = newFile(new File(PatchingTestUtil.AS_DISTRIBUTION), MODULES, SYSTEM, LAYERS, BASE);
String moduleAName = "org.a.module-a";
Module moduleA = new Module.Builder(moduleAName).resourceRoot(new ResourceItem(jarA.getName(), jarABytes)).miscFile(new ResourceItem("resource-a", "resource a in the module".getBytes(StandardCharsets.UTF_8))).build();
File moduleADir = moduleA.writeToDisk(new File(MODULES_PATH));
String moduleBName = "org.b.module-b";
Module moduleB = new Module.Builder(moduleBName).resourceRoot(new ResourceItem(jarB.getName(), jarBBytes)).miscFile(new ResourceItem("resource-b", "resource b in the module".getBytes(StandardCharsets.UTF_8))).build();
File moduleBDir = moduleB.writeToDisk(new File(MODULES_PATH));
moduleA = new Module.Builder(moduleAName).miscFile(new ResourceItem("resource-a", "resource cp1".getBytes(StandardCharsets.UTF_8))).build();
// create the patch with the updated module
ContentModification moduleAModified = ContentModificationUtils.modifyModule(patchDir, patchElement1Id, HashUtils.hashFile(moduleADir), moduleA);
Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).upgradeIdentity(productConfig.getProductName(), productConfig.getProductVersion(), productConfig.getProductVersion()).getParent().upgradeElement(patchElement1Id, "base", false).addContentModification(moduleAModified).getParent().build();
// create the patch
createPatchXMLFile(patchDir, patch);
File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
// no patches applied
assertPatchElements(baseModuleDir, null);
applyPatch(zippedPatch);
assertPatchElements(baseModuleDir, new String[] { patchElement1Id }, false);
patchID = randomString();
final String patchElement2Id = randomString();
patchDir = mkdir(tempDir, patchID);
moduleA = new Module.Builder(moduleAName).miscFile(new ResourceItem("resource-a", "resource oneoff1".getBytes(StandardCharsets.UTF_8))).build();
// create the patch with the updated module
moduleAModified = ContentModificationUtils.modifyModule(patchDir, patchElement2Id, moduleAModified.getItem().getContentHash(), moduleA);
patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().oneOffPatchElement(patchElement2Id, "base", false).addContentModification(moduleAModified).getParent().build();
// create the patch
createPatchXMLFile(patchDir, patch);
zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
applyPatch(zippedPatch);
assertPatchElements(baseModuleDir, new String[] { patchElement1Id, patchElement2Id }, false);
patchID = randomString();
final String patchElement3Id = randomString();
patchDir = mkdir(tempDir, patchID);
moduleB = new Module.Builder(moduleBName).miscFile(new ResourceItem("resource-b", "resource b cp".getBytes(StandardCharsets.UTF_8))).build();
// create the patch with the updated module
ContentModification moduleBModified = ContentModificationUtils.modifyModule(patchDir, patchElement3Id, HashUtils.hashFile(moduleBDir), moduleB);
patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).upgradeIdentity(productConfig.getProductName(), productConfig.getProductVersion(), productConfig.getProductVersion() + "_CP2").getParent().upgradeElement(patchElement3Id, "base", false).addContentModification(moduleBModified).getParent().build();
// create the patch
createPatchXMLFile(patchDir, patch);
zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
applyPatch(zippedPatch);
assertPatchElements(baseModuleDir, new String[] { patchElement1Id, patchElement2Id, patchElement3Id }, false);
assertControllerStarts();
rollbackLast();
assertPatchElements(baseModuleDir, new String[] { patchElement1Id, patchElement2Id }, false);
assertControllerStarts();
rollbackLast();
assertPatchElements(baseModuleDir, new String[] { patchElement1Id }, false);
assertControllerStarts();
rollbackLast();
assertPatchElements(baseModuleDir, null);
assertControllerStarts();
}
use of org.jboss.as.test.patching.util.module.Module in project wildfly-core by wildfly.
the class CPRollingbackOneOffTestCase method testCPAOneOffBCPC.
/**
* - CP patch updates a module;
* - one-off patch updates another module;
* - CP updates another module.
*/
@Test
public void testCPAOneOffBCPC() throws Exception {
// build a one-off patch for the base installation
// with 1 updated file
String patchID = randomString();
File patchDir = mkdir(tempDir, patchID);
final String patchElement1Id = randomString();
// create a module to be updated w/o a conflict
final File baseModuleDir = newFile(new File(PatchingTestUtil.AS_DISTRIBUTION), MODULES, SYSTEM, LAYERS, BASE);
final String moduleAName = "org.a.module-a";
Module moduleA = new Module.Builder(moduleAName).resourceRoot(new ResourceItem(jarA.getName(), jarABytes)).miscFile(new ResourceItem("resource-a", "resource a in the module".getBytes(StandardCharsets.UTF_8))).build();
final File moduleADir = moduleA.writeToDisk(new File(MODULES_PATH));
final String moduleBName = "org.b.module-b";
Module moduleB = new Module.Builder(moduleBName).resourceRoot(new ResourceItem(jarB.getName(), jarBBytes)).miscFile(new ResourceItem("resource-b", "resource b in the module".getBytes(StandardCharsets.UTF_8))).build();
final File moduleBDir = moduleB.writeToDisk(new File(MODULES_PATH));
final String moduleCName = "org.c.module-c";
Module moduleC = new Module.Builder(moduleCName).resourceRoot(new ResourceItem(jarC.getName(), jarCBytes)).miscFile(new ResourceItem("resource-c", "resource c in the module".getBytes(StandardCharsets.UTF_8))).build();
File moduleCDir = moduleC.writeToDisk(new File(MODULES_PATH));
moduleA = new Module.Builder(moduleAName).miscFile(new ResourceItem("resource-a", "resource cp1".getBytes(StandardCharsets.UTF_8))).build();
final ContentModification moduleAModified = ContentModificationUtils.modifyModule(patchDir, patchElement1Id, HashUtils.hashFile(moduleADir), moduleA);
Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).upgradeIdentity(productConfig.getProductName(), productConfig.getProductVersion(), productConfig.getProductVersion()).getParent().upgradeElement(patchElement1Id, "base", false).addContentModification(moduleAModified).getParent().build();
// create the patch
createPatchXMLFile(patchDir, patch);
File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
// no patches applied
assertPatchElements(baseModuleDir, null);
applyPatch(zippedPatch);
assertPatchElements(baseModuleDir, new String[] { patchElement1Id }, false);
patchID = randomString();
final String patchElement2Id = randomString();
patchDir = mkdir(tempDir, patchID);
moduleB = new Module.Builder(moduleBName).miscFile(new ResourceItem("resource-b", "resource oneoff1".getBytes(StandardCharsets.UTF_8))).build();
final ContentModification moduleBModified = ContentModificationUtils.modifyModule(patchDir, patchElement2Id, HashUtils.hashFile(moduleBDir), moduleB);
patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().oneOffPatchElement(patchElement2Id, "base", false).addContentModification(moduleBModified).getParent().build();
// create the patch
createPatchXMLFile(patchDir, patch);
zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
applyPatch(zippedPatch);
assertPatchElements(baseModuleDir, new String[] { patchElement1Id, patchElement2Id }, false);
patchID = randomString();
final String patchElement3Id = randomString();
patchDir = mkdir(tempDir, patchID);
moduleC = new Module.Builder(moduleCName).miscFile(new ResourceItem("resource-c", "resource c cp".getBytes(StandardCharsets.UTF_8))).build();
final ContentModification moduleCModified = ContentModificationUtils.modifyModule(patchDir, patchElement3Id, HashUtils.hashFile(moduleCDir), moduleC);
patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).upgradeIdentity(productConfig.getProductName(), productConfig.getProductVersion(), productConfig.getProductVersion()).getParent().upgradeElement(patchElement3Id, "base", false).addContentModification(moduleCModified).getParent().build();
// create the patch
createPatchXMLFile(patchDir, patch);
zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
applyPatch(zippedPatch);
assertPatchElements(baseModuleDir, new String[] { patchElement1Id, patchElement2Id, patchElement3Id }, false);
assertControllerStarts();
rollbackLast();
assertPatchElements(baseModuleDir, new String[] { patchElement1Id, patchElement2Id }, false);
assertControllerStarts();
rollbackLast();
assertPatchElements(baseModuleDir, new String[] { patchElement1Id }, false);
assertControllerStarts();
rollbackLast();
assertPatchElements(baseModuleDir, null);
assertControllerStarts();
}
use of org.jboss.as.test.patching.util.module.Module in project wildfly-core by wildfly.
the class AgeOutHistoryUnitTestCase method testCPWithOneOffsBeforeCPWithOneOffs.
@Test
public void testCPWithOneOffsBeforeCPWithOneOffs() 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);
targetHash = applyCP("cp1", targetHash);
targetHash = applyOneOff("oneoff3", targetHash);
targetHash = applyOneOff("oneoff4", targetHash);
targetHash = applyCP("cp2", targetHash);
targetHash = applyOneOff("oneoff5", targetHash);
targetHash = applyOneOff("oneoff6", targetHash);
controller.start();
try {
client = createClient();
assertPatched(client, new String[] { "oneoff6", "oneoff5", "cp2", "oneoff4", "oneoff3", "cp1", "oneoff2", "oneoff1" }, new boolean[] { false, false, true, false, false, true, false, false }, new boolean[] { false, false, false, false, false, false, false, false });
assertRollbackList(client, new String[] { "oneoff6", "oneoff5", "cp2", "oneoff4", "oneoff3", "cp1", "oneoff2", "oneoff1" }, new boolean[] { false, false, true, false, false, true, false, false }, new boolean[] { false, false, false, false, false, false, false, false });
ageoutHistory(client);
assertCleanedUp("oneoff1", "oneoff2", "cp1", "oneoff3", "oneoff4");
assertPatched(client, new String[] { "oneoff6", "oneoff5", "cp2", "oneoff4", "oneoff3", "cp1", "oneoff2", "oneoff1" }, new boolean[] { false, false, true, false, false, true, false, false }, new boolean[] { false, false, false, true, true, true, true, true });
assertRollbackList(client, new String[] { "oneoff6", "oneoff5", "cp2" }, new boolean[] { false, false, true }, new boolean[] { false, false, false });
} finally {
controller.stop();
}
}
Aggregations