This repository has been archived by the owner. It is now read-only.
Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
FALCON-1893 : Add documentation and examples for spark workflow engine
Please review the pull request which contains documentation with examples how to use the Spark application with Falcon. Author: peeyush b <pbishnoi@hortonworks.com> Reviewers: "Pavan Kumar Kolamuri <pavan.kolamuri@gmail.com>, Venkat Ranganathan <vranganathan@hortonworks.com>" Closes #150 from peeyushb/FALCON-1893 (cherry picked from commit ff2f9e2) Signed-off-by: pavankumar526 <pavan.kolamuri@gmail.com>
- Loading branch information
1 parent
33a37a6
commit da3e37b25d8d49fca2d54c4fe61425824101ef0e
Showing
11 changed files
with
420 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#/** | ||
# * 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. | ||
# */ | ||
|
||
from __future__ import print_function | ||
|
||
import sys | ||
from operator import add | ||
|
||
from pyspark import SparkContext | ||
|
||
if __name__ == "__main__": | ||
if len(sys.argv) < 2: | ||
print("Usage: wordcount <file>", file=sys.stderr) | ||
exit(-1) | ||
sc = SparkContext(appName="Python WordCount") | ||
|
||
# Read input and output path | ||
inputPath = sys.argv[1] | ||
print ('Path of input file ->' + inputPath) | ||
outputPath = sys.argv[2] | ||
print ('Path of output file ->' + outputPath) | ||
|
||
distFile = sc.textFile(inputPath) | ||
|
||
def flatMap(line): | ||
return line.split(",") | ||
|
||
def map(word): | ||
return (word,1) | ||
|
||
def reduce(a,b): | ||
return a+b | ||
|
||
|
||
counts = distFile.flatMap(flatMap).map(map).reduceByKey(reduce) | ||
|
||
counts.saveAsTextFile(outputPath) |
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,52 @@ | ||
<?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. | ||
--> | ||
|
||
<process name="pyspark-process" xmlns="uri:falcon:process:0.1"> | ||
<clusters> | ||
<cluster name="local"> | ||
<validity start="2013-11-15T00:05Z" end="2013-11-15T01:05Z"/> | ||
</cluster> | ||
</clusters> | ||
|
||
<parallel>1</parallel> | ||
<order>LIFO</order> | ||
<frequency>minutes(5)</frequency> | ||
<timezone>UTC</timezone> | ||
|
||
<inputs> | ||
<!-- In the workflow, the input paths will be available in a variable 'inpaths' --> | ||
<input name="inpaths" feed="in" start="now(0,-5)" end="now(0,-1)"/> | ||
</inputs> | ||
|
||
<outputs> | ||
<!-- In the workflow, the output path will be available in a variable 'outpath' --> | ||
<output name="outpath" feed="out" instance="now(0,0)"/> | ||
</outputs> | ||
|
||
<workflow engine="spark" path="/app/spark"/> | ||
<spark-attributes> | ||
<master>local</master> | ||
<name>Python Spark Wordcount</name> | ||
<jar>/app/spark/wordcount.py</jar> | ||
<spark-opts>--num-executors 1 --driver-memory 512m --executor-memory 512m --executor-cores 1</spark-opts> | ||
</spark-attributes> | ||
|
||
<retry policy="periodic" delay="minutes(3)" attempts="3"/> | ||
|
||
</process> |
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,44 @@ | ||
<?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. | ||
--> | ||
|
||
<process name="spark-pi" xmlns="uri:falcon:process:0.1"> | ||
<clusters> | ||
<cluster name="local"> | ||
<validity start="2013-11-15T00:05Z" end="2013-11-15T01:05Z"/> | ||
</cluster> | ||
</clusters> | ||
|
||
<parallel>1</parallel> | ||
<order>LIFO</order> | ||
<frequency>minutes(5)</frequency> | ||
<timezone>UTC</timezone> | ||
|
||
<workflow engine="spark" path="/app/spark/"/> | ||
<spark-attributes> | ||
<master>local</master> | ||
<name>Spark PI</name> | ||
<class>org.apache.falcon.example.spark.SparkPI</class> | ||
<jar>/app/spark/lib/falcon-examples.jar</jar> | ||
<spark-opts>--num-executors 1 --driver-memory 512m --executor-memory 512m --executor-cores 1</spark-opts> | ||
<arg>2</arg> | ||
</spark-attributes> | ||
|
||
<retry policy="periodic" delay="minutes(3)" attempts="3"/> | ||
|
||
</process> |
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,53 @@ | ||
<?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. | ||
--> | ||
|
||
<process name="spark-process" xmlns="uri:falcon:process:0.1"> | ||
<clusters> | ||
<cluster name="local"> | ||
<validity start="2013-11-15T00:05Z" end="2013-11-15T01:05Z"/> | ||
</cluster> | ||
</clusters> | ||
|
||
<parallel>1</parallel> | ||
<order>LIFO</order> | ||
<frequency>minutes(5)</frequency> | ||
<timezone>UTC</timezone> | ||
|
||
<inputs> | ||
<!-- In the workflow, the input paths will be available in a variable 'inpaths' --> | ||
<input name="inpaths" feed="in" start="now(0,-5)" end="now(0,-1)"/> | ||
</inputs> | ||
|
||
<outputs> | ||
<!-- In the workflow, the output path will be available in a variable 'outpath' --> | ||
<output name="outpath" feed="out" instance="now(0,0)"/> | ||
</outputs> | ||
|
||
<workflow engine="spark" path="/app/spark"/> | ||
<spark-attributes> | ||
<master>local</master> | ||
<name>Java Spark Wordcount</name> | ||
<class>org.apache.falcon.example.spark.SparkWordCount</class> | ||
<jar>/app/spark/lib/falcon-examples.jar</jar> | ||
<spark-opts>--num-executors 1 --driver-memory 512m --executor-memory 512m --executor-cores 1</spark-opts> | ||
</spark-attributes> | ||
|
||
<retry policy="periodic" delay="minutes(3)" attempts="3"/> | ||
|
||
</process> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* 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.falcon.example.spark; | ||
|
||
import org.apache.spark.SparkConf; | ||
import org.apache.spark.api.java.JavaRDD; | ||
import org.apache.spark.api.java.JavaSparkContext; | ||
import org.apache.spark.api.java.function.Function; | ||
import org.apache.spark.api.java.function.Function2; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Computes an approximation to pi. | ||
* Usage: JavaSparkPi [slices] | ||
*/ | ||
public final class SparkPI { | ||
|
||
private SparkPI() { | ||
} | ||
|
||
public static void main(String[] args) throws Exception { | ||
SparkConf sparkConf = new SparkConf().setAppName("JavaSparkPi"); | ||
JavaSparkContext jsc = new JavaSparkContext(sparkConf); | ||
|
||
int slices = (args.length == 1) ? Integer.parseInt(args[0]) : 2; | ||
int n = 1 * slices; | ||
System.out.println("n:"+n+"\tslices:"+slices); | ||
List<Integer> l = new ArrayList<Integer>(n); | ||
for (int i = 0; i < n; i++) { | ||
l.add(i); | ||
} | ||
|
||
JavaRDD<Integer> dataSet = jsc.parallelize(l, slices); | ||
|
||
int count = dataSet.map(new Function<Integer, Integer>() { | ||
@Override | ||
public Integer call(Integer integer) { | ||
double x = Math.random() * 2 - 1; | ||
double y = Math.random() * 2 - 1; | ||
return (x * x + y * y < 1) ? 1 : 0; | ||
} | ||
}).reduce(new Function2<Integer, Integer, Integer>() { | ||
@Override | ||
public Integer call(Integer integer, Integer integer2) { | ||
return integer + integer2; | ||
} | ||
}); | ||
|
||
System.out.println("Pi is roughly " + 4.0 * count / n); | ||
|
||
jsc.stop(); | ||
} | ||
} | ||
|
Oops, something went wrong.