【发布时间】:2014-10-11 13:18:36
【问题描述】:
我是一名学习 Hadoop 和 Apache Spark 的学生。我想知道如何从网络上的 Apache Spark Job 获取输出。
以下是在 web 上运行 Apache Spark Job 的简单 php 代码,因为我只是想对其进行测试。
<?php
echo shell_exec("spark-submit --class stu.ac.TestProject.App --master spark://localhost:7077 /TestProject-0.0.1-SNAPSHOT.jar");
?>
以下是 Apache Spark 作业的示例 java 代码。
public class App
{
public static void main( String[] args )
{
SparkConf sparkConf = new SparkConf().setAppName("JavaSparkPi");
sparkConf.setMaster("spark://localhost:7077");
JavaSparkContext jsc = new JavaSparkContext(sparkConf);
int slices = (args.length == 1) ? Integer.parseInt(args[0]) : 2;
int n = 100000 * 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);
JavaRDD<Integer> countRDD = dataSet.map(new Function<Integer, Integer>() {
public Integer call(Integer arg0) throws Exception {
double x = Math.random() * 2 - 1;
double y = Math.random() * 2 - 1;
return (x * x + y * y < 1) ? 1 : 0;
}
});
int count = countRDD.reduce(new Function2<Integer, Integer, Integer>() {
public Integer call(Integer arg0, Integer arg1) throws Exception {
return arg0 + arg1;
}
});
System.out.println("Pi is roughly " + 4.0 * count / n);
jsc.stop();
}
}
我只想获得标准输出,但运行代码后我得到了空输出。我在 maven 项目上构建了这个 java 代码,所以还检查了它在 cmd 模式下的运行情况。
我该如何解决?
提前感谢您的回答,并为我糟糕的英语感到抱歉。如果您不理解我的问题,请发表评论。
【问题讨论】:
标签: java web-services hadoop apache-spark