Search in sources :

Example 11 with OperationStepHandler

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

the class SecurityDomainAdd method performRuntime.

@Override
protected void performRuntime(OperationContext context, ModelNode operation, final ModelNode model) {
    PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR));
    final String securityDomain = address.getLastElement().getValue();
    // This needs to run after all child resources so that they can detect a fresh state
    context.addStep(new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            final Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
            launchServices(context, securityDomain, Resource.Tools.readModel(resource));
            // Rollback handled by the parent step
            context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
        }
    }, OperationContext.Stage.RUNTIME);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) PathAddress(org.jboss.as.controller.PathAddress) OperationFailedException(org.jboss.as.controller.OperationFailedException) Resource(org.jboss.as.controller.registry.Resource) ModelNode(org.jboss.dmr.ModelNode)

Example 12 with OperationStepHandler

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

the class StackResourceDefinition method register.

@SuppressWarnings("deprecation")
@Override
public void register(ManagementResourceRegistration parentRegistration) {
    ManagementResourceRegistration registration = parentRegistration.registerSubModel(this);
    ResourceDescriptor descriptor = new ResourceDescriptor(this.getResourceDescriptionResolver()).addExtraParameters(TRANSPORT, PROTOCOLS).addCapabilities(Capability.class).addOperationTranslator(new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            if (operation.hasDefined(TRANSPORT.getName())) {
                PathAddress address = context.getCurrentAddress();
                ModelNode transport = operation.get(TRANSPORT.getName());
                String type = AbstractProtocolResourceDefinition.DeprecatedAttribute.TYPE.resolveModelAttribute(context, transport).asString();
                PathElement transportPath = TransportResourceDefinition.pathElement(type);
                PathAddress transportAddress = address.append(transportPath);
                ModelNode transportOperation = Util.createAddOperation(transportAddress);
                OperationEntry addOperationEntry = context.getResourceRegistration().getOperationEntry(PathAddress.pathAddress(TransportResourceDefinition.WILDCARD_PATH), ModelDescriptionConstants.ADD);
                for (AttributeDefinition attribute : addOperationEntry.getOperationDefinition().getParameters()) {
                    String name = attribute.getName();
                    if (transport.hasDefined(name)) {
                        transportOperation.get(name).set(transport.get(name));
                    }
                }
                context.addStep(transportOperation, addOperationEntry.getOperationHandler(), OperationContext.Stage.MODEL);
            }
        }
    }).addOperationTranslator(new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            if (operation.hasDefined(PROTOCOLS.getName())) {
                PathAddress address = context.getCurrentAddress();
                for (ModelNode protocol : operation.get(PROTOCOLS.getName()).asList()) {
                    String type = AbstractProtocolResourceDefinition.DeprecatedAttribute.TYPE.resolveModelAttribute(context, protocol).asString();
                    PathElement protocolPath = ProtocolResourceDefinition.pathElement(type);
                    PathAddress protocolAddress = address.append(protocolPath);
                    ModelNode protocolOperation = Util.createAddOperation(protocolAddress);
                    OperationEntry addOperationEntry = context.getResourceRegistration().getOperationEntry(PathAddress.pathAddress(ProtocolResourceDefinition.WILDCARD_PATH), ModelDescriptionConstants.ADD);
                    for (AttributeDefinition attribute : addOperationEntry.getOperationDefinition().getParameters()) {
                        String name = attribute.getName();
                        if (protocol.hasDefined(name)) {
                            protocolOperation.get(name).set(protocol.get(name));
                        }
                    }
                    context.addStep(protocolOperation, addOperationEntry.getOperationHandler(), OperationContext.Stage.MODEL);
                }
            }
        }
    });
    ResourceServiceHandler handler = new StackServiceHandler(this.builderFactory);
    new SimpleResourceRegistration(descriptor, handler).register(registration);
    OperationDefinition legacyAddProtocolOperation = new SimpleOperationDefinitionBuilder("add-protocol", this.getResourceDescriptionResolver()).setParameters(SocketBindingProtocolResourceDefinition.Attribute.SOCKET_BINDING.getDefinition()).addParameter(AbstractProtocolResourceDefinition.DeprecatedAttribute.TYPE.getDefinition()).addParameter(AbstractProtocolResourceDefinition.Attribute.PROPERTIES.getDefinition()).setDeprecated(JGroupsModel.VERSION_3_0_0.getVersion()).build();
    // Transform legacy /subsystem=jgroups/stack=*:add-protocol() operation -> /subsystem=jgroups/stack=*/protocol=*:add()
    OperationStepHandler legacyAddProtocolHandler = new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) {
            PathAddress address = context.getCurrentAddress();
            String protocol = operation.require(AbstractProtocolResourceDefinition.DeprecatedAttribute.TYPE.getName()).asString();
            PathElement protocolPath = ProtocolResourceDefinition.pathElement(protocol);
            PathAddress protocolAddress = address.append(protocolPath);
            ModelNode protocolOperation = Util.createAddOperation(protocolAddress);
            OperationEntry addOperationEntry = context.getResourceRegistration().getOperationEntry(PathAddress.pathAddress(ProtocolResourceDefinition.WILDCARD_PATH), ModelDescriptionConstants.ADD);
            for (AttributeDefinition attribute : addOperationEntry.getOperationDefinition().getParameters()) {
                String name = attribute.getName();
                if (operation.hasDefined(name)) {
                    protocolOperation.get(name).set(operation.get(name));
                }
            }
            context.addStep(protocolOperation, addOperationEntry.getOperationHandler(), OperationContext.Stage.MODEL);
        }
    };
    registration.registerOperationHandler(legacyAddProtocolOperation, legacyAddProtocolHandler);
    OperationDefinition legacyRemoveProtocolOperation = new SimpleOperationDefinitionBuilder("remove-protocol", this.getResourceDescriptionResolver()).setParameters(AbstractProtocolResourceDefinition.DeprecatedAttribute.TYPE.getDefinition()).setDeprecated(JGroupsModel.VERSION_3_0_0.getVersion()).build();
    // Transform legacy /subsystem=jgroups/stack=*:remove-protocol() operation -> /subsystem=jgroups/stack=*/protocol=*:remove()
    OperationStepHandler legacyRemoveProtocolHandler = new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) {
            PathAddress address = context.getCurrentAddress();
            String protocol = operation.require(AbstractProtocolResourceDefinition.DeprecatedAttribute.TYPE.getName()).asString();
            PathElement protocolPath = ProtocolResourceDefinition.pathElement(protocol);
            PathAddress protocolAddress = address.append(protocolPath);
            ModelNode removeOperation = Util.createRemoveOperation(protocolAddress);
            context.addStep(removeOperation, context.getResourceRegistration().getOperationHandler(PathAddress.pathAddress(ProtocolResourceDefinition.WILDCARD_PATH), ModelDescriptionConstants.REMOVE), context.getCurrentStage());
        }
    };
    registration.registerOperationHandler(legacyRemoveProtocolOperation, legacyRemoveProtocolHandler);
    if (this.allowRuntimeOnlyRegistration) {
        new OperationHandler<>(new StackOperationExecutor(), StackOperation.class).register(registration);
    }
    new TransportRegistration(this.builderFactory).register(registration);
    new ProtocolRegistration(this.builderFactory).register(registration);
    new RelayResourceDefinition(this.builderFactory).register(registration);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) SimpleOperationDefinitionBuilder(org.jboss.as.controller.SimpleOperationDefinitionBuilder) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) OperationEntry(org.jboss.as.controller.registry.OperationEntry) OperationFailedException(org.jboss.as.controller.OperationFailedException) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) ObjectListAttributeDefinition(org.jboss.as.controller.ObjectListAttributeDefinition) ObjectTypeAttributeDefinition(org.jboss.as.controller.ObjectTypeAttributeDefinition) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) SimpleResourceRegistration(org.jboss.as.clustering.controller.SimpleResourceRegistration) PathElement(org.jboss.as.controller.PathElement) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode) ResourceServiceHandler(org.jboss.as.clustering.controller.ResourceServiceHandler) OperationDefinition(org.jboss.as.controller.OperationDefinition) ResourceDescriptor(org.jboss.as.clustering.controller.ResourceDescriptor)

