Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2EBCE1964A for ; Fri, 22 Apr 2016 19:07:27 +0000 (UTC) Received: (qmail 63922 invoked by uid 500); 22 Apr 2016 19:07:27 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 63869 invoked by uid 500); 22 Apr 2016 19:07:27 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 63859 invoked by uid 99); 22 Apr 2016 19:07:27 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 Apr 2016 19:07:27 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id D8006E020A; Fri, 22 Apr 2016 19:07:26 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: davsclaus@apache.org To: commits@camel.apache.org Date: Fri, 22 Apr 2016 19:07:26 -0000 Message-Id: <8a5b9b56c7dc41ddb817c6e99179c3c2@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [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 Authored: Fri Apr 22 16:35:28 2016 +0200 Committer: Claus Ibsen 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 routes = server.queryNames(query, null); List processors = new ArrayList(); 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 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 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 exchangesInFlightStartTimestamps = new ConcurrentSkipListMap(); private final ConcurrentHashMap exchangesInFlightKeys = new ConcurrentHashMap(); + 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 names = server.queryNames(query, null); List mps = new ArrayList(); 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 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"); + } + }; + } + +}