@Override protected Layer getProvider(final String name, final InstalledIdentity identity) throws OperationFailedException { final Layer target = identity.getLayer(name); if (target == null) { throw new OperationFailedException(PatchLogger.ROOT_LOGGER.noSuchLayer(name).getLocalizedMessage()); } return target; } }
@Override protected Layer getProvider(final String name, final InstalledIdentity identity) throws OperationFailedException { final Layer target = identity.getLayer(name); if (target == null) { throw new OperationFailedException(PatchLogger.ROOT_LOGGER.noSuchLayer(name).getLocalizedMessage()); } return target; } }
PatchableTarget getLayer(final String layerName) { return installationManager.getDefaultIdentity().getLayer(layerName); }
final Layer layer = installedIdentity.getLayer(layerName); if (layer == null) {
private static boolean isAgedOut(InstalledIdentity installedIdentity, final Patch metadata) { for (PatchElement pe : metadata.getElements()) { final PatchElementProvider peProvider = pe.getProvider(); final PatchableTarget layer = peProvider.isAddOn() ? installedIdentity.getAddOn(peProvider.getName()) : installedIdentity.getLayer(peProvider.getName()); if (layer == null) { // if an identity is missing a layer that means either it was re-configured and the layer // was removed // or the layer in the patch is optional and may be missing on the disk // we haven't had this case yet, not sure how critical this is to terminate the process of // cleaning up throw new IllegalStateException(PatchLogger.ROOT_LOGGER.layerNotFound(peProvider.getName())); } final File patchDir = layer.getDirectoryStructure().getModulePatchDirectory(pe.getId()); if (!patchDir.exists()) { return true; } } return false; }
private static boolean isAgedOut(InstalledIdentity installedIdentity, final Patch metadata) { for (PatchElement pe : metadata.getElements()) { final PatchElementProvider peProvider = pe.getProvider(); final PatchableTarget layer = peProvider.isAddOn() ? installedIdentity.getAddOn(peProvider.getName()) : installedIdentity.getLayer(peProvider.getName()); if (layer == null) { // if an identity is missing a layer that means either it was re-configured and the layer // was removed // or the layer in the patch is optional and may be missing on the disk // we haven't had this case yet, not sure how critical this is to terminate the process of // cleaning up throw new IllegalStateException(PatchLogger.ROOT_LOGGER.layerNotFound(peProvider.getName())); } final File patchDir = layer.getDirectoryStructure().getModulePatchDirectory(pe.getId()); if (!patchDir.exists()) { return true; } } return false; }
protected String getExpectedOverlayDir(String layerName, final String patchId) throws IOException { final Layer layer = updateInstallationManager().getDefaultIdentity().getLayer(layerName); if(layer == null) { fail("No layer " + layerName); } return layer.getDirectoryStructure().getModulePatchDirectory(layerName + "-" + patchId).getAbsolutePath(); }
switch(target) { case LAYER: dirStructure = originalIdentity.getLayer(name).getDirectoryStructure(); break; case ADD_ON:
switch(target) { case LAYER: dirStructure = originalIdentity.getLayer(name).getDirectoryStructure(); break; case ADD_ON:
final PatchElementProvider provider = element.getProvider(); final String layerName = provider.getName(); final PatchableTarget target = provider.isAddOn() ? identity.getAddOn(layerName) : identity.getLayer(layerName); boolean modules = false; boolean bundles = false;
final PatchElementProvider provider = element.getProvider(); final String layerName = provider.getName(); final PatchableTarget target = provider.isAddOn() ? identity.getAddOn(layerName) : identity.getLayer(layerName); boolean modules = false; boolean bundles = false;
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 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 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 testWrongModuleContent() throws Exception { final PatchingTestBuilder builder = createDefaultBuilder(); // Add some random content ContentModificationUtils.addModule(builder.getRoot(), "base-patch-001", "test.module", randomString()); // Override the hash with a wrong one final ModuleItem item = new ModuleItem("test.module", "main", WRONG_HASH); final ContentModification wrongModification = new ContentModification(item, IoUtils.NO_CONTENT, ModificationType.ADD); final PatchingTestStepBuilder step1 = builder.createStepBuilder(); step1.oneOffPatchIdentity(PRODUCT_VERSION) .setPatchId("oo1") .oneOffPatchElement("base-patch-001", "base", false) .addContentModification(wrongModification) .getParent() .addFileWithRandomContent(null, "test", "content"); // try { apply(step1); Assert.fail("should have failed"); } catch (PatchingException e) { Assert.assertFalse(builder.hasFile("test", "content")); final InstalledIdentity identity = loadInstallationManager().getDefaultIdentity(); final PatchableTarget base = identity.getLayer("base"); Assert.assertFalse(base.getDirectoryStructure().getModulePatchDirectory("base-patch-001").exists()); Assert.assertFalse(identity.getInstalledImage().getPatchHistoryDir("oo1").exists()); } }
@Test public void testWrongMiscContent() throws Exception { final PatchingTestBuilder builder = createDefaultBuilder(); ContentModificationUtils.addMisc(builder.getRoot(), "oo2", "test-content", "wrong-content"); final MiscContentItem item = new MiscContentItem("wrong-content", new String[0], WRONG_HASH); final ContentModification wrongModification = new ContentModification(item, IoUtils.NO_CONTENT, ModificationType.ADD); final PatchingTestStepBuilder step1 = builder.createStepBuilder(); step1.oneOffPatchIdentity(PRODUCT_VERSION) .setPatchId("oo2") .oneOffPatchElement("base-patch-002", "base", false) .addModuleWithRandomContent("other.test", null) .getParent() .addFileWithRandomContent(null, "test", "content") .addContentModification(wrongModification) ; // try { apply(step1); Assert.fail("should have failed"); } catch (PatchingException e) { Assert.assertFalse(builder.hasFile("test", "content")); Assert.assertFalse(builder.hasFile("wrong-content")); final InstalledIdentity identity = loadInstallationManager().getDefaultIdentity(); final PatchableTarget base = identity.getLayer("base"); Assert.assertFalse(base.getDirectoryStructure().getModulePatchDirectory("base-patch-002").exists()); Assert.assertFalse(identity.getInstalledImage().getPatchHistoryDir("oo2").exists()); } }
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);
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()); } }
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()); } }