use of org.jboss.as.patching.installation.InstalledIdentity 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.installation.InstalledIdentity in project wildfly-core by wildfly.
the class PatchToolImpl method execute.
protected PatchingResult execute(final File workDir, final ContentVerificationPolicy contentPolicy) throws PatchingException, IOException, XMLStreamException {
final File patchBundleXml = new File(workDir, PatchBundleXml.MULTI_PATCH_XML);
if (patchBundleXml.exists()) {
final InputStream patchIs = new FileInputStream(patchBundleXml);
try {
// Handle multi patch installs
final BundledPatch bundledPatch = PatchBundleXml.parse(patchIs);
return applyPatchBundle(workDir, bundledPatch, contentPolicy);
} finally {
safeClose(patchIs);
}
} else {
// Parse the xml
File patchXml = new File(workDir, PatchXml.PATCH_XML);
PatchMetadataResolver patchResolver = parsePatchXml(patchXml);
Patch patch = patchResolver.resolvePatch(null, null);
final InstalledIdentity installedIdentity = manager.getInstalledIdentity(patch.getIdentity().getName(), null);
final String currentVersion = installedIdentity.getIdentity().getVersion();
if (!Constants.UNKNOWN.equals(currentVersion) && !patch.getIdentity().getVersion().equals(currentVersion)) {
patchXml = new File(workDir, currentVersion + PatchMerger.PATCH_XML_SUFFIX);
if (!patchXml.exists()) {
throw new PatchingException("The patch does not contain metadata for currently installed " + patch.getIdentity().getName() + " version " + currentVersion);
}
patchResolver = parsePatchXml(patchXml);
patch = patchResolver.resolvePatch(null, null);
}
return apply(patchResolver, PatchContentProvider.DefaultContentProvider.create(workDir), contentPolicy);
}
}
use of org.jboss.as.patching.installation.InstalledIdentity in project wildfly-core by wildfly.
the class PatchToolImpl method rollbackLast.
@Override
public PatchingResult rollbackLast(final String streamName, final ContentVerificationPolicy contentPolicy, final boolean resetConfiguration) throws PatchingException {
final InstalledIdentity targetIdentity = streamName == null ? manager.getDefaultIdentity() : manager.getInstalledIdentity(streamName, null);
final InstallationManager.InstallationModification modification = targetIdentity.modifyInstallation(runner);
try {
return runner.rollbackLast(contentPolicy, resetConfiguration, modification);
} catch (Exception e) {
modification.cancel();
throw rethrowException(e);
}
}
use of org.jboss.as.patching.installation.InstalledIdentity in project wildfly-core by wildfly.
the class PatchToolImpl method getPatchInfo.
@Override
public PatchInfo getPatchInfo(String streamName) throws PatchingException {
try {
final InstalledIdentity installedIdentity = streamName == null ? manager.getDefaultIdentity() : manager.getInstalledIdentity(streamName, null);
final PatchableTarget.TargetInfo info = installedIdentity.getIdentity().loadTargetInfo();
final VerbosePatchInfo.Builder infoBuilder = VerbosePatchInfo.builder().setVersion(installedIdentity.getIdentity().getVersion()).setCumulativePatchId(info.getCumulativePatchID()).setPatchIds(info.getPatchIDs());
for (Layer layer : installedIdentity.getLayers()) {
infoBuilder.addLayerInfo(layer.getName(), layer.loadTargetInfo());
}
for (AddOn addon : installedIdentity.getAddOns()) {
infoBuilder.addAddOnInfo(addon.getName(), addon.loadTargetInfo());
}
return infoBuilder.build();
} catch (IOException e) {
// why throw a rethrowException(e) ?
throw new RuntimeException(e);
}
}
use of org.jboss.as.patching.installation.InstalledIdentity in project wildfly-core by wildfly.
the class PatchToolImpl method getPatchStreams.
@Override
public List<String> getPatchStreams() throws PatchingException {
final List<InstalledIdentity> installedIdentities = manager.getInstalledIdentities();
if (installedIdentities.size() == 1) {
return Collections.singletonList(installedIdentities.get(0).getIdentity().getName());
}
final List<String> result = new ArrayList<String>(installedIdentities.size());
for (InstalledIdentity ii : installedIdentities) {
result.add(ii.getIdentity().getName());
}
return result;
}
Aggregations