Search in sources :

Example 1 with QueueGraph

use of org.jaffa.qm.apis.data.QueueGraph in project jaffa-framework by jaffa-projects.

the class TransactionAdmin method toggleQueueStatus.

/**
 * NOTE: Each graph is expected to contain type. It may also contain the optional queueMetaData.queueSystemId, which may help optimize the process.
 */
public QueueAdminResponse[] toggleQueueStatus(QueueGraph[] graphs) {
    if (log.isDebugEnabled()) {
        log.debug("Input to toggleQueueStatus: " + Arrays.toString(graphs));
    }
    Collection<QueueAdminResponse> output = null;
    String[] types = TransactionEngine.getInstance().getAccessibleTypeNames();
    Arrays.sort(types);
    for (QueueGraph graph : graphs) {
        if (graph.getQueueMetaData() == null || graph.getQueueMetaData().getQueueSystemId() == null || graph.getQueueMetaData().getQueueSystemId().equals(QUEUE_SYSTEM_ID)) {
            if (types != null && Arrays.binarySearch(types, graph.getType()) >= 0) {
                try {
                    if (!TransactionEngine.getInstance().hasAdminAccess(graph.getType())) {
                        throw new ApplicationExceptions(new ApplicationException("error.Jaffa.Transaction.Transaction.noAdminAccess", new Object[] { graph.getType() }));
                    }
                } catch (Exception e) {
                    QueueAdminResponse response = new QueueAdminResponse();
                    response.setSource(graph);
                    ApplicationExceptions appExps = ExceptionHelper.extractApplicationExceptions(e);
                    if (appExps != null) {
                        if (log.isDebugEnabled()) {
                            log.debug("Error while toggling status of queue " + graph.getType(), appExps);
                        }
                        response.setErrors(ServiceError.generate(appExps));
                    } else {
                        log.error("Internal Error while toggling status of queue " + graph.getType(), e);
                        response.setErrors(ServiceError.generate(e));
                    }
                    if (output == null) {
                        output = new LinkedList<QueueAdminResponse>();
                    }
                    output.add(response);
                }
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("Status of queue " + graph.getType() + " will not be toggled by this implementation, since the queue does not belong to this system");
                }
            }
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Status of queue " + graph.getType() + " will not be toggled by this implementation, since the input queueSystemId does not match this system");
            }
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("Output from toggleQueueStatus: " + output);
    }
    return output != null && output.size() > 0 ? output.toArray(new QueueAdminResponse[output.size()]) : null;
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) ApplicationException(org.jaffa.exceptions.ApplicationException) QueueGraph(org.jaffa.qm.apis.data.QueueGraph) QueueAdminResponse(org.jaffa.qm.apis.data.QueueAdminResponse) IllegalPersistentStateRuntimeException(org.jaffa.persistence.exceptions.IllegalPersistentStateRuntimeException) JaffaMessagingFrameworkException(org.jaffa.modules.messaging.services.JaffaMessagingFrameworkException) PostLoadFailedException(org.jaffa.persistence.exceptions.PostLoadFailedException) FrameworkException(org.jaffa.exceptions.FrameworkException) QueryFailedException(org.jaffa.persistence.exceptions.QueryFailedException) ApplicationException(org.jaffa.exceptions.ApplicationException) LinkedList(java.util.LinkedList)

Example 2 with QueueGraph

use of org.jaffa.qm.apis.data.QueueGraph in project jaffa-framework by jaffa-projects.

the class JmsQueueAdmin method toggleQueueStatus.

/**
 * NOTE: Each graph is expected to contain type. It may also contain the optional queueMetaData.queueSystemId, which may help optimize the process.
 */
