def trm_task(main_p, command_data, web=False): try: return_message = [] command_string = ' '.join(command_data[1:]) for task_name in map(lambda x:x.strip(), command_string.split(',')): ret = main_p.thread_daemon_list['Core'].trm_task(task_name) for line in ret: return_message.append(line) if not web: return MF.make_message(return_message) else: return MF.simple_result_json(return_message) except Exception, e: error_msg = "NOK : Exception occured in trm task [%s]" % str(e) if not web: return MF.make_message(error_msg) else: return MF.simple_result_json([error_msg])
def set_recovery(main_p, command_data, web=False): try: return_message = [] command_string = " ".join(command_data[2:]) for command in map(lambda x:x.strip(), command_string.split(',')): _task_name, _message = map(lambda x:x.strip(), command.split(':')) ret = main_p.thread_daemon_list['Core'].add_recovery(_task_name, _message) for line in ret: return_message.append(line) if not web: return MF.make_message(return_message) else: return MF.simple_result_json(return_message) except Exception, e: error_msg = "NOK : Exception occured in set recovery [%s]" % str(e) if not web: return MF.make_message(error_msg) else: return MF.simple_result_json([error_msg])
def shw_global_queue(main_p, command_data, web=False): try: return_value = [] for x in main_p.mon_deque: return_value.append('[%s] : %s : %s' % x) if not web: return MF.make_message(return_value) else: return MF.simple_result_json( return_value, header='GLOBAL_QUEUE', column=['DATETIME', 'DIRECTION', 'MESSAGE']) except Exception, e: error_msg = "NOK : Exception occured in shw global_queue [%s]" % str(e) if not web: return MF.make_message(error_msg) else: return MF.simple_result_json([error_msg])
def shw_status(main_p, command_data, web=False, recursive=False): task_list_obj = main_p.thread_daemon_list['Core'].all_task_object group_list_obj = main_p.thread_daemon_list['Core'].all_group try: return_hash = {} return_hash['STATUS'] = [] if recursive: command_string = command_data else: command_string = ' '.join(command_data[2:]) if type(command_string) == type('') and len(command_string.strip()) == 0: command_string = 'all' for command in map(lambda x:x.strip(), command_string.split(',')): if command not in task_list_obj: if command.lower() == 'all': for _task_name in task_list_obj.keys(): ret = shw_status(main_p, _task_name, recursive=True) for _key in ret['STATUS']: return_hash['STATUS'].append(_key) elif command in group_list_obj: for _task_name in group_list_obj[command]: ret = shw_status(main_p, _task_name, recursive=True) for _key in ret['STATUS']: return_hash['STATUS'].append(_key) else: temp_hash = {} temp_hash['name'] = command temp_hash['error'] = 'NOK : [%s] task not exists' % command return_hash['STATUS'].append(temp_hash) else: return_hash['STATUS'].append(task_list_obj[command].status) if recursive: return return_hash if not web: return_message = [] prefix = '%10s | %86s' return_hash['STATUS'] = sorted(return_hash['STATUS'], key=lambda value:value['name']) for _item in return_hash['STATUS']: return_message.append('=' * 100) return_message.append(_item['name']) return_message.append('-' * 100) if 'error' in _item: return_message.append( prefix % ('error', _item['error']) ) continue for _key in [ 'type', 'status', 'act-status', 'act-time', 'act-count', 'pid', 'command' ]: return_message.append( prefix % ( _key, str(_item[_key]) )) return_message.append('-' * 100) return_message.append('last-status') return_message.append('-' * 100) for _key in [ 'std-in', 'std-out', 'std-err' ]: return_message.append( prefix % ( _key, str(_item['last-status']['last-' + _key]) ) ) return MF.make_message(return_message) else: return MF.make_json(return_hash) except Exception, e: error_msg = "NOK : Exception occured in shw status [%s]" % str(e) if not web: return MF.make_message(error_msg) else: return MF.simple_result_json([error_msg])
def shw_schedule(main_p, command_data, web=False): try: parser = OptionParser() parser.add_option('-f', '--time-format', dest='time_format') parser.add_option('-t', '--task', dest='task') options, _ = parser.parse_args(command_data) except OptionParsingError, e: error_msg = 'NOK : shw schedule option error [%s]' % str(e) if not web: return MF.make_message(error_msg) else: return MF.simple_result_json([error_msg])
def del_schedule(main_p, command_data, web=False): command_string = ' '.join(command_data[2:]) try: for command in map(lambda x:x.strip(), command_string.split(',')): time_info, dst_task = map(lambda x:x.strip(), command_string.split(':')) if len(time_info.split()) != 5: raise Exception, "time format follow cron expression" main_p.schedule_conn.rmv(time_info, dst_task) except Exception, e: error_msg = 'NOK : Exception occured in del schedule [%s]' % str(e) if not web: return MF.make_message(error_msg) else: return MF.simple_result_json([error_msg])
def set_flow(main_p, command_data, web=False): core_obj = main_p.thread_daemon_list['Core'] try: return_message = [] command_string = ' '.join(command_data[2:]) for command in map(lambda x:x.strip(), command_string.split(',')): flow_type, flow_from, flow_to = map(lambda x:x.strip(), command.split(':')) for flow_from_item in map(lambda x:x.strip(), flow_from.split('|')): for flow_to_item in map(lambda x:x.strip(), flow_to.split('|')): ret = core_obj.add_flow(flow_type.lower(), flow_from_item, flow_to_item) for item in ret: return_message.append(item) try: main_p.flow_conn.set(flow_type.lower(), flow_from_item, flow_to_item) except Exception, e: return_message.append( 'NOK : Exception occured in set flow save : %s' % str(e) ) if not web: return MF.make_message(return_message) else: return MF.simple_result_json(return_message) except Exception, e: error_msg = "NOK : Exception occured in set flow [%s]" % str(e) if not web: return MF.make_message(error_msg) else: return MF.simple_result_json([error_msg])
def set_schedule(main_p, command_data, web=False): core_obj = main_p.thread_daemon_list['Core'] command_string = ' '.join(command_data[2:]) try: for command in map(lambda x:x.strip(), command_string.split(',')): time_info, dst_task, message = map(lambda x:x.strip(), command_string.split(':')) if len(time_info.split()) != 5: raise Exception, 'time format follow cron expression' if dst_task not in core_obj.all_task_object: raise Exception, '[%s] task not exists' % dst_task main_p.schedule_conn.set(time_info, dst_task, message) except Exception, e: error_msg = 'NOK : Exception occured in set schedule [%s]' % str(e) if not web: return MF.make_message(error_msg) else: return MF.simple_result_json([error_msg])
def shw_task(main_p, command_data, web=False): try: parser = OptionParser() parser.add_option('-t', '--task', dest='task') parser.add_option('-y', '--task-type', dest='task_type') parser.add_option('-s', '--status', dest='status') parser.add_option('-a', '--act-status', dest='act_status') parser.add_option('-p', '--pid', dest='pid') options, _ = parser.parse_args(command_data) except OptionParsingError, e: error_msg = 'NOK : shw task option error [%s]' % str(e) if not web: return MF.make_message(error_msg) else: return MF.simple_result_json([error_msg])
def set_stdin(main_p, command_data, web=False): return_message = [] command_string = ' '.join(command_data[2:]) for command in map(lambda x: x.strip(), command_string.split(',')): dst_task, message = command.split(':') if dst_task not in main_p.thread_daemon_list['Core'].all_task_object: return_message.append("NOK : [%s] task not exists" % dst_task) continue main_p.thread_daemon_list['Core'].all_task_object[dst_task].put_queue( message) return_message.append("OK : set stdin [%s] to %s" % (message, dst_task)) if not web: return MF.make_message(return_message) else: return MF.simple_result_json(return_message)
def lad_task_queue(main_p, command_data, web=False): tasks = main_p.thread_daemon_list['Core'].all_task_object command_string = ' '.join(command_data[1:]) result_message = [] try: if command_string.strip() == '': command_string = 'all' task_list = map(lambda x: x.strip(), command_string.split(',')) if 'all' in task_list: for task_name in tasks.keys(): if task_name not in task_list: task_list.append(task_name) for task_name in task_list: if task_name not in tasks: result_message.append('NOK : [%s] task not exist') continue ret = tasks[task_name].load_queue() for line in ret: result_message.append(line) if not web: return MF.make_message(result_message) else: return MF.simple_result_json(result_message) except Exception, e: error_msg = "NOK : Exception occured in del task queue : %s" % str(e) if not web: return MF.make_message(error_msg) else: return MF.simple_result_json([error_msg])
def decorated_function(*args, **kwargs): if self.debugMode:debugLog('decorator called by %s' % f.__name__) default_config = WLH._default_config.copy() try: if f.__name__ not in default_config:raise Exception, '%s is not supported' % f.__name__ try: json_data = request.get_json() except Exception, e: json_data = None command = default_config[f.__name__](request.method, json_data, kwargs) return self.middle_interface.command(command) except Exception, e: exceptionLog(str(e)) error_msg = "NOK : Exception is occured in decorator [%s]" % str(e) return MF.simple_result_json([error_msg])
def shw_ready(main_p, command_data, web=False): return_message = [] task_list_obj = main_p.thread_daemon_list['Core'].all_task_object add_list_obj = main_p.thread_daemon_list['Core'].add_list command_string = ' '.join(command_data[2:]) for task_name in map(lambda x:x.strip(), command_string.split(',')): if task_name in task_list_obj: return_message.append("OK : [%s] task ready" % task_name) continue message_data = "NOK : [%s] task not exists" % task_name for item in add_list_obj: if item[1] == task_name: message_data = "OK : [%s] task not ready" % task_name return_message.append(message_data) if not web: return MF.make_message(return_message) else: return MF.simple_result_json(return_message)
def set_schedule(main_p, command_data, web=False): core_obj = main_p.thread_daemon_list['Core'] command_string = ' '.join(command_data[2:]) try: for command in map(lambda x:x.strip(), command_string.split(',')): time_info, dst_task, message = map(lambda x:x.strip(), command_string.split(':')) if len(time_info.split()) != 5: raise Exception, 'time format follow cron expression' if dst_task not in core_obj.all_task_object: raise Exception, '[%s] task not exists' % dst_task main_p.schedule_conn.set(time_info, dst_task, message) except Exception, e: error_msg = 'NOK : Exception occured in set schedule [%s]' % str(e) if not web: return MF.make_message(error_msg) else: return MF.simple_result_json([error_msg]) return_msg = "OK : schedule set success" if not web: return MF.make_message(return_msg) else: return MF.simple_result_json([return_msg]) def del_schedule(main_p, command_data, web=False): command_string = ' '.join(command_data[2:]) try: for command in map(lambda x:x.strip(), command_string.split(',')): time_info, dst_task = map(lambda x:x.strip(), command_string.split(':')) if len(time_info.split()) != 5: raise Exception, "time format follow cron expression" main_p.schedule_conn.rmv(time_info, dst_task) except Exception, e: error_msg = 'NOK : Exception occured in del schedule [%s]' % str(e) if not web: return MF.make_message(error_msg) else: return MF.simple_result_json([error_msg]) return_msg = "OK : schedule del success" if not web: return MF.make_message(return_msg) else: return MF.simple_result_json([return_msg])
return_value.append(line) except Exception, e: return_value.append( "NOK : Exception occured in clear queue [%s]" % str(e)) else: return_value.append("NOK : [%s] task not exists" % task_name) else: for line in main_p.thread_daemon_list['Core'].all_task_object[ task_name].clear_queue(): return_value.append(line) if not web: return MF.make_message(return_value) else: return MF.simple_result_json(return_value) except Exception, e: error_msg = "NOK : Exception occured in del task queue : %s" % str(e) if not web: return MF.make_message(error_msg) else: return MF.simple_result_json([error_msg]) def sav_task_queue(main_p, command_data, web=False): tasks = main_p.thread_daemon_list['Core'].all_task_object command_string = ' '.join(command_data[1:]) result_message = [] try: if command_string.strip() == '': command_string = 'all' task_list = map(lambda x: x.strip(), command_string.split(',')) if 'all' in task_list: for task_name in tasks.keys():
def _call_error(message): error_msg = "NOK : %s" % message return MF.simple_result_json([error_msg])
options, _ = parser.parse_args(command_data) except OptionParsingError, e: error_msg = 'NOK : shw task option error [%s]' % str(e) if not web: return MF.make_message(error_msg) else: return MF.simple_result_json([error_msg]) try: if options.task: options.task = map(lambda x:x.strip(), options.task.split(',')) if options.task_type: options.task_type = map(lambda x:x.strip(), options.task_type.split(',')) if options.status: options.status = map(lambda x:x.strip(), options.status.split(',')) if options.act_status: options.act_status = map(lambda x:x.strip(), options.act_status.split(',')) if options.pid: options.pid = map(lambda x:x.strip(), options.pid.split(',')) except Exception, e: error_msg = 'NOK : shw task option split error [%s]' % str(e) if not web: return MF.make_message(error_msg) else: return MF.simple_result_json([error_msg]) def view_filter(options, data, message): if options.task != None and data[1] not in options.task: return message if options.task_type != None and data[0] not in options.task_type: return message if options.status != None and data[2] not in options.status: return message if options.act_status != None and data[3] not in options.act_status: return message if options.pid != None and data[6] not in options.pid: return message message.append(data) return message try: task_name_list = main_p.thread_daemon_list['Core'].all_task_object.keys() result_list = [] for task_name in task_name_list: pso = main_p.thread_daemon_list['Core'].all_task_object[task_name].status
def shw_recovery(main_p, command_data, web=False): result_list = [] for item in main_p.thread_daemon_list['Core'].recovery_result: result_list.append( (item, main_p.thread_daemon_list['Core'].recovery_result[item][0], main_p.thread_daemon_list['Core'].recovery_result[item][1] ) ) if not web: return MF.shw_recovery_list(result_list) else: return MF.simple_result_json(result_list, header='RECOVERY', column=['NAME', 'START_TIME', 'END_TIME'])