Search in sources :

Example 61 with OperationFailedException

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

the class JMSTopicControlHandler method executeRuntimeStep.

@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
    if (rollbackOperationIfServerNotActive(context, operation)) {
        return;
    }
    final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
    final String operationName = operation.require(ModelDescriptionConstants.OP).asString();
    final String topicName = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue();
    ServiceController<?> service = context.getServiceRegistry(false).getService(serviceName);
    ActiveMQServer server = ActiveMQServer.class.cast(service.getValue());
    TopicControl control = TopicControl.class.cast(server.getManagementService().getResource(ResourceNames.JMS_TOPIC + topicName));
    if (control == null) {
        PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
        throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(address);
    }
    try {
        if (LIST_ALL_SUBSCRIPTIONS.equals(operationName)) {
            String json = control.listAllSubscriptionsAsJSON();
            ModelNode jsonAsNode = ModelNode.fromJSONString(json);
            context.getResult().set(jsonAsNode);
        } else if (LIST_ALL_SUBSCRIPTIONS_AS_JSON.equals(operationName)) {
            context.getResult().set(control.listAllSubscriptionsAsJSON());
        } else if (LIST_DURABLE_SUBSCRIPTIONS.equals(operationName)) {
            String json = control.listDurableSubscriptionsAsJSON();
            ModelNode jsonAsNode = ModelNode.fromJSONString(json);
            context.getResult().set(jsonAsNode);
        } else if (LIST_DURABLE_SUBSCRIPTIONS_AS_JSON.equals(operationName)) {
            context.getResult().set(control.listDurableSubscriptionsAsJSON());
        } else if (LIST_NON_DURABLE_SUBSCRIPTIONS.equals(operationName)) {
            String json = control.listNonDurableSubscriptionsAsJSON();
            ModelNode jsonAsNode = ModelNode.fromJSONString(json);
            context.getResult().set(jsonAsNode);
        } else if (LIST_NON_DURABLE_SUBSCRIPTIONS_AS_JSON.equals(operationName)) {
            context.getResult().set(control.listNonDurableSubscriptionsAsJSON());
        } else if (LIST_MESSAGES_FOR_SUBSCRIPTION.equals(operationName)) {
            final String queueName = QUEUE_NAME.resolveModelAttribute(context, operation).asString();
            String json = control.listMessagesForSubscriptionAsJSON(queueName);
            context.getResult().set(ModelNode.fromJSONString(json));
        } else if (LIST_MESSAGES_FOR_SUBSCRIPTION_AS_JSON.equals(operationName)) {
            final String queueName = QUEUE_NAME.resolveModelAttribute(context, operation).asString();
            context.getResult().set(control.listMessagesForSubscriptionAsJSON(queueName));
        } else if (COUNT_MESSAGES_FOR_SUBSCRIPTION.equals(operationName)) {
            String clientId = CLIENT_ID.resolveModelAttribute(context, operation).asString();
            String subscriptionName = SUBSCRIPTION_NAME.resolveModelAttribute(context, operation).asString();
            String filter = resolveFilter(context, operation);
            context.getResult().set(control.countMessagesForSubscription(clientId, subscriptionName, filter));
        } else if (DROP_DURABLE_SUBSCRIPTION.equals(operationName)) {
            String clientId = CLIENT_ID.resolveModelAttribute(context, operation).asString();
            String subscriptionName = SUBSCRIPTION_NAME.resolveModelAttribute(context, operation).asString();
            control.dropDurableSubscription(clientId, subscriptionName);
            context.getResult();
        } else if (DROP_ALL_SUBSCRIPTIONS.equals(operationName)) {
            control.dropAllSubscriptions();
            context.getResult();
        } else if (REMOVE_MESSAGES.equals(operationName)) {
            String filter = resolveFilter(context, operation);
            context.getResult().set(control.removeMessages(filter));
        } else {
            // Bug
            throw MessagingLogger.ROOT_LOGGER.unsupportedOperation(operationName);
        }
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        context.getFailureDescription().set(e.toString());
    }
    context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ServiceName(org.jboss.msc.service.ServiceName) TopicControl(org.apache.activemq.artemis.api.jms.management.TopicControl) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Example 62 with OperationFailedException

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

the class JMSTopicReadAttributeHandler method executeRuntimeStep.

