You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by kw...@apache.org on 2016/11/27 20:57:39 UTC

svn commit: r1771645 - /qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/

Author: kwall
Date: Sun Nov 27 20:57:39 2016
New Revision: 1771645

URL: http://svn.apache.org/viewvc?rev=1771645&view=rev
Log:
QPID-7552: [Perf Test Framework] Change QpidRestAPIQueueCreator to retrieve Broker's version number using REST API

Added:
    qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/QpidQueueCreatorFactory.java
Modified:
    qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/ClientJmsDelegate.java
    qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/ControllerJmsDelegate.java
    qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/ExistingQueueDrainer.java
    qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/NoOpQueueCreator.java
    qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/QpidQueueCreator.java
    qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/QpidRestAPIQueueCreator.java
    qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/QueueCreator.java

Modified: qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/ClientJmsDelegate.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/ClientJmsDelegate.java?rev=1771645&r1=1771644&r2=1771645&view=diff
==============================================================================
--- qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/ClientJmsDelegate.java (original)
+++ qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/ClientJmsDelegate.java Sun Nov 27 20:57:39 2016
@@ -19,8 +19,6 @@
  */
 package org.apache.qpid.disttest.jms;
 
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
 import java.util.Enumeration;
 import java.util.Map;
 import java.util.UUID;
@@ -73,6 +71,7 @@ public class ClientJmsDelegate
     private final MessageProducer _controlQueueProducer;
 
     private final String _clientName;
+    private final QueueCreator _queueCreator;
     private Queue _instructionQueue;
 
     private final ConcurrentMap<String, Connection> _testConnections;
@@ -106,6 +105,7 @@ public class ClientJmsDelegate
             _testMessageProviders = new ConcurrentHashMap<>();
             _defaultMessageProvider = new MessageProvider(null);
             _testSessionToConnections = new ConcurrentHashMap<>();
