Search in sources :

Example 41 with OperationFailedException

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

the class JGroupsTransportServiceHandler method removeServices.

@Override
public void removeServices(OperationContext context, ModelNode model) throws OperationFailedException {
    PathAddress address = context.getCurrentAddress();
    PathAddress containerAddress = address.getParent();
    String name = containerAddress.getLastElement().getValue();
    for (GroupAliasBuilderProvider provider : ServiceLoader.load(GroupAliasBuilderProvider.class, GroupAliasBuilderProvider.class.getClassLoader())) {
        for (ServiceNameProvider builder : provider.getBuilders(requirement -> CLUSTERING_CAPABILITIES.get(requirement).getServiceName(address), name, null)) {
            context.removeService(builder.getServiceName());
        }
    }
    EnumSet.allOf(CacheContainerComponent.class).stream().map(component -> component.getServiceName(containerAddress)).forEach(serviceName -> context.removeService(serviceName));
}
Also used : JGroupsTransportResourceDefinition(org.jboss.as.clustering.infinispan.subsystem.JGroupsTransportResourceDefinition) ServiceNameProvider(org.wildfly.clustering.service.ServiceNameProvider) PathAddress(org.jboss.as.controller.PathAddress) ServiceLoader(java.util.ServiceLoader) ServiceController(org.jboss.msc.service.ServiceController) OperationContext(org.jboss.as.controller.OperationContext) ResourceServiceHandler(org.jboss.as.clustering.controller.ResourceServiceHandler) OperationFailedException(org.jboss.as.controller.OperationFailedException) ModelNode(org.jboss.dmr.ModelNode) CapabilityServiceBuilder(org.jboss.as.clustering.controller.CapabilityServiceBuilder) ServiceTarget(org.jboss.msc.service.ServiceTarget) GroupAliasBuilderProvider(org.wildfly.clustering.spi.GroupAliasBuilderProvider) EnumSet(java.util.EnumSet) GroupAliasBuilderProvider(org.wildfly.clustering.spi.GroupAliasBuilderProvider) PathAddress(org.jboss.as.controller.PathAddress) ServiceNameProvider(org.wildfly.clustering.service.ServiceNameProvider)

Example 42 with OperationFailedException

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

the class CacheContainerServiceHandler method installServices.

@Override
public void installServices(OperationContext context, ModelNode model) throws OperationFailedException {
    PathAddress address = context.getCurrentAddress();
    String name = context.getCurrentAddressValue();
    // This can happen if the ejb cache-container is added to a running server
    if (context.getProcessType().isServer() && !context.isBooting() && name.equals("ejb")) {
        Resource rootResource = context.readResourceFromRoot(PathAddress.EMPTY_ADDRESS);
        PathElement ejbPath = PathElement.pathElement(ModelDescriptionConstants.SUBSYSTEM, "ejb3");
        if (rootResource.hasChild(ejbPath) && rootResource.getChild(ejbPath).hasChild(PathElement.pathElement("service", "remote"))) {
            // Following restart, these services will be installed by this handler, rather than the ejb remote handler
            context.addStep(new OperationStepHandler() {

                @Override
                public void execute(final OperationContext context, final ModelNode operation) throws OperationFailedException {
                    context.reloadRequired();
                    context.completeStep(OperationContext.RollbackHandler.REVERT_RELOAD_REQUIRED_ROLLBACK_HANDLER);
                }
            }, OperationContext.Stage.RUNTIME);
            return;
        }
    }
    ServiceTarget target = context.getServiceTarget();
    new ModuleBuilder(CacheContainerComponent.MODULE.getServiceName(address), MODULE).configure(context, model).build(target).install();
    new GlobalConfigurationBuilder(address).configure(context, model).build(target).install();
    CacheContainerBuilder containerBuilder = new CacheContainerBuilder(address).configure(context, model);
    containerBuilder.build(target).install();
    new KeyAffinityServiceFactoryBuilder(address).build(target).install();
    BinderServiceBuilder<?> bindingBuilder = new BinderServiceBuilder<>(InfinispanBindingFactory.createCacheContainerBinding(name), containerBuilder.getServiceName(), CacheContainer.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();
    String defaultCache = containerBuilder.getDefaultCache();
    if (defaultCache != null) {
        DEFAULT_CAPABILITIES.entrySet().forEach(entry -> new AliasServiceBuilder<>(entry.getValue().getServiceName(address), entry.getKey().getServiceName(context, name, defaultCache), entry.getKey().getType()).build(target).install());
        if (!defaultCache.equals(JndiNameFactory.DEFAULT_LOCAL_NAME)) {
            new BinderServiceBuilder<>(InfinispanBindingFactory.createCacheBinding(name, JndiNameFactory.DEFAULT_LOCAL_NAME), DEFAULT_CAPABILITIES.get(InfinispanCacheRequirement.CACHE).getServiceName(address), Cache.class).build(target).install();
            new BinderServiceBuilder<>(InfinispanBindingFactory.createCacheConfigurationBinding(name, JndiNameFactory.DEFAULT_LOCAL_NAME), DEFAULT_CAPABILITIES.get(InfinispanCacheRequirement.CONFIGURATION).getServiceName(address), Configuration.class).build(target).install();
        }
        for (CacheAliasBuilderProvider provider : ServiceLoader.load(CacheAliasBuilderProvider.class, CacheAliasBuilderProvider.class.getClassLoader())) {
            for (CapabilityServiceBuilder<?> builder : provider.getBuilders(requirement -> DEFAULT_CLUSTERING_CAPABILITIES.get(requirement).getServiceName(address), name, null, defaultCache)) {
                builder.configure(context).build(target).install();
            }
        }
    }
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) BinderServiceBuilder(org.jboss.as.clustering.naming.BinderServiceBuilder) 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) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) ServiceTarget(org.jboss.msc.service.ServiceTarget) ModuleBuilder(org.jboss.as.clustering.controller.ModuleBuilder) Resource(org.jboss.as.controller.registry.Resource) OperationFailedException(org.jboss.as.controller.OperationFailedException) CacheAliasBuilderProvider(org.wildfly.clustering.spi.CacheAliasBuilderProvider) PathElement(org.jboss.as.controller.PathElement) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode)

