Search in sources :

Example 11 with ObjectId

use of org.apache.qpid.qmf2.common.ObjectId in project qpid by apache.

the class ConnectionAudit method validateQueue.

/**
 * Looks up the exchange and binding information from the supplied queuename then calls the main validateQueue()
 * @param queueName the name of the queue that we want to check against the whitelists.
 * @param address the connection address information for the subscription.
 * @param timestamp the timestamp of the subscription.
 */
private void validateQueue(final String queueName, final String address, final String timestamp) {
    ObjectId queueId = null;
    List<QmfConsoleData> queues = _console.getObjects("org.apache.qpid.broker", "queue");
    for (QmfConsoleData queue : queues) {
        // We first have to find the ObjectId of the queue called queueName.
        if (queue.getStringValue("name").equals(queueName)) {
            queueId = queue.getObjectId();
            break;
        }
    }
    if (queueId == null) {
        System.out.printf("%s ERROR ConnectionAudit.validateQueue() %s reference couldn't be found\n", new Date().toString(), queueName);
    } else {
        // If we've got the queue's ObjectId we then find the binding that references it.
        List<QmfConsoleData> bindings = _console.getObjects("org.apache.qpid.broker", "binding");
        for (QmfConsoleData binding : bindings) {
            ObjectId queueRef = binding.getRefValue("queueRef");
            if (queueRef.equals(queueId)) {
                // We've found a binding that matches queue queueName so look up the associated exchange and validate.
                QmfConsoleData exchange = dereference(binding.getRefValue("exchangeRef"));
                String exchangeName = exchange.getStringValue("name");
                validateQueue(queueName, exchangeName, binding, address, timestamp);
            }
        }
    }
}
Also used : ObjectId(org.apache.qpid.qmf2.common.ObjectId) QmfConsoleData(org.apache.qpid.qmf2.console.QmfConsoleData) Date(java.util.Date)

Example 12 with ObjectId

use of org.apache.qpid.qmf2.common.ObjectId in project qpid by apache.

the class ConnectionLogger method logQueueInformation.

/**
 * For every queue list the bindings (equivalent of qpid-config -b queues)
 *
 * More or less a direct Java port of QueueListRecurse in qpid-config, which handles qpid-config -b queues
 *
 * @param ref If ref is null list info about all queues else list info about queue referenced by ObjectID
 */
private void logQueueInformation(final ObjectId ref) {
    List<QmfConsoleData> queues = _console.getObjects("org.apache.qpid.broker", "queue");
    List<QmfConsoleData> bindings = _console.getObjects("org.apache.qpid.broker", "binding");
    List<QmfConsoleData> exchanges = _console.getObjects("org.apache.qpid.broker", "exchange");
    for (QmfConsoleData queue : queues) {
        ObjectId queueId = queue.getObjectId();
        if (ref == null || ref.equals(queueId)) {
            System.out.printf("    Queue '%s'\n", queue.getStringValue("name"));
            System.out.println("        arguments " + (Map) queue.getValue("arguments"));
            for (QmfConsoleData binding : bindings) {
                ObjectId queueRef = binding.getRefValue("queueRef");
                if (queueRef.equals(queueId)) {
                    ObjectId exchangeRef = binding.getRefValue("exchangeRef");
                    QmfConsoleData exchange = findById(exchanges, exchangeRef);
                    String exchangeName = "<unknown>";
                    if (exchange != null) {
                        exchangeName = exchange.getStringValue("name");
                        if (exchangeName.equals("")) {
                            exchangeName = "''";
                        }
                    }
                    String bindingKey = binding.getStringValue("bindingKey");
                    Map arguments = (Map) binding.getValue("arguments");
                    if (arguments.isEmpty()) {
                        System.out.printf("        bind [%s] => %s\n", bindingKey, exchangeName);
                    } else {
                        // If there are binding arguments then it's a headers exchange
                        System.out.printf("        bind [%s] => %s %s\n", bindingKey, exchangeName, arguments);
                    }
                }
            }
        }
    }
}
Also used : ObjectId(org.apache.qpid.qmf2.common.ObjectId) QmfConsoleData(org.apache.qpid.qmf2.console.QmfConsoleData) Map(java.util.Map)

Example 13 with ObjectId

use of org.apache.qpid.qmf2.common.ObjectId in project qpid by apache.

the class QpidConfig method queueListRecurse.

/**
 * For every queue list the bindings (equivalent of qpid-config -b queues).
 *
 * More or less a direct Java port of QueueListRecurse in qpid-config, which handles qpid-config -b queues.
 *
 * @param filter specifies the queue name to display info for, if set to "" displays info for every queue.
 */
