2016-03-31 86 views
3

我试图在使用DCOS cli的mesos上启动火花流作业。 我能够开始工作。我的程序希望一个配置文件作为cli参数传递。我如何实现这一点dcos spark run --submit-args使用mesos的火花提交dcos cli

我试过--files http://server/path/to//file希望它会下载文件,但没有奏效。驱动程序启动但失败,因为配置文件丢失。

我也尝试将jar和配置文件作为tar卷起来并提交。我可以在Mesos日志中看到焦油被提取和解压。 config和jar文件都可以在工作目录中看到。但是,作业因ClassNotFoundException而失败。我怀疑有关火花提交是如何开始的。

dcos spark run --submit-args="--supervise --deploy-mode cluster --class package.name.classname http://file-server:8000/Streaming.tar.gz Streaming.conf" 

任何提示如何进行?另外,在哪个日志文件中可以看到DCOS使用的基础spark-submit命令?

回答

3

这里是你应该为了使启动命令它工作的例子:

dcos spark run --submit-args='--conf spark.mesos.uris=https://s3-us-west-2.amazonaws.com/andrey-so-36323287/pi.conf --class JavaSparkPiConf https://s3-us-west-2.amazonaws.com/andrey-so-36323287/sparkPi_without_config_file.jar /mnt/mesos/sandbox/pi.conf'

--conf spark.mesos.uris=...驱动程序或执行程序由Mesos启动时,要下载到沙箱的逗号分隔列表。这适用于粗粒度和细粒度模式。

/mnt/mesos/sandbox/pi.conf下载文件的路径,您的主类接收为第0个参数(请参阅下面的代码段)。 /mnt/mesos/sandbox/是映射到corespondent mesos任务沙箱的容器内的标准路径。

public final class JavaSparkPiConf { 

    public static void main(String[] args) throws Exception { 
    SparkConf sparkConf = new SparkConf().setAppName("JavaSparkPi"); 
    JavaSparkContext jsc = new JavaSparkContext(sparkConf); 

    Scanner scanner = new Scanner(new FileInputStream(args[0])); 
    int slices; 
    if (scanner.hasNextInt()) { 
     slices = scanner.nextInt(); 
    } else { 
     slices = 2; 
    } 
    int n = 100000 * slices; 
    List<Integer> l = new ArrayList<>(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(); 
    } 
} 
+0

就是这样。缺失的部分是在/ mnt/mesos/sandbox中查找下载的文件。 – Cheeko

2

Streaming.conf只是一个字符串,将传递给您的驱动程序。您的驱动程序必须能够看到它。最简单的方法是将其放置在一个可访问的位置,指定要通过spark.mesos.uris [1]将其下载到沙盒中。您可以交替编写应用程序以支持从远程位置读取数据,只需在CLI上传递位置即可。

--files用于在执行文件中放置文件,但是您尝试将文件传递给驱动程序,因此无法正常工作。

[1] http://spark.apache.org/docs/latest/running-on-mesos.html

迈克尔Gummelt
中层

+0

我知道的参数传递给程序:) 驱动程序字符串已经读取该文件。我试图让它可用。我会尝试你的建议。 URI中指定的链接在什么时候被下载?我在启动spark上下文之前阅读conf文件。 – Cheeko

+0

多一个,如果我需要在执行器中放置额外的文件( - 文件)或罐子( - 罐子),我该如何实现? – Cheeko

+0

spark.mesos.uris does not download the file。我可以在mesos fetcher日志中看到。但它不在当前目录或类路径中。我无法在代码中“查看”该文件。我已经使用直接从共享位置阅读,但知道如何管理和共享资源将是一件好事。 – Cheeko