You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2020/04/03 06:05:26 UTC

[GitHub] [incubator-pinot] kishoreg commented on a change in pull request #5189: Stream github events demo

kishoreg commented on a change in pull request #5189: Stream github events demo
URL: https://github.com/apache/incubator-pinot/pull/5189#discussion_r402753334
 
 

 ##########
 File path: pinot-tools/src/main/java/org/apache/pinot/tools/GithubEventsQuickstart.java
 ##########
 @@ -0,0 +1,149 @@
+/**
+ * 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.tools;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import java.io.File;
+import java.net.URL;
+import org.apache.commons.io.FileUtils;
+import org.apache.pinot.common.utils.ZkStarter;
+import org.apache.pinot.spi.plugin.PluginManager;
+import org.apache.pinot.spi.stream.StreamDataProvider;
+import org.apache.pinot.spi.stream.StreamDataServerStartable;
+import org.apache.pinot.tools.Quickstart.Color;
+import org.apache.pinot.tools.admin.command.QuickstartRunner;
+import org.apache.pinot.tools.streams.githubevents.PullRequestMergedEventsStream;
+import org.apache.pinot.tools.utils.KafkaStarterUtils;
+
+import static org.apache.pinot.tools.Quickstart.prettyPrintResponse;
+import static org.apache.pinot.tools.Quickstart.printStatus;
+
+
+/**
+ * Sets up a demo Pinot cluster with 1 zookeeper, 1 controller, 1 broker and 1 server
+ * Sets up a demo Kafka cluster, and creates a topic pullRequestMergedEvents
+ * Creates a realtime table pullRequestMergedEvents
+ * Starts the {@link PullRequestMergedEventsStream} to publish pullRequestMergedEvents into the topic
+ */
+public class GithubEventsQuickstart {
+  private StreamDataServerStartable _kafkaStarter;
+  private ZkStarter.ZookeeperInstance _zookeeperInstance;
+
+  private void startKafka() {
+    _zookeeperInstance = ZkStarter.startLocalZkServer();
+    try {
+      _kafkaStarter = StreamDataProvider.getServerDataStartable(KafkaStarterUtils.KAFKA_SERVER_STARTABLE_CLASS_NAME,
+          KafkaStarterUtils.getDefaultKafkaConfiguration());
+    } catch (Exception e) {
+      throw new RuntimeException("Failed to start " + KafkaStarterUtils.KAFKA_SERVER_STARTABLE_CLASS_NAME, e);
+    }
+    _kafkaStarter.start();
+    _kafkaStarter.createTopic("pullRequestMergedEvents", KafkaStarterUtils.getTopicCreationProps(2));
+  }
+
+  public void execute(String personalAccessToken)
+      throws Exception {
+    final File quickStartDataDir = new File("githubEvents" + System.currentTimeMillis());
+
+    if (!quickStartDataDir.exists()) {
+      Preconditions.checkState(quickStartDataDir.mkdirs());
+    }
+
+    File schemaFile = new File(quickStartDataDir, "pullRequestMergedEvents_schema.json");
+    File tableConfigFile = new File(quickStartDataDir, "pullRequestMergedEvents_realtime_table_config.json");
+
+    ClassLoader classLoader = Quickstart.class.getClassLoader();
+    URL resource = classLoader.getResource("examples/stream/githubEvents/pullRequestMergedEvents_schema.json");
+    Preconditions.checkNotNull(resource);
+    FileUtils.copyURLToFile(resource, schemaFile);
+    resource =
+        classLoader.getResource("examples/stream/githubEvents/pullRequestMergedEvents_realtime_table_config.json");
+    Preconditions.checkNotNull(resource);
+    FileUtils.copyURLToFile(resource, tableConfigFile);
+
+    File tempDir = new File("/tmp", String.valueOf(System.currentTimeMillis()));
+    Preconditions.checkState(tempDir.mkdirs());
+    QuickstartTableRequest request = new QuickstartTableRequest("pullRequestMergedEvents", schemaFile, tableConfigFile);
+    final QuickstartRunner runner = new QuickstartRunner(Lists.newArrayList(request), 1, 1, 1, tempDir);
+
+    printStatus(Color.CYAN, "***** Starting Kafka *****");
+    startKafka();
+
+    printStatus(Color.CYAN, "***** Starting zookeeper, controller, server and broker *****");
+    runner.startAll();
+
+    printStatus(Color.CYAN, "***** Adding pullRequestMergedEvents table *****");
+    runner.addTable();
+
+    printStatus(Color.CYAN, "***** Starting pullRequestMergedEvents data stream and publishing to Kafka *****");
+    final PullRequestMergedEventsStream pullRequestMergedEventsStream =
+        new PullRequestMergedEventsStream(schemaFile.getAbsolutePath(), "pullRequestMergedEvents",
+            KafkaStarterUtils.DEFAULT_KAFKA_BROKER, personalAccessToken);
+    pullRequestMergedEventsStream.execute();
+    printStatus(Color.CYAN, "***** Waiting for 10 seconds for a few events to get populated *****");
+    Thread.sleep(10000);
+
+    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
+      try {
+        printStatus(Color.GREEN, "***** Shutting down GithubEventsQuickStart *****");
+        runner.stop();
+        _kafkaStarter.stop();
+        ZkStarter.stopLocalZkServer(_zookeeperInstance);
+        FileUtils.deleteDirectory(quickStartDataDir);
+      } catch (Exception e) {
+        e.printStackTrace();
 
 Review comment:
   logger?

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

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