Example 43 with OperationFailedException

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

the class AbstractEJBComponentResourceDefinition method registerAttributes.

@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
    final AbstractEJBComponentRuntimeHandler<?> handler = componentType.getRuntimeHandler();
    resourceRegistration.registerReadOnlyAttribute(COMPONENT_CLASS_NAME, handler);
    resourceRegistration.registerReadOnlyAttribute(SECURITY_DOMAIN, handler);
    resourceRegistration.registerReadOnlyAttribute(RUN_AS_ROLE, handler);
    resourceRegistration.registerReadOnlyAttribute(DECLARED_ROLES, handler);
    if (componentType.hasTimer()) {
        resourceRegistration.registerReadOnlyAttribute(TimerAttributeDefinition.INSTANCE, handler);
    }
    if (componentType.hasPool()) {
        resourceRegistration.registerReadOnlyAttribute(POOL_AVAILABLE_COUNT, handler);
        resourceRegistration.registerReadOnlyAttribute(POOL_CREATE_COUNT, handler);
        resourceRegistration.registerReadOnlyAttribute(POOL_NAME, handler);
        resourceRegistration.registerReadOnlyAttribute(POOL_REMOVE_COUNT, handler);
        resourceRegistration.registerReadOnlyAttribute(POOL_CURRENT_SIZE, handler);
        resourceRegistration.registerReadWriteAttribute(POOL_MAX_SIZE, handler, handler);
    }
    if (componentType.equals(EJBComponentType.STATEFUL)) {
        resourceRegistration.registerMetric(CACHE_SIZE, new AbstractRuntimeMetricsHandler() {

            @Override
            protected void executeReadMetricStep(final OperationContext context, final ModelNode operation, final EJBComponent component) throws OperationFailedException {
                context.getResult().set(((StatefulSessionComponent) component).getCache().getCacheSize());
            }
        });
        resourceRegistration.registerMetric(PASSIVATED_SIZE, new AbstractRuntimeMetricsHandler() {

            @Override
            protected void executeReadMetricStep(final OperationContext context, final ModelNode operation, final EJBComponent component) throws OperationFailedException {
                context.getResult().set(((StatefulSessionComponent) component).getCache().getPassivatedCount());
            }
        });
        resourceRegistration.registerMetric(TOTAL_SIZE, new AbstractRuntimeMetricsHandler() {

            @Override
            protected void executeReadMetricStep(final OperationContext context, final ModelNode operation, final EJBComponent component) throws OperationFailedException {
                context.getResult().set(((StatefulSessionComponent) component).getCache().getTotalSize());
            }
        });
    }
    resourceRegistration.registerMetric(EXECUTION_TIME, new AbstractRuntimeMetricsHandler() {

        @Override
        protected void executeReadMetricStep(final OperationContext context, final ModelNode operation, final EJBComponent component) throws OperationFailedException {
            context.getResult().set(component.getInvocationMetrics().getExecutionTime());
        }
    });
    resourceRegistration.registerMetric(INVOCATIONS, new AbstractRuntimeMetricsHandler() {

        @Override
        protected void executeReadMetricStep(final OperationContext context, final ModelNode operation, final EJBComponent component) throws OperationFailedException {
            context.getResult().set(component.getInvocationMetrics().getInvocations());
        }
    });
    resourceRegistration.registerMetric(PEAK_CONCURRENT_INVOCATIONS, new AbstractRuntimeMetricsHandler() {

        @Override
        protected void executeReadMetricStep(final OperationContext context, final ModelNode operation, final EJBComponent component) throws OperationFailedException {
            context.getResult().set(component.getInvocationMetrics().getPeakConcurrent());
        }
    });
    resourceRegistration.registerMetric(WAIT_TIME, new AbstractRuntimeMetricsHandler() {

        @Override
        protected void executeReadMetricStep(final OperationContext context, final ModelNode operation, final EJBComponent component) throws OperationFailedException {
            context.getResult().set(component.getInvocationMetrics().getWaitTime());
        }
    });
    resourceRegistration.registerMetric(METHODS, new AbstractRuntimeMetricsHandler() {

        @Override
        protected void executeReadMetricStep(final OperationContext context, final ModelNode operation, final EJBComponent component) throws OperationFailedException {
            context.getResult().setEmptyObject();
            for (final Map.Entry<String, InvocationMetrics.Values> entry : component.getInvocationMetrics().getMethods().entrySet()) {
                final InvocationMetrics.Values values = entry.getValue();
                final ModelNode result = new ModelNode();
                result.get("execution-time").set(values.getExecutionTime());
                result.get("invocations").set(values.getInvocations());
                result.get("wait-time").set(values.getWaitTime());
                context.getResult().get(entry.getKey()).set(result);
            }
        }
    });
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) InvocationMetrics(org.jboss.as.ejb3.component.invocationmetrics.InvocationMetrics) OperationFailedException(org.jboss.as.controller.OperationFailedException) ModelNode(org.jboss.dmr.ModelNode) EJBComponent(org.jboss.as.ejb3.component.EJBComponent)

