@Override public void finishPatch(final Patch processedPatch, final RollbackPatch rollbackPatch, final IdentityPatchContext context) throws Exception { final File historyDir = structure.getInstalledImage().getPatchHistoryDir(patchId); if (!historyDir.exists()) { historyDir.mkdirs(); } // Backup the current active patch Info final File timestamp = new File(historyDir, Constants.TIMESTAMP); PatchUtils.writeRef(timestamp, generateTimestamp()); // Persist the processed patch, which contains the records of changes final File backupPatchXml = new File(historyDir, PatchXml.PATCH_XML); IdentityPatchContext.writePatch(processedPatch, backupPatchXml); // Persist the rollback.xml in the history directory final File rollbackPatchXml = new File(historyDir, Constants.ROLLBACK_XML); IdentityPatchContext.writePatch(rollbackPatch, rollbackPatchXml); // Backup the configuration context.backupConfiguration(); }
/** * Backup the current configuration as part of the patch history. * * @throws IOException for any error */ void backupConfiguration() throws IOException { final String configuration = Constants.CONFIGURATION; final File a = new File(installedImage.getAppClientDir(), configuration); final File d = new File(installedImage.getDomainDir(), configuration); final File s = new File(installedImage.getStandaloneDir(), configuration); if (a.exists()) { final File ab = new File(configBackup, Constants.APP_CLIENT); backupDirectory(a, ab); } if (d.exists()) { final File db = new File(configBackup, Constants.DOMAIN); backupDirectory(d, db); } if (s.exists()) { final File sb = new File(configBackup, Constants.STANDALONE); backupDirectory(s, sb); } }
/** * Create a patch representing what we actually processed. This may contain some fixed content hashes for removed * modules. * * @param original the original * @return the processed patch */ protected Patch createProcessedPatch(final Patch original) { // Process elements final List<PatchElement> elements = new ArrayList<PatchElement>(); // Process layers for (final PatchEntry entry : getLayers()) { final PatchElement element = createPatchElement(entry, entry.element.getId(), entry.modifications); elements.add(element); } // Process add-ons for (final PatchEntry entry : getAddOns()) { final PatchElement element = createPatchElement(entry, entry.element.getId(), entry.modifications); elements.add(element); } // Swap the patch element modifications, keep the identity ones since we don't need to fix the misc modifications return new PatchImpl(original.getPatchId(), original.getDescription(), original.getLink(), original.getIdentity(), elements, identityEntry.modifications); }
@Override public void completed(IdentityPatchContext context) { final InstalledImage installedImage = directoryStructure.getInstalledImage(); final File history = installedImage.getPatchHistoryDir(patch.getPatchId()); if (!recursiveDelete(history)) { context.failedToCleanupDir(history); } // Cleanup all the recorded rollbacks cleanupEntry(context.getLayers()); cleanupEntry(context.getAddOns()); cleanupEntry(Collections.singleton(context.getIdentityEntry())); }
final File workDir = createTempDir(); final PatchContentProvider provider = PatchContentProvider.ROLLBACK_PROVIDER; final IdentityPatchContext context = new IdentityPatchContext(workDir, provider, contentPolicy, modification, ROLLBACK, installedImage); try { final IdentityPatchContext.PatchEntry identity = context.getIdentityEntry(); final IdentityRollbackCallback callback = new IdentityRollbackCallback(patchId, patches, resetConfiguration, identity.getDirectoryStructure()); try { return executeTasks(context, callback); } catch (Exception e) { context.cancel(callback); PatchLogger.ROOT_LOGGER.debugf(e, "failed to rollback patch %s", patchId); throw rethrowException(e); PatchLogger.ROOT_LOGGER.cannotDeleteFile(workDir.getAbsolutePath()); context.cleanup();
final InstallationManager.InstallationModification modification = context.getModification(); if (patchType == Patch.PatchType.CUMULATIVE) { final IdentityPatchContext.PatchEntry target = context.resolveForElement(element); final PatchElementProvider provider = element.getProvider(); final Patch.PatchType elementPatchType = provider.getPatchType(); final IdentityPatchContext.PatchEntry identityEntry = context.getIdentityEntry(); apply(patchId, patch.getModifications(), identityEntry); identityEntry.apply(patchId, patchType); return executeTasks(context, callback); } catch (Exception e) { context.cancel(callback); throw rethrowException(e);
for (final PatchEntry entry : getLayers()) { final PatchElement element = createRollbackElement(entry); elements.add(element); for (final PatchEntry entry : getAddOns()) { final PatchElement element = createRollbackElement(entry); elements.add(element);
final Patch processedPatch = createProcessedPatch(original); final RollbackPatch rollbackPatch = createRollbackPatch(patchId, patchType); callback.finishPatch(processedPatch, rollbackPatch, this); } catch (Exception e) { if (undoChanges()) { callback.operationCancelled(this);
final IdentityPatchContext context = new IdentityPatchContext(backup, contentProvider, contentPolicy, modification, APPLY, installedImage); try { return applyPatch(patchId, patch, context); throw rethrowException(e); } finally { context.cleanup();
/** * Cleanup the history directories for all recorded rolled back patches. */ protected void cleanupRollbackPatchHistory() { final DirectoryStructure structure = getDirectoryStructure(); for (final String rollback : rollbacks) { if (!IoUtils.recursiveDelete(structure.getBundlesPatchDirectory(rollback))) { failedToCleanupDir(structure.getBundlesPatchDirectory(rollback)); } if (!IoUtils.recursiveDelete(structure.getModulePatchDirectory(rollback))) { failedToCleanupDir(structure.getModulePatchDirectory(rollback)); } } } }
/** * Create a patch element for the rollback patch. * * @param entry the entry * @return the new patch element */ protected static PatchElement createRollbackElement(final PatchEntry entry) { final PatchElement patchElement = entry.element; final String patchId; final Patch.PatchType patchType = patchElement.getProvider().getPatchType(); if (patchType == Patch.PatchType.CUMULATIVE) { patchId = entry.getCumulativePatchID(); } else { patchId = patchElement.getId(); } return createPatchElement(entry, patchId, entry.rollbackActions); }
@Override public void completed(IdentityPatchContext context) { final InstalledImage installedImage = directoryStructure.getInstalledImage(); final File history = installedImage.getPatchHistoryDir(patch.getPatchId()); if (!recursiveDelete(history)) { context.failedToCleanupDir(history); } // Cleanup all the recorded rollbacks cleanupEntry(context.getLayers()); cleanupEntry(context.getAddOns()); cleanupEntry(Collections.singleton(context.getIdentityEntry())); }
final File workDir = createTempDir(); final PatchContentProvider provider = PatchContentProvider.ROLLBACK_PROVIDER; final IdentityPatchContext context = new IdentityPatchContext(workDir, provider, contentPolicy, modification, ROLLBACK, installedImage); try { final IdentityPatchContext.PatchEntry identity = context.getIdentityEntry(); final IdentityRollbackCallback callback = new IdentityRollbackCallback(patchId, patches, resetConfiguration, identity.getDirectoryStructure()); try { return executeTasks(context, callback); } catch (Exception e) { context.cancel(callback); PatchLogger.ROOT_LOGGER.debugf(e, "failed to rollback patch %s", patchId); throw rethrowException(e); PatchLogger.ROOT_LOGGER.cannotDeleteFile(workDir.getAbsolutePath()); context.cleanup();
final InstallationManager.InstallationModification modification = context.getModification(); if (patchType == Patch.PatchType.CUMULATIVE) { final IdentityPatchContext.PatchEntry target = context.resolveForElement(element); final PatchElementProvider provider = element.getProvider(); final Patch.PatchType elementPatchType = provider.getPatchType(); final IdentityPatchContext.PatchEntry identityEntry = context.getIdentityEntry(); apply(patchId, patch.getModifications(), identityEntry); identityEntry.apply(patchId, patchType); return executeTasks(context, callback); } catch (Exception e) { context.cancel(callback); throw rethrowException(e);
for (final PatchEntry entry : getLayers()) { final PatchElement element = createRollbackElement(entry); elements.add(element); for (final PatchEntry entry : getAddOns()) { final PatchElement element = createRollbackElement(entry); elements.add(element);
final Patch processedPatch = createProcessedPatch(original); final RollbackPatch rollbackPatch = createRollbackPatch(patchId, patchType); callback.finishPatch(processedPatch, rollbackPatch, this); } catch (Exception e) { if (undoChanges()) { callback.operationCancelled(this);
final IdentityPatchContext context = new IdentityPatchContext(backup, contentProvider, contentPolicy, modification, APPLY, installedImage); try { return applyPatch(patchId, patch, context); throw rethrowException(e); } finally { context.cleanup();
/** * Cleanup the history directories for all recorded rolled back patches. */ protected void cleanupRollbackPatchHistory() { final DirectoryStructure structure = getDirectoryStructure(); for (final String rollback : rollbacks) { if (!IoUtils.recursiveDelete(structure.getBundlesPatchDirectory(rollback))) { failedToCleanupDir(structure.getBundlesPatchDirectory(rollback)); } if (!IoUtils.recursiveDelete(structure.getModulePatchDirectory(rollback))) { failedToCleanupDir(structure.getModulePatchDirectory(rollback)); } } } }
/** * Create a patch element for the rollback patch. * * @param entry the entry * @return the new patch element */ protected static PatchElement createRollbackElement(final PatchEntry entry) { final PatchElement patchElement = entry.element; final String patchId; final Patch.PatchType patchType = patchElement.getProvider().getPatchType(); if (patchType == Patch.PatchType.CUMULATIVE) { patchId = entry.getCumulativePatchID(); } else { patchId = patchElement.getId(); } return createPatchElement(entry, patchId, entry.rollbackActions); }
/** * Create a patch representing what we actually processed. This may contain some fixed content hashes for removed * modules. * * @param original the original * @return the processed patch */ protected Patch createProcessedPatch(final Patch original) { // Process elements final List<PatchElement> elements = new ArrayList<PatchElement>(); // Process layers for (final PatchEntry entry : getLayers()) { final PatchElement element = createPatchElement(entry, entry.element.getId(), entry.modifications); elements.add(element); } // Process add-ons for (final PatchEntry entry : getAddOns()) { final PatchElement element = createPatchElement(entry, entry.element.getId(), entry.modifications); elements.add(element); } // Swap the patch element modifications, keep the identity ones since we don't need to fix the misc modifications return new PatchImpl(original.getPatchId(), original.getDescription(), original.getLink(), original.getIdentity(), elements, identityEntry.modifications); }