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/08/23 19:10:04 UTC
svn commit: r1160807 - in /activemq/activemq-apollo/trunk:
apollo-dto/src/main/java/org/apache/activemq/apollo/dto/
apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/
Author: chirino
Date: Tue Aug 23 17:10:03 2011
New Revision: 1160807
URL: http://svn.apache.org/viewvc?rev=1160807&view=rev
Log:
- Expose the current time in the queue-metrics
- Add topic, queue, dsub count fields in the virtual_host_status so that the aggregate count can more easily be obtained via the tabular management interface.
- The virtual host collection is now exposed as a tabular view too.
- The tabular view now can display fields which only exist in subclasses of the objects.
Modified:
activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/QueueMetricsDTO.java
activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/VirtualHostStatusDTO.java
activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/BrokerResource.scala
Modified: activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/QueueMetricsDTO.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/QueueMetricsDTO.java?rev=1160807&r1=1160806&r2=1160807&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/QueueMetricsDTO.java (original)
+++ activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/QueueMetricsDTO.java Tue Aug 23 17:10:03 2011
@@ -42,6 +42,12 @@ import javax.xml.bind.annotation.XmlRoot
public class QueueMetricsDTO {
/**
+ * The current time on the broker machine. In milliseconds since the epoch.
+ */
+ @XmlAttribute(name="current_time")
+ public long current_time;
+
+ /**
* The number of messages that have been added to the queue.
* This includes any messages which were recovered from
* persistent storage when the broker was first started.
Modified: activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/VirtualHostStatusDTO.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/VirtualHostStatusDTO.java?rev=1160807&r1=1160806&r2=1160807&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/VirtualHostStatusDTO.java (original)
+++ activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/VirtualHostStatusDTO.java Tue Aug 23 17:10:03 2011
@@ -33,27 +33,50 @@ import java.util.List;
public class VirtualHostStatusDTO extends ServiceStatusDTO {
/**
- * Ids of all the topics that exist on the broker
+ * Ids of all the topics that exist on the virtual host
*/
@XmlElement(name="topic")
public List<String> topics = new ArrayList<String>();
/**
+ * The number of topics that exist on the virtual host
+ */
+ @XmlAttribute(name="topic_count")
+ public int topic_count;
+
+ /**
* Ids of all the queues that exist on the broker
*/
@XmlElement(name="queue")
public List<String> queues = new ArrayList<String>();
/**
+ * The number of queues that exist on the virtual host
+ */
+ @XmlAttribute(name="topic_count")
+ public int queue_count;
+
+ /**
* Ids of all the durable subscriptions that exist on the broker
*/
@XmlElement(name="dsub")
public List<String> dsubs = new ArrayList<String>();
/**
+ * The number of durable subscriptions that exist on the virtual host
+ */
+ @XmlAttribute(name="dsub_count")
+ public int dsub_count;
+
+ /**
* Is the virtual host using a store.
*/
- @XmlElement(name="store")
+ @XmlAttribute(name="store")
public boolean store;
+ /**
+ * The host names route you to the the virtual host.
+ */
+ @XmlElement(name="host_names")
+ public List<String> host_names = new ArrayList<String>();
}
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=1160807&r1=1160806&r2=1160807&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 Tue Aug 23 17:10:03 2011
@@ -154,17 +154,12 @@ case class BrokerResource() extends Reso
@GET
@Path("queue-metrics")
def get_queue_metrics(): AggregateQueueMetricsDTO = {
- with_broker { broker =>
+ val rc:AggregateQueueMetricsDTO = with_broker { broker =>
monitoring(broker) {
get_queue_metrics(broker)
}
}
- }
-
- @GET @Path("virtual-hosts")
- def virtualHosts = {
- val rc = new StringListDTO
- rc.items = get_broker.virtual_hosts
+ rc.current_time = System.currentTimeMillis()
rc
}
@@ -230,40 +225,65 @@ case class BrokerResource() extends Reso
}
+ @GET @Path("virtual-hosts")
+ @Produces(Array("application/json"))
+ def virtual_host(@QueryParam("f") f:java.util.List[String], @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_broker { broker =>
+ monitoring(broker) {
+ val records = broker.virtual_hosts.values.map { value =>
+ Success(status(value))
+ }
+ FutureResult(narrow(classOf[VirtualHostStatusDTO], records, f, q, p, ps, o))
+ }
+ }
+ }
+
@GET @Path("virtual-hosts/{id}")
def virtual_host(@PathParam("id") id : String):VirtualHostStatusDTO = {
with_virtual_host(id) { host =>
monitoring(host) {
- val result = new VirtualHostStatusDTO
- result.id = host.id
- result.state = host.service_state.toString
- result.state_since = host.service_state.since
- result.store = host.store!=null
+ status(host)
+ }
+ }
+ }
- val router:LocalRouter = host
+ def status(host: VirtualHost): VirtualHostStatusDTO = {
+ val result = new VirtualHostStatusDTO
+ result.id = host.id
+ result.state = host.service_state.toString
+ result.state_since = host.service_state.since
+ result.store = host.store != null
+ result.host_names = host.config.host_names
- router.queue_domain.destinations.foreach { node=>
- result.queues.add(node.id)
- }
- router.topic_domain.destinations.foreach { node=>
- result.topics.add(node.id)
- }
- router.topic_domain.durable_subscriptions_by_id.keys.foreach { id=>
- result.dsubs.add(id)
- }
+ val router: LocalRouter = host
- result
- }
+ router.queue_domain.destinations.foreach { node =>
+ result.queues.add(node.id)
}
+ result.queue_count = result.queues.size()
+ router.topic_domain.destinations.foreach { node =>
+ result.topics.add(node.id)
+ }
+ result.topic_count = result.topics.size()
+ router.topic_domain.durable_subscriptions_by_id.keys.foreach { id =>
+ result.dsubs.add(id)
+ }
+ result.dsub_count = result.dsubs.size()
+
+ result
}
@GET @Path("virtual-hosts/{id}/queue-metrics")
def virtual_host_queue_metrics(@PathParam("id") id : String): AggregateQueueMetricsDTO = {
- with_virtual_host(id) { host =>
+ val rc:AggregateQueueMetricsDTO = with_virtual_host(id) { host =>
monitoring(host) {
get_queue_metrics(host)
}
}
+ rc.current_time = System.currentTimeMillis()
+ rc
}
@GET @Path("virtual-hosts/{id}/store")
@@ -299,6 +319,18 @@ case class BrokerResource() extends Reso
link
}
+ class JosqlHelper {
+ def get(o:AnyRef, name:String):AnyRef = {
+ try {
+ o.getClass().getField(name).get(o)
+ } catch {
+ case e:Throwable =>
+ e.printStackTrace()
+ null
+ }
+ }
+ }
+
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 {
@@ -308,7 +340,8 @@ case class BrokerResource() extends Reso
val page = if( p !=null ) p.intValue() else 0
val query = new Query
- val fields = if (f.isEmpty) "*" else f.toList.mkString(",")
+ query.addFunctionHandler(new JosqlHelper)
+ val fields = if (f.isEmpty) "*" else f.toList.map("get(:_currobj, \""+_+"\")").mkString(",")
val where_clause = if (q != null) q else "1=1"
val orderby_clause = if (o.isEmpty) "" else " ORDER BY "+o.toList.mkString(",")
@@ -323,6 +356,8 @@ case class BrokerResource() extends Reso
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(query_result.getWhereResults.length, rc.page_size)
rc.total_rows = query_result.getWhereResults.length
@@ -506,6 +541,7 @@ case class BrokerResource() extends Reso
rc.binding = q.binding.binding_dto
rc.config = q.config
rc.metrics = get_queue_metrics(q)
+ rc.metrics.current_time = System.currentTimeMillis()
if( entries ) {
var cur = q.head_entry