Search in sources :

Example 1 with BundledPatchEntry

use of org.jboss.as.patching.metadata.BundledPatch.BundledPatchEntry 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);
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchingException(org.jboss.as.patching.PatchingException) ArrayList(java.util.ArrayList) BundledPatch(org.jboss.as.patching.metadata.BundledPatch) FileInputStream(java.io.FileInputStream) BundledPatchEntry(org.jboss.as.patching.metadata.BundledPatch.BundledPatchEntry) PatchingResult(org.jboss.as.patching.tool.PatchingResult) File(java.io.File)

Example 2 with BundledPatchEntry

use of org.jboss.as.patching.metadata.BundledPatch.BundledPatchEntry in project wildfly-core by wildfly.

the class PatchHandler method displayPatchBundleXml.

private void displayPatchBundleXml(CommandContext ctx, List<BundledPatchEntry> patches, ZipFile patchZip) throws CommandLineException {
    if (patches.isEmpty()) {
        return;
    }
    for (BundledPatchEntry bundledPatch : patches) {
        final ZipEntry bundledZip = patchZip.getEntry(bundledPatch.getPatchPath());
        if (bundledZip == null) {
            throw new CommandLineException("Patch file not found in the bundle: " + bundledPatch.getPatchPath());
        }
        InputStream is = null;
        ZipInputStream bundledPatchIs = null;
        try {
            is = patchZip.getInputStream(bundledZip);
            bundledPatchIs = new ZipInputStream(is);
            ZipEntry bundledPatchXml = bundledPatchIs.getNextEntry();
            while (bundledPatchXml != null) {
                if (PatchXml.PATCH_XML.equals(bundledPatchXml.getName())) {
                    break;
                }
                bundledPatchXml = bundledPatchIs.getNextEntry();
            }
            if (bundledPatchXml == null) {
                throw new CommandLineException("Failed to locate " + PatchXml.PATCH_XML + " in bundled patch " + bundledPatch.getPatchPath());
            }
            final Patch patch = PatchXml.parse(bundledPatchIs).resolvePatch(null, null);
            if (verbose.isPresent(ctx.getParsedCommandLine())) {
                // to make the separation better in the verbose mode
                ctx.printLine("CONTENT OF " + bundledPatch.getPatchPath() + ':' + Util.LINE_SEPARATOR);
            }
            displayPatchXml(ctx, patch);
            ctx.printLine("");
        } catch (Exception e) {
            throw new CommandLineException("Failed to inspect " + bundledPatch.getPatchPath(), e);
        } finally {
            IoUtils.safeClose(bundledPatchIs);
            IoUtils.safeClose(is);
        }
    }
}
Also used : BundledPatchEntry(org.jboss.as.patching.metadata.BundledPatch.BundledPatchEntry) ZipInputStream(java.util.zip.ZipInputStream) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) Patch(org.jboss.as.patching.metadata.Patch) CommandLineException(org.jboss.as.cli.CommandLineException) XMLStreamException(javax.xml.stream.XMLStreamException) ZipException(java.util.zip.ZipException) CommandFormatException(org.jboss.as.cli.CommandFormatException) PatchingException(org.jboss.as.patching.PatchingException) IOException(java.io.IOException) CommandLineException(org.jboss.as.cli.CommandLineException)

Example 3 with BundledPatchEntry

use of org.jboss.as.patching.metadata.BundledPatch.BundledPatchEntry 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)

Aggregations

PatchingException (org.jboss.as.patching.PatchingException)3 BundledPatchEntry (org.jboss.as.patching.metadata.BundledPatch.BundledPatchEntry)3 File (java.io.File)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ZipEntry (java.util.zip.ZipEntry)2 ZipException (java.util.zip.ZipException)2 ZipInputStream (java.util.zip.ZipInputStream)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 CommandLineException (org.jboss.as.cli.CommandLineException)2 Patch (org.jboss.as.patching.metadata.Patch)2 FileInputStream (java.io.FileInputStream)1 ArrayList (java.util.ArrayList)1 ZipFile (java.util.zip.ZipFile)1 CommandFormatException (org.jboss.as.cli.CommandFormatException)1 ParsedCommandLine (org.jboss.as.cli.operation.ParsedCommandLine)1 InstalledIdentity (org.jboss.as.patching.installation.InstalledIdentity)1 BundledPatch (org.jboss.as.patching.metadata.BundledPatch)1 PatchingResult (org.jboss.as.patching.tool.PatchingResult)1