You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2022/03/29 16:59:45 UTC

[camel] 02/12: CAMEL-17792: Add doc about the message headers of camel-hbase

This is an automated email from the ASF dual-hosted git repository.

nfilotto pushed a commit to branch CAMEL-17792/doc-message-headers
in repository https://gitbox.apache.org/repos/asf/camel.git

commit 00df841a42748c3f0682bd0209695de589568901
Author: Nicolas Filotto <nf...@talend.com>
AuthorDate: Wed Mar 23 11:50:44 2022 +0100

    CAMEL-17792: Add doc about the message headers of camel-hbase
---
 .../resources/org/apache/camel/component/hbase/hbase.json |  9 +++++++++
 components/camel-hbase/src/main/docs/hbase-component.adoc | 12 +++++++-----
 .../org/apache/camel/component/hbase/HBaseConstants.java  | 15 +++++++++++++--
 .../org/apache/camel/component/hbase/HBaseConsumer.java   |  8 ++++----
 .../org/apache/camel/component/hbase/HBaseEndpoint.java   |  2 +-
 .../org/apache/camel/component/hbase/HBaseProducer.java   |  9 ++++-----
 .../hbase/mapping/CellMappingStrategyFactory.java         | 12 +++++-------
 7 files changed, 43 insertions(+), 24 deletions(-)

