CAMEL-8526: Add more EIP as specialized mbeans
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/542ab3e8 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/542ab3e8 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/542ab3e8 Branch: refs/heads/master Commit: 542ab3e8c7e6fd74bf7053b8a75039dc0f0c5094 Parents: 1db6c64 Author: Claus Ibsen <davscl...@apache.org> Authored: Wed Jul 22 09:46:23 2015 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Wed Jul 22 09:53:18 2015 +0200 ---------------------------------------------------------------------- .../management/mbean/ManagedProcessMBean.java | 29 ++++++ .../DefaultManagementObjectStrategy.java | 7 +- .../camel/management/mbean/ManagedProcess.java | 62 ++++++++++++ .../camel/management/ManagedProcessTest.java | 100 +++++++++++++++++++ .../camel/management/ManagementTestSupport.java | 7 -- .../camel/management/MyDummyProcessor.java | 28 ++++++ 6 files changed, 224 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/542ab3e8/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedProcessMBean.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedProcessMBean.java b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedProcessMBean.java new file mode 100644 index 0000000..1b1a2ab --- /dev/null +++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedProcessMBean.java @@ -0,0 +1,29 @@ +/** + * 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.api.management.mbean; + +import org.apache.camel.api.management.ManagedAttribute; + +public interface ManagedProcessMBean extends ManagedProcessorMBean { + + @ManagedAttribute(description = "Reference to the Processor to lookup in the registry to use") + String getRef(); + + @ManagedAttribute(description = "The class name of the Processor in use (may be null if not resolved yet)") + String getProcessorClassName(); + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/542ab3e8/camel-core/src/main/java/org/apache/camel/management/DefaultManagementObjectStrategy.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/management/DefaultManagementObjectStrategy.java b/camel-core/src/main/java/org/apache/camel/management/DefaultManagementObjectStrategy.java index be87c46..a86f6c2 100644 --- a/camel-core/src/main/java/org/apache/camel/management/DefaultManagementObjectStrategy.java +++ b/camel-core/src/main/java/org/apache/camel/management/DefaultManagementObjectStrategy.java @@ -50,6 +50,7 @@ import org.apache.camel.management.mbean.ManagedIdempotentConsumer; import org.apache.camel.management.mbean.ManagedLoop; import org.apache.camel.management.mbean.ManagedMulticast; import org.apache.camel.management.mbean.ManagedPollEnricher; +import org.apache.camel.management.mbean.ManagedProcess; import org.apache.camel.management.mbean.ManagedProcessor; import org.apache.camel.management.mbean.ManagedProducer; import org.apache.camel.management.mbean.ManagedRecipientList; @@ -78,6 +79,7 @@ import org.apache.camel.management.mbean.ManagedTransformer; import org.apache.camel.management.mbean.ManagedValidate; import org.apache.camel.management.mbean.ManagedWireTapProcessor; import org.apache.camel.model.ModelCamelContext; +import org.apache.camel.model.ProcessDefinition; import org.apache.camel.model.ProcessorDefinition; import org.apache.camel.model.RecipientListDefinition; import org.apache.camel.model.ThreadsDefinition; @@ -243,7 +245,6 @@ public class DefaultManagementObjectStrategy implements ManagementObjectStrategy return false; } - // look for specialized processor which we should prefer to use if (target instanceof ConvertBodyProcessor) { answer = new ManagedConvertBody(context, (ConvertBodyProcessor) target, definition); } else if (target instanceof Delayer) { @@ -336,7 +337,9 @@ public class DefaultManagementObjectStrategy implements ManagementObjectStrategy } } - if (answer == null) { + if (answer == null && definition instanceof ProcessDefinition) { + answer = new ManagedProcess(context, target, (ProcessDefinition) definition); + } else if (answer == null) { // fallback to a generic processor answer = new ManagedProcessor(context, target, definition); } http://git-wip-us.apache.org/repos/asf/camel/blob/542ab3e8/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedProcess.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedProcess.java b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedProcess.java new file mode 100644 index 0000000..34720fa --- /dev/null +++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedProcess.java @@ -0,0 +1,62 @@ +/** + * 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.mbean; + +import org.apache.camel.CamelContext; +import org.apache.camel.DelegateProcessor; +import org.apache.camel.Processor; +import org.apache.camel.api.management.ManagedResource; +import org.apache.camel.api.management.mbean.ManagedProcessMBean; +import org.apache.camel.model.ProcessDefinition; +import org.apache.camel.util.ObjectHelper; + +/** + * @version + */ +@ManagedResource(description = "Managed Process") +public class ManagedProcess extends ManagedProcessor implements ManagedProcessMBean { + private final Processor processor; + private String processorClassName; + + public ManagedProcess(CamelContext context, Processor processor, ProcessDefinition definition) { + super(context, processor, definition); + this.processor = processor; + } + + @Override + public ProcessDefinition getDefinition() { + return (ProcessDefinition) super.getDefinition(); + } + + @Override + public String getRef() { + return getDefinition().getRef(); + } + + @Override + public String getProcessorClassName() { + if (processorClassName != null) { + return processorClassName; + } + Processor target = processor; + if (target instanceof DelegateProcessor) { + target = ((DelegateProcessor) target).getProcessor(); + } + processorClassName = ObjectHelper.className(target); + return processorClassName; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/542ab3e8/camel-core/src/test/java/org/apache/camel/management/ManagedProcessTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedProcessTest.java b/camel-core/src/test/java/org/apache/camel/management/ManagedProcessTest.java new file mode 100644 index 0000000..334a67c --- /dev/null +++ b/camel-core/src/test/java/org/apache/camel/management/ManagedProcessTest.java @@ -0,0 +1,100 @@ +/** + * 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 javax.management.MBeanServer; +import javax.management.ObjectName; +import javax.management.openmbean.TabularData; + +import org.apache.camel.ServiceStatus; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.impl.JndiRegistry; + +/** + * @version + */ +public class ManagedProcessTest extends ManagementTestSupport { + + @Override + protected JndiRegistry createRegistry() throws Exception { + JndiRegistry jndi = super.createRegistry(); + jndi.bind("foo", new MyDummyProcessor()); + return jndi; + } + + public void testManageProcess() throws Exception { + // JMX tests dont work well on AIX CI servers (hangs them) + if (isPlatform("aix")) { + return; + } + + MockEndpoint foo = getMockEndpoint("mock:foo"); + foo.expectedMessageCount(1); + + template.sendBodyAndHeader("direct:start", "Hello World", "foo", "123"); + + assertMockEndpointsSatisfied(); + + // get the stats for the route + MBeanServer mbeanServer = getMBeanServer(); + + // get the object name for the delayer + ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"mysend\""); + + // should be on route1 + String routeId = (String) mbeanServer.getAttribute(on, "RouteId"); + assertEquals("route1", routeId); + + String camelId = (String) mbeanServer.getAttribute(on, "CamelId"); + assertEquals("camel-1", camelId); + + String state = (String) mbeanServer.getAttribute(on, "State"); + assertEquals(ServiceStatus.Started.name(), state); + + String ref = (String) mbeanServer.getAttribute(on, "Ref"); + assertEquals("foo", ref); + + String processorClassName = (String) mbeanServer.getAttribute(on, "ProcessorClassName"); + assertEquals("org.apache.camel.management.MyDummyProcessor", processorClassName); + + TabularData data = (TabularData) mbeanServer.invoke(on, "explain", new Object[]{false}, new String[]{"boolean"}); + assertNotNull(data); + assertEquals(2, data.size()); + + data = (TabularData) mbeanServer.invoke(on, "explain", new Object[]{true}, new String[]{"boolean"}); + assertNotNull(data); + assertEquals(3, data.size()); + + String json = (String) mbeanServer.invoke(on, "informationJson", null, null); + assertNotNull(json); + assertTrue(json.contains("\"description\": \"Calls a Camel processor.")); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start") + .process("foo").id("mysend") + .to("mock:foo"); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/542ab3e8/camel-core/src/test/java/org/apache/camel/management/ManagementTestSupport.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagementTestSupport.java b/camel-core/src/test/java/org/apache/camel/management/ManagementTestSupport.java index 8680fa7..cb10885 100644 --- a/camel-core/src/test/java/org/apache/camel/management/ManagementTestSupport.java +++ b/camel-core/src/test/java/org/apache/camel/management/ManagementTestSupport.java @@ -18,9 +18,7 @@ package org.apache.camel.management; import javax.management.MBeanServer; -import org.apache.camel.CamelContext; import org.apache.camel.ContextTestSupport; -import org.apache.camel.impl.DefaultCamelContext; /** * Base class for JMX tests. @@ -34,11 +32,6 @@ public abstract class ManagementTestSupport extends ContextTestSupport { return true; } - protected CamelContext createCamelContext() throws Exception { - CamelContext context = new DefaultCamelContext(); - return context; - } - protected MBeanServer getMBeanServer() { return context.getManagementStrategy().getManagementAgent().getMBeanServer(); } http://git-wip-us.apache.org/repos/asf/camel/blob/542ab3e8/camel-core/src/test/java/org/apache/camel/management/MyDummyProcessor.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/management/MyDummyProcessor.java b/camel-core/src/test/java/org/apache/camel/management/MyDummyProcessor.java new file mode 100644 index 0000000..1a8ef4b --- /dev/null +++ b/camel-core/src/test/java/org/apache/camel/management/MyDummyProcessor.java @@ -0,0 +1,28 @@ +/** + * 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.Exchange; +import org.apache.camel.Processor; + +public class MyDummyProcessor implements Processor { + + @Override + public void process(Exchange exchange) throws Exception { + exchange.getIn().setBody("Bye World"); + } +}