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