Пример #1
0
def shw_stdin(main_p, command_data, web=False, recursive=False):
    core_obj = main_p.thread_daemon_list['Core']
    if recursive:
        command_string = command_data
    else:
        command_string = ' '.join(command_data[2:])
    if command_string.strip() == '': command_string = 'all'
    result_hash = {}
    result_hash['QUEUES'] = []
    for task_name in map(lambda x: x.strip(), command_string.split(',')):
        if task_name not in core_obj.all_task_object:
            if task_name == 'all':
                for sub_task_name in core_obj.all_task_object:
                    sub_return_message = shw_stdin(main_p,
                                                   sub_task_name,
                                                   recursive=True)
                    for item in sub_return_message['QUEUES']:
                        result_hash['QUEUES'].append(item)
            else:
                temp_hash = {}
                temp_hash['NAME'] = task_name
                temp_hash['ERROR'] = []
                temp_hash['BROADCASTING STDIN'] = []
                temp_hash['SHARING STDIN'] = []
                temp_hash['ERROR'].append('NOK : task not exists')
                result_hash['QUEUES'].append(temp_hash)
        else:
            temp_hash = {}
            temp_hash['NAME'] = task_name
            temp_hash['ERROR'] = []
            temp_hash['BROADCASTING STDIN'] = []
            for msg in core_obj.all_task_object[
                    task_name].broadcast_deq.__copy__():
                temp_hash['BROADCASTING STDIN'].append(msg)
            temp_hash['SHARING STDIN'] = []
            for dst_task in core_obj.all_task_object[
                    task_name].sharing_task_list:
                for msg in dst_task.sharing_deq.__copy__():
                    temp_hash['SHARING STDIN'].append(msg)
            result_hash['QUEUES'].append(temp_hash)
    if recursive:
        return result_hash
    if not web:
        temp_list = result_hash['QUEUES'][:]
        sorted(temp_list, key=lambda queue_data: queue_data['NAME'])
        result_message = []
        for item in temp_list:
            result_message.append('=' * 100)
            result_message.append(item['NAME'])
            result_message.append('-' * 100)
            for _key in item:
                if _key == 'NAME': continue
                if len(item[_key]) == 0: continue
                result_message.append(_key)
                result_message.append('-' * 100)
                for line in item[_key]:
                    result_message.append('  ' + line)
        return MF.make_message(result_message)
    else:
        return MF.make_json(result_hash)
Пример #2
0
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])
Пример #3
0
def del_task(main_p, command_data, web=False):
    try:
        return_message = []
        command_string = ' '.join(command_data[2:])
        for task_name in map(lambda x:x.strip(), command_string.split(',')):
            ret = main_p.thread_daemon_list['Core'].del_task(task_name)
            for line in ret:
                return_message.append(line)
            try:
                main_p.node_conn.rmv(task_name)
            except Exception, e:
                return_message.append( 'NOK : Exception occured in del task db : %s' % str(e))
        if not web:
            return MF.make_message(return_message)
        else:
            return_data = {}
            return_data['RESULTS'] = []
            for message in return_message:
                result, msg = map(lambda x:x.strip(), message.strip().split(':', 1))
                temp_hash = {}
                temp_hash['RESULT'] = result
                temp_hash['MESSAGE'] = msg
                return_data['RESULTS'].append(temp_hash)
            return MF.make_json(return_data)
