Search code examples
apache-sparkspark-launcher

Spark launcher handle and listener not giving state


I have a web application which will submit spark jobs on Cloudera spark cluster using spark launcher library.

It is successfully submitting the spark job to cluster. However it is not calling back the listener class methods and also the getState() on returned SparkAppHandle never changes from "UNKNOWN" even after job finishes execution on cluster.

I am using yarn-cluster mode. Here is my code. Is anything else needs to be done?

SparkLauncher launcher = new SparkLauncher()
                           .setSparkHome("sparkhome")
                           .setMaster("yarn-cluster")
                           .setAppResource("spark job jar file")
                           .setMainClass("spark job driver class")
                           .setAppName("appname")
                           .addAppArgs(argsArray)
                           .setVerbose(true)
                           .addSparkArg("--verbose");

SparkAppHandle handle = launcher.startApplication(new LauncherListener());

int c = 0;
while(!handle.getState().isFinal()) {
  LOG.info(">>>>>>>> state is=  "+handle.getState() );
  LOG.info(">>>>>>>> state is not final yet. counter=  "+c++ );
  LOG.info(">>>>>>>> sleeping for a second");
  try {
    Thread.sleep(1000L);
  } catch (InterruptedException e) {
  }
  if(c == 200)
    break;
}

Here are the things I have already tried:

  1. Added listener instance to SparkAppHandle once application is launched.
  2. Made the current class implement SparkAppHandle.Listener and passed it (this) in both ways (while launching, and by setting it on SparkAppHandle)
  3. Tried to use launcher.launch() method so that at least I can block on the resulting Process object by calling process.waitFor() method till spark job finishes running on cluster. However in this case, for long running spark jobs, corresponding process on this node never returns (though it works fine for spark jobs which are finishing in 1 or 2 min)

Solution

  • I have got answer for this question from spark user mailing list. For this functionality to work, not only spark launcher needs to be 1.6.0 but also underlying spark should be 1.6.0 at least.

    I have been using spark 1.5.1 and 1.6.0 version of launcher library. Now I have updated spark cluster to 1.6.0 version and now I am getting the callbacks to listener methods.