def send_job_execution_uve(self, fabric_fq_name, job_template_fqname, job_execution_id, timestamp=None, percentage_completed=None): try: fabric_job_name = list(job_template_fqname) fabric_job_name.insert(0, fabric_fq_name) fabric_job_uve_name = ':'.join(map(str, fabric_job_name)) job_exe_data = FabricJobExecution( name=fabric_job_uve_name, job_status='IN_PROGRESS', percentage_completed=percentage_completed) job_uve = FabricJobUve(data=job_exe_data, sandesh=self.config_logger._sandesh) job_uve.send(sandesh=self.config_logger._sandesh) except Exception as exp: job_template_fqname = self.get_fq_name_log_str(job_template_fqname) msg = MsgBundle.getMessage(MsgBundle.SEND_JOB_EXC_UVE_ERROR, job_template_fqname=job_template_fqname, job_execution_id=job_execution_id, exc_msg=repr(exp)) raise JobException(msg, job_execution_id)
def create_fabric_job_uve(self, fabric_job_uve_name, execution_id, job_status, percentage_completed): job_execution_data = FabricJobExecution( name=fabric_job_uve_name, execution_id=execution_id, job_start_ts=int(round(time.time() * 1000)), job_status=job_status, percentage_completed=percentage_completed) job_execution_uve = FabricJobUve(data=job_execution_data, sandesh=self._sandesh) job_execution_uve.send(sandesh=self._sandesh)
def job_mgr_signal_handler(self, signalnum, frame): pid = None signal_var = None try: # get the child process id that called the signal handler pid = os.waitpid(-1, os.WNOHANG) signal_var = self._job_mgr_running_instances.get(str(pid[0])) if not signal_var: self._logger.error( "Job mgr process %s not found in the instance " "map" % str(pid)) return msg = "Entered job_mgr_signal_handler for: %s" % signal_var self._logger.notice(msg) exec_id = signal_var.get('exec_id') status, prouter_info, device_op_results, failed_devices_list = \ self._extracted_file_output(exec_id) self.job_status[exec_id] = status self.publish_job_status_notification(exec_id, status) if signal_var.get('fabric_name') != "__DEFAULT__"\ and not signal_var.get('device_fqnames'): job_execution_data = FabricJobExecution( name=signal_var.get('fabric_name'), job_status=status, percentage_completed=100) job_execution_uve = FabricJobUve(data=job_execution_data, sandesh=self._sandesh) job_execution_uve.send(sandesh=self._sandesh) else: for prouter_uve_name in signal_var.get('device_fqnames'): prouter_status = status device_name = prouter_uve_name.split(":")[1] if device_name in failed_devices_list: prouter_status = "FAILURE" prouter_job_data = PhysicalRouterJobExecution( name=prouter_uve_name, job_status=prouter_status, percentage_completed=100, device_op_results=json.dumps( device_op_results.get(device_name, {}))) prouter_job_uve = PhysicalRouterJobUve( data=prouter_job_data, sandesh=self._sandesh) prouter_job_uve.send(sandesh=self._sandesh) for k, v in prouter_info.iteritems(): prouter_uve_name = "%s:%s" % (k, signal_var.get('fabric_name')) prouter_job_data = PhysicalRouterJobExecution( name=prouter_uve_name, execution_id=exec_id, job_start_ts=int(round( signal_var.get('start_time') * 1000)), prouter_state=v) prouter_job_uve = PhysicalRouterJobUve(data=prouter_job_data, sandesh=self._sandesh) prouter_job_uve.send(sandesh=self._sandesh) self._clean_up_job_data(signal_var, str(pid[0])) self._logger.info( "Job : %s finished. Current number of job_mgr " "processes running now %s " % (signal_var, self._job_mgr_statistics['number_processess_running'])) except OSError as process_error: self._logger.error("Could not retrieve the child process id. " "OS call returned with error %s" % str(process_error)) except Exception as unknown_exception: self._clean_up_job_data(signal_var, str(pid[0])) self._logger.error("Failed in job signal handler %s" % str(unknown_exception))