Search in sources :

Example 31 with OperationStepHandler

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

the class StatisticsResourceDefinition method registerAttributes.

@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
    super.registerAttributes(resourceRegistration);
    for (AttributeDefinition attribute : getAttributesFromPlugin(plugin)) {
        resourceRegistration.registerMetric(attribute, new PoolMetrics.ParametrizedPoolMetricsHandler(plugin));
    }
    //adding enable/disable for pool stats
    OperationStepHandler readHandler = new PoolStatisticsRuntimeAttributeReadHandler(plugin);
    OperationStepHandler writeHandler = new PoolStatisticsRuntimeAttributeWriteHandler(plugin);
    resourceRegistration.registerReadWriteAttribute(org.jboss.as.connector.subsystems.common.pool.Constants.POOL_STATISTICS_ENABLED, readHandler, writeHandler);
}
Also used : OperationStepHandler(org.jboss.as.controller.OperationStepHandler) PoolStatisticsRuntimeAttributeWriteHandler(org.jboss.as.connector.subsystems.common.pool.PoolStatisticsRuntimeAttributeWriteHandler) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) PoolStatisticsRuntimeAttributeReadHandler(org.jboss.as.connector.subsystems.common.pool.PoolStatisticsRuntimeAttributeReadHandler) PoolMetrics(org.jboss.as.connector.subsystems.common.pool.PoolMetrics)

Example 32 with OperationStepHandler

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

the class BatchSubsystemDefinition method registerAttributes.

@Override
public void registerAttributes(final ManagementResourceRegistration resourceRegistration) {
    super.registerAttributes(resourceRegistration);
    final OperationStepHandler writeHandler = new ReloadRequiredWriteAttributeHandler(DEFAULT_JOB_REPOSITORY, DEFAULT_THREAD_POOL, SECURITY_DOMAIN);
    resourceRegistration.registerReadWriteAttribute(DEFAULT_JOB_REPOSITORY, null, writeHandler);
    resourceRegistration.registerReadWriteAttribute(DEFAULT_THREAD_POOL, null, writeHandler);
    resourceRegistration.registerReadWriteAttribute(SECURITY_DOMAIN, null, writeHandler);
    resourceRegistration.registerReadWriteAttribute(RESTART_JOBS_ON_RESUME, null, new AbstractWriteAttributeHandler<Boolean>(RESTART_JOBS_ON_RESUME) {

        @Override
        protected boolean applyUpdateToRuntime(final OperationContext context, final ModelNode operation, final String attributeName, final ModelNode resolvedValue, final ModelNode currentValue, final HandbackHolder<Boolean> handbackHolder) throws OperationFailedException {
            setValue(context, resolvedValue);
            return false;
        }

        @Override
        protected void revertUpdateToRuntime(final OperationContext context, final ModelNode operation, final String attributeName, final ModelNode valueToRestore, final ModelNode valueToRevert, final Boolean handback) throws OperationFailedException {
            setValue(context, valueToRestore);
        }

        private void setValue(final OperationContext context, final ModelNode value) {
            final BatchConfigurationService service = (BatchConfigurationService) context.getServiceRegistry(true).getService(context.getCapabilityServiceName(Capabilities.BATCH_CONFIGURATION_CAPABILITY.getName(), BatchConfiguration.class)).getService();
            service.setRestartOnResume(value.asBoolean());
        }
    });
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) OperationFailedException(org.jboss.as.controller.OperationFailedException) ModelNode(org.jboss.dmr.ModelNode) ReloadRequiredWriteAttributeHandler(org.jboss.as.controller.ReloadRequiredWriteAttributeHandler)

Example 33 with OperationStepHandler

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

the class AddStepHandler method execute.

@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    PathAddress address = context.getCurrentAddress();
    PathAddress parentAddress = address.getParent();
    PathElement path = address.getLastElement();
    OperationStepHandler parentHandler = context.getRootResourceRegistration().getOperationHandler(parentAddress, ModelDescriptionConstants.ADD);
    if (parentHandler instanceof DescribedAddStepHandler) {
        AddStepHandlerDescriptor parentDescriptor = ((DescribedAddStepHandler) parentHandler).getDescriptor();
        if (parentDescriptor.getRequiredChildren().contains(path)) {
            if (context.readResourceFromRoot(parentAddress, false).hasChild(path)) {
                // If we are a required child resource of our parent, we need to remove the auto-created resource first
                context.addStep(Util.createRemoveOperation(address), context.getRootResourceRegistration().getOperationHandler(address, ModelDescriptionConstants.REMOVE), OperationContext.Stage.MODEL);
                context.addStep(operation, this, OperationContext.Stage.MODEL);
                return;
            }
        } else {
            Optional<PathElement> singletonPathResult = parentDescriptor.getRequiredSingletonChildren().stream().filter((PathElement requiredPath) -> requiredPath.getKey().equals(path.getKey()) && !requiredPath.getValue().equals(path.getValue())).findFirst();
            if (singletonPathResult.isPresent()) {
                PathElement singletonPath = singletonPathResult.get();
                if (context.readResourceFromRoot(parentAddress, false).hasChild(singletonPath)) {
                    // If there is a required singleton sibling resource, we need to remove it first
                    PathAddress singletonAddress = parentAddress.append(singletonPath);
                    context.addStep(Util.createRemoveOperation(singletonAddress), context.getRootResourceRegistration().getOperationHandler(singletonAddress, ModelDescriptionConstants.REMOVE), OperationContext.Stage.MODEL);
                    context.addStep(operation, this, OperationContext.Stage.MODEL);
                    return;
                }
            }
        }
    }
    super.execute(context, operation);
    if (this.requiresRuntime(context)) {
        this.descriptor.getRuntimeResourceRegistrations().forEach(registration -> context.addStep(registration, OperationContext.Stage.MODEL));
    }
}
Also used : PathElement(org.jboss.as.controller.PathElement) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) PathAddress(org.jboss.as.controller.PathAddress)

