Search in sources :

Example 31 with OperationFailedException

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

the class ActiveMQServerControlHandler method executeRuntimeStep.

@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
    final String operationName = operation.require(OP).asString();
    final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
    if (READ_ATTRIBUTE_OPERATION.equals(operationName)) {
        ActiveMQServer server = null;
        if (context.getRunningMode() == RunningMode.NORMAL) {
            ServiceController<?> service = context.getServiceRegistry(false).getService(serviceName);
            if (service == null || service.getState() != ServiceController.State.UP) {
                throw MessagingLogger.ROOT_LOGGER.activeMQServerNotInstalled(serviceName.getSimpleName());
            }
            server = ActiveMQServer.class.cast(service.getValue());
        }
        handleReadAttribute(context, operation, server);
        return;
    }
    if (rollbackOperationIfServerNotActive(context, operation)) {
        return;
    }
    final ActiveMQServerControl serverControl = getServerControl(context, operation);
    try {
        if (GET_CONNECTORS_AS_JSON.equals(operationName)) {
            String json = serverControl.getConnectorsAsJSON();
            context.getResult().set(json);
        } else if (RESET_ALL_MESSAGE_COUNTERS.equals(operationName)) {
            serverControl.resetAllMessageCounters();
            context.getResult();
        } else if (RESET_ALL_MESSAGE_COUNTER_HISTORIES.equals(operationName)) {
            serverControl.resetAllMessageCounterHistories();
            context.getResult();
        } else if (LIST_PREPARED_TRANSACTIONS.equals(operationName)) {
            String[] list = serverControl.listPreparedTransactions();
            reportListOfStrings(context, list);
        } else if (LIST_PREPARED_TRANSACTION_DETAILS_AS_JSON.equals(operationName)) {
            String json = serverControl.listPreparedTransactionDetailsAsJSON();
            context.getResult().set(json);
        } else if (LIST_PREPARED_TRANSACTION_DETAILS_AS_HTML.equals(operationName)) {
            String html = serverControl.listPreparedTransactionDetailsAsHTML();
            context.getResult().set(html);
        } else if (LIST_HEURISTIC_COMMITTED_TRANSACTIONS.equals(operationName)) {
            String[] list = serverControl.listHeuristicCommittedTransactions();
            reportListOfStrings(context, list);
        } else if (LIST_HEURISTIC_ROLLED_BACK_TRANSACTIONS.equals(operationName)) {
            String[] list = serverControl.listHeuristicRolledBackTransactions();
            reportListOfStrings(context, list);
        } else if (COMMIT_PREPARED_TRANSACTION.equals(operationName)) {
            String txId = TRANSACTION_AS_BASE_64.resolveModelAttribute(context, operation).asString();
            boolean committed = serverControl.commitPreparedTransaction(txId);
            context.getResult().set(committed);
        } else if (ROLLBACK_PREPARED_TRANSACTION.equals(operationName)) {
            String txId = TRANSACTION_AS_BASE_64.resolveModelAttribute(context, operation).asString();
            boolean committed = serverControl.rollbackPreparedTransaction(txId);
            context.getResult().set(committed);
        } else if (LIST_REMOTE_ADDRESSES.equals(operationName)) {
            ModelNode address = OPTIONAL_IP_ADDRESS.resolveModelAttribute(context, operation);
            String[] list = address.isDefined() ? serverControl.listRemoteAddresses(address.asString()) : serverControl.listRemoteAddresses();
            reportListOfStrings(context, list);
        } else if (CLOSE_CONNECTIONS_FOR_ADDRESS.equals(operationName)) {
            String address = REQUIRED_IP_ADDRESS.resolveModelAttribute(context, operation).asString();
            boolean closed = serverControl.closeConnectionsForAddress(address);
            context.getResult().set(closed);
        } else if (CLOSE_CONNECTIONS_FOR_USER.equals(operationName)) {
            String user = USER.resolveModelAttribute(context, operation).asString();
            boolean closed = serverControl.closeConnectionsForUser(user);
            context.getResult().set(closed);
        } else if (CLOSE_CONSUMER_CONNECTIONS_FOR_ADDRESS.equals(operationName)) {
            String address = ADDRESS_MATCH.resolveModelAttribute(context, operation).asString();
            boolean closed = serverControl.closeConsumerConnectionsForAddress(address);
            context.getResult().set(closed);
        } else if (LIST_CONNECTION_IDS.equals(operationName)) {
            String[] list = serverControl.listConnectionIDs();
            reportListOfStrings(context, list);
        } else if (LIST_PRODUCERS_INFO_AS_JSON.equals(operationName)) {
            String json = serverControl.listProducersInfoAsJSON();
            context.getResult().set(json);
        } else if (LIST_SESSIONS.equals(operationName)) {
            String connectionID = CONNECTION_ID.resolveModelAttribute(context, operation).asString();
            String[] list = serverControl.listSessions(connectionID);
            reportListOfStrings(context, list);
        } else if (GET_ROLES.equals(operationName)) {
            String addressMatch = ADDRESS_MATCH.resolveModelAttribute(context, operation).asString();
            String json = serverControl.getRolesAsJSON(addressMatch);
            reportRoles(context, json);
        } else if (GET_ROLES_AS_JSON.equals(operationName)) {
            String addressMatch = ADDRESS_MATCH.resolveModelAttribute(context, operation).asString();
            String json = serverControl.getRolesAsJSON(addressMatch);
            reportRolesAsJSON(context, json);
        } else if (GET_ADDRESS_SETTINGS_AS_JSON.equals(operationName)) {
            String addressMatch = ADDRESS_MATCH.resolveModelAttribute(context, operation).asString();
            String json = serverControl.getAddressSettingsAsJSON(addressMatch);
            context.getResult().set(json);
        } else if (FORCE_FAILOVER.equals(operationName)) {
            serverControl.forceFailover();
            context.getResult();
        } else {
            // Bug
            throw MessagingLogger.ROOT_LOGGER.unsupportedOperation(operationName);
        }
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        context.getFailureDescription().set(e.getLocalizedMessage());
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ActiveMQServerControl(org.apache.activemq.artemis.api.core.management.ActiveMQServerControl) ServiceName(org.jboss.msc.service.ServiceName) ModelNode(org.jboss.dmr.ModelNode) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Example 32 with OperationFailedException

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

the class BroadcastGroupAdd method populateModel.

@Override
protected void populateModel(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException {
    super.populateModel(context, operation, resource);
    final ModelNode connectorRefs = resource.getModel().get(CONNECTOR_REFS.getName());
    if (connectorRefs.isDefined()) {
        context.addStep(new OperationStepHandler() {

            @Override
            public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
                validateConnectors(context, operation, connectorRefs);
            }
        }, 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 33 with OperationFailedException

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

the class ClusterConnectionControlHandler method handleOperation.

@Override
protected Object handleOperation(String operationName, OperationContext context, ModelNode operation) throws OperationFailedException {
    if (ClusterConnectionDefinition.GET_NODES.equals(operationName)) {
        ClusterConnectionControl control = getActiveMQComponentControl(context, operation, false);
        try {
            Map<String, String> nodes = control.getNodes();
            final ModelNode result = context.getResult();
            result.setEmptyObject();
            for (Map.Entry<String, String> entry : nodes.entrySet()) {
                result.get(entry.getKey()).set(entry.getValue());
            }
        } catch (Exception e) {
            context.getFailureDescription().set(e.getLocalizedMessage());
        }
    } else {
        unsupportedOperation(operationName);
    }
    return null;
}
Also used : ModelNode(org.jboss.dmr.ModelNode) ClusterConnectionControl(org.apache.activemq.artemis.api.core.management.ClusterConnectionControl) Map(java.util.Map) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Example 34 with OperationFailedException

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

the class DivertRemove method performRuntime.

@Override
protected void performRuntime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
    final String name = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue();
    final ServiceRegistry registry = context.getServiceRegistry(true);
    final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
    final ServiceController<?> service = registry.getService(serviceName);
    if (service != null && service.getState() == ServiceController.State.UP) {
        ActiveMQServer server = ActiveMQServer.class.cast(service.getValue());
        try {
            server.getActiveMQServerControl().destroyDivert(name);
        } catch (RuntimeException e) {
            throw e;
        } catch (Exception e) {
            // TODO should this be an OFE instead?
            throw new RuntimeException(e);
        }
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ServiceName(org.jboss.msc.service.ServiceName) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Example 35 with OperationFailedException

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

the class ExportJournalOperation method executeRuntimeStep.

@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
    if (context.getRunningMode() != ADMIN_ONLY) {
        throw MessagingLogger.ROOT_LOGGER.managementOperationAllowedOnlyInRunningMode("export-journal", ADMIN_ONLY);
    }
    final ServiceController<PathManager> service = (ServiceController<PathManager>) context.getServiceRegistry(false).getService(PathManagerService.SERVICE_NAME);
    final PathManager pathManager = service.getService().getValue();
    final String journal = resolvePath(context, pathManager, JOURNAL_DIRECTORY_PATH);
    final String bindings = resolvePath(context, pathManager, BINDINGS_DIRECTORY_PATH);
    final String paging = resolvePath(context, pathManager, PAGING_DIRECTORY_PATH);
    final String largeMessages = resolvePath(context, pathManager, LARGE_MESSAGES_DIRECTORY_PATH);
    final XmlDataExporter exporter = new XmlDataExporter();
    String name = String.format(FILE_NAME_FORMAT, new Date());
    // write the exported dump at the same level than the journal directory
    File dump = new File(new File(journal).getParent(), name);
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(dump);
        exporter.process(fos, bindings, journal, paging, largeMessages);
        context.getResult().set(dump.getAbsolutePath());
    } catch (Exception e) {
        throw new OperationFailedException(e);
    } finally {
        if (fos != null) {
            try {
                fos.close();
            } catch (IOException e) {
            }
        }
    }
}
Also used : PathManager(org.jboss.as.controller.services.path.PathManager) FileOutputStream(java.io.FileOutputStream) OperationFailedException(org.jboss.as.controller.OperationFailedException) ServiceController(org.jboss.msc.service.ServiceController) IOException(java.io.IOException) File(java.io.File) XmlDataExporter(org.apache.activemq.artemis.cli.commands.tools.XmlDataExporter) Date(java.util.Date) IOException(java.io.IOException) 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