You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2019/12/11 10:48:39 UTC

[GitHub] [camel-kafka-connector] omarsmak commented on a change in pull request #36: Adds support for ElasticSearch index operation + tests

omarsmak commented on a change in pull request #36: Adds support for ElasticSearch index operation + tests
URL: https://github.com/apache/camel-kafka-connector/pull/36#discussion_r356521738
 
 

 ##########
 File path: core/src/main/java/org/apache/camel/kafkaconnector/converters/ElasticSearchTransformer.java
 ##########
 @@ -0,0 +1,68 @@
+/*
+ * 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.kafkaconnector.converters;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.kafka.common.config.ConfigDef;
+import org.apache.kafka.connect.connector.ConnectRecord;
+import org.apache.kafka.connect.data.Schema;
+import org.apache.kafka.connect.transforms.Transformation;
+
+public class ElasticSearchTransformer <R extends ConnectRecord<R>> implements Transformation<R> {
+
+    public static final ConfigDef CONFIG_DEF = new ConfigDef()
+            .define("test", ConfigDef.Type.STRING, "test", ConfigDef.Importance.MEDIUM,
+                    "Transforms String-based content from Kafka into a map");
+
+    private String key;
+
+    @Override
+    public R apply(R r) {
+        Map<String, Object> targetMap = new HashMap<>();
+
+        targetMap.put(key, r.value());
+        return r.newRecord(r.topic(), r.kafkaPartition(), null, r.key(), Schema.STRING_SCHEMA, targetMap, r.timestamp());
+    }
+
+    @Override
+    public ConfigDef config() {
+        return CONFIG_DEF;
+    }
+
+    @Override
+    public void close() {
+
+    }
+
+    @Override
+    public void configure(Map<String, ?> map) {
+        Object keyObjectValue = map.get("key");
+
+        if (keyObjectValue == null) {
+            throw new UnsupportedOperationException("The ElasticSearch transformer requires a 'key'");
 
 Review comment:
   I'd prefer to throw here `ConfigException` since it inherits from `ConnectException` that can make the connector goes into halt 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services