Search in sources :

Example 1 with ModuleItem

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

the class ContentModificationUtils method modifyModule.

public static ContentModification modifyModule(File patchDir, String patchElementID, String moduleName, byte[] existingHash, String newContent) throws IOException {
    File modulesDir = newFile(patchDir, patchElementID, MODULES);
    File modifiedModule = createModule0(modulesDir, moduleName, newContent);
    byte[] updatedHash = hashFile(modifiedModule);
    ContentModification moduleUpdated = new ContentModification(new ModuleItem(moduleName, ModuleItem.MAIN_SLOT, updatedHash), existingHash, MODIFY);
    return moduleUpdated;
}
Also used : ModuleItem(org.jboss.as.patching.metadata.ModuleItem) IoUtils.newFile(org.jboss.as.patching.IoUtils.newFile) HashUtils.hashFile(org.jboss.as.patching.HashUtils.hashFile) File(java.io.File) ContentModification(org.jboss.as.patching.metadata.ContentModification)

Example 2 with ModuleItem

use of org.jboss.as.patching.metadata.ModuleItem 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 3 with ModuleItem

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

the class Location method hashCode.

static int hashCode(final ContentItem item) {
    final ContentType type = item.getContentType();
    switch(type) {
        case MODULE:
        case BUNDLE:
            final ModuleItem module = (ModuleItem) item;
            final String[] path = module.getName().split("\\.");
            return hashCode(type.toString(), module.getSlot(), path);
        case MISC:
            final MiscContentItem misc = (MiscContentItem) item;
            return hashCode(type.toString(), misc.getName(), misc.getPath());
        default:
            throw new IllegalStateException();
    }
}
Also used : ModuleItem(org.jboss.as.patching.metadata.ModuleItem) ContentType(org.jboss.as.patching.metadata.ContentType) MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem)

Example 4 with ModuleItem

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

the class ModuleRemoveTask method getOriginalModification.

@Override
protected ContentModification getOriginalModification(byte[] targetHash, byte[] itemHash) {
    final ModuleItem original = getContentItem();
    final ModuleItem item = new ModuleItem(original.getName(), original.getSlot(), targetHash);
    return new ContentModification(item, description.getModification().getTargetHash(), ModificationType.MODIFY, description.getModification().getCondition());
}
Also used : ModuleItem(org.jboss.as.patching.metadata.ModuleItem) ContentModification(org.jboss.as.patching.metadata.ContentModification)

Example 5 with ModuleItem

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

the class ModuleUpdateTask method createRollbackEntry.

@Override
ContentModification createRollbackEntry(ContentModification original, byte[] targetHash, byte[] itemHash) {
    // Although modules are ignored for rollback, we still keep track of our changes
    final ModuleItem item = createContentItem(contentItem, itemHash);
    final ModificationType type;
    // and we need to track that they can be rolled back to the last state
    if (original.getType() != ModificationType.MODIFY && itemHash.length == 0) {
        type = ModificationType.REMOVE;
    } else {
        type = ModificationType.MODIFY;
    }
    return new ContentModification(item, targetHash, type, original.getCondition());
}
Also used : ModuleItem(org.jboss.as.patching.metadata.ModuleItem) ModificationType(org.jboss.as.patching.metadata.ModificationType) ContentModification(org.jboss.as.patching.metadata.ContentModification)

Aggregations

ModuleItem (org.jboss.as.patching.metadata.ModuleItem)13 ContentModification (org.jboss.as.patching.metadata.ContentModification)11 File (java.io.File)7 HashUtils.hashFile (org.jboss.as.patching.HashUtils.hashFile)5 IoUtils.newFile (org.jboss.as.patching.IoUtils.newFile)5 InstalledIdentity (org.jboss.as.patching.installation.InstalledIdentity)2 PatchableTarget (org.jboss.as.patching.installation.PatchableTarget)2 Patch (org.jboss.as.patching.metadata.Patch)2 PatchElement (org.jboss.as.patching.metadata.PatchElement)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 ContentConflictsException (org.jboss.as.patching.ContentConflictsException)1 PatchingException (org.jboss.as.patching.PatchingException)1 ContentType (org.jboss.as.patching.metadata.ContentType)1 Identity (org.jboss.as.patching.metadata.Identity)1 IdentityUpgrade (org.jboss.as.patching.metadata.Identity.IdentityUpgrade)1 MiscContentItem (org.jboss.as.patching.metadata.MiscContentItem)1