use of org.jboss.as.patching.installation.InstalledIdentity 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.InstalledIdentity in project wildfly-core by wildfly.
the class CumulativePatchTestCase method testApplyReleasePatchThenOneOffPatchThenRollbackReleasePatch.
@Test
public void testApplyReleasePatchThenOneOffPatchThenRollbackReleasePatch() throws Exception {
// build a Release patch for the base installation
// with 1 added module
String releasePatchID = randomString();
String releaseLayerPatchID = randomString();
File releasePatchDir = mkdir(tempDir, releasePatchID);
String moduleName = randomString();
ContentModification moduleAdded = ContentModificationUtils.addModule(releasePatchDir, releaseLayerPatchID, moduleName);
InstalledIdentity identityBeforePatch = loadInstalledIdentity();
final String resultingVersion = identityBeforePatch.getIdentity().getVersion() + "-Release1";
Patch releasePatch = PatchBuilder.create().setPatchId(releasePatchID).setDescription(randomString()).upgradeIdentity(identityBeforePatch.getIdentity().getName(), identityBeforePatch.getIdentity().getVersion(), resultingVersion).getParent().upgradeElement(releaseLayerPatchID, BASE, false).addContentModification(moduleAdded).getParent().build();
createPatchXMLFile(releasePatchDir, releasePatch);
File zippedReleasePatch = createZippedPatchFile(releasePatchDir, releasePatchID);
PatchingResult resultOfReleasePatch = executePatch(zippedReleasePatch);
assertPatchHasBeenApplied(resultOfReleasePatch, releasePatch);
// FIXME when is the product version persisted when the release is applied?
productConfig = new ProductConfig(productConfig.getProductName(), productConfig.getProductVersion() + "-Release1", productConfig.getConsoleSlot());
InstalledIdentity updatedInstalledIdentity = loadInstalledIdentity();
File modulePatchDirectory = updatedInstalledIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(releaseLayerPatchID);
assertDirExists(modulePatchDirectory);
assertDefinedModule(modulePatchDirectory, moduleName, moduleAdded.getItem().getContentHash());
// apply a one-off patch now
String oneOffPatchID = randomString();
String oneOffLayerPatchID = randomString();
File oneOffPatchDir = mkdir(tempDir, oneOffPatchID);
ContentModification moduleModified = ContentModificationUtils.modifyModule(oneOffPatchDir, oneOffLayerPatchID, newFile(modulePatchDirectory, moduleName), "new resource in the module");
Patch oneOffPatch = PatchBuilder.create().setPatchId(oneOffPatchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), resultingVersion).getParent().oneOffPatchElement(oneOffLayerPatchID, BASE, false).addContentModification(moduleModified).getParent().build();
createPatchXMLFile(oneOffPatchDir, oneOffPatch);
File zippedOneOffPatch = createZippedPatchFile(oneOffPatchDir, oneOffPatchID);
PatchingResult resultOfOneOffPatch = executePatch(zippedOneOffPatch);
assertPatchHasBeenApplied(resultOfOneOffPatch, oneOffPatch);
InstalledIdentity installedIdentityAfterOneOffPatch = loadInstalledIdentity();
modulePatchDirectory = installedIdentityAfterOneOffPatch.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(oneOffLayerPatchID);
assertDirExists(modulePatchDirectory);
assertDefinedModule(modulePatchDirectory, moduleName, moduleModified.getItem().getContentHash());
// rollback the release patch, this should also rollback the one-off patch
PatchingResult resultOfReleasePatchRollback = rollback(releasePatchID);
tree(env.getInstalledImage().getJbossHome());
assertPatchHasBeenRolledBack(resultOfReleasePatchRollback, identityBeforePatch.getIdentity());
updatedInstalledIdentity = loadInstalledIdentity();
File layerModuleRoot = updatedInstalledIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModuleRoot();
assertDirDoesNotExist(newFile(layerModuleRoot, moduleName));
}
use of org.jboss.as.patching.installation.InstalledIdentity in project wildfly-core by wildfly.
the class CumulativePatchTestCase method testApplyReleasePatchThenOneOffPatch.
@Test
public void testApplyReleasePatchThenOneOffPatch() throws Exception {
// build a Release patch for the base installation
// with 1 added module
String releasePatchID = randomString();
String releaseLayerPatchID = randomString();
File releasePatchDir = mkdir(tempDir, releasePatchID);
String moduleName = randomString();
ContentModification moduleAdded = ContentModificationUtils.addModule(releasePatchDir, releaseLayerPatchID, moduleName);
InstalledIdentity installedIdentity = loadInstalledIdentity();
final String resultingVersion = productConfig.getProductVersion() + "-Release1";
Patch releasePatch = PatchBuilder.create().setPatchId(releasePatchID).setDescription(randomString()).upgradeIdentity(installedIdentity.getIdentity().getName(), installedIdentity.getIdentity().getVersion(), resultingVersion).getParent().upgradeElement(releaseLayerPatchID, BASE, false).addContentModification(moduleAdded).getParent().build();
createPatchXMLFile(releasePatchDir, releasePatch);
File zippedReleasePatch = createZippedPatchFile(releasePatchDir, releasePatchID);
PatchingResult resultOfReleasePatch = executePatch(zippedReleasePatch);
assertPatchHasBeenApplied(resultOfReleasePatch, releasePatch);
// FIXME when is the product version persisted when the release is applied?
productConfig = new ProductConfig(productConfig.getProductName(), productConfig.getProductVersion() + "-Release1", productConfig.getConsoleSlot());
InstalledIdentity updatedInstalledIdentity = loadInstalledIdentity();
File modulePatchDirectory = updatedInstalledIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(releaseLayerPatchID);
assertDirExists(modulePatchDirectory);
assertDefinedModule(modulePatchDirectory, moduleName, moduleAdded.getItem().getContentHash());
// apply a one-off patch now
String oneOffPatchID = randomString();
String oneOffLayerPatchID = randomString();
File oneOffPatchDir = mkdir(tempDir, oneOffPatchID);
ContentModification moduleModified = ContentModificationUtils.modifyModule(oneOffPatchDir, oneOffLayerPatchID, newFile(modulePatchDirectory, moduleName), "new resource in the module");
Patch oneOffPatch = PatchBuilder.create().setPatchId(oneOffPatchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), resultingVersion).getParent().oneOffPatchElement(oneOffLayerPatchID, BASE, false).addContentModification(moduleModified).getParent().build();
createPatchXMLFile(oneOffPatchDir, oneOffPatch);
File zippedOneOffPatch = createZippedPatchFile(oneOffPatchDir, oneOffPatchID);
PatchingResult resultOfOneOffPatch = executePatch(zippedOneOffPatch);
assertPatchHasBeenApplied(resultOfOneOffPatch, oneOffPatch);
InstalledIdentity installedIdentityAfterOneOffPatch = loadInstalledIdentity();
modulePatchDirectory = installedIdentityAfterOneOffPatch.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(oneOffLayerPatchID);
assertDirExists(modulePatchDirectory);
assertDefinedModule(modulePatchDirectory, moduleName, moduleModified.getItem().getContentHash());
}
use of org.jboss.as.patching.installation.InstalledIdentity in project wildfly-core by wildfly.
the class ModuleTaskTestCase method testAddModule.
@Test
public void testAddModule() throws Exception {
// build a one-off patch for the base installation
// with 1 added module
String patchID = randomString();
File patchDir = mkdir(tempDir, patchID);
String baseLayerPatchID = randomString();
String moduleName = randomString();
ContentModification moduleAdded = ContentModificationUtils.addModule(patchDir, baseLayerPatchID, moduleName);
Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().oneOffPatchElement(baseLayerPatchID, BASE, false).addContentModification(moduleAdded).getParent().build();
createPatchXMLFile(patchDir, patch);
File zippedPatch = createZippedPatchFile(patchDir, patchID);
PatchingResult result = executePatch(zippedPatch);
assertPatchHasBeenApplied(result, patch);
InstalledIdentity updatedInstalledIdentity = loadInstalledIdentity();
File modulePatchDirectory = updatedInstalledIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(baseLayerPatchID);
assertDirExists(modulePatchDirectory);
assertDefinedModule(modulePatchDirectory, moduleName, moduleAdded.getItem().getContentHash());
}
use of org.jboss.as.patching.installation.InstalledIdentity in project wildfly-core by wildfly.
the class AbstractPatchingTest method apply.
protected PatchingResult apply(final PatchingTestStepBuilder builder, final ContentVerificationPolicy verificationPolicy, final PatchStepAssertions assertions) throws PatchingException {
final Patch patch = builder.build();
final File installation = new File(tempDir, JBOSS_INSTALLATION);
try {
assertions.before(installation, patch, installationManager);
} catch (IOException e) {
throw new PatchingException(e);
}
// Write patch
writePatch(builder.getPatchDir(), patch);
// Create the patch tool and apply the patch
final PatchTool patchTool = PatchTool.Factory.create(installationManager);
final PatchingResult result = patchTool.applyPatch(builder.getPatchDir(), verificationPolicy);
result.commit();
final InstalledIdentity identity = ((InstallationManagerImpl) installationManager).getInstalledIdentity(patch.getIdentity().getName(), null);
Assert.assertTrue(identity.getAllInstalledPatches().contains(patch.getPatchId()));
try {
assertions.after(installation, patch, installationManager);
} catch (IOException e) {
throw new PatchingException(e);
}
return result;
}
Aggregations