public QueueAdminResponse[] toggleQueueStatus(QueueGraph[] graphs) {
    if (log.isDebugEnabled())
        log.debug("Input to toggleQueueStatus: " + Arrays.toString(graphs));
    Collection<QueueAdminResponse> output = null;
    String[] queueNames = null;
    for (QueueGraph graph : graphs) {
        if (graph.getQueueMetaData() == null || graph.getQueueMetaData().getQueueSystemId() == null || graph.getQueueMetaData().getQueueSystemId().equals(QUEUE_SYSTEM_ID)) {
            // Initialize and sort the queueNames array; if not already done
            if (queueNames == null) {
                queueNames = ConfigurationService.getInstance().getQueueNames();
                Arrays.sort(queueNames);
            }
            if (Arrays.binarySearch(queueNames, graph.getType()) >= 0) {
                try {
                    if (!JmsBrowser.hasAdminMessageAccess(graph.getType()))
                        throw new JaffaMessagingApplicationException(JaffaMessagingApplicationException.NO_ADMIN_MESSAGE_ACESSS, new Object[] { graph.getType() });
                    if (ConfigurationService.getInstance().getQueueInfo(graph.getType()).getConsumerPolicy() == ConsumerPolicy.NONE) {
                        if (log.isDebugEnabled())
                            log.debug("ConsumerPolicy of queue " + graph.getType() + " is NONE. It's status cannnot be toggled");
                    }
                } catch (Exception e) {
                    QueueAdminResponse response = new QueueAdminResponse();
                    response.setSource(graph);
                    ApplicationExceptions appExps = ExceptionHelper.extractApplicationExceptions(e);
                    if (appExps != null) {
                        if (log.isDebugEnabled())
                            log.debug("Error while toggling status of queue " + graph.getType(), appExps);
                        response.setErrors(ServiceError.generate(appExps));
                    } else {
                        log.error("Internal Error while toggling status of queue " + graph.getType(), e);
                        response.setErrors(ServiceError.generate(e));
                    }
                    if (output == null)
                        output = new LinkedList<QueueAdminResponse>();
                    output.add(response);
                }
            } else {
                if (log.isDebugEnabled())
                    log.debug("Status of queue " + graph.getType() + " will not be toggled by this implementation, since the queue does not belong to this system");
            }
        } else {
            if (log.isDebugEnabled())
                log.debug("Status of queue " + graph.getType() + " will not be toggled by this implementation, since the input queueSystemId does not match this system");
        }
    }
    if (log.isDebugEnabled())
        log.debug("Output from toggleQueueStatus: " + output);
    return output != null && output.size() > 0 ? output.toArray(new QueueAdminResponse[output.size()]) : null;
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) QueueGraph(org.jaffa.qm.apis.data.QueueGraph) QueueAdminResponse(org.jaffa.qm.apis.data.QueueAdminResponse) JMSException(javax.jms.JMSException) IntrospectionException(java.beans.IntrospectionException)

Example 3 with QueueGraph

use of org.jaffa.qm.apis.data.QueueGraph in project jaffa-framework by jaffa-projects.

the class JmsQueueAdmin method queueQuery.

