Search in sources :

Example 1 with ContentItem

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

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

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

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

the class PatchStepAssertions method assertContentModification.

static void assertContentModification(final String patchID, final PatchableTarget target, final ContentModification modification) {
    final ContentItem item = modification.getItem();
    final ContentType contentType = item.getContentType();
    switch(contentType) {
        case MODULE:
            assertModule(patchID, target, (ModuleItem) item);
            break;
        case BUNDLE:
            break;
        case MISC:
            final File home = target.getDirectoryStructure().getInstalledImage().getJbossHome();
            final ModificationCondition condition = modification.getCondition();
            if (condition != null) {
                if (condition instanceof ModificationCondition.ExistsCondition) {
                    final ContentItem requiredItem = ((ModificationCondition.ExistsCondition) condition).getContentItem();
                    File requiredFile;
                    switch(requiredItem.getContentType()) {
                        case MISC:
                            requiredFile = PatchContentLoader.getMiscPath(home, (MiscContentItem) requiredItem);
                            break;
                        case MODULE:
                        case BUNDLE:
                        default:
                            throw new IllegalStateException("Unsupported content type");
                    }
                    if (!requiredFile.exists()) {
                        final File file = PatchContentLoader.getMiscPath(home, (MiscContentItem) item);
                        Assert.assertFalse(file.exists());
                        return;
                    }
                }
            }
            assertMisc(home, modification.getType(), (MiscContentItem) item);
            break;
        default:
            Assert.fail();
    }
}
Also used : ContentType(org.jboss.as.patching.metadata.ContentType) ModificationCondition(org.jboss.as.patching.metadata.ModificationCondition) MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem) File(java.io.File) MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem) ContentItem(org.jboss.as.patching.metadata.ContentItem)

Example 5 with ContentItem

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

the class IdentityPatchRunner method executeTasks.

/**
 * Execute all recorded tasks.
 *
 * @param context  the patch context
 * @param callback the finalization callback
 * @throws Exception
 */
static PatchingResult executeTasks(final IdentityPatchContext context, final IdentityPatchContext.FinalizeCallback callback) throws Exception {
    final List<PreparedTask> tasks = new ArrayList<PreparedTask>();
    final List<ContentItem> conflicts = new ArrayList<ContentItem>();
    // Identity
    prepareTasks(context.getIdentityEntry(), context, tasks, conflicts);
    // Layers
    for (final IdentityPatchContext.PatchEntry layer : context.getLayers()) {
        prepareTasks(layer, context, tasks, conflicts);
    }
    // AddOns
    for (final IdentityPatchContext.PatchEntry addOn : context.getAddOns()) {
        prepareTasks(addOn, context, tasks, conflicts);
    }
    // If there were problems report them
    if (!conflicts.isEmpty()) {
        throw PatchLogger.ROOT_LOGGER.conflictsDetected(conflicts);
    }
    // Execute the tasks
    for (final PreparedTask task : tasks) {
        // Unless it's excluded by the user
        final ContentItem item = task.getContentItem();
        if (item != null && context.isExcluded(item)) {
            continue;
        }
        // Run the task
        task.execute();
    }
    return context.finalize(callback);
}
Also used : ArrayList(java.util.ArrayList) ContentItem(org.jboss.as.patching.metadata.ContentItem) PatchEntry(org.jboss.as.patching.runner.IdentityPatchContext.PatchEntry)

Aggregations

ContentItem (org.jboss.as.patching.metadata.ContentItem)16 ContentModification (org.jboss.as.patching.metadata.ContentModification)12 MiscContentItem (org.jboss.as.patching.metadata.MiscContentItem)5 Patch (org.jboss.as.patching.metadata.Patch)5 Test (org.junit.Test)5 Identity (org.jboss.as.patching.metadata.Identity)4 IdentityUpgrade (org.jboss.as.patching.metadata.Identity.IdentityUpgrade)4 PatchElement (org.jboss.as.patching.metadata.PatchElement)4 PatchElementProvider (org.jboss.as.patching.metadata.PatchElementProvider)4 ContentType (org.jboss.as.patching.metadata.ContentType)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 ModificationCondition (org.jboss.as.patching.metadata.ModificationCondition)2 TestUtils.randomString (org.jboss.as.patching.runner.TestUtils.randomString)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 ContentConflictsException (org.jboss.as.patching.ContentConflictsException)1 PatchingException (org.jboss.as.patching.PatchingException)1 PatchEntry (org.jboss.as.patching.runner.IdentityPatchContext.PatchEntry)1