Search in sources :

Example 36 with PatchingException

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

the class PatchBundleUnitTestCase method testConflicts.

@Test
public void testConflicts() throws Exception {
    final PatchingTestBuilder builder = createDefaultBuilder();
    final byte[] standaloneHash = new byte[20];
    final byte[] configHash = new byte[20];
    final byte[] existingHash = new byte[20];
    // Create a file
    final File existing = builder.getFile(FILE_EXISTING);
    touch(existing);
    dump(existing, randomString());
    final PatchingTestStepBuilder cp1 = builder.createStepBuilder();
    cp1.setPatchId("cp1").upgradeIdentity(PRODUCT_VERSION, PRODUCT_VERSION).addFileWithRandomContent(standaloneHash, FILE_ONE);
    final PatchingTestStepBuilder cp2 = builder.createStepBuilder();
    cp2.setPatchId("cp2").upgradeIdentity(PRODUCT_VERSION, PRODUCT_VERSION).addFileWithRandomContent(configHash, FILE_TWO);
    final PatchingTestStepBuilder cp3 = builder.createStepBuilder();
    cp3.setPatchId("cp3").upgradeIdentity(PRODUCT_VERSION, PRODUCT_VERSION).addFileWithRandomContent(existingHash, FILE_EXISTING);
    final File multiPatch = prepare(builder.getRoot(), cp1, cp2, cp3);
    // Create the patch tool and apply the patch
    InstallationManager mgr = loadInstallationManager();
    final PatchTool patchTool = PatchTool.Factory.create(mgr);
    try {
        patchTool.applyPatch(multiPatch, ContentVerificationPolicy.STRICT);
        Assert.fail();
    } catch (PatchingException e) {
    // ok
    }
    Assert.assertFalse(builder.hasFile(FILE_ONE));
    Assert.assertFalse(builder.hasFile(FILE_TWO));
}
Also used : PatchingException(org.jboss.as.patching.PatchingException) InstallationManager(org.jboss.as.patching.installation.InstallationManager) PatchTool(org.jboss.as.patching.tool.PatchTool) File(java.io.File) Test(org.junit.Test)

Example 37 with PatchingException

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

the class PatchBundleUnitTestCase method testMultiInstall.

@Test
public void testMultiInstall() 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 byte[] moduleHashFour = new byte[20];
    final byte[] moduleHashFive = new byte[20];
    final byte[] moduleHashSix = 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);
    final PatchingTestStepBuilder cp4 = builder.createStepBuilder();
    cp4.setPatchId("CP4").upgradeIdentity(PRODUCT_VERSION, PRODUCT_VERSION).upgradeElement("base-CP2", "base", false).addModuleWithRandomContent("org.jboss.test.four", moduleHashFour);
    final PatchingTestStepBuilder cp5 = builder.createStepBuilder();
    cp5.setPatchId("CP5").upgradeIdentity(PRODUCT_VERSION, PRODUCT_VERSION).upgradeElement("base-CP3", "base", false).updateModuleWithRandomContent("org.jboss.test.four", moduleHashFour, null).getParent().upgradeElement("layer-1-CP2", "layer-1", false).addModuleWithRandomContent("org.jboss.test.five", moduleHashFive).getParent().upgradeElement("layer-2-CP2", "layer-2", false).addModuleWithRandomContent("org.jboss.test.six", moduleHashSix);
    final File multiPatch = prepare(builder.getRoot(), cp1, cp2, cp3, cp4, cp5);
    // 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), cp5.build(), mgr);
    } catch (IOException e) {
        throw new PatchingException(e);
    }
    mgr = loadInstallationManager();
    final InstalledIdentity installedIdentity = mgr.getDefaultIdentity();
    Assert.assertEquals(Arrays.asList(new String[] { "CP1", "CP2", "CP3", "CP4", "CP5" }), installedIdentity.getAllInstalledPatches());
    PatchStepAssertions.assertModule("base-CP3", installedIdentity.getLayer("base"), "org.jboss.test", "main");
    PatchStepAssertions.assertModule("base-CP3", installedIdentity.getLayer("base"), "org.jboss.test.four", "main");
    PatchStepAssertions.assertModule("layer-1-CP2", installedIdentity.getLayer("layer-1"), "org.jboss.test.two", "main");
    PatchStepAssertions.assertModule("layer-1-CP2", installedIdentity.getLayer("layer-1"), "org.jboss.test.five", "main");
    PatchStepAssertions.assertModule("layer-2-CP2", installedIdentity.getLayer("layer-2"), "org.jboss.test.three", "main");
    PatchStepAssertions.assertModule("layer-2-CP2", installedIdentity.getLayer("layer-2"), "org.jboss.test.six", "main");
    rollback(cp5);
    mgr = loadInstallationManager();
    PatchStepAssertions.assertModule("base-CP2", installedIdentity.getLayer("base"), "org.jboss.test", "main");
    PatchStepAssertions.assertModule("base-CP2", installedIdentity.getLayer("base"), "org.jboss.test.four", "main");
    rollback(cp4);
    rollback(cp3);
    rollback(cp2);
    rollback(cp1);
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) 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) TestUtils.randomString(org.jboss.as.patching.runner.TestUtils.randomString) File(java.io.File) Test(org.junit.Test)

Example 38 with PatchingException

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

the class PatchUndoTestCase method testWrongModuleContent.

@Test
public void testWrongModuleContent() throws Exception {
    final PatchingTestBuilder builder = createDefaultBuilder();
    // Add some random content
    ContentModificationUtils.addModule(builder.getRoot(), "base-patch-001", "test.module", randomString());
    // Override the hash with a wrong one
    final ModuleItem item = new ModuleItem("test.module", "main", WRONG_HASH);
    final ContentModification wrongModification = new ContentModification(item, IoUtils.NO_CONTENT, ModificationType.ADD);
    final PatchingTestStepBuilder step1 = builder.createStepBuilder();
    step1.oneOffPatchIdentity(PRODUCT_VERSION).setPatchId("oo1").oneOffPatchElement("base-patch-001", "base", false).addContentModification(wrongModification).getParent().addFileWithRandomContent(null, "test", "content");
    // 
    try {
        apply(step1);
        Assert.fail("should have failed");
    } catch (PatchingException e) {
        Assert.assertFalse(builder.hasFile("test", "content"));
        final InstalledIdentity identity = loadInstallationManager().getDefaultIdentity();
        final PatchableTarget base = identity.getLayer("base");
        Assert.assertFalse(base.getDirectoryStructure().getModulePatchDirectory("base-patch-001").exists());
        Assert.assertFalse(identity.getInstalledImage().getPatchHistoryDir("oo1").exists());
    }
}
Also used : ModuleItem(org.jboss.as.patching.metadata.ModuleItem) InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchableTarget(org.jboss.as.patching.installation.PatchableTarget) PatchingException(org.jboss.as.patching.PatchingException) ContentModification(org.jboss.as.patching.metadata.ContentModification) Test(org.junit.Test)

Example 39 with PatchingException

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

the class PatchingHistoryUnitTestCase method cannotRollbackPatch.

protected void cannotRollbackPatch(final String patchID) throws Exception {
    InstalledIdentity installedIdentity = updateInstallationManager().getDefaultIdentity();
    PatchingException expectedEx = null;
    try {
        validateRollbackState(patchID, installedIdentity);
    } catch (PatchingException e) {
        expectedEx = e;
    }
    assertNotNull("should not be able to rollback " + patchID, expectedEx);
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchingException(org.jboss.as.patching.PatchingException)

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