+            _queueCreator = QpidQueueCreatorFactory.createInstance();
         }
         catch (final NamingException ne)
         {
@@ -744,7 +744,7 @@ public class ClientJmsDelegate
 
         if (connection != null)
         {
-            return getProviderVersion(connection);
+            return _queueCreator.getProviderVersion(connection);
         }
         else
         {
@@ -758,7 +758,7 @@ public class ClientJmsDelegate
         Connection connection = getConnectionFor(session);
         if (connection != null)
         {
-            return getProtocolVersion(connection);
+            return _queueCreator.getProtocolVersion(connection);
         }
         else
         {
@@ -766,77 +766,6 @@ public class ClientJmsDelegate
         }
     }
 
-    private String getProviderVersion(final Connection connection)
-    {
-        try
-        {
-            // Unfortunately, Qpid 0-8..0-10 does not define ConnectionMetaData#getProviderVersion in a useful way
-            String qpidRelease = getQpidReleaseVersionByReflection("org.apache.qpid.configuration.CommonProperties");
-            if (qpidRelease == null)
-            {
-                qpidRelease = getQpidReleaseVersionByReflection("org.apache.qpid.common.QpidProperties");  // < 0.32
-
-                if (qpidRelease == null && connection.getMetaData() != null)
-                {
-                    ConnectionMetaData metaData = connection.getMetaData();
-                    qpidRelease = metaData.getProviderVersion();
-                }
-            }
-
-            return qpidRelease;
-        }
-        catch (JMSException e)
-        {
-            return null;
-        }
-    }
-
-    private String getQpidReleaseVersionByReflection(final String className)
-    {
-        try
-        {
-            Class clazz = Class.forName(className);
-            Method method = clazz.getMethod("getReleaseVersion");
-            Object version =  method.invoke(null);
-            return String.valueOf(version);
-        }
-        catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException e)
-        {
-            return null;
-        }
-    }
-
-    private String getProtocolVersion(final Connection connection)
-    {
-        if (connection != null)
-        {
-            try
-            {
-                final Method method = connection.getClass().getMethod("getProtocolVersion"); // Qpid 0-8..0-10 method only
-                Object version =  method.invoke(connection);
-                return String.valueOf(version);
-            }
-            catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e)
-            {
-                try
-                {
-                    ConnectionMetaData  metaData = connection.getMetaData();
-                    if (metaData != null && ("QpidJMS".equals(metaData.getJMSProviderName()) ||
-                                             "AMQP.ORG".equals(metaData.getJMSProviderName())))
-                    {
-                        return "1.0";
-                    }
-                }
-                catch (JMSException e1)
-                {
-                    return null;
-                }
-                return null;
-            }
-        }
-        return null;
-    }
-
     private Connection getConnectionFor(final Session session)
     {
         if (session != null)

Modified: qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/ControllerJmsDelegate.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/ControllerJmsDelegate.java?rev=1771645&r1=1771644&r2=1771645&view=diff
==============================================================================
--- qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/ControllerJmsDelegate.java (original)
+++ qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/ControllerJmsDelegate.java Sun Nov 27 20:57:39 2016
@@ -51,14 +51,12 @@ public class ControllerJmsDelegate
 {
     private static final Logger LOGGER = LoggerFactory.getLogger(ControllerJmsDelegate.class);
 
-    private static final String QUEUE_CREATOR_CLASS_NAME_SYSTEM_PROPERTY = "qpid.disttest.queue.creator.class";
-
     private final Map<String, Destination> _clientNameToQueueMap = new ConcurrentHashMap<String, Destination>();
     private final Connection _connection;
     private final Queue _controllerQueue;
     private final Session _controllerQueueListenerSession;
     private final Session _commandSession;
-    private QueueCreator _queueCreator;
+    private final QueueCreator _queueCreator;
 
     private List<CommandListener> _commandListeners = new CopyOnWriteArrayList<CommandListener>();
 
@@ -70,39 +68,7 @@ public class ControllerJmsDelegate
         _controllerQueue = (Queue) context.lookup("controllerqueue");
         _controllerQueueListenerSession = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
         _commandSession = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
-        createVendorSpecificQueueCreator();
-    }
-
-    private void createVendorSpecificQueueCreator()
-    {
-        String queueCreatorClassName = System.getProperty(QUEUE_CREATOR_CLASS_NAME_SYSTEM_PROPERTY);
-        if(queueCreatorClassName == null)
-        {
-            queueCreatorClassName = QpidQueueCreator.class.getName();
-        }
-        else
-        {
-            LOGGER.info("Using overridden queue creator class " + queueCreatorClassName);
-        }
-
-        try
-        {
-            Class<? extends QueueCreator> queueCreatorClass = (Class<? extends QueueCreator>) Class.forName(queueCreatorClassName);
-            _queueCreator = queueCreatorClass.newInstance();
-        }
-        catch (ClassNotFoundException e)
-        {
-            throw new DistributedTestException("Unable to instantiate queue creator using class name " + queueCreatorClassName, e);
-        }
-        catch (InstantiationException e)
-        {
-            throw new DistributedTestException("Unable to instantiate queue creator using class name " + queueCreatorClassName, e);
-        }
-        catch (IllegalAccessException e)
-        {
-            throw new DistributedTestException("Unable to instantiate queue creator using class name " + queueCreatorClassName, e);
-        }
+        _queueCreator = QpidQueueCreatorFactory.createInstance();
     }
 
     public void start()

Modified: qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/ExistingQueueDrainer.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/ExistingQueueDrainer.java?rev=1771645&r1=1771644&r2=1771645&view=diff
==============================================================================
--- qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/ExistingQueueDrainer.java (original)
+++ qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/ExistingQueueDrainer.java Sun Nov 27 20:57:39 2016
@@ -49,6 +49,18 @@ public class ExistingQueueDrainer implem
         }
     }
 
+    @Override
+    public String getProtocolVersion(final Connection connection)
+    {
+        return null;
+    }
+
+    @Override
+    public String getProviderVersion(final Connection connection)
+    {
+        return null;
+    }
+
     private void drainQueue(Connection connection, String queueName)
     {
         try

Modified: qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/NoOpQueueCreator.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/NoOpQueueCreator.java?rev=1771645&r1=1771644&r2=1771645&view=diff
==============================================================================
--- qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/NoOpQueueCreator.java (original)
+++ qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/NoOpQueueCreator.java Sun Nov 27 20:57:39 2016
@@ -24,6 +24,7 @@ import javax.jms.Connection;
 import javax.jms.Session;
 
 import org.apache.qpid.disttest.controller.config.QueueConfig;
+
 public class NoOpQueueCreator implements QueueCreator
 {
     @Override
@@ -35,4 +36,16 @@ public class NoOpQueueCreator implements
     public void deleteQueues(Connection connection, Session session, List<QueueConfig> configs)
     {
     }
+
+    @Override
+    public String getProtocolVersion(final Connection connection)
+    {
+        return null;
+    }
+
+    @Override
+    public String getProviderVersion(final Connection connection)
+    {
+        return null;
+    }
 }

Modified: qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/QpidQueueCreator.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/QpidQueueCreator.java?rev=1771645&r1=1771644&r2=1771645&view=diff
==============================================================================
--- qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/QpidQueueCreator.java (original)
+++ qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/QpidQueueCreator.java Sun Nov 27 20:57:39 2016
@@ -252,7 +252,59 @@ public class QpidQueueCreator implements
         {
             executorService.shutdown();
         }
+    }
 
