Search in sources :

Example 61 with OperationStepHandler

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

the class ReadAttributeTranslationHandler method execute.

@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    PathAddress currentAddress = context.getCurrentAddress();
    PathAddress targetAddress = this.translation.getPathAddressTransformation().apply(currentAddress);
    Attribute targetAttribute = this.translation.getTargetAttribute();
    ModelNode targetOperation = Operations.createReadAttributeOperation(targetAddress, targetAttribute);
    if (operation.hasDefined(ModelDescriptionConstants.INCLUDE_DEFAULTS)) {
        targetOperation.get(ModelDescriptionConstants.INCLUDE_DEFAULTS).set(operation.get(ModelDescriptionConstants.INCLUDE_DEFAULTS));
    }
    ImmutableManagementResourceRegistration registration = (currentAddress == targetAddress) ? context.getResourceRegistration() : context.getRootResourceRegistration().getSubModel(targetAddress);
    if (registration == null) {
        throw new OperationFailedException(ControllerLogger.MGMT_OP_LOGGER.noSuchResourceType(targetAddress));
    }
    OperationStepHandler readAttributeHandler = registration.getAttributeAccess(PathAddress.EMPTY_ADDRESS, targetAttribute.getName()).getReadHandler();
    OperationStepHandler readTranslatedAttributeHandler = new ReadTranslatedAttributeStepHandler(readAttributeHandler, targetAttribute, this.translation.getReadTranslator());
    // If targetOperation applies to the current resource, we can execute in the current step
    if (targetAddress == currentAddress) {
        readTranslatedAttributeHandler.execute(context, targetOperation);
    } else {
        if (registration.isRuntimeOnly()) {
            try {
                context.readResourceFromRoot(targetAddress, false);
            } catch (Resource.NoSuchResourceException ignore) {
                // If the target runtime resource does not exist return UNDEFINED
                return;
            }
        }
        context.addStep(targetOperation, readTranslatedAttributeHandler, context.getCurrentStage(), true);
    }
}
Also used : OperationStepHandler(org.jboss.as.controller.OperationStepHandler) PathAddress(org.jboss.as.controller.PathAddress) OperationFailedException(org.jboss.as.controller.OperationFailedException) Resource(org.jboss.as.controller.registry.Resource) ImmutableManagementResourceRegistration(org.jboss.as.controller.registry.ImmutableManagementResourceRegistration) ModelNode(org.jboss.dmr.ModelNode)

Example 62 with OperationStepHandler

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

the class AddStepHandler method execute.

@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    PathAddress address = context.getCurrentAddress();
    PathAddress parentAddress = address.getParent();
    PathElement path = address.getLastElement();
    OperationStepHandler parentHandler = context.getRootResourceRegistration().getOperationHandler(parentAddress, ModelDescriptionConstants.ADD);
    if (parentHandler instanceof DescribedAddStepHandler) {
        AddStepHandlerDescriptor parentDescriptor = ((DescribedAddStepHandler) parentHandler).getDescriptor();
        if (parentDescriptor.getRequiredChildren().contains(path)) {
            if (context.readResourceFromRoot(parentAddress, false).hasChild(path)) {
                // If we are a required child resource of our parent, we need to remove the auto-created resource first
                context.addStep(Util.createRemoveOperation(address), context.getRootResourceRegistration().getOperationHandler(address, ModelDescriptionConstants.REMOVE), OperationContext.Stage.MODEL);
                context.addStep(operation, this, OperationContext.Stage.MODEL);
                return;
            }
        }
        for (PathElement requiredPath : parentDescriptor.getRequiredSingletonChildren()) {
            String requiredPathKey = requiredPath.getKey();
            if (requiredPath.getKey().equals(path.getKey())) {
                Set<String> childrenNames = context.readResourceFromRoot(parentAddress, false).getChildrenNames(requiredPathKey);
                if (!childrenNames.isEmpty()) {
                    // If there is a required singleton sibling resource, we need to remove it first
                    for (String childName : childrenNames) {
                        PathAddress singletonAddress = parentAddress.append(requiredPathKey, childName);
                        context.addStep(Util.createRemoveOperation(singletonAddress), context.getRootResourceRegistration().getOperationHandler(singletonAddress, ModelDescriptionConstants.REMOVE), OperationContext.Stage.MODEL);
                    }
                    context.addStep(operation, this, OperationContext.Stage.MODEL);
                    return;
                }
            }
        }
    }
    super.execute(context, operation);
    if (this.requiresRuntime(context)) {
        for (RuntimeResourceRegistration registration : this.descriptor.getRuntimeResourceRegistrations()) {
            context.addStep(new RuntimeResourceRegistrationStepHandler(registration), OperationContext.Stage.MODEL);
        }
    }
}
Also used : PathElement(org.jboss.as.controller.PathElement) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) PathAddress(org.jboss.as.controller.PathAddress)

