ashulin commented on code in PR #2821:
URL: 
https://github.com/apache/incubator-seatunnel/pull/2821#discussion_r980673469


##########
seatunnel-e2e/seatunnel-flink-connector-v2-e2e/connector-elasticsearch-flink-e2e/src/test/java/org/apache/seatunnel/e2e/flink/v2/elasticsearch/FakeSourceToElasticsearchIT.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.seatunnel.e2e.flink.v2.elasticsearch;
+
+import org.apache.seatunnel.e2e.flink.FlinkContainer;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testcontainers.containers.Container;
+import org.testcontainers.containers.output.Slf4jLogConsumer;
+import org.testcontainers.elasticsearch.ElasticsearchContainer;
+import org.testcontainers.utility.DockerImageName;
+
+import java.io.IOException;
+
+public class FakeSourceToElasticsearchIT extends FlinkContainer {
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(FakeSourceToElasticsearchIT.class);
+
+    private ElasticsearchContainer container;
+
+    @SuppressWarnings({"checkstyle:MagicNumber", "checkstyle:Indentation"})

Review Comment:
   ```suggestion
   ```
   IT will automatically ignore MagicNumber, please do not ignore the 
indentation.



##########
seatunnel-connectors-v2/connector-elasticsearch/src/main/java/org/apache/seatunnel/connectors/seatunnel/elasticsearch/source/ElasticsearchSourceSplitEnumerator.java:
##########
@@ -0,0 +1,116 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.elasticsearch.source;
+
+import org.apache.seatunnel.api.source.SourceSplitEnumerator;
+import 
org.apache.seatunnel.connectors.seatunnel.elasticsearch.client.EsRestClient;
+import 
org.apache.seatunnel.connectors.seatunnel.elasticsearch.config.source.SourceConfig;
+import 
org.apache.seatunnel.connectors.seatunnel.elasticsearch.config.source.SourceConfigDeaultConstant;
+import 
org.apache.seatunnel.connectors.seatunnel.elasticsearch.dto.source.IndexDocsCount;
+import 
org.apache.seatunnel.connectors.seatunnel.elasticsearch.dto.source.SourceIndexInfo;
+
+import org.apache.seatunnel.shade.com.typesafe.config.Config;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class ElasticsearchSourceSplitEnumerator implements 
SourceSplitEnumerator<ElasticsearchSourceSplit, ElasticsearchSourceState> {
+
+    private SourceSplitEnumerator.Context<ElasticsearchSourceSplit> 
enumeratorContext;
+
+    private Config pluginConfig;
+
+    private EsRestClient esRestClient;
+
+    public 
ElasticsearchSourceSplitEnumerator(SourceSplitEnumerator.Context<ElasticsearchSourceSplit>
 enumeratorContext, Config pluginConfig) {
+        this.enumeratorContext = enumeratorContext;
+        this.pluginConfig = pluginConfig;
+    }
+
+    @Override
+    public void open() {
+        esRestClient = EsRestClient.createInstance(pluginConfig);
+    }
+
+    @Override
+    public void run() throws Exception {
+
+    }
+
+    @Override
+    public void close() throws IOException {
+        esRestClient.close();
+    }
+
+    @Override
+    public void addSplitsBack(List<ElasticsearchSourceSplit> splits, int 
subtaskId) {
+
+    }
+
+    @Override
+    public int currentUnassignedSplitSize() {
+        return 0;
+    }
+
+    @Override
+    public void handleSplitRequest(int subtaskId) {
+
+    }
+
+    @Override
+    public void registerReader(int subtaskId) {
+        String scrolllTime = SourceConfigDeaultConstant.SCROLLL_TIME;
+        if (pluginConfig.hasPath(SourceConfig.SCROLL_TIME)) {
+            scrolllTime = pluginConfig.getString(SourceConfig.SCROLL_TIME);
+        }
+        int scrollSize = SourceConfigDeaultConstant.SCROLLL_SIZE;
+        if (pluginConfig.hasPath(SourceConfig.SCROLL_SIZE)) {
+            scrollSize = pluginConfig.getInt(SourceConfig.SCROLL_SIZE);
+        }
+
+        List<IndexDocsCount> indexDocsCounts = 
esRestClient.getIndexDocsCount(pluginConfig.getString(SourceConfig.INDEX));
+        indexDocsCounts = indexDocsCounts.stream().filter(x -> 
x.getDocsCount() != null && x.getDocsCount() > 0)
+                
.sorted(Comparator.comparingLong(IndexDocsCount::getDocsCount)).collect(Collectors.toList());
+        List<ElasticsearchSourceSplit> splits = new ArrayList<>();
+        int parallelism = enumeratorContext.currentParallelism();

Review Comment:
   `EnumeratorContext.currentParallelism()` is Runtime Method, Use it in 
`SplitEnumerator#run()`



##########
seatunnel-connectors-v2/connector-elasticsearch/src/main/java/org/apache/seatunnel/connectors/seatunnel/elasticsearch/source/ElasticsearchSourceReader.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.elasticsearch.source;
+
+import org.apache.seatunnel.api.source.Collector;
+import org.apache.seatunnel.api.source.SourceReader;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import 
org.apache.seatunnel.connectors.seatunnel.elasticsearch.client.EsRestClient;
+import 
org.apache.seatunnel.connectors.seatunnel.elasticsearch.dto.source.ScrollResult;
+import 
org.apache.seatunnel.connectors.seatunnel.elasticsearch.dto.source.SourceIndexInfo;
+
+import org.apache.seatunnel.shade.com.typesafe.config.Config;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Deque;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+public class ElasticsearchSourceReader implements SourceReader<SeaTunnelRow, 
ElasticsearchSourceSplit> {
+
+    protected static final Logger LOG = 
LoggerFactory.getLogger(ElasticsearchSourceReader.class);
+
+    SourceReader.Context context;
+
+    private Config pluginConfig;
+
+    private EsRestClient esRestClient;
+
+    Deque<ElasticsearchSourceSplit> splits = new LinkedList<>();
+    boolean noMoreSplit;
+
+    private final long pollNextWaitTime = 1000L;
+
+    public ElasticsearchSourceReader(SourceReader.Context context, Config 
pluginConfig) {
+        this.context = context;
+        this.pluginConfig = pluginConfig;
+    }
+
+    @Override
+    public void open() {
+        esRestClient = EsRestClient.createInstance(this.pluginConfig);
+    }
+
+    @Override
+    public void close() throws IOException {
+        esRestClient.close();
+    }
+
+    @Override
+    public void pollNext(Collector<SeaTunnelRow> output) throws Exception {
+        ElasticsearchSourceSplit split = splits.poll();
+        if (null != split) {
+            SourceIndexInfo sourceIndexInfo = split.getSourceIndexInfo();
+
+            ScrollResult scrollResult = 
esRestClient.searchByScroll(sourceIndexInfo.getIndex(), 
sourceIndexInfo.getSource(), sourceIndexInfo.getScrollTime(), 
sourceIndexInfo.getScrollSize());
+            outputFromScrollResult(scrollResult, sourceIndexInfo.getSource(), 
output);
+            while (scrollResult.getDocs() != null && 
scrollResult.getDocs().size() > 0) {
+                scrollResult = 
esRestClient.searchWithScrollId(scrollResult.getScrollId(), 
sourceIndexInfo.getScrollTime());
+                outputFromScrollResult(scrollResult, 
sourceIndexInfo.getSource(), output);
+            }

Review Comment:
   ```suggestion
               synchronized (output.getCheckpointLock()) {
                   ScrollResult scrollResult = 
esRestClient.searchByScroll(sourceIndexInfo.getIndex(), 
sourceIndexInfo.getSource(), sourceIndexInfo.getScrollTime(), 
sourceIndexInfo.getScrollSize());
                   outputFromScrollResult(scrollResult, 
sourceIndexInfo.getSource(), output);
                   while (scrollResult.getDocs() != null && 
scrollResult.getDocs().size() > 0) {
                       scrollResult = 
esRestClient.searchWithScrollId(scrollResult.getScrollId(), 
sourceIndexInfo.getScrollTime());
                       outputFromScrollResult(scrollResult, 
sourceIndexInfo.getSource(), output);
                   }
               }
   ```



##########
seatunnel-connectors-v2/connector-elasticsearch/src/main/java/org/apache/seatunnel/connectors/seatunnel/elasticsearch/dto/source/SourceIndexInfo.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * 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.seatunnel.connectors.seatunnel.elasticsearch.dto.source;
+
+import java.io.Serializable;
+import java.util.List;
+
+public class SourceIndexInfo implements Serializable {

Review Comment:
   ```suggestion
   @Data
   @AllArgsConstructor
   public class SourceIndexInfo implements Serializable {
   ```
   Please use lombok.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to