use of org.jboss.as.patching.PatchingException in project wildfly-core by wildfly.
the class AbstractPatchingTest method writePatch.
protected static void writePatch(final File patchRoot, final Patch patch) throws PatchingException {
FileOutputStream os = null;
try {
os = new FileOutputStream(new File(patchRoot, PatchXml.PATCH_XML));
PatchXml.marshal(os, patch);
} catch (Exception e) {
throw new PatchingException(e);
} finally {
IoUtils.safeClose(os);
}
}
use of org.jboss.as.patching.PatchingException in project wildfly-core by wildfly.
the class AbstractPatchingTest method apply.
protected PatchingResult apply(final PatchingTestStepBuilder builder, final ContentVerificationPolicy verificationPolicy, final PatchStepAssertions assertions) throws PatchingException {
final Patch patch = builder.build();
final File installation = new File(tempDir, JBOSS_INSTALLATION);
try {
assertions.before(installation, patch, installationManager);
} catch (IOException e) {
throw new PatchingException(e);
}
// Write patch
writePatch(builder.getPatchDir(), patch);
// Create the patch tool and apply the patch
final PatchTool patchTool = PatchTool.Factory.create(installationManager);
final PatchingResult result = patchTool.applyPatch(builder.getPatchDir(), verificationPolicy);
result.commit();
final InstalledIdentity identity = ((InstallationManagerImpl) installationManager).getInstalledIdentity(patch.getIdentity().getName(), null);
Assert.assertTrue(identity.getAllInstalledPatches().contains(patch.getPatchId()));
try {
assertions.after(installation, patch, installationManager);
} catch (IOException e) {
throw new PatchingException(e);
}
return result;
}
use of org.jboss.as.patching.PatchingException in project wildfly-core by wildfly.
the class AbstractPatchingTest method rollback.
protected PatchingResult rollback(final PatchingTestStepBuilder builder, final ContentVerificationPolicy verificationPolicy, final PatchStepAssertions assertions, boolean rollbackTo) throws PatchingException {
final Patch patch = builder.build();
final File installation = new File(tempDir, JBOSS_INSTALLATION);
try {
assertions.before(installation, patch, installationManager);
} catch (IOException e) {
throw new PatchingException(e);
}
final String patchId = patch.getPatchId();
final PatchTool patchTool = PatchTool.Factory.create(installationManager);
final PatchingResult result = patchTool.rollback(patchId, verificationPolicy, rollbackTo, false);
result.commit();
final InstalledIdentity identity = installationManager.getInstalledIdentity(patch.getIdentity().getName(), null);
Assert.assertFalse(identity.getAllInstalledPatches().contains(patch.getPatchId()));
try {
assertions.after(installation, patch, installationManager);
} catch (IOException e) {
throw new PatchingException(e);
}
return result;
}
use of org.jboss.as.patching.PatchingException 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.PatchingException in project wildfly-core by wildfly.
the class PatchToolImpl method rollback.
@Override
public PatchingResult rollback(final String streamName, final String patchId, final ContentVerificationPolicy contentPolicy, final boolean rollbackTo, final boolean resetConfiguration) throws PatchingException {
InstalledIdentity targetIdentity = null;
if (streamName == null) {
for (InstalledIdentity identity : manager.getInstalledIdentities()) {
if (identity.getAllInstalledPatches().contains(patchId)) {
if (targetIdentity != null) {
throw new PatchingException(PatchLogger.ROOT_LOGGER.patchIdFoundInMoreThanOneStream(patchId, targetIdentity.getIdentity().getName(), identity.getIdentity().getName()));
}
targetIdentity = identity;
}
}
if (targetIdentity == null) {
throw PatchLogger.ROOT_LOGGER.patchNotFoundInHistory(patchId);
}
} else {
targetIdentity = manager.getInstalledIdentity(streamName, null);
}
// Rollback the patch
final InstallationManager.InstallationModification modification = targetIdentity.modifyInstallation(runner);
try {
return runner.rollbackPatch(patchId, contentPolicy, rollbackTo, resetConfiguration, modification);
} catch (Exception e) {
modification.cancel();
throw rethrowException(e);
}
}
Aggregations