Example 63 with OperationStepHandler

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

the class CacheContainerResourceDefinition method register.

@Override
public ManagementResourceRegistration register(ManagementResourceRegistration parent) {
    ManagementResourceRegistration registration = parent.registerSubModel(this);
    ResourceDescriptor descriptor = new ResourceDescriptor(this.getResourceDescriptionResolver()).addAttributes(Attribute.class).addAttributes(ListAttribute.class).addIgnoredAttributes(ExecutorAttribute.class).addIgnoredAttributes(EnumSet.complementOf(EnumSet.of(DeprecatedAttribute.MODULE))).addAttributeTranslation(DeprecatedAttribute.MODULE, new ListAttributeTranslation(ListAttribute.MODULES)).addCapabilities(Capability.class).addCapabilities(model -> model.hasDefined(Attribute.DEFAULT_CACHE.getName()), DEFAULT_CAPABILITIES.values()).addCapabilities(model -> model.hasDefined(Attribute.DEFAULT_CACHE.getName()), DEFAULT_CLUSTERING_CAPABILITIES.values()).addRequiredChildren(EnumSet.complementOf(EnumSet.of(ThreadPoolResourceDefinition.CLIENT))).addRequiredChildren(ScheduledThreadPoolResourceDefinition.class).addRequiredSingletonChildren(NoTransportResourceDefinition.PATH).setResourceTransformation(CacheContainerResource::new);
    ServiceValueExecutorRegistry<EmbeddedCacheManager> managerExecutors = new ServiceValueExecutorRegistry<>();
    ServiceValueExecutorRegistry<Cache<?, ?>> cacheExecutors = new ServiceValueExecutorRegistry<>();
    ResourceServiceHandler handler = new CacheContainerServiceHandler(managerExecutors, cacheExecutors);
    new SimpleResourceRegistration(descriptor, handler).register(registration);
    // Translate legacy add-alias operation to list-add operation
    OperationStepHandler addAliasHandler = new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode legacyOperation) {
            String value = legacyOperation.get(ALIAS.getName()).asString();
            ModelNode operation = Operations.createListAddOperation(context.getCurrentAddress(), ListAttribute.ALIASES, value);
            context.addStep(operation, ListOperations.LIST_ADD_HANDLER, context.getCurrentStage());
        }
    };
    registration.registerOperationHandler(ALIAS_ADD, addAliasHandler);
    // Translate legacy remove-alias operation to list-remove operation
    OperationStepHandler removeAliasHandler = new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode legacyOperation) throws OperationFailedException {
            String value = legacyOperation.get(ALIAS.getName()).asString();
            ModelNode operation = Operations.createListRemoveOperation(context.getCurrentAddress(), ListAttribute.ALIASES, value);
            context.addStep(operation, ListOperations.LIST_REMOVE_HANDLER, context.getCurrentStage());
        }
    };
    registration.registerOperationHandler(ALIAS_REMOVE, removeAliasHandler);
    if (registration.isRuntimeOnlyRegistrationValid()) {
        new MetricHandler<>(new CacheContainerMetricExecutor(managerExecutors), CacheContainerMetric.class).register(registration);
        new CacheRuntimeResourceDefinition(cacheExecutors).register(registration);
    }
    new JGroupsTransportResourceDefinition().register(registration);
    new NoTransportResourceDefinition().register(registration);
    for (ThreadPoolResourceDefinition pool : EnumSet.complementOf(EnumSet.of(ThreadPoolResourceDefinition.CLIENT))) {
        pool.register(registration);
    }
    for (ScheduledThreadPoolResourceDefinition pool : EnumSet.allOf(ScheduledThreadPoolResourceDefinition.class)) {
        pool.register(registration);
    }
    new LocalCacheResourceDefinition(cacheExecutors).register(registration);
    new InvalidationCacheResourceDefinition(cacheExecutors).register(registration);
    new ReplicatedCacheResourceDefinition(cacheExecutors).register(registration);
    new DistributedCacheResourceDefinition(cacheExecutors).register(registration);
    new ScatteredCacheResourceDefinition(cacheExecutors).register(registration);
    return registration;
}
Also used : OperationStepHandler(org.jboss.as.controller.OperationStepHandler) SimpleResourceRegistration(org.jboss.as.clustering.controller.SimpleResourceRegistration) Operations(org.jboss.as.clustering.controller.Operations) SimpleAttributeDefinitionBuilder(org.jboss.as.controller.SimpleAttributeDefinitionBuilder) StringListAttributeDefinition(org.jboss.as.controller.StringListAttributeDefinition) UnaryOperator(java.util.function.UnaryOperator) Cache(org.infinispan.Cache) CapabilityReference(org.jboss.as.clustering.controller.CapabilityReference) AttributeAccess(org.jboss.as.controller.registry.AttributeAccess) OperationContext(org.jboss.as.controller.OperationContext) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) InfinispanLogger(org.jboss.as.clustering.infinispan.InfinispanLogger) InfinispanRequirement(org.wildfly.clustering.infinispan.spi.InfinispanRequirement) Map(java.util.Map) ChildResourceDefinition(org.jboss.as.clustering.controller.ChildResourceDefinition) SimpleOperationDefinitionBuilder(org.jboss.as.controller.SimpleOperationDefinitionBuilder) ModelDescriptionConstants(org.jboss.as.controller.descriptions.ModelDescriptionConstants) EnumSet(java.util.EnumSet) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) UnaryRequirement(org.wildfly.clustering.service.UnaryRequirement) ClusteringCacheRequirement(org.wildfly.clustering.spi.ClusteringCacheRequirement) ManagementResourceRegistration(org.jboss.as.clustering.controller.ManagementResourceRegistration) OperationDefinition(org.jboss.as.controller.OperationDefinition) EnumMap(java.util.EnumMap) InfinispanMarshallerFactory(org.wildfly.clustering.infinispan.spi.marshalling.InfinispanMarshallerFactory) EnumValidator(org.jboss.as.clustering.controller.validation.EnumValidator) ListOperations(org.jboss.as.controller.operations.global.ListOperations) ResourceDescriptor(org.jboss.as.clustering.controller.ResourceDescriptor) PathElement(org.jboss.as.controller.PathElement) ServiceValueExecutorRegistry(org.jboss.as.clustering.controller.ServiceValueExecutorRegistry) ResourceServiceHandler(org.jboss.as.clustering.controller.ResourceServiceHandler) UnaryRequirementCapability(org.jboss.as.clustering.controller.UnaryRequirementCapability) OperationFailedException(org.jboss.as.controller.OperationFailedException) InfinispanCacheRequirement(org.wildfly.clustering.infinispan.spi.InfinispanCacheRequirement) ListAttributeTranslation(org.jboss.as.clustering.controller.ListAttributeTranslation) ModelNode(org.jboss.dmr.ModelNode) MetricHandler(org.jboss.as.clustering.controller.MetricHandler) CapabilityProvider(org.jboss.as.clustering.controller.CapabilityProvider) ModuleIdentifierValidatorBuilder(org.jboss.as.clustering.controller.validation.ModuleIdentifierValidatorBuilder) ModelType(org.jboss.dmr.ModelType) ListAttributeTranslation(org.jboss.as.clustering.controller.ListAttributeTranslation) ManagementResourceRegistration(org.jboss.as.clustering.controller.ManagementResourceRegistration) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) SimpleResourceRegistration(org.jboss.as.clustering.controller.SimpleResourceRegistration) OperationContext(org.jboss.as.controller.OperationContext) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) ServiceValueExecutorRegistry(org.jboss.as.clustering.controller.ServiceValueExecutorRegistry) ModelNode(org.jboss.dmr.ModelNode) ResourceServiceHandler(org.jboss.as.clustering.controller.ResourceServiceHandler) ResourceDescriptor(org.jboss.as.clustering.controller.ResourceDescriptor) Cache(org.infinispan.Cache)

