Search in sources :

Example 1 with LayerType

use of org.jboss.as.patching.metadata.LayerType in project wildfly-core by wildfly.

the class IdentityPatchContext method resolveForElement.

/**
 * Get the target entry for a given patch element.
 *
 * @param element the patch element
 * @return the patch entry
 * @throws PatchingException
 */
protected PatchEntry resolveForElement(final PatchElement element) throws PatchingException {
    assert state == State.NEW;
    final PatchElementProvider provider = element.getProvider();
    final String layerName = provider.getName();
    final LayerType layerType = provider.getLayerType();
    final Map<String, PatchEntry> map;
    if (layerType == LayerType.Layer) {
        map = layers;
    } else {
        map = addOns;
    }
    PatchEntry entry = map.get(layerName);
    if (entry == null) {
        final InstallationManager.MutablePatchingTarget target = modification.resolve(layerName, layerType);
        if (target == null) {
            throw PatchLogger.ROOT_LOGGER.noSuchLayer(layerName);
        }
        entry = new PatchEntry(target, element);
        map.put(layerName, entry);
    }
    // Maintain the most recent element
    entry.updateElement(element);
    return entry;
}
Also used : InstallationManager(org.jboss.as.patching.installation.InstallationManager) PatchElementProvider(org.jboss.as.patching.metadata.PatchElementProvider) LayerType(org.jboss.as.patching.metadata.LayerType)

Example 2 with LayerType

use of org.jboss.as.patching.metadata.LayerType in project wildfly-core by wildfly.

the class IdentityPatchRunner method rollback.

/**
 * Rollback a patch.
 *
 * @param patchID the patch id
 * @param context the patch context
 * @throws PatchingException
 */
