camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject camel git commit: CAMEL-9285 - controlbus - Allow to grab current route id so you can control current route easier
Date Thu, 25 Feb 2016 12:13:27 GMT
Repository: camel
Updated Branches:
  refs/heads/master c69f3edf6 -> d0b49ac70


CAMEL-9285 - controlbus - Allow to grab current route id so you can control current route
easier


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/d0b49ac7
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d0b49ac7
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d0b49ac7

Branch: refs/heads/master
Commit: d0b49ac707c797f9b4a89c39f4e88e04974c4796
Parents: c69f3ed
Author: lburgazzoli <lburgazzoli@gmail.com>
Authored: Thu Feb 25 10:14:51 2016 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Thu Feb 25 13:13:19 2016 +0100

----------------------------------------------------------------------
 .../component/controlbus/ControlBusEndpoint.java |  1 +
 .../component/controlbus/ControlBusProducer.java |  7 +++++++
 .../controlbus/ControlBusStartRouteTest.java     | 17 +++++++++++++++++
 .../controlbus/ControlBusStatsTest.java          | 19 ++++++++++++++++++-
 4 files changed, 43 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/d0b49ac7/camel-core/src/main/java/org/apache/camel/component/controlbus/ControlBusEndpoint.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/controlbus/ControlBusEndpoint.java
b/camel-core/src/main/java/org/apache/camel/component/controlbus/ControlBusEndpoint.java
index 4bdff83..57c21dc 100644
--- a/camel-core/src/main/java/org/apache/camel/component/controlbus/ControlBusEndpoint.java
+++ b/camel-core/src/main/java/org/apache/camel/component/controlbus/ControlBusEndpoint.java
@@ -95,6 +95,7 @@ public class ControlBusEndpoint extends DefaultEndpoint {
 
     /**
      * To specify a route by its id.
+     * The special keyword "current" indicates the current route.
      */
     public void setRouteId(String routeId) {
         this.routeId = routeId;

http://git-wip-us.apache.org/repos/asf/camel/blob/d0b49ac7/camel-core/src/main/java/org/apache/camel/component/controlbus/ControlBusProducer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/controlbus/ControlBusProducer.java
b/camel-core/src/main/java/org/apache/camel/component/controlbus/ControlBusProducer.java
index 95cadef..f2d1574 100644
--- a/camel-core/src/main/java/org/apache/camel/component/controlbus/ControlBusProducer.java
+++ b/camel-core/src/main/java/org/apache/camel/component/controlbus/ControlBusProducer.java
@@ -26,15 +26,18 @@ import org.apache.camel.Exchange;
 import org.apache.camel.Expression;
 import org.apache.camel.Route;
 import org.apache.camel.ServiceStatus;
+import org.apache.camel.builder.ExpressionBuilder;
 import org.apache.camel.impl.DefaultAsyncProducer;
 import org.apache.camel.spi.Language;
 import org.apache.camel.util.CamelLogger;
 import org.apache.camel.util.ExchangeHelper;
+import org.apache.camel.util.ObjectHelper;
 
 /**
  * The control bus producer.
  */
 public class ControlBusProducer extends DefaultAsyncProducer {
+    private static final Expression ROUTE_ID_EXPRESSION = ExpressionBuilder.routeIdExpression();
 
     private final CamelLogger logger;
 
@@ -144,6 +147,10 @@ public class ControlBusProducer extends DefaultAsyncProducer {
             String action = getEndpoint().getAction();
             String id = getEndpoint().getRouteId();
 
+            if (ObjectHelper.equal("current", id)) {
+                id = ROUTE_ID_EXPRESSION.evaluate(exchange, String.class);
+            }
+
             Object result = null;
             String task = action + " route " + id;
 

http://git-wip-us.apache.org/repos/asf/camel/blob/d0b49ac7/camel-core/src/test/java/org/apache/camel/component/controlbus/ControlBusStartRouteTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/controlbus/ControlBusStartRouteTest.java
b/camel-core/src/test/java/org/apache/camel/component/controlbus/ControlBusStartRouteTest.java
index b526546..68c6169 100644
--- a/camel-core/src/test/java/org/apache/camel/component/controlbus/ControlBusStartRouteTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/controlbus/ControlBusStartRouteTest.java
@@ -17,7 +17,9 @@
 package org.apache.camel.component.controlbus;
 
 import org.apache.camel.ContextTestSupport;
+import org.apache.camel.ServiceStatus;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
 
 /**
  *
@@ -77,6 +79,18 @@ public class ControlBusStartRouteTest extends ContextTestSupport {
         assertEquals("Started", status);
     }
 
+    public void testControlBusCurrentRouteStatus() throws Exception {
+        assertTrue(context.getRouteStatus("current").isStarted());
+
+        MockEndpoint mock = getMockEndpoint("mock:current");
+        mock.expectedMessageCount(1);
+        mock.expectedBodiesReceived(ServiceStatus.Started.name());
+
+        sendBody("seda:current", null);
+
+        mock.assertIsSatisfied();
+    }
+
     public void testControlBusStatusLevelWarn() throws Exception {
         assertEquals("Stopped", context.getRouteStatus("foo").name());
 
@@ -96,6 +110,9 @@ public class ControlBusStartRouteTest extends ContextTestSupport {
             public void configure() throws Exception {
                 from("seda:foo").routeId("foo").noAutoStartup()
                     .to("mock:foo");
+                from("seda:current").routeId("current")
+                    .to("controlbus:route?routeId=current&action=status&loggingLevel=WARN")
+                    .to("mock:current");
             }
         };
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/d0b49ac7/camel-core/src/test/java/org/apache/camel/component/controlbus/ControlBusStatsTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/controlbus/ControlBusStatsTest.java
b/camel-core/src/test/java/org/apache/camel/component/controlbus/ControlBusStatsTest.java
index 20b100b..13ef308 100644
--- a/camel-core/src/test/java/org/apache/camel/component/controlbus/ControlBusStatsTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/controlbus/ControlBusStatsTest.java
@@ -45,6 +45,22 @@ public class ControlBusStatsTest extends ContextTestSupport {
         assertTrue(xml.contains("exchangesCompleted=\"1\""));
     }
 
+    public void testControlBusCurrentRouteStat() throws Exception {
+        getMockEndpoint("mock:current").expectedBodiesReceived("Hello World");
+
+        template.sendBody("direct:current", "Hello World");
+
+        assertMockEndpointsSatisfied();
+
+        String xml = template.requestBody("controlbus:route?routeId=current&action=stats",
null, String.class);
+        assertNotNull(xml);
+
+        assertTrue(xml.contains("routeStat"));
+        assertTrue(xml.contains("processorStat"));
+        assertTrue(xml.contains("id=\"current\""));
+        assertTrue(xml.contains("exchangesCompleted=\"1\""));
+    }
+
     public void testControlBusContextStat() throws Exception {
         getMockEndpoint("mock:bar").expectedBodiesReceived("Hello World");
 
@@ -69,9 +85,10 @@ public class ControlBusStatsTest extends ContextTestSupport {
             public void configure() throws Exception {
                 from("direct:foo").routeId("foo")
                     .to("mock:foo");
-
                 from("direct:bar").routeId("bar")
                     .to("mock:bar");
+                from("direct:current").routeId("current")
+                    .to("mock:current");
             }
         };
     }


Mime
View raw message