forked from opensearch-project/data-prepper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DocumentDB/MongoDB source for initial load (opensearch-project#4285)
* Add DocumentDB/MongoDB source for initial load Signed-off-by: Dinu John <86094133+dinujoh@users.noreply.github.com> * Update unit test parameter Signed-off-by: Dinu John <86094133+dinujoh@users.noreply.github.com> --------- Signed-off-by: Dinu John <86094133+dinujoh@users.noreply.github.com>
- Loading branch information
Showing
11 changed files
with
683 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
.../src/main/java/org/opensearch/dataprepper/plugins/mongo/documentdb/DocumentDBService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package org.opensearch.dataprepper.plugins.mongo.documentdb; | ||
|
||
import org.opensearch.dataprepper.metrics.PluginMetrics; | ||
import org.opensearch.dataprepper.model.acknowledgements.AcknowledgementSetManager; | ||
import org.opensearch.dataprepper.model.buffer.Buffer; | ||
import org.opensearch.dataprepper.model.event.Event; | ||
import org.opensearch.dataprepper.model.record.Record; | ||
import org.opensearch.dataprepper.model.source.coordinator.enhanced.EnhancedSourceCoordinator; | ||
import org.opensearch.dataprepper.plugins.mongo.export.MongoDBExportPartitionSupplier; | ||
import org.opensearch.dataprepper.plugins.mongo.configuration.MongoDBSourceConfig; | ||
import org.opensearch.dataprepper.plugins.mongo.export.ExportScheduler; | ||
import org.opensearch.dataprepper.plugins.mongo.export.ExportWorker; | ||
import org.opensearch.dataprepper.plugins.mongo.leader.LeaderScheduler; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
|
||
public class DocumentDBService { | ||
private static final Logger LOG = LoggerFactory.getLogger(DocumentDBService.class); | ||
private final EnhancedSourceCoordinator sourceCoordinator; | ||
private final PluginMetrics pluginMetrics; | ||
private final MongoDBSourceConfig sourceConfig; | ||
private final AcknowledgementSetManager acknowledgementSetManager; | ||
private final ExecutorService executor; | ||
private ExportScheduler exportScheduler; | ||
private ExportWorker exportWorker; | ||
private LeaderScheduler leaderScheduler; | ||
private final MongoDBExportPartitionSupplier mongoDBExportPartitionSupplier; | ||
public DocumentDBService(final EnhancedSourceCoordinator sourceCoordinator, | ||
final MongoDBSourceConfig sourceConfig, | ||
final PluginMetrics pluginMetrics, | ||
final AcknowledgementSetManager acknowledgementSetManager) { | ||
this.sourceCoordinator = sourceCoordinator; | ||
this.pluginMetrics = pluginMetrics; | ||
this.acknowledgementSetManager = acknowledgementSetManager; | ||
this.sourceConfig = sourceConfig; | ||
|
||
this.mongoDBExportPartitionSupplier = new MongoDBExportPartitionSupplier(sourceConfig); | ||
executor = Executors.newFixedThreadPool(3); | ||
} | ||
|
||
/** | ||
* This service start three long-running threads (scheduler) | ||
* Each thread is responsible for one type of job. | ||
* The data will be guaranteed to be sent to {@link Buffer} in order. | ||
* | ||
* @param buffer Data Prepper Buffer | ||
*/ | ||
public void start(Buffer<Record<Event>> buffer) { | ||
this.exportScheduler = new ExportScheduler(sourceCoordinator, mongoDBExportPartitionSupplier, pluginMetrics); | ||
this.exportWorker = new ExportWorker(sourceCoordinator, buffer, pluginMetrics, acknowledgementSetManager, sourceConfig); | ||
this.leaderScheduler = new LeaderScheduler(sourceCoordinator, sourceConfig.getCollections()); | ||
|
||
executor.submit(leaderScheduler); | ||
executor.submit(exportScheduler); | ||
executor.submit(exportWorker); | ||
} | ||
|
||
/** | ||
* Interrupt the running of schedulers. | ||
* Each scheduler must implement logic for gracefully shutdown. | ||
*/ | ||
public void shutdown() { | ||
LOG.info("shutdown DocumentDB Service scheduler and worker"); | ||
executor.shutdownNow(); | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
...b/src/main/java/org/opensearch/dataprepper/plugins/mongo/documentdb/DocumentDBSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package org.opensearch.dataprepper.plugins.mongo.documentdb; | ||
|
||
import org.opensearch.dataprepper.metrics.PluginMetrics; | ||
import org.opensearch.dataprepper.model.acknowledgements.AcknowledgementSetManager; | ||
import org.opensearch.dataprepper.model.annotations.DataPrepperPlugin; | ||
import org.opensearch.dataprepper.model.annotations.DataPrepperPluginConstructor; | ||
import org.opensearch.dataprepper.model.buffer.Buffer; | ||
import org.opensearch.dataprepper.model.event.Event; | ||
import org.opensearch.dataprepper.model.record.Record; | ||
import org.opensearch.dataprepper.model.source.Source; | ||
import org.opensearch.dataprepper.model.source.coordinator.SourcePartitionStoreItem; | ||
import org.opensearch.dataprepper.model.source.coordinator.enhanced.EnhancedSourceCoordinator; | ||
import org.opensearch.dataprepper.model.source.coordinator.enhanced.EnhancedSourcePartition; | ||
import org.opensearch.dataprepper.model.source.coordinator.enhanced.UsesEnhancedSourceCoordination; | ||
import org.opensearch.dataprepper.plugins.mongo.coordination.PartitionFactory; | ||
import org.opensearch.dataprepper.plugins.mongo.coordination.partition.LeaderPartition; | ||
import org.opensearch.dataprepper.plugins.mongo.configuration.MongoDBSourceConfig; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.Objects; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
import java.util.function.Function; | ||
|
||
|
||
@DataPrepperPlugin(name = "documentdb", pluginType = Source.class, pluginConfigurationType = MongoDBSourceConfig.class) | ||
|
||
public class DocumentDBSource implements Source<Record<Event>>, UsesEnhancedSourceCoordination { | ||
private static final Logger LOG = LoggerFactory.getLogger(DocumentDBSource.class); | ||
|
||
private final PluginMetrics pluginMetrics; | ||
private final MongoDBSourceConfig sourceConfig; | ||
private final ExecutorService executor; | ||
private EnhancedSourceCoordinator sourceCoordinator; | ||
private final AcknowledgementSetManager acknowledgementSetManager; | ||
private DocumentDBService documentDBService; | ||
|
||
@DataPrepperPluginConstructor | ||
public DocumentDBSource(final PluginMetrics pluginMetrics, | ||
final MongoDBSourceConfig sourceConfig, | ||
final AcknowledgementSetManager acknowledgementSetManager) { | ||
this.pluginMetrics = pluginMetrics; | ||
this.sourceConfig = sourceConfig; | ||
executor = Executors.newFixedThreadPool(2); | ||
this.acknowledgementSetManager = acknowledgementSetManager; | ||
} | ||
|
||
@Override | ||
public void start(final Buffer<Record<Event>> buffer) { | ||
Objects.requireNonNull(sourceCoordinator); | ||
sourceCoordinator.createPartition(new LeaderPartition()); | ||
|
||
documentDBService = new DocumentDBService(sourceCoordinator, sourceConfig, pluginMetrics, | ||
acknowledgementSetManager); | ||
|
||
LOG.info("Start DocumentDB service"); | ||
documentDBService.start(buffer); | ||
} | ||
|
||
|
||
@Override | ||
public void stop() { | ||
LOG.info("Stop DocumentDB service"); | ||
if (Objects.nonNull(documentDBService)) { | ||
documentDBService.shutdown(); | ||
} | ||
} | ||
|
||
@Override | ||
public void setEnhancedSourceCoordinator(EnhancedSourceCoordinator sourceCoordinator) { | ||
this.sourceCoordinator = sourceCoordinator; | ||
this.sourceCoordinator.initialize(); | ||
} | ||
|
||
@Override | ||
public Function<SourcePartitionStoreItem, EnhancedSourcePartition> getPartitionFactory() { | ||
return new PartitionFactory(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.