Search in sources :

Example 36 with PathElement

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

the class ProxyConfigurationResourceDefinition method register.

@SuppressWarnings("deprecation")
@Override
public ManagementResourceRegistration register(ManagementResourceRegistration parent) {
    ManagementResourceRegistration registration = parent.registerSubModel(this);
    ResourceDescriptor descriptor = new ResourceDescriptor(this.getResourceDescriptionResolver()).addAttributes(EnumSet.complementOf(EnumSet.of(Attribute.SSL_CONTEXT))).addExtraParameters(Attribute.SSL_CONTEXT).addAttributeTranslation(DeprecatedAttribute.SIMPLE_LOAD_PROVIDER, SIMPLE_LOAD_PROVIDER_TRANSLATION).addAlias(DeprecatedAttribute.CONNECTOR, Attribute.LISTENER).addRequiredSingletonChildren(SimpleLoadProviderResourceDefinition.PATH).addCapabilities(Capability.class);
    registration.registerReadWriteAttribute(Attribute.SSL_CONTEXT.getDefinition(), null, new ReloadRequiredWriteAttributeHandler() {

        @Override
        protected void validateUpdatedModel(OperationContext context, Resource model) {
            context.addStep(new OperationStepHandler() {

                @Override
                public void execute(OperationContext ctx, ModelNode op) throws OperationFailedException {
                    if (model.hasChild(SSLResourceDefinition.PATH)) {
                        throw new OperationFailedException(ROOT_LOGGER.bothElytronAndLegacySslContextDefined());
                    }
                }
            }, OperationContext.Stage.MODEL);
        }
    });
    parent.registerAlias(LEGACY_PATH, new AliasEntry(registration) {

        @Override
        public PathAddress convertToTargetAddress(PathAddress aliasAddress, AliasContext aliasContext) {
            PathAddress rebuiltAddress = PathAddress.EMPTY_ADDRESS;
            for (PathElement pathElement : aliasAddress) {
                if (pathElement.equals(LEGACY_PATH)) {
                    try {
                        if (aliasContext.readResourceFromRoot(rebuiltAddress, false).hasChildren(ProxyConfigurationResourceDefinition.WILDCARD_PATH.getKey())) {
                            Set<Resource.ResourceEntry> children = aliasContext.readResourceFromRoot(rebuiltAddress, false).getChildren(ProxyConfigurationResourceDefinition.WILDCARD_PATH.getKey());
                            if (children.size() > 1 && !Operations.getOperationName(aliasContext.getOperation()).equals(AliasContext.RECURSIVE_GLOBAL_OP)) {
                                throw new IllegalStateException(ModClusterLogger.ROOT_LOGGER.legacyOperationsWithMultipleProxies());
                            }
                            PathAddress proxyPath = PathAddress.pathAddress(ProxyConfigurationResourceDefinition.pathElement(children.iterator().next().getName()));
                            rebuiltAddress = rebuiltAddress.append(proxyPath);
                        } else {
                            // handle :add
                            rebuiltAddress = rebuiltAddress.append(ProxyConfigurationResourceDefinition.pathElement("default"));
                        }
                    } catch (Resource.NoSuchResourceException ignore) {
                        // handle recursive-global-op
                        rebuiltAddress = rebuiltAddress.append(ProxyConfigurationResourceDefinition.WILDCARD_PATH);
                    }
                } else {
                    rebuiltAddress = rebuiltAddress.append(pathElement);
                }
            }
            return rebuiltAddress;
        }
    });
    if (registration.isRuntimeOnlyRegistrationValid()) {
        new OperationHandler<>(new ProxyOperationExecutor(this.executors), ProxyOperation.class).register(registration);
    }
    new ReloadRequiredResourceRegistration(descriptor).register(registration);
    new LegacyMetricOperationsRegistration().register(registration);
    new SimpleLoadProviderResourceDefinition().register(registration);
    new DynamicLoadProviderResourceDefinition().register(registration);
    new SSLResourceDefinition().register(registration);
    return registration;
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) EnumSet(java.util.EnumSet) Set(java.util.Set) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) Resource(org.jboss.as.controller.registry.Resource) OperationFailedException(org.jboss.as.controller.OperationFailedException) ManagementResourceRegistration(org.jboss.as.clustering.controller.ManagementResourceRegistration) ReloadRequiredWriteAttributeHandler(org.jboss.as.controller.ReloadRequiredWriteAttributeHandler) PathElement(org.jboss.as.controller.PathElement) PathAddress(org.jboss.as.controller.PathAddress) ReloadRequiredResourceRegistration(org.jboss.as.clustering.controller.ReloadRequiredResourceRegistration) AliasEntry(org.jboss.as.controller.registry.AliasEntry) ModelNode(org.jboss.dmr.ModelNode) ResourceDescriptor(org.jboss.as.clustering.controller.ResourceDescriptor)

Example 37 with PathElement

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

the class SecuritySubsystemParser_2_0 method parseElytronRealm.

