1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
"""
Rhizi kernel, home to core operation login
"""
import json
import logging
import traceback
import db_controller
from db_op import DBO_diff_commit__attr, DBO_block_chain__commit
from db_op import DBO_diff_commit__topo
from model.graph import Topo_Diff
from neo4j_cypher import QT_Node_Filter__Doc_ID_Label
log = logging.getLogger('rhizi')
class RZDoc_Exception__not_found(Exception):
def __init__(self, rzdoc_name):
super(RZDoc_Exception__not_found, self).__init__('rzdoc not found: \'%s\'' % (rzdoc_name))
class RZ_Kernel(object):
def __init__(self):
self.db_ctl = None
def exec_chain_commit_op(self, diff_obj, ctx):
# FIXME: clean
if isinstance(diff_obj, Topo_Diff):
commit_obj = diff_obj.to_json_dict()
else:
commit_obj = diff_obj
rzdoc = ctx.rzdoc
chain_commit_op = DBO_block_chain__commit(commit_obj, ctx)
chain_commit_op = QT_RZDOC_Meta_NS_Filter(rzdoc)(chain_commit_op)
self.db_ctl.exec_op(chain_commit_op)
def diff_commit__topo(self, topo_diff, ctx=None):
"""
commit a graph topology diff - this is a common pathway for:
- RESP API calls
- socket.io calls
- future interfaces
@return: a tuple containing the input diff and the result of it's commit
"""
rzdoc = ctx.rzdoc
op = DBO_diff_commit__topo(topo_diff)
op = QT_RZDOC_NS_Filter(rzdoc)(op)
try:
op_ret = self.db_ctl.exec_op(op)
self.exec_chain_commit_op(topo_diff, ctx)
return topo_diff, op_ret
except Exception as e:
log.error(e.message)
log.error(traceback.print_exc())
raise e
def diff_commit__attr(self, attr_diff, ctx=None):
"""
commit a graph attribute diff - this is a common pathway for:
- RESP API calls
- socket.io calls
- future interfaces
@return: a tuple containing the input diff and the result of it's commit
"""
rzdoc = ctx.rzdoc
op = DBO_diff_commit__attr(attr_diff)
op = QT_RZDOC_NS_Filter(rzdoc)(op)
try:
op_ret = self.db_ctl.exec_op(op)
self.exec_chain_commit_op(attr_diff, ctx)
return attr_diff, op_ret
except Exception as e:
log.error(e.message)
log.error(traceback.print_exc())
raise e
def rzdoc__clone(self, rzdoc, ctx=None):
"""
Clone entire rzdoc
@return Topo_Diff with node/link attributes
"""
op = DBO_rz_clone()
op = QT_RZDOC_NS_Filter(rzdoc)(op)
try:
topo_diff = self.db_ctl.exec_op(op)
return topo_diff
except Exception as e:
log.exception(e)
log.error(traceback.print_exc())
raise e
|