Search in sources :

Example 1 with PatchElementProvider

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

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

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

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

the class PatchStepAssertions method assertApplied.

static void assertApplied(final Patch patch, InstallationManager manager) throws IOException {
    final String patchID = patch.getPatchId();
    InstalledIdentity installedIdentity = null;
    try {
        installedIdentity = manager.getInstalledIdentity(patch.getIdentity().getName(), null);
    } catch (PatchingException e) {
        Assert.fail(e.getLocalizedMessage());
    }
    final PatchableTarget target = installedIdentity.getIdentity();
    final PatchableTarget.TargetInfo identity = target.loadTargetInfo();
    assertIsApplied(patch.getIdentity().getPatchType(), patchID, identity);
    assertExists(identity.getDirectoryStructure().getInstalledImage().getPatchHistoryDir(patchID));
    assertContentItems(patchID, target, patch.getModifications());
    for (final PatchElement element : patch.getElements()) {
        final PatchElementProvider provider = element.getProvider();
        final PatchableTarget targetElement = provider.isAddOn() ? installedIdentity.getAddOn(provider.getName()) : installedIdentity.getLayer(provider.getName());
        assertIsApplied(provider.getPatchType(), element.getId(), targetElement.loadTargetInfo());
        assertContentItems(element.getId(), targetElement, element.getModifications());
    }
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchableTarget(org.jboss.as.patching.installation.PatchableTarget) PatchingException(org.jboss.as.patching.PatchingException) PatchElementProvider(org.jboss.as.patching.metadata.PatchElementProvider) PatchElement(org.jboss.as.patching.metadata.PatchElement)

Example 5 with PatchElementProvider

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

Aggregations

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