Search in sources :

Example 6 with PatchElement

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

the class IdentityPatchRunner method reenableNotOverridenModules.

void reenableNotOverridenModules(final RollbackPatch patch, IdentityPatchContext context) throws PatchingException, IOException, XMLStreamException {
    assert patch.getIdentity().getPatchType() == Patch.PatchType.CUMULATIVE;
    final Iterator historyIterator = context.getHistory().iterator(patch.getIdentityState().getIdentity().loadTargetInfo());
    if (!historyIterator.hasNext()) {
        return;
    }
    final List<PatchElement> elements = patch.getElements();
    final Map<String, List<PatchElement>> layerPatches = new HashMap<String, List<PatchElement>>(elements.size());
    final Map<String, List<PatchElement>> addonPatches = new HashMap<String, List<PatchElement>>(elements.size());
    for (PatchElement e : elements) {
        if (e.getProvider().isAddOn()) {
            addonPatches.put(e.getProvider().getName(), Collections.<PatchElement>emptyList());
        } else {
            layerPatches.put(e.getProvider().getName(), Collections.<PatchElement>emptyList());
        }
    }
    Patch prevCP = null;
    while (historyIterator.hasNext()) {
        final Entry entry = historyIterator.next();
        if (entry.getType() == PatchType.CUMULATIVE) {
            prevCP = entry.getMetadata();
            break;
        }
        final Patch oneOff = entry.getMetadata();
        for (PatchElement oneOffElement : oneOff.getElements()) {
            final Map<String, List<PatchElement>> providerPatches;
            if (oneOffElement.getProvider().isAddOn()) {
                providerPatches = addonPatches;
            } else {
                providerPatches = layerPatches;
            }
            List<PatchElement> patches = providerPatches.get(oneOffElement.getProvider().getName());
            if (patches != null) {
                switch(patches.size()) {
                    case 0:
                        providerPatches.put(oneOffElement.getProvider().getName(), Collections.singletonList(oneOffElement));
                        break;
                    case 1:
                        patches = new ArrayList<PatchElement>(patches);
                        providerPatches.put(oneOffElement.getProvider().getName(), patches);
                    default:
                        patches.add(oneOffElement);
                }
            }
        }
    }
    Set<ModuleItem> cpElementModules;
    Set<ModuleItem> reenabledModules = Collections.emptySet();
    for (PatchElement e : elements) {
        final List<PatchElement> patches;
        if (e.getProvider().isAddOn()) {
            patches = addonPatches.get(e.getProvider().getName());
        } else {
            patches = layerPatches.get(e.getProvider().getName());
        }
        if (patches.isEmpty()) {
            continue;
        }
        cpElementModules = null;
        final PatchEntry rollbackEntry = context.resolveForElement(e);
        for (PatchElement oneOff : patches) {
            for (ContentModification mod : oneOff.getModifications()) {
                if (mod.getItem().getContentType() != ContentType.MODULE) {
                    continue;
                }
                final ModuleItem module = (ModuleItem) mod.getItem();
                if (rollbackEntry.get(new Location(module)) != null) {
                    continue;
                }
                if (reenabledModules.contains(module)) {
                    continue;
                }
                final File modulePath = PatchContentLoader.getModulePath(rollbackEntry.getDirectoryStructure().getModulePatchDirectory(oneOff.getId()), module);
                rollbackEntry.invalidateRoot(modulePath);
                if (reenabledModules.isEmpty()) {
                    reenabledModules = new HashSet<ModuleItem>();
                }
                reenabledModules.add(module);
                if (prevCP == null) {
                    rollbackEntry.disableBaseModule(module);
                } else {
                    if (cpElementModules == null) {
                        for (PatchElement cpE : prevCP.getElements()) {
                            if (cpE.getProvider().getName().equals(e.getProvider().getName()) && cpE.getProvider().getLayerType().equals(e.getProvider().getLayerType())) {
                                cpElementModules = new HashSet<ModuleItem>(cpE.getModifications().size());
                                for (ContentModification cpMod : cpE.getModifications()) {
                                    if (cpMod.getItem().getContentType() == ContentType.MODULE) {
                                        cpElementModules.add(cpMod.getItem(ModuleItem.class));
                                    }
                                }
                                break;
                            }
                        }
                    }
                    if (cpElementModules != null && !cpElementModules.contains(module)) {
                        rollbackEntry.disableBaseModule(module);
                    }
                }
            }
        }
    }
}
Also used : PatchEntry(org.jboss.as.patching.runner.IdentityPatchContext.PatchEntry) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) PatchElement(org.jboss.as.patching.metadata.PatchElement) ModuleItem(org.jboss.as.patching.metadata.ModuleItem) Entry(org.jboss.as.patching.tool.PatchingHistory.Entry) PatchEntry(org.jboss.as.patching.runner.IdentityPatchContext.PatchEntry) Iterator(org.jboss.as.patching.tool.PatchingHistory.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Patch(org.jboss.as.patching.metadata.Patch) RollbackPatch(org.jboss.as.patching.metadata.RollbackPatch) ContentModification(org.jboss.as.patching.metadata.ContentModification) File(java.io.File)

Example 7 with PatchElement

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

the class IdentityPatchRunner method portForward.

/**
 * Port forward missing module changes for each layer.
 *
 * @param patch   the current patch
 * @param context the patch context
 * @throws PatchingException
 * @throws IOException
 * @throws XMLStreamException
 */
void portForward(final Patch patch, IdentityPatchContext context) throws PatchingException, IOException, XMLStreamException {
    assert patch.getIdentity().getPatchType() == Patch.PatchType.CUMULATIVE;
    final PatchingHistory history = context.getHistory();
    for (final PatchElement element : patch.getElements()) {
        final PatchElementProvider provider = element.getProvider();
        final String name = provider.getName();
        final boolean addOn = provider.isAddOn();
        final IdentityPatchContext.PatchEntry target = context.resolveForElement(element);
        final String cumulativePatchID = target.getCumulativePatchID();
        if (Constants.BASE.equals(cumulativePatchID)) {
            reenableRolledBackInBase(target);
            continue;
        }
        boolean found = false;
        final PatchingHistory.Iterator iterator = history.iterator();
        while (iterator.hasNextCP()) {
            final PatchingHistory.Entry entry = iterator.nextCP();
            final String patchId = addOn ? entry.getAddOnPatches().get(name) : entry.getLayerPatches().get(name);
            if (patchId != null && patchId.equals(cumulativePatchID)) {
                final Patch original = loadPatchInformation(entry.getPatchId(), installedImage);
                for (final PatchElement originalElement : original.getElements()) {
                    if (name.equals(originalElement.getProvider().getName()) && addOn == originalElement.getProvider().isAddOn()) {
                        PatchingTasks.addMissingModifications(target, originalElement.getModifications(), ContentItemFilter.ALL_BUT_MISC);
                    }
                }
                // Record a loader to have access to the current modules
                final DirectoryStructure structure = target.getDirectoryStructure();
                final File modulesRoot = structure.getModulePatchDirectory(patchId);
                final File bundlesRoot = structure.getBundlesPatchDirectory(patchId);
                final PatchContentLoader loader = PatchContentLoader.create(null, bundlesRoot, modulesRoot);
                context.recordContentLoader(patchId, loader);
                found = true;
                break;
            }
        }
        if (!found) {
            throw PatchLogger.ROOT_LOGGER.patchNotFoundInHistory(cumulativePatchID);
        }
        reenableRolledBackInBase(target);
    }
}
Also used : PatchElementProvider(org.jboss.as.patching.metadata.PatchElementProvider) PatchElement(org.jboss.as.patching.metadata.PatchElement) Entry(org.jboss.as.patching.tool.PatchingHistory.Entry) Iterator(org.jboss.as.patching.tool.PatchingHistory.Iterator) PatchingHistory(org.jboss.as.patching.tool.PatchingHistory) Patch(org.jboss.as.patching.metadata.Patch) RollbackPatch(org.jboss.as.patching.metadata.RollbackPatch) File(java.io.File) PatchEntry(org.jboss.as.patching.runner.IdentityPatchContext.PatchEntry) DirectoryStructure(org.jboss.as.patching.DirectoryStructure)

Example 8 with PatchElement

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

the class IdentityPatchContext method createProcessedPatch.

/**
 * 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);
}
Also used : ArrayList(java.util.ArrayList) PatchElement(org.jboss.as.patching.metadata.PatchElement) PatchImpl(org.jboss.as.patching.metadata.PatchImpl)

Example 9 with PatchElement

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

the class PatchInspect method displayPatchXml.

private void displayPatchXml(CommandContext ctx, Patch patch) throws CommandException {
    final Identity identity = patch.getIdentity();
    SimpleTable table = new SimpleTable(2, ctx.getTerminalWidth());
    table.addLine(new String[] { "Patch ID:", patch.getPatchId() });
    table.addLine(new String[] { "Type:", identity.getPatchType().getName() });
    table.addLine(new String[] { "Identity name:", identity.getName() });
    table.addLine(new String[] { "Identity version:", identity.getVersion() });
    table.addLine(new String[] { "Description:", patch.getDescription() == null ? "n/a" : patch.getDescription() });
    if (patch.getLink() != null) {
        table.addLine(new String[] { "Link:", patch.getLink() });
    }
    ctx.printLine(table.toString(false));
    if (verbose) {
        ctx.printLine("");
        ctx.printLine("ELEMENTS");
        for (PatchElement e : patch.getElements()) {
            table = new SimpleTable(2, ctx.getTerminalWidth());
            table.addLine(new String[] { "Patch ID:", e.getId() });
            table.addLine(new String[] { "Name:", e.getProvider().getName() });
            table.addLine(new String[] { "Type:", e.getProvider().isAddOn() ? Constants.ADD_ON : Constants.LAYER });
            table.addLine(new String[] { "Description:", e.getDescription() });
            ctx.printLine("");
            ctx.printLine(table.toString(false));
        }
    }
}
Also used : SimpleTable(org.jboss.as.cli.util.SimpleTable) PatchElement(org.jboss.as.patching.metadata.PatchElement) Identity(org.jboss.as.patching.metadata.Identity)

Example 10 with PatchElement

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

the class PatchInfoHandler method patchIdInfo.

private ModelNode patchIdInfo(final OperationContext context, final String patchId, final boolean verbose, final PatchingHistory.Iterator i) {
    while (i.hasNext()) {
        final Entry entry = i.next();
        if (patchId.equals(entry.getPatchId())) {
            final ModelNode result = new ModelNode();
            result.get(Constants.PATCH_ID).set(entry.getPatchId());
            result.get(Constants.TYPE).set(entry.getType().getName());
            result.get(Constants.DESCRIPTION).set(entry.getMetadata().getDescription());
            final String link = entry.getMetadata().getLink();
            if (link != null) {
                result.get(Constants.LINK).set(link);
            }
            final Identity identity = entry.getMetadata().getIdentity();
            result.get(Constants.IDENTITY_NAME).set(identity.getName());
            result.get(Constants.IDENTITY_VERSION).set(identity.getVersion());
            if (verbose) {
                final ModelNode list = result.get(Constants.ELEMENTS).setEmptyList();
                final Patch metadata = entry.getMetadata();
                for (PatchElement e : metadata.getElements()) {
                    final ModelNode element = new ModelNode();
                    element.get(Constants.PATCH_ID).set(e.getId());
                    element.get(Constants.TYPE).set(e.getProvider().isAddOn() ? Constants.ADD_ON : Constants.LAYER);
                    element.get(Constants.NAME).set(e.getProvider().getName());
                    element.get(Constants.DESCRIPTION).set(e.getDescription());
                    list.add(element);
                }
            }
            return result;
        }
    }
    return null;
}
Also used : Entry(org.jboss.as.patching.tool.PatchingHistory.Entry) PatchElement(org.jboss.as.patching.metadata.PatchElement) ModelNode(org.jboss.dmr.ModelNode) Identity(org.jboss.as.patching.metadata.Identity) InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) Patch(org.jboss.as.patching.metadata.Patch)

Aggregations

PatchElement (org.jboss.as.patching.metadata.PatchElement)20 Patch (org.jboss.as.patching.metadata.Patch)13 PatchElementProvider (org.jboss.as.patching.metadata.PatchElementProvider)11 Identity (org.jboss.as.patching.metadata.Identity)10 ContentModification (org.jboss.as.patching.metadata.ContentModification)8 InstalledIdentity (org.jboss.as.patching.installation.InstalledIdentity)7 RollbackPatch (org.jboss.as.patching.metadata.RollbackPatch)6 IdentityUpgrade (org.jboss.as.patching.metadata.Identity.IdentityUpgrade)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 PatchingException (org.jboss.as.patching.PatchingException)4 PatchableTarget (org.jboss.as.patching.installation.PatchableTarget)4 ContentItem (org.jboss.as.patching.metadata.ContentItem)4 PatchEntry (org.jboss.as.patching.runner.IdentityPatchContext.PatchEntry)4 Entry (org.jboss.as.patching.tool.PatchingHistory.Entry)3 File (java.io.File)2 IOException (java.io.IOException)2 LinkedHashMap (java.util.LinkedHashMap)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 SimpleTable (org.jboss.as.cli.util.SimpleTable)2