+    @Override
+    public String getProtocolVersion(final Connection connection)
+    {
+        if (connection != null)
+        {
+            try
+            {
+                final Method method = connection.getClass().getMethod("getProtocolVersion"); // Qpid 0-8..0-10 method only
+                Object version =  method.invoke(connection);
+                return String.valueOf(version);
+            }
+            catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e)
+            {
+                return null;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * We currently rely on the fact that the client version numbers follow the broker's.
+     * This should be changed to use AMQP Management.
+     *
+     * @param connection
+     * @return
+     */
+    @Override
+    public String getProviderVersion(final Connection connection)
+    {
+        // Unfortunately, Qpid 0-8..0-10 does not define ConnectionMetaData#getProviderVersion in a useful way
+        String qpidRelease = getQpidReleaseVersionByReflection("org.apache.qpid.configuration.CommonProperties");
+        if (qpidRelease == null)
+        {
+            qpidRelease = getQpidReleaseVersionByReflection("org.apache.qpid.common.QpidProperties");  // < 0.32
+        }
+        return qpidRelease;
+    }
+
+    private String getQpidReleaseVersionByReflection(final String className)
+    {
+        try
+        {
+            Class clazz = Class.forName(className);
+            Method method = clazz.getMethod("getReleaseVersion");
+            Object version =  method.invoke(null);
+            return String.valueOf(version);
+        }
+        catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | IllegalAccessException e)
+        {
+            return null;
+        }
     }
 
     private void closeAllSessions(final Map<Thread, AMQSession<?, ?>> sessionMap)

Added: qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/QpidQueueCreatorFactory.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/QpidQueueCreatorFactory.java?rev=1771645&view=auto
==============================================================================
--- qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/QpidQueueCreatorFactory.java (added)
+++ qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/QpidQueueCreatorFactory.java Sun Nov 27 20:57:39 2016
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.qpid.disttest.jms;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.qpid.disttest.DistributedTestException;
+
+public class QpidQueueCreatorFactory
+{
+    private static final Logger LOGGER = LoggerFactory.getLogger(QpidQueueCreatorFactory.class);
+
+    private static final String QUEUE_CREATOR_CLASS_NAME_SYSTEM_PROPERTY = "qpid.disttest.queue.creator.class";
+
+    private QpidQueueCreatorFactory()
+    {
+    }
+
+    public static QueueCreator createInstance()
+    {
+        String queueCreatorClassName = System.getProperty(QUEUE_CREATOR_CLASS_NAME_SYSTEM_PROPERTY);
+        if(queueCreatorClassName == null)
+        {
+            queueCreatorClassName = QpidQueueCreator.class.getName();
+        }
+        else
+        {
+            LOGGER.info("Using overridden queue creator class " + queueCreatorClassName);
+        }
+
+        try
+        {
+            Class<? extends QueueCreator> queueCreatorClass = (Class<? extends QueueCreator>) Class.forName(queueCreatorClassName);
+            return queueCreatorClass.newInstance();
+        }
+        catch (ClassNotFoundException e)
+        {
+            throw new DistributedTestException("Unable to instantiate queue creator using class name " + queueCreatorClassName, e);
+        }
+        catch (InstantiationException e)
+        {
+            throw new DistributedTestException("Unable to instantiate queue creator using class name " + queueCreatorClassName, e);
+        }
+        catch (IllegalAccessException e)
+        {
+            throw new DistributedTestException("Unable to instantiate queue creator using class name " + queueCreatorClassName, e);
+        }
+    }
+}

Modified: qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/QpidRestAPIQueueCreator.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/QpidRestAPIQueueCreator.java?rev=1771645&r1=1771644&r2=1771645&view=diff
==============================================================================
--- qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/QpidRestAPIQueueCreator.java (original)
+++ qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/QpidRestAPIQueueCreator.java Sun Nov 27 20:57:39 2016
@@ -19,22 +19,32 @@
  */
 package org.apache.qpid.disttest.jms;
 
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import javax.jms.Connection;
+import javax.jms.ConnectionMetaData;
 import javax.jms.JMSException;
 import javax.jms.MessageConsumer;
 import javax.jms.QueueBrowser;
 import javax.jms.Session;
 
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpResponse;
 import org.apache.http.auth.UsernamePasswordCredentials;
 import org.apache.http.client.HttpClient;
 import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.client.methods.HttpGet;
 import org.apache.http.client.methods.HttpPut;
 import org.apache.http.client.protocol.HttpClientContext;
 import org.apache.http.entity.StringEntity;
@@ -54,12 +64,15 @@ public class QpidRestAPIQueueCreator imp
 {
     private static final Logger LOGGER = LoggerFactory.getLogger(QpidRestAPIQueueCreator.class);
     private static int _drainPollTimeout = Integer.getInteger(QUEUE_CREATOR_DRAIN_POLL_TIMEOUT, 500);
+    private static final TypeReference<List<HashMap<String, Object>>> MAP_TYPE_REFERENCE = new TypeReference<List<HashMap<String,Object>>>(){};
+
     private final HttpHost _management;
     private final String _managementUser;
     private final String _managementPassword;
     private final String _virtualhostnode;
     private final String _virtualhost;
     private final String _queueApiUrl;
+    private final String _brokerApiUrl;
 
     public QpidRestAPIQueueCreator()
     {
@@ -71,6 +84,7 @@ public class QpidRestAPIQueueCreator imp
 
         _management = HttpHost.create(System.getProperty("perftests.manangement-url", "http://localhost:8080"));
         _queueApiUrl = System.getProperty("perftests.manangement-api-queue", "/api/latest/queue/%s/%s/%s");
+        _brokerApiUrl = System.getProperty("perftests.manangement-api-broker", "/api/latest/broker");
     }
 
     @Override
@@ -98,6 +112,47 @@ public class QpidRestAPIQueueCreator imp
         }
     }
 