Example 44 with OperationFailedException

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

the class AddStepHandler method recordCapabilitiesAndRequirements.

@Override
protected void recordCapabilitiesAndRequirements(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException {
    PathAddress address = context.getCurrentAddress();
    ModelNode model = resource.getModel();
    // The super implementation assumes that the capability name is a simple extension of the base name - we do not.
    // Only register capabilities when allowed by the associated predicate
    this.descriptor.getCapabilities().entrySet().stream().filter(entry -> entry.getValue().test(model)).map(Map.Entry::getKey).forEach(capability -> context.registerCapability(capability.resolve(address)));
    ImmutableManagementResourceRegistration registration = context.getResourceRegistration();
    registration.getAttributeNames(PathAddress.EMPTY_ADDRESS).stream().map(name -> registration.getAttributeAccess(PathAddress.EMPTY_ADDRESS, name)).filter(Objects::nonNull).map(AttributeAccess::getAttributeDefinition).filter(Objects::nonNull).filter(AttributeDefinition::hasCapabilityRequirements).forEach(attribute -> attribute.addCapabilityRequirements(context, model.get(attribute.getName())));
    this.descriptor.getResourceCapabilityReferences().forEach((reference, resolver) -> reference.addCapabilityRequirements(context, (String) null, resolver.apply(address)));
}
Also used : OperationEntry(org.jboss.as.controller.registry.OperationEntry) OperationStepHandler(org.jboss.as.controller.OperationStepHandler) Resource(org.jboss.as.controller.registry.Resource) PathAddress(org.jboss.as.controller.PathAddress) Collection(java.util.Collection) SimpleAttributeDefinitionBuilder(org.jboss.as.controller.SimpleAttributeDefinitionBuilder) PathElement(org.jboss.as.controller.PathElement) ImmutableManagementResourceRegistration(org.jboss.as.controller.registry.ImmutableManagementResourceRegistration) AttributeAccess(org.jboss.as.controller.registry.AttributeAccess) Objects(java.util.Objects) BiPredicate(java.util.function.BiPredicate) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) OperationContext(org.jboss.as.controller.OperationContext) Stream(java.util.stream.Stream) AbstractAddStepHandler(org.jboss.as.controller.AbstractAddStepHandler) OperationFailedException(org.jboss.as.controller.OperationFailedException) Util(org.jboss.as.controller.operations.common.Util) Map(java.util.Map) Optional(java.util.Optional) ModelNode(org.jboss.dmr.ModelNode) SimpleOperationDefinitionBuilder(org.jboss.as.controller.SimpleOperationDefinitionBuilder) ModelDescriptionConstants(org.jboss.as.controller.descriptions.ModelDescriptionConstants) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) ModelType(org.jboss.dmr.ModelType) PathAddress(org.jboss.as.controller.PathAddress) Objects(java.util.Objects) ImmutableManagementResourceRegistration(org.jboss.as.controller.registry.ImmutableManagementResourceRegistration) ModelNode(org.jboss.dmr.ModelNode) Map(java.util.Map)

Example 45 with OperationFailedException

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

