def get(self, id): ''' GET(read) operation ''' version = self.get_argument('version', None) internal = self.get_argument('internal', None) txid = self.get_argument('txid', None) tega_id = self.get_argument('tega_id') regex_flag = str2bool(self.get_argument('regex_flag', False)) if version: version = int(version) internal = str2bool(internal) path = url2path(id) value = None try: value = tega.idb.get(url2path(id), version=version, regex_flag=regex_flag) if isinstance(value, Cont) or is_builtin_type(value): self.write(value.dumps_(internal=internal)) elif isinstance(value, list): dict_ = {v[0]: {'groups':v[2], 'instance':v[1].serialize_(internal=internal)} for v in value} self.write(json.dumps(dict_)) else: self.write(json.dumps(value)) self.set_header('Content-Type', 'application/json') except KeyError: logging.info('path "{}" not found in global idb'.format(path)) raise tornado.web.HTTPError(404) # Not Found(404)
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)
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)