-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-7799][SPARK-12786][Streaming]Add "streaming-akka" project #10744
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a5ec644
c20b51a
f267157
f650ff5
f2a07d4
463569c
4e25229
9a1b275
d495ecc
0c8bd04
5ac46f9
9e36df1
5e2ac50
c31be35
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,7 +31,8 @@ | |
| import org.apache.spark.streaming.Duration; | ||
| import org.apache.spark.streaming.api.java.JavaDStream; | ||
| import org.apache.spark.streaming.api.java.JavaStreamingContext; | ||
| import org.apache.spark.streaming.receiver.JavaActorReceiver; | ||
| import org.apache.spark.streaming.akka.AkkaUtils; | ||
| import org.apache.spark.streaming.akka.JavaActorReceiver; | ||
|
|
||
| /** | ||
| * A sample actor as receiver, is also simplest. This receiver actor | ||
|
|
@@ -56,6 +57,7 @@ public void preStart() { | |
| remotePublisher.tell(new SubscribeReceiver(getSelf()), getSelf()); | ||
| } | ||
|
|
||
| @Override | ||
| public void onReceive(Object msg) throws Exception { | ||
| store((T) msg); | ||
| } | ||
|
|
@@ -100,18 +102,20 @@ public static void main(String[] args) { | |
| String feederActorURI = "akka.tcp://test@" + host + ":" + port + "/user/FeederActor"; | ||
|
|
||
| /* | ||
| * Following is the use of actorStream to plug in custom actor as receiver | ||
| * Following is the use of AkkaUtils.createStream to plug in custom actor as receiver | ||
| * | ||
| * An important point to note: | ||
| * Since Actor may exist outside the spark framework, It is thus user's responsibility | ||
| * to ensure the type safety, i.e type of data received and InputDstream | ||
| * should be same. | ||
| * | ||
| * For example: Both actorStream and JavaSampleActorReceiver are parameterized | ||
| * For example: Both AkkaUtils.createStream and JavaSampleActorReceiver are parameterized | ||
| * to same type to ensure type safety. | ||
| */ | ||
| JavaDStream<String> lines = jssc.actorStream( | ||
| Props.create(JavaSampleActorReceiver.class, feederActorURI), "SampleReceiver"); | ||
| JavaDStream<String> lines = AkkaUtils.createStream( | ||
| jssc, | ||
| Props.create(JavaSampleActorReceiver.class, feederActorURI), | ||
| "SampleReceiver"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| // compute wordcount | ||
| lines.flatMap(new FlatMapFunction<String, String>() { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,12 +22,12 @@ import scala.collection.mutable.LinkedList | |
| import scala.reflect.ClassTag | ||
| import scala.util.Random | ||
|
|
||
| import akka.actor.{actorRef2Scala, Actor, ActorRef, Props} | ||
| import akka.actor._ | ||
| import com.typesafe.config.ConfigFactory | ||
|
|
||
| import org.apache.spark.{SecurityManager, SparkConf} | ||
| import org.apache.spark.SparkConf | ||
| import org.apache.spark.streaming.{Seconds, StreamingContext} | ||
| import org.apache.spark.streaming.receiver.ActorReceiver | ||
| import org.apache.spark.util.AkkaUtils | ||
| import org.apache.spark.streaming.akka.{ActorReceiver, AkkaUtils} | ||
|
|
||
| case class SubscribeReceiver(receiverActor: ActorRef) | ||
| case class UnsubscribeReceiver(receiverActor: ActorRef) | ||
|
|
@@ -78,8 +78,7 @@ class FeederActor extends Actor { | |
| * | ||
| * @see [[org.apache.spark.examples.streaming.FeederActor]] | ||
| */ | ||
| class SampleActorReceiver[T: ClassTag](urlOfPublisher: String) | ||
| extends ActorReceiver { | ||
| class SampleActorReceiver[T](urlOfPublisher: String) extends ActorReceiver { | ||
|
|
||
| lazy private val remotePublisher = context.actorSelection(urlOfPublisher) | ||
|
|
||
|
|
@@ -108,9 +107,13 @@ object FeederActor { | |
| } | ||
| val Seq(host, port) = args.toSeq | ||
|
|
||
| val conf = new SparkConf | ||
| val actorSystem = AkkaUtils.createActorSystem("test", host, port.toInt, conf = conf, | ||
| securityManager = new SecurityManager(conf))._1 | ||
| val akkaConf = ConfigFactory.parseString( | ||
| s"""akka.actor.provider = "akka.remote.RemoteActorRefProvider" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this change will resolve SPARK-12786.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @zsxwing Could you also tag that JIRA in this PR and resolve it when this is closed.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated the title |
||
| |akka.remote.enabled-transports = ["akka.remote.netty.tcp"] | ||
| |akka.remote.netty.tcp.hostname = "$host" | ||
| |akka.remote.netty.tcp.port = $port | ||
| |""".stripMargin) | ||
| val actorSystem = ActorSystem("test", akkaConf) | ||
| val feeder = actorSystem.actorOf(Props[FeederActor], "FeederActor") | ||
|
|
||
| println("Feeder started as:" + feeder) | ||
|
|
@@ -121,6 +124,7 @@ object FeederActor { | |
|
|
||
| /** | ||
| * A sample word count program demonstrating the use of plugging in | ||
| * | ||
| * Actor as Receiver | ||
| * Usage: ActorWordCount <hostname> <port> | ||
| * <hostname> and <port> describe the AkkaSystem that Spark Sample feeder is running on. | ||
|
|
@@ -146,20 +150,21 @@ object ActorWordCount { | |
| val ssc = new StreamingContext(sparkConf, Seconds(2)) | ||
|
|
||
| /* | ||
| * Following is the use of actorStream to plug in custom actor as receiver | ||
| * Following is the use of AkkaUtils.createStream to plug in custom actor as receiver | ||
| * | ||
| * An important point to note: | ||
| * Since Actor may exist outside the spark framework, It is thus user's responsibility | ||
| * to ensure the type safety, i.e type of data received and InputDstream | ||
| * to ensure the type safety, i.e type of data received and InputDStream | ||
| * should be same. | ||
| * | ||
| * For example: Both actorStream and SampleActorReceiver are parameterized | ||
| * For example: Both AkkaUtils.createStream and SampleActorReceiver are parameterized | ||
| * to same type to ensure type safety. | ||
| */ | ||
|
|
||
| val lines = ssc.actorStream[String]( | ||
| Props(new SampleActorReceiver[String]("akka.tcp://test@%s:%s/user/FeederActor".format( | ||
| host, port.toInt))), "SampleReceiver") | ||
| val lines = AkkaUtils.createStream[String]( | ||
| ssc, | ||
| Props(classOf[SampleActorReceiver[String]], | ||
| "akka.tcp://test@%s:%s/user/FeederActor".format(host, port.toInt)), | ||
| "SampleReceiver") | ||
|
|
||
| // compute wordcount | ||
| lines.flatMap(_.split("\\s+")).map(x => (x, 1)).reduceByKey(_ + _).print() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
| ~ 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. | ||
| --> | ||
|
|
||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <parent> | ||
| <groupId>org.apache.spark</groupId> | ||
| <artifactId>spark-parent_2.10</artifactId> | ||
| <version>2.0.0-SNAPSHOT</version> | ||
| <relativePath>../../pom.xml</relativePath> | ||
| </parent> | ||
|
|
||
| <groupId>org.apache.spark</groupId> | ||
| <artifactId>spark-streaming-akka_2.10</artifactId> | ||
| <properties> | ||
| <sbt.project.name>streaming-akka</sbt.project.name> | ||
| </properties> | ||
| <packaging>jar</packaging> | ||
| <name>Spark Project External Akka</name> | ||
| <url>http://spark.apache.org/</url> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.apache.spark</groupId> | ||
| <artifactId>spark-streaming_${scala.binary.version}</artifactId> | ||
| <version>${project.version}</version> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.spark</groupId> | ||
| <artifactId>spark-core_${scala.binary.version}</artifactId> | ||
| <version>${project.version}</version> | ||
| <type>test-jar</type> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>${akka.group}</groupId> | ||
| <artifactId>akka-actor_${scala.binary.version}</artifactId> | ||
| <version>${akka.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>${akka.group}</groupId> | ||
| <artifactId>akka-remote_${scala.binary.version}</artifactId> | ||
| <version>${akka.version}</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.spark</groupId> | ||
| <artifactId>spark-core_${scala.binary.version}</artifactId> | ||
| <version>${project.version}</version> | ||
| <type>test-jar</type> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| </dependencies> | ||
| <build> | ||
| <outputDirectory>target/scala-${scala.binary.version}/classes</outputDirectory> | ||
| <testOutputDirectory>target/scala-${scala.binary.version}/test-classes</testOutputDirectory> | ||
| </build> | ||
| </project> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also make sure to add this is not supported in Python?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done