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());
}
}
}
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());
}
}
}
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());
}
}
}
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();
}
}
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);
}
Aggregations