Search in sources :

Example 6 with OverrideDescriptionProvider

use of org.jboss.as.controller.descriptions.OverrideDescriptionProvider in project wildfly by wildfly.

the class ParsedRaDeploymentProcessor method deploy.

/**
 * Process a deployment for a Connector. Will install a {@Code
 * JBossService} for this ResourceAdapter.
 *
 * @param phaseContext the deployment unit context
 * @throws DeploymentUnitProcessingException
 */
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final ConnectorXmlDescriptor connectorXmlDescriptor = deploymentUnit.getAttachment(ConnectorXmlDescriptor.ATTACHMENT_KEY);
    final ManagementResourceRegistration registration;
    final ManagementResourceRegistration baseRegistration = deploymentUnit.getAttachment(DeploymentModelUtils.MUTABLE_REGISTRATION_ATTACHMENT);
    final Resource deploymentResource = deploymentUnit.getAttachment(DeploymentModelUtils.DEPLOYMENT_RESOURCE);
    final CapabilityServiceSupport support = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
    if (connectorXmlDescriptor == null) {
        return;
    }
    final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
    if (deploymentUnit.getParent() != null) {
        registration = baseRegistration.getSubModel(PathAddress.pathAddress(PathElement.pathElement("subdeployment")));
    } else {
        registration = baseRegistration;
    }
    final IronJacamarXmlDescriptor ironJacamarXmlDescriptor = deploymentUnit.getAttachment(IronJacamarXmlDescriptor.ATTACHMENT_KEY);
    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    DEPLOYMENT_CONNECTOR_LOGGER.debugf("ParsedRaDeploymentProcessor: Processing=%s", deploymentUnit);
    final ClassLoader classLoader = module.getClassLoader();
    Map<ResourceRoot, Index> annotationIndexes = AnnotationIndexUtils.getAnnotationIndexes(deploymentUnit);
    ServiceBuilder builder = process(connectorXmlDescriptor, ironJacamarXmlDescriptor, classLoader, serviceTarget, annotationIndexes, deploymentUnit.getServiceName(), registration, deploymentResource, support);
    if (builder != null) {
        String bootstrapCtx = null;
        if (ironJacamarXmlDescriptor != null && ironJacamarXmlDescriptor.getIronJacamar() != null && ironJacamarXmlDescriptor.getIronJacamar().getBootstrapContext() != null)
            bootstrapCtx = ironJacamarXmlDescriptor.getIronJacamar().getBootstrapContext();
        if (bootstrapCtx == null)
            bootstrapCtx = "default";
        builder.requires(ConnectorServices.BOOTSTRAP_CONTEXT_SERVICE.append(bootstrapCtx));
        // Register an empty override model regardless of we're enabled or not - the statistics listener will add the relevant childresources
        if (registration.isAllowsOverride() && registration.getOverrideModel(deploymentUnit.getName()) == null) {
            registration.registerOverrideModel(deploymentUnit.getName(), new OverrideDescriptionProvider() {

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

                @Override
                public Map<String, ModelNode> getChildTypeOverrideDescriptions(Locale locale) {
                    return Collections.emptyMap();
                }
            });
        }
        builder.setInitialMode(Mode.ACTIVE).install();
    }
}
Also used : Locale(java.util.Locale) ServiceTarget(org.jboss.msc.service.ServiceTarget) Resource(org.jboss.as.controller.registry.Resource) ConnectorXmlDescriptor(org.jboss.as.connector.metadata.xmldescriptors.ConnectorXmlDescriptor) Index(org.jboss.jandex.Index) OverrideDescriptionProvider(org.jboss.as.controller.descriptions.OverrideDescriptionProvider) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) CapabilityServiceSupport(org.jboss.as.controller.capability.CapabilityServiceSupport) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) IronJacamarXmlDescriptor(org.jboss.as.connector.metadata.xmldescriptors.IronJacamarXmlDescriptor) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) Map(java.util.Map)

Example 7 with OverrideDescriptionProvider

use of org.jboss.as.controller.descriptions.OverrideDescriptionProvider in project wildfly by wildfly.

the class ForkProtocolResourceRegistrationHandler method execute.

@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    ManagementResourceRegistration registration = context.getResourceRegistrationForUpdate();
    String protocolName = context.getCurrentAddressValue();
    String moduleName = ProtocolResourceDefinition.Attribute.MODULE.resolveModelAttribute(context, operation).asString();
    Class<? extends Protocol> protocolClass = ProtocolResourceRegistrationHandler.findProtocolClass(context, protocolName, moduleName);
    final Map<String, Attribute> attributes = ProtocolMetricsHandler.findProtocolAttributes(protocolClass);
    OverrideDescriptionProvider provider = new OverrideDescriptionProvider() {

        @Override
        public Map<String, ModelNode> getAttributeOverrideDescriptions(Locale locale) {
            Map<String, ModelNode> result = new HashMap<>();
            for (Attribute attribute : attributes.values()) {
                ModelNode value = new ModelNode();
                value.get(ModelDescriptionConstants.DESCRIPTION).set(attribute.getDescription());
                result.put(attribute.getName(), value);
            }
            return result;
        }

        @Override
        public Map<String, ModelNode> getChildTypeOverrideDescriptions(Locale locale) {
            return Collections.emptyMap();
        }
    };
    ManagementResourceRegistration protocolRegistration = registration.registerOverrideModel(protocolName, provider);
    ProtocolMetricsHandler handler = new ProtocolMetricsHandler(this);
    for (Attribute attribute : attributes.values()) {
        String name = attribute.getName();
        FieldType type = FieldType.valueOf(attribute.getType());
        protocolRegistration.registerMetric(new SimpleAttributeDefinitionBuilder(name, type.getModelType()).setStorageRuntime().build(), handler);
    }
}
Also used : Locale(java.util.Locale) Attribute(org.jboss.as.clustering.jgroups.subsystem.ProtocolMetricsHandler.Attribute) HashMap(java.util.HashMap) OverrideDescriptionProvider(org.jboss.as.controller.descriptions.OverrideDescriptionProvider) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) FieldType(org.jboss.as.clustering.jgroups.subsystem.ProtocolMetricsHandler.FieldType) ModelNode(org.jboss.dmr.ModelNode) SimpleAttributeDefinitionBuilder(org.jboss.as.controller.SimpleAttributeDefinitionBuilder)

