Author: chirino
Date: Tue Nov 27 17:46:06 2012
New Revision: 1414283
URL: http://svn.apache.org/viewvc?rev=1414283&view=rev
Log:
Fixes APLO-272: Support creating topics and queues via the REST management api.
Modified:
activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/WebModule.scala
activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/BrokerResource.scala
activemq/activemq-apollo/trunk/apollo-website/src/documentation/management-api.md
Modified:
activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/WebModule.scala
URL:
http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/WebModule.scala?rev=1414283&r1=1414282&r2=1414283&view=diff
==============================================================================
---
activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/WebModule.scala
(original)
+++
activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/WebModule.scala
Tue Nov 27 17:46:06 2012
@@ -41,7 +41,7 @@ object WebModule {
val (root_redirect, web_resources) = {
// sort by priority. Highest priority wins.
- val sorted = TreeMap(finder.singletons.map(x=> x.priority -> x): _*).values
+ val sorted = finder.singletons.sortBy( _.priority )
val web_resources = LinkedHashMap[Class[_], Class[_]]()
for( provider <- sorted; resource <- provider.web_resources ) {
web_resources.put(resource,resource)
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=1414283&r1=1414282&r2=1414283&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 Nov 27 17:46:06 2012
@@ -22,7 +22,7 @@ import scala.collection.Iterable
import org.apache.activemq.apollo.util.path.PathParser
import org.apache.activemq.apollo.util._
import javax.ws.rs._
-import core.Context
+import core.{Response, Context}
import javax.ws.rs.core.Response.Status._
import management.ManagementFactory
import javax.management.ObjectName
@@ -36,6 +36,7 @@ import javax.ws.rs.core.MediaType._
import com.wordnik.swagger.core._
import javax.servlet.http.HttpServletResponse
import FutureResult._
+import java.security.Principal
@Path( "/api/json/broker")
@Api(value = "/api/json/broker",
@@ -528,6 +529,24 @@ class BrokerResource() extends Resource
}
}
+ @PUT @Path("/virtual-hosts/{id}/topics/{name:.*}")
+ @Produces(Array(APPLICATION_JSON, APPLICATION_XML,TEXT_XML))
+ @ApiOperation(value = "Creates the named topic.")
+ def topic_create(@PathParam("id") id : String, @PathParam("name") name :
String) = ok {
+ with_virtual_host(id) { host =>
+ val rc = FutureResult[Null]()
+ authenticate(host.broker.authenticator) { security_context =>
+ val address = (new
DestinationParser).decode_single_destination("topic:"+name, null)
+ host.local_topic_domain.get_or_create_destination(address,
security_context).failure_option match {
+ case Some(x) => rc.set(Failure(new Exception(x)))
+ case _ =>
+ }
+ rc.set(Success(null))
+ }
+ rc
+ }
+ }
+
@DELETE @Path("/virtual-hosts/{id}/topics/{name:.*}")
@Produces(Array(APPLICATION_JSON, APPLICATION_XML,TEXT_XML))
@ApiOperation(value = "Deletes the named topic.")
@@ -615,6 +634,24 @@ class BrokerResource() extends Resource
}
}
+ @PUT @Path("/virtual-hosts/{id}/queues/{name:.*}")
+ @Produces(Array(APPLICATION_JSON, APPLICATION_XML,TEXT_XML))
+ @ApiOperation(value = "Creates the named queue.")
+ def queue_create(@PathParam("id") id : String, @PathParam("name") name :
String) = ok {
+ with_virtual_host(id) { host =>
+ val rc = FutureResult[Null]()
+ authenticate(host.broker.authenticator) { security_context =>
+ val address = (new
DestinationParser).decode_single_destination("queue:"+name, null)
+ host.local_queue_domain.get_or_create_destination(address,
security_context).failure_option match {
+ case Some(x) => rc.set(Failure(new Exception(x)))
+ case _ =>
+ }
+ rc.set(Success(null))
+ }
+ rc
+ }
+ }
+
@POST @Path("/virtual-hosts/{id}/queues/{name:.*}/action/delete")
@Produces(Array("text/html;qs=5"))
def post_queue_delete_and_redirect(@PathParam("id") id : String,
@PathParam("name") name : String) = {
Modified:
activemq/activemq-apollo/trunk/apollo-website/src/documentation/management-api.md
URL:
http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-website/src/documentation/management-api.md?rev=1414283&r1=1414282&r2=1414283&view=diff
==============================================================================
---
activemq/activemq-apollo/trunk/apollo-website/src/documentation/management-api.md
(original)
+++
activemq/activemq-apollo/trunk/apollo-website/src/documentation/management-api.md
Tue Nov 27 17:46:06 2012
@@ -548,6 +548,10 @@ parameter to define the order in which t
:markdown
Deletes the `{dest}` queue on the `{host}` virtual host.
+ - route("PUT", "/broker/virtual-hosts/{host}/queues/{dest}.json", 200)
+ :markdown
+ Creates the `{dest}` queue on the `{host}` virtual host.
+
- route("GET", "/broker/virtual-hosts/{host}/topics.json", 200,
"DataPageDTO", null, "TopicStatusDTO")
:markdown
Provides tabular access to all topic destinations on the `{host}`
virtual host.
@@ -633,6 +637,10 @@ parameter to define the order in which t
Deletes the `{dest}` topic on the `{host}` virtual host. Returns a 304
(Not Modified) if the
topic is being used by any clients.
+ - route("PUT", "/broker/virtual-hosts/{host}/topics/{dest}.json", 200)
+ :markdown
+ Creates the `{dest}` topic on the `{host}` virtual host.
+
- route("GET",
"/broker/virtual-hosts/{host}/topic-queues/{dest}/{queue}.json", 200,
"QueueStatusDTO")
:markdown
Gets metrics and details about `{queue}` consumer queue which is being
used to