def hanale_worklistserver_response(self, message, conn): """ check worklist server response data and call continue event """ #检查消息的完整性 tmp_msg_is_complete = ResponseClientHandle.check_message_complete( message) if False == tmp_msg_is_complete: log.debug_info(message) err_info = "Recv WorkList server's response incomplete" log.debug_info(err_info) self.handle_request_except(self.msg, self.conn, err_info) return else: response = ResponseClientHandle.switch_msg_stream_type_str2dict( message) msg_group = int(response.get(event.KEY_MESSAGE)) & 0xFF00 if (msg_group == event.EVENT_WORKLIST_GROUP): #检查返回消息与请求消息的匹配关系 if not self.handle_response_message_type_verify( response.get(event.KEY_MESSAGE)): err_info = "WorkList server's response message type error" log.debug_info(err_info) self.handle_request_except(self.msg, self.conn, err_info) return #当请求消息是执行工单时,特殊处理, if (event.EV_WORKLIST_EXECUTE_RQST == self.msg_type): #更新工单等待执行状态,表示发起工单成功 self.set_worklist_execute_request_WLServer_check_response( "request_suc") else: #worklist download #其他消息正常处理 # send worklist down to user or ACS ResponseClientHandle.handle_send_response(response, conn) else: err_info = "Unsupport msg event group:%d" % msg_group log.debug_info(err_info) self.handle_request_except(self.msg, self.conn, err_info) return
def insert_dut_obj(request): """ 解析消息,根据消息类型,分发到DUT_ID对应的DUTQueue对象消息队列中 """ #检查消息的完整性 tmp_msg_is_complete = ResponseClientHandle.check_message_complete( request[0]) if False == tmp_msg_is_complete: err_info = "Recv client request event data incomplete" log.debug_err(err_info) ResponseClientHandle.handle_except(request[0], request[1], err_info) return DUTQueueManagement.delete_expired_dut_obj() message = request[0] message_type = message.get(event.KEY_MESSAGE) #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #add by wangjun 20131024 #拦截守护进程的心跳包数据并发送响应结果 if (message_type == event.EV_QUERY_IS_HANG_RQST): rc_status = DUTQueueManagement.keepalive_request_response( message, request[1]) if True == rc_status: #消息不在往下分发 return #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #add by wangjun 20130716 #获取消息的sequence id message_sequence_id = message.get(event.KEY_SEQUENCE) #将消息加入到MessageSequenceManagement管理队列中,如果该消息已经处理过了, #则直接向client发送处理结果,并返回False标志,否则,返回True,继续消息分发流程 insert_sequence_rc = MessageSequenceManagement.insert_message_sequence_obj( message_sequence_id, request[1]) if False == insert_sequence_rc: return #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ log.app_info( "(Request from client %s)Insert request(message==%s) to DUTQueue" % (ResponseClientHandle.get_client_ipaddress( request[1]), event.get_event_desc(message_type))) dut_id = DUTQueueManagement.get_dut_id(message) if None == dut_id: err_info = "Not found message request sn data" log.debug_err(err_info) if (message_type == event.EV_WORKLIST_EXECUTE_RSP_RQST ): #add by wangjun 20130531 DUTqueue.ResponseWLexecHandle.handle_WLexec_request_except( request[0], err_info) else: ResponseClientHandle.handle_except(request[0], request[1], err_info) return log_dut_id = "insert_dut_obj get_dut_id=" + dut_id log.debug_err(log_dut_id) dut_obj_handle = DUTQueueManagement.get_dut_obj_handle(dut_id) if None == dut_obj_handle: if (message_type == event.EV_WORKLIST_EXECUTE_RSP_RQST ): #add by wangjun 20130531 err_info = "Not found execute worklist DUTQueue running process" log.debug_err(err_info) DUTqueue.ResponseWLexecHandle.handle_WLexec_request_except( request[0], err_info) else: dut_obj_handle = DUTQueueManagement.new_dut_obj(dut_id) if None == dut_obj_handle: return conn = request[1] #add by wangjun 20130523 message_key_sender = message.get(event.KEY_SENDER) if (None == message_key_sender): message_key_sender = event.KEY_SENDER_USER #open QUEUE_INIT key control to GUI #change by wangjun 20130826 if (event.KEY_SENDER_USER == message_key_sender): dut_obj_request_queue_busy = DUTQueueManagement.handle_dutqueue_request_queue_status_check( dut_obj_handle, message, conn) if True == dut_obj_request_queue_busy: log.debug_err("DUTQueue request queue busy") return else: pass #log.debug_err("insert_dut_obj call dispath_event") message_priority_level = message.get(event.KEY_PRIORITY_LEVEL) dut_obj_handle.dispath_event(message_type, message_priority_level, request, message_key_sender)
def run(self): """ override run """ #更新从Agent发送出去消息的KEY_SEQUENCE属性 #add by wangjun 20130722 self.construct_agent_send_message_sequence_property() # send http request and recv response log.app_info( "(Request from client %s)Send request(message=%s) to WorkList server's" % (ResponseClientHandle.get_client_ipaddress( self.conn), event.get_event_desc(self.msg_type))) res, self.response = httpclienthandle.HttClientHandle.send_http_msg( in_message=self.msg, in_timeout=self.timeout, in_try_count=3, in_url=self.url, in_method=self.method) log.app_info( "(Request from client %s)Recv WorkList Server server's response(request message=%s)" % (ResponseClientHandle.get_client_ipaddress( self.conn), event.get_event_desc(self.msg_type))) # parse response data try: if res == "error": err_info = "Agent to WorkList server's http client error:" + self.response log.debug_err(err_info) self.handle_request_except(self.msg, self.conn, err_info) return elif res == "fail": err_info = "Agent to WorkList server's http client fail:" + self.response log.debug_err(err_info) self.handle_request_except(self.msg, self.conn, err_info) return elif res == "response": #检查消息的完整性 check_complete_flag = ResponseClientHandle.check_message_complete( self.response) if False == check_complete_flag: err_info = "Recv HTTP server's response incomplete" log.debug_info(err_info) self.handle_request_except(self.msg, self.conn, err_info) return else: self.hanale_worklistserver_response( self.response, self.conn) return except Exception, e: err_info = "Pickle object occurs exception: %s" % e log.debug_err(err_info) self.handle_request_except(self.msg, self.conn, err_info) return