[ 
https://issues.apache.org/jira/browse/GOBBLIN-672?focusedWorklogId=230954&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-230954
 ]

ASF GitHub Bot logged work on GOBBLIN-672:
------------------------------------------

                Author: ASF GitHub Bot
            Created on: 22/Apr/19 23:22
            Start Date: 22/Apr/19 23:22
    Worklog Time Spent: 10m 
      Work Description: yukuai518 commented on pull request #2542: 
[GOBBLIN-672] add EventHub source
URL: https://github.com/apache/incubator-gobblin/pull/2542#discussion_r277470525
 
 

 ##########
 File path: 
gobblin-modules/gobblin-eventhub/src/main/java/org/apache/gobblin/eventhub/source/EventhubSource.java
 ##########
 @@ -0,0 +1,152 @@
+/*
+ * 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.gobblin.eventhub.source;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import com.google.gson.Gson;
+import com.microsoft.azure.eventhubs.EventData;
+import org.apache.gobblin.configuration.ConfigurationKeys;
+import org.apache.gobblin.configuration.SourceState;
+import org.apache.gobblin.configuration.WorkUnitState;
+import org.apache.gobblin.source.extractor.extract.AbstractSource;
+import org.apache.gobblin.source.extractor.extract.LongWatermark;
+import org.apache.gobblin.source.extractor.partition.Partition;
+import org.apache.gobblin.source.extractor.partition.Partitioner;
+import org.apache.gobblin.source.workunit.Extract;
+import org.apache.gobblin.source.workunit.MultiWorkUnit;
+import org.apache.gobblin.source.workunit.WorkUnit;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.*;
+
+
+/**
+ * Created by Jan on 23-Jan-19.
+ */
+public class EventhubSource extends AbstractSource<Void, EventData> {
+
+    public static final Logger LOG = 
LoggerFactory.getLogger(EventhubSource.class);
+
+    public static final String WORK_UNIT_STATE_VERSION_KEY = 
"source.querybased.workUnitState.version";
+    public static final Integer CURRENT_WORK_UNIT_STATE_VERSION = 1;
+
+    @Override
+    public List<WorkUnit> getWorkunits(SourceState state) {
+        List<WorkUnit> workUnits = new ArrayList<>();
+
+        Long previousWatermark = getPreviousWatermark(state);
+        if (previousWatermark == null) {
+            previousWatermark = ConfigurationKeys.DEFAULT_WATERMARK_VALUE;
+        }
+
+        // for now, enforce single work unit to simplify watermark handling:
+        if 
(state.getPropAsInt(ConfigurationKeys.SOURCE_MAX_NUMBER_OF_PARTITIONS, 1) != 1) 
{
+            LOG.error("Unsupported number of partitions, resetting to 1.");
+        }
+        state.setProp(ConfigurationKeys.SOURCE_MAX_NUMBER_OF_PARTITIONS, 1);
+        workUnits.addAll(generateWorkUnits(state, previousWatermark));
+
+        LOG.info("Total number of workunits for the current run: " + 
workUnits.size());
+        List<WorkUnit> previousWorkUnits = 
this.getPreviousWorkUnitsForRetry(state);
+        LOG.info("Total number of incomplete tasks from the previous run: " + 
previousWorkUnits.size());
+        workUnits.addAll(previousWorkUnits);
+
+        int numOfMultiWorkunits =
+                state.getPropAsInt(ConfigurationKeys.MR_JOB_MAX_MAPPERS_KEY, 
ConfigurationKeys.DEFAULT_MR_JOB_MAX_MAPPERS);
+
+        return pack(workUnits, numOfMultiWorkunits);
+    }
+
+    private static List<WorkUnit> pack(List<WorkUnit> workUnits, int 
numOfMultiWorkunits) {
+        Preconditions.checkArgument(numOfMultiWorkunits > 0);
+
+        if (workUnits.size() <= numOfMultiWorkunits) {
+            return workUnits;
+        }
+        List<WorkUnit> result = 
Lists.newArrayListWithCapacity(numOfMultiWorkunits);
+        for (int i = 0; i < numOfMultiWorkunits; i++) {
+            result.add(MultiWorkUnit.createEmpty());
+        }
+        for (int i = 0; i < workUnits.size(); i++) {
+            ((MultiWorkUnit) result.get(i % 
numOfMultiWorkunits)).addWorkUnit(workUnits.get(i));
+        }
+        return result;
+    }
+
+    protected List<WorkUnit> generateWorkUnits(SourceState state, long 
previousWatermark) {
 
 Review comment:
   I think we should not have a global previousWatermark. If you only support 
one partition, this will work. But if you have multiple partitions, each 
partition should have its own previousWatermark. I guess right now your source 
is much like a QueryBasedSource instead of a partition like source such as 
KafkaSource. You need to check if you can model it in the same way as 
KafkaSource, which maintains previousOffsets list for each workunit.
 
----------------------------------------------------------------
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:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 230954)
    Time Spent: 2h  (was: 1h 50m)

> Add EventHub source
> -------------------
>
>                 Key: GOBBLIN-672
>                 URL: https://issues.apache.org/jira/browse/GOBBLIN-672
>             Project: Apache Gobblin
>          Issue Type: New Feature
>            Reporter: Jan Fabian
>            Priority: Minor
>          Time Spent: 2h
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to