use of org.jboss.as.patching.installation.InstalledIdentity 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);
}
}
use of org.jboss.as.patching.installation.InstalledIdentity in project wildfly-core by wildfly.
the class PatchToolImpl method applyPatchBundle.
protected PatchingResult applyPatchBundle(final File workDir, final BundledPatch bundledPatch, final ContentVerificationPolicy contentPolicy) throws PatchingException, IOException {
final List<BundledPatchEntry> patches = bundledPatch.getPatches();
if (patches.isEmpty()) {
throw new PatchingException(PatchLogger.ROOT_LOGGER.patchBundleIsEmpty());
}
PatchingResult result = null;
BundledPatchEntry lastCommittedEntry = null;
final List<BundledPatch.BundledPatchEntry> results = new ArrayList<BundledPatch.BundledPatchEntry>(patches.size());
final List<InstalledIdentity> installedIdentities = manager.getInstalledIdentities();
for (BundledPatchEntry entry : patches) {
// TODO this has to be checked against the specific one targeted by the patch
boolean alreadyApplied = false;
for (InstalledIdentity identity : installedIdentities) {
if (identity.getAllInstalledPatches().contains(entry.getPatchId())) {
alreadyApplied = true;
break;
}
}
if (alreadyApplied) {
continue;
}
if (result != null) {
result.commit();
results.add(0, lastCommittedEntry);
}
final File patch = new File(workDir, entry.getPatchPath());
final FileInputStream is = new FileInputStream(patch);
PatchingResult currentResult = null;
try {
currentResult = applyPatch(workDir, is, contentPolicy);
} catch (PatchingException e) {
// Undo the changes included as part of this patch
for (BundledPatch.BundledPatchEntry committed : results) {
try {
rollback(committed.getPatchId(), contentPolicy, false, false).commit();
} catch (PatchingException oe) {
PatchLogger.ROOT_LOGGER.debugf(oe, "failed to rollback patch '%s'", committed.getPatchId());
}
}
throw e;
} finally {
safeClose(is);
}
if (currentResult != null) {
result = currentResult;
lastCommittedEntry = entry;
}
}
if (result == null) {
throw new PatchingException();
}
return new WrappedMultiInstallPatch(result, contentPolicy, results);
}
use of org.jboss.as.patching.installation.InstalledIdentity in project wildfly-core by wildfly.
the class RollbackPatchXml_1_0 method handleRootElement.
@Override
protected void handleRootElement(String localName, XMLExtendedStreamReader reader, PatchBuilder patch, InstalledIdentity originalIdentity) throws XMLStreamException {
final RollbackPatchBuilder builder = (RollbackPatchBuilder) patch;
final Element element = Element.forName(localName);
if (element == Element.INSTALLATION) {
final InstalledIdentity identity = processInstallation(reader, originalIdentity);
builder.setIdentity(identity);
} else {
throw unexpectedElement(reader);
}
}
use of org.jboss.as.patching.installation.InstalledIdentity in project wildfly-core by wildfly.
the class PatchAttributeReadHandler method execute.
@Override
protected void execute(final OperationContext context, final ModelNode operation, final InstalledIdentity installedIdentity) throws OperationFailedException {
final ModelNode result = context.getResult();
final Identity info = installedIdentity.getIdentity();
try {
handle(result, info);
} catch (IOException e) {
throw new OperationFailedException(PatchLogger.ROOT_LOGGER.failedToLoadInfo(info.getName()), e);
}
context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
use of org.jboss.as.patching.installation.InstalledIdentity in project wildfly-core by wildfly.
the class PatchStreamResourceOperationStepHandler method execute.
protected void execute(OperationContext context, ModelNode operation, InstallationManager instMgr, String patchStream) throws OperationFailedException {
final InstalledIdentity installedIdentity;
if (patchStream != null) {
try {
installedIdentity = instMgr.getInstalledIdentity(patchStream, null);
} catch (PatchingException e) {
throw new OperationFailedException(PatchLogger.ROOT_LOGGER.failedToLoadInfo(patchStream), e);
}
} else {
installedIdentity = instMgr.getDefaultIdentity();
}
execute(context, operation, installedIdentity);
}
Aggregations