@Override
public void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
    if (ignoreOperationIfServerNotActive(context, operation)) {
        return;
    }
    validator.validate(operation);
    final String attributeName = operation.require(ModelDescriptionConstants.NAME).asString();
    String topicName = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue();
    final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
    ServiceController<?> service = context.getServiceRegistry(false).getService(serviceName);
    ActiveMQServer server = ActiveMQServer.class.cast(service.getValue());
    TopicControl control = TopicControl.class.cast(server.getManagementService().getResource(ResourceNames.JMS_TOPIC + topicName));
    if (control == null) {
        PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
        throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(address);
    }
    if (CommonAttributes.MESSAGE_COUNT.getName().equals(attributeName)) {
        try {
            context.getResult().set(control.getMessageCount());
        } catch (RuntimeException e) {
            throw e;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    } else if (CommonAttributes.DELIVERING_COUNT.getName().equals(attributeName)) {
        context.getResult().set(control.getDeliveringCount());
    } else if (CommonAttributes.MESSAGES_ADDED.getName().equals(attributeName)) {
        context.getResult().set(control.getMessagesAdded());
    } else if (DURABLE_MESSAGE_COUNT.getName().equals(attributeName)) {
        context.getResult().set(control.getDurableMessageCount());
    } else if (NON_DURABLE_MESSAGE_COUNT.getName().equals(attributeName)) {
        context.getResult().set(control.getNonDurableMessageCount());
    } else if (SUBSCRIPTION_COUNT.getName().equals(attributeName)) {
        context.getResult().set(control.getSubscriptionCount());
    } else if (DURABLE_SUBSCRIPTION_COUNT.getName().equals(attributeName)) {
        context.getResult().set(control.getDurableSubscriptionCount());
    } else if (NON_DURABLE_SUBSCRIPTION_COUNT.getName().equals(attributeName)) {
        context.getResult().set(control.getNonDurableSubscriptionCount());
    } else if (TOPIC_ADDRESS.getName().equals(attributeName)) {
        context.getResult().set(control.getAddress());
    } else if (CommonAttributes.TEMPORARY.getName().equals(attributeName)) {
        context.getResult().set(control.isTemporary());
    } else {
        throw MessagingLogger.ROOT_LOGGER.unsupportedAttribute(attributeName);
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ServiceName(org.jboss.msc.service.ServiceName) TopicControl(org.apache.activemq.artemis.api.jms.management.TopicControl) PathAddress(org.jboss.as.controller.PathAddress) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Example 63 with OperationFailedException

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

the class ModClusterSubsystemAdd method addLoadMetrics.

private void addLoadMetrics(Set<LoadMetric> metrics, ModelNode nodes, final OperationContext context) throws OperationFailedException {
    for (Property p : nodes.asPropertyList()) {
        ModelNode node = p.getValue();
        double capacity = CAPACITY.resolveModelAttribute(context, node).asDouble();
        int weight = WEIGHT.resolveModelAttribute(context, node).asInt();
        Map<String, String> propertyMap = PROPERTY.unwrap(context, node);
        Class<? extends LoadMetric> loadMetricClass = null;
        if (node.hasDefined(CommonAttributes.TYPE)) {
            String type = TYPE.resolveModelAttribute(context, node).asString();
            // MODCLUSTER-288 Metric "mem" has been dropped, keep it in the model for versions prior to 8.0
            if (type.equals("mem")) {
                ROOT_LOGGER.unsupportedMetric(type);
                continue;
            }
            LoadMetricEnum metric = LoadMetricEnum.forType(type);
            loadMetricClass = (metric != null) ? metric.getLoadMetricClass() : null;
        } else {
            String className = CustomLoadMetricDefinition.CLASS.resolveModelAttribute(context, node).asString();
            try {
                loadMetricClass = this.getClass().getClassLoader().loadClass(className).asSubclass(LoadMetric.class);
            } catch (ClassNotFoundException e) {
                ROOT_LOGGER.errorAddingMetrics(e);
            }
        }
        if (loadMetricClass != null) {
            try {
                LoadMetric metric = loadMetricClass.newInstance();
                metric.setCapacity(capacity);
                metric.setWeight(weight);
                // Apply Java Bean properties if any are set
                if (propertyMap != null && !propertyMap.isEmpty()) {
                    Properties props = new Properties();
                    props.putAll(propertyMap);
                    try {
                        BeanUtils.mapJavaBeanProperties(metric, props, true);
                    } catch (Exception ex) {
                        ROOT_LOGGER.errorApplyingMetricProperties(ex, loadMetricClass.getCanonicalName());
                        // Do not add this incomplete metric.
                        continue;
                    }
                }
                metrics.add(metric);
            } catch (InstantiationException | IllegalAccessException e) {
                ROOT_LOGGER.errorAddingMetrics(e);
            }
        }
    }
}
Also used : Properties(java.util.Properties) OperationFailedException(org.jboss.as.controller.OperationFailedException) LoadMetric(org.jboss.modcluster.load.metric.LoadMetric) ModelNode(org.jboss.dmr.ModelNode) Property(org.jboss.dmr.Property)

Example 64 with OperationFailedException

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

the class HAPolicyConfigurationBuilder method addHAPolicyConfiguration.

public static void addHAPolicyConfiguration(OperationContext context, Configuration configuration, ModelNode model) throws OperationFailedException {
    if (!model.hasDefined(HA_POLICY)) {
        return;
    }
    Property prop = model.get(HA_POLICY).asProperty();
    ModelNode haPolicy = prop.getValue();
    final HAPolicyConfiguration haPolicyConfiguration;
    String type = prop.getName();
    switch(type) {
        case LIVE_ONLY:
            {
                haPolicyConfiguration = LiveOnlyDefinition.buildConfiguration(context, haPolicy);
                break;
            }
        case REPLICATION_MASTER:
            {
                haPolicyConfiguration = ReplicationMasterDefinition.buildConfiguration(context, haPolicy);
                break;
            }
        case REPLICATION_SLAVE:
            {
                haPolicyConfiguration = ReplicationSlaveDefinition.buildConfiguration(context, haPolicy);
                break;
            }
        case REPLICATION_COLOCATED:
            {
                haPolicyConfiguration = ReplicationColocatedDefinition.buildConfiguration(context, haPolicy);
                break;
            }
        case SHARED_STORE_MASTER:
            {
                haPolicyConfiguration = SharedStoreMasterDefinition.buildConfiguration(context, haPolicy);
                break;
            }
        case SHARED_STORE_SLAVE:
            {
                haPolicyConfiguration = SharedStoreSlaveDefinition.buildConfiguration(context, haPolicy);
                break;
            }
        case SHARED_STORE_COLOCATED:
            {
                haPolicyConfiguration = SharedStoreColocatedDefinition.buildConfiguration(context, haPolicy);
                break;
            }
        default:
            {
                throw new OperationFailedException("unknown ha policy type");
            }
    }
    configuration.setHAPolicyConfiguration(haPolicyConfiguration);
}
Also used : HAPolicyConfiguration(org.apache.activemq.artemis.core.config.HAPolicyConfiguration) OperationFailedException(org.jboss.as.controller.OperationFailedException) ModelNode(org.jboss.dmr.ModelNode) Property(org.jboss.dmr.Property)

Example 65 with OperationFailedException

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

the class XTSSubsystemDefinition method registerAttributes.

@Override
public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
    resourceRegistration.registerReadWriteAttribute(HOST_NAME, null, new ReloadRequiredWriteAttributeHandler(HOST_NAME));
    resourceRegistration.registerReadWriteAttribute(ENVIRONMENT_URL, null, new ReloadRequiredWriteAttributeHandler(ENVIRONMENT_URL));
    resourceRegistration.registerReadWriteAttribute(DEFAULT_CONTEXT_PROPAGATION, null, new ReloadRequiredWriteAttributeHandler(DEFAULT_CONTEXT_PROPAGATION));
    //this here just for legacy support!
    resourceRegistration.registerReadOnlyAttribute(ENVIRONMENT, new OperationStepHandler() {

        @Override
        public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
            ModelNode url = context.readResource(PathAddress.EMPTY_ADDRESS).getModel().get(ModelDescriptionConstants.URL);
            context.getResult().get(ModelDescriptionConstants.URL).set(url);
            context.stepCompleted();
        }
    });
}
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) ReloadRequiredWriteAttributeHandler(org.jboss.as.controller.ReloadRequiredWriteAttributeHandler)

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