the class RemoveStepHandler method performRemove.

@Override
protected void performRemove(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    Resource resource = context.readResource(PathAddress.EMPTY_ADDRESS);
    // Determine whether super impl will actually remove the resource
    boolean remove = !resource.getChildTypes().stream().anyMatch(type -> resource.getChildren(type).stream().filter(entry -> !entry.isRuntime()).map(entry -> entry.getPathElement()).anyMatch(path -> resource.hasChild(path)));
    if (remove) {
        // We need to remove capabilities *before* removing the resource, since the capability reference resolution might involve reading the resource
        PathAddress address = context.getCurrentAddress();
        this.descriptor.getCapabilities().entrySet().stream().filter(entry -> entry.getValue().test(model)).map(Map.Entry::getKey).forEach(capability -> context.deregisterCapability(capability.resolve(address).getName()));
        ImmutableManagementResourceRegistration registration = context.getResourceRegistration();
        registration.getAttributeNames(PathAddress.EMPTY_ADDRESS).stream().map(name -> registration.getAttributeAccess(PathAddress.EMPTY_ADDRESS, name)).filter(Objects::nonNull).map(AttributeAccess::getAttributeDefinition).filter(Objects::nonNull).filter(AttributeDefinition::hasCapabilityRequirements).forEach(attribute -> attribute.removeCapabilityRequirements(context, model.get(attribute.getName())));
        this.descriptor.getResourceCapabilityReferences().forEach((reference, resolver) -> reference.removeCapabilityRequirements(context, (String) null, resolver.apply(address)));
        // Remove any runtime child resources
        removeRuntimeChildren(context, PathAddress.EMPTY_ADDRESS);
    }
    super.performRemove(context, operation, model);
    if (remove) {
        PathAddress address = context.getResourceRegistration().getPathAddress();
        PathElement path = address.getLastElement();
        // If override model was registered, unregister it
        if (!path.isWildcard() && (context.getResourceRegistration().getParent().getSubModel(PathAddress.pathAddress(path.getKey(), PathElement.WILDCARD_VALUE)) != null)) {
            context.getResourceRegistrationForUpdate().unregisterOverrideModel(context.getCurrentAddressValue());
        }
    }
}
Also used : OperationEntry(org.jboss.as.controller.registry.OperationEntry) Resource(org.jboss.as.controller.registry.Resource) PathAddress(org.jboss.as.controller.PathAddress) PathElement(org.jboss.as.controller.PathElement) ImmutableManagementResourceRegistration(org.jboss.as.controller.registry.ImmutableManagementResourceRegistration) AttributeAccess(org.jboss.as.controller.registry.AttributeAccess) Objects(java.util.Objects) ManagementResourceRegistration(org.jboss.as.controller.registry.ManagementResourceRegistration) OperationContext(org.jboss.as.controller.OperationContext) OperationFailedException(org.jboss.as.controller.OperationFailedException) Map(java.util.Map) AbstractRemoveStepHandler(org.jboss.as.controller.AbstractRemoveStepHandler) ModelNode(org.jboss.dmr.ModelNode) SimpleOperationDefinitionBuilder(org.jboss.as.controller.SimpleOperationDefinitionBuilder) ModelDescriptionConstants(org.jboss.as.controller.descriptions.ModelDescriptionConstants) AttributeDefinition(org.jboss.as.controller.AttributeDefinition) PathElement(org.jboss.as.controller.PathElement) PathAddress(org.jboss.as.controller.PathAddress) Resource(org.jboss.as.controller.registry.Resource) Objects(java.util.Objects) ImmutableManagementResourceRegistration(org.jboss.as.controller.registry.ImmutableManagementResourceRegistration) Map(java.util.Map)

Aggregations

OperationFailedException (org.jboss.as.controller.OperationFailedException)113 ModelNode (org.jboss.dmr.ModelNode)86 PathAddress (org.jboss.as.controller.PathAddress)51 OperationContext (org.jboss.as.controller.OperationContext)49 OperationStepHandler (org.jboss.as.controller.OperationStepHandler)34 ServiceName (org.jboss.msc.service.ServiceName)33 Resource (org.jboss.as.controller.registry.Resource)26 ServiceController (org.jboss.msc.service.ServiceController)19 ServiceTarget (org.jboss.msc.service.ServiceTarget)15 PathElement (org.jboss.as.controller.PathElement)13 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)12 IOException (java.io.IOException)11 Map (java.util.Map)11 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)11 ArrayList (java.util.ArrayList)9 AttributeDefinition (org.jboss.as.controller.AttributeDefinition)9 ContextNames (org.jboss.as.naming.deployment.ContextNames)7 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)7 List (java.util.List)6 ResourceServiceHandler (org.jboss.as.clustering.controller.ResourceServiceHandler)6