diff --git a/components/camel-hbase/src/generated/resources/org/apache/camel/component/hbase/hbase.json b/components/camel-hbase/src/generated/resources/org/apache/camel/component/hbase/hbase.json
index 5b44581..700b561 100644
--- a/components/camel-hbase/src/generated/resources/org/apache/camel/component/hbase/hbase.json
+++ b/components/camel-hbase/src/generated/resources/org/apache/camel/component/hbase/hbase.json
@@ -28,6 +28,15 @@
     "autowiredEnabled": { "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which t [...]
     "configuration": { "kind": "property", "displayName": "Configuration", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.apache.hadoop.conf.Configuration", "deprecated": false, "autowired": false, "secret": false, "description": "To use the shared configuration" }
   },
+  "headers": {
+    "CamelHBaseOperation": { "kind": "header", "displayName": "", "group": "producer", "label": "producer", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The HBase operation to perform" },
+    "CamelHBaseMaxScanResults": { "kind": "header", "displayName": "", "group": "producer", "label": "producer", "required": false, "javaType": "Integer", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The maximum number of rows to scan." },
+    "CamelHBaseStartRow": { "kind": "header", "displayName": "", "group": "producer", "label": "producer", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The row to start scanner at or after" },
+    "CamelHBaseStopRow": { "kind": "header", "displayName": "", "group": "producer", "label": "producer", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The row to end at (exclusive)" },
+    "CamelMappingStrategy": { "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The strategy to use for mapping Camel messages to HBase columns.\n\nSupported values:\n\n* header\n* body" },
+    "CamelMappingStrategyClassName": { "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The class name of a custom mapping strategy implementation." },
+    "CamelHBaseMarkedRowId": { "kind": "header", "displayName": "", "group": "consumer", "label": "consumer", "required": false, "javaType": "byte[]", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The marked row id" }
+  },
   "properties": {
     "tableName": { "kind": "path", "displayName": "Table Name", "group": "common", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The name of the table" },
     "cellMappingStrategyFactory": { "kind": "parameter", "displayName": "Cell Mapping Strategy Factory", "group": "common", "label": "", "required": false, "type": "object", "javaType": "org.apache.camel.component.hbase.mapping.CellMappingStrategyFactory", "deprecated": false, "autowired": false, "secret": false, "description": "To use a custom CellMappingStrategyFactory that is responsible for mapping cells." },
diff --git a/components/camel-hbase/src/main/docs/hbase-component.adoc b/components/camel-hbase/src/main/docs/hbase-component.adoc
index 6b7b123..1abd115 100644
--- a/components/camel-hbase/src/main/docs/hbase-component.adoc
+++ b/components/camel-hbase/src/main/docs/hbase-component.adoc
@@ -13,7 +13,7 @@
 
 *{component-header}*
 
-This component provides an idemptotent repository, producers and
+This component provides an idempotent repository, producers and
 consumers for http://hbase.apache.org/[Apache HBase].
 
 Maven users will need to add the following dependency to their `pom.xml`
@@ -39,8 +39,8 @@ http://hbase.apache.org[Apache HBase].
 
 == Camel and HBase
 
-When using a datasotre inside a camel route, there is always the
-chalenge of specifying how the camel message will stored to the
+When using a datastore inside a camel route, there is always the
+challenge of specifying how the camel message will store to the
 datastore. In document based stores things are more easy as the message
 body can be directly mapped to a document. In relational databases an
 ORM solution can be used to map properties to columns etc. In column
@@ -88,7 +88,7 @@ client configuration and dependencies]
 
 == HBase Producer
 
-As mentioned above camel provides produers endpoints for HBase. This
+As mentioned above camel provides producers endpoints for HBase. This
 allows you to store, delete, retrieve or query data from HBase using
 your camel routes.
 
@@ -118,7 +118,9 @@ include::partial$component-endpoint-options.adoc[]
 // endpoint options: START
 
 // endpoint options: END
-
+// component headers: START
+include::partial$component-endpoint-headers.adoc[]
+// component headers: END
 
 === Put Operations.
 
diff --git a/components/camel-hbase/src/main/java/org/apache/camel/component/hbase/HBaseConstants.java b/components/camel-hbase/src/main/java/org/apache/camel/component/hbase/HBaseConstants.java
index a1ce696..5a902d8 100644
--- a/components/camel-hbase/src/main/java/org/apache/camel/component/hbase/HBaseConstants.java
+++ b/components/camel-hbase/src/main/java/org/apache/camel/component/hbase/HBaseConstants.java
@@ -16,8 +16,11 @@
  */
 package org.apache.camel.component.hbase;
 
+import org.apache.camel.spi.Metadata;
+
 public interface HBaseConstants {
 
+    @Metadata(label = "producer", description = "The HBase operation to perform", javaType = "String")
     String OPERATION = "CamelHBaseOperation";
 
     String PUT = "CamelHBasePut";
@@ -25,9 +28,17 @@ public interface HBaseConstants {
     String SCAN = "CamelHBaseScan";
     String DELETE = "CamelHBaseDelete";
 
+    @Metadata(label = "producer", description = "The maximum number of rows to scan.", javaType = "Integer")
     String HBASE_MAX_SCAN_RESULTS = "CamelHBaseMaxScanResults";
-
+    @Metadata(label = "producer", description = "The row to start scanner at or after", javaType = "String")
     String FROM_ROW = "CamelHBaseStartRow";
-
+    @Metadata(label = "producer", description = "The row to end at (exclusive)", javaType = "String")
     String STOP_ROW = "CamelHBaseStopRow";
+    @Metadata(description = "The strategy to use for mapping Camel messages to HBase columns.\n\nSupported values:\n\n* header\n* body",
+              javaType = "String")
+    String STRATEGY = "CamelMappingStrategy";
+    @Metadata(description = "The class name of a custom mapping strategy implementation.", javaType = "String")
+    String STRATEGY_CLASS_NAME = "CamelMappingStrategyClassName";
+    @Metadata(label = "consumer", description = "The marked row id", javaType = "byte[]")
+    String HBASE_MARKED_ROW_ID = HBaseAttribute.HBASE_MARKED_ROW_ID.asHeader();
 }
diff --git a/components/camel-hbase/src/main/java/org/apache/camel/component/hbase/HBaseConsumer.java b/components/camel-hbase/src/main/java/org/apache/camel/component/hbase/HBaseConsumer.java
index 88b3b64..8ad4978 100644
--- a/components/camel-hbase/src/main/java/org/apache/camel/component/hbase/HBaseConsumer.java
+++ b/components/camel-hbase/src/main/java/org/apache/camel/component/hbase/HBaseConsumer.java
@@ -97,7 +97,7 @@ public class HBaseConsumer extends ScheduledBatchPollingConsumer {
             int exchangeCount = 0;
             // The next three statements are used just to get a reference to the BodyCellMappingStrategy instance.
             Exchange exchange = new DefaultExchange(endpoint);
-            exchange.getIn().setHeader(CellMappingStrategyFactory.STRATEGY, CellMappingStrategyFactory.BODY);
+            exchange.getIn().setHeader(HBaseConstants.STRATEGY, CellMappingStrategyFactory.BODY);
             CellMappingStrategy mappingStrategy = endpoint.getCellMappingStrategyFactory().getStrategy(exchange.getIn());
             for (Result result = scanner.next();
                  (exchangeCount < maxMessagesPerPoll || maxMessagesPerPoll <= 0) && result != null;
@@ -141,10 +141,10 @@ public class HBaseConsumer extends ScheduledBatchPollingConsumer {
                     data.getRows().add(resultRow);
                     exchange = createExchange(true);
                     // Probably overkill but kept it here for consistency.
-                    exchange.getIn().setHeader(CellMappingStrategyFactory.STRATEGY, CellMappingStrategyFactory.BODY);
+                    exchange.getIn().setHeader(HBaseConstants.STRATEGY, CellMappingStrategyFactory.BODY);
                     mappingStrategy.applyScanResults(exchange.getIn(), data);
                     //Make sure that there is a header containing the marked row ids, so that they can be deleted.
-                    exchange.getIn().setHeader(HBaseAttribute.HBASE_MARKED_ROW_ID.asHeader(), result.getRow());
+                    exchange.getIn().setHeader(HBaseConstants.HBASE_MARKED_ROW_ID, result.getRow());
                     queue.add(exchange);
                     exchangeCount++;
                 }
@@ -184,7 +184,7 @@ public class HBaseConsumer extends ScheduledBatchPollingConsumer {
             }
 
             if (endpoint.isRemove()) {
-                remove((byte[]) exchange.getIn().getHeader(HBaseAttribute.HBASE_MARKED_ROW_ID.asHeader()));
+                remove((byte[]) exchange.getIn().getHeader(HBaseConstants.HBASE_MARKED_ROW_ID));
             }
         }
 
diff --git a/components/camel-hbase/src/main/java/org/apache/camel/component/hbase/HBaseEndpoint.java b/components/camel-hbase/src/main/java/org/apache/camel/component/hbase/HBaseEndpoint.java
index 0db0d73..2576176 100644
--- a/components/camel-hbase/src/main/java/org/apache/camel/component/hbase/HBaseEndpoint.java
+++ b/components/camel-hbase/src/main/java/org/apache/camel/component/hbase/HBaseEndpoint.java
@@ -43,7 +43,7 @@ import org.apache.hadoop.security.UserGroupInformation;
  * Reading and write from/to an HBase store (Hadoop database).
  */
 @UriEndpoint(firstVersion = "2.10.0", scheme = "hbase", title = "HBase", syntax = "hbase:tableName",
-             category = { Category.BIGDATA, Category.DATABASE, Category.HADOOP })
+             category = { Category.BIGDATA, Category.DATABASE, Category.HADOOP }, headersClass = HBaseConstants.class)
 public class HBaseEndpoint extends DefaultEndpoint {
 
     @UriPath(description = "The name of the table")
diff --git a/components/camel-hbase/src/main/java/org/apache/camel/component/hbase/HBaseProducer.java b/components/camel-hbase/src/main/java/org/apache/camel/component/hbase/HBaseProducer.java
index 076ee6c..5a7a6bd 100644
--- a/components/camel-hbase/src/main/java/org/apache/camel/component/hbase/HBaseProducer.java
+++ b/components/camel-hbase/src/main/java/org/apache/camel/component/hbase/HBaseProducer.java
@@ -23,7 +23,6 @@ import java.util.Set;
 import org.apache.camel.Exchange;
 import org.apache.camel.component.hbase.filters.ModelAwareFilter;
 import org.apache.camel.component.hbase.mapping.CellMappingStrategy;
-import org.apache.camel.component.hbase.mapping.CellMappingStrategyFactory;
 import org.apache.camel.component.hbase.model.HBaseCell;
 import org.apache.camel.component.hbase.model.HBaseData;
 import org.apache.camel.component.hbase.model.HBaseRow;
@@ -278,13 +277,13 @@ public class HBaseProducer extends DefaultProducer {
                 exchange.getIn().setHeader(HBaseConstants.HBASE_MAX_SCAN_RESULTS, endpoint.getMaxResults());
             }
             if (endpoint.getMappingStrategyName() != null
-                    && exchange.getIn().getHeader(CellMappingStrategyFactory.STRATEGY) == null) {
-                exchange.getIn().setHeader(CellMappingStrategyFactory.STRATEGY, endpoint.getMappingStrategyName());
+                    && exchange.getIn().getHeader(HBaseConstants.STRATEGY) == null) {
+                exchange.getIn().setHeader(HBaseConstants.STRATEGY, endpoint.getMappingStrategyName());
             }
 
             if (endpoint.getMappingStrategyName() != null
-                    && exchange.getIn().getHeader(CellMappingStrategyFactory.STRATEGY_CLASS_NAME) == null) {
-                exchange.getIn().setHeader(CellMappingStrategyFactory.STRATEGY_CLASS_NAME,
+                    && exchange.getIn().getHeader(HBaseConstants.STRATEGY_CLASS_NAME) == null) {
+                exchange.getIn().setHeader(HBaseConstants.STRATEGY_CLASS_NAME,
                         endpoint.getMappingStrategyClassName());
             }
 
diff --git a/components/camel-hbase/src/main/java/org/apache/camel/component/hbase/mapping/CellMappingStrategyFactory.java b/components/camel-hbase/src/main/java/org/apache/camel/component/hbase/mapping/CellMappingStrategyFactory.java
index 0daa1928..212ce25 100644
--- a/components/camel-hbase/src/main/java/org/apache/camel/component/hbase/mapping/CellMappingStrategyFactory.java
+++ b/components/camel-hbase/src/main/java/org/apache/camel/component/hbase/mapping/CellMappingStrategyFactory.java
@@ -20,14 +20,12 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.camel.Message;
+import org.apache.camel.component.hbase.HBaseConstants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class CellMappingStrategyFactory {
 
-    public static final String STRATEGY = "CamelMappingStrategy";
-    public static final String STRATEGY_CLASS_NAME = "CamelMappingStrategyClassName";
-
     public static final String HEADER = "header";
     public static final String BODY = "body";
 
@@ -43,12 +41,12 @@ public class CellMappingStrategyFactory {
         CellMappingStrategy strategy = null;
 
         //Check if strategy has been explicitly set.
-        if (message.getHeader(STRATEGY) != null) {
-            strategy = DEFAULT_STRATEGIES.get(message.getHeader(STRATEGY, String.class));
+        if (message.getHeader(HBaseConstants.STRATEGY) != null) {
+            strategy = DEFAULT_STRATEGIES.get(message.getHeader(HBaseConstants.STRATEGY, String.class));
         }
 
-        if (strategy == null && message.getHeader(STRATEGY_CLASS_NAME) != null) {
-            strategy = loadStrategyFromClassName(message.getHeader(STRATEGY_CLASS_NAME, String.class));
+        if (strategy == null && message.getHeader(HBaseConstants.STRATEGY_CLASS_NAME) != null) {
+            strategy = loadStrategyFromClassName(message.getHeader(HBaseConstants.STRATEGY_CLASS_NAME, String.class));
         }
 
         if (strategy != null) {