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)
def get_job(self, jobid): try: # App id jobid = jobid.replace('job', 'application') job = self.resource_manager_api.app(jobid)['app'] if job['state'] == 'ACCEPTED': raise ApplicationNotRunning(jobid, job) elif job['state'] == 'KILLED': return KilledYarnJob(self.resource_manager_api, job) if job.get('applicationType') == 'SPARK': job = SparkJob(job, self.resource_manager_api) elif job.get('applicationType') == 'MAPREDUCE': jobid = jobid.replace('application', 'job') if job['state'] in ('NEW', 'SUBMITTED', 'ACCEPTED', 'RUNNING'): json = self.mapreduce_api.job(self.user, jobid) job = YarnJob(self.mapreduce_api, json['job']) else: json = self.history_server_api.job(self.user, jobid) job = YarnJob(self.history_server_api, json['job']) else: job = Application(job, self.resource_manager_api) except ApplicationNotRunning, e: raise e
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'] in ('KILLED', 'FAILED'): job = KilledYarnJob(self.resource_manager_api, app) else: # Job succeeded, attempt to fetch from JHS job = self._get_job_from_history_server(job_id) 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) if not isinstance(resp, dict): raise PopupException(_('Mapreduce Proxy API did not return JSON response, check if the job is running.')) 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 JHS job = self._get_job_from_history_server(job_id) else: raise JobExpired(app_id)