def job_url_update(_job_key=""): func_name = sys._getframe().f_code.co_name file_name = __name__.upper() helpers.job_key_check(_job_key, func_name, file_name) file_dir_name = os.path.dirname(os.path.abspath(__file__)) job_status_interface = weibox_macros.CC_JOB_UPDATE_INTERFACE job_space = helpers.job_space(_job_key) job_trace_log_file = job_space + "/weiflow-from-weiclient.log" job_status = "" try: # job submit failed if (not os.path.isdir(job_space)): job_status_update.job_status_update(_job_key, "FAILED") # job run failed elif (not os.path.isfile(job_trace_log_file)): job_status_update.job_status_update(_job_key, "LOST") # job run successed. else: yarn_app_id = read_yarn_app_id(_job_key) # job not fount applicationId : submitted just now or has no applicationId if ("NULL_YARN_APPLICATION_ID" == yarn_app_id): job_status_update.job_status_update(_job_key, "WAITING") else: log_url = weibox_macros.CC_JOB_LOG_URL_INTERFACE % _job_key job_url = yarn_operation.job_trace_url(yarn_app_id) # job_status = json.loads(com.weibo.weibox.yarn.tools.yarn_operation.yarn_job_query(yarn_app_id)).get("app").get("state") job_status = yarn_operation.yarn_job_status(yarn_app_id) job_status_update.job_update(_job_key=_job_key, _status=job_status, _job_url=job_url, _log_url=log_url) except Exception, e: logger.error(func_name + " : " + e.message)
def job_status(_job_key=""): # checke the job_key func_name = sys._getframe().f_code.co_name file_name = __name__.upper() helpers.job_key_check(_job_key, func_name, file_name) job_status_update.job_status_update(_job_key=_job_key, _status="acceptted") status_cmd = assembleCmd(_job_key) print("arena status cmd: %s " % status_cmd) '''
def job_query(_job_key = ""): func_name = sys._getframe().f_code.co_name file_name = __name__.upper() helpers.job_key_check(_job_key,func_name,file_name) try: response_info = helpers.get(utils.weibox_macros.CC_JOB_QUERY_INTERFACE % _job_key) response_obj = json.loads(response_info) except Exception,e: logger.error(e.message + "at %s." % file_name)
def job_update(_job_key = "", _status = "", _job_url = "", _log_url = ""): func_name = sys._getframe().f_code.co_name file_name = __name__.upper() helpers.job_key_check(_job_key,func_name,file_name) job_status_interface = utils.weibox_macros.CC_JOB_UPDATE_INTERFACE job_update_url = job_status_interface + "&jobUrl=%s&logUrl=%s&jobStatus=%s" % (_job_url,_log_url,_status) job_update_url = job_status_interface param_update = {"jobKey" : _job_key, "jobUrl" : _job_url, "logUrl" : _log_url, "jobStatus" : _status} return helpers.post(job_update_url, param_update, "basic")
def job_stdout_update(_job_key=""): func_name = sys._getframe().f_code.co_name file_name = __name__.upper() helpers.job_key_check(_job_key, func_name, file_name) file_dir_name = os.path.dirname(os.path.abspath(__file__)) job_stdout_interface = utils.weibox_macros.CC_JOB_STDOUT_INTERFACE job_space = helpers.job_space(_job_key) job_log_file = job_space + "/weiflow-from-weiclient.log" param_value = {"jobKey": _job_key, "file": job_log_file} return helpers.post(job_stdout_interface, param_value, "stdout")
def read_yarn_app_id(_job_key = ""): func_name = sys._getframe().f_code.co_name file_name = __name__.upper() helpers.job_key_check(_job_key,func_name,file_name) file_dir_name = os.path.dirname(os.path.abspath(__file__)) job_status_interface = weibox_macros.CC_JOB_UPDATE_INTERFACE job_space = helpers.job_space(_job_key) job_trace_log_file = job_space + weibox_macros.WEIBOX_LOG logger.info("JOB_TRACE_LOG_FILE : %s." % job_trace_log_file) try: job_log_content = open(job_trace_log_file).read() yarn_app_id = resolve_yarn_app_id([job_log_content]) except Exception,e: logger.error(func_name + " : " + e.message)
def job_prepare(_job_key=""): # checke the job_key func_name = sys._getframe().f_code.co_name file_name = __name__.upper() helpers.job_key_check(_job_key, func_name, file_name) # update the status to cc show weibox received the job. job_status_update.job_status_update(_job_key=_job_key, _status="submitting") weibox_operation.job_seperate(_job_key) _key = "result.json" rst_json = get_args.get_args(_job_key, _key) # job prepared. ready job_status_update.job_status_update(_job_key=_job_key, _status="ready") return rst_json
def job_seperate(_job_key=""): func_name = sys._getframe().f_code.co_name file_name = __name__.upper() helpers.job_key_check(_job_key, func_name, file_name) #response_obj = job_status_update.job_query(_job_key) #code_path = helpers.get_value("result.codePath", response_obj) job_space = helpers.job_space(_job_key) if (os.path.isdir(job_space)): import shutil shutil.rmtree(job_space) mkdir_response_code = os.makedirs(job_space) print("mkdir code:%s" % mkdir_response_code) #rsync_response_code = 0 #if("null" != code_path): #rsync_response_code = helpers.sys_run("rsync -zr --progress 10.77.29.68::backup/weiflow/%s/* %s/" % (code_path,job_space)) return mkdir_response_code # or rsync_response_code
def job_prepare(_job_key=""): # checke the job_key func_name = sys._getframe().f_code.co_name file_name = __name__.upper() helpers.job_key_check(_job_key, func_name, file_name) # update the status to cc show weibox received the job. job_status_update.job_status_update(_job_key=_job_key, _status="submitting") response_obj = job_status_update.job_query(_job_key) target_user_cc = weibox_macros.submit_account( helpers.get_value("result.submitAccount", response_obj)) # run_command = helpers.get_value("result.runCommand", response_obj) _key = "result.json" rst_json = get_args.get_args(_job_key, _key) specified_submit_type = rst_json.get("job_common_submit_type") # job prepared. ready job_status_update.job_status_update(_job_key=_job_key, _status="ready") return rst_json
def job_submit(_job_key=""): # checke the job_key func_name = sys._getframe().f_code.co_name file_name = __name__.upper() helpers.job_key_check(_job_key, func_name, file_name) rst_json = job_prepare(_job_key) job_status_update.job_status_update(_job_key=_job_key, _status="acceptted") submit_cmd = assemble_cmd(rst_json, _job_key) print("arena submit cmd: %s " % submit_cmd) try: #sys_run_code = helpers.sys_run(submit_cmd) status, output = commands.getstatusoutput(submit_cmd) print("status code :%s" % status) print("output :%s" % output) if (0 == status): log_url = get_log_url(rst_json) print("log url:%s" % log_url) job_url = get_job_url(log_url) print("job url:%s" % job_url) job_log_url = job_url + "\n" + log_url #job_status_update.job_update(_job_key, "acceptted", log_url, "") job_status_update.job_update(_job_key, "acceptted", job_log_url, "") #job_space = helpers.job_space(_job_key) #log_cmd = "arena logs -f " + rst_json.get("job_name") + " >> " + job_space + "/weiflow-from-weiclient.log" #print("logs cmd:%s" % log_cmd) #status, output = commands.getstatusoutput(log_cmd) #job_url_update.job_url_update(_job_key) #job_status_update.job_status_update(_job_key = _job_key, _status = "finished") else: job_status_update.job_status_update(_job_key=_job_key, _status="failed") print(output) except Exception, e: logger.warn(e) job_status_update.job_status_update(_job_key=_job_key, _status="failed")
def job_log_and_update(_job_key=""): func_name = sys._getframe().f_code.co_name file_name = __name__.upper() helpers.job_key_check(_job_key, func_name, file_name) job_url_update(_job_key) job_stdout_update(_job_key)