public QueueQueryResponse queueQuery(QueueCriteria criteria) {
    if (log.isDebugEnabled())
        log.debug("Input to queueQuery: " + criteria);
    QueueQueryResponse output = new QueueQueryResponse();
    try {
        // Match the queueSystemId as well apply checks for unsupported criteria
        if (FinderTx.match(QUEUE_SYSTEM_ID, criteria.getQueueSystemId()) && FinderTx.match(null, criteria.getSuccessCount()) && FinderTx.match(null, criteria.getHoldCount()) && FinderTx.match(null, criteria.getInterruptedCount())) {
            String[] queueNames = JmsBrowser.getAccessibleQueueNames();
            if (queueNames != null && queueNames.length > 0) {
                PropertyFilter pf = PropertyFilter.getInstance(QueueGraph.class, criteria.getResultGraphRules());
                Collection<QueueGraph> graphs = new LinkedList<QueueGraph>();
                for (String queueName : queueNames) {
                    if (FinderTx.match(queueName, criteria.getType())) {
                        QueueGraph graph = new QueueGraph();
                        // Compute message count only if required by criteria or if it is included in the property-filter
                        if (criteria.getOpenCount() != null || pf.isFieldIncluded("openCount")) {
                            Message[] messages = JmsBrowser.getPendingMessages(queueName);
                            Long count = messages != null ? messages.length : 0L;
                            if (!FinderTx.match(count, criteria.getOpenCount()))
                                continue;
                            if (pf.isFieldIncluded("openCount"))
                                graph.setOpenCount(count);
                        }
                        // Apply the status criteria
                        if (criteria.getStatus() != null || pf.isFieldIncluded("status")) {
                            QueueGraph.Status status;
                            QueueInfo queueInfo = ConfigurationService.getInstance().getQueueInfo(queueName);
                            if (queueInfo != null && queueInfo.getConsumerPolicy() != ConsumerPolicy.NONE)
                                status = QueueGraph.Status.ACTIVE;
                            else
                                status = QueueGraph.Status.ACTIVE;
                            if (!FinderTx.match(status.toString(), criteria.getStatus()))
                                continue;
                            if (pf.isFieldIncluded("status"))
                                graph.setStatus(status);
                        }
                        // Stamp the remaining properties, if included in the property-filter
                        graph.setQueueMetaData(createQueueMetaData(queueName, pf));
                        if (pf.isFieldIncluded("type"))
                            graph.setType(queueName);
                        if (pf.isFieldIncluded("hasAdminAccess"))
                            graph.setHasAdminAccess(JmsBrowser.hasAdminMessageAccess(queueName));
                        graphs.add(graph);
                    }
                }
                if (graphs.size() > 0)
                    output.setGraphs(graphs.toArray(new QueueGraph[graphs.size()]));
            }
        }
    } catch (Exception e) {
        // add errors to the response
        ApplicationExceptions appExps = ExceptionHelper.extractApplicationExceptions(e);
        if (appExps != null) {
            if (log.isDebugEnabled())
                log.debug("Error in queueQuery execution", appExps);
            output.setErrors(ServiceError.generate(appExps));
        } else {
            log.error("Internal Error in queueQuery execution", e);
            output.setErrors(ServiceError.generate(e));
        }
    }
    if (log.isDebugEnabled())
        log.debug("Output from queueQuery: " + output);
    return output;
}
Also used : QueueInfo(org.jaffa.modules.messaging.services.configdomain.QueueInfo) ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) QueueQueryResponse(org.jaffa.qm.apis.data.QueueQueryResponse) LinkedList(java.util.LinkedList) JMSException(javax.jms.JMSException) IntrospectionException(java.beans.IntrospectionException) QueueGraph(org.jaffa.qm.apis.data.QueueGraph) PropertyFilter(org.jaffa.qm.util.PropertyFilter)

Example 4 with QueueGraph

use of org.jaffa.qm.apis.data.QueueGraph in project jaffa-framework by jaffa-projects.

the class QueueManager method queueQuery.

// TODO-SWAT add script events here
public QueueQueryResponse queueQuery(QueueCriteria criteria) {
    try {
        if (log.isDebugEnabled())
            log.debug("Input to queueQuery: " + criteria);
        QueueQueryResponse aggregateResponse = new QueueQueryResponse();
        IQueueAdmin[] implementations = findImplementations();
        if (implementations != null && implementations.length > 0) {
            for (IQueueAdmin implementation : implementations) {
                QueueQueryResponse response = implementation.queueQuery(criteria);
                if (response != null && response.getErrors() != null && response.getErrors().length > 0) {
                    aggregateResponse.setErrors(response.getErrors());
                    break;
                } else if (response != null && response.getGraphs() != null && response.getGraphs().length > 0) {
                    aggregateResponse.setGraphs(concatenate(aggregateResponse.getGraphs(), response.getGraphs()));
                }
            }
            if (aggregateResponse.getErrors() == null && aggregateResponse.getGraphs() != null && aggregateResponse.getGraphs().length > 0 && criteria.getOrderByFields() != null && criteria.getOrderByFields().length > 0)
                Arrays.sort(aggregateResponse.getGraphs(), new GraphComparator(criteria.getOrderByFields()));
            handlePaging(aggregateResponse, criteria);
        }
        if (aggregateResponse.getGraphs() == null)
            aggregateResponse.setGraphs(new QueueGraph[0]);
        if (log.isDebugEnabled())
            log.debug("Response from queueQuery: " + aggregateResponse);
        return aggregateResponse;
    } catch (Exception e) {
        log.error("Error in obtaining IQueueAdmin implementations", e);
        return new QueueQueryResponse(null, ServiceError.generate(e));
    }
}
Also used : QueueQueryResponse(org.jaffa.qm.apis.data.QueueQueryResponse) QueueGraph(org.jaffa.qm.apis.data.QueueGraph) GraphComparator(org.jaffa.soa.graph.GraphComparator)

