Search in sources :

Example 66 with OperationContext

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

the class ServerRemove method performRemove.

@Override
protected void performRemove(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
    // add a runtime step to remove services related to broadcast-group/discovery-group that are started
    // when the server is added.
    context.addStep(new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            final String serverName = context.getCurrentAddressValue();
            final ServiceName serviceName = MessagingServices.getActiveMQServiceName(serverName);
            for (final Resource.ResourceEntry broadcastGroup : resource.getChildren(CommonAttributes.BROADCAST_GROUP)) {
                context.removeService(GroupBindingService.getBroadcastBaseServiceName(serviceName).append(broadcastGroup.getName()));
            }
            for (final Resource.ResourceEntry divertGroup : resource.getChildren(CommonAttributes.DISCOVERY_GROUP)) {
                context.removeService(GroupBindingService.getDiscoveryBaseServiceName(serviceName).append(divertGroup.getName()));
            }
        }
    }, OperationContext.Stage.RUNTIME);
    super.performRemove(context, operation, model);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) ServiceName(org.jboss.msc.service.ServiceName) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) Resource(org.jboss.as.controller.registry.Resource) OperationFailedException(org.jboss.as.controller.OperationFailedException) ModelNode(org.jboss.dmr.ModelNode)

Example 67 with OperationContext

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

the class GroupingHandlerAdd method performRuntime.

@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    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) {
        final ActiveMQServer server = ActiveMQServer.class.cast(service.getValue());
        if (server.getGroupingHandler() != null) {
            throw new OperationFailedException(MessagingLogger.ROOT_LOGGER.childResourceAlreadyExists(CommonAttributes.GROUPING_HANDLER));
        }
        // the groupingHandler is added as a child of the server resource. Requires a reload to restart the server with the grouping-handler
        if (context.isNormalServer()) {
            context.addStep(new OperationStepHandler() {

                public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
                    context.reloadRequired();
                    context.completeStep(OperationContext.RollbackHandler.REVERT_RELOAD_REQUIRED_ROLLBACK_HANDLER);
                }
            }, OperationContext.Stage.RUNTIME);
        }
    }
// else the initial subsystem install is not complete and the grouping handler will be added in ServerAdd
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ServiceName(org.jboss.msc.service.ServiceName) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) OperationFailedException(org.jboss.as.controller.OperationFailedException) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

OperationContext (org.jboss.as.controller.OperationContext)67 ModelNode (org.jboss.dmr.ModelNode)67 OperationFailedException (org.jboss.as.controller.OperationFailedException)51 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)40 PathAddress (org.jboss.as.controller.PathAddress)34 ServiceController (org.jboss.msc.service.ServiceController)18 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)17 Resource (org.jboss.as.controller.registry.Resource)16 ServiceName (org.jboss.msc.service.ServiceName)13 SimpleAttributeDefinition (org.jboss.as.controller.SimpleAttributeDefinition)11 ServiceTarget (org.jboss.msc.service.ServiceTarget)11 ResourceServiceHandler (org.jboss.as.clustering.controller.ResourceServiceHandler)9 AbstractAddStepHandler (org.jboss.as.controller.AbstractAddStepHandler)8 InjectedValue (org.jboss.msc.value.InjectedValue)8 EnumSet (java.util.EnumSet)7 Map (java.util.Map)7 PathElement (org.jboss.as.controller.PathElement)7 ManagementResourceRegistration (org.jboss.as.controller.registry.ManagementResourceRegistration)7 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)7 ArrayList (java.util.ArrayList)6