private void rollback(final String patchID, final IdentityPatchContext context) throws PatchingException {
    try {
        // Load the patch history
        final PatchingTaskContext.Mode mode = context.getMode();
        final Patch originalPatch = loadPatchInformation(patchID, installedImage);
        final RollbackPatch rollbackPatch = loadRollbackInformation(patchID, installedImage);
        final Patch.PatchType patchType = rollbackPatch.getIdentity().getPatchType();
        final InstalledIdentity history = rollbackPatch.getIdentityState();
        // Process originals by type first
        final LinkedHashMap<String, PatchElement> originalLayers = new LinkedHashMap<String, PatchElement>();
        final LinkedHashMap<String, PatchElement> originalAddOns = new LinkedHashMap<String, PatchElement>();
        for (final PatchElement patchElement : originalPatch.getElements()) {
            final PatchElementProvider provider = patchElement.getProvider();
            final String layerName = provider.getName();
            final LayerType layerType = provider.getLayerType();
            final Map<String, PatchElement> originals;
            switch(layerType) {
                case Layer:
                    originals = originalLayers;
                    break;
                case AddOn:
                    originals = originalAddOns;
                    break;
                default:
                    throw new IllegalStateException();
            }
            if (!originals.containsKey(layerName)) {
                originals.put(layerName, patchElement);
            } else {
                throw PatchLogger.ROOT_LOGGER.installationDuplicateLayer(layerType.toString(), layerName);
            }
        }
        // Process the rollback xml
        for (final PatchElement patchElement : rollbackPatch.getElements()) {
            final String elementPatchId = patchElement.getId();
            final PatchElementProvider provider = patchElement.getProvider();
            final String layerName = provider.getName();
            final LayerType layerType = provider.getLayerType();
            final LinkedHashMap<String, PatchElement> originals;
            switch(layerType) {
                case Layer:
                    originals = originalLayers;
                    break;
                case AddOn:
                    originals = originalAddOns;
                    break;
                default:
                    throw new IllegalStateException();
            }
            final PatchElement original = originals.remove(layerName);
            if (original == null) {
                throw PatchLogger.ROOT_LOGGER.noSuchLayer(layerName);
            }
            final IdentityPatchContext.PatchEntry entry = context.resolveForElement(patchElement);
            // Create the rollback
            PatchingTasks.rollback(elementPatchId, original.getModifications(), patchElement.getModifications(), entry, ContentItemFilter.ALL_BUT_MISC, mode);
            entry.rollback(original.getId());
            // We need to restore the previous state
            final Patch.PatchType elementPatchType = provider.getPatchType();
            final PatchableTarget.TargetInfo info;
            if (layerType == LayerType.AddOn) {
                info = history.getAddOn(layerName).loadTargetInfo();
            } else {
                info = history.getLayer(layerName).loadTargetInfo();
            }
            if (mode == ROLLBACK) {
                restoreFromHistory(entry, elementPatchId, elementPatchType, info);
            }
        }
        if (!originalLayers.isEmpty() || !originalAddOns.isEmpty()) {
            throw PatchLogger.ROOT_LOGGER.invalidRollbackInformation();
        }
        // Rollback the patch
        final IdentityPatchContext.PatchEntry identity = context.getIdentityEntry();
        PatchingTasks.rollback(patchID, originalPatch.getModifications(), rollbackPatch.getModifications(), identity, ContentItemFilter.MISC_ONLY, mode);
        identity.rollback(patchID);
        // Restore previous state
        if (mode == ROLLBACK) {
            final PatchableTarget.TargetInfo identityHistory = history.getIdentity().loadTargetInfo();
            restoreFromHistory(identity, rollbackPatch.getPatchId(), patchType, identityHistory);
            if (patchType == Patch.PatchType.CUMULATIVE) {
                reenableNotOverridenModules(rollbackPatch, context);
            }
        }
        if (patchType == Patch.PatchType.CUMULATIVE) {
            final Identity.IdentityUpgrade upgrade = rollbackPatch.getIdentity().forType(Patch.PatchType.CUMULATIVE, Identity.IdentityUpgrade.class);
            identity.setResultingVersion(upgrade.getResultingVersion());
        }
    } catch (Exception e) {
        throw rethrowException(e);
    }
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchableTarget(org.jboss.as.patching.installation.PatchableTarget) PatchElementProvider(org.jboss.as.patching.metadata.PatchElementProvider) RollbackPatch(org.jboss.as.patching.metadata.RollbackPatch) PatchElement(org.jboss.as.patching.metadata.PatchElement) XMLStreamException(javax.xml.stream.XMLStreamException) PatchingException(org.jboss.as.patching.PatchingException) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) LayerType(org.jboss.as.patching.metadata.LayerType) PatchType(org.jboss.as.patching.metadata.Patch.PatchType) Identity(org.jboss.as.patching.metadata.Identity) InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) Patch(org.jboss.as.patching.metadata.Patch) RollbackPatch(org.jboss.as.patching.metadata.RollbackPatch) PatchEntry(org.jboss.as.patching.runner.IdentityPatchContext.PatchEntry)

Aggregations

LayerType (org.jboss.as.patching.metadata.LayerType)2 PatchElementProvider (org.jboss.as.patching.metadata.PatchElementProvider)2 IOException (java.io.IOException)1 LinkedHashMap (java.util.LinkedHashMap)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 PatchingException (org.jboss.as.patching.PatchingException)1 InstallationManager (org.jboss.as.patching.installation.InstallationManager)1 InstalledIdentity (org.jboss.as.patching.installation.InstalledIdentity)1 PatchableTarget (org.jboss.as.patching.installation.PatchableTarget)1 Identity (org.jboss.as.patching.metadata.Identity)1 Patch (org.jboss.as.patching.metadata.Patch)1 PatchType (org.jboss.as.patching.metadata.Patch.PatchType)1 PatchElement (org.jboss.as.patching.metadata.PatchElement)1 RollbackPatch (org.jboss.as.patching.metadata.RollbackPatch)1 PatchEntry (org.jboss.as.patching.runner.IdentityPatchContext.PatchEntry)1