2017-05-24 39 views
1

我知道有關於此的一些問題,但沒有足夠的信息來解決我的問題。客戶端紗線作業的Scala錯誤

我嘗試從我的Eclipse項目中以yarn-client模式運行作業。我有一個擁有2個節點的hadoop集羣(其中一個目前關閉)。我試圖在集羣模式下運行它(使用spark-submit),它的工作。我試圖從當地月食項目,運行它:

我試圖做一個星火背景是這樣的:

 SparkConf conf = new SparkConf().setAppName("AnomalyDetection-BuildModel").setMaster("local[*]"); 

和它的作品。

但是,當我嘗試使用「紗客戶」運行:

SparkConf conf = new SparkConf().setAppName("AnomalyDetection-BuildModel").setMaster("yarn-client").set("driver-memory", "556m").set("executor-memory", "556m").set("executor-cores", "1").set("queue", "default"); 

我recived錯誤:

cannot assign instance of scala.collection.immutable.List$SerializationProxy to field org.apache.spark.rdd.RDD.org$apache$spark$rdd$RDD$$dependencies_ of type scala.collection.Seq in instance of org.apache.spark.rdd.MapPartitionsRDD 

另一個問題是,我不知道到底該如何依賴和兼容性工作在這種情況下,爲什麼與本地[*]我沒有收到任何錯誤。

這是我的pom.xml文件:

<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> 
    <groupId>buildModelTest</groupId> 
    <artifactId>buildModelTest</artifactId> 
    <version>1</version> 
    <properties> 
     <encoding>UTF-8</encoding> 
     <scala.version>2.11.8</scala.version> 
     <spark.version>2.1.0</spark.version> 
     <hadoop.version>2.7.0</hadoop.version> 
    </properties> 
    <dependencies> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>3.8.1</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.spark</groupId> 
      <artifactId>spark-core_2.10</artifactId> 
      <version>2.1.0</version> 
      <scope>provided</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.spark</groupId> 
      <artifactId>spark-mllib_2.10</artifactId> 
      <version>2.1.0</version> 
      <scope>provided</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.scala-lang</groupId> 
      <artifactId>scala-reflect</artifactId> 
      <version>2.11.8</version> 
      <scope>provided</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.spark</groupId> 
      <artifactId>spark-yarn_2.10</artifactId> 
      <version>2.1.0</version> 
      <scope>provided</scope> 
     </dependency> 
     <dependency> 
      <groupId>org.scalatest</groupId> 
      <artifactId>scalatest_2.11</artifactId> 
      <version>3.0.0</version> 
      <scope>provided</scope> 
     </dependency> 
    </dependencies> 
    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-jar-plugin</artifactId> 
       <configuration> 
        <archive> 
         <manifest> 
          <mainClass>buildModelTest.Main</mainClass> 
         </manifest> 
        </archive> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.3</version> 
      </plugin> 
     </plugins> 
    </build> 
</project> 

在我加入Hadoop的的配置文件的Eclipse項目,並構建配置SCALA_HOME,SPARK_HOME,HADOOP_CONF_DIR環境變量。關於SPARK,我有spark-2.1.0-bin-hadoop2.7和SCALA 2.11.8。在我的Java項目中,我添加了Spark/bin中的所有jar。

所以,你們有什麼想法,爲什麼這不是與「客戶端紗」,是否有依賴問題?如果是的話,正常和紗線客戶之間在依賴方面有什麼不同? Maven爲我下載了一些從Spark/bin添加的jar,所以我想其中有些是多餘的。

編輯

sparkContext正確初始化(我猜)。當我打電話.rrd()方法將引發錯誤:

 JavaRDD<Vector> parsedTrainingData = data.map(new Function<String, Vector>() { 

        private static final long serialVersionUID = 1L; 

        public Vector call(String s) { 
         String[] sarray = s.split(" "); 
         double[] values = new double[sarray.length]; 
         for (int i = 0; i < sarray.length; i++) { 
          values[i] = Double.parseDouble(sarray[i]); 
         } 
         return Vectors.dense(values); 
        } 
       }); 
       parsedTrainingData.cache(); 

       // Cluster the data into two classes using KMeans 
       KMeansModel clusters = KMeans.train(parsedTrainingData.rdd(), numClusters, numIterations); 

回答

0

從你的代碼,它看起來像你正在嘗試運行YARN集羣上的星火應用。

SparkConf conf = new SparkConf().setAppName("AnomalyDetection-BuildModel").setMaster("yarn-client").set("driver-memory", "556m").set("executor-memory", "556m").set("executor-cores", "1").set("queue", "default"); 

這裏,setMaster("yarn-client")是master的錯誤參數。

當您將主設置爲local[*]時,您的Spark應用程序在您的機器中的單個JVM中運行。

要將火花應用程序提交到正在運行的YARN羣集,請設置setMaster("yarn")並且還可以選擇將deploy-mode屬性設置爲客戶端或羣集。

有關這些參數的更多詳細信息,請參閱this

此外,如果您想從代碼而不是從命令行提交您的應用程序,則請參閱this post

+0

我試圖改變我的參數,如你所說。該應用程序的行爲完全相同。所以我猜.setmaster(「紗線客戶端」)是一樣的。setmaster( 「紗」)。組( 「部署模式」, 「客戶端」)。 嗯,我這樣做是爲了避免從命令行執行它。根據我的理解,這是他們從代碼提交Spark應用程序的方式。 –