protected static InstalledIdentity copy(InstalledIdentity original) throws IOException { final InstalledIdentityImpl copy = new InstalledIdentityImpl(original.getIdentity(), original.getAllInstalledPatches(), original.getInstalledImage()); for (final Layer layer : original.getLayers()) { copy.putLayer(layer.getName(), new LayerInfo(layer.getName(), layer.loadTargetInfo(), layer.getDirectoryStructure())); } for (final AddOn addOn : original.getAddOns()) { copy.putAddOn(addOn.getName(), new LayerInfo(addOn.getName(), addOn.loadTargetInfo(), addOn.getDirectoryStructure())); } return copy; }
protected static InstalledIdentity copy(InstalledIdentity original) throws IOException { final InstalledIdentityImpl copy = new InstalledIdentityImpl(original.getIdentity(), original.getAllInstalledPatches(), original.getInstalledImage()); for (final Layer layer : original.getLayers()) { copy.putLayer(layer.getName(), new LayerInfo(layer.getName(), layer.loadTargetInfo(), layer.getDirectoryStructure())); } for (final AddOn addOn : original.getAddOns()) { copy.putAddOn(addOn.getName(), new LayerInfo(addOn.getName(), addOn.loadTargetInfo(), addOn.getDirectoryStructure())); } return copy; }
@Override public PatchInfo getPatchInfo(String streamName) throws PatchingException { try { final InstalledIdentity installedIdentity = streamName == null ? manager.getDefaultIdentity() : manager.getInstalledIdentity(streamName, null); final PatchableTarget.TargetInfo info = installedIdentity.getIdentity().loadTargetInfo(); final VerbosePatchInfo.Builder infoBuilder = VerbosePatchInfo.builder() .setVersion(installedIdentity.getIdentity().getVersion()) .setCumulativePatchId(info.getCumulativePatchID()) .setPatchIds(info.getPatchIDs()); for(Layer layer : installedIdentity.getLayers()) { infoBuilder.addLayerInfo(layer.getName(), layer.loadTargetInfo()); } for(AddOn addon : installedIdentity.getAddOns()) { infoBuilder.addAddOnInfo(addon.getName(), addon.loadTargetInfo()); } return infoBuilder.build(); } catch (IOException e) { // why throw a rethrowException(e) ? throw new RuntimeException(e); } }
@Override public PatchInfo getPatchInfo(String streamName) throws PatchingException { try { final InstalledIdentity installedIdentity = streamName == null ? manager.getDefaultIdentity() : manager.getInstalledIdentity(streamName, null); final PatchableTarget.TargetInfo info = installedIdentity.getIdentity().loadTargetInfo(); final VerbosePatchInfo.Builder infoBuilder = VerbosePatchInfo.builder() .setVersion(installedIdentity.getIdentity().getVersion()) .setCumulativePatchId(info.getCumulativePatchID()) .setPatchIds(info.getPatchIDs()); for(Layer layer : installedIdentity.getLayers()) { infoBuilder.addLayerInfo(layer.getName(), layer.loadTargetInfo()); } for(AddOn addon : installedIdentity.getAddOns()) { infoBuilder.addAddOnInfo(addon.getName(), addon.loadTargetInfo()); } return infoBuilder.build(); } catch (IOException e) { // why throw a rethrowException(e) ? throw new RuntimeException(e); } }
@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()); }
@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()); }
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()); }
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()); }
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); }
installedIdentity.getLayer("base").loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(baseCP1ID), "org", "jboss", "test2"); cp2BaseModule2Removed = ContentModificationUtils.removeModule(baseModule2Dir, moduleName + 2); installedIdentity.getLayer("layer2").loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(layer2CP1ID), "org", "jboss", "test"); cp2Layer2ModuleRemoved = ContentModificationUtils.removeModule(layer2ModuleDir, moduleName);
@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 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()); }
@Test public void testRemoveModule() throws Exception { String moduleName = randomString(); // create an empty module in the AS7 installation File baseModuleDir = newFile(env.getInstalledImage().getModulesDir(), SYSTEM, LAYERS, BASE); File moduleDir = createModule0(baseModuleDir, moduleName); // build a one-off patch for the installation base layer // with 1 module removed String baseLayerPatchID = randomString(); Patch patch = PatchBuilder.create() .setPatchId(randomString()) .setDescription(randomString()) .oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()) .getParent() .oneOffPatchElement(baseLayerPatchID, BASE, false) .addContentModification(ContentModificationUtils.removeModule(moduleDir)) .getParent() .build(); // create the patch File patchDir = mkdir(tempDir, patch.getPatchId()); createPatchXMLFile(patchDir, patch); File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId()); PatchingResult result = executePatch(zippedPatch); assertPatchHasBeenApplied(result, patch); InstalledIdentity installedIdentity = loadInstalledIdentity(); File modulesPatchDir = installedIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(baseLayerPatchID); assertDirExists(modulesPatchDir); assertDefinedAbsentModule(modulesPatchDir, moduleName); }
@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()); }
File modulesPatchDir = installedIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(baseLayerPatchID); assertDirExists(modulesPatchDir);
DirectoryStructure layerDirStructure = installedIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure(); File modulesPatchDir = layerDirStructure.getModulePatchDirectory(layerPatchId); assertDirExists(modulesPatchDir);
assertFileExists(env.getInstalledImage().getJbossHome(), "bin", fileAdded.getItem().getName()); DirectoryStructure layerDirStructure = installedIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure(); File modulesPatchDir = layerDirStructure.getModulePatchDirectory(layerPatchId); assertDirExists(modulesPatchDir);
File modulePatchDirectory = updatedInstalledIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(layerPatchID); assertDirExists(modulePatchDirectory); assertDefinedModule(modulePatchDirectory, moduleName, moduleAdded.getItem().getContentHash());
File modulePatchDirectory = updatedInstalledIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(layerPatchID); assertDirExists(modulePatchDirectory); assertDefinedModule(modulePatchDirectory, moduleName, moduleAdded.getItem().getContentHash());