Example 64 with OperationStepHandler

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

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

the class GetInstalledDriverOperationHandler method execute.

@Override
public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException {
    validator.validate(operation);
    final String name = operation.require(DRIVER_NAME.getName()).asString();
    if (context.isNormalServer()) {
        context.addStep(new OperationStepHandler() {

            @Override
            public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException {
                ServiceRegistry registry = context.getServiceRegistry(false);
                DriverRegistry driverRegistry = (DriverRegistry) registry.getRequiredService(ConnectorServices.JDBC_DRIVER_REGISTRY_SERVICE).getValue();
                ServiceModuleLoader serviceModuleLoader = (ServiceModuleLoader) registry.getRequiredService(Services.JBOSS_SERVICE_MODULE_LOADER).getValue();
                ModelNode result = new ModelNode();
                InstalledDriver driver = driverRegistry.getInstalledDriver(name);
                ModelNode driverNode = new ModelNode();
                driverNode.get(DRIVER_NAME.getName()).set(driver.getDriverName());
                if (driver.isFromDeployment()) {
                    driverNode.get(DEPLOYMENT_NAME.getName()).set(driver.getDriverName());
                    driverNode.get(DRIVER_MODULE_NAME.getName());
                    driverNode.get(MODULE_SLOT.getName());
                    driverNode.get(DRIVER_DATASOURCE_CLASS_NAME.getName());
                    driverNode.get(DRIVER_XA_DATASOURCE_CLASS_NAME.getName());
                } else {
                    driverNode.get(DEPLOYMENT_NAME.getName());
                    driverNode.get(DRIVER_MODULE_NAME.getName()).set(driver.getModuleName().getName());
                    driverNode.get(MODULE_SLOT.getName()).set(driver.getModuleName() != null ? driver.getModuleName().getSlot() : "");
                    driverNode.get(DRIVER_DATASOURCE_CLASS_NAME.getName()).set(driver.getDataSourceClassName() != null ? driver.getDataSourceClassName() : "");
                    driverNode.get(DRIVER_XA_DATASOURCE_CLASS_NAME.getName()).set(driver.getXaDataSourceClassName() != null ? driver.getXaDataSourceClassName() : "");
                }
                driverNode.get(DATASOURCE_CLASS_INFO.getName()).set(dsClsInfoNode(serviceModuleLoader, driver.getModuleName(), driver.getDataSourceClassName(), driver.getXaDataSourceClassName()));
                driverNode.get(DRIVER_CLASS_NAME.getName()).set(driver.getDriverClassName());
                driverNode.get(DRIVER_MAJOR_VERSION.getName()).set(driver.getMajorVersion());
                driverNode.get(DRIVER_MINOR_VERSION.getName()).set(driver.getMinorVersion());
                driverNode.get(JDBC_COMPLIANT.getName()).set(driver.isJdbcCompliant());
                result.add(driverNode);
                context.getResult().set(result);
            }
        }, OperationContext.Stage.RUNTIME);
    }
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) InstalledDriver(org.jboss.as.connector.services.driver.InstalledDriver) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) DriverRegistry(org.jboss.as.connector.services.driver.registry.DriverRegistry) OperationFailedException(org.jboss.as.controller.OperationFailedException) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ServiceModuleLoader(org.jboss.as.server.moduleservice.ServiceModuleLoader) ModelNode(org.jboss.dmr.ModelNode)

