KKcorps commented on a change in pull request #7026:
URL: https://github.com/apache/incubator-pinot/pull/7026#discussion_r648039321



##########
File path: 
pinot-plugins/pinot-stream-ingestion/pinot-pulsar/src/main/java/org/apache/pinot/plugin/stream/pulsar/PulsarConfig.java
##########
@@ -0,0 +1,98 @@
+/**
+ * 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.pinot.plugin.stream.pulsar;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import org.apache.pinot.spi.stream.StreamConfig;
+import org.apache.pinot.spi.stream.StreamConfigProperties;
+import org.apache.pulsar.client.api.MessageId;
+
+public class PulsarConfig {
+  public static final String STREAM_TYPE = "pulsar";
+  public static final String PULSAR_PROP_PREFIX = "consumer.prop";
+  public static final String BOOTSTRAP_SERVERS = "bootstrap.servers";
+  public static final String START_POSITION = "start_position";
+  public static final String DEFAULT_BOOTSTRAP_BROKERS = 
"pulsar://localhost:6650";
+
+  private String _pulsarTopicName;
+  private String _subscriberId;
+  private String _bootstrapServers;
+  private MessageId _initialMessageId = MessageId.latest;
+  private Map<String, String> _pulsarConsumerProperties;
+
+  public PulsarConfig(StreamConfig streamConfig, String subscriberId){
+    Map<String, String> streamConfigMap = streamConfig.getStreamConfigsMap();
+    _pulsarTopicName = streamConfig.getTopicName();
+    _bootstrapServers = streamConfigMap.getOrDefault(BOOTSTRAP_SERVERS, 
DEFAULT_BOOTSTRAP_BROKERS);

Review comment:
       done

##########
File path: 
pinot-plugins/pinot-stream-ingestion/pinot-pulsar/src/main/java/org/apache/pinot/plugin/stream/pulsar/PulsarConfig.java
##########
@@ -0,0 +1,98 @@
+/**
+ * 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.pinot.plugin.stream.pulsar;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import org.apache.pinot.spi.stream.StreamConfig;
+import org.apache.pinot.spi.stream.StreamConfigProperties;
+import org.apache.pulsar.client.api.MessageId;
+
+public class PulsarConfig {
+  public static final String STREAM_TYPE = "pulsar";
+  public static final String PULSAR_PROP_PREFIX = "consumer.prop";
+  public static final String BOOTSTRAP_SERVERS = "bootstrap.servers";
+  public static final String START_POSITION = "start_position";
+  public static final String DEFAULT_BOOTSTRAP_BROKERS = 
"pulsar://localhost:6650";
+
+  private String _pulsarTopicName;
+  private String _subscriberId;
+  private String _bootstrapServers;
+  private MessageId _initialMessageId = MessageId.latest;
+  private Map<String, String> _pulsarConsumerProperties;
+
+  public PulsarConfig(StreamConfig streamConfig, String subscriberId){
+    Map<String, String> streamConfigMap = streamConfig.getStreamConfigsMap();
+    _pulsarTopicName = streamConfig.getTopicName();
+    _bootstrapServers = streamConfigMap.getOrDefault(BOOTSTRAP_SERVERS, 
DEFAULT_BOOTSTRAP_BROKERS);
+    _subscriberId = subscriberId;
+
+    String startPositionProperty = 
StreamConfigProperties.constructStreamProperty(STREAM_TYPE, START_POSITION);
+    String startPosition = streamConfigMap.getOrDefault(startPositionProperty, 
"latest");
+    if(startPosition.equals("earliest")){
+      _initialMessageId =  MessageId.earliest;
+    } else if(startPosition.equals("latest")) {
+      _initialMessageId = MessageId.latest;
+    } else {
+      try {
+        _initialMessageId = MessageId.fromByteArray(startPosition.getBytes());
+      } catch (IOException e){
+        throw new RuntimeException("Invalid start position found: " + 
startPosition);
+      }
+    }
+
+    _pulsarConsumerProperties = new HashMap<>();
+
+    String pulsarConsumerPropertyPrefix =
+        StreamConfigProperties.constructStreamProperty(STREAM_TYPE, 
PULSAR_PROP_PREFIX);
+    for (String key : streamConfigMap.keySet()) {
+      if (key.startsWith(pulsarConsumerPropertyPrefix)) {
+        _pulsarConsumerProperties
+            .put(StreamConfigProperties.getPropertySuffix(key, 
pulsarConsumerPropertyPrefix), streamConfigMap.get(key));
+      }
+    }
+  }
+
+  public String getPulsarTopicName() {
+    return _pulsarTopicName;
+  }
+
+  public String getSubscriberId() {
+    return _subscriberId;
+  }
+
+  public String getBootstrapServers() {
+    return _bootstrapServers;
+  }
+
+  public Properties getPulsarConsumerProperties() {
+    Properties props = new Properties();
+    for (String key : _pulsarConsumerProperties.keySet()) {
+      props.put(key, _pulsarConsumerProperties.get(key));
+    }
+

Review comment:
       done

##########
File path: 
pinot-plugins/pinot-stream-ingestion/pinot-pulsar/src/main/java/org/apache/pinot/plugin/stream/pulsar/PulsarPartitionLevelConnectionHandler.java
##########
@@ -0,0 +1,77 @@
+/**
+ * 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.pinot.plugin.stream.pulsar;
+
+import com.google.common.annotations.VisibleForTesting;
+import java.io.IOException;
+import java.util.List;
+import org.apache.pinot.spi.stream.StreamConfig;
+import org.apache.pulsar.client.api.PulsarClient;
+import org.apache.pulsar.client.api.PulsarClientException;
+import org.apache.pulsar.client.api.Reader;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class PulsarPartitionLevelConnectionHandler {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(PulsarPartitionLevelConnectionHandler.class);
+
+  public static final String SEPERATOR = "-";
+  public static final String TOPIC_PARTITION_NAME_SUFFIX = "partition";

Review comment:
       removed

##########
File path: 
pinot-plugins/pinot-stream-ingestion/pinot-pulsar/src/main/java/org/apache/pinot/plugin/stream/pulsar/PulsarPartitionLevelConsumer.java
##########
@@ -0,0 +1,115 @@
+/**
+ * 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.pinot.plugin.stream.pulsar;
+
+import com.google.common.collect.Iterables;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import org.apache.pinot.spi.stream.MessageBatch;
+import org.apache.pinot.spi.stream.PartitionGroupConsumer;
+import org.apache.pinot.spi.stream.PartitionGroupConsumptionStatus;
+import org.apache.pinot.spi.stream.PartitionLevelConsumer;
+import org.apache.pinot.spi.stream.StreamConfig;
+import org.apache.pinot.spi.stream.StreamPartitionMsgOffset;
+import org.apache.pulsar.client.api.Message;
+import org.apache.pulsar.client.api.MessageId;
+import org.apache.pulsar.client.api.PulsarClientException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class PulsarPartitionLevelConsumer extends 
PulsarPartitionLevelConnectionHandler implements PartitionGroupConsumer {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(PulsarPartitionLevelConsumer.class);
+  private final ExecutorService _executorService;
+  private final PartitionGroupConsumptionStatus 
_partitionGroupConsumptionStatus;
+
+  public PulsarPartitionLevelConsumer(String clientId, StreamConfig 
streamConfig,
+      PartitionGroupConsumptionStatus partitionGroupConsumptionStatus) {
+    super(clientId, streamConfig, 
partitionGroupConsumptionStatus.getPartitionGroupId());
+    _partitionGroupConsumptionStatus = partitionGroupConsumptionStatus;
+    _executorService = Executors.newSingleThreadExecutor();
+  }
+
+  @Override
+  public MessageBatch fetchMessages(StreamPartitionMsgOffset startMsgOffset, 
StreamPartitionMsgOffset endMsgOffset,
+      int timeoutMillis) {
+    final MessageId startMessageId = ((MessageIdStreamOffset) 
startMsgOffset).getMessageId();
+    final MessageId endMessageId =
+        endMsgOffset == null ? MessageId.latest : ((MessageIdStreamOffset) 
endMsgOffset).getMessageId();
+
+    List<Message<byte[]>> messagesList = new ArrayList<>();
+    Future<PulsarMessageBatch> pulsarResultFuture =
+        _executorService.submit(() -> fetchMessages(startMessageId, 
endMessageId, messagesList));
+
+    try {
+      return pulsarResultFuture.get(timeoutMillis, TimeUnit.MILLISECONDS);
+    } catch (TimeoutException e) {
+      //The fetchMessages has thrown an exception. Most common cause is the 
timeout.

Review comment:
       done




-- 
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:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to