code: public static void killJobOnCluster(String applicationId, Logger log) throws YarnException,
        IOException {
  
      YarnConfiguration yarnConf = new YarnConfiguration();
      YarnClient yarnClient = YarnClient.createYarnClient();
      yarnClient.init(yarnConf);
      yarnClient.start();
  
      String[] split = applicationId.split("_");
      ApplicationId aid = ApplicationId.newInstance(Long.parseLong(split[1]),
          Integer.parseInt(split[2]));
  
      log.info("start klling application: " + aid);
      yarnClient.killApplication(aid);
      log.info("successfully killed application: " + aid);
    }
docs: <pre>
  Uses YarnClient to kill the job on HDFS.
  Using JobClient only works partially:
  If yarn container has started but spark job haven't, it will kill
  If spark job has started, the cancel will hang until the spark job is complete
  If the spark job is complete, it will return immediately, with a job not found on job tracker
  </pre>