You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2011/06/20 18:24:15 UTC

svn commit: r1137685 - in /activemq/activemq-apollo/trunk: apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/ apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/ apollo-website/src/documentation/

Author: chirino
Date: Mon Jun 20 16:24:15 2011
New Revision: 1137685

URL: http://svn.apache.org/viewvc?rev=1137685&view=rev
Log:
Fixes https://issues.apache.org/jira/browse/APLO-51 - We retain original creation ordering for resources plus allow users to select the order they would rather get results in.

Modified:
    activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala
    activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/LocalRouter.scala
    activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/BrokerResource.scala
    activemq/activemq-apollo/trunk/apollo-website/src/documentation/management-api.md

Modified: activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala?rev=1137685&r1=1137684&r2=1137685&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala (original)
+++ activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala Mon Jun 20 16:24:15 2011
@@ -229,7 +229,7 @@ class Broker() extends BaseService {
   val virtual_hosts_by_hostname = new LinkedHashMap[AsciiBuffer, VirtualHost]()
 
   val connectors = LinkedHashMap[String, Connector]()
-  val connections = HashMap[Long, BrokerConnection]()
+  val connections = LinkedHashMap[Long, BrokerConnection]()
 
   val dispatch_queue = createQueue("broker")
 

Modified: activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/LocalRouter.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/LocalRouter.scala?rev=1137685&r1=1137684&r2=1137685&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/LocalRouter.scala (original)
+++ activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/LocalRouter.scala Mon Jun 20 16:24:15 2011
@@ -16,22 +16,17 @@
  */
 package org.apache.activemq.apollo.broker
 
-import _root_.org.fusesource.hawtbuf._
 import org.fusesource.hawtdispatch._
 import collection.JavaConversions
 import org.apache.activemq.apollo.util._
-import collection.mutable.HashMap
 import org.apache.activemq.apollo.broker.store.QueueRecord
-import Buffer._
 import path._
 import security.SecurityContext
 import java.util.concurrent.TimeUnit
-import collection.mutable.ListBuffer._
-import collection.mutable.HashMap._
 import scala.Array
-import tools.nsc.doc.model.ProtectedInInstance
 import org.apache.activemq.apollo.dto._
 import java.util.{Arrays, ArrayList}
+import collection.mutable.{LinkedHashMap, HashMap}
 
 trait DomainDestination {
 
@@ -128,7 +123,7 @@ class LocalRouter(val virtual_host:Virtu
   trait Domain[D <: DomainDestination] {
 
     // holds all the destinations in the domain by id
-    var destination_by_id = HashMap[String, D]()
+    var destination_by_id = LinkedHashMap[String, D]()
     // holds all the destinations in the domain by path
     var destination_by_path = new PathMap[D]()
     // Can store consumers on wild cards paths
@@ -870,8 +865,8 @@ class LocalRouter(val virtual_host:Virtu
   //
   /////////////////////////////////////////////////////////////////////////////
 
-  var queues_by_binding = HashMap[QueueBinding, Queue]()
-  var queues_by_id = HashMap[String, Queue]()
+  var queues_by_binding = LinkedHashMap[QueueBinding, Queue]()
+  var queues_by_id = LinkedHashMap[String, Queue]()
 
   /**
    * Gets an existing queue.

Modified: activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/BrokerResource.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/BrokerResource.scala?rev=1137685&r1=1137684&r2=1137685&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/BrokerResource.scala (original)
+++ activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/BrokerResource.scala Mon Jun 20 16:24:15 2011
@@ -25,7 +25,6 @@ import scala.Some
 import security.{SecurityContext, Authorizer}
 import org.apache.activemq.apollo.util.path.PathParser
 import org.apache.activemq.apollo.web.resources.Resource._
-import org.josql.Query
 import org.apache.activemq.apollo.util._
 import collection.mutable.ListBuffer
 import javax.ws.rs._
@@ -37,6 +36,8 @@ import management.ManagementFactory
 import javax.management.ObjectName
 import javax.management.openmbean.CompositeData
 import javax.management.remote.rmi._RMIConnection_Stub
+import org.josql.{QueryResults, Query}
+import java.util.Collections
 
 /**
  * <p>
@@ -294,7 +295,7 @@ case class BrokerResource() extends Reso
     link
   }
 
-  def narrow[T](kind:Class[T], x:Iterable[Result[T, Throwable]], f:java.util.List[String], q:String, p:java.lang.Integer, ps:java.lang.Integer) = {
+  def narrow[T](kind:Class[T], x:Iterable[Result[T, Throwable]], f:java.util.List[String], q:String, p:java.lang.Integer, ps:java.lang.Integer, o:java.util.List[String]) = {
     import collection.JavaConversions._
     try {
       var records = x.toSeq.flatMap(_.success_option)
@@ -306,19 +307,21 @@ case class BrokerResource() extends Reso
       val fields = if (f.isEmpty) "*" else f.toList.mkString(",")
       val where_clause = if (q != null) q else "1=1"
 
-      query.parse("SELECT " + fields + " FROM " + kind.getName + " WHERE "+ where_clause+" LIMIT "+((page_size*page)+1)+", "+page_size)
+      val orderby_clause = if (o.isEmpty) "" else " ORDER BY "+o.toList.mkString(",")
+
+      query.parse("SELECT " + fields + " FROM " + kind.getName + " WHERE "+ where_clause+orderby_clause+" LIMIT "+((page_size*page)+1)+", "+page_size)
       val headers = if (f.isEmpty) seqAsJavaList(List("*")) else f
 
-      val list = query.execute(records).getResults
+      val query_result: QueryResults = query.execute(records)
+      val list = query_result.getResults
 
       val rc = new DataPageDTO
       rc.page = page
       rc.page_size = page_size
 
       def total_pages(x:Int,y:Int) = if(x==0) 1 else { x/y + (if ( x%y == 0 ) 0 else 1) }
-      rc.total_pages = total_pages(records.length, rc.page_size)
-
-      rc.total_rows =  records.length
+      rc.total_pages = total_pages(query_result.getWhereResults.length, rc.page_size)
+      rc.total_rows = query_result.getWhereResults.length
       rc.headers = headers
       rc.rows = list
 
@@ -331,7 +334,7 @@ case class BrokerResource() extends Reso
   @GET @Path("virtual-hosts/{id}/topics")
   @Produces(Array("application/json"))
   def topics(@PathParam("id") id : String, @QueryParam("f") f:java.util.List[String],
-            @QueryParam("q") q:String, @QueryParam("p") p:java.lang.Integer, @QueryParam("ps") ps:java.lang.Integer ):DataPageDTO = {
+            @QueryParam("q") q:String, @QueryParam("p") p:java.lang.Integer, @QueryParam("ps") ps:java.lang.Integer, @QueryParam("o") o:java.util.List[String] ):DataPageDTO = {
     with_virtual_host(id) { host =>
       val router: LocalRouter = host
       val records = Future.all {
@@ -339,7 +342,7 @@ case class BrokerResource() extends Reso
           status(value)
         }
       }
-      val rc:FutureResult[DataPageDTO] = records.map(narrow(classOf[TopicStatusDTO], _, f, q, p, ps))
+      val rc:FutureResult[DataPageDTO] = records.map(narrow(classOf[TopicStatusDTO], _, f, q, p, ps, o))
       rc
     }
   }
@@ -356,7 +359,7 @@ case class BrokerResource() extends Reso
   @GET @Path("virtual-hosts/{id}/queues")
   @Produces(Array("application/json"))
   def queues(@PathParam("id") id : String, @QueryParam("f") f:java.util.List[String],
-            @QueryParam("q") q:String, @QueryParam("p") p:java.lang.Integer, @QueryParam("ps") ps:java.lang.Integer ):DataPageDTO = {
+            @QueryParam("q") q:String, @QueryParam("p") p:java.lang.Integer, @QueryParam("ps") ps:java.lang.Integer, @QueryParam("o") o:java.util.List[String] ):DataPageDTO = {
     with_virtual_host(id) { host =>
       val router: LocalRouter = host
       val values: Iterable[Queue] = router.queue_domain.destination_by_id.values
@@ -365,7 +368,7 @@ case class BrokerResource() extends Reso
         status(value, false)
       }
 
-      val rc:FutureResult[DataPageDTO] = records.map(narrow(classOf[QueueStatusDTO], _, f, q, p, ps))
+      val rc:FutureResult[DataPageDTO] = records.map(narrow(classOf[QueueStatusDTO], _, f, q, p, ps, o))
       rc
     }
   }
@@ -403,7 +406,7 @@ case class BrokerResource() extends Reso
   @GET @Path("virtual-hosts/{id}/dsubs")
   @Produces(Array("application/json"))
   def durable_subscriptions(@PathParam("id") id : String, @QueryParam("f") f:java.util.List[String],
-            @QueryParam("q") q:String, @QueryParam("p") p:java.lang.Integer, @QueryParam("ps") ps:java.lang.Integer ):DataPageDTO = {
+            @QueryParam("q") q:String, @QueryParam("p") p:java.lang.Integer, @QueryParam("ps") ps:java.lang.Integer, @QueryParam("o") o:java.util.List[String] ):DataPageDTO = {
     with_virtual_host(id) { host =>
       val router: LocalRouter = host
       val values: Iterable[Queue] = router.topic_domain.durable_subscriptions_by_id.values
@@ -412,7 +415,7 @@ case class BrokerResource() extends Reso
         status(value, false)
       }
 
-      val rc:FutureResult[DataPageDTO] = records.map(narrow(classOf[QueueStatusDTO], _, f, q, p, ps))
+      val rc:FutureResult[DataPageDTO] = records.map(narrow(classOf[QueueStatusDTO], _, f, q, p, ps, o))
       rc
     }
   }
@@ -553,14 +556,14 @@ case class BrokerResource() extends Reso
   @GET @Path("connectors")
   @Produces(Array("application/json"))
   def connectors(@QueryParam("f") f:java.util.List[String], @QueryParam("q") q:String,
-                  @QueryParam("p") p:java.lang.Integer, @QueryParam("ps") ps:java.lang.Integer ):DataPageDTO = {
+                  @QueryParam("p") p:java.lang.Integer, @QueryParam("ps") ps:java.lang.Integer, @QueryParam("o") o:java.util.List[String] ):DataPageDTO = {
 
     with_broker { broker =>
       monitoring(broker) {
         val records = broker.connectors.values.map { value =>
           Success(status(value))
         }
-        FutureResult(narrow(classOf[ConnectorStatusDTO], records, f, q, p, ps))
+        FutureResult(narrow(classOf[ConnectorStatusDTO], records, f, q, p, ps, o))
       }
     }
   }
@@ -623,7 +626,7 @@ case class BrokerResource() extends Reso
   @GET @Path("connections")
   @Produces(Array("application/json"))
   def connections(@QueryParam("f") f:java.util.List[String], @QueryParam("q") q:String,
-                  @QueryParam("p") p:java.lang.Integer, @QueryParam("ps") ps:java.lang.Integer ):DataPageDTO = {
+                  @QueryParam("p") p:java.lang.Integer, @QueryParam("ps") ps:java.lang.Integer, @QueryParam("o") o:java.util.List[String] ):DataPageDTO = {
 
     with_broker { broker =>
       monitoring(broker) {
@@ -632,7 +635,7 @@ case class BrokerResource() extends Reso
           value.get_connection_status
         }
 
-        val rc:FutureResult[DataPageDTO] = records.map(narrow(classOf[ConnectionStatusDTO], _, f, q, p, ps))
+        val rc:FutureResult[DataPageDTO] = records.map(narrow(classOf[ConnectionStatusDTO], _, f, q, p, ps, o))
         rc
       }
     }

Modified: activemq/activemq-apollo/trunk/apollo-website/src/documentation/management-api.md
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-website/src/documentation/management-api.md?rev=1137685&r1=1137684&r2=1137685&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-website/src/documentation/management-api.md (original)
+++ activemq/activemq-apollo/trunk/apollo-website/src/documentation/management-api.md Mon Jun 20 16:24:15 2011
@@ -146,6 +146,13 @@ records will be displayed. If you want t
 set the `p` query parameter to the page you wish to access. You can change
 the page size by setting the `ps` query parameter.
 
+The results are typically return in the order in which the records were original
+created.  If you want to retrieve them in a different order, use the `o` query
+parameter to define the order in which they are returned.  Example:
+
+    curl -u "admin:password" \
+    'http://localhost:61680/broker/connections.json?o=write_counter%20DESC&o=id'
+
 
 ### Broker Management