protected void parseElytronRealm(final XMLExtendedStreamReader reader, final List<ModelNode> operations, final PathAddress subsystemPath) throws XMLStreamException {
    final ModelNode elytronRealmAddOperation = Util.createAddOperation();
    PathElement elytronRealmPath = null;
    final EnumSet<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.LEGACY_JAAS_CONFIG);
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        requireNoNamespaceAttribute(reader, i);
        final String value = reader.getAttributeValue(i);
        final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
        required.remove(attribute);
        switch(attribute) {
            case NAME:
                {
                    if (value == null || value.length() == 0) {
                        throw invalidAttributeValue(reader, i);
                    }
                    elytronRealmPath = PathElement.pathElement(ELYTRON_REALM, value);
                    break;
                }
            case LEGACY_JAAS_CONFIG:
                {
                    LEGACY_JAAS_CONFIG.parseAndSetParameter(value, elytronRealmAddOperation, reader);
                    break;
                }
            case APPLY_ROLE_MAPPERS:
                {
                    APPLY_ROLE_MAPPERS.parseAndSetParameter(value, elytronRealmAddOperation, reader);
                    break;
                }
            default:
                throw unexpectedAttribute(reader, i);
        }
    }
    if (!required.isEmpty()) {
        throw missingRequired(reader, required);
    }
    elytronRealmAddOperation.get(OP_ADDR).set(subsystemPath.append(elytronRealmPath).toModelNode());
    operations.add(elytronRealmAddOperation);
    requireNoContent(reader);
}
Also used : PathElement(org.jboss.as.controller.PathElement) ParseUtils.unexpectedAttribute(org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute) ParseUtils.requireNoNamespaceAttribute(org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute) ModelNode(org.jboss.dmr.ModelNode)

Example 38 with PathElement

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

the class SecuritySubsystemParser_2_0 method parseTLSEntity.

protected void parseTLSEntity(final XMLExtendedStreamReader reader, final List<ModelNode> operations, final PathAddress subsystemPath, final String tlsEntityName) throws XMLStreamException {
    final ModelNode elytronTLSEntityAddOperation = Util.createAddOperation();
    PathElement elytronTLSEntityPath = null;
    final EnumSet<Attribute> required = EnumSet.of(Attribute.NAME, Attribute.LEGACY_JSSE_CONFIG);
    final int count = reader.getAttributeCount();
    for (int i = 0; i < count; i++) {
        requireNoNamespaceAttribute(reader, i);
        final String value = reader.getAttributeValue(i);
        final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
        required.remove(attribute);
        switch(attribute) {
            case NAME:
                {
                    if (value == null || value.length() == 0) {
                        throw invalidAttributeValue(reader, i);
                    }
                    elytronTLSEntityPath = PathElement.pathElement(tlsEntityName, value);
                    break;
                }
            case LEGACY_JSSE_CONFIG:
                {
                    LEGACY_JSSE_CONFIG.parseAndSetParameter(value, elytronTLSEntityAddOperation, reader);
                    break;
                }
            default:
                throw unexpectedAttribute(reader, i);
        }
    }
    if (!required.isEmpty()) {
        throw missingRequired(reader, required);
    }
    elytronTLSEntityAddOperation.get(OP_ADDR).set(subsystemPath.append(elytronTLSEntityPath).toModelNode());
    operations.add(elytronTLSEntityAddOperation);
    requireNoContent(reader);
}
Also used : PathElement(org.jboss.as.controller.PathElement) ParseUtils.unexpectedAttribute(org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute) ParseUtils.requireNoNamespaceAttribute(org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute) ModelNode(org.jboss.dmr.ModelNode)

Example 39 with PathElement

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

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

the class ConnectionDefinitionStatisticsService method stop.

@Override
public void stop(StopContext context) {
    PathElement peCD = PathElement.pathElement(Constants.STATISTICS_NAME, "pool");
    if (overrideRegistration.getSubModel(PathAddress.pathAddress(peCD)) != null) {
        overrideRegistration.unregisterSubModel(peCD);
    }
    PathElement peExtended = PathElement.pathElement(Constants.STATISTICS_NAME, "extended");
    if (overrideRegistration.getSubModel(PathAddress.pathAddress(peExtended)) != null) {
        overrideRegistration.unregisterSubModel(peExtended);
    }
}
Also used : PathElement(org.jboss.as.controller.PathElement)

Aggregations

PathElement (org.jboss.as.controller.PathElement)84 PathAddress (org.jboss.as.controller.PathAddress)47 ModelNode (org.jboss.dmr.ModelNode)46 Resource (org.jboss.as.controller.registry.Resource)24 OperationFailedException (org.jboss.as.controller.OperationFailedException)12 ServiceName (org.jboss.msc.service.ServiceName)12 Test (org.junit.Test)10 Map (java.util.Map)9 ArrayList (java.util.ArrayList)8 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)8 ParseUtils.requireNoNamespaceAttribute (org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute)7 ParseUtils.unexpectedAttribute (org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute)7 ManagementResourceRegistration (org.jboss.as.controller.registry.ManagementResourceRegistration)7 DeploymentResourceSupport (org.jboss.as.server.deployment.DeploymentResourceSupport)7 AbstractSubsystemBaseTest (org.jboss.as.subsystem.test.AbstractSubsystemBaseTest)7 ServiceTarget (org.jboss.msc.service.ServiceTarget)6 StatisticsResourceDefinition (org.jboss.as.connector.dynamicresource.StatisticsResourceDefinition)4 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)4 OperationContext (org.jboss.as.controller.OperationContext)4 StandardResourceDescriptionResolver (org.jboss.as.controller.descriptions.StandardResourceDescriptionResolver)4