Search in sources :

Example 1 with Connector

use of org.jboss.jca.core.api.management.Connector in project wildfly by wildfly.

the class IronJacamarActivationResourceService method start.

@Override
public void start(StartContext context) throws StartException {
    final CommonDeployment deploymentMD = deployment.getValue().getDeployment();
    final String deploymentName = deploymentMD.getDeploymentName();
    ROOT_LOGGER.debugf("Starting IronJacamarActivationResourceService %s", deploymentName);
    try {
        Connector connector = deploymentMD.getConnector();
        if (connector != null && connector.getResourceAdapter() != null) {
            final OverrideDescriptionProvider OD_PROVIDER = new OverrideDescriptionProvider() {

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

                @Override
                public Map<String, ModelNode> getChildTypeOverrideDescriptions(Locale locale) {
                    return Collections.emptyMap();
                }
            };
            final PathElement EXTENDED_STATS = PathElement.pathElement(Constants.STATISTICS_NAME, "extended");
            final PathAddress EXTENDED_STATS_ADDR = PathAddress.pathAddress(EXTENDED_STATS);
            final PathAddress CON_DEF_ADDR = PathAddress.EMPTY_ADDRESS.append(Constants.CONNECTIONDEFINITIONS_NAME);
            ManagementResourceRegistration raRegistration = registration.getSubModel(RA_ADDRESS).registerOverrideModel(deploymentName, OD_PROVIDER);
            ResourceBuilder resourceBuilder = ResourceBuilder.Factory.create(EXTENDED_STATS, new StandardResourceDescriptionResolver(Constants.STATISTICS_NAME + "." + Constants.WORKMANAGER_NAME, CommonAttributes.RESOURCE_NAME, CommonAttributes.class.getClassLoader()));
            ManagementResourceRegistration raStatsSubRegistration = raRegistration.registerSubModel(resourceBuilder.build());
            StatisticsPlugin raStats = connector.getResourceAdapter().getStatistics();
            if (raStats != null) {
                raStats.setEnabled(statsEnabled);
                PoolMetrics.ParametrizedPoolMetricsHandler handler = new PoolMetrics.ParametrizedPoolMetricsHandler(raStats);
                for (AttributeDefinition attribute : StatisticsResourceDefinition.getAttributesFromPlugin(raStats)) {
                    raStatsSubRegistration.registerMetric(attribute, handler);
                }
                raStatsSubRegistration.registerOperationHandler(ClearStatisticsHandler.DEFINITION, new ClearStatisticsHandler(raStats));
            }
            List<ConnectionFactory> connectionFactories = connector.getConnectionFactories();
            if (connectionFactories != null) {
                for (ConnectionFactory cf : connectionFactories) {
                    ManagedConnectionFactory mcf = cf.getManagedConnectionFactory();
                    StatisticsPlugin extendStats = mcf == null ? null : mcf.getStatistics();
                    if (extendStats != null) {
                        extendStats.setEnabled(statsEnabled);
                        if (!extendStats.getNames().isEmpty()) {
                            ManagementResourceRegistration cdRegistration = raRegistration.getSubModel(CON_DEF_ADDR);
                            ManagementResourceRegistration overrideCdRegistration = cdRegistration.registerOverrideModel(cf.getJndiName(), OD_PROVIDER);
                            if (overrideCdRegistration.getSubModel(EXTENDED_STATS_ADDR) == null) {
                                overrideCdRegistration.registerSubModel(new StatisticsResourceDefinition(EXTENDED_STATS, CommonAttributes.RESOURCE_NAME, extendStats));
                            }
                        }
                    }
                }
            }
            ConnectionManager[] connectionManagers = deploymentMD.getConnectionManagers();
            if (connectionManagers != null) {
                PathElement POOL_STATS = PathElement.pathElement(Constants.STATISTICS_NAME, "pool");
                PathAddress POOL_STATS_ADDR = PathAddress.pathAddress(POOL_STATS);
                for (ConnectionManager cm : connectionManagers) {
                    if (cm.getPool() != null) {
                        StatisticsPlugin poolStats = cm.getPool().getStatistics();
                        poolStats.setEnabled(statsEnabled);
                        if (!poolStats.getNames().isEmpty()) {
                            ManagementResourceRegistration cdRegistration = raRegistration.getSubModel(CON_DEF_ADDR);
                            ManagementResourceRegistration overrideCdRegistration = cdRegistration.registerOverrideModel(cm.getJndiName(), OD_PROVIDER);
                            if (overrideCdRegistration.getSubModel(POOL_STATS_ADDR) == null) {
                                overrideCdRegistration.registerSubModel(new StatisticsResourceDefinition(POOL_STATS, CommonAttributes.RESOURCE_NAME, poolStats));
                            }
                        }
                    }
                }
            }
            List<AdminObject> adminObjects = connector.getAdminObjects();
            if (adminObjects != null) {
                PathAddress AO_ADDR = PathAddress.EMPTY_ADDRESS.append(Constants.ADMIN_OBJECTS_NAME);
                for (AdminObject ao : adminObjects) {
                    StatisticsPlugin extendStats = ao.getStatistics();
                    if (extendStats != null) {
                        extendStats.setEnabled(statsEnabled);
                        if (!extendStats.getNames().isEmpty()) {
                            ManagementResourceRegistration cdRegistration = raRegistration.getSubModel(AO_ADDR);
                            ManagementResourceRegistration overrideCdRegistration = cdRegistration.registerOverrideModel(ao.getJndiName(), OD_PROVIDER);
                            if (overrideCdRegistration.getSubModel(EXTENDED_STATS_ADDR) == null) {
                                overrideCdRegistration.registerSubModel(new StatisticsResourceDefinition(EXTENDED_STATS, CommonAttributes.RESOURCE_NAME, extendStats));
                            }
                        }
                    }
                }
            }
        }
    } catch (IllegalArgumentException e) {
    // ignore it, already restered
    }
    Resource subsystemResource;
    if (!deploymentResource.hasChild(SUBSYSTEM_PATH_ELEMENT)) {
        subsystemResource = new IronJacamarResource.IronJacamarRuntimeResource();
        deploymentResource.registerChild(SUBSYSTEM_PATH_ELEMENT, subsystemResource);
    } else {
        subsystemResource = deploymentResource.getChild(SUBSYSTEM_PATH_ELEMENT);
    }
    IronJacamarResourceCreator.INSTANCE.execute(subsystemResource, mdr.getValue(), deployment.getValue().getRaName());
}
Also used : Locale(java.util.Locale) Connector(org.jboss.jca.core.api.management.Connector) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) IronJacamarResource(org.jboss.as.connector.subsystems.resourceadapters.IronJacamarResource) OverrideDescriptionProvider(org.jboss.as.controller.descriptions.OverrideDescriptionProvider) StandardResourceDescriptionResolver(org.jboss.as.controller.descriptions.StandardResourceDescriptionResolver) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) PoolMetrics(org.jboss.as.connector.subsystems.common.pool.PoolMetrics) ConnectionFactory(org.jboss.jca.core.api.management.ConnectionFactory) ManagedConnectionFactory(org.jboss.jca.core.api.management.ManagedConnectionFactory) ConnectionManager(org.jboss.jca.core.connectionmanager.ConnectionManager) PathElement(org.jboss.as.controller.PathElement) ClearStatisticsHandler(org.jboss.as.connector.dynamicresource.ClearStatisticsHandler) AdminObject(org.jboss.jca.core.api.management.AdminObject) StatisticsResourceDefinition(org.jboss.as.connector.dynamicresource.StatisticsResourceDefinition) ResourceBuilder(org.jboss.as.controller.ResourceBuilder) StatisticsPlugin(org.jboss.jca.core.spi.statistics.StatisticsPlugin) Resource(org.jboss.as.controller.registry.Resource) IronJacamarResource(org.jboss.as.connector.subsystems.resourceadapters.IronJacamarResource) CommonDeployment(org.jboss.jca.deployers.common.CommonDeployment) ManagedConnectionFactory(org.jboss.jca.core.api.management.ManagedConnectionFactory) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode)

