Search in sources :

Example 1 with MiscContentItem

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

the class PatchStepAssertions method assertContentModification.

static void assertContentModification(final String patchID, final PatchableTarget target, final ContentModification modification) {
    final ContentItem item = modification.getItem();
    final ContentType contentType = item.getContentType();
    switch(contentType) {
        case MODULE:
            assertModule(patchID, target, (ModuleItem) item);
            break;
        case BUNDLE:
            break;
        case MISC:
            final File home = target.getDirectoryStructure().getInstalledImage().getJbossHome();
            final ModificationCondition condition = modification.getCondition();
            if (condition != null) {
                if (condition instanceof ModificationCondition.ExistsCondition) {
                    final ContentItem requiredItem = ((ModificationCondition.ExistsCondition) condition).getContentItem();
                    File requiredFile;
                    switch(requiredItem.getContentType()) {
                        case MISC:
                            requiredFile = PatchContentLoader.getMiscPath(home, (MiscContentItem) requiredItem);
                            break;
                        case MODULE:
                        case BUNDLE:
                        default:
                            throw new IllegalStateException("Unsupported content type");
                    }
                    if (!requiredFile.exists()) {
                        final File file = PatchContentLoader.getMiscPath(home, (MiscContentItem) item);
                        Assert.assertFalse(file.exists());
                        return;
                    }
                }
            }
            assertMisc(home, modification.getType(), (MiscContentItem) item);
            break;
        default:
            Assert.fail();
    }
}
Also used : ContentType(org.jboss.as.patching.metadata.ContentType) ModificationCondition(org.jboss.as.patching.metadata.ModificationCondition) MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem) File(java.io.File) MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem) ContentItem(org.jboss.as.patching.metadata.ContentItem)

Example 2 with MiscContentItem

use of org.jboss.as.patching.metadata.MiscContentItem 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 3 with MiscContentItem

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

Example 4 with MiscContentItem

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

the class ContentModificationUtils method modifyMisc.

public static ContentModification modifyMisc(File patchDir, String patchElementID, String modifiedContent, byte[] existingHash, String[] fileSegments, String[] requiredSegments) throws IOException {
    File miscDir = newFile(patchDir, patchElementID, MISC);
    File modifiedFile = touch(miscDir, fileSegments);
    dump(modifiedFile, modifiedContent);
    byte[] modifiedHash = hashFile(modifiedFile);
    String[] subdir = new String[0];
    if (fileSegments.length > 0) {
        subdir = new String[fileSegments.length - 1];
        System.arraycopy(fileSegments, 0, subdir, 0, fileSegments.length - 1);
    }
    final MiscContentItem item = new MiscContentItem(modifiedFile.getName(), subdir, modifiedHash);
    ModificationCondition condition = null;
    if (requiredSegments != null && requiredSegments.length > 0) {
        subdir = new String[requiredSegments.length - 1];
        System.arraycopy(requiredSegments, 0, subdir, 0, requiredSegments.length - 1);
        condition = ModificationCondition.Factory.exists(new MiscContentItem(requiredSegments[requiredSegments.length - 1], subdir, null));
    }
    return new ContentModification(item, existingHash, MODIFY, condition);
}
Also used : MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem) ModificationCondition(org.jboss.as.patching.metadata.ModificationCondition) IoUtils.newFile(org.jboss.as.patching.IoUtils.newFile) HashUtils.hashFile(org.jboss.as.patching.HashUtils.hashFile) File(java.io.File) ContentModification(org.jboss.as.patching.metadata.ContentModification)

Example 5 with MiscContentItem

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

the class ContentModificationUtils method removeMisc.

public static ContentModification removeMisc(File existingFile, String... fileSegments) throws IOException {
    byte[] existingHash = hashFile(existingFile);
    String[] subdir = new String[0];
    if (fileSegments.length > 0) {
        subdir = new String[fileSegments.length - 1];
        System.arraycopy(fileSegments, 0, subdir, 0, fileSegments.length - 1);
    }
    ContentModification fileRemoved = new ContentModification(new MiscContentItem(existingFile.getName(), subdir, NO_CONTENT), existingHash, REMOVE);
    return fileRemoved;
}
Also used : MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem) ContentModification(org.jboss.as.patching.metadata.ContentModification)

Aggregations

MiscContentItem (org.jboss.as.patching.metadata.MiscContentItem)20 ContentModification (org.jboss.as.patching.metadata.ContentModification)17 File (java.io.File)9 HashUtils.hashFile (org.jboss.as.patching.HashUtils.hashFile)6 Test (org.junit.Test)6 IoUtils.newFile (org.jboss.as.patching.IoUtils.newFile)5 ContentItem (org.jboss.as.patching.metadata.ContentItem)4 ModificationCondition (org.jboss.as.patching.metadata.ModificationCondition)4 TestUtils.randomString (org.jboss.as.patching.runner.TestUtils.randomString)4 ContentType (org.jboss.as.patching.metadata.ContentType)3 TestUtils.createPatchXMLFile (org.jboss.as.patching.runner.TestUtils.createPatchXMLFile)3 TestUtils.createZippedPatchFile (org.jboss.as.patching.runner.TestUtils.createZippedPatchFile)3 PatchingException (org.jboss.as.patching.PatchingException)2 Patch (org.jboss.as.patching.metadata.Patch)2 Before (org.junit.Before)2 InstalledIdentity (org.jboss.as.patching.installation.InstalledIdentity)1 PatchableTarget (org.jboss.as.patching.installation.PatchableTarget)1 ModuleItem (org.jboss.as.patching.metadata.ModuleItem)1 PatchBuilder (org.jboss.as.patching.metadata.PatchBuilder)1 PatchingResult (org.jboss.as.patching.tool.PatchingResult)1