Search in sources :

Example 26 with Patch

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

the class PatchInspect method displayPatchBundleXml.

private void displayPatchBundleXml(CommandContext ctx, List<BundledPatch.BundledPatchEntry> patches, ZipFile patchZip) throws CommandException {
    if (patches.isEmpty()) {
        return;
    }
    for (BundledPatch.BundledPatchEntry bundledPatch : patches) {
        final ZipEntry bundledZip = patchZip.getEntry(bundledPatch.getPatchPath());
        if (bundledZip == null) {
            throw new CommandException("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) {
                // 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 CommandException("Failed to inspect " + bundledPatch.getPatchPath(), e);
        } finally {
            IoUtils.safeClose(bundledPatchIs);
            IoUtils.safeClose(is);
        }
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) CommandException(org.aesh.command.CommandException) BundledPatch(org.jboss.as.patching.metadata.BundledPatch) Patch(org.jboss.as.patching.metadata.Patch) BundledPatch(org.jboss.as.patching.metadata.BundledPatch) CommandLineException(org.jboss.as.cli.CommandLineException) XMLStreamException(javax.xml.stream.XMLStreamException) PatchingException(org.jboss.as.patching.PatchingException) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) CommandException(org.aesh.command.CommandException) CommandLineException(org.jboss.as.cli.CommandLineException)

Example 27 with Patch

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

the class PatchInfoHandler method patchIdInfo.

private ModelNode patchIdInfo(final OperationContext context, final String patchId, final boolean verbose, final PatchingHistory.Iterator i) {
    while (i.hasNext()) {
        final Entry entry = i.next();
        if (patchId.equals(entry.getPatchId())) {
            final ModelNode result = new ModelNode();
            result.get(Constants.PATCH_ID).set(entry.getPatchId());
            result.get(Constants.TYPE).set(entry.getType().getName());
            result.get(Constants.DESCRIPTION).set(entry.getMetadata().getDescription());
            final String link = entry.getMetadata().getLink();
            if (link != null) {
                result.get(Constants.LINK).set(link);
            }
            final Identity identity = entry.getMetadata().getIdentity();
            result.get(Constants.IDENTITY_NAME).set(identity.getName());
            result.get(Constants.IDENTITY_VERSION).set(identity.getVersion());
            if (verbose) {
                final ModelNode list = result.get(Constants.ELEMENTS).setEmptyList();
                final Patch metadata = entry.getMetadata();
                for (PatchElement e : metadata.getElements()) {
                    final ModelNode element = new ModelNode();
                    element.get(Constants.PATCH_ID).set(e.getId());
                    element.get(Constants.TYPE).set(e.getProvider().isAddOn() ? Constants.ADD_ON : Constants.LAYER);
                    element.get(Constants.NAME).set(e.getProvider().getName());
                    element.get(Constants.DESCRIPTION).set(e.getDescription());
                    list.add(element);
                }
            }
            return result;
        }
    }
    return null;
}
Also used : Entry(org.jboss.as.patching.tool.PatchingHistory.Entry) PatchElement(org.jboss.as.patching.metadata.PatchElement) ModelNode(org.jboss.dmr.ModelNode) Identity(org.jboss.as.patching.metadata.Identity) InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) Patch(org.jboss.as.patching.metadata.Patch)

Example 28 with Patch

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

the class PatchBundleTestCase method createNextCumulativePatchAddingRandomModule.

