Search in sources :

Example 61 with OperationContext

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

the class CacheContainerResourceDefinition method register.

@Override
public void register(ManagementResourceRegistration parentRegistration) {
    ManagementResourceRegistration registration = parentRegistration.registerSubModel(this);
    ResourceDescriptor descriptor = new ResourceDescriptor(this.getResourceDescriptionResolver()).addAttributes(Attribute.class).addAttributes(ExecutorAttribute.class).addAttributes(DeprecatedAttribute.class).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(ThreadPoolResourceDefinition.class).addRequiredChildren(ScheduledThreadPoolResourceDefinition.class).addRequiredSingletonChildren(NoTransportResourceDefinition.PATH);
    ResourceServiceHandler handler = new CacheContainerServiceHandler();
    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(), Attribute.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(), Attribute.ALIASES, value);
            context.addStep(operation, ListOperations.LIST_REMOVE_HANDLER, context.getCurrentStage());
        }
    };
    registration.registerOperationHandler(ALIAS_REMOVE, removeAliasHandler);
    if (this.allowRuntimeOnlyRegistration) {
        new MetricHandler<>(new CacheContainerMetricExecutor(), CacheContainerMetric.class).register(registration);
    }
    new JGroupsTransportResourceDefinition().register(registration);
    new NoTransportResourceDefinition().register(registration);
    EnumSet.allOf(ThreadPoolResourceDefinition.class).forEach(p -> p.register(registration));
    EnumSet.allOf(ScheduledThreadPoolResourceDefinition.class).forEach(p -> p.register(registration));
    new LocalCacheResourceDefinition(this.pathManager, this.allowRuntimeOnlyRegistration).register(registration);
    new InvalidationCacheResourceDefinition(this.pathManager, this.allowRuntimeOnlyRegistration).register(registration);
    new ReplicatedCacheResourceDefinition(this.pathManager, this.allowRuntimeOnlyRegistration).register(registration);
    new DistributedCacheResourceDefinition(this.pathManager, this.allowRuntimeOnlyRegistration).register(registration);
}
Also used : DiscardAttributeChecker(org.jboss.as.controller.transform.description.DiscardAttributeChecker) 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) CapabilityReference(org.jboss.as.clustering.controller.CapabilityReference) AttributeAccess(org.jboss.as.controller.registry.AttributeAccess) EnumValidatorBuilder(org.jboss.as.clustering.controller.validation.EnumValidatorBuilder) OperationContext(org.jboss.as.controller.OperationContext) RejectAttributeChecker(org.jboss.as.controller.transform.description.RejectAttributeChecker) OperationTransformer(org.jboss.as.clustering.controller.transform.OperationTransformer) Util(org.jboss.as.controller.operations.common.Util) ResourceTransformationDescriptionBuilder(org.jboss.as.controller.transform.description.ResourceTransformationDescriptionBuilder) InfinispanRequirement(org.wildfly.clustering.infinispan.spi.InfinispanRequirement) Map(java.util.Map) ModelVersion(org.jboss.as.controller.ModelVersion) 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) CapabilityReferenceRecorder(org.jboss.as.controller.CapabilityReferenceRecorder) UnaryRequirement(org.wildfly.clustering.service.UnaryRequirement) ClusteringCacheRequirement(org.wildfly.clustering.spi.ClusteringCacheRequirement) AttributeParsers(org.jboss.as.clustering.controller.AttributeParsers) OperationDefinition(org.jboss.as.controller.OperationDefinition) EnumMap(java.util.EnumMap) PathAddress(org.jboss.as.controller.PathAddress) SimpleOperationTransformer(org.jboss.as.clustering.controller.transform.SimpleOperationTransformer) ListOperations(org.jboss.as.controller.operations.global.ListOperations) ResourceDescriptor(org.jboss.as.clustering.controller.ResourceDescriptor) PathElement(org.jboss.as.controller.PathElement) PathManager(org.jboss.as.controller.services.path.PathManager) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) 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) ModelNode(org.jboss.dmr.ModelNode) MetricHandler(org.jboss.as.clustering.controller.MetricHandler) ParameterValidatorBuilder(org.jboss.as.clustering.controller.validation.ParameterValidatorBuilder) CapabilityProvider(org.jboss.as.clustering.controller.CapabilityProvider) ModuleIdentifierValidatorBuilder(org.jboss.as.clustering.controller.validation.ModuleIdentifierValidatorBuilder) ModelType(org.jboss.dmr.ModelType) OperationContext(org.jboss.as.controller.OperationContext) UnaryRequirementCapability(org.jboss.as.clustering.controller.UnaryRequirementCapability) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) SimpleResourceRegistration(org.jboss.as.clustering.controller.SimpleResourceRegistration) ModelNode(org.jboss.dmr.ModelNode) ResourceServiceHandler(org.jboss.as.clustering.controller.ResourceServiceHandler) ResourceDescriptor(org.jboss.as.clustering.controller.ResourceDescriptor)

