You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2016/04/22 21:07:26 UTC

[1/4] camel git commit: CAMEL-9903 Fix jmx operations when jmx domain is custom + test

Repository: camel
Updated Branches:
  refs/heads/camel-2.17.x 0811dc599 -> 1099e619e
  refs/heads/master 41249ba9d -> 16163aa05


CAMEL-9903 Fix jmx operations when jmx domain is custom + test


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

Branch: refs/heads/master
Commit: 51900761fcc6c8124dd651f1bf267625643fc8ba
Parents: 41249ba
Author: Guillaume Terral <gu...@github.com>
Authored: Fri Apr 22 16:35:28 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Apr 22 21:00:33 2016 +0200

----------------------------------------------------------------------
 .../management/mbean/ManagedCamelContext.java   |  8 +-
 .../camel/management/mbean/ManagedRoute.java    |  6 +-
 ...pStatsAsXmlAndResetWithCustomDomainTest.java | 90 ++++++++++++++++++++
 ...agedRouteDumpStatsAsXmlCustomDomainTest.java | 75 ++++++++++++++++
 4 files changed, 174 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/51900761/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
index d849d99..91e7713 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
@@ -78,9 +78,11 @@ public class ManagedCamelContext extends ManagedPerformanceCounter implements Ti
 
     private final ModelCamelContext context;
     private final LoadTriplet load = new LoadTriplet();
+    private final String jmxDomain;
 
     public ManagedCamelContext(ModelCamelContext context) {
         this.context = context;
+        this.jmxDomain = context.getManagementStrategy().getManagementAgent().getMBeanObjectDomainName();
     }
 
     @Override
