Search in sources :

Example 11 with ManagementResourceRegistration

use of org.jboss.as.controller.registry.ManagementResourceRegistration in project wildfly by wildfly.

the class BatchSubsystemExtension method initialize.

@Override
public void initialize(final ExtensionContext context) {
    final SubsystemRegistration subsystem = context.registerSubsystem(BatchSubsystemDefinition.NAME, CURRENT_MODEL_VERSION);
    subsystem.registerSubsystemModel(new BatchSubsystemDefinition(context.isRuntimeOnlyRegistrationValid()));
    subsystem.registerXMLElementWriter(new BatchSubsystemWriter());
    // Register the deployment resources
    if (context.isRuntimeOnlyRegistrationValid()) {
        final ManagementResourceRegistration deployments = subsystem.registerDeploymentModel(new BatchDeploymentResourceDefinition());
        final ManagementResourceRegistration jobRegistration = deployments.registerSubModel(BatchJobResourceDefinition.INSTANCE);
        jobRegistration.registerSubModel(new BatchJobExecutionResourceDefinition());
    }
}
Also used : BatchDeploymentResourceDefinition(org.wildfly.extension.batch.jberet.deployment.BatchDeploymentResourceDefinition) BatchJobExecutionResourceDefinition(org.wildfly.extension.batch.jberet.deployment.BatchJobExecutionResourceDefinition) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) SubsystemRegistration(org.jboss.as.controller.SubsystemRegistration)

Example 12 with ManagementResourceRegistration

use of org.jboss.as.controller.registry.ManagementResourceRegistration 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 ManagementResourceRegistration

use of org.jboss.as.controller.registry.ManagementResourceRegistration 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 ManagementResourceRegistration

use of org.jboss.as.controller.registry.ManagementResourceRegistration in project wildfly by wildfly.

the class ProtocolResourceRegistrationHandler method execute.

@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    OverrideDescriptionProvider provider = new OverrideDescriptionProvider() {

        @Override
        public Map<String, ModelNode> getAttributeOverrideDescriptions(Locale locale) {
            return Collections.emptyMap();
        }

        @Override
        public Map<String, ModelNode> getChildTypeOverrideDescriptions(Locale locale) {
            StandardResourceDescriptionResolver resolver = new JGroupsResourceDescriptionResolver();
            String description = resolver.getChildTypeDescription(ProtocolResourceDefinition.WILDCARD_PATH.getKey(), locale, resolver.getResourceBundle(locale));
            ModelNode result = new ModelNode();
            result.get(ModelDescriptionConstants.DESCRIPTION).set(description);
            return Collections.singletonMap(ProtocolResourceDefinition.WILDCARD_PATH.getKey(), result);
        }
    };
    Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS);
    String stack = STACK.resolveModelAttribute(context, resource.getModel()).asString();
    ManagementResourceRegistration registration = context.getResourceRegistrationForUpdate().registerOverrideModel(context.getCurrentAddressValue(), provider);
    PathAddress stackAddress = context.getCurrentAddress().getParent().append(StackResourceDefinition.pathElement(stack));
    Resource stackResource = context.readResourceFromRoot(stackAddress, false);
    for (String name : stackResource.getChildrenNames(TransportResourceDefinition.WILDCARD_PATH.getKey())) {
        PathAddress transportAddress = stackAddress.append(TransportResourceDefinition.pathElement(name));
        ModelNode transport = context.readResourceFromRoot(transportAddress, false).getModel();
        String moduleName = MODULE.resolveModelAttribute(context, transport).asString();
        Class<? extends Protocol> transportClass = findProtocolClass(context, name, moduleName);
        registration.registerSubModel(this.createProtocolResourceDefinition(name, transportClass));
        resource.registerChild(ProtocolResourceDefinition.pathElement(name), PlaceholderResource.INSTANCE);
    }
    for (String name : stackResource.getChildrenNames(ProtocolResourceDefinition.WILDCARD_PATH.getKey())) {
        Resource protocolResource = context.readResourceFromRoot(stackAddress.append(ProtocolResourceDefinition.pathElement(name)), false);
        String moduleName = MODULE.resolveModelAttribute(context, protocolResource.getModel()).asString();
        Class<? extends Protocol> protocolClass = findProtocolClass(context, name, moduleName);
        registration.registerSubModel(this.createProtocolResourceDefinition(name, protocolClass));
        resource.registerChild(ProtocolResourceDefinition.pathElement(name), PlaceholderResource.INSTANCE);
    }
    if (stackResource.hasChild(RelayResourceDefinition.PATH)) {
        registration.registerSubModel(this.createProtocolResourceDefinition(RelayConfiguration.PROTOCOL_NAME, RELAY2.class));
        resource.registerChild(ProtocolResourceDefinition.pathElement(RelayConfiguration.PROTOCOL_NAME), PlaceholderResource.INSTANCE);
    }
}
Also used : Locale(java.util.Locale) PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource) PlaceholderResource(org.jboss.as.controller.registry.PlaceholderResource) OverrideDescriptionProvider(org.jboss.as.controller.descriptions.OverrideDescriptionProvider) StandardResourceDescriptionResolver(org.jboss.as.controller.descriptions.StandardResourceDescriptionResolver) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) ModelNode(org.jboss.dmr.ModelNode) RELAY2(org.jgroups.protocols.relay.RELAY2)

