Beispiel #1
0
 def put(self, id):
     '''
     PUT(create/update) operation
     '''
     data = tornado.escape.json_decode(self.request.body)
     version = self.get_argument('version', None)
     txid = self.get_argument('txid', None)
     tega_id = self.get_argument('tega_id')
     ephemeral = self.get_argument('ephemeral', False)
     if version:
         version = int(version)
     if ephemeral == 'True':
         ephemeral = True
     else:
         ephemeral = False
     path = url2path(id)
     cont = subtree(path, data)
     if txid:
         with tx_lock:
             if txid in transactions:
                 t = transactions[txid]['tx']
                 t.put(cont, version=version, deepcopy=False,
                         ephemeral=ephemeral)
             else:
                 raise tornado.web.HTTPError(404)  # Not Found(404)
     else:
         with tx(subscriber=_tega_id2subscriber(tega_id)) as t:
             try:
                 t.put(cont, version=version, deepcopy=False,
                         ephemeral=ephemeral)
             except ValueError as e:
                 raise tornado.web.HTTPError(409)  # Not Acceptible(409)
Beispiel #2
0
 def delete(self, id):
     '''
     DELETE operation
     '''
     version = self.get_argument('version', None)
     txid = self.get_argument('txid', None)
     tega_id = self.get_argument('tega_id')
     if version:
         version = int(version)
     path = url2path(id)
     if txid:
         with tx_lock:
             if txid in transactions:
                 t = transactions[txid]['tx']
                 t.delete(path, version=version)
             else:
                 raise tornado.web.HTTPError(404)  # Not Found(404)
     else:
         tega_id = self.get_argument('tega_id')
         with tx(subscriber=_tega_id2subscriber(tega_id)) as t:
             try:
                 t.delete(path, version=version)
             except ValueError as e:
                 raise tornado.web.HTTPError(409)  # Not Acceptible(409)
Beispiel #3
0
    def post(self, cmd):
        if cmd == 'clear':
            result = globals()[cmd]()  # commands in tega.idb
            if result:
                self.write(json.dumps(result))
                self.set_header('Content-Type', 'application/json')
        elif cmd == 'rollback':
            tega_id = self.get_argument('tega_id')
            root_oid = self.get_argument('root_oid', None)
            backto = self.get_argument('backto', None)
            subscriber = _tega_id2subscriber(tega_id)
            tega.idb.rollback(tega_id, root_oid, int(backto),
                    subscriber=subscriber)
        elif cmd == 'begin':
            tega_id = self.get_argument('tega_id')
            t = tx(subscriber=_tega_id2subscriber(tega_id))
            txid = t.txid
            with tx_lock:
                transactions[txid] = {'tx': t, 'expire': 2}
            data = {'txid': txid}
            self.write(json.dumps(data))
            self.set_header('Content-Type', 'application/json')
        elif cmd == 'cand':
            txid = self.get_argument('txid', None)
            internal = self.get_argument('internal', False)
            if txid:
                with tx_lock:
                    if txid in transactions:
                        t = transactions[txid]['tx']
                        data = t.get_candidate()
                        self.write(json.dumps(data))
                        self.set_header('Content-Type', 'application/json')
                    else:
                        raise tornado.web.HTTPError(404)  # Not Found(404)
            else:
                raise tornado.web.HTTPError(404)  # Not Found(404)

        elif cmd == 'cancel':
            txid = self.get_argument('txid', None)
            with tx_lock:
                if txid in transactions:
                    del transactions[txid]
                else:
                    raise tornado.web.HTTPError(404)  # Not Found(404)
        elif cmd == 'commit':
            txid = self.get_argument('txid', None)
            with tx_lock:
                if txid in transactions:
                    t = transactions[txid]['tx']
                    del transactions[txid]
                    try:
                        t.commit()
                    except ValueError:
                        raise tornado.web.HTTPError(406)  # Not Acceptable(406)
                else:
                    raise tornado.web.HTTPError(404)  # Not Found(404)
        elif cmd == 'sync':
            if server_as_subscriber:
                sync_check(server_as_subscriber.config,
                           server_as_subscriber.subscriber)
            else:
                raise tornado.web.HTTPError(404)
        elif cmd == 'ss':
            tega_id = self.get_argument('tega_id', None)
            tega.idb.save_snapshot(tega_id)