Search in sources :

Example 1 with SimpleOperationDefinitionBuilder

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

the class ModClusterConfigResourceDefinition method registerOperations.

@Override
public void registerOperations(ManagementResourceRegistration resourceRegistration) {
    super.registerOperations(resourceRegistration);
    final ResourceDescriptionResolver rootResolver = getResourceDescriptionResolver();
    final OperationDefinition addMetricDef = new SimpleOperationDefinitionBuilder(CommonAttributes.ADD_METRIC, rootResolver).setParameters(LoadMetricDefinition.ATTRIBUTES).setRuntimeOnly().build();
    final OperationDefinition addCustomDef = new SimpleOperationDefinitionBuilder(CommonAttributes.ADD_CUSTOM_METRIC, rootResolver).setParameters(CustomLoadMetricDefinition.ATTRIBUTES).setRuntimeOnly().build();
    final OperationDefinition removeMetricDef = new SimpleOperationDefinitionBuilder(CommonAttributes.REMOVE_METRIC, rootResolver).setParameters(LoadMetricDefinition.TYPE).setRuntimeOnly().build();
    final OperationDefinition removeCustomDef = new SimpleOperationDefinitionBuilder(CommonAttributes.REMOVE_CUSTOM_METRIC, rootResolver).setParameters(CustomLoadMetricDefinition.CLASS).setRuntimeOnly().build();
    resourceRegistration.registerOperationHandler(addMetricDef, ModClusterAddMetric.INSTANCE);
    resourceRegistration.registerOperationHandler(addCustomDef, ModClusterAddCustomMetric.INSTANCE);
    resourceRegistration.registerOperationHandler(removeMetricDef, ModClusterRemoveMetric.INSTANCE);
    resourceRegistration.registerOperationHandler(removeCustomDef, ModClusterRemoveCustomMetric.INSTANCE);
}
Also used : SimpleOperationDefinitionBuilder(org.jboss.as.controller.SimpleOperationDefinitionBuilder) ResourceDescriptionResolver(org.jboss.as.controller.descriptions.ResourceDescriptionResolver) OperationDefinition(org.jboss.as.controller.OperationDefinition)

Example 2 with SimpleOperationDefinitionBuilder

use of org.jboss.as.controller.SimpleOperationDefinitionBuilder 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 3 with SimpleOperationDefinitionBuilder

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

the class MessageDrivenBeanResourceDefinition method registerOperations.

@Override
public void registerOperations(ManagementResourceRegistration registry) {
    super.registerOperations(registry);
    final SimpleOperationDefinition startDelivery = new SimpleOperationDefinitionBuilder(START_DELIVERY, getResourceDescriptionResolver()).setRuntimeOnly().build();
    registry.registerOperationHandler(startDelivery, MessageDrivenBeanRuntimeHandler.INSTANCE);
    final SimpleOperationDefinition stopDelivery = new SimpleOperationDefinitionBuilder(STOP_DELIVERY, getResourceDescriptionResolver()).setRuntimeOnly().build();
    registry.registerOperationHandler(stopDelivery, MessageDrivenBeanRuntimeHandler.INSTANCE);
}
Also used : SimpleOperationDefinitionBuilder(org.jboss.as.controller.SimpleOperationDefinitionBuilder) SimpleOperationDefinition(org.jboss.as.controller.SimpleOperationDefinition)

Example 4 with SimpleOperationDefinitionBuilder

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

the class AddStepHandler method register.

@Override
public void register(ManagementResourceRegistration registration) {
    SimpleOperationDefinitionBuilder builder = new SimpleOperationDefinitionBuilder(ModelDescriptionConstants.ADD, this.descriptor.getDescriptionResolver()).withFlag(OperationEntry.Flag.RESTART_NONE);
    if (registration.isOrderedChildResource()) {
        builder.addParameter(SimpleAttributeDefinitionBuilder.create(ModelDescriptionConstants.ADD_INDEX, ModelType.INT, true).build());
    }
    Stream<AttributeDefinition> parameters = this.descriptor.getAttributes().stream();
    parameters = Stream.concat(parameters, this.descriptor.getExtraParameters().stream());
    parameters = Stream.concat(parameters, this.descriptor.getAttributeTranslations().keySet().stream());
    parameters.forEach(attribute -> builder.addParameter(attribute));
    registration.registerOperationHandler(builder.build(), this);
}
Also used : SimpleOperationDefinitionBuilder(org.jboss.as.controller.SimpleOperationDefinitionBuilder) AttributeDefinition(org.jboss.as.controller.AttributeDefinition)

Example 5 with SimpleOperationDefinitionBuilder

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

the class EeLegacySubsystemTestCase method createAdditionalInitialization.

