Search in sources :

Example 1 with PatchingException

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

the class PatchBundleUnitTestCase method testSkipInstalled.

@Test
public void testSkipInstalled() throws Exception {
    final PatchingTestBuilder builder = createDefaultBuilder("layer-2", "layer-1", "base");
    final byte[] moduleHashOne = new byte[20];
    final byte[] moduleHashTwo = new byte[20];
    final byte[] moduleHashThree = new byte[20];
    final PatchingTestStepBuilder cp1 = builder.createStepBuilder();
    cp1.setPatchId("CP1").upgradeIdentity(PRODUCT_VERSION, PRODUCT_VERSION).upgradeElement("base-CP1", "base", false).addModuleWithRandomContent("org.jboss.test", moduleHashOne);
    final PatchingTestStepBuilder cp2 = builder.createStepBuilder();
    cp2.setPatchId("CP2").upgradeIdentity(PRODUCT_VERSION, PRODUCT_VERSION).upgradeElement("layer-1-CP1", "layer-1", false).addModuleWithRandomContent("org.jboss.test.two", moduleHashTwo);
    final PatchingTestStepBuilder cp3 = builder.createStepBuilder();
    cp3.setPatchId("CP3").upgradeIdentity(PRODUCT_VERSION, PRODUCT_VERSION).upgradeElement("layer-2-CP1", "layer-2", false).removeModule("org.jboss.test.three", "main", moduleHashThree);
    apply(cp1);
    apply(cp2);
    // Prepare multi patch
    final File multiPatch = prepare(builder.getRoot(), cp1, cp2, cp3);
    // Create the patch tool and apply the patch
    // Get installation manager instance for the unit test
    InstallationManager mgr = updateInstallationManager();
    final PatchTool patchTool = PatchTool.Factory.create(mgr);
    final PatchingResult result = patchTool.applyPatch(multiPatch, ContentVerificationPolicy.STRICT);
    result.commit();
    try {
        PatchStepAssertions.APPLY.after(builder.getFile(JBOSS_INSTALLATION), cp3.build(), mgr);
    } catch (IOException e) {
        throw new PatchingException(e);
    }
}
Also used : PatchingException(org.jboss.as.patching.PatchingException) InstallationManager(org.jboss.as.patching.installation.InstallationManager) PatchingResult(org.jboss.as.patching.tool.PatchingResult) PatchTool(org.jboss.as.patching.tool.PatchTool) IOException(java.io.IOException) File(java.io.File) Test(org.junit.Test)

Example 2 with PatchingException

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

the class PatchBundleUnitTestCase method prepare.

/**
 * Prepare the multi patch bundle.
 *
 * @param root  the temp dir root
 * @param steps the individual steps
 * @return the prepared content
 * @throws PatchingException
 */
protected File prepare(File root, PatchingTestStepBuilder... steps) throws PatchingException {
    final File tempDir = new File(root, randomString());
    tempDir.mkdir();
    final List<BundledPatch.BundledPatchEntry> entries = new ArrayList<BundledPatch.BundledPatchEntry>();
    for (final PatchingTestStepBuilder step : steps) {
        // Prepare the patches.
        final Patch patch = step.build();
        writePatch(step.getPatchDir(), patch);
        final String patchId = patch.getPatchId();
        final String path = patchId + ".zip";
        final File patchOutput = new File(tempDir, path);
        ZipUtils.zip(step.getPatchDir(), patchOutput);
        entries.add(new BundledPatch.BundledPatchEntry(patchId, path));
    }
    final File multiPatchXml = new File(tempDir, PatchBundleXml.MULTI_PATCH_XML);
    try {
        final OutputStream os = new FileOutputStream(multiPatchXml);
        try {
            PatchBundleXml.marshal(os, new BundledPatch() {

                @Override
                public List<BundledPatchEntry> getPatches() {
                    return entries;
                }
            });
        } finally {
            safeClose(os);
        }
    } catch (Exception e) {
        throw new PatchingException(e);
    }
    final File result = new File(root, "multi-step-contents.zip");
    ZipUtils.zip(tempDir, result);
    return result;
}
Also used : PatchingException(org.jboss.as.patching.PatchingException) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) TestUtils.randomString(org.jboss.as.patching.runner.TestUtils.randomString) BundledPatch(org.jboss.as.patching.metadata.BundledPatch) IOException(java.io.IOException) PatchingException(org.jboss.as.patching.PatchingException) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) BundledPatch(org.jboss.as.patching.metadata.BundledPatch) Patch(org.jboss.as.patching.metadata.Patch)

Example 3 with PatchingException

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

the class PatchStepAssertions method assertApplied.

