def run(self): name = self.getName() logger.info('%s started!'%name) while True: try: operation = self.queue.get() if operation == FINISH_FLAG: logger.info('%s stoped!'%name) break try: PluginManager.process(operation) except Exception, err: logger.error('Processing operation %s failed! Details: %s.\ \nInput parameters: session_id=%s, node=%s, parameters=%s'% (operation.operation_name, err, operation.session_id, operation.node, operation.parameters)) op_args = Dictionary(signature='ss') op_args.update(operation.parameters) self.dbus_client.operationProcessedEvent(str(operation.session_id), str(operation.node), str(operation.operation_name), op_args) except Exception, err: logger.error('%s failed: %s'%(name, err))
def onDataReceive( self, json_object ): #get session_id session_id = json_object.get('id', None) if session_id is None: raise Exception('Element <id> is not found in FRI packet!') try: session_id = int(session_id) except: raise Exception('Session is should be integer! But: %s'%session_id) if session_id == 0: #LIVE packet return #get node node = json_object.get('node', None) if not node: raise Exception('Element <node> is not found in FRI packet!') node = node.strip() #get operation operation = json_object.get('operation', None) if not operation: raise Exception('Element <operation> is not found in FRI packet') operation = operation.strip() #get parameters parameters = json_object.get('parameters', None) #send message to D-BUS op_args = Dictionary(signature='ss') op_args.update(parameters) self.dbus_client.operationReceivedEvent(str(session_id), str(node), str(operation), op_args) #check appropriate plugin can_process = PluginManager.can_process_operation( operation ) if not can_process: raise Exception('NodeAgent can not process operation %s. No appropriate plugin found!'%operation) op = Operation(session_id, node, operation, parameters) self.__operations_queue.put(op)