use of org.jboss.as.patching.metadata.ContentModification in project wildfly-core by wildfly.
the class PatchMergeUnitTestCase method createRollbackInfo.
static RollbackInfo createRollbackInfo(String id, byte[] oih, byte[] oth, byte[] rih, byte[] rth) {
//
final MiscContentItem oi = new MiscContentItem(name, path, oih);
final MiscContentItem ri = new MiscContentItem(name, path, rih);
//
final Patch o = createPatch(id, Patch.PatchType.ONE_OFF, new ContentModification(oi, oth, ModificationType.MODIFY));
final Patch r = createPatch(id, Patch.PatchType.ONE_OFF, new ContentModification(ri, rth, ModificationType.MODIFY));
//
return new RollbackInfo(o, r);
}
use of org.jboss.as.patching.metadata.ContentModification in project wildfly-core by wildfly.
the class PatchMergeUnitTestCase method testSimple.
@Test
public void testSimple() throws Exception {
// content-item 'two' replacing 'one'
final RollbackInfo patch01 = createRollbackInfo("patch01", two, one);
// content-item 'three' replacing 'two'
final RollbackInfo patch02 = createRollbackInfo("patch02", three, two);
// [patch-two, patch-one]
final ContentTaskDefinitions defs = process(patch02, patch01);
Assert.assertEquals(1, defs.size());
final PatchingTasks.ContentTaskDefinition def = defs.get(new Location(new MiscContentItem(name, path, one)));
Assert.assertNotNull(def);
Assert.assertFalse(def.hasConflicts());
// We want to restore one (from the backup)
Assert.assertEquals(one, def.getTarget().getItem().getContentHash());
// The original target was two
Assert.assertEquals(two, def.getTarget().getTargetHash());
// The current content however is three
Assert.assertEquals(three, def.getLatest().getTargetHash());
// And originally replaced two
Assert.assertEquals(two, def.getLatest().getItem().getContentHash());
// The resulting operation should replace 'three' with 'one'
final ContentModification modification = PatchingTaskDescription.resolveDefinition(def);
Assert.assertEquals(one, modification.getItem().getContentHash());
Assert.assertEquals(three, modification.getTargetHash());
}
use of org.jboss.as.patching.metadata.ContentModification in project wildfly-core by wildfly.
the class ContentConflictsUnitTestCase method testApply.
/**
* Tests content conflicts reporting in the CLI during patch application.
*
* The test creates 2 misc files, 2 modules and 2 bundles and a patch
* which updates all of them. Before the patch is applied, one file,
* one module and one bundle are modified on the disk. The patch is
* expected to fail and the failure description should contain the
* info about the conflicting content items.
*
* @throws Exception
*/
@Test
public void testApply() throws Exception {
final File binDir = createInstalledImage(env, "consoleSlot", productConfig.getProductName(), productConfig.getProductVersion());
// build a one-off patch for the base installation
// with 1 updated file
String patchID = randomString();
File patchDir = mkdir(tempDir, patchID);
// create a module for the conflict
File baseModuleDir = newFile(env.getInstalledImage().getModulesDir(), SYSTEM, LAYERS, BASE);
String moduleConflictName = "module-conflict";
File moduleConflictDir = createModule0(baseModuleDir, moduleConflictName);
// create the patch with the updated module
ContentModification moduleConflictModified = ContentModificationUtils.modifyModule(patchDir, patchID, moduleConflictDir, "new resource in the module");
// create a module to be updated w/o a conflict
String moduleNoConflictName = "module-no-conflict";
File moduleNoConflictDir = createModule0(baseModuleDir, moduleNoConflictName);
// create the patch with the updated module
ContentModification moduleNoConflictModified = ContentModificationUtils.modifyModule(patchDir, patchID, moduleNoConflictDir, "new resource in the module");
// create a file for the conflict
String fileConflictName = "file-conflict.txt";
File conflictFile = touch(binDir, fileConflictName);
dump(conflictFile, "original script to run standalone AS7");
// patch the file
ContentModification fileConflictModified = ContentModificationUtils.modifyMisc(patchDir, patchID, "updated script", conflictFile, "bin", fileConflictName);
// create a file for the conflict
String fileNoConflictName = "file-no-conflict.txt";
File noConflictFile = touch(binDir, fileNoConflictName);
dump(noConflictFile, "original script to run standalone AS7");
// patch the file
ContentModification fileNoConflictModified = ContentModificationUtils.modifyMisc(patchDir, patchID, "updated script", noConflictFile, "bin", fileNoConflictName);
// TestUtils.tree(env.getInstalledImage().getJbossHome());
Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().addContentModification(fileConflictModified).addContentModification(fileNoConflictModified).oneOffPatchElement(patchID, "base", false).addContentModification(moduleConflictModified).addContentModification(moduleNoConflictModified).getParent().build();
// create the patch
createPatchXMLFile(patchDir, patch, false);
File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
// create a conflict for the file
dump(conflictFile, "conflicting change");
// create a conflict for the module
createModule0(baseModuleDir, moduleConflictName, "oops");
// apply the patch using the cli
CommandContext ctx = CommandContextFactory.getInstance().newCommandContext();
try {
ctx.handle("patch apply " + zippedPatch.getAbsolutePath() + " --distribution=" + env.getInstalledImage().getJbossHome());
fail("Conflicts expected.");
} catch (CommandLineException e) {
// e.printStackTrace();
final int relativeIndex = env.getInstalledImage().getJbossHome().getAbsolutePath().length() + 1;
assertConflicts(e, moduleConflictName + ":main", conflictFile.getAbsolutePath().substring(relativeIndex));
} finally {
ctx.terminateSession();
}
}
use of org.jboss.as.patching.metadata.ContentModification in project wildfly-core by wildfly.
the class ContentConflictsUnitTestCase method testRollback.
/**
* Tests content conflicts reporting in the CLI during patch rollback.
*
* The test creates 2 misc files, 2 modules and 2 bundles and a patch
* which updates all of them. The patch is applied. Then one file,
* one module and one bundle are modified on the disk. The patch is
* rolled back then which is expected to fail and the failure description
* should contain the info about the conflicting content items.
*
* @throws Exception
*/
@Test
public void testRollback() throws Exception {
final File binDir = createInstalledImage(env, "consoleSlot", productConfig.getProductName(), productConfig.getProductVersion());
// build a one-off patch for the base installation
// with 1 updated file
String patchID = randomString();
String patchElementId = randomString();
File patchDir = mkdir(tempDir, patchID);
// create a module for the conflict
File baseModuleDir = newFile(env.getInstalledImage().getModulesDir(), SYSTEM, LAYERS, BASE);
String moduleConflictName = "module-conflict";
File moduleConflictDir = createModule0(baseModuleDir, moduleConflictName);
// create the patch with the updated module
ContentModification moduleConflictModified = ContentModificationUtils.modifyModule(patchDir, patchElementId, moduleConflictDir, "new resource in the module");
// create a module to be updated w/o a conflict
String moduleNoConflictName = "module-no-conflict";
File moduleNoConflictDir = createModule0(baseModuleDir, moduleNoConflictName);
// create the patch with the updated module
ContentModification moduleNoConflictModified = ContentModificationUtils.modifyModule(patchDir, patchElementId, moduleNoConflictDir, "new resource in the module");
// create a file for the conflict
String fileConflictName = "file-conflict.txt";
File conflictFile = touch(binDir, fileConflictName);
dump(conflictFile, "original script to run standalone AS7");
// patch the file
ContentModification fileConflictModified = ContentModificationUtils.modifyMisc(patchDir, patchID, "updated script", conflictFile, "bin", fileConflictName);
// create a file for the conflict
String fileNoConflictName = "file-no-conflict.txt";
File noConflictFile = touch(binDir, fileNoConflictName);
dump(noConflictFile, "original script to run standalone AS7");
// patch the file
ContentModification fileNoConflictModified = ContentModificationUtils.modifyMisc(patchDir, patchID, "updated script", noConflictFile, "bin", fileNoConflictName);
// TestUtils.tree(env.getInstalledImage().getJbossHome());
Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().addContentModification(fileConflictModified).addContentModification(fileNoConflictModified).oneOffPatchElement(patchElementId, "base", false).addContentModification(moduleConflictModified).addContentModification(moduleNoConflictModified).getParent().build();
// create the patch
createPatchXMLFile(patchDir, patch, false);
File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
// apply the patch using the cli
CommandContext ctx = CommandContextFactory.getInstance().newCommandContext();
try {
ctx.handle("patch apply " + zippedPatch.getAbsolutePath() + " --distribution=" + env.getInstalledImage().getJbossHome());
} catch (CommandLineException e) {
ctx.terminateSession();
fail("Failed to apply the patch: " + e);
}
// create a conflict for the file
dump(conflictFile, "conflicting change");
// create a conflict for the module
createModule0(baseModuleDir, moduleConflictName, "oops");
try {
ctx.handle("patch rollback --patch-id=" + patchID + " --distribution=" + env.getInstalledImage().getJbossHome() + " --reset-configuration=false");
fail("Conflicts expected");
} catch (CommandLineException e) {
final int relativeIndex = env.getInstalledImage().getJbossHome().getAbsolutePath().length() + 1;
// TODO modules and bundles are not checked at the moment
assertConflicts(e, moduleConflictName + ":main", conflictFile.getAbsolutePath().substring(relativeIndex));
// assertConflicts(e, conflictFile.getAbsolutePath().substring(relativeIndex));
} finally {
ctx.terminateSession();
}
}
use of org.jboss.as.patching.metadata.ContentModification in project wildfly-core by wildfly.
the class ResetConfigurationUnitTestCase method testResetConfigurationTrue.
/**
* Applies a patch, modifies standalone, appclient and domain xml config and rolls back the patch
* with --reset-configuration=true
* The expected result is:
* - the modified config files are replaced with the original configuration files;
* - the restored-configuration dir is not created in any of the configuration dirs
* .
* @throws Exception
*/
@Test
public void testResetConfigurationTrue() throws Exception {
final File binDir = createInstalledImage(env, "consoleSlot", productConfig.getProductName(), productConfig.getProductVersion());
// build a one-off patch for the base installation
// with 1 updated file
String patchID = randomString();
String patchElementId = randomString();
File patchDir = mkdir(tempDir, patchID);
// create a file for the conflict
String fileNoConflictName = "file-no-conflict.txt";
File noConflictFile = touch(binDir, fileNoConflictName);
dump(noConflictFile, "original script to run standalone AS7");
// patch the file
ContentModification fileNoConflictModified = ContentModificationUtils.modifyMisc(patchDir, patchID, "updated script", noConflictFile, "bin", fileNoConflictName);
// TestUtils.tree(env.getInstalledImage().getJbossHome());
Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).upgradeIdentity(productConfig.getProductName(), productConfig.getProductVersion(), productConfig.getProductVersion() + "CP1").getParent().addContentModification(fileNoConflictModified).upgradeElement(patchElementId, "base", false).getParent().build();
// create the patch
createPatchXMLFile(patchDir, patch, false);
File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
// apply the patch using the cli
CommandContext ctx = CommandContextFactory.getInstance().newCommandContext();
try {
ctx.handle("patch apply " + zippedPatch.getAbsolutePath() + " --distribution=" + env.getInstalledImage().getJbossHome());
} catch (Exception e) {
ctx.terminateSession();
throw e;
}
// check the config files have been backed up
File backupAppclientXmlFile = assertFileExists(env.getInstalledImage().getPatchHistoryDir(patch.getPatchId()), "configuration", "appclient", "appclient.xml");
assertFileContent(originalAppClientHash, backupAppclientXmlFile);
File backupStandaloneXmlFile = assertFileExists(env.getInstalledImage().getPatchHistoryDir(patch.getPatchId()), "configuration", "standalone", "standalone.xml");
assertFileContent(originalStandaloneHash, backupStandaloneXmlFile);
File backupDomainXmlFile = assertFileExists(env.getInstalledImage().getPatchHistoryDir(patch.getPatchId()), "configuration", "domain", "domain.xml");
assertFileContent(originalDomainHash, backupDomainXmlFile);
// let's change the standalone.xml file
dump(standaloneXmlFile, "<updated standalone configuration with changes from the added module>");
byte[] updatedStandaloneXmlFile = hashFile(standaloneXmlFile);
assertNotEquals(bytesToHexString(originalStandaloneHash), bytesToHexString(updatedStandaloneXmlFile));
dump(appClientXmlFile, "<updated app client configuration with changes from the added module>");
byte[] updatedAppClientXmlHash = hashFile(appClientXmlFile);
assertNotEquals(bytesToHexString(originalAppClientHash), bytesToHexString(updatedAppClientXmlHash));
dump(domainXmlFile, "<updated domain configuration with changes from the added module>");
byte[] updatedDomainXmlHash = hashFile(domainXmlFile);
assertNotEquals(bytesToHexString(originalDomainHash), bytesToHexString(updatedDomainXmlHash));
try {
ctx.handle("patch rollback --reset-configuration=true --distribution=" + env.getInstalledImage().getJbossHome());
} finally {
ctx.terminateSession();
}
// TestUtils.tree(env.getInstalledImage().getJbossHome());
File rolledBackStandaloneXmlFile = assertFileExists(env.getInstalledImage().getStandaloneDir(), "configuration", "standalone.xml");
assertEquals(bytesToHexString(originalStandaloneHash), bytesToHexString(hashFile(rolledBackStandaloneXmlFile)));
File rolledBackAppClientXmlFile = assertFileExists(env.getInstalledImage().getAppClientDir(), "configuration", "appclient.xml");
assertEquals(bytesToHexString(originalAppClientHash), bytesToHexString(hashFile(rolledBackAppClientXmlFile)));
File rolledBackDomainXmlFile = assertFileExists(env.getInstalledImage().getDomainDir(), "configuration", "domain.xml");
assertEquals(bytesToHexString(originalDomainHash), bytesToHexString(hashFile(rolledBackDomainXmlFile)));
assertDirDoesNotExist(env.getInstalledImage().getStandaloneDir(), "configuration", "restored-configuration");
assertDirDoesNotExist(env.getInstalledImage().getAppClientDir(), "configuration", "restored-configuration");
assertDirDoesNotExist(env.getInstalledImage().getDomainDir(), "configuration", "restored-configuration");
}
Aggregations