Repository: camel Updated Branches: refs/heads/master 0b246429b -> 648c751bc
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/648c751b Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/648c751b Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/648c751b Branch: refs/heads/master Commit: 648c751bcade131ea13c9e639cf41ee45050495e Parents: 0b24642 Author: Claus Ibsen <davscl...@apache.org> Authored: Wed Jul 22 11:44:11 2015 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Wed Jul 22 11:44:11 2015 +0200 ---------------------------------------------------------------------- .../management/mbean/ManagedMarshalMBean.java | 26 ++++++ .../management/mbean/ManagedUnmarshalMBean.java | 26 ++++++ .../DefaultManagementObjectStrategy.java | 8 ++ .../camel/management/mbean/ManagedMarshal.java | 50 +++++++++++ .../management/mbean/ManagedUnmarshal.java | 50 +++++++++++ .../camel/management/ManagedMarshalTest.java | 94 ++++++++++++++++++++ .../camel/management/ManagedUnmarshalTest.java | 94 ++++++++++++++++++++ 7 files changed, 348 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/648c751b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedMarshalMBean.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedMarshalMBean.java b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedMarshalMBean.java new file mode 100644 index 0000000..f4c1300 --- /dev/null +++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedMarshalMBean.java @@ -0,0 +1,26 @@ +/** + * 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 ManagedMarshalMBean extends ManagedProcessorMBean { + + @ManagedAttribute(description = "The name of the DataFormat to use for marshal") + String getDataFormatName(); + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/648c751b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedUnmarshalMBean.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedUnmarshalMBean.java b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedUnmarshalMBean.java new file mode 100644 index 0000000..cc9c231 --- /dev/null +++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedUnmarshalMBean.java @@ -0,0 +1,26 @@ +/** + * 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 ManagedUnmarshalMBean extends ManagedProcessorMBean { + + @ManagedAttribute(description = "The name of the DataFormat to use for unmarshal") + String getDataFormatName(); + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/648c751b/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 b20525f..5470bb4 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 @@ -49,6 +49,7 @@ import org.apache.camel.management.mbean.ManagedFilter; import org.apache.camel.management.mbean.ManagedIdempotentConsumer; import org.apache.camel.management.mbean.ManagedLog; import org.apache.camel.management.mbean.ManagedLoop; +import org.apache.camel.management.mbean.ManagedMarshal; import org.apache.camel.management.mbean.ManagedMulticast; import org.apache.camel.management.mbean.ManagedPollEnricher; import org.apache.camel.management.mbean.ManagedProcess; @@ -82,6 +83,7 @@ import org.apache.camel.management.mbean.ManagedThrottler; import org.apache.camel.management.mbean.ManagedThroughputLogger; import org.apache.camel.management.mbean.ManagedThrowException; import org.apache.camel.management.mbean.ManagedTransformer; +import org.apache.camel.management.mbean.ManagedUnmarshal; import org.apache.camel.management.mbean.ManagedValidate; import org.apache.camel.management.mbean.ManagedWireTapProcessor; import org.apache.camel.model.ModelCamelContext; @@ -98,6 +100,7 @@ import org.apache.camel.processor.ExchangePatternProcessor; import org.apache.camel.processor.FilterProcessor; import org.apache.camel.processor.LogProcessor; import org.apache.camel.processor.LoopProcessor; +import org.apache.camel.processor.MarshalProcessor; import org.apache.camel.processor.MulticastProcessor; import org.apache.camel.processor.Pipeline; import org.apache.camel.processor.PollEnricher; @@ -124,6 +127,7 @@ import org.apache.camel.processor.Throttler; import org.apache.camel.processor.ThroughputLogger; import org.apache.camel.processor.ThrowExceptionProcessor; import org.apache.camel.processor.TransformProcessor; +import org.apache.camel.processor.UnmarshalProcessor; import org.apache.camel.processor.WireTapProcessor; import org.apache.camel.processor.aggregate.AggregateProcessor; import org.apache.camel.processor.idempotent.IdempotentConsumer; @@ -273,6 +277,10 @@ public class DefaultManagementObjectStrategy implements ManagementObjectStrategy answer = new ManagedLog(context, (LogProcessor) target, definition); } else if (target instanceof LoopProcessor) { answer = new ManagedLoop(context, (LoopProcessor) target, definition); + } else if (target instanceof MarshalProcessor) { + answer = new ManagedMarshal(context, (MarshalProcessor) target, (org.apache.camel.model.MarshalDefinition) definition); + } else if (target instanceof UnmarshalProcessor) { + answer = new ManagedUnmarshal(context, (UnmarshalProcessor) target, (org.apache.camel.model.UnmarshalDefinition) definition); } else if (target instanceof RecipientList) { answer = new ManagedRecipientList(context, (RecipientList) target, definition); } else if (target instanceof Splitter) { http://git-wip-us.apache.org/repos/asf/camel/blob/648c751b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedMarshal.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedMarshal.java b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedMarshal.java new file mode 100644 index 0000000..ea6e553 --- /dev/null +++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedMarshal.java @@ -0,0 +1,50 @@ +/** + * 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.api.management.ManagedResource; +import org.apache.camel.api.management.mbean.ManagedMarshalMBean; +import org.apache.camel.model.MarshalDefinition; +import org.apache.camel.processor.MarshalProcessor; + +/** + * @version + */ +@ManagedResource(description = "Managed Marshal") +public class ManagedMarshal extends ManagedProcessor implements ManagedMarshalMBean { + private final MarshalProcessor processor; + + public ManagedMarshal(CamelContext context, MarshalProcessor processor, MarshalDefinition definition) { + super(context, processor, definition); + this.processor = processor; + } + + @Override + public MarshalDefinition getDefinition() { + return (MarshalDefinition) super.getDefinition(); + } + + @Override + public String getDataFormatName() { + String name = getDefinition().getRef(); + if (name == null && getDefinition().getDataFormatType() != null) { + name = getDefinition().getDataFormatType().getDataFormatName(); + } + return name; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/648c751b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedUnmarshal.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedUnmarshal.java b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedUnmarshal.java new file mode 100644 index 0000000..f5b1fa6 --- /dev/null +++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedUnmarshal.java @@ -0,0 +1,50 @@ +/** + * 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.api.management.ManagedResource; +import org.apache.camel.api.management.mbean.ManagedUnmarshalMBean; +import org.apache.camel.model.UnmarshalDefinition; +import org.apache.camel.processor.UnmarshalProcessor; + +/** + * @version + */ +@ManagedResource(description = "Managed Unmarshal") +public class ManagedUnmarshal extends ManagedProcessor implements ManagedUnmarshalMBean { + private final UnmarshalProcessor processor; + + public ManagedUnmarshal(CamelContext context, UnmarshalProcessor processor, UnmarshalDefinition definition) { + super(context, processor, definition); + this.processor = processor; + } + + @Override + public UnmarshalDefinition getDefinition() { + return (UnmarshalDefinition) super.getDefinition(); + } + + @Override + public String getDataFormatName() { + String name = getDefinition().getRef(); + if (name == null && getDefinition().getDataFormatType() != null) { + name = getDefinition().getDataFormatType().getDataFormatName(); + } + return name; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/648c751b/camel-core/src/test/java/org/apache/camel/management/ManagedMarshalTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedMarshalTest.java b/camel-core/src/test/java/org/apache/camel/management/ManagedMarshalTest.java new file mode 100644 index 0000000..e9f38e6 --- /dev/null +++ b/camel-core/src/test/java/org/apache/camel/management/ManagedMarshalTest.java @@ -0,0 +1,94 @@ +/** + * 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; + +/** + * @version + */ +public class ManagedMarshalTest extends ManagementTestSupport { + + public void testManageMarshal() 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 name = (String) mbeanServer.getAttribute(on, "DataFormatName"); + assertEquals("string", name); + + String xml = (String) mbeanServer.invoke(on, "dumpProcessorAsXml", null, null); + assertTrue(xml.contains("<marshal")); + assertTrue(xml.contains("</marshal>")); + assertTrue(xml.contains("<string charset=\"iso-8859-1\"/>")); + + 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(4, data.size()); + + String json = (String) mbeanServer.invoke(on, "informationJson", null, null); + assertNotNull(json); + assertTrue(json.contains("\"description\": \"Marshals data into a specified format for transmission over a transport or component")); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start") + .marshal().string("iso-8859-1").id("mysend") + .to("mock:foo"); + } + }; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/648c751b/camel-core/src/test/java/org/apache/camel/management/ManagedUnmarshalTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedUnmarshalTest.java b/camel-core/src/test/java/org/apache/camel/management/ManagedUnmarshalTest.java new file mode 100644 index 0000000..da72319 --- /dev/null +++ b/camel-core/src/test/java/org/apache/camel/management/ManagedUnmarshalTest.java @@ -0,0 +1,94 @@ +/** + * 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; + +/** + * @version + */ +public class ManagedUnmarshalTest extends ManagementTestSupport { + + public void testManageUnmarshal() 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 name = (String) mbeanServer.getAttribute(on, "DataFormatName"); + assertEquals("string", name); + + String xml = (String) mbeanServer.invoke(on, "dumpProcessorAsXml", null, null); + assertTrue(xml.contains("<unmarshal")); + assertTrue(xml.contains("</unmarshal>")); + assertTrue(xml.contains("<string charset=\"iso-8859-1\"/>")); + + 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(4, data.size()); + + String json = (String) mbeanServer.invoke(on, "informationJson", null, null); + assertNotNull(json); + assertTrue(json.contains("\"description\": \"Converts the message data received from the wire into a format that Apache Camel processors can consume")); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start") + .unmarshal().string("iso-8859-1").id("mysend") + .to("mock:foo"); + } + }; + } + +}