Example 8 with OverrideDescriptionProvider

use of org.jboss.as.controller.descriptions.OverrideDescriptionProvider in project wildfly by wildfly.

the class ForkProtocolRuntimeResourceRegistration method register.

@Override
public void register(OperationContext context) throws OperationFailedException {
    Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
    ManagementResourceRegistration registration = context.getResourceRegistrationForUpdate();
    String protocolName = context.getCurrentAddressValue();
    String moduleName = ProtocolResourceDefinition.Attribute.MODULE.resolveModelAttribute(context, resource.getModel()).asString();
    Class<? extends Protocol> protocolClass = ChannelRuntimeResourceRegistration.findProtocolClass(context, protocolName, moduleName);
    Map<String, Attribute> attributes = ProtocolMetricsHandler.findProtocolAttributes(protocolClass);
    // If this is a wildcard registration, create an override model registration with which to register protocol-specific metrics
    if (registration.getPathAddress().getLastElement().isWildcard()) {
        OverrideDescriptionProvider provider = new OverrideDescriptionProvider() {

            @Override
            public Map<String, ModelNode> getAttributeOverrideDescriptions(Locale locale) {
                Map<String, ModelNode> result = new HashMap<>();
                for (Attribute attribute : attributes.values()) {
                    ModelNode value = new ModelNode();
                    value.get(ModelDescriptionConstants.DESCRIPTION).set(attribute.getDescription());
                    result.put(attribute.getName(), value);
                }
                return result;
            }

            @Override
            public Map<String, ModelNode> getChildTypeOverrideDescriptions(Locale locale) {
                return Collections.emptyMap();
            }
        };
        registration = registration.registerOverrideModel(protocolName, provider);
    }
    ProtocolMetricsHandler handler = new ProtocolMetricsHandler(this.executors);
    for (Attribute attribute : attributes.values()) {
        String name = attribute.getName();
        FieldType type = FieldType.valueOf(attribute.getType());
        registration.registerMetric(new SimpleAttributeDefinitionBuilder(name, type.getModelType()).setStorageRuntime().build(), handler);
    }
}
Also used : Locale(java.util.Locale) Attribute(org.jboss.as.clustering.jgroups.subsystem.ProtocolMetricsHandler.Attribute) HashMap(java.util.HashMap) Resource(org.jboss.as.controller.registry.Resource) OverrideDescriptionProvider(org.jboss.as.controller.descriptions.OverrideDescriptionProvider) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) FieldType(org.jboss.as.clustering.jgroups.subsystem.ProtocolMetricsHandler.FieldType) ModelNode(org.jboss.dmr.ModelNode) SimpleAttributeDefinitionBuilder(org.jboss.as.controller.SimpleAttributeDefinitionBuilder)

Aggregations

Locale (java.util.Locale)8 OverrideDescriptionProvider (org.jboss.as.controller.descriptions.OverrideDescriptionProvider)8 ManagementResourceRegistration (org.jboss.as.controller.registry.ManagementResourceRegistration)6 Resource (org.jboss.as.controller.registry.Resource)5 ModelNode (org.jboss.dmr.ModelNode)5 Map (java.util.Map)3 PathAddress (org.jboss.as.controller.PathAddress)3 HashMap (java.util.HashMap)2 Attribute (org.jboss.as.clustering.jgroups.subsystem.ProtocolMetricsHandler.Attribute)2 FieldType (org.jboss.as.clustering.jgroups.subsystem.ProtocolMetricsHandler.FieldType)2 ResourceAdapterDeployment (org.jboss.as.connector.metadata.deployment.ResourceAdapterDeployment)2 ResourceAdapterXmlDeploymentService (org.jboss.as.connector.services.resourceadapters.deployment.ResourceAdapterXmlDeploymentService)2 SimpleAttributeDefinitionBuilder (org.jboss.as.controller.SimpleAttributeDefinitionBuilder)2 StandardResourceDescriptionResolver (org.jboss.as.controller.descriptions.StandardResourceDescriptionResolver)2 PlaceholderResource (org.jboss.as.controller.registry.PlaceholderResource)2 ServiceName (org.jboss.msc.service.ServiceName)2 RELAY2 (org.jgroups.protocols.relay.RELAY2)2 ClearStatisticsHandler (org.jboss.as.connector.dynamicresource.ClearStatisticsHandler)1 StatisticsResourceDefinition (org.jboss.as.connector.dynamicresource.StatisticsResourceDefinition)1 ConnectorXmlDescriptor (org.jboss.as.connector.metadata.xmldescriptors.ConnectorXmlDescriptor)1