+    @Override
+    public String getProtocolVersion(final Connection connection)
+    {
+        if (connection != null)
+        {
+            try
+            {
+                final Method method = connection.getClass().getMethod("getProtocolVersion"); // Qpid 0-8..0-10 method only
+                Object version =  method.invoke(connection);
+                return String.valueOf(version);
+            }
+            catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e)
+            {
+                try
+                {
+                    ConnectionMetaData metaData = connection.getMetaData();
+                    if (metaData != null && ("QpidJMS".equals(metaData.getJMSProviderName()) ||
+                                             "AMQP.ORG".equals(metaData.getJMSProviderName())))
+                    {
+                        return "1.0";
+                    }
+                }
+                catch (JMSException e1)
+                {
+                    return null;
+                }
+                return null;
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public String getProviderVersion(final Connection connection)
+    {
+        HttpClientContext context = HttpClientContext.create();
+
+        final Map<String, Object> stringObjectMap = managementQueryBroker(context);
+        return stringObjectMap == null || stringObjectMap.get("productVersion") == null ? null : String.valueOf(stringObjectMap.get("productVersion"));
+    }
+
     private void drainQueue(Connection connection, String queueName)
     {
         try
@@ -181,6 +236,13 @@ public class QpidRestAPIQueueCreator imp
         }
     }
 
+    private Map<String, Object> managementQueryBroker(final HttpClientContext context)
+    {
+        HttpGet get = new HttpGet(_brokerApiUrl);
+        final List<Map<String, Object>> maps = executeManagement(get, context);
+        return maps.isEmpty() ? Collections.<String, Object>emptyMap() : maps.get(0);
+    }
+
     private void managementCreateQueue(final String name, final HttpClientContext context)
     {
         HttpPut put = new HttpPut(String.format(_queueApiUrl, _virtualhostnode, _virtualhost, name));
@@ -210,7 +272,7 @@ public class QpidRestAPIQueueCreator imp
         }
     }
 
-    private void executeManagement(final HttpRequest httpRequest, final HttpClientContext context)
+    private List<Map<String, Object>> executeManagement(final HttpRequest httpRequest, final HttpClientContext context)
     {
         try
         {
@@ -229,6 +291,19 @@ public class QpidRestAPIQueueCreator imp
                                                          response.getStatusLine()));
             }
 
+            if (response.getEntity() != null)
+            {
+                try (ByteArrayOutputStream bos = new ByteArrayOutputStream())
+                {
+                    response.getEntity().writeTo(bos);
+                    if (bos.size() > 0)
+                    {
+                        return new ObjectMapper().readValue(bos.toByteArray(), MAP_TYPE_REFERENCE);
+                    }
+                }
+            }
+            return null;
+
         }
         catch (IOException | org.apache.http.auth.AuthenticationException e)
         {

Modified: qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/QueueCreator.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/QueueCreator.java?rev=1771645&r1=1771644&r2=1771645&view=diff
==============================================================================
--- qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/QueueCreator.java (original)
+++ qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/jms/QueueCreator.java Sun Nov 27 20:57:39 2016
@@ -33,4 +33,7 @@ public interface QueueCreator
 
     void createQueues(Connection connection, Session session, List<QueueConfig> configs);
     void deleteQueues(Connection connection, Session session, List<QueueConfig> configs);
+
+    String getProtocolVersion(Connection connection);
+    String getProviderVersion(Connection connection);
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org