Example 62 with OperationContext

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

the class CacheContainerServiceHandler method removeServices.

@Override
public void removeServices(OperationContext context, ModelNode model) throws OperationFailedException {
    PathAddress address = context.getCurrentAddress();
    String name = context.getCurrentAddressValue();
    ModelNodes.optionalString(DEFAULT_CACHE.resolveModelAttribute(context, model)).ifPresent(defaultCache -> {
        for (CacheAliasBuilderProvider provider : ServiceLoader.load(CacheAliasBuilderProvider.class, CacheAliasBuilderProvider.class.getClassLoader())) {
            for (ServiceNameProvider builder : provider.getBuilders(requirement -> DEFAULT_CLUSTERING_CAPABILITIES.get(requirement).getServiceName(address), name, null, defaultCache)) {
                context.removeService(builder.getServiceName());
            }
        }
        if (!defaultCache.equals(JndiNameFactory.DEFAULT_LOCAL_NAME)) {
            context.removeService(InfinispanBindingFactory.createCacheBinding(name, JndiNameFactory.DEFAULT_LOCAL_NAME).getBinderServiceName());
            context.removeService(InfinispanBindingFactory.createCacheConfigurationBinding(name, JndiNameFactory.DEFAULT_LOCAL_NAME).getBinderServiceName());
        }
        DEFAULT_CAPABILITIES.values().forEach(capability -> context.removeService(capability.getServiceName(address)));
    });
    context.removeService(InfinispanBindingFactory.createCacheContainerBinding(name).getBinderServiceName());
    context.removeService(CacheContainerComponent.MODULE.getServiceName(address));
    EnumSet.allOf(CacheContainerResourceDefinition.Capability.class).stream().map(component -> component.getServiceName(address)).forEach(serviceName -> context.removeService(serviceName));
}
Also used : OperationStepHandler(org.jboss.as.controller.OperationStepHandler) ServiceNameProvider(org.wildfly.clustering.service.ServiceNameProvider) Cache(org.infinispan.Cache) CacheContainer(org.wildfly.clustering.infinispan.spi.CacheContainer) ModuleBuilder(org.jboss.as.clustering.controller.ModuleBuilder) OperationContext(org.jboss.as.controller.OperationContext) AliasServiceBuilder(org.wildfly.clustering.service.AliasServiceBuilder) CacheAliasBuilderProvider(org.wildfly.clustering.spi.CacheAliasBuilderProvider) DEFAULT_CLUSTERING_CAPABILITIES(org.jboss.as.clustering.infinispan.subsystem.CacheContainerResourceDefinition.DEFAULT_CLUSTERING_CAPABILITIES) CapabilityServiceBuilder(org.jboss.as.clustering.controller.CapabilityServiceBuilder) ServiceTarget(org.jboss.msc.service.ServiceTarget) Attribute(org.jboss.as.clustering.infinispan.subsystem.CacheContainerResourceDefinition.Attribute) ModelDescriptionConstants(org.jboss.as.controller.descriptions.ModelDescriptionConstants) EnumSet(java.util.EnumSet) BinderServiceBuilder(org.jboss.as.clustering.naming.BinderServiceBuilder) ContextNames(org.jboss.as.naming.deployment.ContextNames) Resource(org.jboss.as.controller.registry.Resource) PathAddress(org.jboss.as.controller.PathAddress) ServiceLoader(java.util.ServiceLoader) PathElement(org.jboss.as.controller.PathElement) ModelNodes(org.jboss.as.clustering.dmr.ModelNodes) ResourceServiceHandler(org.jboss.as.clustering.controller.ResourceServiceHandler) OperationFailedException(org.jboss.as.controller.OperationFailedException) DEFAULT_CAPABILITIES(org.jboss.as.clustering.infinispan.subsystem.CacheContainerResourceDefinition.DEFAULT_CAPABILITIES) Configuration(org.infinispan.configuration.cache.Configuration) InfinispanCacheRequirement(org.wildfly.clustering.infinispan.spi.InfinispanCacheRequirement) ModelNode(org.jboss.dmr.ModelNode) JndiNameFactory(org.jboss.as.clustering.naming.JndiNameFactory) CacheAliasBuilderProvider(org.wildfly.clustering.spi.CacheAliasBuilderProvider) PathAddress(org.jboss.as.controller.PathAddress) ServiceNameProvider(org.wildfly.clustering.service.ServiceNameProvider)

