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/01/04 03:24:31 UTC

svn commit: r1054865 - in /activemq/activemq-apollo/trunk: apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/ apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/ apollo-web/src/main/webapp/WEB-INF/org/apache/activemq/apo...

Author: chirino
Date: Tue Jan  4 02:24:30 2011
New Revision: 1054865

URL: http://svn.apache.org/viewvc?rev=1054865&view=rev
Log:
add rest action to support shutting down connections. changed broker shutdown url to be consistent /w it.

Modified:
    activemq/activemq-apollo/trunk/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Stop.scala
    activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/RootResource.scala
    activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/RuntimeResource.scala
    activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/org/apache/activemq/apollo/dto/BrokerStatusDTO.jade
    activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/org/apache/activemq/apollo/dto/ConnectionStatusDTO.jade
    activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/org/apache/activemq/apollo/dto/StompConnectionStatusDTO.jade

Modified: activemq/activemq-apollo/trunk/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Stop.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Stop.scala?rev=1054865&r1=1054864&r2=1054865&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Stop.scala (original)
+++ activemq/activemq-apollo/trunk/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Stop.scala Tue Jan  4 02:24:30 2011
@@ -73,7 +73,7 @@ class Stop extends Action with Logging {
         }
 
         val connection = new URL(
-          "http://%s:%s%s/command/shutdown".format(host, port, prefix)
+          "http://%s:%s%s/runtime/action/shutdown".format(host, port, prefix)
         ).openConnection.asInstanceOf[HttpURLConnection]
         connection.setRequestMethod("POST");
         auth.foreach{x=> connection.setRequestProperty("Authorization", "Basic "+new String(Base64.encodeBase64(x.getBytes("UTF-8")), "UTF-8")) }

