IdentityPatchContext(final File backup, final PatchContentProvider contentProvider, final ContentVerificationPolicy contentPolicy, final InstallationManager.InstallationModification modification, final PatchingTaskContext.Mode mode, final InstalledImage installedImage) { this.miscTargetRoot = installedImage.getJbossHome(); this.mode = mode; this.contentProvider = contentProvider; this.contentPolicy = contentPolicy; this.modification = modification; this.installedImage = installedImage; this.history = PatchingHistory.Factory.getHistory(modification.getUnmodifiedInstallationState()); if (backup != null) { this.miscBackup = new File(backup, PatchContentLoader.MISC); this.configBackup = new File(backup, Constants.CONFIGURATION); } else { this.miscBackup = null; // This will trigger a failure when the root is actually needed this.configBackup = null; } this.identityEntry = new IdentityEntry(modification, null); }
IdentityPatchContext(final File backup, final PatchContentProvider contentProvider, final ContentVerificationPolicy contentPolicy, final InstallationManager.InstallationModification modification, final PatchingTaskContext.Mode mode, final InstalledImage installedImage) { this.miscTargetRoot = installedImage.getJbossHome(); this.mode = mode; this.contentProvider = contentProvider; this.contentPolicy = contentPolicy; this.modification = modification; this.installedImage = installedImage; this.history = PatchingHistory.Factory.getHistory(modification.getUnmodifiedInstallationState()); if (backup != null) { this.miscBackup = new File(backup, PatchContentLoader.MISC); this.configBackup = new File(backup, Constants.CONFIGURATION); } else { this.miscBackup = null; // This will trigger a failure when the root is actually needed this.configBackup = null; } this.identityEntry = new IdentityEntry(modification, null); }
@Before public void init() throws Exception { installLayers("layer1", "layer2"); final File binDir = mkdir(env.getInstalledImage().getJbossHome(), "bin"); standaloneSh = touch(binDir, "standalone.sh"); dump(standaloneSh, "original script to run standalone server"); originalStandaloneHash = hashFile(standaloneSh); addedByCP1 = new File(binDir, "added-by-cp1.txt"); addedByCP1RemovedByCP3 = new File(binDir, "added-by-cp1-removed-by-cp3.txt"); addedByCP2 = new File(binDir, "added-by-cp2.txt"); tool = newPatchTool(); }
break; case MISC: final File home = target.getDirectoryStructure().getInstalledImage().getJbossHome(); final ModificationCondition condition = modification.getCondition(); if(condition != null) {
@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 testAddDirectory() throws Exception { final ContentItem item = new MiscContentItem("dir", new String[] { "test"}, NO_CONTENT, true, false); final ContentModification addDir = new ContentModification(item, NO_CONTENT, ModificationType.ADD); final String patchID = randomString(); final Patch patch = PatchBuilder.create() .setPatchId(patchID) .setDescription(randomString()) .oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()) .getParent() .addContentModification(addDir) .build(); // create the patch final File patchDir = mkdir(tempDir, patch.getPatchId()); createPatchXMLFile(patchDir, patch); final File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId()); // Apply PatchingResult result = executePatch(zippedPatch); assertPatchHasBeenApplied(result, patch); final File test = new File(env.getInstalledImage().getJbossHome(), "test"); assertTrue(test.exists()); assertTrue(test.isDirectory()); final File dir = new File(test, "dir"); assertTrue(dir.exists()); assertTrue(dir.isDirectory()); rollback(patchID); }
@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()); }
@Test public void testAddFile() throws Exception { // build a one-off patch for the base installation // with 1 added file String patchID = randomString(); File patchDir = mkdir(tempDir, patchID); ContentModification fileAdded = ContentModificationUtils.addMisc(patchDir, patchID, "new file resource", "bin", "my-new-standalone.sh"); Patch patch = PatchBuilder.create() .setPatchId(patchID) .setDescription(randomString()) .oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()) .getParent() .addContentModification(fileAdded) .build(); assertFileDoesNotExist(env.getInstalledImage().getJbossHome(), "bin", fileAdded.getItem().getName()); createPatchXMLFile(patchDir, patch); File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId()); PatchingResult result = executePatch(zippedPatch); assertPatchHasBeenApplied(result, patch); assertFileExists(env.getInstalledImage().getJbossHome(), "bin", fileAdded.getItem().getName()); }
InstalledIdentity patchedInstalledIdentity = InstalledIdentity.load(env.getInstalledImage().getJbossHome(), productConfig, env.getInstalledImage().getModulesDir()); assertInstallationIsPatched(patch, patchedInstalledIdentity.getIdentity().loadTargetInfo()); assertFileExists(env.getInstalledImage().getJbossHome(), "bin", fileAdded.getItem().getName()); tree(env.getInstalledImage().getJbossHome());
assertPatchHasBeenApplied(patchResult, patch); InstalledIdentity patchedInstalledIdentity = InstalledIdentity.load(env.getInstalledImage().getJbossHome(), productConfig, env.getInstalledImage().getModulesDir()); assertInstallationIsPatched(patch, patchedInstalledIdentity.getIdentity().loadTargetInfo()); assertFileExists(env.getInstalledImage().getJbossHome(), "bin", fileAdded.getItem().getName()); assertPatchHasBeenRolledBack(rollbackResult, identityBeforePatch); InstalledIdentity rolledBackInstalledIdentity = InstalledIdentity.load(env.getInstalledImage().getJbossHome(), productConfig, env.getInstalledImage().getModulesDir()); PatchingAssert.assertFileDoesNotExist(env.getInstalledImage().getJbossHome(), "bin", fileAdded.getItem().getName()); if (File.separatorChar != '\\') { assertDirDoesNotExist(rolledBackInstalledIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(layerPatchId));
InstalledIdentity patchedInstalledIdentity = InstalledIdentity.load(env.getInstalledImage().getJbossHome(), productConfig, env.getInstalledImage().getModulesDir()); assertInstallationIsPatched(patch, patchedInstalledIdentity.getIdentity().loadTargetInfo()); assertFileExists(env.getInstalledImage().getJbossHome(), "bin", fileAdded.getItem().getName());
@Before public void setUp() throws Exception{ // with a file in it File binDir = mkdir(env.getInstalledImage().getJbossHome(), "bin"); String fileName = "standalone.sh"; removedFile = touch(binDir, fileName); dump(removedFile, "modified script to run standalone AS"); expectedModifiedHash = hashFile(removedFile); // let's simulate that the file has been modified by the users by using a hash that is not the file checksum byte[] unmodifiedHash = randomString().getBytes(StandardCharsets.UTF_8); String patchID = randomString(); File patchDir = mkdir(tempDir, patchID); File updatedFile = touch(patchDir, "misc", "bin", fileName); dump(updatedFile, "updated script"); // build a one-off patch for the base installation // with 1 removed file fileRemoved = new ContentModification(new MiscContentItem(fileName, new String[] { "bin" }, NO_CONTENT), unmodifiedHash, REMOVE); patch = PatchBuilder.create() .setPatchId(patchID) .setDescription(randomString()) .oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()) .getParent() .addContentModification(fileRemoved) .build(); // create the patch createPatchXMLFile(patchDir, patch); zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId()); runner = newPatchTool(); }
@Before public void setUp() throws Exception{ File binDir = mkdir(env.getInstalledImage().getJbossHome(), "bin"); String fileName = "standalone.sh"; modifiedFile = touch(binDir, fileName);
File binDir = mkdir(env.getInstalledImage().getJbossHome(), "bin"); String fileName = "standalone.sh"; File standaloneShellFile = touch(binDir, fileName); tree(env.getInstalledImage().getJbossHome()); assertPatchHasBeenRolledBack(rollbackResult, identityBeforePatch); assertFileExists(standaloneShellFile);
assertPatchHasBeenApplied(result, patch); tree(env.getInstalledImage().getJbossHome());
@Test public void testRemoveFile() throws Exception { // start from a base installation // with a file in it String fileName = "standalone.sh"; File standaloneShellFile = touch(env.getInstalledImage().getJbossHome(), "bin", fileName ); dump(standaloneShellFile, "original script to run standalone AS7"); // build a one-off patch for the base installation // with 1 removed file ContentModification fileRemoved = ContentModificationUtils.removeMisc(standaloneShellFile, "bin", fileName); Patch patch = PatchBuilder.create() .setPatchId(randomString()) .setDescription(randomString()) .oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()) .getParent() .addContentModification(fileRemoved) .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); /// file has been removed from the AS7 installation assertFileDoesNotExist(standaloneShellFile); // but it's been backed up assertFileExists(env.getInstalledImage().getPatchHistoryDir(patch.getPatchId()), "misc", "bin", fileName); }
InstalledIdentity patchedInstalledIdentity = loadInstalledIdentity(); assertInstallationIsPatched(patch, patchedInstalledIdentity.getIdentity().loadTargetInfo()); assertFileExists(env.getInstalledImage().getJbossHome(), "bin", fileAdded.getItem().getName());
File binDir = mkdir(env.getInstalledImage().getJbossHome(), "bin"); String fileName = "standalone.sh"; File standaloneShellFile = touch(binDir, fileName);
@Test public void testApplyOneOffPatchAndRollback() throws Exception { File binDir = mkdir(env.getInstalledImage().getJbossHome(), "bin"); String fileName = "standalone.sh"; File standaloneShellFile = touch(binDir, fileName);