camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/2] camel git commit: CAMEL-10970: RuntimeCamelCatalog - Add JMX api
Date Thu, 09 Mar 2017 16:49:17 GMT
Repository: camel
Updated Branches:
  refs/heads/master 3c4c881b0 -> f51df7039


CAMEL-10970: RuntimeCamelCatalog - Add JMX api


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/6135ba9e
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/6135ba9e
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/6135ba9e

Branch: refs/heads/master
Commit: 6135ba9e6ab2c512cf5ffd678f603fae4194ae21
Parents: 3c4c881
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Thu Mar 9 17:08:48 2017 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Thu Mar 9 17:08:48 2017 +0100

----------------------------------------------------------------------
 .../mbean/ManagedRuntimeCamelCatalogMBean.java  | 35 +++++++++++
 .../catalog/DefaultRuntimeCamelCatalog.java     | 10 ++++
 .../camel/catalog/RuntimeCamelCatalog.java      | 26 +-------
 .../apache/camel/impl/DefaultCamelContext.java  |  1 +
 .../DefaultManagementLifecycleStrategy.java     |  4 ++
 .../management/ManagedManagementStrategy.java   |  1 +
 .../mbean/ManagedRuntimeCamelCatalog.java       | 62 ++++++++++++++++++++
 .../ManagedNonManagedServiceTest.java           |  4 +-
 ...roducerRouteAddRemoveRegisterAlwaysTest.java |  2 +-
 .../management/ManagedRouteAddRemoveTest.java   |  2 +-
 .../ManagedRuntimeCamelCatalogTest.java         | 58 ++++++++++++++++++
 11 files changed, 178 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/6135ba9e/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedRuntimeCamelCatalogMBean.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedRuntimeCamelCatalogMBean.java
b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedRuntimeCamelCatalogMBean.java
new file mode 100644
index 0000000..d992292
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedRuntimeCamelCatalogMBean.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.ManagedOperation;
+
+public interface ManagedRuntimeCamelCatalogMBean {
+
+    @ManagedOperation(description = "Returns the component information as JSon format")
+    String componentJSonSchema(String name);
+
+    @ManagedOperation(description = "Returns the data format information as JSon format.")
+    String dataFormatJSonSchema(String name);
+
+    @ManagedOperation(description = "Returns the language information as JSon format")
+    String languageJSonSchema(String name);
+
+    @ManagedOperation(description = "Returns the model information as JSon format")
+    String modelJSonSchema(String name);
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/6135ba9e/camel-core/src/main/java/org/apache/camel/catalog/DefaultRuntimeCamelCatalog.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/catalog/DefaultRuntimeCamelCatalog.java
b/camel-core/src/main/java/org/apache/camel/catalog/DefaultRuntimeCamelCatalog.java
index 8579849..dd66c55 100644
--- a/camel-core/src/main/java/org/apache/camel/catalog/DefaultRuntimeCamelCatalog.java
+++ b/camel-core/src/main/java/org/apache/camel/catalog/DefaultRuntimeCamelCatalog.java
@@ -51,6 +51,16 @@ public class DefaultRuntimeCamelCatalog extends AbstractCamelCatalog implements
     }
 
     @Override