Modified: activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/RootResource.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/RootResource.scala?rev=1054865&r1=1054864&r2=1054865&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/RootResource.scala (original)
+++ activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/RootResource.scala Tue Jan  4 02:24:30 2011
@@ -63,6 +63,10 @@ abstract class Resource(private val pare
 
   def path(value:Any) = uri_info.getAbsolutePathBuilder().path(value.toString).build()
 
+  def strip_resolve(value:String) = {
+    new URI(uri_info.getAbsolutePath.resolve(value).toString.stripSuffix("/"))
+  }
+
 }
 
 object ViewHelper {
@@ -156,19 +160,6 @@ class BrokerResource extends Resource {
     rc
   }
 
-  @POST
-  @Path("command/shutdown")
-  def command_shutdown:Unit = {
-    info("JVM shutdown requested via web interface")
-
-    // do the the exit async so that we don't
-    // kill the current request.
-    Broker.BLOCKABLE_THREAD_POOL {
-      Thread.sleep(200);
-      System.exit(0)
-    }
-  }
-
   @Path("config")
   def config_resource = ConfigurationResource(this)
 

Modified: activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/RuntimeResource.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/RuntimeResource.scala?rev=1054865&r1=1054864&r2=1054865&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/RuntimeResource.scala (original)
+++ activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/RuntimeResource.scala Tue Jan  4 02:24:30 2011
@@ -39,6 +39,18 @@ import scala.util.continuations._
 @Produces(Array("application/json", "application/xml","text/xml", "text/html;qs=5"))
 case class RuntimeResource(parent:BrokerResource) extends Resource(parent) {
 
+  @POST
+  @Path("action/shutdown")
+  def command_shutdown:Unit = {
+    info("JVM shutdown requested via web interface")
+
+    // do the the exit async so that we don't
+    // kill the current request.
+    Broker.BLOCKABLE_THREAD_POOL {
+      Thread.sleep(200);
+      System.exit(0)
+    }
+  }
   private def with_broker[T](func: (org.apache.activemq.apollo.broker.Broker, Option[T]=>Unit)=>Unit):T = {
     BrokerRegistry.list.headOption match {
       case None=> result(NOT_FOUND)
@@ -329,17 +341,39 @@ case class RuntimeResource(parent:Broker
     }
   }
 
-  @GET @Path("connections/{id}")
-  def connections(@PathParam("id") id : Long):ConnectionStatusDTO = {
+  def with_connection[T](id:Long)(func: BrokerConnection=>T):T = {
     with_broker { case (broker, cb) =>
       broker.connectors.flatMap{ _.connections.get(id) }.headOption match {
         case None => cb(None)
         case Some(connection:BrokerConnection) =>
           connection.dispatch_queue {
-            cb(Some(connection.get_connection_status))
+            cb(Some(func(connection)))
           }
       }
     }
   }
 
+  @GET @Path("connections/{id}")
+  def connections(@PathParam("id") id : Long):ConnectionStatusDTO = {
+    with_connection(id){ connection=>
+      connection.get_connection_status
+    }
+  }
+
+  @POST @Path("connections/{id}/action/shutdown")
+  @Produces(Array("application/json", "application/xml","text/xml"))
+  def post_connection_shutdown(@PathParam("id") id : Long):Unit = {
+    with_connection(id){ connection=>
+      connection.stop
+    }
+  }
+
+
+  @POST @Path("connections/{id}/action/shutdown")
+  @Produces(Array("text/html;qs=5"))
+  def post_connection_shutdown_and_redirect(@PathParam("id") id : Long):Unit = {
+    post_connection_shutdown(id)
+    result(strip_resolve("../../.."))
+  }
+
 }

Modified: activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/org/apache/activemq/apollo/dto/BrokerStatusDTO.jade
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/org/apache/activemq/apollo/dto/BrokerStatusDTO.jade?rev=1054865&r1=1054864&r2=1054865&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/org/apache/activemq/apollo/dto/BrokerStatusDTO.jade (original)
+++ activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/org/apache/activemq/apollo/dto/BrokerStatusDTO.jade Tue Jan  4 02:24:30 2011
@@ -23,6 +23,10 @@
 
 p state: #{state} #{ uptime(state_since) } ago
 
+- if( state == "STARTED" )
+  form(method="post" action={path("action/shutdown")})
+    input(type="submit" value="shutdown")
+
 h2 Virtual Hosts
 ul
   - for( x <- virtual_hosts )

Modified: activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/org/apache/activemq/apollo/dto/ConnectionStatusDTO.jade
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/org/apache/activemq/apollo/dto/ConnectionStatusDTO.jade?rev=1054865&r1=1054864&r2=1054865&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/org/apache/activemq/apollo/dto/ConnectionStatusDTO.jade (original)
+++ activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/org/apache/activemq/apollo/dto/ConnectionStatusDTO.jade Tue Jan  4 02:24:30 2011
@@ -20,6 +20,9 @@
 .breadcumbs
   a(href={strip_resolve(".")}) Back
 p state: #{state} #{ uptime(state_since) } ago
+- if( state == "STARTED" )
+  form(method="post" action={path("action/shutdown")})
+    input(type="submit" value="shutdown")
 
 p remote address: #{remote_address}
 p protocol: #{protocol}

Modified: activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/org/apache/activemq/apollo/dto/StompConnectionStatusDTO.jade
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/org/apache/activemq/apollo/dto/StompConnectionStatusDTO.jade?rev=1054865&r1=1054864&r2=1054865&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/org/apache/activemq/apollo/dto/StompConnectionStatusDTO.jade (original)
+++ activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/org/apache/activemq/apollo/dto/StompConnectionStatusDTO.jade Tue Jan  4 02:24:30 2011
@@ -21,6 +21,10 @@
   a(href={strip_resolve(".")}) Back
 p state: #{state} #{ uptime(state_since) } ago
 
+- if( state == "STARTED" )
+  form(method="post" action={path("action/shutdown")})
+    input(type="submit" value="shutdown")
+
 p remote address: #{remote_address}
 p protocol: #{protocol}
 p transport: #{transport}