Пример #4
0
    def command(self, line):
        command_data = line.strip().split()


        if command_data[-1].lower() == 'hlp':
            try: 
                if not self.web: return MF.make_message(HLPMessage.help_msg(command_data[0].lower(), command_data[1].lower()))
            except:
                try:
                    if not self.web: return MF.make_message(HLPMessage.help_msg(command_data[0].lower(), None))
                except:
                    if not self.web: return MF.make_message(HLPMessage.help_msg('hlp', None))

        if len(command_data) == 1 and command_data[0].lower() in [ 'shw', 'set', 'del' ]:
            if not self.web: return MF.make_message(HLPMessage.help_msg(command_data[0].lower(), None))

        if command_data[0].lower() == 'shw':
            if command_data[1].lower() == 'conf':
                return ConfigInterface.shw_conf(self.main_p, command_data, web=self.web)
            elif command_data[1].lower() == 'task':
                return TaskInterface.shw_task(self.main_p, command_data, web=self.web)
            elif command_data[1].lower() == 'flow':
                return FlowInterface.shw_flow(self.main_p, command_data, web=self.web)
            elif command_data[1].lower() == 'group':
                return GroupInterface.shw_group(self.main_p, command_data, web=self.web)
            elif command_data[1].lower() == 'stdin':
                return StdInInterface.shw_stdin(self.main_p, command_data, web=self.web)
            elif command_data[1].lower() == 'schedule':
                return ScheduleInterface.shw_schedule(self.main_p, command_data, web=self.web)
            elif command_data[1].lower() == 'global_queue':
                return QueueInterface.shw_global_queue(self.main_p, command_data, web=self.web)
            elif command_data[1].lower() == 'status':
                return TaskInterface.shw_status(self.main_p, command_data, web=self.web)
            elif command_data[1].lower() == 'recovery':
                return TaskInterface.shw_recovery(self.main_p, command_data, web=self.web)
            elif command_data[1].lower() == 'ready':
                return TaskInterface.shw_ready(self.main_p, command_data, web=self.web)
            else:
                if not self.web: return MF.make_message(HLPMessage.help_msg(command_data[0].lower(), None))

        elif command_data[0].lower() == 'set':
            if command_data[1].lower() == 'conf':
                return ConfigInterface.set_conf(self.main_p, command_data, web=self.web)
            elif command_data[1].lower() == 'task':
                return TaskInterface.set_task(self.main_p, command_data, web=self.web)
            elif command_data[1].lower() == 'flow':
                return FlowInterface.set_flow(self.main_p, command_data, web=self.web)
            elif command_data[1].lower() == 'group':
                return GroupInterface.set_group(self.main_p, command_data, web=self.web)
            elif command_data[1].lower() == 'stdin':
                return StdInInterface.set_stdin(self.main_p, command_data, web=self.web)
            elif command_data[1].lower() == 'schedule':
                return ScheduleInterface.set_schedule(self.main_p, command_data, web=self.web)
            elif command_data[1].lower() == 'recovery':
                return TaskInterface.set_recovery(self.main_p, command_data, web=self.web)
            else:
                if not self.web: return MF.make_message(HLPMessage.help_msg(command_data[0].lower(), None))

        elif command_data[0].lower() == 'del':
            if command_data[1].lower() == 'task':
                return TaskInterface.del_task(self.main_p, command_data, web=self.web)
            elif command_data[1].lower() == 'flow':
                return FlowInterface.del_flow(self.main_p, command_data, web=self.web)
            elif command_data[1].lower() == 'group':
                return GroupInterface.del_group(self.main_p, command_data, web=self.web)
            elif command_data[1].lower() == 'schedule':
                return ScheduleInterface.del_schedule(self.main_p, command_data, web=self.web)
            elif command_data[1].lower() == 'task_queue':
                return QueueInterface.del_task_queue(self.main_p, command_data, web=self.web)
            else:
                if not self.web: return MF.make_message(HLPMessage.help_msg(command_data[0].lower(), None))

        elif command_data[0].lower() == 'act':
            return TaskInterface.act_task(self.main_p, command_data, web=self.web)
        elif command_data[0].lower() == 'trm':
            return TaskInterface.trm_task(self.main_p, command_data, web=self.web)

        elif command_data[0].lower() == 'lad':
            return QueueInterface.lad_task_queue(self.main_p, command_data, web=self.web)
        elif command_data[0].lower() == 'sav':
            return QueueInterface.sav_task_queue(self.main_p, command_data, web=self.web)

        if not self.web: return MF.make_message(HLPMessage.help_msg('hlp', None))
        else: return MF.make_json( { 'RESULT' : 'NOK', 'MESSAGE' : 'unknown command [%s]' % repr(line) } )
Пример #5
0
def del_task(main_p, command_data, web=False):
    try:
        return_message = []
        command_string = ' '.join(command_data[2:])
        for task_name in map(lambda x:x.strip(), command_string.split(',')):
            ret = main_p.thread_daemon_list['Core'].del_task(task_name)
            for line in ret:
                return_message.append(line)
            try:
                main_p.node_conn.rmv(task_name)
            except Exception, e:
                return_message.append( 'NOK : Exception occured in del task db : %s' % str(e))
        if not web:
            return MF.make_message(return_message)
        else:
            return_data = {}
            return_data['RESULTS'] = []
            for message in return_message:
                result, msg = map(lambda x:x.strip(), message.strip().split(':', 1))
                temp_hash = {}
                temp_hash['RESULT'] = result
                temp_hash['MESSAGE'] = msg
                return_data['RESULTS'].append(temp_hash)
            return MF.make_json(return_data)
    except Exception, e:
        if not web:
            return MF.make_message( "NOK : Exception occured in del task : %s" % str(e) )
        else:
            return MF.make_json( { "RESULT" : "NOK", "MESSAGE" : " Exception occured in del task : %s" % str(e) } )

Пример #6
0
            result_message = view_check(options, ( 'broad', from_task, core_obj.all_broad_flow[from_task] ), result_message)
        for from_task in core_obj.all_share_flow:
            result_message = view_check(options, ( 'share', from_task, core_obj.all_share_flow[from_task] ), result_message)

        if not web:
            return MF.shw_flow_list(result_message) 
        else:
            return_hash = {}
            return_hash['FLOWS'] = {}
            for item in result_message:
                if item[0] not in return_hash['FLOW']: return_hash['FLOW'][item[0]] = []
                temp_hash = {}
                temp_hash['FROM'] = item[1]
                temp_hash['TO'] = item[2]
                return_hash['FLOW'][item[0]].append(temp_hash)
            return MF.make_json( return_hash )

    except Exception, e:
        error_msg = "NOK : Exception occured in shw flow [%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('|')):