Author: kwall Date: Mon Jun 30 16:07:50 2014 New Revision: 1606812 URL: http://svn.apache.org/r1606812 Log: QPID-5820: [Java QMF2 Plugin] changes to plugin owing to the Java Broker model updates made during 0.29
* VHNs (virtualhostnodes) may exist within a VH (virtualhost) * Use Port#availableProtocols rather than Port#protocols when trying to find the AMQP port * Like the CPP Broker, Binding#arguments will be null if the binding was created with none. Note that the QMF plugin still does not support virtualhosts created at runtime. They'll be ignored until the next restart. Work done by Andrew MacBean <[email protected]> and me. Modified: qpid/trunk/qpid/tools/src/java/qpid-broker-plugins-management-qmf2/src/main/java/org/apache/qpid/server/qmf2/QmfManagementAgent.java qpid/trunk/qpid/tools/src/java/qpid-broker-plugins-management-qmf2/src/main/java/org/apache/qpid/server/qmf2/QmfManagementPluginImpl.java qpid/trunk/qpid/tools/src/java/qpid-broker-plugins-management-qmf2/src/main/java/org/apache/qpid/server/qmf2/agentdata/Binding.java qpid/trunk/qpid/tools/src/java/qpid-broker-plugins-management-qmf2/src/main/java/org/apache/qpid/server/qmf2/agentdata/Broker.java Modified: qpid/trunk/qpid/tools/src/java/qpid-broker-plugins-management-qmf2/src/main/java/org/apache/qpid/server/qmf2/QmfManagementAgent.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/java/qpid-broker-plugins-management-qmf2/src/main/java/org/apache/qpid/server/qmf2/QmfManagementAgent.java?rev=1606812&r1=1606811&r2=1606812&view=diff ============================================================================== --- qpid/trunk/qpid/tools/src/java/qpid-broker-plugins-management-qmf2/src/main/java/org/apache/qpid/server/qmf2/QmfManagementAgent.java (original) +++ qpid/trunk/qpid/tools/src/java/qpid-broker-plugins-management-qmf2/src/main/java/org/apache/qpid/server/qmf2/QmfManagementAgent.java Mon Jun 30 16:07:50 2014 @@ -124,7 +124,7 @@ public class QmfManagementAgent implemen public QmfManagementAgent(final String url, final Broker broker) { _broker = broker; - _defaultVirtualHost = (String)broker.getAttribute("defaultVirtualHost"); + _defaultVirtualHost = broker.getDefaultVirtualHost(); try { @@ -174,12 +174,12 @@ public class QmfManagementAgent implemen } catch (QmfException qmfe) { - _log.info("QmfException {} caught in QmfManagementAgent Constructor", qmfe.getMessage()); + _log.error("QmfException caught in QmfManagementAgent Constructor", qmfe); _agent = null; // Causes isConnected() to be false and thus prevents the "QMF2 Management Ready" message. } catch (Exception e) { - _log.info("Exception {} caught in QmfManagementAgent Constructor", e.getMessage()); + _log.error("Exception caught in QmfManagementAgent Constructor", e); _agent = null; // Causes isConnected() to be false and thus prevents the "QMF2 Management Ready" message. } } @@ -212,84 +212,119 @@ public class QmfManagementAgent implemen { childAdded(null, _broker); + if (_log.isDebugEnabled()) + { + _log.debug("Registering model listeners for broker " + _broker); + } + for (VirtualHostNode<?> vhostNode : _broker.getVirtualHostNodes()) { + + if (_log.isDebugEnabled()) + { + _log.debug("Considering virtualhostnode " + vhostNode); + } + VirtualHost<?,?,?> vhost = vhostNode.getVirtualHost(); // We don't add QmfAgentData VirtualHost objects. Possibly TODO, but it's a bit awkward at the moment // because the C++ Broker doesn't *seem* to do much with them and the command line tools such // as qpid-config don't appear to be VirtualHost aware. A way to stay compatible is to mark queues, // exchanges etc with [vhost:<vhost-name>/]<object-name> (see Constructor comments). - vhost.addChangeListener(this); - for (Connection<?> connection : vhost.getConnections()) + if (vhost != null) { - childAdded(vhost, connection); - - for (Session<?> session : connection.getSessions()) - { - childAdded(connection, session); + vhost.addChangeListener(this); - if (session.getConsumers() != null) - { - for (Consumer subscription : session.getConsumers()) - { - childAdded(session, subscription); - } - } - } + addListenersForConnectionsAndChildren(vhost); + addListenersForExchangesAndChildren(vhost); + addListenersForQueuesAndChildren(vhost); } + } - // The code blocks for adding Bindings (and adding Queues) contain checks to see if what is being added - // relates to Queues or Bindings for the QmfManagementAgent. If they are QmfManagementAgent related - // we avoid registering the Object as a QMF Object, in other words we "hide" QmfManagementAgent QMF Objects. - // This is done to be consistent with the C++ broker which also "hides" its own Connection, Queue & Binding. - for (Exchange<?> exchange : vhost.getExchanges()) - { - childAdded(vhost, exchange); - - for (Binding binding : exchange.getBindings()) - { - String key = binding.getName(); - if (key.equals("broker") || key.equals("console.request.agent_locate") || - key.startsWith("apache.org:qpidd:") || key.startsWith("TempQueue")) - { // Don't add QMF related Bindings in registerConfigurationChangeListeners as those will relate - } // to the Agent and we want to "hide" those. - else - { - childAdded(exchange, binding); - } + + if (_log.isDebugEnabled()) + { + _log.debug("Registered model listeners"); + } + + } + + private void addListenersForQueuesAndChildren(final VirtualHost<?, ?, ?> vhost) + { + for (Queue<?> queue : vhost.getQueues()) + { + boolean agentQueue = false; + for (Binding binding : queue.getBindings()) + { + String key = binding.getName(); + if (key.equals("broker") || key.equals("console.request.agent_locate") || + key.startsWith("apache.org:qpidd:")) + { + agentQueue = true; + break; } } - for (Queue<?> queue : vhost.getQueues()) + // Don't add QMF related bindings or Queues in registerConfigurationChangeListeners as those will + // relate to the Agent itself and we want to "hide" those to be consistent with the C++ Broker. + if (!agentQueue) { - boolean agentQueue = false; + childAdded(vhost, queue); + for (Binding binding : queue.getBindings()) { - String key = binding.getName(); - if (key.equals("broker") || key.equals("console.request.agent_locate") || - key.startsWith("apache.org:qpidd:")) - { - agentQueue = true; - break; - } + childAdded(queue, binding); } - // Don't add QMF related bindings or Queues in registerConfigurationChangeListeners as those will - // relate to the Agent itself and we want to "hide" those to be consistent with the C++ Broker. - if (!agentQueue) + for (Consumer subscription : queue.getChildren(Consumer.class)) { - childAdded(vhost, queue); + childAdded(queue, subscription); + } + } + } + } - for (Binding binding : queue.getBindings()) - { - childAdded(queue, binding); - } + private void addListenersForExchangesAndChildren(final VirtualHost<?, ?, ?> vhost) + { + // The code blocks for adding Bindings (and adding Queues) contain checks to see if what is being added + // relates to Queues or Bindings for the QmfManagementAgent. If they are QmfManagementAgent related + // we avoid registering the Object as a QMF Object, in other words we "hide" QmfManagementAgent QMF Objects. + // This is done to be consistent with the C++ broker which also "hides" its own Connection, Queue & Binding. + for (Exchange<?> exchange : vhost.getExchanges()) + { + childAdded(vhost, exchange); + + for (Binding binding : exchange.getBindings()) + { + String key = binding.getName(); + if (key.equals("broker") || key.equals("console.request.agent_locate") || + key.startsWith("apache.org:qpidd:") || key.startsWith("TempQueue")) + { // Don't add QMF related Bindings in registerConfigurationChangeListeners as those will relate + } // to the Agent and we want to "hide" those. + else + { + childAdded(exchange, binding); + } + } + } + } - for (Consumer subscription : queue.getChildren(Consumer.class)) + private void addListenersForConnectionsAndChildren(final VirtualHost<?, ?, ?> vhost) + { + for (Connection<?> connection : vhost.getConnections()) + { + childAdded(vhost, connection); + + for (Session<?> session : connection.getSessions()) + { + childAdded(connection, session); + + if (session.getConsumers() != null) + { + for (Consumer subscription : session.getConsumers()) { - childAdded(queue, subscription); + childAdded(session, subscription); } } } @@ -341,10 +376,17 @@ public class QmfManagementAgent implemen @Override public void childAdded(final ConfiguredObject object, final ConfiguredObject child) { -//System.out.println("childAdded: " + child.getClass().getSimpleName() + "." + child.getName()); + + if (_log.isDebugEnabled()) + { + _log.debug("childAdded: " + child.getClass().getSimpleName() + "." + child.getName()); + } QmfAgentData data = null; + // We current don't listen for new virtualhostnodes or new virtualhosts, so any new instances + // of these objects wont be seen through QMF until the Broker is restarted. + if (child instanceof Broker) { data = new org.apache.qpid.server.qmf2.agentdata.Broker((Broker)child); @@ -478,7 +520,7 @@ public class QmfManagementAgent implemen } catch (QmfException qmfe) { - _log.info("QmfException {} caught in QmfManagementAgent.addObject()", qmfe.getMessage()); + _log.error("QmfException caught in QmfManagementAgent.addObject()", qmfe); } child.addChangeListener(this); @@ -497,7 +539,12 @@ public class QmfManagementAgent implemen @Override public void childRemoved(final ConfiguredObject object, final ConfiguredObject child) { -//System.out.println("childRemoved: " + child.getClass().getSimpleName() + "." + child.getName()); + + + if (_log.isDebugEnabled()) + { + _log.debug("childRemoved: " + child.getClass().getSimpleName() + "." + child.getName()); + } child.removeChangeListener(this); Modified: qpid/trunk/qpid/tools/src/java/qpid-broker-plugins-management-qmf2/src/main/java/org/apache/qpid/server/qmf2/QmfManagementPluginImpl.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/java/qpid-broker-plugins-management-qmf2/src/main/java/org/apache/qpid/server/qmf2/QmfManagementPluginImpl.java?rev=1606812&r1=1606811&r2=1606812&view=diff ============================================================================== --- qpid/trunk/qpid/tools/src/java/qpid-broker-plugins-management-qmf2/src/main/java/org/apache/qpid/server/qmf2/QmfManagementPluginImpl.java (original) +++ qpid/trunk/qpid/tools/src/java/qpid-broker-plugins-management-qmf2/src/main/java/org/apache/qpid/server/qmf2/QmfManagementPluginImpl.java Mon Jun 30 16:07:50 2014 @@ -152,7 +152,8 @@ public class QmfManagementPluginImpl ext { VirtualHost<?, ?, ?> vhost = node.getVirtualHost(); - if (vhost.getName().equals(_defaultVirtualHost)) + + if (vhost != null && vhost.getName().equals(_defaultVirtualHost)) { foundDefaultVirtualHost = true; @@ -200,7 +201,7 @@ public class QmfManagementPluginImpl ext } catch (Exception e) // Catch and log any Exception so we avoid Plugin failures stopping Broker startup. { - _log.info("Exception {} caught in QmfManagementPlugin.start()", e.getMessage()); + _log.error("Exception caught in QmfManagementPlugin.start()", e); } } Modified: qpid/trunk/qpid/tools/src/java/qpid-broker-plugins-management-qmf2/src/main/java/org/apache/qpid/server/qmf2/agentdata/Binding.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/java/qpid-broker-plugins-management-qmf2/src/main/java/org/apache/qpid/server/qmf2/agentdata/Binding.java?rev=1606812&r1=1606811&r2=1606812&view=diff ============================================================================== --- qpid/trunk/qpid/tools/src/java/qpid-broker-plugins-management-qmf2/src/main/java/org/apache/qpid/server/qmf2/agentdata/Binding.java (original) +++ qpid/trunk/qpid/tools/src/java/qpid-broker-plugins-management-qmf2/src/main/java/org/apache/qpid/server/qmf2/agentdata/Binding.java Mon Jun 30 16:07:50 2014 @@ -118,9 +118,8 @@ public class Binding extends QmfAgentDat setValue("bindingKey", binding.getName()); Map<String, Object> arguments = binding.getArguments(); - // binding.getArguments() always returns a Map, but with the C++ broker if there are no arguments - // the property isn't populated, so we only add it if the _arguments.size() > 0 - if (arguments.size() > 0) + // Only add arguments property if the bindings have arguments + if (arguments != null && arguments.size() > 0) { setValue("arguments", arguments); } Modified: qpid/trunk/qpid/tools/src/java/qpid-broker-plugins-management-qmf2/src/main/java/org/apache/qpid/server/qmf2/agentdata/Broker.java URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/tools/src/java/qpid-broker-plugins-management-qmf2/src/main/java/org/apache/qpid/server/qmf2/agentdata/Broker.java?rev=1606812&r1=1606811&r2=1606812&view=diff ============================================================================== --- qpid/trunk/qpid/tools/src/java/qpid-broker-plugins-management-qmf2/src/main/java/org/apache/qpid/server/qmf2/agentdata/Broker.java (original) +++ qpid/trunk/qpid/tools/src/java/qpid-broker-plugins-management-qmf2/src/main/java/org/apache/qpid/server/qmf2/agentdata/Broker.java Mon Jun 30 16:07:50 2014 @@ -352,7 +352,7 @@ public class Broker extends QmfAgentData super(getSchema()); _broker = broker; - _defaultVirtualHost = (String)broker.getAttribute("defaultVirtualHost"); + _defaultVirtualHost = broker.getDefaultVirtualHost(); int amqpPort = 5672; // Default AMQP Port. // Search through the available Ports on this Broker looking for the AMQP Port using the TCP Transport @@ -364,7 +364,7 @@ public class Broker extends QmfAgentData { boolean isAMQP = false; boolean isTCP = false; - for (Protocol protocol : port.getProtocols()) + for (Protocol protocol : port.getAvailableProtocols()) { isAMQP = protocol.isAMQP(); if (isAMQP) --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