private void queueListRecurse(final String filter) {
    List<QmfConsoleData> queues = _console.getObjects("org.apache.qpid.broker", "queue");
    List<QmfConsoleData> bindings = _console.getObjects("org.apache.qpid.broker", "binding");
    List<QmfConsoleData> exchanges = _console.getObjects("org.apache.qpid.broker", "exchange");
    for (QmfConsoleData queue : queues) {
        ObjectId queueId = queue.getObjectId();
        String name = queue.getStringValue("name");
        if (filter.equals("") || filter.equals(name)) {
            System.out.printf("Queue '%s'\n", name);
            for (QmfConsoleData binding : bindings) {
                ObjectId queueRef = binding.getRefValue("queueRef");
                if (queueRef.equals(queueId)) {
                    ObjectId exchangeRef = binding.getRefValue("exchangeRef");
                    QmfConsoleData exchange = findById(exchanges, exchangeRef);
                    String exchangeName = "<unknown>";
                    if (exchange != null) {
                        exchangeName = exchange.getStringValue("name");
                        if (exchangeName.equals("")) {
                            exchangeName = "''";
                        }
                    }
                    String bindingKey = binding.getStringValue("bindingKey");
                    Map arguments = (Map) binding.getValue("arguments");
                    if (arguments == null || arguments.isEmpty()) {
                        System.out.printf("    bind [%s] => %s\n", bindingKey, exchangeName);
                    } else {
                        // If there are binding arguments then it's a headers exchange
                        System.out.printf("    bind [%s] => %s %s\n", bindingKey, exchangeName, arguments);
                    }
                }
            }
        }
    }
}
Also used : ObjectId(org.apache.qpid.qmf2.common.ObjectId) QmfConsoleData(org.apache.qpid.qmf2.console.QmfConsoleData) HashMap(java.util.HashMap) Map(java.util.Map)

Example 14 with ObjectId

use of org.apache.qpid.qmf2.common.ObjectId in project qpid by apache.

the class QpidConfig method queueList.

/**
 * For every queue list detailed info (equivalent of qpid-config queues).
 *
 * More or less a direct Java port of QueueList in qpid-config, which handles qpid-config queues.
 *
 * @param filter specifies the queue name to display info for, if set to "" displays info for every queue.
 */
private void queueList(final String filter) {
    List<QmfConsoleData> queues = _console.getObjects("org.apache.qpid.broker", "queue");
    String caption = "Queue Name";
    int maxNameLen = caption.length();
    for (QmfConsoleData queue : queues) {
        String name = queue.getStringValue("name");
        if (filter.equals("") || filter.equals(name)) {
            if (name.length() > maxNameLen) {
                maxNameLen = name.length();
            }
        }
    }
    System.out.printf("%-" + maxNameLen + "s Attributes\n", caption);
    StringBuilder buf = new StringBuilder();
    for (int i = 0; i < ((maxNameLen / 5) + 5); i++) {
        buf.append("=====");
    }
    String line = buf.toString();
    System.out.println(line);
    for (QmfConsoleData queue : queues) {
        String name = queue.getStringValue("name");
        if (filter.equals("") || filter.equals(name)) {
            System.out.printf("%-" + maxNameLen + "s ", name);
            Map<String, Object> args = queue.<Map<String, Object>>getValue("arguments");
            args = (args == null) ? Collections.EMPTY_MAP : args;
            /*System.out.println(args);
for (Map.Entry<String, Object> entry  : args.entrySet()) {
    System.out.println(entry.getKey() + " " + entry.getValue().getClass().getCanonicalName());
}*/
            if (queue.getBooleanValue("durable")) {
                System.out.printf("--durable ");
            }
            if (queue.getBooleanValue("autoDelete")) {
                System.out.printf("auto-del ");
            }
            if (queue.getBooleanValue("exclusive")) {
                System.out.printf("excl ");
            }
            if (args.containsKey(FILESIZE)) {
                System.out.printf("--file-size=%d ", QmfData.getLong(args.get(FILESIZE)));
            }
            if (args.containsKey(FILECOUNT)) {
                System.out.printf("--file-count=%d ", QmfData.getLong(args.get(FILECOUNT)));
            }
            if (args.containsKey(MAX_QUEUE_SIZE)) {
                System.out.printf("--max-queue-size=%d ", QmfData.getLong(args.get(MAX_QUEUE_SIZE)));
            }
            if (args.containsKey(MAX_QUEUE_COUNT)) {
                System.out.printf("--max-queue-count=%d ", QmfData.getLong(args.get(MAX_QUEUE_COUNT)));
            }
            if (args.containsKey(POLICY_TYPE)) {
                System.out.printf("--limit-policy=%s ", (QmfData.getString(args.get(POLICY_TYPE))).replace("_", "-"));
            }
            if (args.containsKey(LVQ) && QmfData.getLong(args.get(LVQ)) == 1) {
                System.out.printf("--order lvq ");
            }
            if (args.containsKey(LVQNB) && QmfData.getLong(args.get(LVQNB)) == 1) {
                System.out.printf("--order lvq-no-browse ");
            }
            if (queue.hasValue("altExchange")) {
                ObjectId altExchangeRef = queue.getRefValue("altExchange");
                List<QmfConsoleData> altExchanges = _console.getObjects(altExchangeRef);
                if (altExchanges.size() == 1) {
                    QmfConsoleData altExchange = altExchanges.get(0);
                    System.out.printf("--alternate-exchange=%s", altExchange.getStringValue("name"));
                }
            }
            if (args.containsKey(FLOW_STOP_SIZE)) {
                System.out.printf("--flow-stop-size=%d ", QmfData.getLong(args.get(FLOW_STOP_SIZE)));
            }
            if (args.containsKey(FLOW_RESUME_SIZE)) {
                System.out.printf("--flow-resume-size=%d ", QmfData.getLong(args.get(FLOW_RESUME_SIZE)));
            }
            if (args.containsKey(FLOW_STOP_COUNT)) {
                System.out.printf("--flow-stop-count=%d ", QmfData.getLong(args.get(FLOW_STOP_COUNT)));
            }
            if (args.containsKey(FLOW_RESUME_COUNT)) {
                System.out.printf("--flow-resume-count=%d ", QmfData.getLong(args.get(FLOW_RESUME_COUNT)));
            }
            for (Map.Entry<String, Object> entry : args.entrySet()) {
                // Display generic queue arguments
                if (!SPECIAL_ARGS.contains(entry.getKey())) {
                    System.out.printf("--argument %s=%s ", entry.getKey(), entry.getValue());
                }
            }
            System.out.println();
        }
    }
}
Also used : ObjectId(org.apache.qpid.qmf2.common.ObjectId) QmfConsoleData(org.apache.qpid.qmf2.console.QmfConsoleData) HashMap(java.util.HashMap) Map(java.util.Map)

