Search in sources :

Example 1 with Identity

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

the class MergingPatchMetadataTestCase method testModifyModify.

@Test
public void testModifyModify() throws Exception {
    final Patch cp1 = generateCP("base", "cp1", ModificationType.MODIFY);
    final Patch cp2 = generateCP("cp1", "cp2", ModificationType.MODIFY);
    final Patch merged = PatchMerger.merge(cp1, cp2);
    assertEquals("cp2", merged.getPatchId());
    assertEquals("cp2" + " description", merged.getDescription());
    final IdentityUpgrade identity = merged.getIdentity().forType(PatchType.CUMULATIVE, Identity.IdentityUpgrade.class);
    assertEquals("base", identity.getVersion());
    assertEquals("cp2", identity.getResultingVersion());
    assertEquals(PatchType.CUMULATIVE, identity.getPatchType());
    final List<PatchElement> elements = merged.getElements();
    assertEquals(1, elements.size());
    final PatchElement e = elements.get(0);
    assertEquals("base-" + "cp2", e.getId());
    final PatchElementProvider provider = e.getProvider();
    assertEquals("base", provider.getName());
    assertEquals(PatchType.CUMULATIVE, provider.getPatchType());
    assertEquals(LayerType.Layer, provider.getLayerType());
    assertEquals(3, e.getModifications().size());
    for (ContentModification mod : e.getModifications()) {
        assertEquals(ModificationType.MODIFY, mod.getType());
        final ContentItem item = mod.getItem();
        if (ContentType.MODULE.equals(item.getContentType())) {
            Assert.assertArrayEquals(moduleHash("base"), mod.getTargetHash());
            Assert.assertArrayEquals(moduleHash("cp2"), item.getContentHash());
        } else if (ContentType.MISC.equals(item.getContentType())) {
            Assert.assertArrayEquals(miscHash("base"), mod.getTargetHash());
            Assert.assertArrayEquals(miscHash("cp2"), item.getContentHash());
        } else {
            Assert.assertArrayEquals(bundleHash("base"), mod.getTargetHash());
            Assert.assertArrayEquals(bundleHash("cp2"), item.getContentHash());
        }
    }
}
Also used : IdentityUpgrade(org.jboss.as.patching.metadata.Identity.IdentityUpgrade) PatchElementProvider(org.jboss.as.patching.metadata.PatchElementProvider) PatchElement(org.jboss.as.patching.metadata.PatchElement) Identity(org.jboss.as.patching.metadata.Identity) Patch(org.jboss.as.patching.metadata.Patch) ContentModification(org.jboss.as.patching.metadata.ContentModification) ContentItem(org.jboss.as.patching.metadata.ContentItem) Test(org.junit.Test)

Example 2 with Identity

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

the class MergingPatchMetadataTestCase method testModifyRemove.

@Test
public void testModifyRemove() throws Exception {
    final Patch cp1 = generateCP("base", "cp1", ModificationType.MODIFY);
    final Patch cp2 = generateCP("cp1", "cp2", ModificationType.REMOVE);
    final Patch merged = PatchMerger.merge(cp1, cp2);
    assertEquals("cp2", merged.getPatchId());
    assertEquals("cp2" + " description", merged.getDescription());
    final IdentityUpgrade identity = merged.getIdentity().forType(PatchType.CUMULATIVE, Identity.IdentityUpgrade.class);
    assertEquals("base", identity.getVersion());
    assertEquals("cp2", identity.getResultingVersion());
    assertEquals(PatchType.CUMULATIVE, identity.getPatchType());
    final List<PatchElement> elements = merged.getElements();
    assertEquals(1, elements.size());
    final PatchElement e = elements.get(0);
    assertEquals("base-" + "cp2", e.getId());
    final PatchElementProvider provider = e.getProvider();
    assertEquals("base", provider.getName());
    assertEquals(PatchType.CUMULATIVE, provider.getPatchType());
    assertEquals(LayerType.Layer, provider.getLayerType());
    assertEquals(3, e.getModifications().size());
    for (ContentModification mod : e.getModifications()) {
        assertEquals(ModificationType.REMOVE, mod.getType());
        final ContentItem item = mod.getItem();
        assertEquals(0, item.getContentHash().length);
        if (ContentType.MODULE.equals(item.getContentType())) {
            Assert.assertArrayEquals(moduleHash("base"), mod.getTargetHash());
        } else if (ContentType.MISC.equals(item.getContentType())) {
            Assert.assertArrayEquals(miscHash("base"), mod.getTargetHash());
        } else {
            Assert.assertArrayEquals(bundleHash("base"), mod.getTargetHash());
        }
    }
}
Also used : IdentityUpgrade(org.jboss.as.patching.metadata.Identity.IdentityUpgrade) PatchElementProvider(org.jboss.as.patching.metadata.PatchElementProvider) PatchElement(org.jboss.as.patching.metadata.PatchElement) Identity(org.jboss.as.patching.metadata.Identity) Patch(org.jboss.as.patching.metadata.Patch) ContentModification(org.jboss.as.patching.metadata.ContentModification) ContentItem(org.jboss.as.patching.metadata.ContentItem) Test(org.junit.Test)

