title: Spark Launcher waiting for job completion infinitely
body: <p>I am trying to submit a JAR with Spark job into the YARN cluster from Java code. I am using SparkLauncher to submit SparkPi example:</p>
  
  <pre><code>Process spark = new SparkLauncher()
      .setAppResource("C:\\spark-1.4.1-bin-hadoop2.6\\lib\\spark-examples-1.4.1-hadoop2.6.0.jar")
      .setMainClass("org.apache.spark.examples.SparkPi")
      .setMaster("yarn-cluster")
      .launch();
  System.out.println("Waiting for finish...");
  int exitCode = spark.waitFor();
  System.out.println("Finished! Exit code:" + exitCode);
  </code></pre>
  
  <p>There are two problems:</p>
  
  <ol>
  <li>While submitting in "yarn-cluster" mode, the application is sucessfully submitted to YARN and executes successfully (it is visible in the YARN UI, reported as SUCCESS and pi is printed in the output). However, the submitting application is never notified that processing is finished - it hangs infinitely after printing "Waiting to finish..." The log of the container can be found <a href="http://pastebin.com/LscBjHQc">here</a></li>
  <li>While submitting in "yarn-client" mode, the application does not appear in YARN UI and the submitting application hangs at "Waiting to finish..." When hanging code is killed, the application shows up in YARN UI and it is reported as SUCCESS, but the output is empty (pi is not printed out). The log of the container can be found <a href="http://pastebin.com/9KHi81r4">here</a></li>
  </ol>
  
  <p>I tried to execute the submitting application both with Oracle Java 7 and 8.</p>