Search in sources :

Example 56 with OperationContext

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

the class IDMConfigAddStepHandler method configureModelValidators.

private void configureModelValidators(ModelValidationStepHandler[] modelValidators) {
    List<AttributeDefinition> alternativeAttributes = new ArrayList<AttributeDefinition>();
    for (AttributeDefinition attribute : this.attributes) {
        if (attribute.getAlternatives() != null && attribute.getAlternatives().length > 0) {
            alternativeAttributes.add(attribute);
        }
    }
    if (!alternativeAttributes.isEmpty()) {
        this.modelValidators.add(new AlternativeAttributeValidationStepHandler(alternativeAttributes.toArray(new AttributeDefinition[alternativeAttributes.size()]), isAlternativesRequired()));
    }
    if (modelValidators != null) {
        this.modelValidators.addAll(Arrays.asList(modelValidators));
    }
    this.modelValidators.add(new ModelValidationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            final PathAddress address = getParentAddress(PathAddress.pathAddress(operation.require(OP_ADDR)));
            Resource resource = context.readResourceFromRoot(address);
            final ModelNode parentModel = Resource.Tools.readModel(resource);
            PartitionManagerAddHandler.INSTANCE.validateModel(context, address.getLastElement().getValue(), parentModel);
            context.stepCompleted();
        }
    });
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) PathAddress(org.jboss.as.controller.PathAddress) ArrayList(java.util.ArrayList) OperationFailedException(org.jboss.as.controller.OperationFailedException) Resource(org.jboss.as.controller.registry.Resource) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) ModelValidationStepHandler(org.wildfly.extension.picketlink.common.model.validator.ModelValidationStepHandler) ModelNode(org.jboss.dmr.ModelNode) AlternativeAttributeValidationStepHandler(org.wildfly.extension.picketlink.common.model.validator.AlternativeAttributeValidationStepHandler)

Example 57 with OperationContext

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

the class IdentityStoreRemoveStepHandler method updateModel.

@Override
protected void updateModel(OperationContext context, ModelNode operation) throws OperationFailedException {
    checkIfLastIdentityStore(context);
    super.updateModel(context, operation);
    context.addStep(new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            PathAddress address = context.getCurrentAddress();
            String configurationName = address.getElement(address.size() - 2).getValue();
            String partitionManagerName = address.getElement(address.size() - 3).getValue();
            String identityStoreName = address.getLastElement().getValue();
            context.removeService(PartitionManagerService.createIdentityStoreServiceName(partitionManagerName, configurationName, identityStoreName));
            context.completeStep(OperationContext.ResultHandler.NOOP_RESULT_HANDLER);
        }
    }, OperationContext.Stage.RUNTIME);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) PathAddress(org.jboss.as.controller.PathAddress) OperationFailedException(org.jboss.as.controller.OperationFailedException) ModelNode(org.jboss.dmr.ModelNode)

Example 58 with OperationContext

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

the class LogStoreParticipantDeleteHandler method refreshParticipant.

void refreshParticipant(OperationContext context) {
    final ModelNode operation = Util.createEmptyOperation("refresh-log-store", context.getCurrentAddress().getParent().getParent());
    context.addStep(operation, new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            probeHandler.execute(context, operation);
        }
    }, OperationContext.Stage.MODEL);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) OperationFailedException(org.jboss.as.controller.OperationFailedException) ModelNode(org.jboss.dmr.ModelNode)

Example 59 with OperationContext

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

the class CacheServiceHandler method removeServices.

