spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tdas <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-1981] Add AWS Kinesis streaming support
Date Fri, 01 Aug 2014 22:43:49 GMT
Github user tdas commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1434#discussion_r15722833
  
    --- Diff: examples/src/main/scala/org/apache/spark/examples/streaming/KinesisWordCountASL.scala
---
    @@ -0,0 +1,237 @@
    +/*
    + * 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.spark.examples.streaming
    +
    +import java.nio.ByteBuffer
    +
    +import scala.util.Random
    +
    +import org.apache.spark.Logging
    +import org.apache.spark.SparkConf
    +import org.apache.spark.storage.StorageLevel
    +import org.apache.spark.streaming.Milliseconds
    +import org.apache.spark.streaming.StreamingContext
    +import org.apache.spark.streaming.StreamingContext.toPairDStreamFunctions
    +import org.apache.spark.streaming.kinesis.KinesisUtils
    +
    +import com.amazonaws.auth.DefaultAWSCredentialsProviderChain
    +import com.amazonaws.services.kinesis.AmazonKinesisClient
    +import com.amazonaws.services.kinesis.clientlibrary.lib.worker.InitialPositionInStream
    +import com.amazonaws.services.kinesis.model.PutRecordRequest
    +
    +/**
    + * Kinesis Spark Streaming WordCount example.
    + *
    + * See http://spark.apache.org/docs/latest/streaming-kinesis.html for more details on
    + *   the Kinesis Spark Streaming integration.
    + *
    + * This example spins up 1 Kinesis Worker (Spark Streaming Receiver) per shard 
    + *   for the given stream.
    + * It then starts pulling from the last checkpointed sequence number of the given 
    + *   <stream-name> and <endpoint-url>. 
    + *
    + * Valid endpoint urls:  http://docs.aws.amazon.com/general/latest/gr/rande.html#ak_region
    + * 
    + * This code uses the DefaultAWSCredentialsProviderChain and searches for credentials
    + *   in the following order of precedence:
    + * Environment Variables - AWS_ACCESS_KEY_ID and AWS_SECRET_KEY
    + * Java System Properties - aws.accessKeyId and aws.secretKey
    + * Credential profiles file - default location (~/.aws/credentials) shared by all AWS
SDKs
    + * Instance profile credentials - delivered through the Amazon EC2 metadata service
    + *
    + * Usage: KinesisWordCountASL <stream-name> <endpoint-url>
    + *   <stream-name> is the name of the Kinesis stream (ie. mySparkStream)
    + *   <endpoint-url> is the endpoint of the Kinesis service
    + *     (ie. https://kinesis.us-east-1.amazonaws.com)
    + *
    + * Example:
    + *    $ export AWS_ACCESS_KEY_ID=<your-access-key>
    + *    $ export AWS_SECRET_KEY=<your-secret-key>
    + *    $ $SPARK_HOME/bin/run-example \
    + *        org.apache.spark.examples.streaming.KinesisWordCountASL mySparkStream \
    + *        https://kinesis.us-east-1.amazonaws.com
    + *
    + * There is a companion helper class below called KinesisWordCountProducerASL which puts
    + *   dummy data onto the Kinesis stream.
    + * Usage instructions for KinesisWordCountProducerASL are provided in that class definition.
    + */
    +object KinesisWordCountASL extends Logging {
    +  def main(args: Array[String]) {
    +/**
    + * Check that all required args were passed in.
    + */
    +    if (args.length < 2) {
    +      System.err.println(
    +        """
    +          |Usage: KinesisWordCount <stream-name> <endpoint-url>
    +          |    <stream-name> is the name of the Kinesis stream
    +          |    <endpoint-url> is the endpoint of the Kinesis service
    +          |                   (e.g. https://kinesis.us-east-1.amazonaws.com)
    +        """.stripMargin)
    +      System.exit(1)
    +    }
    +
    +    StreamingExamples.setStreamingLogLevels()
    +    
    +    /** Populate the appropriate variables from the given args */
    +    val Array(streamName, endpointUrl) = args
    +
    +    /** Determine the number of shards from the stream */
    +    val kinesisClient = new AmazonKinesisClient(new DefaultAWSCredentialsProviderChain())
    +    kinesisClient.setEndpoint(endpointUrl)
    +    val numShards = kinesisClient.describeStream(streamName).getStreamDescription().getShards()
    +      .size()
    +
    +    /** In this example, we're going to create 1 Kinesis Worker/Receiver/DStream for
each shard. */
    +    val numStreams = numShards
    +
    +    /** 
    +     *  numSparkThreads should be 1 more thread than the number of receivers.
    +     *  This leaves one thread available for actually processing the data.
    +     */
    +    val numSparkThreads = numStreams + 1
    +
    +    /** Setup the and SparkConfig and StreamingContext */
    +    /** Spark Streaming batch interval */
    +    val batchInterval = Milliseconds(2000)    
    +    val sparkConfig = new SparkConf().setAppName("KinesisWordCount")
    +      .setMaster(s"local[$numSparkThreads]")
    +    val ssc = new StreamingContext(sparkConfig, batchInterval)
    +    /** Setup the checkpoint directory used by Spark Streaming */
    +    ssc.checkpoint("/tmp/checkpoint");
    --- End diff --
    
    Dont need checkpoint directory in this example.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message