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 2012/06/21 17:21:29 UTC
svn commit: r1352569 - in /activemq/activemq-apollo/trunk:
apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/
apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/
apollo-web/src/main/webapp/WEB-INF/org/apache/activemq/apollo...
Author: chirino
Date: Thu Jun 21 15:21:29 2012
New Revision: 1352569
URL: http://svn.apache.org/viewvc?rev=1352569&view=rev
Log:
Fixes APLO-212: Allow topic deletion via the REST API
Modified:
activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Topic.scala
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/TopicStatusDTO.jade
activemq/activemq-apollo/trunk/apollo-website/src/documentation/management-api.md
Modified: activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Topic.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Topic.scala?rev=1352569&r1=1352568&r2=1352569&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Topic.scala (original)
+++ activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Topic.scala Thu Jun 21 15:21:29 2012
@@ -198,12 +198,14 @@ class Topic(val router:LocalRouter, val
rc
}
+ var state = "STARTED"
+
def status(on_complete:(TopicStatusDTO)=>Unit) = {
dispatch_queue.assertExecuting()
val rc = new TopicStatusDTO
rc.id = this.id
- rc.state = "STARTED"
+ rc.state = state
rc.state_since = this.created_at
rc.config = this.config
@@ -313,6 +315,23 @@ class Topic(val router:LocalRouter, val
check_idle
}
+ def delete:Option[String] = {
+ dispatch_queue.assertExecuting()
+ state match {
+ case "STARTED" =>
+ if (producers.isEmpty && consumers.isEmpty) {
+ state = "DELETED"
+ router.local_topic_domain.remove_destination(address.path, this)
+ DestinationMetricsSupport.add_destination_metrics(router.virtual_host.dead_topic_metrics, topic_metrics)
+ None
+ } else {
+ Some("Topic is in use.")
+ }
+ case _ =>
+ Some("Topic already deleted.")
+ }
+ }
+
def check_idle {
if (producers.isEmpty && consumers.isEmpty) {
if (idled_at==0) {
@@ -321,8 +340,7 @@ class Topic(val router:LocalRouter, val
if( auto_delete_after!=0 ) {
dispatch_queue.after(auto_delete_after, TimeUnit.SECONDS) {
if( previously_idle_at == idled_at ) {
- router.local_topic_domain.remove_destination(address.path, this)
- DestinationMetricsSupport.add_destination_metrics(router.virtual_host.dead_topic_metrics, topic_metrics)
+ delete
}
}
}
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=1352569&r1=1352568&r2=1352569&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 Thu Jun 21 15:21:29 2012
@@ -533,6 +533,27 @@ class BrokerResource() extends Resource
}
}
+ @DELETE @Path("/virtual-hosts/{id}/topics/{name:.*}")
+ @Produces(Array(APPLICATION_JSON, APPLICATION_XML,TEXT_XML))
+ @ApiOperation(value = "Deletes the named topic.")
+ def topic_delete(@PathParam("id") id : String, @PathParam("name") name : String) = ok {
+ with_virtual_host(id) { host =>
+ val router: LocalRouter = host
+ val node = router.local_topic_domain.destination_by_id.get(name).getOrElse(result(NOT_FOUND))
+ admining(node) {
+ node.delete.map(result(NOT_MODIFIED, _))
+ }
+ }
+ }
+
+ @POST @Path("/virtual-hosts/{id}/topics/{name:.*}/action/delete")
+ @Produces(Array("text/html;qs=5"))
+ def post_topic_delete_and_redirect(@PathParam("id") id : String, @PathParam("name") name : String) = {
+ if_ok(topic_delete(id, name)) {
+ result(strip_resolve("../../.."))
+ }
+ }
+
@GET @Path("/virtual-hosts/{id}/topic-queues/{name:.*}/{qid}")
@ApiOperation(value = "Gets the status of a topic consumer queue.")
def topic(@PathParam("id") id : String,@PathParam("name") name : String, @PathParam("qid") qid : Long, @QueryParam("entries") entries:Boolean):QueueStatusDTO = {
@@ -595,9 +616,10 @@ class BrokerResource() extends Resource
@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) = ok {
- queue_delete(id, name)
- result(strip_resolve("../../.."))
+ def post_queue_delete_and_redirect(@PathParam("id") id : String, @PathParam("name") name : String) = {
+ if_ok(queue_delete(id, name)) {
+ result(strip_resolve("../../.."))
+ }
}
@GET @Path("/virtual-hosts/{id}/dsubs")
@@ -648,9 +670,10 @@ class BrokerResource() extends Resource
@POST @Path("/virtual-hosts/{id}/dsubs/{name:.*}/action/delete")
@Produces(Array("text/html;qs=5"))
- def post_dsub_delete_and_redirect(@PathParam("id") id : String, @PathParam("name") name : String) = ok {
- dsub_delete(id, name)
- result(strip_resolve("../../.."))
+ def post_dsub_delete_and_redirect(@PathParam("id") id : String, @PathParam("name") name : String) = {
+ if_ok(dsub_delete(id, name)) {
+ result(strip_resolve("../../.."))
+ }
}
@@ -786,9 +809,10 @@ class BrokerResource() extends Resource
@POST @Path("/connections/{id}/action/delete")
@ApiOperation(value = "Disconnect a connection from the broker.")
@Produces(Array("text/html;qs=5"))
- def post_connection_delete_and_redirect(@PathParam("id") id : Long) = ok {
- connection_delete(id)
- result(strip_resolve("../../.."))
+ def post_connection_delete_and_redirect(@PathParam("id") id : Long) = {
+ if_ok(connection_delete(id)) {
+ result(strip_resolve("../../.."))
+ }
}
@POST
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=1352569&r1=1352568&r2=1352569&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 Thu Jun 21 15:21:29 2012
@@ -90,7 +90,20 @@ abstract class Resource(parent:Resource=
def ok[T](value:FutureResult[T]):Unit = {
unwrap_future_result(value)
throw new WebApplicationException(Response.ok().build)
- }
+ }
+
+ def if_ok[T](func: =>T)(then: =>T):T = {
+ try {
+ func
+ } catch {
+ case e:WebApplicationException =>
+ if( e.getResponse.getStatus == 200 ) {
+ then
+ } else {
+ throw e;
+ }
+ }
+ }
if( parent!=null ) {
@@ -165,7 +178,7 @@ abstract class Resource(parent:Resource=
protected def monitoring[T](broker:Broker)(func: =>FutureResult[T]):FutureResult[T] = {
authorize(broker.authenticator, broker.authorizer, "monitor", broker) {
- broker.dispatch_queue.flatFuture {
+ sync(broker) {
func
}
}
@@ -173,7 +186,7 @@ abstract class Resource(parent:Resource=
protected def admining[T](broker:Broker)(func: =>FutureResult[T]):FutureResult[T] = {
authorize(broker.authenticator, broker.authorizer, "admin", broker) {
- broker.dispatch_queue.flatFuture {
+ sync(broker) {
func
}
}
@@ -181,7 +194,7 @@ abstract class Resource(parent:Resource=
protected def configing[T](broker:Broker)(func: =>FutureResult[T]):FutureResult[T] = {
authorize(broker.authenticator, broker.authorizer, "config", broker) {
- broker.dispatch_queue.flatFuture {
+ sync(broker) {
func
}
}
@@ -189,14 +202,14 @@ abstract class Resource(parent:Resource=
protected def admining[T](host:VirtualHost)(func: =>FutureResult[T]):FutureResult[T] = {
authorize(host.authenticator, host.authorizer, "admin", host) {
- host.dispatch_queue.flatFuture {
+ sync(host) {
func
}
}
}
protected def monitoring[T](host:VirtualHost)(func: =>FutureResult[T]):FutureResult[T] = {
authorize(host.authenticator, host.authorizer, "monitor", host){
- host.dispatch_queue.flatFuture {
+ sync(host) {
func
}
}
@@ -204,14 +217,14 @@ abstract class Resource(parent:Resource=
protected def admining[T](dest:Queue)(func: =>FutureResult[T]):FutureResult[T] = {
authorize(dest.virtual_host.authenticator, dest.virtual_host.authorizer, "admin", dest) {
- dest.dispatch_queue.flatFuture {
+ sync(dest) {
func
}
}
}
protected def monitoring[T](dest:Queue)(func: =>FutureResult[T]):FutureResult[T] = {
authorize(dest.virtual_host.authenticator, dest.virtual_host.authorizer, "monitor", dest){
- dest.dispatch_queue.flatFuture {
+ sync(dest) {
func
}
}
@@ -219,14 +232,14 @@ abstract class Resource(parent:Resource=
protected def admining[T](dest:Topic)(func: =>FutureResult[T]):FutureResult[T] = {
authorize(dest.virtual_host.authenticator, dest.virtual_host.authorizer,"admin", dest) {
- dest.virtual_host.dispatch_queue.flatFuture {
+ sync(dest.virtual_host) {
func
}
}
}
protected def monitoring[T](dest:Topic)(func: =>FutureResult[T]):FutureResult[T] = {
authorize(dest.virtual_host.authenticator, dest.virtual_host.authorizer, "monitor", dest) {
- dest.virtual_host.dispatch_queue.flatFuture {
+ sync(dest.virtual_host) {
func
}
}
Modified: activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/org/apache/activemq/apollo/dto/TopicStatusDTO.jade
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/org/apache/activemq/apollo/dto/TopicStatusDTO.jade?rev=1352569&r1=1352568&r2=1352569&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/org/apache/activemq/apollo/dto/TopicStatusDTO.jade (original)
+++ activemq/activemq-apollo/trunk/apollo-web/src/main/webapp/WEB-INF/org/apache/activemq/apollo/dto/TopicStatusDTO.jade Thu Jun 21 15:21:29 2012
@@ -23,6 +23,10 @@
h1 Topic: #{id}
p state: #{state} #{ uptime(state_since) } ago
+- if( state == "STARTED" )
+ form(method="post" action={path("action/delete")})
+ input(type="submit" value="delete")
+
h3 Topic Domain
h4 Enqueue/Deqeueue Counters
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=1352569&r1=1352568&r2=1352569&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 Thu Jun 21 15:21:29 2012
@@ -46,6 +46,7 @@ succeeded or failed. Expect the followi
* *`200`*: If a GET, PUT, or DELETE request succeeds.
* *`303`*: If a POST request succeeds.
+* *`304`*: If the resource cannot be modified at the current time.
* *`400`*: The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.
* *`404`*: If the resource cannot be found.
* *`401`*: If the user does not have access to the resource.
@@ -615,6 +616,11 @@ parameter to define the order in which t
}
{pygmentize}
+ - route("DELETE", "/broker/virtual-hosts/{host}/topics/{dest}.json", 200)
+ :markdown
+ Deletes the `{dest}` topic on the `{host}` virtual host. Returns a 304 (Not Modified) if the
+ topic is being used by any clients.
+
- 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