@@ -480,13 +482,13 @@ public class ManagedCamelContext extends ManagedPerformanceCounter implements Ti
         if (server != null) {
             // gather all the routes for this CamelContext, which requires JMX
             String prefix = getContext().getManagementStrategy().getManagementAgent().getIncludeHostName() ? "*/" : "";
-            ObjectName query = ObjectName.getInstance("org.apache.camel:context=" + prefix + getContext().getManagementName() + ",type=routes,*");
+            ObjectName query = ObjectName.getInstance(jmxDomain + ":context=" + prefix + getContext().getManagementName() + ",type=routes,*");
             Set<ObjectName> routes = server.queryNames(query, null);
 
             List<ManagedProcessorMBean> processors = new ArrayList<ManagedProcessorMBean>();
             if (includeProcessors) {
                 // gather all the processors for this CamelContext, which requires JMX
-                query = ObjectName.getInstance("org.apache.camel:context=" + prefix + getContext().getManagementName() + ",type=processors,*");
+                query = ObjectName.getInstance(jmxDomain + ":context=" + prefix + getContext().getManagementName() + ",type=processors,*");
                 Set<ObjectName> names = server.queryNames(query, null);
                 for (ObjectName on : names) {
                     ManagedProcessorMBean processor = context.getManagementStrategy().getManagementAgent().newProxyClient(on, ManagedProcessorMBean.class);
@@ -765,7 +767,7 @@ public class ManagedCamelContext extends ManagedPerformanceCounter implements Ti
             MBeanServer server = getContext().getManagementStrategy().getManagementAgent().getMBeanServer();
             if (server != null) {
                 String prefix = getContext().getManagementStrategy().getManagementAgent().getIncludeHostName() ? "*/" : "";
-                ObjectName query = ObjectName.getInstance("org.apache.camel:context=" + prefix + getContext().getManagementName() + ",type=routes,*");
+                ObjectName query = ObjectName.getInstance(jmxDomain + ":context=" + prefix + getContext().getManagementName() + ",type=routes,*");
                 Set<ObjectName> names = server.queryNames(query, null);
                 for (ObjectName name : names) {
                     server.invoke(name, "reset", new Object[]{true}, new String[]{"boolean"});

http://git-wip-us.apache.org/repos/asf/camel/blob/51900761/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java
index 7bd414e..e56b024 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java
@@ -70,11 +70,13 @@ public class ManagedRoute extends ManagedPerformanceCounter implements TimerList
     private final LoadTriplet load = new LoadTriplet();
     private final ConcurrentSkipListMap<InFlightKey, Long> exchangesInFlightStartTimestamps = new ConcurrentSkipListMap<InFlightKey, Long>();
     private final ConcurrentHashMap<String, InFlightKey> exchangesInFlightKeys = new ConcurrentHashMap<String, InFlightKey>();
+    private final String jmxDomain;
 
     public ManagedRoute(ModelCamelContext context, Route route) {
         this.route = route;
         this.context = context;
         this.description = route.getDescription();
+        this.jmxDomain = context.getManagementStrategy().getManagementAgent().getMBeanObjectDomainName();
     }
 
     @Override
@@ -349,7 +351,7 @@ public class ManagedRoute extends ManagedPerformanceCounter implements TimerList
             if (server != null) {
                 // get all the processor mbeans and sort them accordingly to their index
                 String prefix = getContext().getManagementStrategy().getManagementAgent().getIncludeHostName() ? "*/" : "";
-                ObjectName query = ObjectName.getInstance("org.apache.camel:context=" + prefix + getContext().getManagementName() + ",type=processors,*");
+                ObjectName query = ObjectName.getInstance(jmxDomain + ":context=" + prefix + getContext().getManagementName() + ",type=processors,*");
                 Set<ObjectName> names = server.queryNames(query, null);
                 List<ManagedProcessorMBean> mps = new ArrayList<ManagedProcessorMBean>();
                 for (ObjectName on : names) {
@@ -427,7 +429,7 @@ public class ManagedRoute extends ManagedPerformanceCounter implements TimerList
             if (server != null) {
                 // get all the processor mbeans and sort them accordingly to their index
                 String prefix = getContext().getManagementStrategy().getManagementAgent().getIncludeHostName() ? "*/" : "";
-                ObjectName query = ObjectName.getInstance("org.apache.camel:context=" + prefix + getContext().getManagementName() + ",type=processors,*");
+                ObjectName query = ObjectName.getInstance(jmxDomain + ":context=" + prefix + getContext().getManagementName() + ",type=processors,*");
                 QueryExp queryExp = Query.match(new AttributeValueExp("RouteId"), new StringValueExp(getRouteId()));
                 Set<ObjectName> names = server.queryNames(query, queryExp);
                 for (ObjectName name : names) {

http://git-wip-us.apache.org/repos/asf/camel/blob/51900761/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpStatsAsXmlAndResetWithCustomDomainTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpStatsAsXmlAndResetWithCustomDomainTest.java b/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpStatsAsXmlAndResetWithCustomDomainTest.java
new file mode 100644
index 0000000..f5fa254
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpStatsAsXmlAndResetWithCustomDomainTest.java
@@ -0,0 +1,90 @@
+/**
+ * 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.camel.management;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.w3c.dom.Document;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+/**
+ * @version
+ */
+public class ManagedRouteDumpStatsAsXmlAndResetWithCustomDomainTest extends ManagementTestSupport {
+
+    private final String CUSTOM_DOMAIN_NAME="custom";
+
+    public void testPerformanceCounterStats() throws Exception {
+        // JMX tests dont work well on AIX CI servers (hangs them)
+        if (isPlatform("aix")) {
+            return;
+        }
+
+        // get the stats for the route
+        MBeanServer mbeanServer = getMBeanServer();
+        ObjectName on = ObjectName.getInstance(CUSTOM_DOMAIN_NAME+":context=camel-1,type=routes,name=\"foo\"");
+
+        getMockEndpoint("mock:result").expectedMessageCount(1);
+
+        template.asyncSendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+
+        String xml = (String) mbeanServer.invoke(on, "dumpRouteStatsAsXml", new Object[]{false, true}, new String[]{"boolean", "boolean"});
+        log.info(xml);
+
+        // should be valid XML
+        Document doc = context.getTypeConverter().convertTo(Document.class, xml);
+        assertNotNull(doc);
+
+        int processors = doc.getDocumentElement().getElementsByTagName("processorStat").getLength();
+        assertEquals(3, processors);
+
+        int exchangeCompleted = Integer.parseInt(doc.getDocumentElement().getElementsByTagName("processorStat").item(0).getAttributes().getNamedItem("exchangesCompleted").getNodeValue());
+        assertEquals(1, exchangeCompleted);
+
+        //ResetValues
+        mbeanServer.invoke(on, "reset", new Object[]{true}, new String[]{"boolean"});
+
+        xml = (String) mbeanServer.invoke(on, "dumpRouteStatsAsXml", new Object[]{false, true}, new String[]{"boolean", "boolean"});
+        log.info(xml);
+
+        // should be valid XML
+        doc = context.getTypeConverter().convertTo(Document.class, xml);
+        assertNotNull(doc);
+        exchangeCompleted = Integer.parseInt(doc.getDocumentElement().getElementsByTagName("processorStat").item(0).getAttributes().getNamedItem("exchangesCompleted").getNodeValue());
+        assertEquals(0, exchangeCompleted);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+//              System.setProperty("org.apache.camel.jmx.mbeanObjectDomainName", CUSTOM_DOMAIN_NAME);
+//              Or
+                getContext().getManagementStrategy().getManagementAgent().setMBeanObjectDomainName(CUSTOM_DOMAIN_NAME);
+                from("direct:start").routeId("foo")
+                        .to("log:foo").id("to-log")
+                        .delay(100)
+                        .to("mock:result").id("to-mock");
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/51900761/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpStatsAsXmlCustomDomainTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpStatsAsXmlCustomDomainTest.java b/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpStatsAsXmlCustomDomainTest.java
new file mode 100644
index 0000000..6d624ba
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpStatsAsXmlCustomDomainTest.java
@@ -0,0 +1,75 @@
+/**
+ * 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.camel.management;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.w3c.dom.Document;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+/**
+ * @version
+ */
+public class ManagedRouteDumpStatsAsXmlCustomDomainTest extends ManagementTestSupport {
+
+    private final String CUSTOM_DOMAIN_NAME="custom";
+
+    public void testPerformanceCounterStats() throws Exception {
+        // JMX tests dont work well on AIX CI servers (hangs them)
+        if (isPlatform("aix")) {
+            return;
+        }
+
+        // get the stats for the route
+        MBeanServer mbeanServer = getMBeanServer();
+        ObjectName on = ObjectName.getInstance(CUSTOM_DOMAIN_NAME+":context=camel-1,type=routes,name=\"foo\"");
+
+        getMockEndpoint("mock:result").expectedMessageCount(1);
+
+        template.asyncSendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+
+        String xml = (String) mbeanServer.invoke(on, "dumpRouteStatsAsXml", new Object[]{false, true}, new String[]{"boolean", "boolean"});
+        log.info(xml);
+
+        // should be valid XML
+        Document doc = context.getTypeConverter().convertTo(Document.class, xml);
+        assertNotNull(doc);
+
+        int processors = doc.getDocumentElement().getElementsByTagName("processorStat").getLength();
+        assertEquals(3, processors);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+//              System.setProperty("org.apache.camel.jmx.mbeanObjectDomainName", CUSTOM_DOMAIN_NAME);
+//              Or
+                getContext().getManagementStrategy().getManagementAgent().setMBeanObjectDomainName(CUSTOM_DOMAIN_NAME);
+                from("direct:start").routeId("foo")
+                        .to("log:foo").id("to-log")
+                        .delay(100)
+                        .to("mock:result").id("to-mock");
+            }
+        };
+    }
+
+}


[4/4] camel git commit: Fixed CS. This closes #956

Posted by da...@apache.org.
Fixed CS. This closes #956


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

Branch: refs/heads/camel-2.17.x
Commit: 1099e619eb583556ba3115ff5f666239d2a6c535
Parents: 6009e81
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Apr 22 21:05:02 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Apr 22 21:07:16 2016 +0200

----------------------------------------------------------------------
 ...dRouteDumpStatsAsXmlAndResetWithCustomDomainTest.java | 11 ++++++-----
 .../ManagedRouteDumpStatsAsXmlCustomDomainTest.java      | 11 ++++++-----
 2 files changed, 12 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/1099e619/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpStatsAsXmlAndResetWithCustomDomainTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpStatsAsXmlAndResetWithCustomDomainTest.java b/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpStatsAsXmlAndResetWithCustomDomainTest.java
index f5fa254..e4b3b3b 100644
--- a/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpStatsAsXmlAndResetWithCustomDomainTest.java
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpStatsAsXmlAndResetWithCustomDomainTest.java
@@ -16,18 +16,19 @@
  */
 package org.apache.camel.management;
 
-import org.apache.camel.builder.RouteBuilder;
-import org.w3c.dom.Document;
-
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
 
+import org.w3c.dom.Document;
+
+import org.apache.camel.builder.RouteBuilder;
+
 /**
  * @version
  */
 public class ManagedRouteDumpStatsAsXmlAndResetWithCustomDomainTest extends ManagementTestSupport {
 
-    private final String CUSTOM_DOMAIN_NAME="custom";
+    private static final String CUSTOM_DOMAIN_NAME = "custom";
 
     public void testPerformanceCounterStats() throws Exception {
         // JMX tests dont work well on AIX CI servers (hangs them)
@@ -37,7 +38,7 @@ public class ManagedRouteDumpStatsAsXmlAndResetWithCustomDomainTest extends Mana
 
         // get the stats for the route
         MBeanServer mbeanServer = getMBeanServer();
-        ObjectName on = ObjectName.getInstance(CUSTOM_DOMAIN_NAME+":context=camel-1,type=routes,name=\"foo\"");
+        ObjectName on = ObjectName.getInstance(CUSTOM_DOMAIN_NAME + ":context=camel-1,type=routes,name=\"foo\"");
 
         getMockEndpoint("mock:result").expectedMessageCount(1);
 

http://git-wip-us.apache.org/repos/asf/camel/blob/1099e619/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpStatsAsXmlCustomDomainTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpStatsAsXmlCustomDomainTest.java b/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpStatsAsXmlCustomDomainTest.java
index 6d624ba..a94c766 100644
--- a/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpStatsAsXmlCustomDomainTest.java
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpStatsAsXmlCustomDomainTest.java
@@ -16,18 +16,19 @@
  */
 package org.apache.camel.management;
 
-import org.apache.camel.builder.RouteBuilder;
-import org.w3c.dom.Document;
-
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
 
+import org.w3c.dom.Document;
+
+import org.apache.camel.builder.RouteBuilder;
+
 /**
  * @version
  */
 public class ManagedRouteDumpStatsAsXmlCustomDomainTest extends ManagementTestSupport {
 
-    private final String CUSTOM_DOMAIN_NAME="custom";
+    private static final String CUSTOM_DOMAIN_NAME = "custom";
 
     public void testPerformanceCounterStats() throws Exception {
         // JMX tests dont work well on AIX CI servers (hangs them)
@@ -37,7 +38,7 @@ public class ManagedRouteDumpStatsAsXmlCustomDomainTest extends ManagementTestSu
 
         // get the stats for the route
         MBeanServer mbeanServer = getMBeanServer();
-        ObjectName on = ObjectName.getInstance(CUSTOM_DOMAIN_NAME+":context=camel-1,type=routes,name=\"foo\"");
+        ObjectName on = ObjectName.getInstance(CUSTOM_DOMAIN_NAME + ":context=camel-1,type=routes,name=\"foo\"");
 
         getMockEndpoint("mock:result").expectedMessageCount(1);
 


[2/4] camel git commit: Fixed CS. This closes #956

Posted by da...@apache.org.
Fixed CS. This closes #956


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

Branch: refs/heads/master
Commit: 16163aa05dbfda62e62e510f7dfcfca7ca13dd56
Parents: 5190076
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Apr 22 21:05:02 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Apr 22 21:05:02 2016 +0200

----------------------------------------------------------------------
 .../impl/EndpointRegistryKeepRouteEndpointsTest.java     |  2 +-
 ...dRouteDumpStatsAsXmlAndResetWithCustomDomainTest.java | 11 ++++++-----
 .../ManagedRouteDumpStatsAsXmlCustomDomainTest.java      | 11 ++++++-----
 3 files changed, 13 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/16163aa0/camel-core/src/test/java/org/apache/camel/impl/EndpointRegistryKeepRouteEndpointsTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/impl/EndpointRegistryKeepRouteEndpointsTest.java b/camel-core/src/test/java/org/apache/camel/impl/EndpointRegistryKeepRouteEndpointsTest.java
index db6e734..6a67176 100644
--- a/camel-core/src/test/java/org/apache/camel/impl/EndpointRegistryKeepRouteEndpointsTest.java
+++ b/camel-core/src/test/java/org/apache/camel/impl/EndpointRegistryKeepRouteEndpointsTest.java
@@ -60,7 +60,7 @@ public class EndpointRegistryKeepRouteEndpointsTest extends ContextTestSupport {
                 count++;
                 // and it should be dynamic
                 assertTrue(context.getEndpointRegistry().isDynamic(uri));
-            };
+            }
         }
         assertEquals("Should only be 20 dynamic endpoints in the cache", 20, count);
 

http://git-wip-us.apache.org/repos/asf/camel/blob/16163aa0/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpStatsAsXmlAndResetWithCustomDomainTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpStatsAsXmlAndResetWithCustomDomainTest.java b/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpStatsAsXmlAndResetWithCustomDomainTest.java
index f5fa254..e4b3b3b 100644
--- a/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpStatsAsXmlAndResetWithCustomDomainTest.java
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpStatsAsXmlAndResetWithCustomDomainTest.java
@@ -16,18 +16,19 @@
  */
 package org.apache.camel.management;
 
-import org.apache.camel.builder.RouteBuilder;
-import org.w3c.dom.Document;
-
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
 
+import org.w3c.dom.Document;
+
+import org.apache.camel.builder.RouteBuilder;
+
 /**
  * @version
  */
 public class ManagedRouteDumpStatsAsXmlAndResetWithCustomDomainTest extends ManagementTestSupport {
 
-    private final String CUSTOM_DOMAIN_NAME="custom";
+    private static final String CUSTOM_DOMAIN_NAME = "custom";
 
     public void testPerformanceCounterStats() throws Exception {
         // JMX tests dont work well on AIX CI servers (hangs them)
@@ -37,7 +38,7 @@ public class ManagedRouteDumpStatsAsXmlAndResetWithCustomDomainTest extends Mana
 
         // get the stats for the route
         MBeanServer mbeanServer = getMBeanServer();
-        ObjectName on = ObjectName.getInstance(CUSTOM_DOMAIN_NAME+":context=camel-1,type=routes,name=\"foo\"");
+        ObjectName on = ObjectName.getInstance(CUSTOM_DOMAIN_NAME + ":context=camel-1,type=routes,name=\"foo\"");
 
         getMockEndpoint("mock:result").expectedMessageCount(1);
 

http://git-wip-us.apache.org/repos/asf/camel/blob/16163aa0/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpStatsAsXmlCustomDomainTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpStatsAsXmlCustomDomainTest.java b/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpStatsAsXmlCustomDomainTest.java
index 6d624ba..a94c766 100644
--- a/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpStatsAsXmlCustomDomainTest.java
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpStatsAsXmlCustomDomainTest.java
@@ -16,18 +16,19 @@
  */
 package org.apache.camel.management;
 
-import org.apache.camel.builder.RouteBuilder;
-import org.w3c.dom.Document;
-
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
 
+import org.w3c.dom.Document;
+
+import org.apache.camel.builder.RouteBuilder;
+
 /**
  * @version
  */
 public class ManagedRouteDumpStatsAsXmlCustomDomainTest extends ManagementTestSupport {
 
-    private final String CUSTOM_DOMAIN_NAME="custom";
+    private static final String CUSTOM_DOMAIN_NAME = "custom";
 
     public void testPerformanceCounterStats() throws Exception {
         // JMX tests dont work well on AIX CI servers (hangs them)
@@ -37,7 +38,7 @@ public class ManagedRouteDumpStatsAsXmlCustomDomainTest extends ManagementTestSu
 
         // get the stats for the route
         MBeanServer mbeanServer = getMBeanServer();
-        ObjectName on = ObjectName.getInstance(CUSTOM_DOMAIN_NAME+":context=camel-1,type=routes,name=\"foo\"");
+        ObjectName on = ObjectName.getInstance(CUSTOM_DOMAIN_NAME + ":context=camel-1,type=routes,name=\"foo\"");
 
         getMockEndpoint("mock:result").expectedMessageCount(1);
 


[3/4] camel git commit: CAMEL-9903 Fix jmx operations when jmx domain is custom + test

Posted by da...@apache.org.
CAMEL-9903 Fix jmx operations when jmx domain is custom + test


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

Branch: refs/heads/camel-2.17.x
Commit: 6009e81ecc9da16bc038dbdfe33425603da840e9
Parents: 0811dc5
Author: Guillaume Terral <gu...@github.com>
Authored: Fri Apr 22 16:35:28 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Apr 22 21:06:41 2016 +0200

----------------------------------------------------------------------
 .../management/mbean/ManagedCamelContext.java   |  8 +-
 .../camel/management/mbean/ManagedRoute.java    |  6 +-
 ...pStatsAsXmlAndResetWithCustomDomainTest.java | 90 ++++++++++++++++++++
 ...agedRouteDumpStatsAsXmlCustomDomainTest.java | 75 ++++++++++++++++
 4 files changed, 174 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/6009e81e/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
index d849d99..91e7713 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
@@ -78,9 +78,11 @@ public class ManagedCamelContext extends ManagedPerformanceCounter implements Ti
 
     private final ModelCamelContext context;
     private final LoadTriplet load = new LoadTriplet();
+    private final String jmxDomain;
 
     public ManagedCamelContext(ModelCamelContext context) {
         this.context = context;
+        this.jmxDomain = context.getManagementStrategy().getManagementAgent().getMBeanObjectDomainName();
     }
 
     @Override
@@ -480,13 +482,13 @@ public class ManagedCamelContext extends ManagedPerformanceCounter implements Ti
         if (server != null) {
             // gather all the routes for this CamelContext, which requires JMX
             String prefix = getContext().getManagementStrategy().getManagementAgent().getIncludeHostName() ? "*/" : "";
-            ObjectName query = ObjectName.getInstance("org.apache.camel:context=" + prefix + getContext().getManagementName() + ",type=routes,*");
+            ObjectName query = ObjectName.getInstance(jmxDomain + ":context=" + prefix + getContext().getManagementName() + ",type=routes,*");
             Set<ObjectName> routes = server.queryNames(query, null);
 
             List<ManagedProcessorMBean> processors = new ArrayList<ManagedProcessorMBean>();
             if (includeProcessors) {
                 // gather all the processors for this CamelContext, which requires JMX
-                query = ObjectName.getInstance("org.apache.camel:context=" + prefix + getContext().getManagementName() + ",type=processors,*");
+                query = ObjectName.getInstance(jmxDomain + ":context=" + prefix + getContext().getManagementName() + ",type=processors,*");
                 Set<ObjectName> names = server.queryNames(query, null);
                 for (ObjectName on : names) {
                     ManagedProcessorMBean processor = context.getManagementStrategy().getManagementAgent().newProxyClient(on, ManagedProcessorMBean.class);
@@ -765,7 +767,7 @@ public class ManagedCamelContext extends ManagedPerformanceCounter implements Ti
             MBeanServer server = getContext().getManagementStrategy().getManagementAgent().getMBeanServer();
             if (server != null) {
                 String prefix = getContext().getManagementStrategy().getManagementAgent().getIncludeHostName() ? "*/" : "";
-                ObjectName query = ObjectName.getInstance("org.apache.camel:context=" + prefix + getContext().getManagementName() + ",type=routes,*");
+                ObjectName query = ObjectName.getInstance(jmxDomain + ":context=" + prefix + getContext().getManagementName() + ",type=routes,*");
                 Set<ObjectName> names = server.queryNames(query, null);
                 for (ObjectName name : names) {
                     server.invoke(name, "reset", new Object[]{true}, new String[]{"boolean"});

http://git-wip-us.apache.org/repos/asf/camel/blob/6009e81e/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java
index 7bd414e..e56b024 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java
@@ -70,11 +70,13 @@ public class ManagedRoute extends ManagedPerformanceCounter implements TimerList
     private final LoadTriplet load = new LoadTriplet();
     private final ConcurrentSkipListMap<InFlightKey, Long> exchangesInFlightStartTimestamps = new ConcurrentSkipListMap<InFlightKey, Long>();
     private final ConcurrentHashMap<String, InFlightKey> exchangesInFlightKeys = new ConcurrentHashMap<String, InFlightKey>();
+    private final String jmxDomain;
 
     public ManagedRoute(ModelCamelContext context, Route route) {
         this.route = route;
         this.context = context;
         this.description = route.getDescription();
+        this.jmxDomain = context.getManagementStrategy().getManagementAgent().getMBeanObjectDomainName();
     }
 
     @Override
@@ -349,7 +351,7 @@ public class ManagedRoute extends ManagedPerformanceCounter implements TimerList
             if (server != null) {
                 // get all the processor mbeans and sort them accordingly to their index
                 String prefix = getContext().getManagementStrategy().getManagementAgent().getIncludeHostName() ? "*/" : "";
-                ObjectName query = ObjectName.getInstance("org.apache.camel:context=" + prefix + getContext().getManagementName() + ",type=processors,*");
+                ObjectName query = ObjectName.getInstance(jmxDomain + ":context=" + prefix + getContext().getManagementName() + ",type=processors,*");
                 Set<ObjectName> names = server.queryNames(query, null);
                 List<ManagedProcessorMBean> mps = new ArrayList<ManagedProcessorMBean>();
                 for (ObjectName on : names) {
@@ -427,7 +429,7 @@ public class ManagedRoute extends ManagedPerformanceCounter implements TimerList
             if (server != null) {
                 // get all the processor mbeans and sort them accordingly to their index
                 String prefix = getContext().getManagementStrategy().getManagementAgent().getIncludeHostName() ? "*/" : "";
-                ObjectName query = ObjectName.getInstance("org.apache.camel:context=" + prefix + getContext().getManagementName() + ",type=processors,*");
+                ObjectName query = ObjectName.getInstance(jmxDomain + ":context=" + prefix + getContext().getManagementName() + ",type=processors,*");
                 QueryExp queryExp = Query.match(new AttributeValueExp("RouteId"), new StringValueExp(getRouteId()));
                 Set<ObjectName> names = server.queryNames(query, queryExp);
                 for (ObjectName name : names) {

http://git-wip-us.apache.org/repos/asf/camel/blob/6009e81e/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpStatsAsXmlAndResetWithCustomDomainTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpStatsAsXmlAndResetWithCustomDomainTest.java b/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpStatsAsXmlAndResetWithCustomDomainTest.java
new file mode 100644
index 0000000..f5fa254
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpStatsAsXmlAndResetWithCustomDomainTest.java
@@ -0,0 +1,90 @@
+/**
+ * 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.camel.management;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.w3c.dom.Document;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+/**
+ * @version
+ */
+public class ManagedRouteDumpStatsAsXmlAndResetWithCustomDomainTest extends ManagementTestSupport {
+
+    private final String CUSTOM_DOMAIN_NAME="custom";
+
+    public void testPerformanceCounterStats() throws Exception {
+        // JMX tests dont work well on AIX CI servers (hangs them)
+        if (isPlatform("aix")) {
+            return;
+        }
+
+        // get the stats for the route
+        MBeanServer mbeanServer = getMBeanServer();
+        ObjectName on = ObjectName.getInstance(CUSTOM_DOMAIN_NAME+":context=camel-1,type=routes,name=\"foo\"");
+
+        getMockEndpoint("mock:result").expectedMessageCount(1);
+
+        template.asyncSendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+
+        String xml = (String) mbeanServer.invoke(on, "dumpRouteStatsAsXml", new Object[]{false, true}, new String[]{"boolean", "boolean"});
+        log.info(xml);
+
+        // should be valid XML
+        Document doc = context.getTypeConverter().convertTo(Document.class, xml);
+        assertNotNull(doc);
+
+        int processors = doc.getDocumentElement().getElementsByTagName("processorStat").getLength();
+        assertEquals(3, processors);
+
+        int exchangeCompleted = Integer.parseInt(doc.getDocumentElement().getElementsByTagName("processorStat").item(0).getAttributes().getNamedItem("exchangesCompleted").getNodeValue());
+        assertEquals(1, exchangeCompleted);
+
+        //ResetValues
+        mbeanServer.invoke(on, "reset", new Object[]{true}, new String[]{"boolean"});
+
+        xml = (String) mbeanServer.invoke(on, "dumpRouteStatsAsXml", new Object[]{false, true}, new String[]{"boolean", "boolean"});
+        log.info(xml);
+
+        // should be valid XML
+        doc = context.getTypeConverter().convertTo(Document.class, xml);
+        assertNotNull(doc);
+        exchangeCompleted = Integer.parseInt(doc.getDocumentElement().getElementsByTagName("processorStat").item(0).getAttributes().getNamedItem("exchangesCompleted").getNodeValue());
+        assertEquals(0, exchangeCompleted);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+//              System.setProperty("org.apache.camel.jmx.mbeanObjectDomainName", CUSTOM_DOMAIN_NAME);
+//              Or
+                getContext().getManagementStrategy().getManagementAgent().setMBeanObjectDomainName(CUSTOM_DOMAIN_NAME);
+                from("direct:start").routeId("foo")
+                        .to("log:foo").id("to-log")
+                        .delay(100)
+                        .to("mock:result").id("to-mock");
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/6009e81e/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpStatsAsXmlCustomDomainTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpStatsAsXmlCustomDomainTest.java b/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpStatsAsXmlCustomDomainTest.java
new file mode 100644
index 0000000..6d624ba
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpStatsAsXmlCustomDomainTest.java
@@ -0,0 +1,75 @@
+/**
+ * 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.camel.management;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.w3c.dom.Document;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+/**
+ * @version
+ */
+public class ManagedRouteDumpStatsAsXmlCustomDomainTest extends ManagementTestSupport {
+
+    private final String CUSTOM_DOMAIN_NAME="custom";
+
+    public void testPerformanceCounterStats() throws Exception {
+        // JMX tests dont work well on AIX CI servers (hangs them)
+        if (isPlatform("aix")) {
+            return;
+        }
+
+        // get the stats for the route
+        MBeanServer mbeanServer = getMBeanServer();
+        ObjectName on = ObjectName.getInstance(CUSTOM_DOMAIN_NAME+":context=camel-1,type=routes,name=\"foo\"");
+
+        getMockEndpoint("mock:result").expectedMessageCount(1);
+
+        template.asyncSendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+
+        String xml = (String) mbeanServer.invoke(on, "dumpRouteStatsAsXml", new Object[]{false, true}, new String[]{"boolean", "boolean"});
+        log.info(xml);
+
+        // should be valid XML
+        Document doc = context.getTypeConverter().convertTo(Document.class, xml);
+        assertNotNull(doc);
+
+        int processors = doc.getDocumentElement().getElementsByTagName("processorStat").getLength();
+        assertEquals(3, processors);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+//              System.setProperty("org.apache.camel.jmx.mbeanObjectDomainName", CUSTOM_DOMAIN_NAME);
+//              Or
+                getContext().getManagementStrategy().getManagementAgent().setMBeanObjectDomainName(CUSTOM_DOMAIN_NAME);
+                from("direct:start").routeId("foo")
+                        .to("log:foo").id("to-log")
+                        .delay(100)
+                        .to("mock:result").id("to-mock");
+            }
+        };
+    }
+
+}