Example 5 with QueueGraph

use of org.jaffa.qm.apis.data.QueueGraph in project jaffa-framework by jaffa-projects.

the class TransactionAdmin method queueQuery.

public QueueQueryResponse queueQuery(QueueCriteria criteria) {
    if (log.isDebugEnabled()) {
        log.debug("Input to queueQuery: " + criteria);
    }
    QueueQueryResponse output = new QueueQueryResponse();
    try {
        // Match the queueSystemId
        if (FinderTx.match(QUEUE_SYSTEM_ID, criteria.getQueueSystemId())) {
            String[] types = TransactionEngine.getInstance().getAccessibleTypeNames();
            if (types != null && types.length > 0) {
                PropertyFilter pf = PropertyFilter.getInstance(QueueGraph.class, criteria.getResultGraphRules());
                Collection<QueueGraph> graphs = new LinkedList<QueueGraph>();
                Map<String, TransactionStatusCount> statusCountMap = transactionDAO.getTransactionCountPerStatusForTypes(types);
                for (String type : types) {
                    if (FinderTx.match(type, criteria.getType())) {
                        QueueGraph graph = new QueueGraph();
                        TransactionStatusCount statusCount = statusCountMap.get(type);
                        // Compute message count only if required by criteria or if it is included in the property-filter
                        if ((statusCount != null) && (criteria.getOpenCount() != null || pf.isFieldIncluded("openCount") || criteria.getSuccessCount() != null || pf.isFieldIncluded("successCount") || criteria.getErrorCount() != null || pf.isFieldIncluded("errorCount") || criteria.getHoldCount() != null || pf.isFieldIncluded("holdCount") || criteria.getInProcessCount() != null || pf.isFieldIncluded("inProcessCount") || criteria.getInterruptedCount() != null || pf.isFieldIncluded("interruptedCount") || pf.isFieldIncluded("lastErroredOn"))) {
                            Long openCount = statusCount.getOpenCount();
                            Long successCount = statusCount.getSuccessCount();
                            Long errorCount = statusCount.getErrorCount();
                            Long holdCount = statusCount.getHoldCount();
                            Long inProcessCount = statusCount.getInProcessCount();
                            Long interruptedCount = statusCount.getInterruptedCount();
                            if (pf.isFieldIncluded("lastErroredOn") && statusCount.getTotalCount() > 0L) {
                                graph.setLastErroredOn(transactionDAO.getLastErrorTimeByType(type));
                            }
                            if (!FinderTx.match(openCount, criteria.getOpenCount())) {
                                continue;
                            }
                            if (pf.isFieldIncluded("openCount")) {
                                graph.setOpenCount(openCount);
                            }
                            if (!FinderTx.match(successCount, criteria.getSuccessCount())) {
                                continue;
                            }
                            if (pf.isFieldIncluded("successCount")) {
                                graph.setSuccessCount(successCount);
                            }
                            if (!FinderTx.match(errorCount, criteria.getErrorCount())) {
                                continue;
                            }
                            if (pf.isFieldIncluded("errorCount")) {
                                graph.setErrorCount(errorCount);
                            }
                            if (!FinderTx.match(holdCount, criteria.getHoldCount())) {
                                continue;
                            }
                            if (pf.isFieldIncluded("holdCount")) {
                                graph.setHoldCount(holdCount);
                            }
                            if (!FinderTx.match(inProcessCount, criteria.getInProcessCount())) {
                                continue;
                            }
                            if (pf.isFieldIncluded("inProcessCount")) {
                                graph.setInProcessCount(inProcessCount);
                            }
                            if (!FinderTx.match(interruptedCount, criteria.getInterruptedCount())) {
                                continue;
                            }
                            if (pf.isFieldIncluded("interruptedCount")) {
                                graph.setInterruptedCount(interruptedCount);
                            }
                        }
                        // Apply the status criteria
                        if (criteria.getStatus() != null || pf.isFieldIncluded("status")) {
                            QueueGraph.Status status = QueueGraph.Status.ACTIVE;
                            if (!FinderTx.match(status.toString(), criteria.getStatus())) {
                                continue;
                            }
                            if (pf.isFieldIncluded("status")) {
                                graph.setStatus(status);
                            }
                        }
                        // Stamp the remaining properties, if included in the property-filter
                        graph.setQueueMetaData(createQueueMetaData(type, pf));
                        if (pf.isFieldIncluded("type")) {
                            graph.setType(type);
                        }
                        if (pf.isFieldIncluded("hasAdminAccess")) {
                            graph.setHasAdminAccess(TransactionEngine.getInstance().hasAdminAccess(type));
                        }
                        graphs.add(graph);
                    }
                }
                if (graphs.size() > 0) {
                    output.setGraphs(graphs.toArray(new QueueGraph[graphs.size()]));
                }
            }
        }
    } catch (Exception e) {
        // add errors to the response
        ApplicationExceptions appExps = ExceptionHelper.extractApplicationExceptions(e);
        if (appExps != null) {
            if (log.isDebugEnabled()) {
                log.debug("Error in queueQuery execution", appExps);
            }
            output.setErrors(ServiceError.generate(appExps));
        } else {
            log.error("Internal Error in queueQuery execution", e);
            output.setErrors(ServiceError.generate(e));
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("Output from queueQuery: " + output);
    }
    return output;
}
Also used : TransactionStatusCount(org.jaffa.transaction.domain.TransactionStatusCount) ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) QueueQueryResponse(org.jaffa.qm.apis.data.QueueQueryResponse) LinkedList(java.util.LinkedList) IllegalPersistentStateRuntimeException(org.jaffa.persistence.exceptions.IllegalPersistentStateRuntimeException) JaffaMessagingFrameworkException(org.jaffa.modules.messaging.services.JaffaMessagingFrameworkException) PostLoadFailedException(org.jaffa.persistence.exceptions.PostLoadFailedException) FrameworkException(org.jaffa.exceptions.FrameworkException) QueryFailedException(org.jaffa.persistence.exceptions.QueryFailedException) ApplicationException(org.jaffa.exceptions.ApplicationException) QueueGraph(org.jaffa.qm.apis.data.QueueGraph) PropertyFilter(org.jaffa.qm.util.PropertyFilter)