Example 63 with OperationContext

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

the class JdrReportRequestHandler method execute.

@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
    // In MODEL stage, just validate the request. Unnecessary if the request has no parameters
    validator.validate(operation);
    // Register a handler for the RUNTIME stage
    context.addStep(new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            ServiceRegistry registry = context.getServiceRegistry(false);
            JdrReportCollector jdrCollector = JdrReportCollector.class.cast(registry.getRequiredService(JdrReportService.SERVICE_NAME).getValue());
            ModelNode response = context.getResult();
            JdrReport report = jdrCollector.collect();
            if (report.getStartTime() != null) {
                response.get("start-time").set(report.getStartTime().toString());
            }
            if (report.getEndTime() != null) {
                response.get("end-time").set(report.getEndTime().toString());
            }
            response.get("report-location").set(report.getLocation());
            context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
        }
    }, OperationContext.Stage.RUNTIME);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) OperationFailedException(org.jboss.as.controller.OperationFailedException) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ModelNode(org.jboss.dmr.ModelNode)

Example 64 with OperationContext

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

the class NamingBindingResourceDefinition method registerOperations.

@Override
public void registerOperations(ManagementResourceRegistration resourceRegistration) {
    super.registerOperations(resourceRegistration);
    SimpleOperationDefinitionBuilder builder = new SimpleOperationDefinitionBuilder(NamingSubsystemModel.REBIND, getResourceDescriptionResolver()).addParameter(BINDING_TYPE).addParameter(TYPE).addParameter(VALUE).addParameter(CLASS).addParameter(MODULE).addParameter(LOOKUP).addParameter(ENVIRONMENT);
    resourceRegistration.registerOperationHandler(builder.build(), new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            context.addStep(new OperationStepHandler() {

                @Override
                public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
                    validateResourceModel(operation, false);
                    Resource resource = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS);
                    ModelNode model = resource.getModel();
                    for (AttributeDefinition attr : ATTRIBUTES) {
                        attr.validateAndSet(operation, model);
                    }
                    context.addStep(new OperationStepHandler() {

                        @Override
                        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
                            final String name = context.getCurrentAddressValue();
                            final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(name);
                            ServiceController<ManagedReferenceFactory> service = (ServiceController<ManagedReferenceFactory>) context.getServiceRegistry(false).getService(bindInfo.getBinderServiceName());
                            if (service == null) {
                                context.reloadRequired();
                                return;
                            }
                            NamingBindingAdd.INSTANCE.doRebind(context, operation, (BinderService) service.getService());
                        }
                    }, OperationContext.Stage.RUNTIME);
                }
            }, OperationContext.Stage.MODEL);
        }
    });
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) SimpleOperationDefinitionBuilder(org.jboss.as.controller.SimpleOperationDefinitionBuilder) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) OperationFailedException(org.jboss.as.controller.OperationFailedException) Resource(org.jboss.as.controller.registry.Resource) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) SimpleAttributeDefinition(org.jboss.as.controller.SimpleAttributeDefinition) PropertiesAttributeDefinition(org.jboss.as.controller.PropertiesAttributeDefinition) BinderService(org.jboss.as.naming.service.BinderService) ManagedReferenceFactory(org.jboss.as.naming.ManagedReferenceFactory) ServiceController(org.jboss.msc.service.ServiceController) ModelNode(org.jboss.dmr.ModelNode)