private File createNextCumulativePatchAddingRandomModule(String patchID, String asVersion, final String currentPatch, final String targetAsVersion, File targetDir) throws Exception {
    String layerPatchID = "layer" + patchID;
    File cpPatchDir = mkdir(tempDir, patchID);
    final String moduleName = "org.wildfly.test." + randomString();
    // Create the version module
    final String versionModuleName = ProductInfo.getVersionModule();
    final Module modifiedModule = PatchingTestUtil.createVersionModule(targetAsVersion);
    // Calculate the target hash of the currently active module
    final String currentLayerPatchID = "layer" + currentPatch;
    File originalVersionModulePath = new File(tempDir, currentPatch);
    originalVersionModulePath = new File(originalVersionModulePath, currentLayerPatchID);
    originalVersionModulePath = new File(originalVersionModulePath, Constants.MODULES);
    originalVersionModulePath = newFile(originalVersionModulePath, versionModuleName.split("\\."));
    originalVersionModulePath = new File(originalVersionModulePath, ProductInfo.getVersionModuleSlot());
    byte[] patchedAsVersionHash = HashUtils.hashFile(originalVersionModulePath);
    assert patchedAsVersionHash != null;
    final ResourceItem resourceItem1 = new ResourceItem("testFile1", "content1".getBytes(StandardCharsets.UTF_8));
    final ResourceItem resourceItem2 = new ResourceItem("testFile2", "content2".getBytes(StandardCharsets.UTF_8));
    Module newModule = new Module.Builder(moduleName).miscFile(resourceItem1).miscFile(resourceItem2).build();
    ContentModification moduleAdded = ContentModificationUtils.addModule(cpPatchDir, layerPatchID, newModule);
    ContentModification versionModuleModified = ContentModificationUtils.modifyModule(cpPatchDir, layerPatchID, patchedAsVersionHash, modifiedModule);
    ProductConfig productConfig = new ProductConfig(PRODUCT, asVersion, "main");
    Patch cpPatch = PatchBuilder.create().setPatchId(patchID).setDescription("A cp patch.").upgradeIdentity(productConfig.getProductName(), productConfig.getProductVersion(), targetAsVersion).getParent().upgradeElement(layerPatchID, "base", false).addContentModification(versionModuleModified).addContentModification(moduleAdded).getParent().build();
    createPatchXMLFile(cpPatchDir, cpPatch);
    return createZippedPatchFile(cpPatchDir, patchID, targetDir);
}
Also used : ProductConfig(org.jboss.as.version.ProductConfig) PatchingTestUtil.randomString(org.jboss.as.test.patching.PatchingTestUtil.randomString) Module(org.jboss.as.test.patching.util.module.Module) IoUtils.newFile(org.jboss.as.patching.IoUtils.newFile) PatchingTestUtil.createPatchBundleXMLFile(org.jboss.as.test.patching.PatchingTestUtil.createPatchBundleXMLFile) PatchingTestUtil.createZippedPatchFile(org.jboss.as.test.patching.PatchingTestUtil.createZippedPatchFile) File(java.io.File) PatchingTestUtil.createPatchXMLFile(org.jboss.as.test.patching.PatchingTestUtil.createPatchXMLFile) ContentModification(org.jboss.as.patching.metadata.ContentModification) Patch(org.jboss.as.patching.metadata.Patch) BundledPatch(org.jboss.as.patching.metadata.BundledPatch)

Example 29 with Patch

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

the class PatchBundleTestCase method createOneOffPatchAddingMiscFile.

private File createOneOffPatchAddingMiscFile(String patchID, String asVersion) throws Exception {
    File oneOffPatchDir = mkdir(tempDir, patchID);
    ContentModification miscFileAdded = ContentModificationUtils.addMisc(oneOffPatchDir, patchID, "test content", "awesomeDirectory", "awesomeFile");
    ProductConfig productConfig = new ProductConfig(PRODUCT, asVersion, "main");
    Patch oneOffPatch = PatchBuilder.create().setPatchId(patchID).setDescription("A one-off patch adding a misc file.").oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().addContentModification(miscFileAdded).build();
    createPatchXMLFile(oneOffPatchDir, oneOffPatch);
    return createZippedPatchFile(oneOffPatchDir, patchID);
}
Also used : ProductConfig(org.jboss.as.version.ProductConfig) IoUtils.newFile(org.jboss.as.patching.IoUtils.newFile) PatchingTestUtil.createPatchBundleXMLFile(org.jboss.as.test.patching.PatchingTestUtil.createPatchBundleXMLFile) PatchingTestUtil.createZippedPatchFile(org.jboss.as.test.patching.PatchingTestUtil.createZippedPatchFile) File(java.io.File) PatchingTestUtil.createPatchXMLFile(org.jboss.as.test.patching.PatchingTestUtil.createPatchXMLFile) ContentModification(org.jboss.as.patching.metadata.ContentModification) Patch(org.jboss.as.patching.metadata.Patch) BundledPatch(org.jboss.as.patching.metadata.BundledPatch)