Aggregations

QueueGraph (org.jaffa.qm.apis.data.QueueGraph)5 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)4 LinkedList (java.util.LinkedList)3 QueueQueryResponse (org.jaffa.qm.apis.data.QueueQueryResponse)3 IntrospectionException (java.beans.IntrospectionException)2 JMSException (javax.jms.JMSException)2 ApplicationException (org.jaffa.exceptions.ApplicationException)2 FrameworkException (org.jaffa.exceptions.FrameworkException)2 JaffaMessagingFrameworkException (org.jaffa.modules.messaging.services.JaffaMessagingFrameworkException)2 IllegalPersistentStateRuntimeException (org.jaffa.persistence.exceptions.IllegalPersistentStateRuntimeException)2 PostLoadFailedException (org.jaffa.persistence.exceptions.PostLoadFailedException)2 QueryFailedException (org.jaffa.persistence.exceptions.QueryFailedException)2 QueueAdminResponse (org.jaffa.qm.apis.data.QueueAdminResponse)2 PropertyFilter (org.jaffa.qm.util.PropertyFilter)2 Message (javax.jms.Message)1 TextMessage (javax.jms.TextMessage)1 QueueInfo (org.jaffa.modules.messaging.services.configdomain.QueueInfo)1 GraphComparator (org.jaffa.soa.graph.GraphComparator)1 TransactionStatusCount (org.jaffa.transaction.domain.TransactionStatusCount)1