use of org.jboss.as.patching.installation.Identity in project wildfly-core by wildfly.
the class CumulativePatchTestCase method testApplyReleasePatchAndRollback.
@Test
public void testApplyReleasePatchAndRollback() throws Exception {
// start from a base installation
// create an existing file in the AS7 installation
File binDir = mkdir(env.getInstalledImage().getJbossHome(), "bin");
String fileName = "standalone.sh";
File standaloneShellFile = touch(binDir, fileName);
dump(standaloneShellFile, "original script to run standalone AS7");
byte[] existingHash = hashFile(standaloneShellFile);
// build a Release patch for the base installation
// with 1 added module
// and 1 updated file
String patchID = randomString();
String layerPatchID = randomString();
File patchDir = mkdir(tempDir, patchID);
String moduleName = randomString();
ContentModification moduleAdded = ContentModificationUtils.addModule(patchDir, layerPatchID, moduleName);
ContentModification fileModified = ContentModificationUtils.modifyMisc(patchDir, patchID, "updated script", standaloneShellFile, "bin", "standalone.sh");
InstalledIdentity installedIdentity = loadInstalledIdentity();
Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).upgradeIdentity(installedIdentity.getIdentity().getName(), installedIdentity.getIdentity().getVersion(), productConfig.getProductVersion() + "-Release1").getParent().upgradeElement(layerPatchID, BASE, false).addContentModification(moduleAdded).getParent().addContentModification(fileModified).build();
createPatchXMLFile(patchDir, patch);
File zippedPatch = createZippedPatchFile(patchDir, patchID);
Identity identityBeforePatch = loadInstalledIdentity().getIdentity();
PatchingResult result = executePatch(zippedPatch);
assertPatchHasBeenApplied(result, patch);
assertFileExists(standaloneShellFile);
assertFileContent(fileModified.getItem().getContentHash(), standaloneShellFile);
InstalledIdentity updatedInstalledIdentity = loadInstalledIdentity();
File modulePatchDirectory = updatedInstalledIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(layerPatchID);
assertDirExists(modulePatchDirectory);
assertDefinedModule(modulePatchDirectory, moduleName, moduleAdded.getItem().getContentHash());
// rollback the patch based on the updated PatchInfo
PatchingResult rollbackResult = rollback(patchID);
tree(env.getInstalledImage().getJbossHome());
assertPatchHasBeenRolledBack(rollbackResult, identityBeforePatch);
assertFileExists(standaloneShellFile);
assertFileContent(existingHash, standaloneShellFile);
}
use of org.jboss.as.patching.installation.Identity in project wildfly-core by wildfly.
the class ConfigurationBackupTestCase method checkApplyPatchAndRollbackRestoresBackupConfiguration.
private void checkApplyPatchAndRollbackRestoresBackupConfiguration(File patchDir, Patch patch) throws Exception {
createPatchXMLFile(patchDir, patch);
File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
Identity identityBeforePatch = loadInstalledIdentity().getIdentity();
PatchingResult result = executePatch(zippedPatch);
assertPatchHasBeenApplied(result, patch);
// check the AS7 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);
tree(tempDir);
PatchingResult rollbackResult = rollback(patch.getPatchId());
assertPatchHasBeenRolledBack(rollbackResult, identityBeforePatch);
File rolledBackStandaloneXmlFile = assertFileExists(env.getInstalledImage().getStandaloneDir(), "configuration", "standalone.xml");
assertEquals("updated content was " + bytesToHexString(updatedStandaloneXmlFile), bytesToHexString(originalStandaloneHash), bytesToHexString(hashFile(rolledBackStandaloneXmlFile)));
}
use of org.jboss.as.patching.installation.Identity in project wildfly-core by wildfly.
the class PatchAttributeReadHandler method execute.
@Override
protected void execute(final OperationContext context, final ModelNode operation, final InstalledIdentity installedIdentity) throws OperationFailedException {
final ModelNode result = context.getResult();
final Identity info = installedIdentity.getIdentity();
try {
handle(result, info);
} catch (IOException e) {
throw new OperationFailedException(PatchLogger.ROOT_LOGGER.failedToLoadInfo(info.getName()), e);
}
context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
use of org.jboss.as.patching.installation.Identity in project wildfly-core by wildfly.
the class OneOffPatchTestCase method testApplyOneOffPatchAndRollback.
@Test
public void testApplyOneOffPatchAndRollback() throws Exception {
// create an existing file in the AS7 installation
File binDir = mkdir(env.getInstalledImage().getJbossHome(), "bin");
String fileName = "standalone.sh";
File standaloneShellFile = touch(binDir, fileName);
dump(standaloneShellFile, "original script to run standalone AS7");
byte[] existingHash = hashFile(standaloneShellFile);
// build a one-off patch for the base installation
// with 1 added module
// and 1 updated file
String patchID = randomString();
String layerPatchID = randomString();
File patchDir = mkdir(tempDir, patchID);
String moduleName = randomString();
ContentModification moduleAdded = ContentModificationUtils.addModule(patchDir, layerPatchID, moduleName);
ContentModification fileUpdated = ContentModificationUtils.modifyMisc(patchDir, patchID, "updated script", standaloneShellFile, "bin", "standalone.sh");
Identity identityBeforePatch = loadInstalledIdentity().getIdentity();
Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().oneOffPatchElement(layerPatchID, BASE, false).addContentModification(moduleAdded).getParent().addContentModification(fileUpdated).build();
createPatchXMLFile(patchDir, patch);
File zippedPatch = createZippedPatchFile(patchDir, patchID);
PatchingResult result = executePatch(zippedPatch);
assertPatchHasBeenApplied(result, patch);
assertFileExists(standaloneShellFile);
assertFileContent(fileUpdated.getItem().getContentHash(), standaloneShellFile);
InstalledIdentity updatedInstalledIdentity = loadInstalledIdentity();
File modulePatchDirectory = updatedInstalledIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(layerPatchID);
assertDirExists(modulePatchDirectory);
assertDefinedModule(modulePatchDirectory, moduleName, moduleAdded.getItem().getContentHash());
// rollback the patch based on the updated PatchInfo
PatchingResult rollbackResult = rollback(patchID);
assertPatchHasBeenRolledBack(rollbackResult, identityBeforePatch);
assertFileExists(standaloneShellFile);
assertFileContent(existingHash, standaloneShellFile);
}
use of org.jboss.as.patching.installation.Identity in project wildfly-core by wildfly.
the class OneOffPatchTestCase method apply2OneOffPatchesAndRollbackTheFirstOne.
@Test
public void apply2OneOffPatchesAndRollbackTheFirstOne() throws Exception {
// create two files in the AS7 installation
File binDir = mkdir(env.getInstalledImage().getJbossHome(), "bin");
String standaloneFileName = "standalone.sh";
File standaloneShellFile = touch(binDir, standaloneFileName);
dump(standaloneShellFile, "original script to run standalone AS7");
byte[] existingHashForStandaloneShell = hashFile(standaloneShellFile);
String domainFileName = "domain.sh";
File domainShellFile = touch(binDir, domainFileName);
dump(domainShellFile, "original script to run domain AS7");
byte[] existingHashForDomainShell = hashFile(domainShellFile);
// build a one-off patch for the base installation
// with 1 added module
// and 1 updated file
String patchID = "patch-1-" + randomString();
String layerPatchID = randomString();
File patchDir = mkdir(tempDir, patchID);
String moduleName = randomString();
ContentModification moduleAdded = ContentModificationUtils.addModule(patchDir, layerPatchID, moduleName);
ContentModification fileUpdated = ContentModificationUtils.modifyMisc(patchDir, patchID, "updated script", standaloneShellFile, "bin", "standalone.sh");
Identity identityBeforePatch = loadInstalledIdentity().getIdentity();
Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().oneOffPatchElement(layerPatchID, BASE, false).addContentModification(moduleAdded).getParent().addContentModification(fileUpdated).build();
createPatchXMLFile(patchDir, patch);
File zippedPatch = createZippedPatchFile(patchDir, patchID);
PatchingResult result = executePatch(zippedPatch);
assertPatchHasBeenApplied(result, patch);
assertFileExists(standaloneShellFile);
assertFileContent(fileUpdated.getItem().getContentHash(), standaloneShellFile);
InstalledIdentity updatedInstalledIdentity = loadInstalledIdentity();
File modulePatchDirectory = updatedInstalledIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(layerPatchID);
assertDirExists(modulePatchDirectory);
assertDefinedModule(modulePatchDirectory, moduleName, moduleAdded.getItem().getContentHash());
// build a 2nd one-off patch for the base installation
// with 1 updated file
String patchID_2 = "patch-2-" + randomString();
File patchDir_2 = mkdir(tempDir, patchID_2);
ContentModification otherFileUpdated = ContentModificationUtils.modifyMisc(patchDir_2, patchID_2, "updated domain script", domainShellFile, "bin", "domain.sh");
Patch patch_2 = PatchBuilder.create().setPatchId(patchID_2).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().addContentModification(otherFileUpdated).build();
createPatchXMLFile(patchDir_2, patch_2);
File zippedPatch_2 = createZippedPatchFile(patchDir_2, patchID_2);
PatchingResult result_2 = executePatch(zippedPatch_2);
assertPatchHasBeenApplied(result_2, patch_2);
assertFileExists(domainShellFile);
assertFileContent(otherFileUpdated.getItem().getContentHash(), domainShellFile);
// rollback the *first* patch based on the updated PatchInfo
PatchingResult rollbackResult = rollback(patchID, true);
// both patches must be rolled back
assertFileExists(standaloneShellFile);
assertFileContent(existingHashForStandaloneShell, standaloneShellFile);
assertFileExists(domainShellFile);
assertFileContent(existingHashForDomainShell, domainShellFile);
}
Aggregations