Repository: camel
Updated Branches:
  refs/heads/master 0b5def5c4 -> 93bc28d7a


Fix for CAMEL-7605 Expose the component options for Camel Elasticsearch


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

Branch: refs/heads/master
Commit: 778c848c2f3265468158b0465f192ac9e3447439
Parents: b9764cd
Author: Kevin Earls <[email protected]>
Authored: Wed Jul 16 16:23:27 2014 +0200
Committer: Kevin Earls <[email protected]>
Committed: Wed Jul 16 16:23:27 2014 +0200

----------------------------------------------------------------------
 .../elasticsearch/ElasticsearchComponent.java   |  7 ++-
 .../ElasticsearchConfiguration.java             | 14 +++++
 .../elasticsearch/ElasticsearchEndpoint.java    | 30 +++++-----
 ...ponentConfigurationAndDocumentationTest.java | 58 ++++++++++++++++++++
 4 files changed, 93 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/778c848c/components/camel-elasticsearch/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchComponent.java
----------------------------------------------------------------------
diff --git 
a/components/camel-elasticsearch/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchComponent.java
 
b/components/camel-elasticsearch/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchComponent.java
index 6a1bed0..66423a0 100644
--- 
a/components/camel-elasticsearch/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchComponent.java
+++ 
b/components/camel-elasticsearch/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchComponent.java
@@ -20,18 +20,19 @@ import java.util.Map;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
-import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.impl.UriEndpointComponent;
 
 /**
  * Represents the component that manages {@link ElasticsearchEndpoint}.
  */
