Search in sources :

Example 46 with OperationFailedException

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

the class JMSTopicRemove method performRuntime.

protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
    final String name = context.getCurrentAddress().getLastElement().getValue();
    ServiceController<?> service = context.getServiceRegistry(false).getService(serviceName);
    ActiveMQServer server = ActiveMQServer.class.cast(service.getValue());
    JMSServerControl control = JMSServerControl.class.cast(server.getManagementService().getResource(ResourceNames.JMS_SERVER));
    if (control != null) {
        try {
            control.destroyTopic(name, true);
        } catch (Exception e) {
            throw new OperationFailedException(e);
        }
    }
    context.removeService(JMSServices.getJmsTopicBaseServiceName(serviceName).append(name));
    for (String entry : CommonAttributes.DESTINATION_ENTRIES.unwrap(context, model)) {
        final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(entry);
        ServiceName binderServiceName = bindInfo.getBinderServiceName();
        context.removeService(binderServiceName);
    }
    for (String legacyEntry : CommonAttributes.LEGACY_ENTRIES.unwrap(context, model)) {
        final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(legacyEntry);
        ServiceName binderServiceName = bindInfo.getBinderServiceName();
        context.removeService(binderServiceName);
    }
}
Also used : JMSServerControl(org.apache.activemq.artemis.api.jms.management.JMSServerControl) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ServiceName(org.jboss.msc.service.ServiceName) OperationFailedException(org.jboss.as.controller.OperationFailedException) OperationFailedException(org.jboss.as.controller.OperationFailedException) ContextNames(org.jboss.as.naming.deployment.ContextNames)

Example 47 with OperationFailedException

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

the class ServerAdd method processStorageConfiguration.

private static void processStorageConfiguration(OperationContext context, ModelNode model, Configuration configuration) throws OperationFailedException {
    ModelNode journalDataSource = JOURNAL_DATASOURCE.resolveModelAttribute(context, model);
    if (!journalDataSource.isDefined()) {
        return;
    }
    DatabaseStorageConfiguration storageConfiguration = new DatabaseStorageConfiguration();
    storageConfiguration.setBindingsTableName(JOURNAL_BINDINGS_TABLE.resolveModelAttribute(context, model).asString());
    storageConfiguration.setMessageTableName(JOURNAL_MESSAGES_TABLE.resolveModelAttribute(context, model).asString());
    storageConfiguration.setLargeMessageTableName(JOURNAL_LARGE_MESSAGES_TABLE.resolveModelAttribute(context, model).asString());
    storageConfiguration.setPageStoreTableName(JOURNAL_PAGE_STORE_TABLE.resolveModelAttribute(context, model).asString());
    ModelNode databaseNode = JOURNAL_DATABASE.resolveModelAttribute(context, model);
    final String database = databaseNode.isDefined() ? databaseNode.asString() : null;
    try {
        storageConfiguration.setSqlProvider(new PropertySQLProviderFactory(database));
    } catch (IOException e) {
        throw new OperationFailedException(e);
    }
    configuration.setStoreConfiguration(storageConfiguration);
}
Also used : DatabaseStorageConfiguration(org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration) OperationFailedException(org.jboss.as.controller.OperationFailedException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) IOException(java.io.IOException) ModelNode(org.jboss.dmr.ModelNode)

Example 48 with OperationFailedException

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

