Search in sources :

Example 6 with PatchableTarget

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

the class RollbackPatchXml_1_0 method writeTargetInfo.

static void writeTargetInfo(final XMLExtendedStreamWriter writer, final Element element, final PatchableTarget target) throws XMLStreamException {
    try {
        final PatchableTarget.TargetInfo info = target.loadTargetInfo();
        // 
        writer.writeEmptyElement(element.name);
        writer.writeAttribute(Attribute.NAME.name, target.getName());
        writer.writeAttribute(Attribute.RELEASE_ID.name, info.getCumulativePatchID());
        if (!info.getPatchIDs().isEmpty()) {
            writer.writeAttribute(Attribute.PATCHES.name, PatchUtils.asString(info.getPatchIDs()));
        }
    } catch (IOException e) {
        throw new XMLStreamException(e);
    }
}
Also used : PatchableTarget(org.jboss.as.patching.installation.PatchableTarget) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException)

Example 7 with PatchableTarget

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

the class PatchStepAssertions method assertNotApplied.

static void assertNotApplied(final Patch patch, InstallationManager manager) throws IOException {
    InstalledIdentity installedIdentity = null;
    try {
        installedIdentity = manager.getInstalledIdentity(patch.getIdentity().getName(), patch.getIdentity().getVersion());
    } catch (PatchingException e) {
        Assert.fail(e.getLocalizedMessage());
    }
    final PatchableTarget.TargetInfo identity = installedIdentity.getIdentity().loadTargetInfo();
    assertNotApplied(patch.getIdentity().getPatchType(), patch.getPatchId(), identity);
    assertDoesNotExists(identity.getDirectoryStructure().getInstalledImage().getPatchHistoryDir(patch.getPatchId()));
    for (final PatchElement element : patch.getElements()) {
        final PatchElementProvider provider = element.getProvider();
        final PatchableTarget target = provider.isAddOn() ? installedIdentity.getAddOn(provider.getName()) : installedIdentity.getLayer(provider.getName());
        Assert.assertNotNull(target);
        assertNotApplied(provider.getPatchType(), element.getId(), target.loadTargetInfo());
    }
}
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 8 with PatchableTarget

use of org.jboss.as.patching.installation.PatchableTarget 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 9 with PatchableTarget

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

the class PatchUndoTestCase method testWrongModuleContentOverride.

private void testWrongModuleContentOverride(final ContentVerificationPolicy contentVerificationPolicy) throws Exception {
    final PatchingTestBuilder builder = createDefaultBuilder();
    // Add some random content
    ContentModificationUtils.addModule(builder.getRoot(), "base-patch-003", "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("oo3").oneOffPatchElement("base-patch-003", "base", false).addContentModification(wrongModification).getParent().addFileWithRandomContent(null, "test", "content");
    apply(step1, contentVerificationPolicy);
    Assert.assertTrue(builder.hasFile("test", "content"));
    final InstalledIdentity identity = loadInstallationManager().getDefaultIdentity();
    final PatchableTarget base = identity.getLayer("base");
    Assert.assertTrue(base.getDirectoryStructure().getModulePatchDirectory("base-patch-003").exists());
    Assert.assertTrue(identity.getInstalledImage().getPatchHistoryDir("oo3").exists());
}
Also used : ModuleItem(org.jboss.as.patching.metadata.ModuleItem) InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchableTarget(org.jboss.as.patching.installation.PatchableTarget) ContentModification(org.jboss.as.patching.metadata.ContentModification)

Aggregations

PatchableTarget (org.jboss.as.patching.installation.PatchableTarget)9 InstalledIdentity (org.jboss.as.patching.installation.InstalledIdentity)6 PatchingException (org.jboss.as.patching.PatchingException)4 ContentModification (org.jboss.as.patching.metadata.ContentModification)4 PatchElement (org.jboss.as.patching.metadata.PatchElement)3 PatchElementProvider (org.jboss.as.patching.metadata.PatchElementProvider)3 IOException (java.io.IOException)2 ModuleItem (org.jboss.as.patching.metadata.ModuleItem)2 ModelNode (org.jboss.dmr.ModelNode)2 Test (org.junit.Test)2 XMLStreamException (javax.xml.stream.XMLStreamException)1 OperationFailedException (org.jboss.as.controller.OperationFailedException)1 PathAddress (org.jboss.as.controller.PathAddress)1 PathElement (org.jboss.as.controller.PathElement)1 SimpleResourceDefinition (org.jboss.as.controller.SimpleResourceDefinition)1 StandardResourceDescriptionResolver (org.jboss.as.controller.descriptions.StandardResourceDescriptionResolver)1 ManagementResourceRegistration (org.jboss.as.controller.registry.ManagementResourceRegistration)1 MiscContentItem (org.jboss.as.patching.metadata.MiscContentItem)1 Patch (org.jboss.as.patching.metadata.Patch)1