activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r1050172 - in /activemq/activemq-apollo/trunk: apollo-cli/src/main/resources/META-INF/services/org.apache.activemq.apollo/ apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/ apollo-web/src/main/scala/org/apache/activemq/apol...
Date Thu, 16 Dec 2010 21:33:09 GMT
Author: chirino
Date: Thu Dec 16 21:33:09 2010
New Revision: 1050172

URL: http://svn.apache.org/viewvc?rev=1050172&view=rev
Log:
Implemented a stop command to shutdown a running broker.

Added:
    activemq/activemq-apollo/trunk/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Stop.scala
Modified:
    activemq/activemq-apollo/trunk/apollo-cli/src/main/resources/META-INF/services/org.apache.activemq.apollo/commands.index
    activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/RootResource.scala

Modified: activemq/activemq-apollo/trunk/apollo-cli/src/main/resources/META-INF/services/org.apache.activemq.apollo/commands.index
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-cli/src/main/resources/META-INF/services/org.apache.activemq.apollo/commands.index?rev=1050172&r1=1050171&r2=1050172&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-cli/src/main/resources/META-INF/services/org.apache.activemq.apollo/commands.index
(original)
+++ activemq/activemq-apollo/trunk/apollo-cli/src/main/resources/META-INF/services/org.apache.activemq.apollo/commands.index
Thu Dec 16 21:33:09 2010
@@ -18,5 +18,5 @@ org.apache.activemq.apollo.cli.commands.
 org.apache.activemq.apollo.cli.commands.Help
 org.apache.activemq.apollo.cli.commands.Create
 #org.apache.activemq.apollo.cli.commands.Start
-#org.apache.activemq.apollo.cli.commands.Stop
+org.apache.activemq.apollo.cli.commands.Stop
 org.apache.activemq.apollo.cli.commands.Run

Added: 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=1050172&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Stop.scala
(added)
+++ activemq/activemq-apollo/trunk/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Stop.scala
Thu Dec 16 21:33:09 2010
@@ -0,0 +1,96 @@
+package org.apache.activemq.apollo.cli.commands
+
+/**
+ * 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.
+ */
+import org.apache.felix.gogo.commands.{Action, Option => option, Argument => argument,
Command => command}
+import org.osgi.service.command.CommandSession
+import java.io.File
+import org.apache.activemq.apollo.broker.FileConfigStore
+import org.apache.activemq.apollo.util.FileSupport._
+import org.apache.activemq.apollo.util.OptionSupport._
+import org.apache.activemq.apollo.util.Logging
+import org.apache.activemq.apollo.dto.WebAdminDTO
+import org.apache.commons.codec.binary.Base64
+import java.net.{HttpURLConnection, URL}
+
+/**
+ * The apollo stop command
+ */
+@command(scope="apollo", name = "stop", description = "stops the broker instance")
+class Stop extends Action with Logging {
+
+  @option(name = "--conf", description = "The Apollo configuration file.")
+  var conf: File = _
+
+  @option(name = "--user", description = "The user id")
+  var user: String = _
+
+  @option(name = "--password", description = "The user password")
+  var password: String = _
+
+  def execute(session: CommandSession):AnyRef = {
+
+    try {
+
+      val base = system_dir("apollo.base")
+
+      if( conf == null ) {
+        conf = base / "etc" / "apollo.xml"
+      }
+
+      if( !conf.exists ) {
+        error("Configuration file'%s' does not exist.\n\nTry creating a broker instance using
the 'apollo create' command.".format(conf));
+      }
+
+      val store = new FileConfigStore
+      store.file = conf
+      store.start
+      val config = store.load(true)
+
+
+      val web_admin = config.web_admin.getOrElse(new WebAdminDTO)
+      if( web_admin.enabled.getOrElse(true) ) {
+
+        val prefix = web_admin.prefix.getOrElse("/").stripSuffix("/")
+        val port = web_admin.port.getOrElse(8080)
+        val host = web_admin.host.getOrElse("127.0.0.1")
+
+        val auth = (user, password) match {
+          case (null,null)=> None
+          case (null,p)=> Some(":"+p)
+          case (u,null)=> Some(u+":")
+          case (u,p)=> Some(u+":"+p)
+        }
+
+        val connection = new URL(
+          "http://%s:%s%s/command/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")) }
+        connection.getContent
+
+      }
+
+    } catch {
+      case x:Helper.Failure=>
+        error(x.getMessage)
+    }
+    null
+  }
+
+
+}
\ No newline at end of file

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=1050172&r1=1050171&r2=1050172&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
Thu Dec 16 21:33:09 2010
@@ -24,8 +24,6 @@ import reflect.{BeanProperty}
 import com.sun.jersey.api.view.ImplicitProduces
 import Response._
 import Response.Status._
-import org.apache.activemq.apollo.broker.ConfigStore
-import org.apache.activemq.apollo.broker.BrokerRegistry
 import collection.JavaConversions._
 import com.sun.jersey.api.core.ResourceContext
 import java.util.concurrent.TimeUnit
@@ -35,6 +33,7 @@ import org.apache.activemq.apollo.util.L
 import org.fusesource.hawtdispatch._
 import java.net.URI
 import org.fusesource.scalate.{NoValueSetException, RenderContext}
+import org.apache.activemq.apollo.broker.{Broker, ConfigStore, BrokerRegistry}
 
 /**
  * Defines the default representations to be used on resources
@@ -156,6 +155,19 @@ 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)
 



Mime
View raw message