use of org.jboss.as.patching.metadata.PatchElementProvider in project wildfly-core by wildfly.
the class IdentityPatchRunner method portForward.
/**
* Port forward missing module changes for each layer.
*
* @param patch the current patch
* @param context the patch context
* @throws PatchingException
* @throws IOException
* @throws XMLStreamException
*/
void portForward(final Patch patch, IdentityPatchContext context) throws PatchingException, IOException, XMLStreamException {
assert patch.getIdentity().getPatchType() == Patch.PatchType.CUMULATIVE;
final PatchingHistory history = context.getHistory();
for (final PatchElement element : patch.getElements()) {
final PatchElementProvider provider = element.getProvider();
final String name = provider.getName();
final boolean addOn = provider.isAddOn();
final IdentityPatchContext.PatchEntry target = context.resolveForElement(element);
final String cumulativePatchID = target.getCumulativePatchID();
if (Constants.BASE.equals(cumulativePatchID)) {
reenableRolledBackInBase(target);
continue;
}
boolean found = false;
final PatchingHistory.Iterator iterator = history.iterator();
while (iterator.hasNextCP()) {
final PatchingHistory.Entry entry = iterator.nextCP();
final String patchId = addOn ? entry.getAddOnPatches().get(name) : entry.getLayerPatches().get(name);
if (patchId != null && patchId.equals(cumulativePatchID)) {
final Patch original = loadPatchInformation(entry.getPatchId(), installedImage);
for (final PatchElement originalElement : original.getElements()) {
if (name.equals(originalElement.getProvider().getName()) && addOn == originalElement.getProvider().isAddOn()) {
PatchingTasks.addMissingModifications(target, originalElement.getModifications(), ContentItemFilter.ALL_BUT_MISC);
}
}
// Record a loader to have access to the current modules
final DirectoryStructure structure = target.getDirectoryStructure();
final File modulesRoot = structure.getModulePatchDirectory(patchId);
final File bundlesRoot = structure.getBundlesPatchDirectory(patchId);
final PatchContentLoader loader = PatchContentLoader.create(null, bundlesRoot, modulesRoot);
context.recordContentLoader(patchId, loader);
found = true;
break;
}
}
if (!found) {
throw PatchLogger.ROOT_LOGGER.patchNotFoundInHistory(cumulativePatchID);
}
reenableRolledBackInBase(target);
}
}
use of org.jboss.as.patching.metadata.PatchElementProvider in project wildfly-core by wildfly.
the class IdentityPatchContext method resolveForElement.
/**
* Get the target entry for a given patch element.
*
* @param element the patch element
* @return the patch entry
* @throws PatchingException
*/
protected PatchEntry resolveForElement(final PatchElement element) throws PatchingException {
assert state == State.NEW;
final PatchElementProvider provider = element.getProvider();
final String layerName = provider.getName();
final LayerType layerType = provider.getLayerType();
final Map<String, PatchEntry> map;
if (layerType == LayerType.Layer) {
map = layers;
} else {
map = addOns;
}
PatchEntry entry = map.get(layerName);
if (entry == null) {
final InstallationManager.MutablePatchingTarget target = modification.resolve(layerName, layerType);
if (target == null) {
throw PatchLogger.ROOT_LOGGER.noSuchLayer(layerName);
}
entry = new PatchEntry(target, element);
map.put(layerName, entry);
}
// Maintain the most recent element
entry.updateElement(element);
return entry;
}
use of org.jboss.as.patching.metadata.PatchElementProvider in project wildfly-core by wildfly.
the class IdentityPatchRunner method rollback.
/**
* Rollback a patch.
*
* @param patchID the patch id
* @param context the patch context
* @throws PatchingException
*/
private void rollback(final String patchID, final IdentityPatchContext context) throws PatchingException {
try {
// Load the patch history
final PatchingTaskContext.Mode mode = context.getMode();
final Patch originalPatch = loadPatchInformation(patchID, installedImage);
final RollbackPatch rollbackPatch = loadRollbackInformation(patchID, installedImage);
final Patch.PatchType patchType = rollbackPatch.getIdentity().getPatchType();
final InstalledIdentity history = rollbackPatch.getIdentityState();
// Process originals by type first
final LinkedHashMap<String, PatchElement> originalLayers = new LinkedHashMap<String, PatchElement>();
final LinkedHashMap<String, PatchElement> originalAddOns = new LinkedHashMap<String, PatchElement>();
for (final PatchElement patchElement : originalPatch.getElements()) {
final PatchElementProvider provider = patchElement.getProvider();
final String layerName = provider.getName();
final LayerType layerType = provider.getLayerType();
final Map<String, PatchElement> originals;
switch(layerType) {
case Layer:
originals = originalLayers;
break;
case AddOn:
originals = originalAddOns;
break;
default:
throw new IllegalStateException();
}
if (!originals.containsKey(layerName)) {
originals.put(layerName, patchElement);
} else {
throw PatchLogger.ROOT_LOGGER.installationDuplicateLayer(layerType.toString(), layerName);
}
}
// Process the rollback xml
for (final PatchElement patchElement : rollbackPatch.getElements()) {
final String elementPatchId = patchElement.getId();
final PatchElementProvider provider = patchElement.getProvider();
final String layerName = provider.getName();
final LayerType layerType = provider.getLayerType();
final LinkedHashMap<String, PatchElement> originals;
switch(layerType) {
case Layer:
originals = originalLayers;
break;
case AddOn:
originals = originalAddOns;
break;
default:
throw new IllegalStateException();
}
final PatchElement original = originals.remove(layerName);
if (original == null) {
throw PatchLogger.ROOT_LOGGER.noSuchLayer(layerName);
}
final IdentityPatchContext.PatchEntry entry = context.resolveForElement(patchElement);
// Create the rollback
PatchingTasks.rollback(elementPatchId, original.getModifications(), patchElement.getModifications(), entry, ContentItemFilter.ALL_BUT_MISC, mode);
entry.rollback(original.getId());
// We need to restore the previous state
final Patch.PatchType elementPatchType = provider.getPatchType();
final PatchableTarget.TargetInfo info;
if (layerType == LayerType.AddOn) {
info = history.getAddOn(layerName).loadTargetInfo();
} else {
info = history.getLayer(layerName).loadTargetInfo();
}
if (mode == ROLLBACK) {
restoreFromHistory(entry, elementPatchId, elementPatchType, info);
}
}
if (!originalLayers.isEmpty() || !originalAddOns.isEmpty()) {
throw PatchLogger.ROOT_LOGGER.invalidRollbackInformation();
}
// Rollback the patch
final IdentityPatchContext.PatchEntry identity = context.getIdentityEntry();
PatchingTasks.rollback(patchID, originalPatch.getModifications(), rollbackPatch.getModifications(), identity, ContentItemFilter.MISC_ONLY, mode);
identity.rollback(patchID);
// Restore previous state
if (mode == ROLLBACK) {
final PatchableTarget.TargetInfo identityHistory = history.getIdentity().loadTargetInfo();
restoreFromHistory(identity, rollbackPatch.getPatchId(), patchType, identityHistory);
if (patchType == Patch.PatchType.CUMULATIVE) {
reenableNotOverridenModules(rollbackPatch, context);
}
}
if (patchType == Patch.PatchType.CUMULATIVE) {
final Identity.IdentityUpgrade upgrade = rollbackPatch.getIdentity().forType(Patch.PatchType.CUMULATIVE, Identity.IdentityUpgrade.class);
identity.setResultingVersion(upgrade.getResultingVersion());
}
} catch (Exception e) {
throw rethrowException(e);
}
}
use of org.jboss.as.patching.metadata.PatchElementProvider in project wildfly-core by wildfly.
the class PatchableTargetsArtifact method process.
@Override
public boolean process(PatchingXmlArtifact.XmlArtifactState<Patch> parent, PatchingArtifactProcessor processor) {
final InstalledIdentity identity = processor.getValidationContext().getInstalledIdentity();
final Patch patch = parent.getPatch();
if (Constants.BASE.equals(patch.getPatchId())) {
return true;
}
final List<PatchElement> elements = patch.getElements();
boolean valid = true;
if (elements != null && !elements.isEmpty()) {
for (final PatchElement element : elements) {
final String patchID = element.getId();
final PatchElementProvider provider = element.getProvider();
final String layerName = provider.getName();
final PatchableTarget target = provider.isAddOn() ? identity.getAddOn(layerName) : identity.getLayer(layerName);
boolean modules = false;
boolean bundles = false;
for (final ContentModification modification : element.getModifications()) {
if (modules && bundles) {
break;
}
if (modification.getItem().getContentType() == ContentType.BUNDLE) {
bundles = true;
} else if (modification.getItem().getContentType() == ContentType.MODULE) {
modules = true;
}
}
final PatchableTargetState state = new PatchableTargetState(patchID, layerName, target, bundles, modules);
if (!processor.process(PatchingArtifacts.LAYER, state)) {
valid = false;
}
}
}
// In case there are misc content modifications also validate that misc backup exists
for (final ContentModification modification : patch.getModifications()) {
if (modification.getType() != ModificationType.ADD && modification.getItem().getContentType() == ContentType.MISC) {
final PatchingHistoryDirArtifact.DirectoryArtifactState history = processor.getParentArtifact(PatchingArtifacts.HISTORY_DIR);
PatchingArtifacts.MISC_BACKUP.process(history, processor);
break;
}
}
return valid;
}
use of org.jboss.as.patching.metadata.PatchElementProvider in project wildfly-core by wildfly.
the class PatchStepAssertions method assertNotApplied.
static void assertNotApplied(final Patch patch, InstallationManager manager) throws IOException {
InstalledIdentity installedIdentity = null;
try {
installedIdentity = manager.getInstalledIdentity(patch.getIdentity().getName(), patch.getIdentity().getVersion());
} catch (PatchingException e) {
Assert.fail(e.getLocalizedMessage());
}
final PatchableTarget.TargetInfo identity = installedIdentity.getIdentity().loadTargetInfo();
assertNotApplied(patch.getIdentity().getPatchType(), patch.getPatchId(), identity);
assertDoesNotExists(identity.getDirectoryStructure().getInstalledImage().getPatchHistoryDir(patch.getPatchId()));
for (final PatchElement element : patch.getElements()) {
final PatchElementProvider provider = element.getProvider();
final PatchableTarget target = provider.isAddOn() ? installedIdentity.getAddOn(provider.getName()) : installedIdentity.getLayer(provider.getName());
Assert.assertNotNull(target);
assertNotApplied(provider.getPatchType(), element.getId(), target.loadTargetInfo());
}
}
Aggregations