@Override
protected AdditionalInitialization createAdditionalInitialization() {
    return new AdditionalInitialization() {

        @Override
        protected RunningMode getRunningMode() {
            return RunningMode.ADMIN_ONLY;
        }

        @Override
        protected void initializeExtraSubystemsAndModel(ExtensionRegistry extensionRegistry, Resource rootResource, ManagementResourceRegistration rootRegistration, RuntimeCapabilityRegistry capabilityRegistry) {
            if (!extensionAdded) {
                //extensionAdded = true;
                //bean validation depends on EE, so we can't use the real subsystem here
                final OperationDefinition removeExtension = new SimpleOperationDefinitionBuilder("remove", NonResolvingResourceDescriptionResolver.INSTANCE).build();
                final OperationDefinition addExtension = new SimpleOperationDefinitionBuilder("add", NonResolvingResourceDescriptionResolver.INSTANCE).addParameter(new SimpleAttributeDefinition("module", ModelType.STRING, false)).build();
                PathElement bvExtension = PathElement.pathElement(EXTENSION, "org.wildfly.extension.bean-validation");
                ManagementResourceRegistration extensionRegistration = rootRegistration.registerSubModel(new SimpleResourceDefinition(bvExtension, NonResolvingResourceDescriptionResolver.INSTANCE));
                extensionRegistration.registerReadOnlyAttribute(new SimpleAttributeDefinition("module", ModelType.STRING, false), new ReloadRequiredWriteAttributeHandler());
                extensionRegistration.registerOperationHandler(removeExtension, new ReloadRequiredRemoveStepHandler());
                extensionRegistration.registerOperationHandler(addExtension, new ReloadRequiredAddStepHandler(new SimpleAttributeDefinition("module", ModelType.STRING, false)));
                final OperationDefinition removeSubsystem = new SimpleOperationDefinitionBuilder("remove", NonResolvingResourceDescriptionResolver.INSTANCE).build();
                final OperationDefinition addSubsystem = new SimpleOperationDefinitionBuilder("add", NonResolvingResourceDescriptionResolver.INSTANCE).build();
                PathElement bvSubsystem = PathElement.pathElement(SUBSYSTEM, "bean-validation");
                ManagementResourceRegistration subsystemRegistration = rootRegistration.registerSubModel(new SimpleResourceDefinition(bvSubsystem, NonResolvingResourceDescriptionResolver.INSTANCE));
                subsystemRegistration.registerOperationHandler(removeSubsystem, new ReloadRequiredRemoveStepHandler());
                subsystemRegistration.registerOperationHandler(addSubsystem, new ReloadRequiredAddStepHandler());
            }
        }
    };
}
Also used : RuntimeCapabilityRegistry(org.jboss.as.controller.capability.registry.RuntimeCapabilityRegistry) SimpleOperationDefinitionBuilder(org.jboss.as.controller.SimpleOperationDefinitionBuilder) Resource(org.jboss.as.controller.registry.Resource) SimpleResourceDefinition(org.jboss.as.controller.SimpleResourceDefinition) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) AdditionalInitialization(org.jboss.as.subsystem.test.AdditionalInitialization) ReloadRequiredWriteAttributeHandler(org.jboss.as.controller.ReloadRequiredWriteAttributeHandler) ReloadRequiredAddStepHandler(org.jboss.as.controller.ReloadRequiredAddStepHandler) ExtensionRegistry(org.jboss.as.controller.extension.ExtensionRegistry) PathElement(org.jboss.as.controller.PathElement) ReloadRequiredRemoveStepHandler(org.jboss.as.controller.ReloadRequiredRemoveStepHandler) OperationDefinition(org.jboss.as.controller.OperationDefinition)

Aggregations

SimpleOperationDefinitionBuilder (org.jboss.as.controller.SimpleOperationDefinitionBuilder)13 OperationDefinition (org.jboss.as.controller.OperationDefinition)6 SimpleOperationDefinition (org.jboss.as.controller.SimpleOperationDefinition)4 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)3 OperationContext (org.jboss.as.controller.OperationContext)2 OperationFailedException (org.jboss.as.controller.OperationFailedException)2 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)2 PathElement (org.jboss.as.controller.PathElement)2 SimpleAttributeDefinition (org.jboss.as.controller.SimpleAttributeDefinition)2 ManagementResourceRegistration (org.jboss.as.controller.registry.ManagementResourceRegistration)2 Resource (org.jboss.as.controller.registry.Resource)2 ModelNode (org.jboss.dmr.ModelNode)2 ResourceDescriptor (org.jboss.as.clustering.controller.ResourceDescriptor)1 ResourceServiceHandler (org.jboss.as.clustering.controller.ResourceServiceHandler)1 SimpleResourceRegistration (org.jboss.as.clustering.controller.SimpleResourceRegistration)1 ObjectListAttributeDefinition (org.jboss.as.controller.ObjectListAttributeDefinition)1 ObjectTypeAttributeDefinition (org.jboss.as.controller.ObjectTypeAttributeDefinition)1 PathAddress (org.jboss.as.controller.PathAddress)1 PropertiesAttributeDefinition (org.jboss.as.controller.PropertiesAttributeDefinition)1 ReloadRequiredAddStepHandler (org.jboss.as.controller.ReloadRequiredAddStepHandler)1