camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [3/4] camel git commit: CAMEL-9903 Fix jmx operations when jmx domain is custom + test
Date Fri, 22 Apr 2016 19:07:28 GMT
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 <guillaumeterral@github.com>
Authored: Fri Apr 22 16:35:28 2016 +0200
Committer: Claus Ibsen <davsclaus@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");
+            }
+        };
+    }
+
+}


Mime
View raw message