Beispiel #1
0
 def post(self):
     tega_id = self.get_argument('tega_id')
     path = self.get_argument('path')
     args = kwargs = None
     if self.request.body:
         body = tornado.escape.json_decode(self.request.body)
         args, kwargs = parse_rpc_body(body)
     result = yield tega.idb.rpc2(path, args, kwargs, tega_id)
     if result:
         self.write(json.dumps({'result': result}))
         self.set_header('Content-Type', 'application/json')
Beispiel #2
0
 def _sync_request(self, param, body):
     seq_no = int(param[0])
     path = param[3]
     args, kwargs = parse_rpc_body(body)
     for root_oid, version in kwargs.items():
         notifications = tega.idb.sync(root_oid, version, self.subscriber)
     self.write_message('RESPONSE {} {} {}\n{}'.
             format(seq_no,
                    REQUEST_TYPE.SYNC.name,
                    None,
                    json.dumps(None)))
Beispiel #3
0
 def _refer_request(self, param, body):
     seq_no = int(param[0])
     path = param[3]
     args, kwargs = parse_rpc_body(body)
     for root_oids in args:
         self.subscriber.on_subscribe(root_oids, SCOPE.GLOBAL)
     self.write_message('RESPONSE {} {} {}\n{}'.
             format(seq_no,
                    REQUEST_TYPE.REFER.name,
                    None,
                    json.dumps(None)))
Beispiel #4
0
    def _process_message(self, msg):
        '''
        Handles a message from global idb.
        '''
        cmd, param, body = self.parser(msg)

        if cmd == 'SESSIONACK':
            remote_tega_id = param
            self.subscriber.tega_id = remote_tega_id
            tega.idb.add_tega_id(remote_tega_id)
        elif cmd == 'NOTIFY':
            tega.idb.crud_batch(body, self.subscriber)
        elif cmd == 'MESSAGE':
            channel = param[0]
            tega_id = param[1]
            tega.idb.publish(channel, tega_id,
                    body['message'], self.subscriber)
        elif cmd == 'SUBSCRIBE':
            channel = param[0]
            scope = SCOPE(param[1])  # Ignored
            tega.idb.subscribe(self.subscriber, channel)
        elif cmd == 'UNSUBSCRIBE':
            if param:
                tega.idb.unsubscribe(self.subscriber, param)
            else:
                tega.idb.unsubscribe_all(self.subscriber)
        elif cmd == 'REQUEST':
            seq_no = param[0]
            type_ = param[1]
            tega_id = param[2]
            path = param[3]
            if REQUEST_TYPE(type_) == REQUEST_TYPE.RPC:
                args, kwargs = parse_rpc_body(body)
                result = tega.idb.rpc(path, args, kwargs)
                self.client.write_message('RESPONSE {} {} {}\n{}'.
                        format(seq_no,
                               REQUEST_TYPE.RPC.name,
                               tega_id,
                               json.dumps(result)))
        elif cmd == 'RESPONSE':
            on_response(param, body)
Beispiel #5
0
 def _route_rpc_request(self, param, body):
     seq_no = int(param[0])
     tega_id = param[2]
     path = param[3]
     args, kwargs = parse_rpc_body(body)
     dst_tega_id = str(tega.idb.get(path)).lstrip('%').split('.')[0]
     if dst_tega_id in plugins.keys():  # to the plugin attached to this db 
         result = tega.idb.rpc(path, args, kwargs)
         if result:   # Returns RESPONSE
             self.write_message('RESPONSE {} {} {}\n{}'.
                     format(seq_no,
                            REQUEST_TYPE.RPC.name,
                            tega_id,
                            json.dumps(result)))
     else:  # Forwards the REQUEST to another local idb
         _subscriber = tega.idb.get_subscriber_instances(dst_tega_id)[0]
         _subscriber.write_message('REQUEST {} {} {} {}\n{}'.
                                   format(seq_no,
                                          REQUEST_TYPE.RPC.name,
                                          tega_id,
                                          path,
                                          json.dumps(body)))