Search in sources :

Example 56 with AttributeDefinition

use of org.jboss.as.controller.AttributeDefinition in project wildfly by wildfly.

the class ConnectionFactoryWriteAttributeHandler method applyUpdateToRuntime.

@Override
protected boolean applyUpdateToRuntime(final OperationContext context, final ModelNode operation, final String attributeName, final ModelNode newValue, final ModelNode currentValue, final HandbackHolder<Void> handbackHolder) throws OperationFailedException {
    AttributeDefinition attr = getAttributeDefinition(attributeName);
    if (attr.getFlags().contains(AttributeAccess.Flag.RESTART_ALL_SERVICES)) {
        // Restart required
        return true;
    }
    ServiceRegistry registry = context.getServiceRegistry(true);
    final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
    ServiceController<?> service = registry.getService(serviceName);
    if (service == null) {
        // The service isn't installed, so the work done in the Stage.MODEL part is all there is to it
        return false;
    } else if (service.getState() != ServiceController.State.UP) {
        // No, don't barf; just let the update apply to the model and put the server in a reload-required state
        return true;
    } else {
        if (!ActiveMQActivationService.isActiveMQServerActive(context, operation)) {
            return false;
        }
        // Actually apply the update
        applyOperationToActiveMQService(context, getName(operation), attributeName, newValue, service);
        return false;
    }
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) ServiceRegistry(org.jboss.msc.service.ServiceRegistry)

Example 57 with AttributeDefinition

use of org.jboss.as.controller.AttributeDefinition in project wildfly by wildfly.

the class ModClusterAddCustomMetric method execute.

@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    PathAddress opAddress = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));
    PathAddress parent = opAddress.append(DynamicLoadProviderDefinition.PATH);
    String name = CustomLoadMetricDefinition.CLASS.resolveModelAttribute(context, operation).asString();
    ModelNode targetOperation = Util.createAddOperation(parent.append(PathElement.pathElement(CustomLoadMetricDefinition.PATH.getKey(), name)));
    for (AttributeDefinition def : CustomLoadMetricDefinition.ATTRIBUTES) {
        def.validateAndSet(operation, targetOperation);
    }
    context.addStep(targetOperation, CustomLoadMetricAdd.INSTANCE, OperationContext.Stage.MODEL, true);
    context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) ModelNode(org.jboss.dmr.ModelNode)

Example 58 with AttributeDefinition

use of org.jboss.as.controller.AttributeDefinition in project wildfly by wildfly.

the class ModClusterAddMetric method execute.

@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    PathAddress opAddress = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));
    PathAddress parent = opAddress.append(DynamicLoadProviderDefinition.PATH);
    String name = LoadMetricDefinition.TYPE.resolveModelAttribute(context, operation).asString();
    ModelNode targetOperation = Util.createAddOperation(parent.append(PathElement.pathElement(LoadMetricDefinition.PATH.getKey(), name)));
    for (AttributeDefinition def : LoadMetricDefinition.ATTRIBUTES) {
        def.validateAndSet(operation, targetOperation);
    }
    context.addStep(targetOperation, LoadMetricAdd.INSTANCE, OperationContext.Stage.MODEL, true);
    context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) ModelNode(org.jboss.dmr.ModelNode)

Example 59 with AttributeDefinition

use of org.jboss.as.controller.AttributeDefinition in project wildfly by wildfly.

the class SAMLResourceDefinition method createAttributeWriterHandler.

@Override
protected OperationStepHandler createAttributeWriterHandler() {
    List<SimpleAttributeDefinition> attributes = getAttributes();
    return new AbstractWriteAttributeHandler(attributes.toArray(new AttributeDefinition[attributes.size()])) {

        @Override
        protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode resolvedValue, ModelNode currentValue, HandbackHolder handbackHolder) throws OperationFailedException {
            PathAddress pathAddress = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));
            updateConfiguration(context, pathAddress, false);
            return false;
        }

        @Override
        protected void revertUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode valueToRestore, ModelNode valueToRevert, Object handback) throws OperationFailedException {
            PathAddress pathAddress = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));
            updateConfiguration(context, pathAddress, true);
        }

        private void updateConfiguration(OperationContext context, PathAddress pathAddress, boolean rollback) throws OperationFailedException {
            String federationAlias = pathAddress.subAddress(0, pathAddress.size() - 1).getLastElement().getValue();
            ServiceRegistry serviceRegistry = context.getServiceRegistry(false);
            ServiceController<SAMLService> serviceController = (ServiceController<SAMLService>) serviceRegistry.getService(SAMLService.createServiceName(federationAlias));
            if (serviceController != null) {
                SAMLService service = serviceController.getValue();
                ModelNode samlNode;
                if (!rollback) {
                    samlNode = context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel();
                } else {
                    Resource rc = context.getOriginalRootResource().navigate(pathAddress);
                    samlNode = rc.getModel();
                }
                service.setStsType(SAMLAddHandler.toSAMLConfig(context, samlNode));
            }
        }
    };
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) Resource(org.jboss.as.controller.registry.Resource) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) AbstractWriteAttributeHandler(org.jboss.as.controller.AbstractWriteAttributeHandler) PathAddress(org.jboss.as.controller.PathAddress) ServiceController(org.jboss.msc.service.ServiceController) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ModelNode(org.jboss.dmr.ModelNode) SAMLService(org.wildfly.extension.picketlink.federation.service.SAMLService)

