Github user brkyvz commented on a diff in the pull request:

    https://github.com/apache/spark/pull/17250#discussion_r105796830
  
    --- Diff: 
external/kinesis-asl/src/main/scala/org/apache/spark/streaming/kinesis/KinesisDStream.scala
 ---
    @@ -0,0 +1,559 @@
    +/*
    + * 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.streaming.kinesis
    +
    +import scala.reflect.ClassTag
    +
    +import 
com.amazonaws.services.kinesis.clientlibrary.lib.worker.InitialPositionInStream
    +import com.amazonaws.services.kinesis.model.Record
    +
    +import org.apache.spark.annotation.InterfaceStability
    +import org.apache.spark.storage.StorageLevel
    +import org.apache.spark.streaming.{Duration, StreamingContext}
    +import org.apache.spark.streaming.api.java.JavaStreamingContext
    +
    +@InterfaceStability.Stable
    +object KinesisDStream {
    +  /**
    +   * Builder for [[KinesisInputDStream]] instances.
    +   *
    +   * @param ssc StreamingContext to be used for creating DStreams
    +   * @param streamName Name of Kinesis stream
    +   * @param messageHandler Function for extracting DStream data type from 
KCL Record
    +   *
    +   * @since 2.2.0
    +   */
    +  @InterfaceStability.Stable
    +  class Builder[T: ClassTag](
    +      ssc: StreamingContext,
    +      streamName: String,
    +      messageHandler: Record => T) {
    +    private var endpointUrl = DEFAULT_KINESIS_ENDPOINT_URL
    +    private var regionName = DEFAULT_KINESIS_REGION_NAME
    +    private var initialPositionInStream = 
DEFAULT_INITIAL_POSITION_IN_STREAM
    +    private var checkpointAppName = ssc.sparkContext.appName
    +    private var checkpointInterval = ssc.graph.batchDuration
    +    private var storageLevel = DEFAULT_STORAGE_LEVEL
    +    private var kinesisCredsProvider: SerializableCredentialsProvider = 
DefaultCredentialsProvider
    +    private var dynamoDBCredsProvider: 
Option[SerializableCredentialsProvider] = None
    +    private var cloudWatchCredsProvider: 
Option[SerializableCredentialsProvider] = None
    +
    +    /**
    +     * Sets the AWS Kinesis endpoint URL. Defaults to 
"https://kinesis.us-east-1.amazonaws.com"; if
    +     * no custom value is specified
    +     *
    +     * @param url Kinesis endpoint URL to use
    +     * @return Reference to this [[KinesisDStream.Builder]]
    +     */
    +    def endpointUrl(url: String): Builder[T] = {
    +      endpointUrl = url
    +      this
    +    }
    +
    +    /**
    +     * Sets the AWS region to construct clients for. Defaults to 
"us-east-1" if no custom value
    +     * is specified.
    +     *
    +     * @param regionName Name of AWS region to use (e.g. "us-west-2")
    +     * @return Reference to this [[KinesisDStream.Builder]]
    +     */
    +    def regionName(regionName: String): Builder[T] = {
    +      this.regionName = regionName
    +      this
    +    }
    +
    +    /**
    +     * Sets the initial position data is read from in the Kinesis stream. 
Defaults to
    +     * InitialPositionInStream.LATEST if no custom value is specified.
    +     *
    +     * @param initialPosition InitialPositionInStream value specifying 
where Spark Streaming
    +     *                        will start reading records in the Kinesis 
stream from
    +     * @return Reference to this [[KinesisDStream.Builder]]
    +     */
    +    def initialPositionInStream(initialPosition: InitialPositionInStream): 
Builder[T] = {
    +      initialPositionInStream = initialPosition
    +      this
    +    }
    +
    +    /**
    +     * Sets the KCL application name to use when checkpointing state to 
DynamoDB. Defaults to the
    +     * Spark app name if no custom value is specified.
    +     *
    +     * @param appName Value to use for the KCL app name (used when 
creating the DynamoDB checkpoint
    +     *                table and when writing metrics to CloudWatch)
    +     * @return Reference to this [[KinesisDStream.Builder]]
    +     */
    +    def checkpointAppName(appName: String): Builder[T] = {
    +      checkpointAppName = appName
    +      this
    +    }
    +
    +    /**
    +     * Sets how often the KCL application state is checkpointed to 
DynamoDB. Defaults to the Spark
    +     * Streaming batch interval if no custom value is specified.
    +     *
    +     * @param interval [[Duration]] specifying how often the KCL state 
should be checkpointed to
    +     *                 DynamoDB.
    +     * @return Reference to this [[KinesisDStream.Builder]]
    +     */
    +    def checkpointInterval(interval: Duration): Builder[T] = {
    +      checkpointInterval = interval
    +      this
    +    }
    +
    +    /**
    +     * Sets the storage level of the blocks for the DStream created. 
Defaults to
    +     * [[StorageLevel.MEMORY_AND_DISK_2]] if no custom value is specified.
    +     *
    +     * @param storageLevel [[StorageLevel]] to use for the DStream data 
blocks
    +     * @return Reference to this [[KinesisDStream.Builder]]
    +     */
    +    def storageLevel(storageLevel: StorageLevel): Builder[T] = {
    +      this.storageLevel = storageLevel
    +      this
    +    }
    +
    +    /**
    +     * Use the default AWS credentials provider chain to authenticate to 
the Kinesis service. This
    +     * is also the default credentials provider used if no custom value is 
specified.
    +     *
    +     * @return Reference to this [[KinesisDStream.Builder]]
    +     */
    +    def kinesisDefaultCredentials(): Builder[T] = {
    +      kinesisCredsProvider = DefaultCredentialsProvider
    +      this
    +    }
    +
    +    /**
    +     * Use an AWS credential keypair to authenticate to the Kinesis 
service. The default AWS
    +     * credentials provider chain is used if no custom value is specified.
    +     *
    +     * @param awsAccessKeyId AWS access key ID
    +     * @param awsSecretKey AWS secret key
    +     * @return Reference to this [[KinesisDStream.Builder]]
    +     */
    +    def kinesisBasicAWSCredentials(awsAccessKeyId: String, awsSecretKey: 
String): Builder[T] = {
    +      kinesisCredsProvider = BasicCredentialsProvider(
    +        awsAccessKeyId = awsAccessKeyId,
    +        awsSecretKey = awsSecretKey)
    +      this
    +    }
    +
    +    /**
    +     * Assume an STS role in order to authenticate to the Kinesis service. 
The default
    +     * credential chain is used to authenticate to STS and no external ID 
is used.
    +     *
    +     * @param stsRoleArn ARN of the IAM role to assume via STS
    +     * @param stsSessionName Name to identify STS sessions by
    +     * @return Reference to this [[KinesisDStream.Builder]]
    +     */
    +    def kinesisSTSCredentials(stsRoleArn: String, stsSessionName: String): 
Builder[T] = {
    +      kinesisCredsProvider = buildSTSCredentials(stsRoleArn, 
stsSessionName)
    +      this
    +    }
    +
    +    /**
    +     * Assume an STS role in order to authenticate to the Kinesis service. 
The provided
    +     * AWS credential keypair is used to authenticate to STS and no 
external ID is used.
    +     *
    +     * @param stsRoleArn ARN of the IAM role to assume via STS
    +     * @param stsSessionName Name to identify STS sessions by
    +     * @param awsAccessKeyId AWS access key ID for authenicating to STS
    +     * @param awsSecretKey AWS secret key for authenticating to STS
    +     * @return Reference to this [[KinesisDStream.Builder]]
    +     */
    +    def kinesisSTSCredentials(
    +        stsRoleArn: String,
    +        stsSessionName: String,
    +        awsAccessKeyId: String,
    +        awsSecretKey: String): Builder[T] = {
    +      kinesisCredsProvider = buildSTSCredentials(
    +        stsRoleArn,
    +        stsSessionName,
    +        awsKeypair = Option(awsAccessKeyId, awsSecretKey))
    +      this
    +    }
    +
    +    /**
    +     * Assume an STS role in order to authenticate to the Kinesis service. 
The default
    +     * credential chain is used to authenticate to STS and the provided 
external ID is
    +     * validated against the value in the assumed role's policy (if one is 
specified).
    +     *
    +     * @param stsRoleArn ARN of the IAM role to assume via STS
    +     * @param stsSessionName Name to identify STS sessions by
    +     * @param stsExternaId External ID used by STS to validate IAM role 
trust policy
    +     * @return Reference to this [[KinesisDStream.Builder]]
    +     */
    +    def kinesisSTSCredentials(
    +        stsRoleArn: String,
    +        stsSessionName: String,
    +        stsExternalId: String): Builder[T] = {
    +      kinesisCredsProvider = buildSTSCredentials(
    +        stsRoleArn,
    +        stsSessionName,
    +        stsExternalId = Option(stsExternalId))
    +      this
    +    }
    +
    +    /**
    +     * Assume an STS role in order to authenticate to the Kinesis service. 
The provided
    +     * AWS credential keypair is used to authenticate to STS and the 
provided external ID
    +     * is validated against the value in the assumed role's policy (if one 
is specified).
    +     *
    +     * @param stsRoleArn ARN of the IAM role to assume via STS
    +     * @param stsSessionName Name to identify STS sessions by
    +     * @param awsAccessKeyId AWS access key ID for authenicating to STS
    +     * @param stsExternaId External ID used by STS to validate IAM role 
trust policy
    +     * @param awsSecretKey AWS secret key for authenticating to STS
    +     * @return Reference to this [[KinesisDStream.Builder]]
    +     */
    +    def kinesisSTSCredentials(
    --- End diff --
    
    With this many methods for the credential provider, I feel we need a 
credential provider builder. I wouldn't want to re-enter everything again 
between `dynamoDb` and `cloudWatch`. If I want to keep them separate from the 
`kinesis` credentials


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

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

Reply via email to