static void assertApplied(final Patch patch, InstallationManager manager) throws IOException {
    final String patchID = patch.getPatchId();
    InstalledIdentity installedIdentity = null;
    try {
        installedIdentity = manager.getInstalledIdentity(patch.getIdentity().getName(), null);
    } catch (PatchingException e) {
        Assert.fail(e.getLocalizedMessage());
    }
    final PatchableTarget target = installedIdentity.getIdentity();
    final PatchableTarget.TargetInfo identity = target.loadTargetInfo();
    assertIsApplied(patch.getIdentity().getPatchType(), patchID, identity);
    assertExists(identity.getDirectoryStructure().getInstalledImage().getPatchHistoryDir(patchID));
    assertContentItems(patchID, target, patch.getModifications());
    for (final PatchElement element : patch.getElements()) {
        final PatchElementProvider provider = element.getProvider();
        final PatchableTarget targetElement = provider.isAddOn() ? installedIdentity.getAddOn(provider.getName()) : installedIdentity.getLayer(provider.getName());
        assertIsApplied(provider.getPatchType(), element.getId(), targetElement.loadTargetInfo());
        assertContentItems(element.getId(), targetElement, element.getModifications());
    }
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchableTarget(org.jboss.as.patching.installation.PatchableTarget) PatchingException(org.jboss.as.patching.PatchingException) PatchElementProvider(org.jboss.as.patching.metadata.PatchElementProvider) PatchElement(org.jboss.as.patching.metadata.PatchElement)

Example 4 with PatchingException

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

the class PatchUndoTestCase method testWrongMiscContent.

@Test
public void testWrongMiscContent() throws Exception {
    final PatchingTestBuilder builder = createDefaultBuilder();
    ContentModificationUtils.addMisc(builder.getRoot(), "oo2", "test-content", "wrong-content");
    final MiscContentItem item = new MiscContentItem("wrong-content", new String[0], WRONG_HASH);
    final ContentModification wrongModification = new ContentModification(item, IoUtils.NO_CONTENT, ModificationType.ADD);
    final PatchingTestStepBuilder step1 = builder.createStepBuilder();
    step1.oneOffPatchIdentity(PRODUCT_VERSION).setPatchId("oo2").oneOffPatchElement("base-patch-002", "base", false).addModuleWithRandomContent("other.test", null).getParent().addFileWithRandomContent(null, "test", "content").addContentModification(wrongModification);
    // 
    try {
        apply(step1);
        Assert.fail("should have failed");
    } catch (PatchingException e) {
        Assert.assertFalse(builder.hasFile("test", "content"));
        Assert.assertFalse(builder.hasFile("wrong-content"));
        final InstalledIdentity identity = loadInstallationManager().getDefaultIdentity();
        final PatchableTarget base = identity.getLayer("base");
        Assert.assertFalse(base.getDirectoryStructure().getModulePatchDirectory("base-patch-002").exists());
        Assert.assertFalse(identity.getInstalledImage().getPatchHistoryDir("oo2").exists());
    }
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchableTarget(org.jboss.as.patching.installation.PatchableTarget) PatchingException(org.jboss.as.patching.PatchingException) MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem) ContentModification(org.jboss.as.patching.metadata.ContentModification) Test(org.junit.Test)

Example 5 with PatchingException

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

the class PatchUndoTestCase method testInvalidPatch.

@Test
public void testInvalidPatch() throws Exception {
    final PatchingTestBuilder builder = createDefaultBuilder();
    ContentModificationUtils.addMisc(builder.getRoot(), "oo2", "test-content", "wrong-content");
    final MiscContentItem item = new MiscContentItem("wrong-content", new String[0], WRONG_HASH);
    final ContentModification wrongModification = new ContentModification(item, IoUtils.NO_CONTENT, ModificationType.ADD);
    final PatchingTestStepBuilder step1 = builder.createStepBuilder();
    step1.oneOffPatchIdentity(PRODUCT_VERSION).setPatchId("oo2").oneOffPatchElement("base-patch-002", "base", false).addModuleWithRandomContent("other.test", null).getParent().addFileWithRandomContent(null, "test", "content");
    apply(step1);
    Assert.assertTrue(builder.hasFile("test", "content"));
    // 
    final PatchingTestStepBuilder step2 = builder.createStepBuilder();
    step2.upgradeIdentity(PRODUCT_VERSION, PRODUCT_VERSION).setPatchId("cp2").upgradeElement("base-patch-cp2", "base", false).getParent().addContentModification(wrongModification);
    try {
        apply(step2);
        Assert.fail("should have failed");
    } catch (PatchingException e) {
        Assert.assertTrue(builder.hasFile("test", "content"));
    }
}
Also used : PatchingException(org.jboss.as.patching.PatchingException) MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem) ContentModification(org.jboss.as.patching.metadata.ContentModification) Test(org.junit.Test)

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