Example 13 with OperationStepHandler

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

the class PropertyResourceDefinition method register.

@Override
public void register(ManagementResourceRegistration parentRegistration) {
    ManagementResourceRegistration registration = parentRegistration.registerSubModel(this);
    // Delegate add of property to "properties" attribute of parent protocol
    AbstractAddStepHandler addHandler = new AbstractAddStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) {
            this.createResource(context);
            String name = context.getCurrentAddressValue();
            String value = operation.get(VALUE.getName()).asString();
            PathAddress storeAddress = context.getCurrentAddress().getParent();
            ModelNode putOperation = Operations.createMapPutOperation(storeAddress, AbstractProtocolResourceDefinition.Attribute.PROPERTIES, name, value);
            context.addStep(putOperation, MapOperations.MAP_PUT_HANDLER, context.getCurrentStage());
        }
    };
    this.registerAddOperation(registration, addHandler);
    // Delegate remove of property to "properties" attribute of parent protocol
    AbstractRemoveStepHandler removeHandler = new AbstractRemoveStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) {
            context.removeResource(PathAddress.EMPTY_ADDRESS);
            String name = context.getCurrentAddressValue();
            PathAddress storeAddress = context.getCurrentAddress().getParent();
            ModelNode putOperation = Operations.createMapRemoveOperation(storeAddress, AbstractProtocolResourceDefinition.Attribute.PROPERTIES, name);
            context.addStep(putOperation, MapOperations.MAP_REMOVE_HANDLER, context.getCurrentStage());
        }
    };
    this.registerRemoveOperation(registration, removeHandler);
    // Delegate read of property value to "properties" attribute of parent protocol
    OperationStepHandler readHandler = new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) {
            PathAddress address = context.getCurrentAddress().getParent();
            String key = context.getCurrentAddressValue();
            ModelNode getOperation = Operations.createMapGetOperation(address, AbstractProtocolResourceDefinition.Attribute.PROPERTIES, key);
            context.addStep(getOperation, MapOperations.MAP_GET_HANDLER, context.getCurrentStage());
        }
    };
    // Delegate write of property value to "properties" attribute of parent protocol
    OperationStepHandler writeHandler = new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) {
            PathAddress address = context.getCurrentAddress().getParent();
            String key = context.getCurrentAddressValue();
            String value = Operations.getAttributeValue(operation).asString();
            ModelNode putOperation = Operations.createMapPutOperation(address, AbstractProtocolResourceDefinition.Attribute.PROPERTIES, key, value);
            context.addStep(putOperation, MapOperations.MAP_PUT_HANDLER, context.getCurrentStage());
        }
    };
    registration.registerReadWriteAttribute(VALUE, readHandler, writeHandler);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) AbstractAddStepHandler(org.jboss.as.controller.AbstractAddStepHandler) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) PathAddress(org.jboss.as.controller.PathAddress) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) ModelNode(org.jboss.dmr.ModelNode) AbstractRemoveStepHandler(org.jboss.as.controller.AbstractRemoveStepHandler)

