Search in sources :

Example 86 with AttributeDefinition

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

the class StatisticsResourceDefinition method getAttributesFromPlugin.

public static List<AttributeDefinition> getAttributesFromPlugin(StatisticsPlugin plugin) {
    LinkedList<AttributeDefinition> result = new LinkedList<>();
    for (String name : plugin.getNames()) {
        ModelType modelType = ModelType.STRING;
        if (plugin.getType(name) == int.class) {
            modelType = ModelType.INT;
        }
        if (plugin.getType(name) == long.class) {
            modelType = ModelType.LONG;
        }
        SimpleAttributeDefinition attribute = new SimpleAttributeDefinitionBuilder(name, modelType).setRequired(false).setStorageRuntime().build();
        result.add(attribute);
    }
    return result;
}
Also used : SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) ModelType(org.jboss.dmr.ModelType) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) SimpleAttributeDefinitionBuilder(org.jboss.as.controller.SimpleAttributeDefinitionBuilder) LinkedList(java.util.LinkedList)

Example 87 with AttributeDefinition

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

the class StatisticsResourceDefinition method registerAttributes.

@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
    super.registerAttributes(resourceRegistration);
    for (AttributeDefinition attribute : getAttributesFromPlugin(plugin)) {
        resourceRegistration.registerMetric(attribute, new PoolMetrics.ParametrizedPoolMetricsHandler(plugin));
    }
    // adding enable/disable for pool stats
    OperationStepHandler readHandler = new PoolStatisticsRuntimeAttributeReadHandler(plugin);
    OperationStepHandler writeHandler = new PoolStatisticsRuntimeAttributeWriteHandler(plugin);
    resourceRegistration.registerReadWriteAttribute(org.jboss.as.connector.subsystems.common.pool.Constants.POOL_STATISTICS_ENABLED, readHandler, writeHandler);
}
Also used : OperationStepHandler(org.jboss.as.controller.OperationStepHandler) PoolStatisticsRuntimeAttributeWriteHandler(org.jboss.as.connector.subsystems.common.pool.PoolStatisticsRuntimeAttributeWriteHandler) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) PoolStatisticsRuntimeAttributeReadHandler(org.jboss.as.connector.subsystems.common.pool.PoolStatisticsRuntimeAttributeReadHandler) PoolMetrics(org.jboss.as.connector.subsystems.common.pool.PoolMetrics)

Example 88 with AttributeDefinition

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

the class JdbcDriverAdd method populateModel.

protected void populateModel(ModelNode operation, ModelNode model) throws OperationFailedException {
    final ModelNode address = operation.require(OP_ADDR);
    final String driverName = PathAddress.pathAddress(address).getLastElement().getValue();
    for (AttributeDefinition attribute : Constants.JDBC_DRIVER_ATTRIBUTES) {
        // https://issues.jboss.org/browse/WFLY-9324 skip validation on driver-name
        if (!attribute.getName().equals(DRIVER_NAME_NAME)) {
            attribute.validateAndSet(operation, model);
        }
    }
    // this shouldn't be here anymore
    model.get(DRIVER_NAME.getName()).set(driverName);
}
Also used : AttributeDefinition(org.jboss.as.controller.AttributeDefinition) ModelNode(org.jboss.dmr.ModelNode)

Example 89 with AttributeDefinition

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

the class CachedConnectionManagerAdd method createResource.

@Override
protected Resource createResource(OperationContext context, ModelNode operation) {
    // exists, so long as it is configured with the values the parser generates (i.e. no defined attributes)
    try {
        // will fail in normal case
        Resource existing = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS);
        ModelNode model = existing.getModel();
        boolean allDefault = true;
        for (JcaCachedConnectionManagerDefinition.CcmParameters param : JcaCachedConnectionManagerDefinition.CcmParameters.values()) {
            if (param == INSTALL || param == DEBUG || param == ERROR || param == IGNORE_UNKNOWN_CONNECTIONS) {
                AttributeDefinition ad = param.getAttribute();
                // else someone changed something and we need to account for that
                assert !ad.isRequired() : ad.getName();
                if (model.hasDefined(ad.getName())) {
                    allDefault = false;
                    break;
                }
            } else {
                // Someone added a new param since WFLY-2640/WFLY-8141 and did not account for it above
                throw new IllegalStateException();
            }
        }
        if (allDefault) {
            // We can use the existing resource as if we just created it
            return existing;
        }
    // else fall through and call super method which will fail due to resource already being present
    } catch (Resource.NoSuchResourceException normal) {
    // normal case; resource doesn't exist yet so fall through
    }
    return super.createResource(context, operation);
}
Also used : Resource(org.jboss.as.controller.registry.Resource) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) ModelNode(org.jboss.dmr.ModelNode)

Example 90 with AttributeDefinition

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

the class JcaCachedConnectionManagerDefinition method registerAttributes.

@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
    super.registerAttributes(resourceRegistration);
    for (final CcmParameters parameter : CcmParameters.values()) {
        if (parameter != CcmParameters.INSTALL) {
            resourceRegistration.registerReadWriteAttribute(parameter.getAttribute(), null, JcaCachedConnectionManagerWriteHandler.INSTANCE);
        } else {
            AttributeDefinition ad = parameter.getAttribute();
            resourceRegistration.registerReadWriteAttribute(ad, null, new ReloadRequiredWriteAttributeHandler(ad));
        }
    }
}
Also used : SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) ReloadRequiredWriteAttributeHandler(org.jboss.as.controller.ReloadRequiredWriteAttributeHandler)

Aggregations

AttributeDefinition (org.jboss.as.controller.AttributeDefinition)102 ModelNode (org.jboss.dmr.ModelNode)48 SimpleAttributeDefinition (org.jboss.as.controller.SimpleAttributeDefinition)40 PathAddress (org.jboss.as.controller.PathAddress)17 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)16 ReloadRequiredWriteAttributeHandler (org.jboss.as.controller.ReloadRequiredWriteAttributeHandler)14 OperationContext (org.jboss.as.controller.OperationContext)13 Resource (org.jboss.as.controller.registry.Resource)12 Property (org.jboss.dmr.Property)12 ObjectTypeAttributeDefinition (org.jboss.as.controller.ObjectTypeAttributeDefinition)9 PropertiesAttributeDefinition (org.jboss.as.controller.PropertiesAttributeDefinition)9 StringListAttributeDefinition (org.jboss.as.controller.StringListAttributeDefinition)9 OperationFailedException (org.jboss.as.controller.OperationFailedException)8 ArrayList (java.util.ArrayList)7 PrimitiveListAttributeDefinition (org.jboss.as.controller.PrimitiveListAttributeDefinition)6 Map (java.util.Map)5 AbstractAddStepHandler (org.jboss.as.controller.AbstractAddStepHandler)5 SimpleListAttributeDefinition (org.jboss.as.controller.SimpleListAttributeDefinition)5 SimpleOperationDefinitionBuilder (org.jboss.as.controller.SimpleOperationDefinitionBuilder)5 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)5