Example 34 with OperationStepHandler

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

the class ManagementHelper method checkNoOtherSibling.

static OperationStepHandler checkNoOtherSibling(final String childType) {
    return new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            PathAddress parentAddress = context.getCurrentAddress().getParent();
            Resource parent = context.readResourceFromRoot(parentAddress, false);
            Set<String> children = parent.getChildrenNames(childType);
            if (children.size() > 1) {
                throw MessagingLogger.ROOT_LOGGER.onlyOneChildIsAllowed(childType, children);
            }
        }
    };
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource) ModelNode(org.jboss.dmr.ModelNode)

Example 35 with OperationStepHandler

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

the class AbstractUpdateJndiHandler method execute.

@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    JNDI_BINDING.validateOperation(operation);
    final String jndiName = JNDI_BINDING.resolveModelAttribute(context, operation).asString();
    final ModelNode entries = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS).getModel().get(CommonAttributes.DESTINATION_ENTRIES.getName());
    if (addOperation) {
        for (ModelNode entry : entries.asList()) {
            if (jndiName.equals(entry.asString())) {
                throw new OperationFailedException(ROOT_LOGGER.jndiNameAlreadyRegistered(jndiName));
            }
        }
        entries.add(jndiName);
    } else {
        ModelNode updatedEntries = new ModelNode();
        boolean updated = false;
        for (ModelNode entry : entries.asList()) {
            if (jndiName.equals(entry.asString())) {
                if (entries.asList().size() == 1) {
                    throw new OperationFailedException(ROOT_LOGGER.canNotRemoveLastJNDIName(jndiName));
                }
                updated = true;
            } else {
                updatedEntries.add(entry);
            }
        }
        if (!updated) {
            throw MessagingLogger.ROOT_LOGGER.canNotRemoveUnknownEntry(jndiName);
        }
        context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS).getModel().get(CommonAttributes.DESTINATION_ENTRIES.getName()).set(updatedEntries);
    }
    if (context.isNormalServer()) {
        if (rollbackOperationIfServerNotActive(context, operation)) {
            return;
        }
        context.addStep(new OperationStepHandler() {

            @Override
            public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
                final String resourceName = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue();
                final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
                final ServiceName jmsManagerServiceName = JMSServices.getJmsManagerBaseServiceName(serviceName);
                final ServiceController<?> jmsServerService = context.getServiceRegistry(false).getService(jmsManagerServiceName);
                if (jmsServerService != null) {
                    JMSServerManager jmsServerManager = JMSServerManager.class.cast(jmsServerService.getValue());
                    if (jmsServerManager == null) {
                        PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
                        throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(address);
                    }
                    try {
                        if (addOperation) {
                            addJndiName(jmsServerManager, resourceName, jndiName);
                        } else {
                            removeJndiName(jmsServerManager, resourceName, jndiName);
                        }
                    } catch (Exception e) {
                        context.getFailureDescription().set(e.getLocalizedMessage());
                    }
                }
                if (!context.hasFailureDescription()) {
                    context.getResult();
                }
                context.completeStep(new OperationContext.RollbackHandler() {

                    @Override
                    public void handleRollback(OperationContext context, ModelNode operation) {
                        if (jmsServerService != null) {
                            JMSServerManager jmsServerManager = JMSServerManager.class.cast(jmsServerService.getValue());
                            try {
                                if (addOperation) {
                                    removeJndiName(jmsServerManager, resourceName, jndiName);
                                } else {
                                    addJndiName(jmsServerManager, resourceName, jndiName);
                                }
                            } catch (Exception e) {
                                context.getFailureDescription().set(e.getLocalizedMessage());
                            }
                        }
                    }
                });
            }
        }, OperationContext.Stage.RUNTIME);
    }
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) JMSServerManager(org.apache.activemq.artemis.jms.server.JMSServerManager) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) OperationFailedException(org.jboss.as.controller.OperationFailedException) OperationFailedException(org.jboss.as.controller.OperationFailedException) ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress) ServiceController(org.jboss.msc.service.ServiceController) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

OperationStepHandler (org.jboss.as.controller.OperationStepHandler)48 ModelNode (org.jboss.dmr.ModelNode)39 OperationContext (org.jboss.as.controller.OperationContext)37 OperationFailedException (org.jboss.as.controller.OperationFailedException)31 PathAddress (org.jboss.as.controller.PathAddress)18 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)12 Resource (org.jboss.as.controller.registry.Resource)11 PathElement (org.jboss.as.controller.PathElement)8 SimpleAttributeDefinition (org.jboss.as.controller.SimpleAttributeDefinition)8 ManagementResourceRegistration (org.jboss.as.controller.registry.ManagementResourceRegistration)7 ServiceController (org.jboss.msc.service.ServiceController)7 ServiceName (org.jboss.msc.service.ServiceName)7 Map (java.util.Map)5 ArrayList (java.util.ArrayList)4 ResourceServiceHandler (org.jboss.as.clustering.controller.ResourceServiceHandler)4 ReloadRequiredWriteAttributeHandler (org.jboss.as.controller.ReloadRequiredWriteAttributeHandler)4 Collection (java.util.Collection)3 LinkedHashMap (java.util.LinkedHashMap)3 List (java.util.List)3 ResourceDescriptor (org.jboss.as.clustering.controller.ResourceDescriptor)3