Example 14 with OperationStepHandler

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

the class DistributedWorkManagerStatisticsService method start.

@Override
public void start(StartContext context) throws StartException {
    synchronized (this) {
        DistributedWorkManager dwm = distributedWorkManager.getValue();
        dwm.setDistributedStatisticsEnabled(statsEnabled);
        if (dwm.getDistributedStatistics() != null) {
            PathElement peDistributedWm = PathElement.pathElement(Constants.STATISTICS_NAME, "distributed");
            ResourceBuilder resourceBuilder = ResourceBuilder.Factory.create(peDistributedWm, new StandardResourceDescriptionResolver(Constants.STATISTICS_NAME + "." + Constants.WORKMANAGER_NAME, CommonAttributes.RESOURCE_NAME, CommonAttributes.class.getClassLoader()));
            ManagementResourceRegistration dwmSubRegistration = overrideRegistration.registerSubModel(resourceBuilder.build());
            OperationStepHandler metricHandler = new WorkManagerRuntimeAttributeReadHandler(dwm, dwm.getDistributedStatistics(), false);
            for (SimpleAttributeDefinition metric : Constants.WORKMANAGER_METRICS) {
                dwmSubRegistration.registerMetric(metric, metricHandler);
            }
            OperationStepHandler readHandler = new WorkManagerRuntimeAttributeReadHandler(dwm, dwm.getDistributedStatistics(), false);
            OperationStepHandler writeHandler = new WorkManagerRuntimeAttributeWriteHandler(dwm, false, Constants.DISTRIBUTED_WORKMANAGER_RW_ATTRIBUTES);
            for (SimpleAttributeDefinition attribute : Constants.DISTRIBUTED_WORKMANAGER_RW_ATTRIBUTES) {
                dwmSubRegistration.registerReadWriteAttribute(attribute, readHandler, writeHandler);
            }
            dwmSubRegistration.registerOperationHandler(ClearWorkManagerStatisticsHandler.DEFINITION, new ClearWorkManagerStatisticsHandler(dwm));
        }
    }
}
Also used : ResourceBuilder(org.jboss.as.controller.ResourceBuilder) DistributedWorkManager(org.jboss.jca.core.api.workmanager.DistributedWorkManager) PathElement(org.jboss.as.controller.PathElement) WorkManagerRuntimeAttributeWriteHandler(org.jboss.as.connector.subsystems.resourceadapters.WorkManagerRuntimeAttributeWriteHandler) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) StandardResourceDescriptionResolver(org.jboss.as.controller.descriptions.StandardResourceDescriptionResolver) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) WorkManagerRuntimeAttributeReadHandler(org.jboss.as.connector.subsystems.resourceadapters.WorkManagerRuntimeAttributeReadHandler) ClearWorkManagerStatisticsHandler(org.jboss.as.connector.dynamicresource.ClearWorkManagerStatisticsHandler)

