I am using Hadoop 2.0 with Cloudera and trying a Java program that will check if a particular Spark applicationID is running or not and take further steps.

I have Main Class and user (account) information which triggered a particular Spark Application. 

I am aware of below but is there any Java API that can help parse and match using Main class name and user name ?

```
yarn application -list

```

Is there any way we can get the applicationID of a running spark Application by using Main Class and user information in another Java program ?

[EDIT] One way to is to issue below command :

```
yarn application -list -appStates RUNNING | grep $application_name | grep $user | cut -f 1

```

If there is any Java API that can simplify, please share.

[EDIT] Above command is fine however I tried with YarnClient as below:

public class SomeCheck {

```
    public boolean run(String account, String appName) throws YarnException, IOException {

        SparkContext sc = new SparkContext(new SparkConf().setMaster("yarn").setAppName("SomeCheck"));
        YarnConfiguration conf = new YarnConfiguration(SparkHadoopUtil.get().newConfiguration(sc.getConf()));

        YarnClient yarnClient = YarnClient.createYarnClient();
        yarnClient.init(conf);
        yarnClient.start();
        EnumSet<YarnApplicationState> states =
                  EnumSet.of(YarnApplicationState.ACCEPTED, YarnApplicationState.RUNNING);

        List<ApplicationReport> applications = yarnClient.getApplications(states);

        for (ApplicationReport application : applications) {
               if ((application.getUser() == account) & (application.getName() == appName)) return true;
        }

        return false;

    }

}

```

It is failing with pointing to `SparkContext sc = new SparkContext(new SparkConf().setMaster("yarn").setAppName("SomeCheck"));`

Error:

```
 ERROR spark.SparkContext: Error initializing SparkContext.
com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'akka.version'

```

Is there anything incorrect in the code ?