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/05/31 18:38:18 UTC
svn commit: r1129791 - in
/activemq/activemq-apollo/trunk/apollo-web/src/main:
scala/org/apache/activemq/apollo/web/resources/
webapp/WEB-INF/org/apache/activemq/apollo/dto/
Author: chirino
Date: Tue May 31 16:38:18 2011
New Revision: 1129791
URL: http://svn.apache.org/viewvc?rev=1129791&view=rev
Log:
Fixes https://issues.apache.org/jira/browse/APLO-32 : Support Connector start/stop actions in the management interface
Modified:
activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/BrokerResource.scala
activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/Support.scala
activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/org/apache/activemq/apollo/dto/ConnectorStatusDTO.jade
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=1129791&r1=1129790&r2=1129791&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 May 31 16:38:18 2011
@@ -420,33 +420,73 @@ case class BrokerResource() extends Reso
@GET @Path("connectors")
- def connectors = {
- val rc = new StringListDTO
- rc.items = get_broker.connectors
- rc
+ @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 ):java.util.List[_] = {
+
+ with_broker { broker =>
+ monitoring(broker) {
+ val records = broker.connectors.map { value =>
+ Success(status(value))
+ }
+ FutureResult(narrow(classOf[ConnectorStatusDTO], records, f, q, p, ps))
+ }
+ }
}
@GET @Path("connectors/{id}")
def connector(@PathParam("id") id : String):ConnectorStatusDTO = {
- with_broker { broker =>
- monitoring(broker) {
- broker.connectors.find(_.id == id) match {
- case None=> result(NOT_FOUND)
- case Some(connector)=>
-
- val result = new ConnectorStatusDTO
- result.id = connector.id.toString
- result.state = connector.service_state.toString
- result.state_since = connector.service_state.since
- result.accepted = connector.accepted.get
- result.connected = connector.connected.get
+ with_connector(id) { connector =>
+ monitoring(connector.broker) {
+ status(connector)
+ }
+ }
+ }
- result
- }
+ def status(connector: Connector): ConnectorStatusDTO = {
+ val result = new ConnectorStatusDTO
+ result.id = connector.id.toString
+ result.state = connector.service_state.toString
+ result.state_since = connector.service_state.since
+ result.accepted = connector.accepted.get
+ result.connected = connector.connected.get
+ result
+ }
+
+ @POST @Path("connectors/{id}/action/stop")
+ @Produces(Array("application/json", "application/xml","text/xml"))
+ def post_connector_stop(@PathParam("id") id : String):Unit = {
+ with_connector(id) { connector =>
+ admining(connector.broker) {
+ connector.stop
+ }
+ }
+ }
+
+ @POST @Path("connectors/{id}/action/stop")
+ @Produces(Array("text/html;qs=5"))
+ def post_connector_stop_and_redirect(@PathParam("id") id : String):Unit = {
+ post_connector_stop(id)
+ result(strip_resolve(".."))
+ }
+
+ @POST @Path("connectors/{id}/action/start")
+ @Produces(Array("application/json", "application/xml","text/xml"))
+ def post_connector_start(@PathParam("id") id : String):Unit = {
+ with_connector(id) { connector =>
+ admining(connector.broker) {
+ connector.start
}
}
}
+ @POST @Path("connectors/{id}/action/start")
+ @Produces(Array("text/html;qs=5"))
+ def post_connector_start_and_redirect(@PathParam("id") id : String):Unit = {
+ post_connector_start(id)
+ result(strip_resolve(".."))
+ }
+
@GET @Path("connections")
@Produces(Array("application/json"))
def connections(@QueryParam("f") f:java.util.List[String], @QueryParam("q") q:String,
Modified: activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/Support.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/Support.scala?rev=1129791&r1=1129790&r2=1129791&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/Support.scala (original)
+++ activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/Support.scala Tue May 31 16:38:18 2011
@@ -232,6 +232,12 @@ abstract class Resource(parent:Resource=
protected def FutureResult[T]() = Future[Result[T, Throwable]]()
+ protected def FutureResult[T](value:Result[T, Throwable]) = {
+ val rc = Future[Result[T, Throwable]]()
+ rc.set(value)
+ rc
+ }
+
protected def sync[T](dispached:Dispatched)(func: =>FutureResult[T]):FutureResult[T] = {
val rc = Future[Result[T, Throwable]]()
dispached.dispatch_queue.apply {
@@ -283,6 +289,16 @@ abstract class Resource(parent:Resource=
}
}
+ protected def with_connector[T](id:String)(func: (org.apache.activemq.apollo.broker.Connector)=>FutureResult[T]):FutureResult[T] = {
+ with_broker { broker =>
+ broker.connectors.find(_.id == id) match {
+ case Some(connector)=>
+ func(connector)
+ case None=> result(NOT_FOUND)
+ }
+ }
+ }
+
protected def with_virtual_host[T](id:String)(func: (VirtualHost)=>FutureResult[T]):FutureResult[T] = {
with_broker { broker =>
broker.virtual_hosts.valuesIterator.find( _.id == id) match {
Modified: activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/org/apache/activemq/apollo/dto/ConnectorStatusDTO.jade
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/org/apache/activemq/apollo/dto/ConnectorStatusDTO.jade?rev=1129791&r1=1129790&r2=1129791&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/org/apache/activemq/apollo/dto/ConnectorStatusDTO.jade (original)
+++ activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/org/apache/activemq/apollo/dto/ConnectorStatusDTO.jade Tue May 31 16:38:18 2011
@@ -22,6 +22,13 @@ h1 Connector: #{id}
p state: #{state} #{ uptime(state_since) } ago
+- if( state == "STARTED" )
+ form(method="post" action={path("action/stop")})
+ input(type="submit" value="stop")
+- else if( state == "STOPPED" )
+ form(method="post" action={path("action/start")})
+ input(type="submit" value="start")
+
p total accepted: #{accepted}
p currently connected: #{connected}