the class JMSQueueReadAttributeHandler 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();
    JMSQueueControl control = getControl(context, operation);
    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.SCHEDULED_COUNT.getName().equals(attributeName)) {
        context.getResult().set(control.getScheduledCount());
    } else if (CommonAttributes.CONSUMER_COUNT.getName().equals(attributeName)) {
        context.getResult().set(control.getConsumerCount());
    } 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 (JMSQueueDefinition.QUEUE_ADDRESS.getName().equals(attributeName)) {
        context.getResult().set(control.getAddress());
    } else if (JMSQueueDefinition.EXPIRY_ADDRESS.getName().equals(attributeName)) {
        // create the result node in all cases
        ModelNode result = context.getResult();
        String expiryAddress = control.getExpiryAddress();
        if (expiryAddress != null) {
            result.set(expiryAddress);
        }
    } else if (JMSQueueDefinition.DEAD_LETTER_ADDRESS.getName().equals(attributeName)) {
        // create the result node in all cases
        ModelNode result = context.getResult();
        String dla = control.getDeadLetterAddress();
        if (dla != null) {
            result.set(dla);
        }
    } else if (CommonAttributes.PAUSED.getName().equals(attributeName)) {
        try {
            context.getResult().set(control.isPaused());
        } catch (RuntimeException e) {
            throw e;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    } else if (CommonAttributes.TEMPORARY.getName().equals(attributeName)) {
        context.getResult().set(control.isTemporary());
    } else {
        throw MessagingLogger.ROOT_LOGGER.unsupportedAttribute(attributeName);
    }
}
Also used : JMSQueueControl(org.apache.activemq.artemis.api.jms.management.JMSQueueControl) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Example 49 with OperationFailedException

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

the class JMSQueueRemove method performRuntime.

protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
    final PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
    final String name = address.getLastElement().getValue();
    ServiceController<?> service = context.getServiceRegistry(false).getService(serviceName);
    ActiveMQServer server = ActiveMQServer.class.cast(service.getValue());
    JMSServerControl control = JMSServerControl.class.cast(server.getManagementService().getResource(ResourceNames.JMS_SERVER));
    if (control != null) {
        try {
            control.destroyQueue(name, true);
        } catch (Exception e) {
            throw new OperationFailedException(e);
        }
    }
    context.removeService(JMSServices.getJmsQueueBaseServiceName(serviceName).append(name));
    for (String entry : CommonAttributes.DESTINATION_ENTRIES.unwrap(context, model)) {
        final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(entry);
        ServiceName binderServiceName = bindInfo.getBinderServiceName();
        context.removeService(binderServiceName);
    }
    for (String legacyEntry : CommonAttributes.LEGACY_ENTRIES.unwrap(context, model)) {
        final ContextNames.BindInfo bindInfo = ContextNames.bindInfoFor(legacyEntry);
        ServiceName binderServiceName = bindInfo.getBinderServiceName();
        context.removeService(binderServiceName);
    }
}
Also used : JMSServerControl(org.apache.activemq.artemis.api.jms.management.JMSServerControl) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress) OperationFailedException(org.jboss.as.controller.OperationFailedException) OperationFailedException(org.jboss.as.controller.OperationFailedException) ContextNames(org.jboss.as.naming.deployment.ContextNames)

Example 50 with OperationFailedException

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

the class SecurityRoleReadAttributeHandler method executeRuntimeStep.

@Override
public void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
    final String attributeName = operation.require(ModelDescriptionConstants.NAME).asString();
    PathAddress pathAddress = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR));
    String addressName = pathAddress.getElement(pathAddress.size() - 2).getValue();
    String roleName = pathAddress.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());
    AddressControl control = AddressControl.class.cast(server.getManagementService().getResource(ResourceNames.CORE_ADDRESS + addressName));
    if (control == null) {
        PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
        throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(address);
    }
    try {
        String rolesAsJSON = control.getRolesAsJSON();
        ModelNode res = ModelNode.fromJSONString(rolesAsJSON);
        ModelNode roles = ManagementUtil.convertSecurityRole(res);
        ModelNode matchedRole = findRole(roleName, roles);
        if (matchedRole == null || !matchedRole.hasDefined(attributeName)) {
            throw MessagingLogger.ROOT_LOGGER.unsupportedAttribute(attributeName);
        }
        boolean value = matchedRole.get(attributeName).asBoolean();
        context.getResult().set(value);
    } catch (Exception e) {
        context.getFailureDescription().set(e.getLocalizedMessage());
    }
}
Also used : AddressControl(org.apache.activemq.artemis.api.core.management.AddressControl) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ServiceName(org.jboss.msc.service.ServiceName) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode) OperationFailedException(org.jboss.as.controller.OperationFailedException)

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