+    public void start() throws Exception {
+        // noop
+    }
+
+    @Override
+    public void stop() throws Exception {
+        cache.clear();
+    }
+
+    @Override
     public String modelJSonSchema(String name) {
         String answer = null;
         if (caching) {

http://git-wip-us.apache.org/repos/asf/camel/blob/6135ba9e/camel-core/src/main/java/org/apache/camel/catalog/RuntimeCamelCatalog.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/catalog/RuntimeCamelCatalog.java b/camel-core/src/main/java/org/apache/camel/catalog/RuntimeCamelCatalog.java
index 6de1f17..c9abf30 100644
--- a/camel-core/src/main/java/org/apache/camel/catalog/RuntimeCamelCatalog.java
+++ b/camel-core/src/main/java/org/apache/camel/catalog/RuntimeCamelCatalog.java
@@ -19,10 +19,12 @@ package org.apache.camel.catalog;
 import java.net.URISyntaxException;
 import java.util.Map;
 
+import org.apache.camel.StaticService;
+
 /**
  * Runtime based CamelCatalog which are included in camel-core that can provided limit CamelCatalog
capabilities
  */
-public interface RuntimeCamelCatalog {
+public interface RuntimeCamelCatalog extends StaticService {
 
     /**
      * Returns the component information as JSon format.
@@ -199,28 +201,6 @@ public interface RuntimeCamelCatalog {
     String endpointComponentName(String uri);
 
     /**
-     * Creates an endpoint uri in Java style from the information in the json schema
-     *
-     * @param scheme the endpoint schema
-     * @param json the json schema with the endpoint properties
-     * @param encode whether to URL encode the returned uri or not
-     * @return the constructed endpoint uri
-     * @throws java.net.URISyntaxException is thrown if there is encoding error
-     */
-    String asEndpointUri(String scheme, String json, boolean encode) throws URISyntaxException;
-
-    /**
-     * Creates an endpoint uri in XML style (eg escape & as &ampl;) from the information
in the json schema
-     *
-     * @param scheme the endpoint schema
-     * @param json the json schema with the endpoint properties
-     * @param encode whether to URL encode the returned uri or not
-     * @return the constructed endpoint uri
-     * @throws java.net.URISyntaxException is thrown if there is encoding error
-     */
-    String asEndpointUriXml(String scheme, String json, boolean encode) throws URISyntaxException;
-
-    /**
      * Creates an endpoint uri in Java style from the information from the properties
      *
      * @param scheme the endpoint schema

http://git-wip-us.apache.org/repos/asf/camel/blob/6135ba9e/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index 28ed39a..5df4dd8 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -3138,6 +3138,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
         addService(packageScanClassResolver, true, true);
         addService(restRegistry, true, true);
         addService(messageHistoryFactory, true, true);
+        addService(runtimeCamelCatalog, true, true);
         if (reloadStrategy != null) {
             log.info("Using ReloadStrategy: {}", reloadStrategy);
             addService(reloadStrategy, true, true);

http://git-wip-us.apache.org/repos/asf/camel/blob/6135ba9e/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
b/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
index 4ab9ab9..e9e8bb8 100644
--- a/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
+++ b/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
@@ -46,6 +46,7 @@ import org.apache.camel.StartupListener;
 import org.apache.camel.TimerListener;
 import org.apache.camel.VetoCamelContextStartException;
 import org.apache.camel.api.management.PerformanceCounter;
+import org.apache.camel.catalog.RuntimeCamelCatalog;
 import org.apache.camel.impl.ConsumerCache;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.impl.DefaultEndpointRegistry;
@@ -66,6 +67,7 @@ import org.apache.camel.management.mbean.ManagedInflightRepository;
 import org.apache.camel.management.mbean.ManagedProducerCache;
 import org.apache.camel.management.mbean.ManagedRestRegistry;
 import org.apache.camel.management.mbean.ManagedRoute;
+import org.apache.camel.management.mbean.ManagedRuntimeCamelCatalog;
 import org.apache.camel.management.mbean.ManagedRuntimeEndpointRegistry;
 import org.apache.camel.management.mbean.ManagedService;
 import org.apache.camel.management.mbean.ManagedStreamCachingStrategy;
@@ -499,6 +501,8 @@ public class DefaultManagementLifecycleStrategy extends ServiceSupport
implement
             answer = new ManagedTransformerRegistry(context, (DefaultTransformerRegistry)service);
         } else if (service instanceof DefaultValidatorRegistry) {
             answer = new ManagedValidatorRegistry(context, (DefaultValidatorRegistry)service);
+        } else if (service instanceof RuntimeCamelCatalog) {
+            answer = new ManagedRuntimeCamelCatalog(context, (RuntimeCamelCatalog) service);
         } else if (service != null) {
             // fallback as generic service
             answer = getManagementObjectStrategy().getManagedObjectForService(context, service);

http://git-wip-us.apache.org/repos/asf/camel/blob/6135ba9e/camel-core/src/main/java/org/apache/camel/management/ManagedManagementStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/ManagedManagementStrategy.java
b/camel-core/src/main/java/org/apache/camel/management/ManagedManagementStrategy.java
index 58a6982..53e52f5 100644
--- a/camel-core/src/main/java/org/apache/camel/management/ManagedManagementStrategy.java
+++ b/camel-core/src/main/java/org/apache/camel/management/ManagedManagementStrategy.java
@@ -32,6 +32,7 @@ import org.apache.camel.management.mbean.ManagedEventNotifier;
 import org.apache.camel.management.mbean.ManagedProcessor;
 import org.apache.camel.management.mbean.ManagedProducer;
 import org.apache.camel.management.mbean.ManagedRoute;
+import org.apache.camel.management.mbean.ManagedRuntimeCamelCatalog;
 import org.apache.camel.management.mbean.ManagedService;
 import org.apache.camel.management.mbean.ManagedThreadPool;
 import org.apache.camel.management.mbean.ManagedTracer;

http://git-wip-us.apache.org/repos/asf/camel/blob/6135ba9e/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRuntimeCamelCatalog.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRuntimeCamelCatalog.java
b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRuntimeCamelCatalog.java
new file mode 100644
index 0000000..20d3f28
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRuntimeCamelCatalog.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.api.management.ManagedResource;
+import org.apache.camel.api.management.mbean.ManagedRuntimeCamelCatalogMBean;
+import org.apache.camel.catalog.RuntimeCamelCatalog;
+import org.apache.camel.spi.ManagementStrategy;
+
+/**
+ * @version 
+ */
+@ManagedResource(description = "Managed RuntimeCamelCatalog")
+public class ManagedRuntimeCamelCatalog extends ManagedService implements ManagedRuntimeCamelCatalogMBean
{
+    private final CamelContext camelContext;
+    private final RuntimeCamelCatalog camelCatalog;
+
+    public ManagedRuntimeCamelCatalog(CamelContext camelContext, RuntimeCamelCatalog camelCatalog)
{
+        super(camelContext, camelCatalog);
+        this.camelContext = camelContext;
+        this.camelCatalog = camelCatalog;
+    }
+
+    public void init(ManagementStrategy strategy) {
+        // do nothing
+    }
+
+    @Override
+    public String componentJSonSchema(String name) {
+        return camelCatalog.componentJSonSchema(name);
+    }
+
+    @Override
+    public String dataFormatJSonSchema(String name) {
+        return camelCatalog.dataFormatJSonSchema(name);
+    }
+
+    @Override
+    public String languageJSonSchema(String name) {
+        return camelCatalog.languageJSonSchema(name);
+    }
+
+    @Override
+    public String modelJSonSchema(String name) {
+        return camelCatalog.modelJSonSchema(name);
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/6135ba9e/camel-core/src/test/java/org/apache/camel/management/ManagedNonManagedServiceTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedNonManagedServiceTest.java
b/camel-core/src/test/java/org/apache/camel/management/ManagedNonManagedServiceTest.java
index b24957b..34c9cce 100644
--- a/camel-core/src/test/java/org/apache/camel/management/ManagedNonManagedServiceTest.java
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedNonManagedServiceTest.java
@@ -48,7 +48,7 @@ public class ManagedNonManagedServiceTest extends ManagementTestSupport
{
         MBeanServer mbeanServer = getMBeanServer();
 
         Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=services,*"),
null);
-        assertEquals(11, set.size());
+        assertEquals(12, set.size());
     }
 
     public void testNonManagedService() throws Exception {
@@ -69,7 +69,7 @@ public class ManagedNonManagedServiceTest extends ManagementTestSupport
{
         MBeanServer mbeanServer = getMBeanServer();
 
         Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=services,*"),
null);
-        assertEquals(10, set.size());
+        assertEquals(11, set.size());
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/camel/blob/6135ba9e/camel-core/src/test/java/org/apache/camel/management/ManagedProducerRouteAddRemoveRegisterAlwaysTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedProducerRouteAddRemoveRegisterAlwaysTest.java
b/camel-core/src/test/java/org/apache/camel/management/ManagedProducerRouteAddRemoveRegisterAlwaysTest.java
index b2b58e5..1b57d5a 100644
--- a/camel-core/src/test/java/org/apache/camel/management/ManagedProducerRouteAddRemoveRegisterAlwaysTest.java
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedProducerRouteAddRemoveRegisterAlwaysTest.java
@@ -29,7 +29,7 @@ import org.apache.camel.component.mock.MockEndpoint;
  */
 public class ManagedProducerRouteAddRemoveRegisterAlwaysTest extends ManagementTestSupport
{
 
-    private int services = 10;
+    private int services = 11;
 
     @Override
     protected CamelContext createCamelContext() throws Exception {

http://git-wip-us.apache.org/repos/asf/camel/blob/6135ba9e/camel-core/src/test/java/org/apache/camel/management/ManagedRouteAddRemoveTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedRouteAddRemoveTest.java
b/camel-core/src/test/java/org/apache/camel/management/ManagedRouteAddRemoveTest.java
index f4804a6..5429a1e 100644
--- a/camel-core/src/test/java/org/apache/camel/management/ManagedRouteAddRemoveTest.java
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedRouteAddRemoveTest.java
@@ -33,7 +33,7 @@ import org.apache.camel.component.mock.MockEndpoint;
  */
 public class ManagedRouteAddRemoveTest extends ManagementTestSupport {
     
-    private int services = 10;
+    private int services = 11;
 
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {

http://git-wip-us.apache.org/repos/asf/camel/blob/6135ba9e/camel-core/src/test/java/org/apache/camel/management/ManagedRuntimeCamelCatalogTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedRuntimeCamelCatalogTest.java
b/camel-core/src/test/java/org/apache/camel/management/ManagedRuntimeCamelCatalogTest.java
new file mode 100644
index 0000000..b49f9c8
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedRuntimeCamelCatalogTest.java
@@ -0,0 +1,58 @@
+/**
+ * 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 org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version 
+ */
+public class ManagedRuntimeCamelCatalogTest extends ManagementTestSupport {
+
+    public void testManagedRuntimeCatalog() throws Exception {
+        // JMX tests dont work well on AIX CI servers (hangs them)
+        if (isPlatform("aix")) {
+            return;
+        }
+
+        MBeanServer mbeanServer = getMBeanServer();
+
+        ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=services,name=DefaultRuntimeCamelCatalog");
+
+        assertTrue(mbeanServer.isRegistered(on));
+
+        String json = (String) mbeanServer.invoke(on, "componentJSonSchema", new Object[]{"log"},
new String[]{"java.lang.String"});
+        assertNotNull(json);
+
+        log.info(json);
+        assertTrue(json.contains("log:loggerName"));
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start").to("mock:result");
+            }
+        };
+    }
+
+}


Mime
View raw message