use of org.jboss.as.patching.PatchingException 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.PatchingException 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.PatchingException in project wildfly-core by wildfly.
the class PatchHandler method doInspect.
protected void doInspect(CommandContext ctx) throws CommandLineException {
final ParsedCommandLine parsedLine = ctx.getParsedCommandLine();
final String patchPath = path.getValue(parsedLine, true);
final File patchFile = new File(patchPath);
if (!patchFile.exists()) {
throw new CommandLineException("Failed to locate " + patchFile.getAbsolutePath());
}
ZipFile patchZip = null;
InputStream is = null;
try {
patchZip = new ZipFile(patchFile);
ZipEntry patchXmlEntry = patchZip.getEntry(PatchBundleXml.MULTI_PATCH_XML);
if (patchXmlEntry == null) {
patchXmlEntry = patchZip.getEntry(PatchXml.PATCH_XML);
if (patchXmlEntry == null) {
throw new CommandLineException("Neither " + PatchBundleXml.MULTI_PATCH_XML + " nor " + PatchXml.PATCH_XML + " were found in " + patchFile.getAbsolutePath());
}
is = patchZip.getInputStream(patchXmlEntry);
final Patch patch = PatchXml.parse(is).resolvePatch(null, null);
displayPatchXml(ctx, patch);
} else {
is = patchZip.getInputStream(patchXmlEntry);
final List<BundledPatchEntry> patches = PatchBundleXml.parse(is).getPatches();
displayPatchBundleXml(ctx, patches, patchZip);
}
} catch (ZipException e) {
throw new CommandLineException("Failed to open " + patchFile.getAbsolutePath(), e);
} catch (IOException e) {
throw new CommandLineException("Failed to open " + patchFile.getAbsolutePath(), e);
} catch (PatchingException e) {
throw new CommandLineException("Failed to resolve parsed patch", e);
} catch (XMLStreamException e) {
throw new CommandLineException("Failed to parse patch.xml", e);
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
}
}
if (patchZip != null) {
try {
patchZip.close();
} catch (IOException e) {
}
}
}
}
use of org.jboss.as.patching.PatchingException in project wildfly-core by wildfly.
the class PatchInspect method doInspect.
private void doInspect(CommandContext ctx) throws CommandException {
if (patchFile == null) {
throw new CommandException("No patch path provided");
}
if (!patchFile.exists()) {
throw new CommandException("Failed to locate " + patchFile.getAbsolutePath());
}
ZipFile patchZip = null;
InputStream is = null;
try {
patchZip = new ZipFile(patchFile);
ZipEntry patchXmlEntry = patchZip.getEntry(PatchBundleXml.MULTI_PATCH_XML);
if (patchXmlEntry == null) {
patchXmlEntry = patchZip.getEntry(PatchXml.PATCH_XML);
if (patchXmlEntry == null) {
throw new CommandException("Neither " + PatchBundleXml.MULTI_PATCH_XML + " nor " + PatchXml.PATCH_XML + " were found in " + patchFile.getAbsolutePath());
}
is = patchZip.getInputStream(patchXmlEntry);
final Patch patch = PatchXml.parse(is).resolvePatch(null, null);
displayPatchXml(ctx, patch);
} else {
is = patchZip.getInputStream(patchXmlEntry);
final List<BundledPatch.BundledPatchEntry> patches = PatchBundleXml.parse(is).getPatches();
displayPatchBundleXml(ctx, patches, patchZip);
}
} catch (ZipException e) {
throw new CommandException("Failed to open " + patchFile.getAbsolutePath(), e);
} catch (IOException e) {
throw new CommandException("Failed to open " + patchFile.getAbsolutePath(), e);
} catch (PatchingException e) {
throw new CommandException("Failed to resolve parsed patch", e);
} catch (XMLStreamException e) {
throw new CommandException("Failed to parse patch.xml", e);
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
}
}
if (patchZip != null) {
try {
patchZip.close();
} catch (IOException e) {
}
}
}
}
use of org.jboss.as.patching.PatchingException in project wildfly-core by wildfly.
the class LocalPatchRollbackHandler method execute.
@Override
protected void execute(final OperationContext context, final ModelNode operation, final InstallationManager installationManager, final String patchStream) throws OperationFailedException {
if (installationManager.requiresRestart()) {
throw PatchLogger.ROOT_LOGGER.serverRequiresRestart();
}
final String patchId = PatchResourceDefinition.PATCH_ID.resolveModelAttribute(context, operation).asString();
final boolean rollbackTo = PatchResourceDefinition.ROLLBACK_TO.resolveModelAttribute(context, operation).asBoolean();
final boolean restoreConfiguration = PatchResourceDefinition.RESET_CONFIGURATION.resolveModelAttribute(context, operation).asBoolean();
final PatchTool runner = PatchTool.Factory.create(installationManager);
final ContentVerificationPolicy policy = PatchTool.Factory.create(operation);
try {
// Rollback
final PatchingResult result = runner.rollback(patchStream, patchId, policy, rollbackTo, restoreConfiguration);
installationManager.restartRequired();
context.restartRequired();
context.completeStep(new OperationContext.ResultHandler() {
@Override
public void handleResult(OperationContext.ResultAction resultAction, OperationContext context, ModelNode operation) {
if (resultAction == OperationContext.ResultAction.KEEP) {
result.commit();
} else {
installationManager.clearRestartRequired();
context.revertRestartRequired();
result.rollback();
}
}
});
} catch (PatchingException e) {
final ModelNode failureDescription = context.getFailureDescription();
PatchOperationTarget.formatFailedResponse(e, failureDescription);
installationManager.clearRestartRequired();
} finally {
//
}
}
Aggregations