camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [26/29] camel git commit: CAMEL-7999: apt compiler to generate json schema documentation for the model, whcih we later use to enrich the xml xsd to include documentation. Work in progress.
Date Tue, 30 Dec 2014 10:42:42 GMT
CAMEL-7999: apt compiler to generate json schema documentation for the model, whcih we later
use to enrich the xml xsd to include documentation. Work in progress.


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

Branch: refs/heads/master
Commit: 03067ae66153c5b94d91870bf5a7139d9b57658b
Parents: a371de7
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Mon Dec 29 17:42:12 2014 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Tue Dec 30 10:56:47 2014 +0100

----------------------------------------------------------------------
 .../java/org/apache/camel/CamelContext.java     |   5 +-
 .../mbean/ManagedCamelContextMBean.java         |   6 +-
 .../apache/camel/impl/DefaultCamelContext.java  | 127 ++++++++++++++++++-
 .../management/mbean/ManagedCamelContext.java   |   4 +-
 .../management/mbean/ManagedProcessor.java      |   2 +-
 5 files changed, 128 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/03067ae6/camel-core/src/main/java/org/apache/camel/CamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/CamelContext.java b/camel-core/src/main/java/org/apache/camel/CamelContext.java
index 28955c0..5cd61b3 100644
--- a/camel-core/src/main/java/org/apache/camel/CamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/CamelContext.java
@@ -1410,12 +1410,11 @@ public interface CamelContext extends SuspendableService, RuntimeConfiguration
{
     /**
      * Returns a JSON schema representation of the EIP parameters for the given EIP by its
id.
      *
-     * @param eipName the name of the EIP ({@link NamedNode#getShortName()}
-     * @param id optional id of an EIP in use from any of the routes to explain
+     * @param nameOrId the name of the EIP ({@link NamedNode#getShortName()} or a node id
to refer to a specific node in the routes.
      * @param includeAllOptions whether to include non configured options also (eg default
options)
      * @return the json or <tt>null</tt> if the eipName or the id was not found
      */
-    String explainEipJson(String eipName, String id, boolean includeAllOptions);
+    String explainEipJson(String nameOrId, boolean includeAllOptions);
 
     /**
      * Returns a JSON schema representation of the endpoint parameters for the given endpoint
uri.

http://git-wip-us.apache.org/repos/asf/camel/blob/03067ae6/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
index 448cacd..ba6ce75 100644
--- a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
+++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
@@ -21,7 +21,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.concurrent.TimeUnit;
-
 import javax.management.openmbean.TabularData;
 
 import org.apache.camel.api.management.ManagedAttribute;
@@ -253,13 +252,12 @@ public interface ManagedCamelContextMBean extends ManagedPerformanceCounterMBean
     /**
      * Returns a JSON schema representation of the EIP parameters for the given EIP by its
id.
      *
-     * @param eipName the name of the EIP ({@link org.apache.camel.NamedNode#getShortName()}
-     * @param id optional id of an EIP in use from any of the routes to explain
+     * @param nameOrId the name of the EIP ({@link org.apache.camel.NamedNode#getShortName()}
or a node id to refer to a specific node in the routes.
      * @param includeAllOptions whether to include non configured options also (eg default
options)
      * @return the json or <tt>null</tt> if the eipName or the id was not found
      */
     @ManagedOperation(description = "Returns a JSON schema representation of the EIP parameters
for the given EIP by its id")
-    String explainEipJson(String eipName, String id, boolean includeAllOptions);
+    String explainEipJson(String nameOrId, boolean includeAllOptions);
 
     /**
      * Returns a JSON schema representation of the endpoint parameters for the given endpoint
uri

http://git-wip-us.apache.org/repos/asf/camel/blob/03067ae6/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 5d8dc95..6a41243 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
@@ -51,6 +51,7 @@ import org.apache.camel.ErrorHandlerFactory;
 import org.apache.camel.FailedToStartRouteException;
 import org.apache.camel.IsSingleton;
 import org.apache.camel.MultipleConsumersSupport;
+import org.apache.camel.NamedNode;
 import org.apache.camel.NoFactoryAvailableException;
 import org.apache.camel.NoSuchEndpointException;
 import org.apache.camel.PollingConsumer;
@@ -82,7 +83,10 @@ import org.apache.camel.management.JmxSystemPropertyKeys;
 import org.apache.camel.management.ManagementStrategyFactory;
 import org.apache.camel.model.Constants;
 import org.apache.camel.model.DataFormatDefinition;
+import org.apache.camel.model.FromDefinition;
 import org.apache.camel.model.ModelCamelContext;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.model.ProcessorDefinitionHelper;
 import org.apache.camel.model.RouteDefinition;
 import org.apache.camel.model.RouteDefinitionHelper;
 import org.apache.camel.model.RoutesDefinition;
@@ -1180,21 +1184,132 @@ public class DefaultCamelContext extends ServiceSupport implements
ModelCamelCon
         return null;
     }
 
-    public String explainEipJson(String eipName, String id, boolean includeAllOptions) {
+    public String explainEipJson(String nameOrId, boolean includeAllOptions) {
         try {
-            // TODO: if eipName is null, then we can find it from the id if its found
-            // and use the getShortName to find the eipName
+            // try to find the id within all known routes and their eips
+            String eipName = nameOrId;
+            NamedNode target = null;
+            for (RouteDefinition route : getRouteDefinitions()) {
+                if (route.getId().equals(nameOrId)) {
+                    target = route;
+                    break;
+                }
+                for (FromDefinition from : route.getInputs()) {
+                    if (nameOrId.equals(from.getId())) {
+                        target = route;
+                        break;
+                    }
+                }
+                Iterator<ProcessorDefinition> it = ProcessorDefinitionHelper.filterTypeInOutputs(route.getOutputs(),
ProcessorDefinition.class);
+                while (it.hasNext()) {
+                    ProcessorDefinition def = it.next();
+                    if (nameOrId.equals(def.getId())) {
+                        target = def;
+                        break;
+                    }
+                }
+                if (target != null) {
+                    break;
+                }
+            }
+
+            if (target != null) {
+                eipName = target.getShortName();
+            }
+
             String json = getEipParameterJsonSchema(eipName);
             if (json == null) {
                 return null;
             }
 
-            return json;
+            // overlay with runtime parameters that id uses at runtime
+            if (target != null) {
+                List<Map<String, String>> rows = JsonSchemaHelper.parseJsonSchema("properties",
json, true);
 
-            // TODO: overlay with runtime parameters that id uses at runtime
+                // selected rows to use for answer
+                Map<String, String[]> selected = new LinkedHashMap<String, String[]>();
 
-            //List<Map<String, String>> rows = JsonSchemaHelper.parseJsonSchema("properties",
json, true);
+                // extract options from the node
+                Map<String, Object> options = new LinkedHashMap<String, Object>();
+                IntrospectionSupport.getProperties(target, options, "", false);
 
+                // include other rows
+                for (Map<String, String> row : rows) {
+                    String name = row.get("name");
+                    String kind = row.get("kind");
+                    String value = row.get("value");
+                    String defaultValue = row.get("defaultValue");
+                    String type = row.get("type");
+                    String javaType = row.get("javaType");
+                    String description = row.get("description");
+
+                    // find the configured option
+                    Object o = options.get(name);
+                    if (o != null) {
+                        value = o.toString();
+                    }
+
+                    value = URISupport.sanitizePath(value);
+
+                    if (includeAllOptions || o != null) {
+                        // add as selected row
+                        if (!selected.containsKey(name)) {
+                            selected.put(name, new String[]{name, kind, type, javaType, value,
defaultValue, description});
+                        }
+                    }
+                }
+
+                StringBuilder buffer = new StringBuilder("{\n  \"properties\": {");
+
+                boolean first = true;
+                for (String[] row : selected.values()) {
+                    if (first) {
+                        first = false;
+                    } else {
+                        buffer.append(",");
+                    }
+                    buffer.append("\n    ");
+
+                    String name = row[0];
+                    String kind = row[1];
+                    String type = row[2];
+                    String javaType = row[3];
+                    String value = row[4];
+                    String defaultValue = row[5];
+                    String description = row[6];
+
+                    // add json of the option
+                    buffer.append(doubleQuote(name)).append(": { ");
+                    CollectionStringBuffer csb = new CollectionStringBuffer();
+                    if (kind != null) {
+                        csb.append("\"kind\": \"" + kind + "\"");
+                    }
+                    if (type != null) {
+                        csb.append("\"type\": \"" + type + "\"");
+                    }
+                    if (javaType != null) {
+                        csb.append("\"javaType\": \"" + javaType + "\"");
+                    }
+                    if (value != null) {
+                        csb.append("\"value\": \"" + value + "\"");
+                    }
+                    if (defaultValue != null) {
+                        csb.append("\"defaultValue\": \"" + defaultValue + "\"");
+                    }
+                    if (description != null) {
+                        csb.append("\"description\": \"" + description + "\"");
+                    }
+                    if (!csb.isEmpty()) {
+                        buffer.append(csb.toString());
+                    }
+                    buffer.append(" }");
+                }
+
+                buffer.append("\n  }\n}\n");
+                return buffer.toString();
+            }
+
+            return json;
         } catch (Exception e) {
             // ignore and return empty response
             return null;

http://git-wip-us.apache.org/repos/asf/camel/blob/03067ae6/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 c8868fe..7ebaeb0 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
@@ -573,8 +573,8 @@ public class ManagedCamelContext extends ManagedPerformanceCounter implements
Ti
         return context.getEipParameterJsonSchema(eipName);
     }
 
-    public String explainEipJson(String eipName, String id, boolean includeAllOptions) {
-        return context.explainEipJson(eipName, id, includeAllOptions);
+    public String explainEipJson(String nameOrId, boolean includeAllOptions) {
+        return context.explainEipJson(nameOrId, includeAllOptions);
     }
 
     public String explainEndpointJson(String uri, boolean includeAllOptions) throws Exception
{

http://git-wip-us.apache.org/repos/asf/camel/blob/03067ae6/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedProcessor.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedProcessor.java
b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedProcessor.java
index b38a6cc..f2d8804 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedProcessor.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedProcessor.java
@@ -139,7 +139,7 @@ public class ManagedProcessor extends ManagedPerformanceCounter implements
Manag
 
     public TabularData explain(boolean allOptions) {
         try {
-            String json = context.explainEipJson(definition.getShortName(), id, allOptions);
+            String json = context.explainEipJson(id, allOptions);
             List<Map<String, String>> rows = JsonSchemaHelper.parseJsonSchema("properties",
json, true);
 
             TabularData answer = new TabularDataSupport(CamelOpenMBeanTypes.explainEipTabularType());


Mime
View raw message