Exemplo n.º 1
0
    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))
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
            time.sleep(.2)
            self.updateOperationProgress(30, ret_message='step2 processed!')
            time.sleep(.3)
            self.updateOperationProgress(80, ret_message='step3 processed!')

            ret = parameters['test1']
            time.sleep(.1)
            self.updateOperationProgress(100, ret_message='all steps are processed!')
        except Exception, err:
            self.updateOperationProgress(88, ret_message='Error: %s'%err, ret_code=324)

        print 'PROCESSED'

from blik.nodeAgent import plugins
plugins.OPERATIONS_PLUGINS['TEST_OPERATION'] = TestPlugin
PluginManager.init()

from blik.utils import friBase
from blik.nodeAgent.nodeAgent import NodeAgent

class FarnsworthSimulator(friBase.FriServer):
    def __init__(self):
        friBase.FriServer.__init__(self, workers_count=1)

    def onDataReceive( self, json_object ):
        print 'FARNSWOTH RECEIVED: ', json_object
        def check_key(key):
            if not json_object.has_key(key):
                print 'ERROR: element <%s> is not found!'%key

        check_key('id')