Example 3 with Identity

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

the class MergingPatchMetadataTestCase method testRemoveAdd.

@Test
public void testRemoveAdd() throws Exception {
    final Patch cp1 = generateCP("base", "cp1", ModificationType.REMOVE);
    final Patch cp2 = generateCP("cp1", "cp2", ModificationType.ADD);
    final Patch merged = PatchMerger.merge(cp1, cp2);
    assertEquals("cp2", merged.getPatchId());
    assertEquals("cp2" + " description", merged.getDescription());
    final IdentityUpgrade identity = merged.getIdentity().forType(PatchType.CUMULATIVE, Identity.IdentityUpgrade.class);
    assertEquals("base", identity.getVersion());
    assertEquals("cp2", identity.getResultingVersion());
    assertEquals(PatchType.CUMULATIVE, identity.getPatchType());
    final List<PatchElement> elements = merged.getElements();
    assertEquals(1, elements.size());
    final PatchElement e = elements.get(0);
    assertEquals("base-" + "cp2", e.getId());
    final PatchElementProvider provider = e.getProvider();
    assertEquals("base", provider.getName());
    assertEquals(PatchType.CUMULATIVE, provider.getPatchType());
    assertEquals(LayerType.Layer, provider.getLayerType());
    assertEquals(3, e.getModifications().size());
    for (ContentModification mod : e.getModifications()) {
        assertEquals(ModificationType.MODIFY, mod.getType());
        final ContentItem item = mod.getItem();
        if (ContentType.MODULE.equals(item.getContentType())) {
            Assert.assertArrayEquals(moduleHash("base"), mod.getTargetHash());
            Assert.assertArrayEquals(moduleHash("cp2"), item.getContentHash());
        } else if (ContentType.MISC.equals(item.getContentType())) {
            Assert.assertArrayEquals(miscHash("base"), mod.getTargetHash());
            Assert.assertArrayEquals(miscHash("cp2"), item.getContentHash());
        } else {
            Assert.assertArrayEquals(bundleHash("base"), mod.getTargetHash());
            Assert.assertArrayEquals(bundleHash("cp2"), item.getContentHash());
        }
    }
}
Also used : IdentityUpgrade(org.jboss.as.patching.metadata.Identity.IdentityUpgrade) PatchElementProvider(org.jboss.as.patching.metadata.PatchElementProvider) PatchElement(org.jboss.as.patching.metadata.PatchElement) Identity(org.jboss.as.patching.metadata.Identity) Patch(org.jboss.as.patching.metadata.Patch) ContentModification(org.jboss.as.patching.metadata.ContentModification) ContentItem(org.jboss.as.patching.metadata.ContentItem) Test(org.junit.Test)

Example 4 with Identity

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

the class IdentityPatchRunner method applyPatch.

/**
 * Apply a patch.
 *
 * @param patchId the patch id
 * @param patch   the patch metadata
 * @param context the patch context
 * @throws PatchingException
 * @throws IOException
 * @throws XMLStreamException
 */