Example 15 with OperationStepHandler

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

the class WorkManagerStatisticsService method start.

@Override
public void start(StartContext context) throws StartException {
    synchronized (this) {
        WorkManager wm = workManager.getValue();
        wm.setStatisticsEnabled(statsEnabled);
        if (wm.getStatistics() != null) {
            PathElement peLocaldWm = PathElement.pathElement(Constants.STATISTICS_NAME, "local");
            ResourceBuilder resourceBuilder = ResourceBuilder.Factory.create(peLocaldWm, new StandardResourceDescriptionResolver(Constants.STATISTICS_NAME + "." + Constants.WORKMANAGER_NAME, CommonAttributes.RESOURCE_NAME, CommonAttributes.class.getClassLoader()));
            ManagementResourceRegistration wmSubRegistration = overrideRegistration.registerSubModel(resourceBuilder.build());
            OperationStepHandler metricHandler = new WorkManagerRuntimeAttributeReadHandler(wm, wm.getStatistics(), false);
            for (SimpleAttributeDefinition metric : Constants.WORKMANAGER_METRICS) {
                wmSubRegistration.registerMetric(metric, metricHandler);
            }
            OperationStepHandler readHandler = new WorkManagerRuntimeAttributeReadHandler(wm, wm.getStatistics(), false);
            OperationStepHandler writeHandler = new WorkManagerRuntimeAttributeWriteHandler(wm, false, Constants.WORKMANAGER_RW_ATTRIBUTES);
            for (SimpleAttributeDefinition attribute : Constants.WORKMANAGER_RW_ATTRIBUTES) {
                wmSubRegistration.registerReadWriteAttribute(attribute, readHandler, writeHandler);
            }
            wmSubRegistration.registerOperationHandler(ClearWorkManagerStatisticsHandler.DEFINITION, new ClearWorkManagerStatisticsHandler(wm));
        }
    }
}
Also used : ResourceBuilder(org.jboss.as.controller.ResourceBuilder) PathElement(org.jboss.as.controller.PathElement) WorkManagerRuntimeAttributeWriteHandler(org.jboss.as.connector.subsystems.resourceadapters.WorkManagerRuntimeAttributeWriteHandler) WorkManager(org.jboss.jca.core.api.workmanager.WorkManager) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) StandardResourceDescriptionResolver(org.jboss.as.controller.descriptions.StandardResourceDescriptionResolver) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) WorkManagerRuntimeAttributeReadHandler(org.jboss.as.connector.subsystems.resourceadapters.WorkManagerRuntimeAttributeReadHandler) ClearWorkManagerStatisticsHandler(org.jboss.as.connector.dynamicresource.ClearWorkManagerStatisticsHandler)

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