Example 60 with AttributeDefinition

use of org.jboss.as.controller.AttributeDefinition in project wildfly by wildfly.

the class KeyStoreProviderResourceDefinition method createAttributeWriterHandler.

@Override
protected OperationStepHandler createAttributeWriterHandler() {
    List<SimpleAttributeDefinition> attributes = getAttributes();
    return new AbstractWriteAttributeHandler(attributes.toArray(new AttributeDefinition[attributes.size()])) {

        @Override
        protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode resolvedValue, ModelNode currentValue, HandbackHolder handbackHolder) throws OperationFailedException {
            PathAddress pathAddress = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));
            updateConfiguration(context, pathAddress, false);
            return false;
        }

        @Override
        protected void revertUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode valueToRestore, ModelNode valueToRevert, Object handback) throws OperationFailedException {
            PathAddress pathAddress = PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR));
            updateConfiguration(context, pathAddress, true);
        }

        private void updateConfiguration(OperationContext context, PathAddress pathAddress, boolean rollback) throws OperationFailedException {
            String federationAlias = pathAddress.subAddress(0, pathAddress.size() - 1).getLastElement().getValue();
            ServiceRegistry serviceRegistry = context.getServiceRegistry(false);
            ServiceController<KeyStoreProviderService> serviceController = (ServiceController<KeyStoreProviderService>) serviceRegistry.getService(KeyStoreProviderService.createServiceName(federationAlias));
            if (serviceController != null) {
                KeyStoreProviderService service = serviceController.getValue();
                ModelNode keyStoreProviderNode;
                if (!rollback) {
                    keyStoreProviderNode = context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel();
                } else {
                    Resource rc = context.getOriginalRootResource().navigate(pathAddress);
                    keyStoreProviderNode = rc.getModel();
                }
                ModelNode relativeToNode = KeyStoreProviderResourceDefinition.RELATIVE_TO.resolveModelAttribute(context, keyStoreProviderNode);
                String relativeTo = null;
                if (relativeToNode.isDefined()) {
                    relativeTo = relativeToNode.asString();
                }
                String file = KeyStoreProviderResourceDefinition.FILE.resolveModelAttribute(context, keyStoreProviderNode).asString();
                service.setKeyProviderType(KeyStoreProviderAddHandler.toKeyProviderType(context, keyStoreProviderNode), file, relativeTo);
            }
        }
    };
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) Resource(org.jboss.as.controller.registry.Resource) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) AbstractWriteAttributeHandler(org.jboss.as.controller.AbstractWriteAttributeHandler) PathAddress(org.jboss.as.controller.PathAddress) ServiceController(org.jboss.msc.service.ServiceController) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ModelNode(org.jboss.dmr.ModelNode) KeyStoreProviderService(org.wildfly.extension.picketlink.federation.service.KeyStoreProviderService)

Aggregations

AttributeDefinition (org.jboss.as.controller.AttributeDefinition)102 ModelNode (org.jboss.dmr.ModelNode)48 SimpleAttributeDefinition (org.jboss.as.controller.SimpleAttributeDefinition)40 PathAddress (org.jboss.as.controller.PathAddress)17 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)16 ReloadRequiredWriteAttributeHandler (org.jboss.as.controller.ReloadRequiredWriteAttributeHandler)14 OperationContext (org.jboss.as.controller.OperationContext)13 Resource (org.jboss.as.controller.registry.Resource)12 Property (org.jboss.dmr.Property)12 ObjectTypeAttributeDefinition (org.jboss.as.controller.ObjectTypeAttributeDefinition)9 PropertiesAttributeDefinition (org.jboss.as.controller.PropertiesAttributeDefinition)9 StringListAttributeDefinition (org.jboss.as.controller.StringListAttributeDefinition)9 OperationFailedException (org.jboss.as.controller.OperationFailedException)8 ArrayList (java.util.ArrayList)7 PrimitiveListAttributeDefinition (org.jboss.as.controller.PrimitiveListAttributeDefinition)6 Map (java.util.Map)5 AbstractAddStepHandler (org.jboss.as.controller.AbstractAddStepHandler)5 SimpleListAttributeDefinition (org.jboss.as.controller.SimpleListAttributeDefinition)5 SimpleOperationDefinitionBuilder (org.jboss.as.controller.SimpleOperationDefinitionBuilder)5 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)5