Example 2 with Connector

use of org.jboss.jca.core.api.management.Connector in project wildfly by wildfly.

the class IronJacamarActivationResourceService method stop.

@Override
public void stop(StopContext context) {
    final CommonDeployment deploymentMD = deployment.getValue().getDeployment();
    final String deploymentName = deploymentMD.getDeploymentName();
    ROOT_LOGGER.debugf("Stopping IronJacamarActivationResourceService %s", deploymentName);
    Connector connector = deploymentMD.getConnector();
    if (connector != null && connector.getResourceAdapter() != null) {
        // We may have registered override resource registrations so we need to remove those
        ManagementResourceRegistration raReg = registration.getSubModel(RA_ADDRESS.getParent().append(Constants.RESOURCEADAPTER_NAME, deploymentName));
        ManagementResourceRegistration cdefReg = raReg.getSubModel(PathAddress.pathAddress(PathElement.pathElement(Constants.CONNECTIONDEFINITIONS_NAME)));
        List<ConnectionFactory> connectionFactories = connector.getConnectionFactories();
        if (connectionFactories != null) {
            // code reads that it won't be null but it's not documented, so...
            for (ConnectionFactory cf : connectionFactories) {
                // We might not have registered an override for this one but it's no harm to remove
                // and simpler to just do it vs analyzing to see if we did
                cdefReg.unregisterOverrideModel(cf.getJndiName());
            }
        }
        ConnectionManager[] connectionManagers = deploymentMD.getConnectionManagers();
        if (connectionManagers != null) {
            for (ConnectionManager cm : connectionManagers) {
                // We might not have registered an override for this one but it's no harm to remove
                // and simpler to just do it vs analyzing to see if we did
                cdefReg.unregisterOverrideModel(cm.getJndiName());
            }
        }
        List<AdminObject> adminObjects = connector.getAdminObjects();
        if (adminObjects != null) {
            // code reads that it won't be null but it's not documented, so...
            ManagementResourceRegistration aoReg = raReg.getSubModel(PathAddress.pathAddress(PathElement.pathElement(Constants.ADMIN_OBJECTS_NAME)));
            for (AdminObject ao : adminObjects) {
                // We might not have registered an override for this one but it's no harm to remove
                // and simpler to just do it vs analyzing to see if we did
                aoReg.unregisterOverrideModel(ao.getJndiName());
            }
        }
        ManagementResourceRegistration raBaseReg = registration.getSubModel(RA_ADDRESS);
        raBaseReg.unregisterOverrideModel(deploymentName);
    }
    deploymentResource.removeChild(SUBSYSTEM_PATH_ELEMENT);
}
Also used : CommonDeployment(org.jboss.jca.deployers.common.CommonDeployment) Connector(org.jboss.jca.core.api.management.Connector) ConnectionFactory(org.jboss.jca.core.api.management.ConnectionFactory) ManagedConnectionFactory(org.jboss.jca.core.api.management.ManagedConnectionFactory) ConnectionManager(org.jboss.jca.core.connectionmanager.ConnectionManager) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) AdminObject(org.jboss.jca.core.api.management.AdminObject)