Aggregations

OperationStepHandler (org.jboss.as.controller.OperationStepHandler)76 ModelNode (org.jboss.dmr.ModelNode)57 OperationContext (org.jboss.as.controller.OperationContext)45 OperationFailedException (org.jboss.as.controller.OperationFailedException)40 PathAddress (org.jboss.as.controller.PathAddress)31 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)23 Resource (org.jboss.as.controller.registry.Resource)19 SimpleAttributeDefinition (org.jboss.as.controller.SimpleAttributeDefinition)17 ReloadRequiredWriteAttributeHandler (org.jboss.as.controller.ReloadRequiredWriteAttributeHandler)14 PathElement (org.jboss.as.controller.PathElement)9 ServiceController (org.jboss.msc.service.ServiceController)8 ServiceName (org.jboss.msc.service.ServiceName)8 Map (java.util.Map)7 ImmutableManagementResourceRegistration (org.jboss.as.controller.registry.ImmutableManagementResourceRegistration)7 ArrayList (java.util.ArrayList)6 List (java.util.List)5 ObjectTypeAttributeDefinition (org.jboss.as.controller.ObjectTypeAttributeDefinition)5 PropertiesAttributeDefinition (org.jboss.as.controller.PropertiesAttributeDefinition)5 SimpleOperationDefinitionBuilder (org.jboss.as.controller.SimpleOperationDefinitionBuilder)5 ManagementResourceRegistration (org.jboss.as.clustering.controller.ManagementResourceRegistration)4