jaseci 1.4.2.5__py3-none-any.whl → 2.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of jaseci might be problematic. Click here for more details.
- jaseci/__init__.py +3 -37
- jaseci-2.0.0.dist-info/METADATA +65 -0
- jaseci-2.0.0.dist-info/RECORD +4 -0
- {jaseci-1.4.2.5.dist-info → jaseci-2.0.0.dist-info}/WHEEL +1 -2
- jaseci/VERSION +0 -1
- jaseci/cli_tools/__init__.py +0 -0
- jaseci/cli_tools/book_tools.py +0 -457
- jaseci/cli_tools/jsctl.py +0 -500
- jaseci/cli_tools/tests/__init__.py +0 -0
- jaseci/cli_tools/tests/test_jsctl.py +0 -556
- jaseci/extens/__init__.py +0 -0
- jaseci/extens/act_lib/__init__.py +0 -0
- jaseci/extens/act_lib/date.py +0 -117
- jaseci/extens/act_lib/elastic.py +0 -87
- jaseci/extens/act_lib/file.py +0 -76
- jaseci/extens/act_lib/file_handler.py +0 -189
- jaseci/extens/act_lib/internal.py +0 -18
- jaseci/extens/act_lib/jaseci.py +0 -61
- jaseci/extens/act_lib/mail.py +0 -10
- jaseci/extens/act_lib/maths.py +0 -168
- jaseci/extens/act_lib/net.py +0 -191
- jaseci/extens/act_lib/rand.py +0 -82
- jaseci/extens/act_lib/regex.py +0 -85
- jaseci/extens/act_lib/request.py +0 -169
- jaseci/extens/act_lib/std.py +0 -235
- jaseci/extens/act_lib/storage.py +0 -53
- jaseci/extens/act_lib/stripe.py +0 -337
- jaseci/extens/act_lib/task.py +0 -13
- jaseci/extens/act_lib/tests/__init__.py +0 -0
- jaseci/extens/act_lib/tests/std_test_code.py +0 -37
- jaseci/extens/act_lib/tests/test_date.py +0 -26
- jaseci/extens/act_lib/tests/test_elastic.py +0 -159
- jaseci/extens/act_lib/tests/test_file.py +0 -116
- jaseci/extens/act_lib/tests/test_file_lib.py +0 -40
- jaseci/extens/act_lib/tests/test_mail_lib.py +0 -33
- jaseci/extens/act_lib/tests/test_maths.py +0 -147
- jaseci/extens/act_lib/tests/test_net_lib.py +0 -62
- jaseci/extens/act_lib/tests/test_regex.py +0 -61
- jaseci/extens/act_lib/tests/test_std.py +0 -51
- jaseci/extens/act_lib/tests/test_std_lib.py +0 -36
- jaseci/extens/act_lib/tests/test_url.py +0 -32
- jaseci/extens/act_lib/tests/test_vector.py +0 -36
- jaseci/extens/act_lib/tests/test_webtool.py +0 -44
- jaseci/extens/act_lib/tests/test_zlib.py +0 -24
- jaseci/extens/act_lib/url.py +0 -79
- jaseci/extens/act_lib/vector.py +0 -157
- jaseci/extens/act_lib/webtool.py +0 -28
- jaseci/extens/act_lib/zip.py +0 -33
- jaseci/extens/api/__init__.py +0 -0
- jaseci/extens/api/actions_api.py +0 -170
- jaseci/extens/api/alias_api.py +0 -139
- jaseci/extens/api/architype_api.py +0 -196
- jaseci/extens/api/config_api.py +0 -129
- jaseci/extens/api/global_api.py +0 -84
- jaseci/extens/api/graph_api.py +0 -167
- jaseci/extens/api/health_api.py +0 -20
- jaseci/extens/api/interface.py +0 -268
- jaseci/extens/api/jac_api.py +0 -171
- jaseci/extens/api/jsorc_api.py +0 -316
- jaseci/extens/api/logger_api.py +0 -89
- jaseci/extens/api/master_api.py +0 -133
- jaseci/extens/api/object_api.py +0 -101
- jaseci/extens/api/prometheus_api.py +0 -74
- jaseci/extens/api/queue_api.py +0 -140
- jaseci/extens/api/sentinel_api.py +0 -270
- jaseci/extens/api/super_api.py +0 -64
- jaseci/extens/api/tests/__init__.py +0 -0
- jaseci/extens/api/tests/test_architype_api.py +0 -66
- jaseci/extens/api/tests/test_global_api.py +0 -179
- jaseci/extens/api/tests/test_graph_api.py +0 -64
- jaseci/extens/api/tests/test_logger_api.py +0 -43
- jaseci/extens/api/tests/test_object_api.py +0 -20
- jaseci/extens/api/tests/test_sentinel_api.py +0 -66
- jaseci/extens/api/tests/test_uncommon.py +0 -107
- jaseci/extens/api/tests/test_user_api.py +0 -32
- jaseci/extens/api/tests/test_walker_api.py +0 -316
- jaseci/extens/api/user_api.py +0 -144
- jaseci/extens/api/walker_api.py +0 -298
- jaseci/extens/api/webhook_api.py +0 -74
- jaseci/extens/svc/__init__.py +0 -0
- jaseci/extens/svc/elastic_svc.py +0 -366
- jaseci/extens/svc/kube_svc.py +0 -432
- jaseci/extens/svc/mail_svc.py +0 -156
- jaseci/extens/svc/prome_svc.py +0 -378
- jaseci/extens/svc/redis_svc.py +0 -63
- jaseci/extens/svc/storage_svc.py +0 -193
- jaseci/extens/svc/stripe_svc.py +0 -51
- jaseci/extens/svc/task_svc.py +0 -155
- jaseci/extens/svc/tasks.py +0 -302
- jaseci/jac/__init__.py +0 -0
- jaseci/jac/interpreter/__init__.py +0 -0
- jaseci/jac/interpreter/architype_interp.py +0 -214
- jaseci/jac/interpreter/interp.py +0 -1783
- jaseci/jac/interpreter/sentinel_interp.py +0 -257
- jaseci/jac/interpreter/tests/__init__.py +0 -0
- jaseci/jac/interpreter/tests/test_interp.py +0 -42
- jaseci/jac/interpreter/walker_interp.py +0 -248
- jaseci/jac/ir/__init__.py +0 -0
- jaseci/jac/ir/ast.py +0 -73
- jaseci/jac/ir/ast_builder.py +0 -249
- jaseci/jac/ir/jac_code.py +0 -152
- jaseci/jac/ir/passes/__init__.py +0 -6
- jaseci/jac/ir/passes/ast_prune_pass.py +0 -9
- jaseci/jac/ir/passes/codegen_pass.py +0 -244
- jaseci/jac/ir/passes/ir_pass.py +0 -29
- jaseci/jac/ir/passes/printer_pass.py +0 -23
- jaseci/jac/ir/passes/pt_prune_pass.py +0 -29
- jaseci/jac/ir/passes/schedule.py +0 -23
- jaseci/jac/ir/passes/stats_pass.py +0 -16
- jaseci/jac/jac.g4 +0 -450
- jaseci/jac/jac_parse/__init__.py +0 -0
- jaseci/jac/jac_parse/jacLexer.py +0 -809
- jaseci/jac/jac_parse/jacListener.py +0 -853
- jaseci/jac/jac_parse/jacParser.py +0 -9192
- jaseci/jac/jac_set.py +0 -119
- jaseci/jac/jsci_vm/__init__.py +0 -0
- jaseci/jac/jsci_vm/disasm.py +0 -94
- jaseci/jac/jsci_vm/inst_ptr.py +0 -31
- jaseci/jac/jsci_vm/machine.py +0 -188
- jaseci/jac/jsci_vm/op_codes.py +0 -82
- jaseci/jac/jsci_vm/tests/__init__.py +0 -0
- jaseci/jac/jsci_vm/tests/test_codegen.py +0 -31
- jaseci/jac/machine/__init__.py +0 -0
- jaseci/jac/machine/jac_scope.py +0 -85
- jaseci/jac/machine/jac_value.py +0 -226
- jaseci/jac/machine/machine_state.py +0 -383
- jaseci/jac/tests/__init__.py +0 -0
- jaseci/jac/tests/book_code.py +0 -624
- jaseci/jac/tests/test_book.py +0 -380
- jaseci/jac/tests/test_lang_14.py +0 -49
- jaseci/jsorc/__init__.py +0 -7
- jaseci/jsorc/jsorc.py +0 -642
- jaseci/jsorc/jsorc_settings.py +0 -211
- jaseci/jsorc/jsorc_utils.py +0 -298
- jaseci/jsorc/live_actions.py +0 -364
- jaseci/jsorc/manifests/__init__.py +0 -0
- jaseci/jsorc/manifests/database.yaml +0 -109
- jaseci/jsorc/manifests/elastic.yaml +0 -6024
- jaseci/jsorc/manifests/prometheus.yaml +0 -1383
- jaseci/jsorc/manifests/redis.yaml +0 -64
- jaseci/jsorc/memory.py +0 -258
- jaseci/jsorc/redis.py +0 -139
- jaseci/jsorc/remote_actions.py +0 -157
- jaseci/jsorc/tests/__init__.py +0 -0
- jaseci/jsorc/tests/test_actions.py +0 -542
- jaseci/jsorc/tests/test_jsorc.py +0 -112
- jaseci/prim/__init__.py +0 -0
- jaseci/prim/ability.py +0 -93
- jaseci/prim/architype.py +0 -89
- jaseci/prim/edge.py +0 -172
- jaseci/prim/element.py +0 -233
- jaseci/prim/graph.py +0 -26
- jaseci/prim/master.py +0 -64
- jaseci/prim/node.py +0 -532
- jaseci/prim/obj_mixins.py +0 -235
- jaseci/prim/sentinel.py +0 -281
- jaseci/prim/super_master.py +0 -31
- jaseci/prim/walker.py +0 -261
- jaseci/svc/__init__.py +0 -0
- jaseci/tests/__init__.py +0 -0
- jaseci/tests/infer.py +0 -39
- jaseci/tests/jac_test_code.py +0 -1293
- jaseci/tests/jac_test_progs.py +0 -774
- jaseci/tests/test_core.py +0 -153
- jaseci/tests/test_jac.py +0 -824
- jaseci/tests/test_node.py +0 -89
- jaseci/tests/test_progs.py +0 -702
- jaseci/tests/test_stack.py +0 -220
- jaseci/tests/test_stripe.py +0 -225
- jaseci/utils/__init__.py +0 -0
- jaseci/utils/actions/__init__.py +0 -0
- jaseci/utils/actions/actions_manager.py +0 -254
- jaseci/utils/actions/actions_optimizer.py +0 -516
- jaseci/utils/actions/actions_state.py +0 -95
- jaseci/utils/file_handler.py +0 -171
- jaseci/utils/gprof2dot.py +0 -3786
- jaseci/utils/id_list.py +0 -168
- jaseci/utils/json_handler.py +0 -70
- jaseci/utils/log_utils.py +0 -57
- jaseci/utils/test_core.py +0 -62
- jaseci/utils/utils.py +0 -387
- jaseci-1.4.2.5.dist-info/LICENSE +0 -21
- jaseci-1.4.2.5.dist-info/METADATA +0 -39
- jaseci-1.4.2.5.dist-info/RECORD +0 -184
- jaseci-1.4.2.5.dist-info/entry_points.txt +0 -3
- jaseci-1.4.2.5.dist-info/top_level.txt +0 -1
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Prometheus APIs
|
|
3
|
-
"""
|
|
4
|
-
from jaseci.extens.api.interface import Interface
|
|
5
|
-
from jaseci.jsorc.jsorc import JsOrc
|
|
6
|
-
from jaseci.extens.svc.prome_svc import PrometheusService
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
def prome():
|
|
10
|
-
return JsOrc.svc("prome").poke(PrometheusService)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class PrometheusApi:
|
|
14
|
-
"""
|
|
15
|
-
Prometheus APIs
|
|
16
|
-
"""
|
|
17
|
-
|
|
18
|
-
@Interface.admin_api()
|
|
19
|
-
def prometheus_metrics_list(self):
|
|
20
|
-
"""
|
|
21
|
-
Return list of availabel metrics
|
|
22
|
-
"""
|
|
23
|
-
return prome().all_metrics()
|
|
24
|
-
|
|
25
|
-
@Interface.admin_api()
|
|
26
|
-
def prometheus_pod_list(self, namespace: str = "", exclude_prom: bool = False):
|
|
27
|
-
"""
|
|
28
|
-
Return list of pods. If exclude_prom,
|
|
29
|
-
"""
|
|
30
|
-
return prome().pods(namespace=namespace, exclude_prom=exclude_prom)
|
|
31
|
-
|
|
32
|
-
@Interface.admin_api()
|
|
33
|
-
def prometheus_pod_info(
|
|
34
|
-
self,
|
|
35
|
-
namespace: str = "",
|
|
36
|
-
exclude_prom: bool = False,
|
|
37
|
-
timestamp: int = 0,
|
|
38
|
-
duration: int = 0,
|
|
39
|
-
):
|
|
40
|
-
"""
|
|
41
|
-
Return pods info and metrics
|
|
42
|
-
"""
|
|
43
|
-
return (
|
|
44
|
-
prome()
|
|
45
|
-
.info(
|
|
46
|
-
namespace=namespace,
|
|
47
|
-
exclude_prom=exclude_prom,
|
|
48
|
-
timestamp=timestamp,
|
|
49
|
-
duration=duration,
|
|
50
|
-
)
|
|
51
|
-
.pod
|
|
52
|
-
)
|
|
53
|
-
|
|
54
|
-
@Interface.admin_api()
|
|
55
|
-
def prometheus_node_info(
|
|
56
|
-
self,
|
|
57
|
-
namespace: str = "",
|
|
58
|
-
exclude_prom: bool = False,
|
|
59
|
-
timestamp: int = 0,
|
|
60
|
-
duration: int = 0,
|
|
61
|
-
):
|
|
62
|
-
"""
|
|
63
|
-
Return pods info and metrics
|
|
64
|
-
"""
|
|
65
|
-
return (
|
|
66
|
-
prome()
|
|
67
|
-
.info(
|
|
68
|
-
namespace=namespace,
|
|
69
|
-
exclude_prom=exclude_prom,
|
|
70
|
-
timestamp=timestamp,
|
|
71
|
-
duration=duration,
|
|
72
|
-
)
|
|
73
|
-
.node
|
|
74
|
-
)
|
jaseci/extens/api/queue_api.py
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Queue api functions as a mixin
|
|
3
|
-
"""
|
|
4
|
-
from jaseci.extens.api.interface import Interface
|
|
5
|
-
from jaseci.jsorc.jsorc import JsOrc
|
|
6
|
-
from jaseci.extens.svc.task_svc import TaskService
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class QueueApi:
|
|
10
|
-
"""
|
|
11
|
-
Queue APIs
|
|
12
|
-
|
|
13
|
-
APIs used for celery configuration and monitoring
|
|
14
|
-
"""
|
|
15
|
-
|
|
16
|
-
@Interface.private_api(allowed_methods=["get"])
|
|
17
|
-
def walker_queue_check(self, task_id: str = ""):
|
|
18
|
-
"""
|
|
19
|
-
Monitor Queues. Check the task if it's still
|
|
20
|
-
pending, running or already have the result
|
|
21
|
-
"""
|
|
22
|
-
task = JsOrc.svc("task", TaskService)
|
|
23
|
-
if not task.is_running():
|
|
24
|
-
return "Task hook is not yet initialized!"
|
|
25
|
-
|
|
26
|
-
if not task_id:
|
|
27
|
-
return task.inspect_tasks()
|
|
28
|
-
else:
|
|
29
|
-
return task.get_by_task_id(task_id)
|
|
30
|
-
|
|
31
|
-
@Interface.private_api(allowed_methods=["get"])
|
|
32
|
-
def walker_queue_wait(self, task_id: str, timeout: int = 30):
|
|
33
|
-
"""
|
|
34
|
-
Forcely wait the queues until executed.
|
|
35
|
-
|
|
36
|
-
:param task_id: the task need to wait for result
|
|
37
|
-
:param timeout: force timeout on your current request
|
|
38
|
-
to avoid hang up if there's too many task running currently
|
|
39
|
-
"""
|
|
40
|
-
task = JsOrc.svc("task", TaskService)
|
|
41
|
-
if not task.is_running():
|
|
42
|
-
return "Task hook is not yet initialized!"
|
|
43
|
-
|
|
44
|
-
if not task_id:
|
|
45
|
-
return "Task id is required!"
|
|
46
|
-
else:
|
|
47
|
-
return task.get_by_task_id(task_id, True, timeout)
|
|
48
|
-
|
|
49
|
-
@Interface.private_api()
|
|
50
|
-
def add_scheduled_walker(self, name: str, schedule: dict, body: dict = {}):
|
|
51
|
-
"""
|
|
52
|
-
Create a scheduled walker
|
|
53
|
-
|
|
54
|
-
:param name: name of the actual queue for reference.
|
|
55
|
-
:param schedule: can be interval or cron.
|
|
56
|
-
Format: {"type": {% interval or cron %}, "conf": {% conf %}, "one_off": {% true if one time only; default false %} }
|
|
57
|
-
Interval conf: {"every": {% integer %}, "period": {% days | hours | minutes | seconds | microseconds %}
|
|
58
|
-
cron conf: {"minute": "*", "hour": "*", "day_of_week": "*", "day_of_month": "*", "month_of_year": "*"}
|
|
59
|
-
:param body: your periodic_task kwargs (dict)
|
|
60
|
-
mst: requestor's master or superadmin requested master - defaults to requestor
|
|
61
|
-
wlk: target walker - defaults to init
|
|
62
|
-
ctx: context to be used upon call - defaults to {}
|
|
63
|
-
nd: target node - defaults to root
|
|
64
|
-
snt: preferred sentinel - defaults to master's active sentinel
|
|
65
|
-
"""
|
|
66
|
-
task = JsOrc.svc("task", TaskService)
|
|
67
|
-
if not task.is_running():
|
|
68
|
-
return "Task hook is not yet initialized!"
|
|
69
|
-
|
|
70
|
-
from jaseci.prim.super_master import SuperMaster
|
|
71
|
-
|
|
72
|
-
if not isinstance(self, SuperMaster) or not body.get("mst"):
|
|
73
|
-
body["mst"] = self.jid
|
|
74
|
-
|
|
75
|
-
return (
|
|
76
|
-
"Scheduled Walker created successfully!"
|
|
77
|
-
if task.add_scheduled_queue(task.scheduled_walker, name, schedule, body)
|
|
78
|
-
else "Django is required to support scheduled walker!"
|
|
79
|
-
)
|
|
80
|
-
|
|
81
|
-
@Interface.admin_api()
|
|
82
|
-
def add_scheduled_sequence(self, name: str, schedule: dict, body: dict):
|
|
83
|
-
"""
|
|
84
|
-
Create a scheduled sequence. More like call multiple api in order.
|
|
85
|
-
|
|
86
|
-
:param name: name of the actual queue for reference.
|
|
87
|
-
:param schedule: can be interval or cron.
|
|
88
|
-
Format: {"type": {% interval or cron %}, "conf": {% conf %}, "one_off": {% true if one time only; default false %} }
|
|
89
|
-
Interval conf: {"every": {% integer %}, "period": {% days | hours | minutes | seconds | microseconds %}
|
|
90
|
-
cron conf: {"minute": "*", "hour": "*", "day_of_week": "*", "day_of_month": "*", "month_of_year": "*"}
|
|
91
|
-
:param body: refer to jaseci/docs/docs/deployment/extension_services/task.md
|
|
92
|
-
under schedule sequence argument structure
|
|
93
|
-
"""
|
|
94
|
-
task = JsOrc.svc("task", TaskService)
|
|
95
|
-
if not task.is_running():
|
|
96
|
-
return "Task hook is not yet initialized!"
|
|
97
|
-
|
|
98
|
-
return (
|
|
99
|
-
"Scheduled Sequence created successfully!"
|
|
100
|
-
if task.add_scheduled_queue(task.scheduled_sequence, name, schedule, body)
|
|
101
|
-
else "Django is required to support scheduled walker!"
|
|
102
|
-
)
|
|
103
|
-
|
|
104
|
-
@Interface.private_api()
|
|
105
|
-
def get_scheduled_queues(
|
|
106
|
-
self, limit: int = 10, offset: int = 0, asc: bool = False, search: str = None
|
|
107
|
-
):
|
|
108
|
-
"""
|
|
109
|
-
Get all periodic_task
|
|
110
|
-
|
|
111
|
-
:param limit: result limit
|
|
112
|
-
:param offset: query offset
|
|
113
|
-
:param asc: sorting
|
|
114
|
-
:param search: search by name
|
|
115
|
-
"""
|
|
116
|
-
task = JsOrc.svc("task", TaskService)
|
|
117
|
-
if not task.is_running():
|
|
118
|
-
return "Task hook is not yet initialized!"
|
|
119
|
-
|
|
120
|
-
return task.get_scheduled_queues(limit, offset, asc, search, self)
|
|
121
|
-
|
|
122
|
-
@Interface.private_api()
|
|
123
|
-
def delete_scheduled_queue(self, scheduled_queue_id: int):
|
|
124
|
-
"""
|
|
125
|
-
Delete specific periodic_task
|
|
126
|
-
|
|
127
|
-
:param scheduled_queue_id: the id of periodic task to delete
|
|
128
|
-
"""
|
|
129
|
-
task = JsOrc.svc("task", TaskService)
|
|
130
|
-
if not task.is_running():
|
|
131
|
-
return "Task hook is not yet initialized!"
|
|
132
|
-
|
|
133
|
-
result = task.delete_scheduled_queue(scheduled_queue_id, self)
|
|
134
|
-
if result == None:
|
|
135
|
-
return "Django is required to support scheduled walker!"
|
|
136
|
-
return (
|
|
137
|
-
"Successfully deleted!"
|
|
138
|
-
if result
|
|
139
|
-
else f"Scheduled Queue with id({scheduled_queue_id}) is not existing!"
|
|
140
|
-
)
|
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Sentinel api functions as a mixin
|
|
3
|
-
"""
|
|
4
|
-
from jaseci.extens.api.interface import Interface
|
|
5
|
-
from jaseci.utils.id_list import IdList
|
|
6
|
-
from jaseci.prim.sentinel import Sentinel
|
|
7
|
-
from jaseci.utils.utils import b64decode_str
|
|
8
|
-
import uuid
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class SentinelApi:
|
|
12
|
-
"""
|
|
13
|
-
Sentinel APIs
|
|
14
|
-
|
|
15
|
-
A sentinel is a unit in Jaseci that represents the organization and management of
|
|
16
|
-
a collection of architypes and walkers. In a sense, you can think of a sentinel
|
|
17
|
-
as a complete Jac implementation of a program or API application. Though its the
|
|
18
|
-
case that many sentinels can be interchangeably across any set of graphs, most
|
|
19
|
-
use cases will typically be a single sentinel shared by all users and managed by an
|
|
20
|
-
admin(s), or each users maintaining a single sentinel customized for their
|
|
21
|
-
individual needs. Many novel usage models are possible, but I'd point the beginner
|
|
22
|
-
to the model most analogous to typical server side software development to start
|
|
23
|
-
with. This model would be to have a single admin account responsible for updating
|
|
24
|
-
a single sentinel that all users would share for their individual graphs. This
|
|
25
|
-
model is achieved through using \\texttt{sentinel_register},
|
|
26
|
-
\\texttt{sentinel_active_global}, and \\texttt{global_sentinel_set}.
|
|
27
|
-
"""
|
|
28
|
-
|
|
29
|
-
def __init__(self):
|
|
30
|
-
self.active_snt_id = None
|
|
31
|
-
self.sentinel_ids = IdList(self)
|
|
32
|
-
|
|
33
|
-
@Interface.private_api(cli_args=["code"])
|
|
34
|
-
def sentinel_register(
|
|
35
|
-
self,
|
|
36
|
-
name: str = "default",
|
|
37
|
-
code: str = "",
|
|
38
|
-
code_dir: str = "./",
|
|
39
|
-
opt_level: int = 4,
|
|
40
|
-
mode: str = "default",
|
|
41
|
-
encoded: bool = False,
|
|
42
|
-
auto_run: str = "init",
|
|
43
|
-
auto_run_ctx: dict = {},
|
|
44
|
-
auto_create_graph: bool = True,
|
|
45
|
-
set_active: bool = True,
|
|
46
|
-
):
|
|
47
|
-
"""
|
|
48
|
-
Create blank or code loaded sentinel and return object
|
|
49
|
-
Auto_run is the walker to execute on register (assumes active graph
|
|
50
|
-
is selected)
|
|
51
|
-
"""
|
|
52
|
-
snt = self.sentinel_ids.get_obj_by_name(name, silent=True)
|
|
53
|
-
new_gph = None
|
|
54
|
-
|
|
55
|
-
if not snt:
|
|
56
|
-
snt = Sentinel(m_id=self._m_id, h=self._h, name=name)
|
|
57
|
-
self.sentinel_ids.add_obj(snt)
|
|
58
|
-
if auto_create_graph:
|
|
59
|
-
new_gph = self.graph_create(set_active=set_active)
|
|
60
|
-
if code:
|
|
61
|
-
self.sentinel_set(
|
|
62
|
-
code=code,
|
|
63
|
-
code_dir=code_dir,
|
|
64
|
-
encoded=encoded,
|
|
65
|
-
snt=snt,
|
|
66
|
-
mode=mode,
|
|
67
|
-
opt_level=opt_level,
|
|
68
|
-
)
|
|
69
|
-
if not snt.is_active:
|
|
70
|
-
return {
|
|
71
|
-
"response": "Error in jac code",
|
|
72
|
-
"errors": snt.errors + snt.runtime_errors,
|
|
73
|
-
"success": False,
|
|
74
|
-
}
|
|
75
|
-
self.attempt_auto_run(sent=snt, walk_name=auto_run, ctx=auto_run_ctx)
|
|
76
|
-
if set_active:
|
|
77
|
-
self.sentinel_active_set(snt)
|
|
78
|
-
self.extract_snt_aliases(snt)
|
|
79
|
-
if new_gph:
|
|
80
|
-
return [snt.serialize(), new_gph]
|
|
81
|
-
return [snt.serialize()]
|
|
82
|
-
|
|
83
|
-
@Interface.private_api()
|
|
84
|
-
def sentinel_pull(self, set_active: bool = True, on_demand: bool = True):
|
|
85
|
-
"""
|
|
86
|
-
Copies global sentinel to local master
|
|
87
|
-
"""
|
|
88
|
-
glob_id = self._h.get_glob("GLOB_SENTINEL")
|
|
89
|
-
if not glob_id:
|
|
90
|
-
return {"response": "No global sentinel is available!", "success": False}
|
|
91
|
-
g_snt = self._h.get_obj(self._m_id, glob_id).duplicate()
|
|
92
|
-
|
|
93
|
-
snt = self.sentinel_ids.get_obj_by_name(g_snt.name, silent=True)
|
|
94
|
-
if not snt:
|
|
95
|
-
snt = Sentinel(m_id=self._m_id, h=self._h, name=g_snt.name)
|
|
96
|
-
self.sentinel_ids.add_obj(snt)
|
|
97
|
-
elif on_demand and snt.is_active:
|
|
98
|
-
return {"response": f"{snt} already active!", "success": True}
|
|
99
|
-
if set_active:
|
|
100
|
-
self.sentinel_active_set(snt)
|
|
101
|
-
return self.sentinel_set(code=g_snt.code_ir, snt=snt, mode="ir")
|
|
102
|
-
|
|
103
|
-
@Interface.private_api()
|
|
104
|
-
def sentinel_get(
|
|
105
|
-
self, snt: Sentinel = None, mode: str = "default", detailed: bool = False
|
|
106
|
-
):
|
|
107
|
-
"""
|
|
108
|
-
Get a sentinel rendered with specific mode
|
|
109
|
-
Valid modes: {default, code, ir, }
|
|
110
|
-
"""
|
|
111
|
-
if mode == "code":
|
|
112
|
-
return snt._jac_ast.get_text()
|
|
113
|
-
elif mode == "ir":
|
|
114
|
-
return snt.ir_dict()
|
|
115
|
-
else:
|
|
116
|
-
return snt.serialize(detailed=detailed)
|
|
117
|
-
|
|
118
|
-
@Interface.private_api(cli_args=["code"])
|
|
119
|
-
def sentinel_set(
|
|
120
|
-
self,
|
|
121
|
-
code: str,
|
|
122
|
-
code_dir: str = "./",
|
|
123
|
-
opt_level: int = 4,
|
|
124
|
-
encoded: bool = False,
|
|
125
|
-
snt: Sentinel = None,
|
|
126
|
-
mode: str = "default",
|
|
127
|
-
):
|
|
128
|
-
"""
|
|
129
|
-
Set code/ir for a sentinel, only replaces walkers/archs in sentinel
|
|
130
|
-
Valid modes: {code, ir, }
|
|
131
|
-
"""
|
|
132
|
-
if encoded:
|
|
133
|
-
code = b64decode_str(code)
|
|
134
|
-
if mode not in ["code", "default", "ir"]:
|
|
135
|
-
return {"response": f"Invalid mode to set {snt}", "success": False}
|
|
136
|
-
snt.register_code(code, dir=code_dir, mode=mode, opt_level=opt_level)
|
|
137
|
-
snt.propagate_access()
|
|
138
|
-
|
|
139
|
-
if snt.is_active:
|
|
140
|
-
self.extract_snt_aliases(snt)
|
|
141
|
-
return {"response": f"{snt} registered and active!", "success": True}
|
|
142
|
-
else:
|
|
143
|
-
return {
|
|
144
|
-
"response": f"{snt} code issues encountered!",
|
|
145
|
-
"success": False,
|
|
146
|
-
"errors": snt.errors + snt.runtime_errors,
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
@Interface.private_api()
|
|
150
|
-
def sentinel_list(self, detailed: bool = False):
|
|
151
|
-
"""
|
|
152
|
-
Provide complete list of all sentinel objects
|
|
153
|
-
"""
|
|
154
|
-
snts = []
|
|
155
|
-
for i in self.sentinel_ids.obj_list():
|
|
156
|
-
snts.append(i.serialize(detailed=detailed))
|
|
157
|
-
return snts
|
|
158
|
-
|
|
159
|
-
@Interface.private_api()
|
|
160
|
-
def sentinel_test(
|
|
161
|
-
self,
|
|
162
|
-
snt: Sentinel = None,
|
|
163
|
-
single: str = "",
|
|
164
|
-
detailed: bool = False,
|
|
165
|
-
profiling: bool = False,
|
|
166
|
-
):
|
|
167
|
-
"""
|
|
168
|
-
Run battery of test cases within sentinel and provide result
|
|
169
|
-
"""
|
|
170
|
-
if not len(single):
|
|
171
|
-
single = None
|
|
172
|
-
return snt.run_tests(specific=single, profiling=profiling, detailed=detailed)
|
|
173
|
-
|
|
174
|
-
@Interface.private_api(cli_args=["snt"])
|
|
175
|
-
def sentinel_active_set(self, snt: Sentinel):
|
|
176
|
-
"""
|
|
177
|
-
Sets the default sentinel master should use
|
|
178
|
-
"""
|
|
179
|
-
self.active_snt_id = snt.jid
|
|
180
|
-
self.alias_register("active:sentinel", snt.jid)
|
|
181
|
-
return [f"Sentinel {snt.id} set as default"]
|
|
182
|
-
|
|
183
|
-
@Interface.private_api()
|
|
184
|
-
def sentinel_active_unset(self):
|
|
185
|
-
"""
|
|
186
|
-
Unsets the default sentinel master should use
|
|
187
|
-
"""
|
|
188
|
-
self.active_snt_id = None
|
|
189
|
-
self.alias_delete("active:sentinel")
|
|
190
|
-
return ["Default sentinel unset"]
|
|
191
|
-
|
|
192
|
-
@Interface.private_api()
|
|
193
|
-
def sentinel_active_global(
|
|
194
|
-
self,
|
|
195
|
-
auto_run: str = "",
|
|
196
|
-
auto_run_ctx: dict = {},
|
|
197
|
-
auto_create_graph: bool = False,
|
|
198
|
-
detailed: bool = False,
|
|
199
|
-
):
|
|
200
|
-
"""
|
|
201
|
-
Sets the default master sentinel to the global sentinel
|
|
202
|
-
Exclusive OR with pull strategy
|
|
203
|
-
"""
|
|
204
|
-
ret = {"success": False, "sentinel": None}
|
|
205
|
-
glob_id = self._h.get_glob("GLOB_SENTINEL")
|
|
206
|
-
if not glob_id:
|
|
207
|
-
ret["response"] = "No global sentinel is available!"
|
|
208
|
-
else:
|
|
209
|
-
self.active_snt_id = "global" # Resolved in interface
|
|
210
|
-
self.alias_register("active:sentinel", glob_id)
|
|
211
|
-
sent = self._h.get_obj(self._m_id, glob_id)
|
|
212
|
-
if auto_create_graph:
|
|
213
|
-
ret["graph_created"] = self.graph_create(set_active=True)
|
|
214
|
-
auto_run_ret = self.attempt_auto_run(
|
|
215
|
-
sent=sent, walk_name=auto_run, ctx=auto_run_ctx
|
|
216
|
-
)
|
|
217
|
-
if auto_run_ret:
|
|
218
|
-
ret["auto_run_result"] = auto_run_ret
|
|
219
|
-
ret["sentinel"] = sent.serialize(detailed=detailed)
|
|
220
|
-
ret["success"] = True
|
|
221
|
-
ret["response"] = f"Global sentinel {glob_id} set as default"
|
|
222
|
-
return ret
|
|
223
|
-
|
|
224
|
-
@Interface.private_api()
|
|
225
|
-
def sentinel_active_get(self, detailed: bool = False):
|
|
226
|
-
"""
|
|
227
|
-
Returns the default sentinel master is using
|
|
228
|
-
"""
|
|
229
|
-
id = self.active_snt_id
|
|
230
|
-
if id == "global":
|
|
231
|
-
id = self._h.get_glob("GLOB_SENTINEL")
|
|
232
|
-
if not id:
|
|
233
|
-
return {"response": "No default sentinel is selected!", "success": False}
|
|
234
|
-
else:
|
|
235
|
-
default = self._h.get_obj(self._m_id, id)
|
|
236
|
-
return default.serialize(detailed=detailed)
|
|
237
|
-
|
|
238
|
-
@Interface.private_api(cli_args=["snt"])
|
|
239
|
-
def sentinel_delete(self, snt: Sentinel):
|
|
240
|
-
"""
|
|
241
|
-
Permanently delete sentinel with given id
|
|
242
|
-
"""
|
|
243
|
-
self.remove_snt_aliases(snt)
|
|
244
|
-
if self.active_snt_id == snt.jid:
|
|
245
|
-
self.sentinel_active_unset()
|
|
246
|
-
self.sentinel_ids.destroy_obj(snt)
|
|
247
|
-
return [f"Sentinel {snt.id} successfully deleted"]
|
|
248
|
-
|
|
249
|
-
def active_snt(self):
|
|
250
|
-
sid = (
|
|
251
|
-
self._h.get_glob("GLOB_SENTINEL")
|
|
252
|
-
if self.active_snt_id == "global"
|
|
253
|
-
else self.active_snt_id
|
|
254
|
-
)
|
|
255
|
-
return self._h.get_obj(self._m_id, sid) if sid is not None else None
|
|
256
|
-
|
|
257
|
-
def attempt_auto_run(self, sent: Sentinel, walk_name, ctx):
|
|
258
|
-
if (
|
|
259
|
-
sent.arch_ids.has_obj_by_name(walk_name, kind="walker")
|
|
260
|
-
and self.active_gph_id
|
|
261
|
-
):
|
|
262
|
-
nd = self._h.get_obj(self._m_id, self.active_gph_id)
|
|
263
|
-
return self.walker_run(name=walk_name, nd=nd, ctx=ctx, snt=sent)
|
|
264
|
-
|
|
265
|
-
def destroy(self):
|
|
266
|
-
"""
|
|
267
|
-
Destroys self from memory and persistent storage
|
|
268
|
-
"""
|
|
269
|
-
for i in self.sentinel_ids.obj_list():
|
|
270
|
-
i.destroy()
|
jaseci/extens/api/super_api.py
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Super (master) api as a mixin
|
|
3
|
-
"""
|
|
4
|
-
from jaseci.extens.api.interface import Interface
|
|
5
|
-
from jaseci.prim.master import Master
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class SuperApi:
|
|
9
|
-
"""Super APIs for creating nicknames for UUIDs and other long strings"""
|
|
10
|
-
|
|
11
|
-
@Interface.admin_api(cli_args=["name"])
|
|
12
|
-
def master_createsuper(
|
|
13
|
-
self,
|
|
14
|
-
name: str,
|
|
15
|
-
password: str = "",
|
|
16
|
-
global_init: str = "",
|
|
17
|
-
global_init_ctx: dict = {},
|
|
18
|
-
other_fields: dict = {},
|
|
19
|
-
):
|
|
20
|
-
"""
|
|
21
|
-
Create a super instance and return root node super object
|
|
22
|
-
|
|
23
|
-
other_fields used for additional feilds for overloaded interfaces
|
|
24
|
-
(i.e., Dango interface)
|
|
25
|
-
"""
|
|
26
|
-
if self.sub_master_ids.has_obj_by_name(name):
|
|
27
|
-
return {"response": f"{name} already exists", "success": False}
|
|
28
|
-
ret = {}
|
|
29
|
-
mast = self.superuser_creator(name, password, other_fields)
|
|
30
|
-
ret["user"] = mast.serialize()
|
|
31
|
-
if len(global_init):
|
|
32
|
-
ret["global_init"] = self.user_global_init(
|
|
33
|
-
mast, global_init, global_init_ctx
|
|
34
|
-
)
|
|
35
|
-
self.take_ownership(mast)
|
|
36
|
-
ret["success"] = True
|
|
37
|
-
return ret
|
|
38
|
-
|
|
39
|
-
@Interface.admin_api()
|
|
40
|
-
def master_allusers(
|
|
41
|
-
self, limit: int = 0, offset: int = 0, asc: bool = False, search: str = None
|
|
42
|
-
):
|
|
43
|
-
"""
|
|
44
|
-
Returns info on a set of users, limit specifies the number of users to
|
|
45
|
-
return and offset specfies where to start
|
|
46
|
-
NOTE: Abstract interface to be overridden
|
|
47
|
-
"""
|
|
48
|
-
|
|
49
|
-
@Interface.admin_api(cli_args=["mast"])
|
|
50
|
-
def master_become(self, mast: Master):
|
|
51
|
-
"""
|
|
52
|
-
Sets the default master master should use
|
|
53
|
-
"""
|
|
54
|
-
self.caller = mast.jid
|
|
55
|
-
self.save()
|
|
56
|
-
return {"response": f"You are now {mast.name}"}
|
|
57
|
-
|
|
58
|
-
@Interface.admin_api(cli_args=["mast"])
|
|
59
|
-
def master_unbecome(self):
|
|
60
|
-
"""
|
|
61
|
-
Unsets the default master master should use
|
|
62
|
-
"""
|
|
63
|
-
self.caller = None
|
|
64
|
-
return {"response": f"You are now {self.name}"}
|
|
File without changes
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
from jaseci.utils.test_core import CoreTest
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class ArchitypeApiTest(CoreTest):
|
|
5
|
-
"""Unit tests for Jac Architype APIs"""
|
|
6
|
-
|
|
7
|
-
fixture_src = __file__
|
|
8
|
-
|
|
9
|
-
def test_architype_register(self):
|
|
10
|
-
self.call(
|
|
11
|
-
self.smast,
|
|
12
|
-
["sentinel_register", {"code": self.load_jac("hello_world.jac")}],
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
ret = self.call(
|
|
16
|
-
self.smast,
|
|
17
|
-
[
|
|
18
|
-
"architype_register",
|
|
19
|
-
{
|
|
20
|
-
"code": self.load_jac("test_architype.jac"),
|
|
21
|
-
"encoded": False,
|
|
22
|
-
},
|
|
23
|
-
],
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
self.assertEqual(ret["success"], True)
|
|
27
|
-
self.assertEqual(ret["architype"]["name"], "test_architype")
|
|
28
|
-
|
|
29
|
-
architype_list_ret = self.call(
|
|
30
|
-
self.smast,
|
|
31
|
-
["architype_list", {"detailed": True}],
|
|
32
|
-
)
|
|
33
|
-
|
|
34
|
-
self.assertEqual(len(architype_list_ret), 7)
|
|
35
|
-
|
|
36
|
-
def test_architype_get(self):
|
|
37
|
-
self.call(
|
|
38
|
-
self.smast,
|
|
39
|
-
["sentinel_register", {"code": self.load_jac("hello_world.jac")}],
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
ret = self.call(
|
|
43
|
-
self.smast,
|
|
44
|
-
[
|
|
45
|
-
"architype_register",
|
|
46
|
-
{
|
|
47
|
-
"code": self.load_jac("test_architype.jac"),
|
|
48
|
-
"encoded": False,
|
|
49
|
-
},
|
|
50
|
-
],
|
|
51
|
-
)
|
|
52
|
-
|
|
53
|
-
architype_get_ret = self.call(
|
|
54
|
-
self.smast,
|
|
55
|
-
["architype_get", {"arch": ret["architype"]["jid"]}],
|
|
56
|
-
)
|
|
57
|
-
|
|
58
|
-
architype_get_ret_code = self.call(
|
|
59
|
-
self.smast,
|
|
60
|
-
["architype_get", {"arch": ret["architype"]["jid"], "mode": "code"}],
|
|
61
|
-
)
|
|
62
|
-
|
|
63
|
-
self.assertEqual(architype_get_ret["architype"]["name"], "test_architype")
|
|
64
|
-
self.assertEqual(
|
|
65
|
-
"walker test_architype" in architype_get_ret_code["code"], True
|
|
66
|
-
)
|