Search in sources :

Example 26 with OperationFailedException

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

the class StoreBuilder method configure.

@Override
public Builder<PersistenceConfiguration> configure(OperationContext context, ModelNode model) throws OperationFailedException {
    this.storeBuilder = this.storeBuilderFactory.apply(context, model);
    this.storeBuilder.persistence().passivation(PASSIVATION.resolveModelAttribute(context, model).asBoolean());
    Properties properties = new Properties();
    ModelNodes.optionalPropertyList(PROPERTIES.resolveModelAttribute(context, model)).ifPresent(list -> list.forEach(property -> properties.setProperty(property.getName(), property.getValue().asString())));
    this.storeBuilder.fetchPersistentState(FETCH_STATE.resolveModelAttribute(context, model).asBoolean()).preload(PRELOAD.resolveModelAttribute(context, model).asBoolean()).purgeOnStartup(PURGE.resolveModelAttribute(context, model).asBoolean()).shared(SHARED.resolveModelAttribute(context, model).asBoolean()).singleton().enabled(SINGLETON.resolveModelAttribute(context, model).asBoolean()).withProperties(properties);
    return this;
}
Also used : PROPERTIES(org.jboss.as.clustering.infinispan.subsystem.StoreResourceDefinition.Attribute.PROPERTIES) ExceptionBiFunction(org.wildfly.common.function.ExceptionBiFunction) Properties(java.util.Properties) SINGLETON(org.jboss.as.clustering.infinispan.subsystem.StoreResourceDefinition.Attribute.SINGLETON) PathAddress(org.jboss.as.controller.PathAddress) PersistenceConfiguration(org.infinispan.configuration.cache.PersistenceConfiguration) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) PURGE(org.jboss.as.clustering.infinispan.subsystem.StoreResourceDefinition.Attribute.PURGE) PRELOAD(org.jboss.as.clustering.infinispan.subsystem.StoreResourceDefinition.Attribute.PRELOAD) ResourceServiceBuilder(org.jboss.as.clustering.controller.ResourceServiceBuilder) PASSIVATION(org.jboss.as.clustering.infinispan.subsystem.StoreResourceDefinition.Attribute.PASSIVATION) Consumer(java.util.function.Consumer) AbstractStoreConfigurationBuilder(org.infinispan.configuration.cache.AbstractStoreConfigurationBuilder) ModelNodes(org.jboss.as.clustering.dmr.ModelNodes) StoreConfiguration(org.infinispan.configuration.cache.StoreConfiguration) OperationContext(org.jboss.as.controller.OperationContext) OperationFailedException(org.jboss.as.controller.OperationFailedException) FETCH_STATE(org.jboss.as.clustering.infinispan.subsystem.StoreResourceDefinition.Attribute.FETCH_STATE) ModelNode(org.jboss.dmr.ModelNode) ServiceTarget(org.jboss.msc.service.ServiceTarget) SHARED(org.jboss.as.clustering.infinispan.subsystem.StoreResourceDefinition.Attribute.SHARED) AsyncStoreConfiguration(org.infinispan.configuration.cache.AsyncStoreConfiguration) Builder(org.wildfly.clustering.service.Builder) InjectedValue(org.jboss.msc.value.InjectedValue) Properties(java.util.Properties)

Example 27 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 28 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 29 with OperationFailedException

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

the class ConfigurationResource method registerOperations.

@Override
public void registerOperations(ManagementResourceRegistration resourceRegistration) {
    super.registerOperations(resourceRegistration);
    resourceRegistration.registerOperationHandler(UPDATE_DEFINITION, new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            context.completeStep(OperationContext.ResultHandler.NOOP_RESULT_HANDLER);
        }
    });
}
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 30 with OperationFailedException

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

the class AbstractQueueControlHandler method executeRuntimeStep.