-public class ElasticsearchComponent extends DefaultComponent {
+public class ElasticsearchComponent extends UriEndpointComponent {
 
     public ElasticsearchComponent() {
+        super(ElasticsearchEndpoint.class);
     }
 
     public ElasticsearchComponent(CamelContext context) {
-        super(context);
+        super(context, ElasticsearchEndpoint.class);
     }
 
     protected Endpoint createEndpoint(String uri, String remaining, 
Map<String, Object> parameters) throws Exception {

http://git-wip-us.apache.org/repos/asf/camel/blob/778c848c/components/camel-elasticsearch/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchConfiguration.java
----------------------------------------------------------------------
diff --git 
a/components/camel-elasticsearch/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchConfiguration.java
 
b/components/camel-elasticsearch/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchConfiguration.java
index 8ed17d2..e1e8aa6 100644
--- 
a/components/camel-elasticsearch/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchConfiguration.java
+++ 
b/components/camel-elasticsearch/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchConfiguration.java
@@ -19,10 +19,14 @@ package org.apache.camel.component.elasticsearch;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.Map;
+
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.spi.UriParams;
 import org.elasticsearch.node.Node;
 import org.elasticsearch.node.NodeBuilder;
 import static org.elasticsearch.node.NodeBuilder.nodeBuilder;
 
+@UriParams
 public class ElasticsearchConfiguration {
 
     public static final String PARAM_OPERATION = "operation";
@@ -40,15 +44,25 @@ public class ElasticsearchConfiguration {
     private static final Integer DEFAULT_PORT = 9300;
 
     private URI uri;
+    @UriParam
     private String protocolType;
+    @UriParam
     private String authority;
+    @UriParam
     private String clusterName;
+    @UriParam
     private String indexName;
+    @UriParam
     private String indexType;
+    @UriParam
     private boolean local;
+    @UriParam
     private Boolean data;
+    @UriParam
     private String operation;
+    @UriParam
     private String ip;
+    @UriParam
     private Integer port;
 
     public ElasticsearchConfiguration(URI uri, Map<String, Object> parameters) 
throws Exception {

http://git-wip-us.apache.org/repos/asf/camel/blob/778c848c/components/camel-elasticsearch/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchEndpoint.java
----------------------------------------------------------------------
diff --git 
a/components/camel-elasticsearch/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchEndpoint.java
 
b/components/camel-elasticsearch/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchEndpoint.java
index d8af587..e88e93c 100644
--- 
a/components/camel-elasticsearch/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchEndpoint.java
+++ 
b/components/camel-elasticsearch/src/main/java/org/apache/camel/component/elasticsearch/ElasticsearchEndpoint.java
@@ -23,6 +23,8 @@ import org.apache.camel.Processor;
 import org.apache.camel.Producer;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.impl.DefaultEndpoint;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
 import org.elasticsearch.client.Client;
 import org.elasticsearch.client.transport.TransportClient;
 import org.elasticsearch.common.settings.ImmutableSettings;
@@ -35,17 +37,19 @@ import org.slf4j.LoggerFactory;
 /**
  * Represents an Elasticsearch endpoint.
  */
+@UriEndpoint(scheme = "elasticsearch")
 public class ElasticsearchEndpoint extends DefaultEndpoint {
 
     private static final Logger LOG = 
LoggerFactory.getLogger(ElasticsearchEndpoint.class);
 
     private Node node;
     private Client client;
-    private ElasticsearchConfiguration config;
+    @UriParam
+    private ElasticsearchConfiguration configuration;
 
     public ElasticsearchEndpoint(String uri, ElasticsearchComponent component, 
Map<String, Object> parameters) throws Exception {
         super(uri, component);
-        this.config = new ElasticsearchConfiguration(new URI(uri), parameters);
+        this.configuration = new ElasticsearchConfiguration(new URI(uri), 
parameters);
     }
 
     public Producer createProducer() throws Exception {
@@ -63,34 +67,34 @@ public class ElasticsearchEndpoint extends DefaultEndpoint {
     @Override
     protected void doStart() throws Exception {
         super.doStart();
-        if (config.isLocal()) {
+        if (configuration.isLocal()) {
             LOG.info("Starting local ElasticSearch server");
         } else {
-            LOG.info("Joining ElasticSearch cluster " + 
config.getClusterName());
+            LOG.info("Joining ElasticSearch cluster " + 
configuration.getClusterName());
         }
-        if (config.getIp() != null) {
-            LOG.info("REMOTE ELASTICSEARCH: {}", config.getIp());
+        if (configuration.getIp() != null) {
+            LOG.info("REMOTE ELASTICSEARCH: {}", configuration.getIp());
             Settings settings = ImmutableSettings.settingsBuilder()
-                    .put("cluster.name", config.getClusterName())
+                    .put("cluster.name", configuration.getClusterName())
                     .put("client.transport.ignore_cluster_name", false)
                     .put("node.client", true)
                     .put("client.transport.sniff", true)
                     .build();
             Client client = new TransportClient(settings)
-                    .addTransportAddress(new 
InetSocketTransportAddress(config.getIp(), config.getPort()));
+                    .addTransportAddress(new 
InetSocketTransportAddress(configuration.getIp(), configuration.getPort()));
             this.client = client;
         } else {
-            node = config.buildNode();
+            node = configuration.buildNode();
             client = node.client();
         }
     }
 
     @Override
     protected void doStop() throws Exception {
-        if (config.isLocal()) {
+        if (configuration.isLocal()) {
             LOG.info("Stopping local ElasticSearch server");
         } else {
-            LOG.info("Leaving ElasticSearch cluster " + 
config.getClusterName());
+            LOG.info("Leaving ElasticSearch cluster " + 
configuration.getClusterName());
         }
         client.close();
         node.close();
@@ -102,11 +106,11 @@ public class ElasticsearchEndpoint extends 
DefaultEndpoint {
     }
 
     public ElasticsearchConfiguration getConfig() {
-        return config;
+        return configuration;
     }
 
     public void setOperation(String operation) {
-        config.setOperation(operation);
+        configuration.setOperation(operation);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/778c848c/components/camel-elasticsearch/src/test/java/org/apache/camel/component/elasticsearch/ElasticsearchComponentConfigurationAndDocumentationTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-elasticsearch/src/test/java/org/apache/camel/component/elasticsearch/ElasticsearchComponentConfigurationAndDocumentationTest.java
 
b/components/camel-elasticsearch/src/test/java/org/apache/camel/component/elasticsearch/ElasticsearchComponentConfigurationAndDocumentationTest.java
new file mode 100644
index 0000000..2acddb0
--- /dev/null
+++ 
b/components/camel-elasticsearch/src/test/java/org/apache/camel/component/elasticsearch/ElasticsearchComponentConfigurationAndDocumentationTest.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.component.elasticsearch;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ComponentConfiguration;
+import org.apache.camel.EndpointConfiguration;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class ElasticsearchComponentConfigurationAndDocumentationTest extends 
CamelTestSupport {
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    @Test
+    public void testComponentConfiguration() throws Exception {
+        ElasticsearchComponent comp = context.getComponent("elasticsearch", 
ElasticsearchComponent.class);
+        EndpointConfiguration conf = 
comp.createConfiguration("elasticsearch://clustername?operation=INDEX&indexName=twitter&indexType=tweet&ip=127.0.0.1");
+
+        assertEquals("INDEX", conf.getParameter("operation"));
+        assertEquals("tweet", conf.getParameter("indexType"));
+
+        ComponentConfiguration compConf = comp.createComponentConfiguration();
+        String json = compConf.createParameterJsonSchema();
+        assertNotNull(json);
+
+        assertTrue(json.contains("\"indexName\": { \"type\": 
\"java.lang.String\" }"));
+        assertTrue(json.contains("\"local\": { \"type\": \"boolean\" }"));
+    }
+
+    @Test
+    public void testComponentDocumentation() throws Exception {
+        CamelContext context = new DefaultCamelContext();
+        String html = context.getComponentDocumentation("elasticsearch");
+        assertNotNull("Should have found some auto-generated HTML if on Java 
7", html);
+        assertTrue("Expected entry for clusterName", 
html.contains("<td>clusterName</td>"));
+        assertTrue("Expected entry for protocolType", 
html.contains("<td>protocolType</td>"));
+    }
+
+}

Reply via email to