Example 3 with Connector

use of org.jboss.jca.core.api.management.Connector in project wildfly by wildfly.

the class EnlistmentTraceAttributeWriteHandler method applyUpdateToRuntime.

@Override
protected boolean applyUpdateToRuntime(final OperationContext context, final ModelNode operation, final String parameterName, final ModelNode newValue, final ModelNode currentValue, final HandbackHolder<List<ConnectionManager>> handbackHolder) throws OperationFailedException {
    final String jndiName = context.readResource(PathAddress.EMPTY_ADDRESS).getModel().get(Constants.JNDINAME.getName()).asString();
    final ServiceController<?> managementRepoService = context.getServiceRegistry(false).getService(ConnectorServices.MANAGEMENT_REPOSITORY_SERVICE);
    Boolean boolValue = Constants.ENLISTMENT_TRACE.resolveValue(context, newValue).asBoolean();
    try {
        final ManagementRepository repository = (ManagementRepository) managementRepoService.getValue();
        if (repository.getConnectors() != null) {
            List<ConnectionManager> handback = new LinkedList<>();
            for (Connector connector : repository.getConnectors()) {
                for (ConnectionManager cm : connector.getConnectionManagers()) {
                    if (jndiName.equalsIgnoreCase(cm.getUniqueId())) {
                        cm.setEnlistmentTrace(boolValue);
                        handback.add(cm);
                    }
                }
            }
            handbackHolder.setHandback(handback);
        }
    } catch (Exception e) {
        throw new OperationFailedException(ConnectorLogger.ROOT_LOGGER.failedToSetAttribute(e.getLocalizedMessage()));
    }
    return false;
}
Also used : Connector(org.jboss.jca.core.api.management.Connector) ConnectionManager(org.jboss.jca.core.api.management.ConnectionManager) ManagementRepository(org.jboss.jca.core.api.management.ManagementRepository) OperationFailedException(org.jboss.as.controller.OperationFailedException) LinkedList(java.util.LinkedList) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Aggregations

Connector (org.jboss.jca.core.api.management.Connector)3 ManagementResourceRegistration (org.jboss.as.controller.registry.ManagementResourceRegistration)2 AdminObject (org.jboss.jca.core.api.management.AdminObject)2 ConnectionFactory (org.jboss.jca.core.api.management.ConnectionFactory)2 ManagedConnectionFactory (org.jboss.jca.core.api.management.ManagedConnectionFactory)2 ConnectionManager (org.jboss.jca.core.connectionmanager.ConnectionManager)2 CommonDeployment (org.jboss.jca.deployers.common.CommonDeployment)2 LinkedList (java.util.LinkedList)1 Locale (java.util.Locale)1 ClearStatisticsHandler (org.jboss.as.connector.dynamicresource.ClearStatisticsHandler)1 StatisticsResourceDefinition (org.jboss.as.connector.dynamicresource.StatisticsResourceDefinition)1 PoolMetrics (org.jboss.as.connector.subsystems.common.pool.PoolMetrics)1 IronJacamarResource (org.jboss.as.connector.subsystems.resourceadapters.IronJacamarResource)1 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)1 OperationFailedException (org.jboss.as.controller.OperationFailedException)1 PathAddress (org.jboss.as.controller.PathAddress)1 PathElement (org.jboss.as.controller.PathElement)1 ResourceBuilder (org.jboss.as.controller.ResourceBuilder)1 OverrideDescriptionProvider (org.jboss.as.controller.descriptions.OverrideDescriptionProvider)1 StandardResourceDescriptionResolver (org.jboss.as.controller.descriptions.StandardResourceDescriptionResolver)1