Example 15 with ObjectId

use of org.apache.qpid.qmf2.common.ObjectId in project qpid by apache.

the class QpidConfig method delQueue.

/**
 * Remove a queue using the QMF "delete" method.
 * @param args the queue name is the first argument.
 * The remaining QMF method properties are populated form config parsed from the command line.
 */
private void delQueue(final String[] args) {
    if (args.length < 1) {
        usage();
    }
    if (_ifEmpty || _ifUnused) {
        // Check the selected queue object to see if it is not empty or is in use
        List<QmfConsoleData> queues = _console.getObjects("org.apache.qpid.broker", "queue");
        for (QmfConsoleData queue : queues) {
            ObjectId queueId = queue.getObjectId();
            String name = queue.getStringValue("name");
            if (name.equals(args[0])) {
                long msgDepth = queue.getLongValue("msgDepth");
                if (_ifEmpty == true && msgDepth > 0) {
                    System.out.println("Cannot delete queue " + name + "; queue not empty");
                    return;
                }
                long consumerCount = queue.getLongValue("consumerCount");
                if (_ifUnused == true && consumerCount > 0) {
                    System.out.println("Cannot delete queue " + name + "; queue in use");
                    return;
                }
            }
        }
    }
    QmfData arguments = new QmfData();
    arguments.setValue("type", "queue");
    arguments.setValue("name", args[0]);
    try {
        _broker.invokeMethod("delete", arguments);
    } catch (QmfException e) {
        System.out.println(e.getMessage());
    }
}
Also used : QmfData(org.apache.qpid.qmf2.common.QmfData) ObjectId(org.apache.qpid.qmf2.common.ObjectId) QmfConsoleData(org.apache.qpid.qmf2.console.QmfConsoleData) QmfException(org.apache.qpid.qmf2.common.QmfException)

Aggregations

ObjectId (org.apache.qpid.qmf2.common.ObjectId)28 QmfConsoleData (org.apache.qpid.qmf2.console.QmfConsoleData)15 Map (java.util.Map)10 HashMap (java.util.HashMap)8 QmfException (org.apache.qpid.qmf2.common.QmfException)7 QmfAgentData (org.apache.qpid.qmf2.agent.QmfAgentData)6 QmfData (org.apache.qpid.qmf2.common.QmfData)6 SchemaClassId (org.apache.qpid.qmf2.common.SchemaClassId)6 ArrayList (java.util.ArrayList)5 QmfEvent (org.apache.qpid.qmf2.common.QmfEvent)5 Agent (org.apache.qpid.qmf2.console.Agent)5 MethodCallParams (org.apache.qpid.qmf2.agent.MethodCallParams)4 MethodCallWorkItem (org.apache.qpid.qmf2.agent.MethodCallWorkItem)4 AgentHeartbeatWorkItem (org.apache.qpid.qmf2.console.AgentHeartbeatWorkItem)4 MethodResult (org.apache.qpid.qmf2.console.MethodResult)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 QmfQuery (org.apache.qpid.qmf2.common.QmfQuery)3 SchemaClass (org.apache.qpid.qmf2.common.SchemaClass)3 EventReceivedWorkItem (org.apache.qpid.qmf2.console.EventReceivedWorkItem)3 MethodResponseWorkItem (org.apache.qpid.qmf2.console.MethodResponseWorkItem)3