@Override
public void removeServices(OperationContext context, ModelNode model) {
    PathAddress cacheAddress = context.getCurrentAddress();
    PathAddress containerAddress = cacheAddress.getParent();
    String containerName = containerAddress.getLastElement().getValue();
    String cacheName = cacheAddress.getLastElement().getValue();
    for (CacheBuilderProvider provider : ServiceLoader.load(this.providerClass, this.providerClass.getClassLoader())) {
        for (ServiceNameProvider builder : provider.getBuilders(requirement -> CLUSTERING_CAPABILITIES.get(requirement).getServiceName(cacheAddress), containerName, cacheName)) {
            context.removeService(builder.getServiceName());
        }
    }
    context.removeService(InfinispanBindingFactory.createCacheBinding(containerName, cacheName).getBinderServiceName());
    context.removeService(InfinispanBindingFactory.createCacheConfigurationBinding(containerName, cacheName).getBinderServiceName());
    context.removeService(new XAResourceRecoveryBuilder(cacheAddress).getServiceName());
    context.removeService(CacheComponent.MODULE.getServiceName(cacheAddress));
    EnumSet.allOf(CacheResourceDefinition.Capability.class).stream().map(capability -> capability.getServiceName(cacheAddress)).forEach(serviceName -> context.removeService(serviceName));
}
Also used : ServiceNameProvider(org.wildfly.clustering.service.ServiceNameProvider) Cache(org.infinispan.Cache) ModuleBuilder(org.jboss.as.clustering.controller.ModuleBuilder) OperationContext(org.jboss.as.controller.OperationContext) AliasServiceBuilder(org.wildfly.clustering.service.AliasServiceBuilder) CacheBuilder(org.wildfly.clustering.infinispan.spi.service.CacheBuilder) Capability(org.jboss.as.clustering.infinispan.subsystem.CacheResourceDefinition.Capability) CapabilityServiceBuilder(org.jboss.as.clustering.controller.CapabilityServiceBuilder) ServiceTarget(org.jboss.msc.service.ServiceTarget) EnumSet(java.util.EnumSet) BinderServiceBuilder(org.jboss.as.clustering.naming.BinderServiceBuilder) ContextNames(org.jboss.as.naming.deployment.ContextNames) PathAddress(org.jboss.as.controller.PathAddress) Attribute(org.jboss.as.clustering.infinispan.subsystem.CacheResourceDefinition.Attribute) ServiceLoader(java.util.ServiceLoader) ResourceServiceBuilderFactory(org.jboss.as.clustering.controller.ResourceServiceBuilderFactory) ModelNodes(org.jboss.as.clustering.dmr.ModelNodes) ServiceController(org.jboss.msc.service.ServiceController) ResourceServiceHandler(org.jboss.as.clustering.controller.ResourceServiceHandler) Module(org.jboss.modules.Module) OperationFailedException(org.jboss.as.controller.OperationFailedException) Configuration(org.infinispan.configuration.cache.Configuration) ServiceName(org.jboss.msc.service.ServiceName) CacheBuilderProvider(org.wildfly.clustering.spi.CacheBuilderProvider) ModelNode(org.jboss.dmr.ModelNode) CLUSTERING_CAPABILITIES(org.jboss.as.clustering.infinispan.subsystem.CacheResourceDefinition.CLUSTERING_CAPABILITIES) JndiNameFactory(org.jboss.as.clustering.naming.JndiNameFactory) CacheBuilderProvider(org.wildfly.clustering.spi.CacheBuilderProvider) Capability(org.jboss.as.clustering.infinispan.subsystem.CacheResourceDefinition.Capability) PathAddress(org.jboss.as.controller.PathAddress) ServiceNameProvider(org.wildfly.clustering.service.ServiceNameProvider)

Example 60 with OperationContext

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

the class CacheServiceHandler method installServices.

