Search in sources :

Example 26 with PatchingException

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);
    }
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchingException(org.jboss.as.patching.PatchingException) PatchMetadataResolver(org.jboss.as.patching.metadata.PatchMetadataResolver) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BundledPatch(org.jboss.as.patching.metadata.BundledPatch) File(java.io.File) Patch(org.jboss.as.patching.metadata.Patch) BundledPatch(org.jboss.as.patching.metadata.BundledPatch) FileInputStream(java.io.FileInputStream)

Example 27 with PatchingException

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);
    }
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) InstallationManager(org.jboss.as.patching.installation.InstallationManager) XMLStreamException(javax.xml.stream.XMLStreamException) PatchingException(org.jboss.as.patching.PatchingException) IOException(java.io.IOException)

Example 28 with PatchingException

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) {
            }
        }
    }
}
Also used : PatchingException(org.jboss.as.patching.PatchingException) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) CommandLineException(org.jboss.as.cli.CommandLineException) BundledPatchEntry(org.jboss.as.patching.metadata.BundledPatch.BundledPatchEntry) ZipFile(java.util.zip.ZipFile) XMLStreamException(javax.xml.stream.XMLStreamException) ParsedCommandLine(org.jboss.as.cli.operation.ParsedCommandLine) ZipFile(java.util.zip.ZipFile) File(java.io.File) Patch(org.jboss.as.patching.metadata.Patch)

Example 29 with PatchingException

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) {
            }
        }
    }
}
Also used : PatchingException(org.jboss.as.patching.PatchingException) ZipFile(java.util.zip.ZipFile) XMLStreamException(javax.xml.stream.XMLStreamException) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) ZipException(java.util.zip.ZipException) CommandException(org.aesh.command.CommandException) IOException(java.io.IOException) Patch(org.jboss.as.patching.metadata.Patch) BundledPatch(org.jboss.as.patching.metadata.BundledPatch)

Example 30 with PatchingException

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 {
    // 
    }
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) PatchingException(org.jboss.as.patching.PatchingException) PatchingResult(org.jboss.as.patching.tool.PatchingResult) PatchTool(org.jboss.as.patching.tool.PatchTool) ContentVerificationPolicy(org.jboss.as.patching.tool.ContentVerificationPolicy) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

PatchingException (org.jboss.as.patching.PatchingException)39 File (java.io.File)20 IOException (java.io.IOException)19 InstalledIdentity (org.jboss.as.patching.installation.InstalledIdentity)17 XMLStreamException (javax.xml.stream.XMLStreamException)9 Patch (org.jboss.as.patching.metadata.Patch)9 PatchTool (org.jboss.as.patching.tool.PatchTool)8 PatchingResult (org.jboss.as.patching.tool.PatchingResult)8 InstallationManager (org.jboss.as.patching.installation.InstallationManager)7 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 PatchableTarget (org.jboss.as.patching.installation.PatchableTarget)5 InputStream (java.io.InputStream)4 BundledPatch (org.jboss.as.patching.metadata.BundledPatch)4 PatchElement (org.jboss.as.patching.metadata.PatchElement)4 PatchElementProvider (org.jboss.as.patching.metadata.PatchElementProvider)4 ModelNode (org.jboss.dmr.ModelNode)4 OperationContext (org.jboss.as.controller.OperationContext)3 ContentModification (org.jboss.as.patching.metadata.ContentModification)3 Identity (org.jboss.as.patching.metadata.Identity)3