Example 15 with ManagementResourceRegistration

use of org.jboss.as.controller.registry.ManagementResourceRegistration in project wildfly by wildfly.

the class ForkResourceDefinition method register.

@Override
public void register(ManagementResourceRegistration parentRegistration) {
    ManagementResourceRegistration registration = parentRegistration.registerSubModel(this);
    ResourceDescriptor descriptor = new ResourceDescriptor(this.getResourceDescriptionResolver()).addCapabilities(Capability.class).addCapabilities(CLUSTERING_CAPABILITIES.values());
    ResourceServiceBuilderFactory<ChannelFactory> builderFactory = address -> new ForkChannelFactoryBuilder(Capability.FORK_CHANNEL_FACTORY.getServiceName(address), address.getParent().getLastElement().getValue());
    ResourceServiceHandler handler = new ForkServiceHandler(builderFactory);
    new SimpleResourceRegistration(descriptor, handler).register(registration);
    new ProtocolRegistration(builderFactory, new ForkProtocolResourceRegistrationHandler()).register(registration);
}
Also used : UnaryRequirement(org.wildfly.clustering.service.UnaryRequirement) EnumMap(java.util.EnumMap) SimpleResourceRegistration(org.jboss.as.clustering.controller.SimpleResourceRegistration) JGroupsRequirement(org.wildfly.clustering.jgroups.spi.JGroupsRequirement) ResourceDescriptor(org.jboss.as.clustering.controller.ResourceDescriptor) PathElement(org.jboss.as.controller.PathElement) ResourceServiceBuilderFactory(org.jboss.as.clustering.controller.ResourceServiceBuilderFactory) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) ClusteringRequirement(org.wildfly.clustering.spi.ClusteringRequirement) ResourceServiceHandler(org.jboss.as.clustering.controller.ResourceServiceHandler) UnaryRequirementCapability(org.jboss.as.clustering.controller.UnaryRequirementCapability) Map(java.util.Map) ChannelFactory(org.wildfly.clustering.jgroups.spi.ChannelFactory) ChildResourceDefinition(org.jboss.as.clustering.controller.ChildResourceDefinition) CapabilityProvider(org.jboss.as.clustering.controller.CapabilityProvider) EnumSet(java.util.EnumSet) SimpleResourceRegistration(org.jboss.as.clustering.controller.SimpleResourceRegistration) UnaryRequirementCapability(org.jboss.as.clustering.controller.UnaryRequirementCapability) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) ChannelFactory(org.wildfly.clustering.jgroups.spi.ChannelFactory) ResourceServiceHandler(org.jboss.as.clustering.controller.ResourceServiceHandler) ResourceDescriptor(org.jboss.as.clustering.controller.ResourceDescriptor)

Aggregations

ManagementResourceRegistration (org.jboss.as.controller.registry.ManagementResourceRegistration)79 SubsystemRegistration (org.jboss.as.controller.SubsystemRegistration)32 ResourceDescriptor (org.jboss.as.clustering.controller.ResourceDescriptor)30 ResourceServiceHandler (org.jboss.as.clustering.controller.ResourceServiceHandler)26 SimpleResourceRegistration (org.jboss.as.clustering.controller.SimpleResourceRegistration)25 SimpleResourceServiceHandler (org.jboss.as.clustering.controller.SimpleResourceServiceHandler)16 PathElement (org.jboss.as.controller.PathElement)12 SimpleAliasEntry (org.jboss.as.clustering.controller.SimpleAliasEntry)9 PathAddress (org.jboss.as.controller.PathAddress)9 ModelNode (org.jboss.dmr.ModelNode)8 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)7 Resource (org.jboss.as.controller.registry.Resource)7 Map (java.util.Map)6 Locale (java.util.Locale)5 UnaryRequirementCapability (org.jboss.as.clustering.controller.UnaryRequirementCapability)5 OperationContext (org.jboss.as.controller.OperationContext)5 EnumMap (java.util.EnumMap)4 EnumSet (java.util.EnumSet)4 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)4 SimpleAttributeDefinitionBuilder (org.jboss.as.controller.SimpleAttributeDefinitionBuilder)4