MutableTargetImpl(PatchableTarget.TargetInfo current, String currentVersion) { this.current = current; this.structure = current.getDirectoryStructure(); this.cumulativeID = current.getCumulativePatchID(); this.patchIds = new ArrayList<String>(current.getPatchIDs()); this.properties = new Properties(current.getProperties()); this.version = currentVersion; }
MutableTargetImpl(PatchableTarget.TargetInfo current, String currentVersion) { this.current = current; this.structure = current.getDirectoryStructure(); this.cumulativeID = current.getCumulativePatchID(); this.patchIds = new ArrayList<String>(current.getPatchIDs()); this.properties = new Properties(current.getProperties()); this.version = currentVersion; }
/** * Add a rollback loader for a give patch. * * @param patchId the patch id. * @param target the patchable target * @throws XMLStreamException * @throws IOException */ private void recordRollbackLoader(final String patchId, PatchableTarget.TargetInfo target) { // setup the content loader paths final DirectoryStructure structure = target.getDirectoryStructure(); final InstalledImage image = structure.getInstalledImage(); final File historyDir = image.getPatchHistoryDir(patchId); final File miscRoot = new File(historyDir, PatchContentLoader.MISC); final File modulesRoot = structure.getModulePatchDirectory(patchId); final File bundlesRoot = structure.getBundlesPatchDirectory(patchId); final PatchContentLoader loader = PatchContentLoader.create(miscRoot, bundlesRoot, modulesRoot); // recordContentLoader(patchId, loader); }
@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()); }
private void prepareCP3(final InstalledIdentity installedIdentity) throws IOException, Exception { final String cp3ID = "CP3"; final File cp3Dir = mkdir(tempDir, cp3ID); cp3StandaloneModified = ContentModificationUtils.modifyMisc(cp3Dir, cp3ID, "updated by cp3", standaloneSh, "bin", standaloneSh.getName()); cp3BaseModuleModified = ContentModificationUtils.modifyModule(cp3Dir, baseCP3ID, moduleName, cp2BaseModuleModified.getItem().getContentHash(), "cp3 content"); // cp3BaseModule2Added = ContentModificationUtils.addModule(cp3Dir, baseCP3ID, moduleName + "2"); the patchgen tool // would generate an update instead final File absentModuleXml = IoUtils.newFile(installedIdentity.getLayer("base").loadTargetInfo() .getDirectoryStructure().getModulePatchDirectory(baseCP2ID), "org", "jboss", "test2", "main", "module.xml"); cp3BaseModule2Added = ContentModificationUtils.modifyModule(cp3Dir, baseCP3ID, moduleName + "2", HashUtils.hashFile(absentModuleXml), "cp3 content"); final ContentModification cp3AddedByCP1RemovedByCP3Removed = ContentModificationUtils.removeMisc(addedByCP1RemovedByCP3, "bin", addedByCP1RemovedByCP3.getName()); cp3 = PatchBuilder.create() .setPatchId(cp3ID) .setDescription(randomString()) .upgradeIdentity(installedIdentity.getIdentity().getName(), productConfig.getProductVersion() + "_CP2", productConfig.getProductVersion() + "_CP3") .getParent() .upgradeElement(baseCP3ID, BASE, false) .addContentModification(cp3BaseModuleModified) .addContentModification(cp3BaseModule2Added) .getParent() .addContentModification(cp3StandaloneModified) .addContentModification(cp3AddedByCP1RemovedByCP3Removed) .build(); createPatchXMLFile(cp3Dir, cp3); cp3Zip = createZippedPatchFile(cp3Dir, cp3ID); }
@Test public void testApplyOneOffPatch() throws Exception { // build a one-off patch for the base installation // with 1 added module String oneOffPatchID = randomString(); String oneOffLayerPatchID = randomString(); File oneOffPatchDir = mkdir(tempDir, oneOffPatchID); String moduleName = randomString(); ContentModification moduleAdded = ContentModificationUtils.addModule(oneOffPatchDir, oneOffLayerPatchID, moduleName); Patch oneOffPatch = PatchBuilder.create() .setPatchId(oneOffPatchID) .setDescription(randomString()) .oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()) .getParent() .oneOffPatchElement(oneOffLayerPatchID, BASE, false) .addContentModification(moduleAdded) .getParent() .build(); createPatchXMLFile(oneOffPatchDir, oneOffPatch); File zippedPatch = createZippedPatchFile(oneOffPatchDir, oneOffPatchID); PatchingResult result = executePatch(zippedPatch); assertPatchHasBeenApplied(result, oneOffPatch); InstalledIdentity updatedInstalledIdentity = loadInstalledIdentity(); File modulePatchDirectory = updatedInstalledIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(oneOffLayerPatchID); assertDirExists(modulePatchDirectory); assertDefinedModule(modulePatchDirectory, moduleName, moduleAdded.getItem().getContentHash()); }
@Test public void testApplyReleasePatch() throws Exception { // build a Release patch for the base installation // with 1 added module String patchID = randomString(); String layerPatchID = randomString(); File patchDir = mkdir(tempDir, patchID); String moduleName = randomString(); ContentModification moduleAdded = ContentModificationUtils.addModule(patchDir, layerPatchID, moduleName); 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() .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(layerPatchID); assertDirExists(modulePatchDirectory); assertDefinedModule(modulePatchDirectory, moduleName, moduleAdded.getItem().getContentHash()); }
private void assertCP3State(PatchingResult result) throws Exception { assertPatchHasBeenApplied(result, cp3); assertFileExists(standaloneSh); assertFileContent(cp3StandaloneModified.getItem().getContentHash(), standaloneSh); assertFileExists(addedByCP1); assertFileContent(cp1AddedByCP1Added.getItem().getContentHash(), addedByCP1); assertFileDoesNotExist(addedByCP1RemovedByCP3); assertFileExists(addedByCP2); assertFileContent(cp2AddedByCp2Added.getItem().getContentHash(), addedByCP2); final InstalledIdentity installedIdentity = loadInstalledIdentity(); File modulePatchDir = installedIdentity.getLayer(BASE).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(baseCP3ID); assertDirExists(modulePatchDir); assertDefinedModule(modulePatchDir, moduleName, cp3BaseModuleModified.getItem().getContentHash()); assertDefinedModule(modulePatchDir, moduleName + 2, cp3BaseModule2Added.getItem().getContentHash()); modulePatchDir = installedIdentity.getLayer("layer1").loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(layer1CP1ID); assertDirExists(modulePatchDir); assertDefinedModule(modulePatchDir, moduleName, cp1Layer1ModuleAdded.getItem().getContentHash()); modulePatchDir = installedIdentity.getLayer("layer2").loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(layer2CP2ID); assertDirExists(modulePatchDir); assertDefinedModule(modulePatchDir, moduleName + "2", cp1Layer2Module2Added.getItem().getContentHash()); assertDefinedModule(modulePatchDir, moduleName + "3", cp2Layer2Module3Added.getItem().getContentHash()); if(IoUtils.newFile(modulePatchDir, "org", "jboss", "test").exists()) { assertDefinedAbsentModule(modulePatchDir, moduleName); } }
private void assertCP2State(PatchingResult result) throws Exception { assertPatchHasBeenApplied(result, cp2); assertFileExists(standaloneSh); assertFileContent(cp2StandaloneModified.getItem().getContentHash(), standaloneSh); assertFileExists(addedByCP1); assertFileContent(cp1AddedByCP1Added.getItem().getContentHash(), addedByCP1); assertFileExists(addedByCP1RemovedByCP3); assertFileExists(addedByCP2); assertFileContent(cp2AddedByCp2Added.getItem().getContentHash(), addedByCP2); final InstalledIdentity installedIdentity = loadInstalledIdentity(); File modulePatchDiry = installedIdentity.getLayer(BASE).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(baseCP2ID); assertDirExists(modulePatchDiry); assertDefinedModule(modulePatchDiry, moduleName, cp2BaseModuleModified.getItem().getContentHash()); assertDefinedAbsentModule(modulePatchDiry, moduleName + "2"); modulePatchDiry = installedIdentity.getLayer("layer1").loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(layer1CP1ID); assertDirExists(modulePatchDiry); assertDefinedModule(modulePatchDiry, moduleName, cp1Layer1ModuleAdded.getItem().getContentHash()); modulePatchDiry = installedIdentity.getLayer("layer2").loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(layer2CP2ID); assertDirExists(modulePatchDiry); assertDefinedAbsentModule(modulePatchDiry, moduleName); assertDefinedModule(modulePatchDiry, moduleName + "2", cp1Layer2Module2Added.getItem().getContentHash()); assertDefinedModule(modulePatchDiry, moduleName + "3", cp2Layer2Module3Added.getItem().getContentHash()); }
@Test public void installedLayer() throws Exception { String layerName = randomString(); installLayers(layerName); TestUtils.tree(env.getInstalledImage().getJbossHome()); InstalledIdentity installedIdentity = loadInstalledIdentity(); Identity identity = installedIdentity.getIdentity(); assertEquals(productConfig.getProductName(), identity.getName()); assertEquals(productConfig.resolveVersion(), identity.getVersion()); List<Layer> layers = installedIdentity.getLayers(); assertEquals(2, layers.size()); Layer layer = layers.get(0); assertEquals(layerName, layer.getName()); assertEquals(BASE, layers.get(1).getName()); // base layer is always appended PatchableTarget.TargetInfo targetInfo = layer.loadTargetInfo(); assertEquals(BASE, targetInfo.getCumulativePatchID()); assertTrue(targetInfo.getPatchIDs().isEmpty()); DirectoryStructure directoryStructure = targetInfo.getDirectoryStructure(); assertEquals(newFile(env.getModuleRoot(), "system", "layers", layerName), directoryStructure.getModuleRoot()); assertNull(directoryStructure.getBundleRepositoryRoot()); }
/** * Add a rollback loader for a give patch. * * @param patchId the patch id. * @param target the patchable target * @throws XMLStreamException * @throws IOException */ private void recordRollbackLoader(final String patchId, PatchableTarget.TargetInfo target) { // setup the content loader paths final DirectoryStructure structure = target.getDirectoryStructure(); final InstalledImage image = structure.getInstalledImage(); final File historyDir = image.getPatchHistoryDir(patchId); final File miscRoot = new File(historyDir, PatchContentLoader.MISC); final File modulesRoot = structure.getModulePatchDirectory(patchId); final File bundlesRoot = structure.getBundlesPatchDirectory(patchId); final PatchContentLoader loader = PatchContentLoader.create(miscRoot, bundlesRoot, modulesRoot); // recordContentLoader(patchId, loader); }
static void assertApplied(final Patch patch, InstallationManager manager) throws IOException { final String patchID = patch.getPatchId(); InstalledIdentity installedIdentity = null; try { installedIdentity = manager.getInstalledIdentity(patch.getIdentity().getName(), null); } catch (PatchingException e) { Assert.fail(e.getLocalizedMessage()); } final PatchableTarget target = installedIdentity.getIdentity(); final PatchableTarget.TargetInfo identity = target.loadTargetInfo(); assertIsApplied(patch.getIdentity().getPatchType(), patchID, identity); assertExists(identity.getDirectoryStructure().getInstalledImage().getPatchHistoryDir(patchID)); assertContentItems(patchID, target, patch.getModifications()); for (final PatchElement element : patch.getElements()) { final PatchElementProvider provider = element.getProvider(); final PatchableTarget targetElement = provider.isAddOn() ? installedIdentity.getAddOn(provider.getName()) : installedIdentity.getLayer(provider.getName()); assertIsApplied(provider.getPatchType(), element.getId(), targetElement.loadTargetInfo()); assertContentItems(element.getId(), targetElement, element.getModifications()); } }
private void assertCP1State(PatchingResult result) throws Exception { assertPatchHasBeenApplied(result, cp1); assertFileExists(standaloneSh); assertFileContent(cp1StandaloneModified.getItem().getContentHash(), standaloneSh); assertFileExists(addedByCP1); assertFileContent(cp1AddedByCP1Added.getItem().getContentHash(), addedByCP1); assertFileExists(addedByCP1RemovedByCP3); assertFileDoesNotExist(addedByCP2); final InstalledIdentity installedIdentity = loadInstalledIdentity(); File modulePatchDir = installedIdentity.getLayer(BASE).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(baseCP1ID); assertDirExists(modulePatchDir); assertDefinedModule(modulePatchDir, moduleName, cp1BaseModuleAdded.getItem().getContentHash()); assertDefinedModule(modulePatchDir, moduleName + "2", cp1BaseModule2Added.getItem().getContentHash()); modulePatchDir = installedIdentity.getLayer("layer1").loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(layer1CP1ID); assertDirExists(modulePatchDir); assertDefinedModule(modulePatchDir, moduleName, cp1Layer1ModuleAdded.getItem().getContentHash()); modulePatchDir = installedIdentity.getLayer("layer2").loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(layer2CP1ID); assertDirExists(modulePatchDir); assertDefinedModule(modulePatchDir, moduleName, cp1Layer2ModuleAdded.getItem().getContentHash()); assertDefinedModule(modulePatchDir, moduleName + "2", cp1Layer2Module2Added.getItem().getContentHash()); }
static void assertNotApplied(final Patch patch, InstallationManager manager) throws IOException { InstalledIdentity installedIdentity = null; try { installedIdentity = manager.getInstalledIdentity(patch.getIdentity().getName(), patch.getIdentity().getVersion()); } catch (PatchingException e) { Assert.fail(e.getLocalizedMessage()); } final PatchableTarget.TargetInfo identity = installedIdentity.getIdentity().loadTargetInfo(); assertNotApplied(patch.getIdentity().getPatchType(), patch.getPatchId(), identity); assertDoesNotExists(identity.getDirectoryStructure().getInstalledImage().getPatchHistoryDir(patch.getPatchId())); for (final PatchElement element : patch.getElements()) { final PatchElementProvider provider = element.getProvider(); final PatchableTarget target = provider.isAddOn() ? installedIdentity.getAddOn(provider.getName()) : installedIdentity.getLayer(provider.getName()); Assert.assertNotNull(target); assertNotApplied(provider.getPatchType(), element.getId(), target.loadTargetInfo()); } }
@Test public void installedAddOn() throws Exception { String addOnName = randomString(); installAddOn(env.getModuleRoot(), addOnName); TestUtils.tree(env.getInstalledImage().getJbossHome()); InstalledIdentity installedIdentity = loadInstalledIdentity(); Collection<AddOn> addOns = installedIdentity.getAddOns(); assertEquals(1, addOns.size()); AddOn addOn = addOns.iterator().next(); assertEquals(addOnName, addOn.getName()); PatchableTarget.TargetInfo targetInfo = addOn.loadTargetInfo(); assertEquals(BASE, targetInfo.getCumulativePatchID()); assertTrue(targetInfo.getPatchIDs().isEmpty()); DirectoryStructure directoryStructure = targetInfo.getDirectoryStructure(); assertEquals(newFile(env.getModuleRoot(), "system", ADD_ONS, addOnName), directoryStructure.getModuleRoot()); assertNull(directoryStructure.getBundleRepositoryRoot()); }
@Test public void baseLayerIsAlwaysInstalled() throws Exception { tree(env.getInstalledImage().getJbossHome()); InstalledIdentity installedIdentity = loadInstalledIdentity(); List<Layer> layers = installedIdentity.getLayers(); assertEquals(1, layers.size()); Layer layer = layers.get(0); assertEquals(BASE, layer.getName()); PatchableTarget.TargetInfo targetInfo = layer.loadTargetInfo(); assertEquals(BASE, targetInfo.getCumulativePatchID()); assertTrue(targetInfo.getPatchIDs().isEmpty()); DirectoryStructure directoryStructure = targetInfo.getDirectoryStructure(); assertEquals(newFile(env.getBundleRepositoryRoot(), "system", LAYERS, BASE), directoryStructure.getBundleRepositoryRoot()); assertEquals(newFile(env.getModuleRoot(), "system", LAYERS, BASE), directoryStructure.getModuleRoot()); }
static void assertIsApplied(final Patch.PatchType patchType, final String patchId, final PatchableTarget.TargetInfo targetInfo) { if (patchType == Patch.PatchType.CUMULATIVE) { Assert.assertEquals(patchId, targetInfo.getCumulativePatchID()); Assert.assertTrue(targetInfo.getPatchIDs().isEmpty()); } else { Assert.assertTrue(targetInfo.getPatchIDs().contains(patchId)); } final DirectoryStructure structure = targetInfo.getDirectoryStructure(); assertExists(structure.getBundlesPatchDirectory(patchId)); assertExists(structure.getModulePatchDirectory(patchId)); }
File getModuleResource(final String layer, final String patchID, final String moduleName) throws IOException { final PatchableTarget.TargetInfo info = getLayer(layer).loadTargetInfo(); final File root = info.getDirectoryStructure().getModulePatchDirectory(patchID); final File moduleRoot = TestUtils.getModuleRoot(root, moduleName); return new File(moduleRoot, RESOURCE); }
File getModuleResource(final String layer, final String patchID, final String moduleName) throws IOException { final PatchableTarget.TargetInfo info = getLayer(layer).loadTargetInfo(); final File root = info.getDirectoryStructure().getModulePatchDirectory(patchID); final File moduleRoot = TestUtils.getModuleRoot(root, moduleName); return new File(moduleRoot, RESOURCE); }
static void assertNotApplied(final Patch.PatchType patchType, final String patchId, final PatchableTarget.TargetInfo targetInfo) { if (patchType == Patch.PatchType.CUMULATIVE) { Assert.assertNotEquals(patchId, targetInfo.getCumulativePatchID()); } else { Assert.assertFalse(targetInfo.getPatchIDs().contains(patchId)); } final DirectoryStructure structure = targetInfo.getDirectoryStructure(); assertDoesNotExists(structure.getBundlesPatchDirectory(patchId)); assertDoesNotExists(structure.getModulePatchDirectory(patchId)); }