Search in sources :

Example 1 with PatchableTarget

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

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

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

the class PatchableTargetsArtifact method process.

@Override
public boolean process(PatchingXmlArtifact.XmlArtifactState<Patch> parent, PatchingArtifactProcessor processor) {
    final InstalledIdentity identity = processor.getValidationContext().getInstalledIdentity();
    final Patch patch = parent.getPatch();
    if (Constants.BASE.equals(patch.getPatchId())) {
        return true;
    }
    final List<PatchElement> elements = patch.getElements();
    boolean valid = true;
    if (elements != null && !elements.isEmpty()) {
        for (final PatchElement element : elements) {
            final String patchID = element.getId();
            final PatchElementProvider provider = element.getProvider();
            final String layerName = provider.getName();
            final PatchableTarget target = provider.isAddOn() ? identity.getAddOn(layerName) : identity.getLayer(layerName);
            boolean modules = false;
            boolean bundles = false;
            for (final ContentModification modification : element.getModifications()) {
                if (modules && bundles) {
                    break;
                }
                if (modification.getItem().getContentType() == ContentType.BUNDLE) {
                    bundles = true;
                } else if (modification.getItem().getContentType() == ContentType.MODULE) {
                    modules = true;
                }
            }
            final PatchableTargetState state = new PatchableTargetState(patchID, layerName, target, bundles, modules);
            if (!processor.process(PatchingArtifacts.LAYER, state)) {
                valid = false;
            }
        }
    }
    // In case there are misc content modifications also validate that misc backup exists
    for (final ContentModification modification : patch.getModifications()) {
        if (modification.getType() != ModificationType.ADD && modification.getItem().getContentType() == ContentType.MISC) {
            final PatchingHistoryDirArtifact.DirectoryArtifactState history = processor.getParentArtifact(PatchingArtifacts.HISTORY_DIR);
            PatchingArtifacts.MISC_BACKUP.process(history, processor);
            break;
        }
    }
    return valid;
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchableTarget(org.jboss.as.patching.installation.PatchableTarget) PatchElementProvider(org.jboss.as.patching.metadata.PatchElementProvider) PatchElement(org.jboss.as.patching.metadata.PatchElement) Patch(org.jboss.as.patching.metadata.Patch) ContentModification(org.jboss.as.patching.metadata.ContentModification)

Example 4 with PatchableTarget

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

the class ElementProviderAttributeReadHandler method execute.

@Override
protected void execute(final OperationContext context, final ModelNode operation, final InstalledIdentity installedIdentity) throws OperationFailedException {
    final PathAddress address = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR));
    final PathElement element = address.getLastElement();
    final String name = element.getValue();
    PatchableTarget target = getProvider(name, installedIdentity);
    final ModelNode result = context.getResult();
    handle(result, target);
    context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
Also used : PatchableTarget(org.jboss.as.patching.installation.PatchableTarget) PathElement(org.jboss.as.controller.PathElement) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode)

Example 5 with PatchableTarget

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

the class PatchResourceDefinition method registerPatchingChildren.

private void registerPatchingChildren(ManagementResourceRegistration registry) {
    StandardResourceDescriptionResolver resolver = new StandardResourceDescriptionResolver("patching.layer", "org.jboss.as.patching.management.LocalDescriptions", PatchResourceDefinition.class.getClassLoader());
    registry.registerSubModel(new SimpleResourceDefinition(new Parameters(PathElement.pathElement("layer"), resolver).setAccessConstraints(SensitiveTargetAccessConstraintDefinition.PATCHING).setRuntime()) {

        @Override
        public void registerAttributes(final ManagementResourceRegistration resource) {
            resource.registerReadOnlyAttribute(CUMULATIVE_PATCH_ID, new ElementProviderAttributeReadHandler.LayerAttributeReadHandler() {

                @Override
                void handle(ModelNode result, PatchableTarget layer) throws OperationFailedException {
                    try {
                        result.set(layer.loadTargetInfo().getCumulativePatchID());
                    } catch (IOException e) {
                        throw new OperationFailedException(PatchLogger.ROOT_LOGGER.failedToLoadInfo(layer.getName()), e);
                    }
                }
            });
            resource.registerReadOnlyAttribute(PATCHES, new ElementProviderAttributeReadHandler.LayerAttributeReadHandler() {

                @Override
                void handle(ModelNode result, PatchableTarget layer) throws OperationFailedException {
                    result.setEmptyList();
                    try {
                        for (final String id : layer.loadTargetInfo().getPatchIDs()) {
                            result.add(id);
                        }
                    } catch (IOException e) {
                        throw new OperationFailedException(PatchLogger.ROOT_LOGGER.failedToLoadInfo(layer.getName()), e);
                    }
                }
            });
        }
    });
    resolver = new StandardResourceDescriptionResolver("patching.addon", "org.jboss.as.patching.management.LocalDescriptions", PatchResourceDefinition.class.getClassLoader());
    registry.registerSubModel(new SimpleResourceDefinition(new Parameters(PathElement.pathElement("addon"), resolver).setAccessConstraints(SensitiveTargetAccessConstraintDefinition.PATCHING).setRuntime()) {

        @Override
        public void registerAttributes(final ManagementResourceRegistration resource) {
            resource.registerReadOnlyAttribute(CUMULATIVE_PATCH_ID, new ElementProviderAttributeReadHandler.AddOnAttributeReadHandler() {

                @Override
                void handle(ModelNode result, PatchableTarget addon) throws OperationFailedException {
                    try {
                        result.set(addon.loadTargetInfo().getCumulativePatchID());
                    } catch (IOException e) {
                        throw new OperationFailedException(PatchLogger.ROOT_LOGGER.failedToLoadInfo(addon.getName()), e);
                    }
                }
            });
            resource.registerReadOnlyAttribute(PATCHES, new ElementProviderAttributeReadHandler.AddOnAttributeReadHandler() {

                @Override
                void handle(ModelNode result, PatchableTarget addon) throws OperationFailedException {
                    result.setEmptyList();
                    try {
                        for (final String id : addon.loadTargetInfo().getPatchIDs()) {
                            result.add(id);
                        }
                    } catch (IOException e) {
                        throw new OperationFailedException(PatchLogger.ROOT_LOGGER.failedToLoadInfo(addon.getName()), e);
                    }
                }
            });
        }
    });
}
Also used : PatchableTarget(org.jboss.as.patching.installation.PatchableTarget) SimpleResourceDefinition(org.jboss.as.controller.SimpleResourceDefinition) OperationFailedException(org.jboss.as.controller.OperationFailedException) StandardResourceDescriptionResolver(org.jboss.as.controller.descriptions.StandardResourceDescriptionResolver) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) IOException(java.io.IOException) ModelNode(org.jboss.dmr.ModelNode)

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