@Override
public void installServices(OperationContext context, ModelNode model) throws OperationFailedException {
    PathAddress cacheAddress = context.getCurrentAddress();
    PathAddress containerAddress = cacheAddress.getParent();
    String containerName = containerAddress.getLastElement().getValue();
    String cacheName = cacheAddress.getLastElement().getValue();
    ServiceTarget target = context.getServiceTarget();
    ServiceName moduleServiceName = CacheComponent.MODULE.getServiceName(cacheAddress);
    if (model.hasDefined(MODULE.getName())) {
        new ModuleBuilder(moduleServiceName, MODULE).configure(context, model).build(target).install();
    } else {
        new AliasServiceBuilder<>(moduleServiceName, CacheContainerComponent.MODULE.getServiceName(containerAddress), Module.class).build(target).install();
    }
    this.builderFactory.createBuilder(cacheAddress).configure(context, model).build(target).setInitialMode(ServiceController.Mode.PASSIVE).install();
    new CacheBuilder<>(CACHE.getServiceName(cacheAddress), containerName, cacheName).configure(context).build(target).install();
    new XAResourceRecoveryBuilder(cacheAddress).build(target).install();
    new BinderServiceBuilder<>(InfinispanBindingFactory.createCacheConfigurationBinding(containerName, cacheName), CONFIGURATION.getServiceName(cacheAddress), Configuration.class).build(target).install();
    BinderServiceBuilder<?> bindingBuilder = new BinderServiceBuilder<>(InfinispanBindingFactory.createCacheBinding(containerName, cacheName), CACHE.getServiceName(cacheAddress), Cache.class);
    ModelNodes.optionalString(JNDI_NAME.resolveModelAttribute(context, model)).map(jndiName -> ContextNames.bindInfoFor(JndiNameFactory.parse(jndiName).getAbsoluteName())).ifPresent(aliasBinding -> bindingBuilder.alias(aliasBinding));
    bindingBuilder.build(target).install();
    for (CacheBuilderProvider provider : ServiceLoader.load(this.providerClass, this.providerClass.getClassLoader())) {
        for (CapabilityServiceBuilder<?> builder : provider.getBuilders(requirement -> CLUSTERING_CAPABILITIES.get(requirement).getServiceName(cacheAddress), containerName, cacheName)) {
            builder.configure(context).build(target).install();
        }
    }
}
Also used : BinderServiceBuilder(org.jboss.as.clustering.naming.BinderServiceBuilder) ServiceNameProvider(org.wildfly.clustering.service.ServiceNameProvider) Cache(org.infinispan.Cache) ModuleBuilder(org.jboss.as.clustering.controller.ModuleBuilder) OperationContext(org.jboss.as.controller.OperationContext) AliasServiceBuilder(org.wildfly.clustering.service.AliasServiceBuilder) CacheBuilder(org.wildfly.clustering.infinispan.spi.service.CacheBuilder) Capability(org.jboss.as.clustering.infinispan.subsystem.CacheResourceDefinition.Capability) CapabilityServiceBuilder(org.jboss.as.clustering.controller.CapabilityServiceBuilder) ServiceTarget(org.jboss.msc.service.ServiceTarget) EnumSet(java.util.EnumSet) BinderServiceBuilder(org.jboss.as.clustering.naming.BinderServiceBuilder) ContextNames(org.jboss.as.naming.deployment.ContextNames) PathAddress(org.jboss.as.controller.PathAddress) Attribute(org.jboss.as.clustering.infinispan.subsystem.CacheResourceDefinition.Attribute) ServiceLoader(java.util.ServiceLoader) ResourceServiceBuilderFactory(org.jboss.as.clustering.controller.ResourceServiceBuilderFactory) ModelNodes(org.jboss.as.clustering.dmr.ModelNodes) ServiceController(org.jboss.msc.service.ServiceController) ResourceServiceHandler(org.jboss.as.clustering.controller.ResourceServiceHandler) Module(org.jboss.modules.Module) OperationFailedException(org.jboss.as.controller.OperationFailedException) Configuration(org.infinispan.configuration.cache.Configuration) ServiceName(org.jboss.msc.service.ServiceName) CacheBuilderProvider(org.wildfly.clustering.spi.CacheBuilderProvider) ModelNode(org.jboss.dmr.ModelNode) CLUSTERING_CAPABILITIES(org.jboss.as.clustering.infinispan.subsystem.CacheResourceDefinition.CLUSTERING_CAPABILITIES) JndiNameFactory(org.jboss.as.clustering.naming.JndiNameFactory) CacheBuilderProvider(org.wildfly.clustering.spi.CacheBuilderProvider) ServiceTarget(org.jboss.msc.service.ServiceTarget) ModuleBuilder(org.jboss.as.clustering.controller.ModuleBuilder) AliasServiceBuilder(org.wildfly.clustering.service.AliasServiceBuilder) ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress)

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