@rm_ha
  def get_job(self, jobid):

    job_id = jobid.replace('application', 'job')
    app_id = jobid.replace('job', 'application')

    try:
      app = self.resource_manager_api.app(app_id)['app']

      if app['finalStatus'] in ('SUCCEEDED', 'FAILED', 'KILLED'):
        if app['applicationType'] == 'SPARK':
          job = SparkJob(app, rm_api=self.resource_manager_api, hs_api=self.spark_history_server_api)
        elif app['state'] == 'KILLED':
          job = KilledYarnJob(self.resource_manager_api, app)
        else:
          resp = self.history_server_api.job(self.user, job_id)
          job = YarnJob(self.history_server_api, resp['job'])
      else:
        if app['state'] == 'ACCEPTED':
          raise ApplicationNotRunning(app_id, app)
        # The MapReduce API only returns JSON when the application is in a RUNNING state
        elif app['state'] in ('NEW', 'SUBMITTED', 'RUNNING') and app['applicationType'] == 'MAPREDUCE':
          resp = self.mapreduce_api.job(self.user, job_id)
          job = YarnJob(self.mapreduce_api, resp['job'])
        else:
          job = Application(app, self.resource_manager_api)
    except RestException, e:
      if e.code == 404:  # Job not found in RM so attempt to find job in History Server
        resp = self.history_server_api.job(self.user, job_id)
        job = YarnJob(self.history_server_api, resp['job'])
      else:
        raise JobExpired(app_id)
    except ApplicationNotRunning, e:
      raise e
    except Exception, e:
      raise PopupException('Job %s could not be found: %s' % (jobid, e), detail=e)

    return job
dataset/ETHPy150Open cloudera/hue/apps/jobbrowser/src/jobbrowser/api.py/YarnApi.get_job/original