Example 30 with Patch

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

the class PatchInfoTestBase method applyPatch.

protected byte[] applyPatch(String product, String version, String newVersion, String patchID, String layer, String layerPatchId, byte[] targetHash) throws Exception {
    final File patchDir = mkdir(tempDir, patchID);
    final Module module = new Module.Builder("module-test").miscFile(new ResourceItem("resource-test", ("resource patch " + patchID).getBytes(StandardCharsets.UTF_8))).build();
    // create the patch with the updated module
    final ContentModification moduleModified = ContentModificationUtils.modifyModule(patchDir, layerPatchId, targetHash, module);
    PatchBuilder patchBuilder = PatchBuilder.create().setPatchId(patchID).setDescription(randomString());
    if (newVersion != null) {
        patchBuilder = patchBuilder.upgradeIdentity(product, version, newVersion).getParent().upgradeElement(layerPatchId, layer, false).addContentModification(moduleModified).getParent();
    } else {
        patchBuilder = patchBuilder.oneOffPatchIdentity(product, version).getParent().oneOffPatchElement(layerPatchId, layer, false).addContentModification(moduleModified).getParent();
    }
    final Patch patch = patchBuilder.build();
    // create the patch
    createPatchXMLFile(patchDir, patch);
    final File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
    // apply the patch and check if server is in restart-required mode
    controller.start();
    try {
        Assert.assertTrue("Patch should be accepted", CliUtilsForPatching.applyPatch(zippedPatch.getAbsolutePath()));
        Assert.assertTrue("server should be in restart-required mode", CliUtilsForPatching.doesServerRequireRestart());
    } finally {
        controller.stop();
    }
    return moduleModified.getItem().getContentHash();
}
Also used : PatchBuilder(org.jboss.as.patching.metadata.PatchBuilder) PatchBuilder(org.jboss.as.patching.metadata.PatchBuilder) Module(org.jboss.as.test.patching.util.module.Module) PatchingTestUtil.createZippedPatchFile(org.jboss.as.test.patching.PatchingTestUtil.createZippedPatchFile) File(java.io.File) PatchingTestUtil.createPatchXMLFile(org.jboss.as.test.patching.PatchingTestUtil.createPatchXMLFile) ContentModification(org.jboss.as.patching.metadata.ContentModification) Patch(org.jboss.as.patching.metadata.Patch)

Aggregations

Patch (org.jboss.as.patching.metadata.Patch)110 ContentModification (org.jboss.as.patching.metadata.ContentModification)94 File (java.io.File)93 Test (org.junit.Test)66 IoUtils.newFile (org.jboss.as.patching.IoUtils.newFile)60 PatchingTestUtil.createPatchXMLFile (org.jboss.as.test.patching.PatchingTestUtil.createPatchXMLFile)55 PatchingTestUtil.createZippedPatchFile (org.jboss.as.test.patching.PatchingTestUtil.createZippedPatchFile)52 PatchingTestUtil.randomString (org.jboss.as.test.patching.PatchingTestUtil.randomString)47 ProductConfig (org.jboss.as.version.ProductConfig)39 TestUtils.randomString (org.jboss.as.patching.runner.TestUtils.randomString)33 TestUtils.createPatchXMLFile (org.jboss.as.patching.runner.TestUtils.createPatchXMLFile)30 TestUtils.createZippedPatchFile (org.jboss.as.patching.runner.TestUtils.createZippedPatchFile)30 Module (org.jboss.as.test.patching.util.module.Module)29 PatchingResult (org.jboss.as.patching.tool.PatchingResult)24 PatchingTestUtil.readFile (org.jboss.as.test.patching.PatchingTestUtil.readFile)24 InstalledIdentity (org.jboss.as.patching.installation.InstalledIdentity)22 IOException (java.io.IOException)14 PatchBuilder (org.jboss.as.patching.metadata.PatchBuilder)14 PatchElement (org.jboss.as.patching.metadata.PatchElement)13 HashUtils.hashFile (org.jboss.as.patching.HashUtils.hashFile)12