@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
    if (rollbackOperationIfServerNotActive(context, operation)) {
        return;
    }
    final String operationName = operation.require(ModelDescriptionConstants.OP).asString();
    final String queueName = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue();
    final ServiceName activeMQServiceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
    ServiceController<?> activeMQService = context.getServiceRegistry(false).getService(activeMQServiceName);
    ActiveMQServer server = ActiveMQServer.class.cast(activeMQService.getValue());
    final DelegatingQueueControl<T> control = getQueueControl(server, queueName);
    if (control == null) {
        PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
        throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(address);
    }
    boolean reversible = false;
    Object handback = null;
    try {
        if (LIST_MESSAGES.equals(operationName)) {
            String filter = resolveFilter(context, operation);
            String json = control.listMessagesAsJSON(filter);
            context.getResult().set(ModelNode.fromJSONString(json));
        } else if (LIST_MESSAGES_AS_JSON.equals(operationName)) {
            String filter = resolveFilter(context, operation);
            context.getResult().set(control.listMessagesAsJSON(filter));
        } else if (LIST_DELIVERING_MESSAGES.equals(operationName)) {
            String json = control.listDeliveringMessagesAsJSON();
            context.getResult().set(ModelNode.fromJSONString(json));
        } else if (LIST_DELIVERING_MESSAGES_AS_JSON.equals(operationName)) {
            context.getResult().set(control.listDeliveringMessagesAsJSON());
        } else if (LIST_SCHEDULED_MESSAGES.equals(operationName)) {
            String json = control.listScheduledMessagesAsJSON();
            context.getResult().set(ModelNode.fromJSONString(json));
        } else if (LIST_SCHEDULED_MESSAGES_AS_JSON.equals(operationName)) {
            context.getResult().set(control.listScheduledMessagesAsJSON());
        } else if (COUNT_MESSAGES.equals(operationName)) {
            String filter = resolveFilter(context, operation);
            context.getResult().set(control.countMessages(filter));
        } else if (REMOVE_MESSAGE.equals(operationName)) {
            ModelNode id = getMessageIDAttributeDefinition().resolveModelAttribute(context, operation);
            context.getResult().set(control.removeMessage(id));
        } else if (REMOVE_MESSAGES.equals(operationName)) {
            String filter = resolveFilter(context, operation);
            context.getResult().set(control.removeMessages(filter));
        } else if (EXPIRE_MESSAGES.equals(operationName)) {
            String filter = resolveFilter(context, operation);
            context.getResult().set(control.expireMessages(filter));
        } else if (EXPIRE_MESSAGE.equals(operationName)) {
            ModelNode id = getMessageIDAttributeDefinition().resolveModelAttribute(context, operation);
            context.getResult().set(control.expireMessage(id));
        } else if (SEND_MESSAGE_TO_DEAD_LETTER_ADDRESS.equals(operationName)) {
            ModelNode id = getMessageIDAttributeDefinition().resolveModelAttribute(context, operation);
            context.getResult().set(control.sendMessageToDeadLetterAddress(id));
        } else if (SEND_MESSAGES_TO_DEAD_LETTER_ADDRESS.equals(operationName)) {
            String filter = resolveFilter(context, operation);
            context.getResult().set(control.sendMessagesToDeadLetterAddress(filter));
        } else if (CHANGE_MESSAGE_PRIORITY.equals(operationName)) {
            ModelNode id = getMessageIDAttributeDefinition().resolveModelAttribute(context, operation);
            int priority = NEW_PRIORITY.resolveModelAttribute(context, operation).asInt();
            context.getResult().set(control.changeMessagePriority(id, priority));
        } else if (CHANGE_MESSAGES_PRIORITY.equals(operationName)) {
            String filter = resolveFilter(context, operation);
            int priority = NEW_PRIORITY.resolveModelAttribute(context, operation).asInt();
            context.getResult().set(control.changeMessagesPriority(filter, priority));
        } else if (MOVE_MESSAGE.equals(operationName)) {
            ModelNode id = getMessageIDAttributeDefinition().resolveModelAttribute(context, operation);
            String otherQueue = OTHER_QUEUE_NAME.resolveModelAttribute(context, operation).asString();
            ModelNode rejectDuplicates = REJECT_DUPLICATES.resolveModelAttribute(context, operation);
            if (rejectDuplicates.isDefined()) {
                context.getResult().set(control.moveMessage(id, otherQueue, rejectDuplicates.asBoolean()));
            } else {
                context.getResult().set(control.moveMessage(id, otherQueue));
            }
        } else if (MOVE_MESSAGES.equals(operationName)) {
            String filter = resolveFilter(context, operation);
            String otherQueue = OTHER_QUEUE_NAME.resolveModelAttribute(context, operation).asString();
            ModelNode rejectDuplicates = REJECT_DUPLICATES.resolveModelAttribute(context, operation);
            if (rejectDuplicates.isDefined()) {
                context.getResult().set(control.moveMessages(filter, otherQueue, rejectDuplicates.asBoolean()));
            } else {
                context.getResult().set(control.moveMessages(filter, otherQueue));
            }
        } else if (LIST_MESSAGE_COUNTER_AS_JSON.equals(operationName)) {
            context.getResult().set(control.listMessageCounter());
        } else if (LIST_MESSAGE_COUNTER_AS_HTML.equals(operationName)) {
            context.getResult().set(control.listMessageCounterAsHTML());
        } else if (LIST_MESSAGE_COUNTER_HISTORY_AS_JSON.equals(operationName)) {
            context.getResult().set(control.listMessageCounterHistory());
        } else if (LIST_MESSAGE_COUNTER_HISTORY_AS_HTML.equals(operationName)) {
            context.getResult().set(control.listMessageCounterHistoryAsHTML());
        } else if (RESET_MESSAGE_COUNTER.equals(operationName)) {
            control.resetMessageCounter();
            // undefined
            context.getResult();
        } else if (PAUSE.equals(operationName)) {
            control.pause();
            reversible = true;
            // undefined
            context.getResult();
        } else if (RESUME.equals(operationName)) {
            control.resume();
            reversible = true;
            // undefined
            context.getResult();
        } else if (LIST_CONSUMERS_AS_JSON.equals(operationName)) {
            context.getResult().set(control.listConsumersAsJSON());
        } else {
            // TODO dmr-based LIST_MESSAGE_COUNTER, LIST_MESSAGE_COUNTER_HISTORY, LIST_CONSUMERS
            handback = handleAdditionalOperation(operationName, operation, context, control.getDelegate());
            reversible = handback == null;
        }
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        context.getFailureDescription().set(e.getLocalizedMessage());
    }
    OperationContext.RollbackHandler rh;
    if (reversible) {
        final Object rhHandback = handback;
        rh = new OperationContext.RollbackHandler() {

            @Override
            public void handleRollback(OperationContext context, ModelNode operation) {
                try {
                    if (PAUSE.equals(operationName)) {
                        control.resume();
                    } else if (RESUME.equals(operationName)) {
                        control.pause();
                    } else {
                        revertAdditionalOperation(operationName, operation, context, control.getDelegate(), rhHandback);
                    }
                } catch (Exception e) {
                    ROOT_LOGGER.revertOperationFailed(e, getClass().getSimpleName(), operation.require(ModelDescriptionConstants.OP).asString(), PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)));
                }
            }
        };
    } else {
        rh = OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER;
    }
    context.completeStep(rh);
}
Also used : OperationContext(org.jboss.as.controller.OperationContext) OperationFailedException(org.jboss.as.controller.OperationFailedException) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) LIST(org.jboss.dmr.ModelType.LIST) INT(org.jboss.dmr.ModelType.INT) ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode)

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