private PatchingResult applyPatch(final String patchId, final Patch patch, final IdentityPatchContext context) throws PatchingException, IOException, XMLStreamException {
    final Identity identity = patch.getIdentity();
    final Patch.PatchType patchType = identity.getPatchType();
    final InstallationManager.InstallationModification modification = context.getModification();
    if (patchType == Patch.PatchType.CUMULATIVE) {
        // Invalidate all installed patches (one-off, cumulative) - we never need to invalidate the release base
        final List<String> invalidation = new ArrayList<String>(modification.getPatchIDs());
        if (!invalidation.isEmpty()) {
            try {
                // Before rolling back the one-off patches, validate that the state until that point is consistent
                validateRollbackState(invalidation.get(invalidation.size() - 1), modification.getUnmodifiedInstallationState());
            } catch (PatchingException e) {
                throw e;
            } catch (Exception e) {
                throw new PatchingException(e);
            }
            // Invalidate the installed patches first
            for (final String rollback : invalidation) {
                rollback(rollback, context);
            }
        }
    }
    // Add to installed patches list
    modification.addInstalledPatch(patchId);
    // Then apply the current patch
    for (final PatchElement element : patch.getElements()) {
        // Apply the content modifications
        final IdentityPatchContext.PatchEntry target = context.resolveForElement(element);
        final PatchElementProvider provider = element.getProvider();
        final Patch.PatchType elementPatchType = provider.getPatchType();
        final String elementPatchId = element.getId();
        // See if we can skip this element
        if (target.isApplied(elementPatchId)) {
            // This needs some further testing, maybe we need to compare our history with the patch if they are consistent
            throw PatchLogger.ROOT_LOGGER.alreadyApplied(elementPatchId);
        }
        // Check upgrade conditions
        checkUpgradeConditions(provider, target);
        apply(elementPatchId, element.getModifications(), target);
        target.apply(elementPatchId, elementPatchType);
    }
    // Apply the patch to the identity
    final IdentityPatchContext.PatchEntry identityEntry = context.getIdentityEntry();
    apply(patchId, patch.getModifications(), identityEntry);
    identityEntry.apply(patchId, patchType);
    // Port forward missing module changes
    if (patchType == Patch.PatchType.CUMULATIVE) {
        portForward(patch, context);
    }
    // We need the resulting version for rollback
    if (patchType == Patch.PatchType.CUMULATIVE) {
        final Identity.IdentityUpgrade upgrade = identity.forType(Patch.PatchType.CUMULATIVE, Identity.IdentityUpgrade.class);
        identityEntry.setResultingVersion(upgrade.getResultingVersion());
    }
    // Execute the tasks
    final IdentityApplyCallback callback = new IdentityApplyCallback(patch, identityEntry.getDirectoryStructure());
    try {
        return executeTasks(context, callback);
    } catch (Exception e) {
        context.cancel(callback);
        throw rethrowException(e);
    }
}
Also used : PatchingException(org.jboss.as.patching.PatchingException) PatchElementProvider(org.jboss.as.patching.metadata.PatchElementProvider) ArrayList(java.util.ArrayList) PatchElement(org.jboss.as.patching.metadata.PatchElement) XMLStreamException(javax.xml.stream.XMLStreamException) PatchingException(org.jboss.as.patching.PatchingException) IOException(java.io.IOException) InstallationManager(org.jboss.as.patching.installation.InstallationManager) Identity(org.jboss.as.patching.metadata.Identity) InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchType(org.jboss.as.patching.metadata.Patch.PatchType) Patch(org.jboss.as.patching.metadata.Patch) RollbackPatch(org.jboss.as.patching.metadata.RollbackPatch) PatchEntry(org.jboss.as.patching.runner.IdentityPatchContext.PatchEntry)

Example 5 with Identity

use of org.jboss.as.patching.metadata.Identity 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)

Aggregations

Identity (org.jboss.as.patching.metadata.Identity)11 PatchElement (org.jboss.as.patching.metadata.PatchElement)10 Patch (org.jboss.as.patching.metadata.Patch)9 PatchElementProvider (org.jboss.as.patching.metadata.PatchElementProvider)7 ContentModification (org.jboss.as.patching.metadata.ContentModification)5 IdentityUpgrade (org.jboss.as.patching.metadata.Identity.IdentityUpgrade)5 Test (org.junit.Test)5 InstalledIdentity (org.jboss.as.patching.installation.InstalledIdentity)4 ContentItem (org.jboss.as.patching.metadata.ContentItem)4 IOException (java.io.IOException)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 PatchingException (org.jboss.as.patching.PatchingException)3 RollbackPatch (org.jboss.as.patching.metadata.RollbackPatch)3 SimpleTable (org.jboss.as.cli.util.SimpleTable)2 PatchType (org.jboss.as.patching.metadata.Patch.PatchType)2 PatchEntry (org.jboss.as.patching.runner.IdentityPatchContext.PatchEntry)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 InstallationManager (org.jboss.as.patching.installation.InstallationManager)1