Example 65 with OperationContext

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

the class StorePropertyResourceDefinition method register.

@Override
public void register(ManagementResourceRegistration parentRegistration) {
    ManagementResourceRegistration registration = parentRegistration.registerSubModel(this);
    AbstractAddStepHandler addHandler = new AbstractAddStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) {
            context.createResource(PathAddress.EMPTY_ADDRESS);
            String name = context.getCurrentAddressValue();
            String value = operation.get(VALUE.getName()).asString();
            PathAddress storeAddress = context.getCurrentAddress().getParent();
            ModelNode putOperation = Operations.createMapPutOperation(storeAddress, StoreResourceDefinition.Attribute.PROPERTIES, name, value);
            context.addStep(putOperation, MapOperations.MAP_PUT_HANDLER, context.getCurrentStage());
        }
    };
    this.registerAddOperation(registration, addHandler);
    AbstractRemoveStepHandler removeHandler = new AbstractRemoveStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) {
            context.removeResource(PathAddress.EMPTY_ADDRESS);
            String name = context.getCurrentAddressValue();
            PathAddress storeAddress = context.getCurrentAddress().getParent();
            ModelNode putOperation = Operations.createMapRemoveOperation(storeAddress, StoreResourceDefinition.Attribute.PROPERTIES, name);
            context.addStep(putOperation, MapOperations.MAP_REMOVE_HANDLER, context.getCurrentStage());
        }
    };
    this.registerRemoveOperation(registration, removeHandler);
    OperationStepHandler readHandler = new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) {
            PathAddress address = context.getCurrentAddress().getParent();
            String key = context.getCurrentAddressValue();
            ModelNode getOperation = Operations.createMapGetOperation(address, StoreResourceDefinition.Attribute.PROPERTIES, key);
            context.addStep(getOperation, MapOperations.MAP_GET_HANDLER, context.getCurrentStage());
        }
    };
    OperationStepHandler writeHandler = new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) {
            PathAddress address = context.getCurrentAddress().getParent();
            String key = context.getCurrentAddressValue();
            String value = Operations.getAttributeValue(operation).asString();
            ModelNode putOperation = Operations.createMapPutOperation(address, StoreResourceDefinition.Attribute.PROPERTIES, key, value);
            context.addStep(putOperation, MapOperations.MAP_PUT_HANDLER, context.getCurrentStage());
        }
    };
    registration.registerReadWriteAttribute(VALUE, readHandler, writeHandler);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) AbstractAddStepHandler(org.jboss.as.controller.AbstractAddStepHandler) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) PathAddress(org.jboss.as.controller.PathAddress) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) ModelNode(org.jboss.dmr.ModelNode) AbstractRemoveStepHandler(org.jboss.as.controller.AbstractRemoveStepHandler)

Aggregations

OperationContext (org.jboss.as.controller.OperationContext)67 ModelNode (org.jboss.dmr.ModelNode)67 OperationFailedException (org.jboss.as.controller.OperationFailedException)51 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)40 PathAddress (org.jboss.as.controller.PathAddress)34 ServiceController (org.jboss.msc.service.ServiceController)18 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)17 Resource (org.jboss.as.controller.registry.Resource)16 ServiceName (org.jboss.msc.service.ServiceName)13 SimpleAttributeDefinition (org.jboss.as.controller.SimpleAttributeDefinition)11 ServiceTarget (org.jboss.msc.service.ServiceTarget)11 ResourceServiceHandler (org.jboss.as.clustering.controller.ResourceServiceHandler)9 AbstractAddStepHandler (org.jboss.as.controller.AbstractAddStepHandler)8 InjectedValue (org.jboss.msc.value.InjectedValue)8 EnumSet (java.util.EnumSet)7 Map (java.util.Map)7 PathElement (org.jboss.as.controller.PathElement)7 ManagementResourceRegistration (org.jboss.as.controller.registry.ManagementResourceRegistration)7 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)7 ArrayList (java.util.ArrayList)6