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/7093be11
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/7093be11
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/7093be11

Branch: refs/heads/master
Commit: 7093be11afbebdec0689f6fdedda6167e8a39391
Parents: 72a06ac
Author: Claus Ibsen <davscl...@apache.org>
Authored: Fri Jul 24 13:16:36 2015 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Fri Jul 24 13:16:36 2015 +0200

----------------------------------------------------------------------
 .../mbean/ManagedCustomLoadBalancerMBean.java   | 29 +++++++
 .../mbean/ManagedFailoverLoadBalancerMBean.java | 35 ++++++++
 .../DefaultManagementObjectStrategy.java        |  4 +
 .../mbean/ManagedCustomLoadBalancer.java        | 47 ++++++++++
 .../mbean/ManagedFailoverLoadBalancer.java      | 56 ++++++++++++
 .../ManagedFailoverLoadBalancerTest.java        | 91 ++++++++++++++++++++
 6 files changed, 262 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/7093be11/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCustomLoadBalancerMBean.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCustomLoadBalancerMBean.java
 
b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCustomLoadBalancerMBean.java
new file mode 100644
index 0000000..47ae3c1
--- /dev/null
+++ 
b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCustomLoadBalancerMBean.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 ManagedCustomLoadBalancerMBean extends ManagedProcessorMBean {
+
+    @ManagedAttribute(description = "The custom load balancer class name")
+    String getCustomLoadBalancerClassName();
+
+    @ManagedAttribute(description = "Number of processors in the load 
balancer")
+    Integer getSize();
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/7093be11/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedFailoverLoadBalancerMBean.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedFailoverLoadBalancerMBean.java
 
b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedFailoverLoadBalancerMBean.java
new file mode 100644
index 0000000..3badab1
--- /dev/null
+++ 
b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedFailoverLoadBalancerMBean.java
@@ -0,0 +1,35 @@
+/**
+ * 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 ManagedFailoverLoadBalancerMBean extends 
ManagedProcessorMBean {
+
+    @ManagedAttribute(description = "Number of processors in the load 
balancer")
+    Integer getSize();
+
+    @ManagedAttribute(description = "Whether or not the failover load balancer 
should operate in round robin mode or not.")
+    Boolean isRoundRobin();
+
+    @ManagedAttribute(description = "Whether or not the failover load balancer 
should operate in sticky mode or not.")
+    Boolean isSticky();
+
+    @ManagedAttribute(description = "A value to indicate after X failover 
attempts we should exhaust (give up).")
+    Integer getMaximumFailoverAttempts();
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/7093be11/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 27669f7..20a0f33 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
@@ -46,6 +46,7 @@ import org.apache.camel.management.mbean.ManagedEndpoint;
 import org.apache.camel.management.mbean.ManagedEnricher;
 import org.apache.camel.management.mbean.ManagedErrorHandler;
 import org.apache.camel.management.mbean.ManagedEventNotifier;
+import org.apache.camel.management.mbean.ManagedFailoverLoadBalancer;
 import org.apache.camel.management.mbean.ManagedFilter;
 import org.apache.camel.management.mbean.ManagedIdempotentConsumer;
 import org.apache.camel.management.mbean.ManagedLog;
@@ -138,6 +139,7 @@ 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;
+import org.apache.camel.processor.loadbalancer.FailOverLoadBalancer;
 import org.apache.camel.processor.loadbalancer.RandomLoadBalancer;
 import org.apache.camel.processor.loadbalancer.RoundRobinLoadBalancer;
 import org.apache.camel.processor.loadbalancer.StickyLoadBalancer;
@@ -295,6 +297,8 @@ public class DefaultManagementObjectStrategy implements 
ManagementObjectStrategy
                 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 FailOverLoadBalancer) {
+                answer = new ManagedFailoverLoadBalancer(context, 
(FailOverLoadBalancer) target, (org.apache.camel.model.LoadBalanceDefinition) 
definition);
             } else if (target instanceof RandomLoadBalancer) {
                 answer = new ManagedRandomLoadBalancer(context, 
(RandomLoadBalancer) target, (org.apache.camel.model.LoadBalanceDefinition) 
definition);
             } else if (target instanceof RoundRobinLoadBalancer) {

http://git-wip-us.apache.org/repos/asf/camel/blob/7093be11/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCustomLoadBalancer.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCustomLoadBalancer.java
 
b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCustomLoadBalancer.java
new file mode 100644
index 0000000..d101c72
--- /dev/null
+++ 
b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCustomLoadBalancer.java
@@ -0,0 +1,47 @@
+/**
+ * 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.ManagedCustomLoadBalancerMBean;
+import org.apache.camel.model.LoadBalanceDefinition;
+import org.apache.camel.processor.loadbalancer.LoadBalancer;
+import org.apache.camel.util.ObjectHelper;
+
+/**
+ * @version 
+ */
+@ManagedResource(description = "Managed Custom LoadBalancer")
+public class ManagedCustomLoadBalancer extends ManagedProcessor implements 
ManagedCustomLoadBalancerMBean {
+    private final LoadBalancer processor;
+
+    public ManagedCustomLoadBalancer(CamelContext context, LoadBalancer 
processor, LoadBalanceDefinition definition) {
+        super(context, processor, definition);
+        this.processor = processor;
+    }
+
+    @Override
+    public String getCustomLoadBalancerClassName() {
+        return ObjectHelper.className(processor);
+    }
+
+    @Override
+    public Integer getSize() {
+        return processor.getProcessors().size();
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/7093be11/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedFailoverLoadBalancer.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedFailoverLoadBalancer.java
 
b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedFailoverLoadBalancer.java
new file mode 100644
index 0000000..3b7bc1f
--- /dev/null
+++ 
b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedFailoverLoadBalancer.java
@@ -0,0 +1,56 @@
+/**
+ * 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.ManagedFailoverLoadBalancerMBean;
+import org.apache.camel.model.LoadBalanceDefinition;
+import org.apache.camel.processor.loadbalancer.FailOverLoadBalancer;
+
+/**
+ * @version 
+ */
+@ManagedResource(description = "Managed Failover LoadBalancer")
+public class ManagedFailoverLoadBalancer extends ManagedProcessor implements 
ManagedFailoverLoadBalancerMBean {
+    private final FailOverLoadBalancer processor;
+
+    public ManagedFailoverLoadBalancer(CamelContext context, 
FailOverLoadBalancer processor, LoadBalanceDefinition definition) {
+        super(context, processor, definition);
+        this.processor = processor;
+    }
+
+    @Override
+    public Integer getSize() {
+        return processor.getProcessors().size();
+    }
+
+    @Override
+    public Boolean isRoundRobin() {
+        return processor.isRoundRobin();
+    }
+
+    @Override
+    public Boolean isSticky() {
+        return processor.isSticky();
+    }
+
+    @Override
+    public Integer getMaximumFailoverAttempts() {
+        return processor.getMaximumFailoverAttempts();
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/7093be11/camel-core/src/test/java/org/apache/camel/management/ManagedFailoverLoadBalancerTest.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/management/ManagedFailoverLoadBalancerTest.java
 
b/camel-core/src/test/java/org/apache/camel/management/ManagedFailoverLoadBalancerTest.java
new file mode 100644
index 0000000..8e0898c
--- /dev/null
+++ 
b/camel-core/src/test/java/org/apache/camel/management/ManagedFailoverLoadBalancerTest.java
@@ -0,0 +1,91 @@
+/**
+ * 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 java.io.IOException;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.management.openmbean.TabularData;
+
+import org.apache.camel.ServiceStatus;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version 
+ */
+public class ManagedFailoverLoadBalancerTest extends ManagementTestSupport {
+
+    public void testManageFailoverLoadBalancer() 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();
+
+        // 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);
+
+        Integer size = (Integer) mbeanServer.getAttribute(on, "Size");
+        assertEquals(2, size.intValue());
+
+        Boolean roundRobin = (Boolean) mbeanServer.getAttribute(on, 
"RoundRobin");
+        assertEquals(true, roundRobin.booleanValue());
+
+        Boolean sticky = (Boolean) mbeanServer.getAttribute(on, "Sticky");
+        assertEquals(true, sticky.booleanValue());
+
+        Integer attempts = (Integer) mbeanServer.getAttribute(on, 
"MaximumFailoverAttempts");
+        assertEquals(3, attempts.intValue());
+
+        TabularData data = (TabularData) mbeanServer.invoke(on, "explain", new 
Object[]{false}, new String[]{"boolean"});
+        assertNotNull(data);
+        assertEquals(3, data.size());
+
+        data = (TabularData) mbeanServer.invoke(on, "explain", new 
Object[]{true}, new String[]{"boolean"});
+        assertNotNull(data);
+        assertEquals(5, data.size());
+
+        String json = (String) mbeanServer.invoke(on, "informationJson", null, 
null);
+        assertNotNull(json);
+        assertTrue(json.contains("\"description\": \"Balances message 
processing among a number of nodes"));
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    .loadBalance().failover(3, false, true, true, 
IOException.class).id("mysend")
+                        .to("mock:foo", "mock:bar");
+            }
+        };
+    }
+
+}

Reply via email to