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/13 02:44:24 UTC
svn commit: r1058385 - in /activemq/activemq-apollo/trunk: apollo-broker/
apollo-broker/src/main/resources/META-INF/services/org.apache.activemq.apollo/
apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/
apollo-broker/src/main/scala/org/ap...
Author: chirino
Date: Thu Jan 13 01:44:24 2011
New Revision: 1058385
URL: http://svn.apache.org/viewvc?rev=1058385&view=rev
Log:
Made the web server implementation used to display the console a plugin and it's now started by the broker and instead of the run command.
Added:
activemq/activemq-apollo/trunk/apollo-broker/src/main/resources/META-INF/services/org.apache.activemq.apollo/web-server-factory.index
activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/web/
activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/web/WebServer.scala
activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/web/WebServerFactory.scala
Modified:
activemq/activemq-apollo/trunk/apollo-broker/pom.xml
activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala
activemq/activemq-apollo/trunk/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Run.scala
Modified: activemq/activemq-apollo/trunk/apollo-broker/pom.xml
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/pom.xml?rev=1058385&r1=1058384&r2=1058385&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-broker/pom.xml (original)
+++ activemq/activemq-apollo/trunk/apollo-broker/pom.xml Thu Jan 13 01:44:24 2011
@@ -79,6 +79,12 @@
<version>1.7</version>
</dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty.aggregate</groupId>
+ <artifactId>jetty-all-server</artifactId>
+ <version>${jetty-version}</version>
+ <optional>true</optional>
+ </dependency>
<!-- Scala Support -->
<dependency>
Added: activemq/activemq-apollo/trunk/apollo-broker/src/main/resources/META-INF/services/org.apache.activemq.apollo/web-server-factory.index
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/resources/META-INF/services/org.apache.activemq.apollo/web-server-factory.index?rev=1058385&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-broker/src/main/resources/META-INF/services/org.apache.activemq.apollo/web-server-factory.index (added)
+++ activemq/activemq-apollo/trunk/apollo-broker/src/main/resources/META-INF/services/org.apache.activemq.apollo/web-server-factory.index Thu Jan 13 01:44:24 2011
@@ -0,0 +1,17 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+org.apache.activemq.apollo.broker.web.JettyWebServerFactory
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=1058385&r1=1058384&r2=1058385&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 Thu Jan 13 01:44:24 2011
@@ -33,6 +33,7 @@ import collection.mutable.LinkedHashMap
import java.util.concurrent.{ThreadFactory, Executors, ConcurrentHashMap}
import security.{AclAuthorizer, Authorizer, JaasAuthenticator, Authenticator}
import java.net.InetSocketAddress
+import org.apache.activemq.apollo.broker.web._
/**
* <p>
@@ -155,6 +156,7 @@ class Broker() extends BaseService {
import Broker._
+ var tmp: File = _
var config: BrokerDTO = defaultConfig
var default_virtual_host: VirtualHost = null
@@ -176,6 +178,8 @@ class Broker() extends BaseService {
var key_storage:KeyStorage = _
+ var web_server:WebServer = _
+
override def toString() = "broker: "+id
@@ -235,25 +239,34 @@ class Broker() extends BaseService {
}
// Start up the virtual hosts
- val tracker = new LoggingTracker("broker startup", dispatch_queue)
+ val first_tracker = new LoggingTracker("broker startup", dispatch_queue)
+ val second_tracker = new LoggingTracker("broker startup", dispatch_queue)
+
+ Option(config.web_admin).foreach{ web_admin=>
+ web_server = WebServerFactory.create(this)
+ second_tracker.start(web_server)
+ }
+
virtual_hosts.valuesIterator.foreach( x=>
- tracker.start(x)
+ first_tracker.start(x)
)
// Once virtual hosts are up.. start up the connectors.
- tracker.callback(^{
- val tracker = new LoggingTracker("broker startup", dispatch_queue)
+ first_tracker.callback(^{
connectors.foreach( x=>
- tracker.start(x)
+ second_tracker.start(x)
)
- tracker.callback(on_completed)
+ second_tracker.callback(on_completed)
})
+
+
}
def _stop(on_completed:Runnable): Unit = {
val tracker = new LoggingTracker("broker shutdown", dispatch_queue)
+
// Stop accepting connections..
connectors.foreach( x=>
tracker.stop(x)
@@ -262,6 +275,10 @@ class Broker() extends BaseService {
virtual_hosts.valuesIterator.foreach( x=>
tracker.stop(x)
)
+
+ if( web_server!=null ) {
+ tracker.stop(web_server)
+ }
tracker.callback(on_completed)
}
Added: activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/web/WebServer.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/web/WebServer.scala?rev=1058385&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/web/WebServer.scala (added)
+++ activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/web/WebServer.scala Thu Jan 13 01:44:24 2011
@@ -0,0 +1,156 @@
+/**
+ * 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.
+ */
+package org.apache.activemq.apollo.broker.web
+
+import org.apache.activemq.apollo.dto.WebAdminDTO
+import org.eclipse.jetty.server.{Connector, Handler, Server}
+import org.eclipse.jetty.security._
+import org.apache.activemq.apollo.dto.{WebAdminDTO, PrincipalDTO}
+import org.apache.activemq.apollo.broker.Broker
+import authentication.BasicAuthenticator
+import org.eclipse.jetty.webapp.WebAppContext
+import org.eclipse.jetty.server.nio.SelectChannelConnector
+import org.eclipse.jetty.plus.jaas.JAASLoginService
+import org.apache.activemq.apollo.util._
+import org.fusesource.hawtdispatch._
+import java.io.File
+import java.lang.String
+
+/**
+ * <p>
+ * </p>
+ *
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
+trait WebServer extends Service
+
+object JettyWebServerFactory extends WebServerFactory.Provider {
+
+ def create(broker:Broker): WebServer = new JettyWebServer(broker)
+
+ def validate(config: WebAdminDTO, reporter: Reporter): ReporterLevel.ReporterLevel = {
+ ReporterLevel.INFO
+ }
+}
+
+object JettyWebServer extends Log
+
+class JettyWebServer(val broker:Broker) extends WebServer with BaseService {
+ import JettyWebServer._
+
+ var server:Server = _
+
+
+ override def toString: String = "jetty webserver"
+
+ protected val dispatch_queue = createQueue()
+
+ protected def _start(on_completed: Runnable) = Broker.BLOCKABLE_THREAD_POOL {
+ this.synchronized {
+ import OptionSupport._
+ import FileSupport._
+ import collection.JavaConversions._
+
+ val config = broker.config
+ val web_admin = config.web_admin
+
+ val prefix = web_admin.prefix.getOrElse("/")
+ val port = web_admin.port.getOrElse(61680)
+ val host = web_admin.host.getOrElse("127.0.0.1")
+
+ // Start up the admin interface...
+ debug("Starting administration interface");
+
+ if( broker.tmp !=null ) {
+ System.setProperty("scalate.workdir", (broker.tmp / "scalate").getCanonicalPath )
+ }
+
+ var connector = new SelectChannelConnector
+ connector.setHost(host)
+ connector.setPort(port)
+
+
+ val webapp = {
+ val x = System.getProperty("apollo.webapp")
+ if( x != null ) {
+ new File(x)
+ } else {
+ val home = system_dir("apollo.home")
+ val lib = home / "lib"
+ lib / lib.list.find( _.matches("""apollo-web-.+-slim.war""")).get
+ }
+ }
+
+ def admin_app = {
+ var app_context = new WebAppContext
+ app_context.setContextPath(prefix)
+ app_context.setWar(webapp.getCanonicalPath)
+ if( broker.tmp !=null ) {
+ app_context.setTempDirectory(broker.tmp)
+ }
+ app_context
+ }
+
+ def secured(handler:Handler) = {
+ if( config.authentication!=null && config.acl!=null ) {
+ val security_handler = new ConstraintSecurityHandler
+ val login_service = new JAASLoginService(config.authentication.domain)
+ val role_class_names:List[String] = config.authentication.acl_principal_kinds().toList
+
+ login_service.setRoleClassNames(role_class_names.toArray)
+ security_handler.setLoginService(login_service)
+ security_handler.setIdentityService(new DefaultIdentityService)
+ security_handler.setAuthenticator(new BasicAuthenticator)
+
+ val cm = new ConstraintMapping
+ val c = new org.eclipse.jetty.http.security.Constraint()
+ c.setName("BASIC")
+ val admins:Set[PrincipalDTO] = config.acl.admins.toSet
+ c.setRoles(admins.map(_.allow).toArray)
+ c.setAuthenticate(true)
+ cm.setConstraint(c)
+ cm.setPathSpec("/*")
+ cm.setMethod("GET")
+ security_handler.addConstraintMapping(cm)
+
+ security_handler.setHandler(handler)
+ security_handler
+ } else {
+ handler
+ }
+ }
+
+ server = new Server
+ server.setHandler(secured(admin_app))
+ server.setConnectors(Array[Connector](connector))
+ server.start
+
+ val localPort = connector.getLocalPort
+ def url = "http://"+host+":" + localPort + prefix
+ info("Administration interface available at: "+url)
+ on_completed.run
+ }
+ }
+
+ protected def _stop(on_completed: Runnable) = Broker.BLOCKABLE_THREAD_POOL {
+ this.synchronized {
+ server.stop
+ server = null
+ }
+ }
+
+}
\ No newline at end of file
Added: activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/web/WebServerFactory.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/web/WebServerFactory.scala?rev=1058385&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/web/WebServerFactory.scala (added)
+++ activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/web/WebServerFactory.scala Thu Jan 13 01:44:24 2011
@@ -0,0 +1,74 @@
+/**
+ * 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.
+ */
+package org.apache.activemq.apollo.broker.web
+
+import org.apache.activemq.apollo.util._
+import ReporterLevel._
+import org.apache.activemq.apollo.broker.store.Store
+import org.apache.activemq.apollo.dto.{WebAdminDTO, StoreDTO}
+import org.apache.activemq.apollo.broker.Broker
+
+/**
+ * <p>
+ * </p>
+ *
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
+object WebServerFactory {
+
+ trait Provider {
+ def create(broker:Broker):WebServer
+ def validate(config: WebAdminDTO, reporter:Reporter):ReporterLevel
+ }
+
+ def discover = {
+ val finder = new ClassFinder[Provider]("META-INF/services/org.apache.activemq.apollo/web-server-factory.index")
+ finder.new_instances
+ }
+
+ var providers = discover
+
+ def create(broker:Broker):WebServer = {
+ if( broker == null ) {
+ return null
+ }
+ providers.foreach { provider=>
+ val rc = provider.create(broker)
+ if( rc!=null ) {
+ return rc
+ }
+ }
+ throw new IllegalArgumentException("Could not find a web server implementation to use.")
+ }
+
+
+ def validate(config: WebAdminDTO, reporter:Reporter):ReporterLevel = {
+ if( config == null ) {
+ return INFO
+ } else {
+ providers.foreach { provider=>
+ val rc = provider.validate(config, reporter)
+ if( rc!=null ) {
+ return rc
+ }
+ }
+ }
+ reporter.report(ERROR, "Could not find a web server implementation to use.")
+ ERROR
+ }
+
+}
Modified: activemq/activemq-apollo/trunk/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Run.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Run.scala?rev=1058385&r1=1058384&r2=1058385&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Run.scala (original)
+++ activemq/activemq-apollo/trunk/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Run.scala Thu Jan 13 01:44:24 2011
@@ -52,6 +52,18 @@ class Run extends Action with Logging {
@option(name = "--tmp", description = "A temp directory.")
var tmp: File = _
+ def system_dir(name:String) = {
+ val base_value = System.getProperty(name)
+ if( base_value==null ) {
+ error("The the %s system property is not set.".format(name))
+ }
+ val file = new File(base_value)
+ if( !file.isDirectory ) {
+ error("The the %s system property is not set to valid directory path %s".format(name, base_value))
+ }
+ file
+ }
+
def execute(session: CommandSession):AnyRef = {
try {
@@ -73,6 +85,7 @@ class Run extends Action with Logging {
}
}
+
val webapp = {
val x = System.getProperty("apollo.webapp")
if( x != null ) {
@@ -106,78 +119,17 @@ class Run extends Action with Logging {
broker.start(^{
info("Broker started");
})
-
- config.web_admin.foreach { web_admin=>
-
- val prefix = web_admin.prefix.getOrElse("/")
- val port = web_admin.port.getOrElse(61680)
- val host = web_admin.host.getOrElse("127.0.0.1")
-
- // Start up the admin interface...
- debug("Starting administration interface");
-
- System.setProperty("scalate.workdir", (tmp / "scalate").getCanonicalPath )
-
- var connector = new SelectChannelConnector
- connector.setHost(host)
- connector.setPort(port)
-
-
- def admin_app = {
- var app_context = new WebAppContext
- app_context.setContextPath(prefix)
- app_context.setWar(webapp.getCanonicalPath)
- app_context.setTempDirectory(tmp)
- app_context
- }
-
- def secured(handler:Handler) = {
- if( config.authentication!=null && config.acl!=null ) {
- import collection.JavaConversions._
-
- val security_handler = new ConstraintSecurityHandler
- val login_service = new JAASLoginService(config.authentication.domain)
- val role_class_names:List[String] = config.authentication.acl_principal_kinds().toList
-
- login_service.setRoleClassNames(role_class_names.toArray)
- security_handler.setLoginService(login_service)
- security_handler.setIdentityService(new DefaultIdentityService)
- security_handler.setAuthenticator(new BasicAuthenticator)
-
- val cm = new ConstraintMapping
- val c = new org.eclipse.jetty.http.security.Constraint()
- c.setName("BASIC")
- val admins:Set[PrincipalDTO] = config.acl.admins.toSet
- c.setRoles(admins.map(_.allow).toArray)
- c.setAuthenticate(true)
- cm.setConstraint(c)
- cm.setPathSpec("/*")
- cm.setMethod("GET")
- security_handler.addConstraintMapping(cm)
-
- security_handler.setHandler(handler)
- security_handler
- } else {
- handler
- }
- }
-
- var server = new Server
- server.setHandler(secured(admin_app))
- server.setConnectors(Array[Connector](connector))
- server.start
-
- val localPort = connector.getLocalPort
- def url = "http://"+host+":" + localPort + prefix
- info("Administration interface available at: "+bold(url))
-
- }
-
+ broker.tmp = tmp
if(java.lang.Boolean.getBoolean("hawtdispatch.profile")) {
monitor_hawtdispatch
}
+ // wait forever... broker will system exit.
+ this.synchronized {
+ this.wait
+ }
+
} catch {
case x:Helper.Failure=>
error(x.getMessage)