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.

Files changed (186) hide show
  1. jaseci/__init__.py +3 -37
  2. jaseci-2.0.0.dist-info/METADATA +65 -0
  3. jaseci-2.0.0.dist-info/RECORD +4 -0
  4. {jaseci-1.4.2.5.dist-info → jaseci-2.0.0.dist-info}/WHEEL +1 -2
  5. jaseci/VERSION +0 -1
  6. jaseci/cli_tools/__init__.py +0 -0
  7. jaseci/cli_tools/book_tools.py +0 -457
  8. jaseci/cli_tools/jsctl.py +0 -500
  9. jaseci/cli_tools/tests/__init__.py +0 -0
  10. jaseci/cli_tools/tests/test_jsctl.py +0 -556
  11. jaseci/extens/__init__.py +0 -0
  12. jaseci/extens/act_lib/__init__.py +0 -0
  13. jaseci/extens/act_lib/date.py +0 -117
  14. jaseci/extens/act_lib/elastic.py +0 -87
  15. jaseci/extens/act_lib/file.py +0 -76
  16. jaseci/extens/act_lib/file_handler.py +0 -189
  17. jaseci/extens/act_lib/internal.py +0 -18
  18. jaseci/extens/act_lib/jaseci.py +0 -61
  19. jaseci/extens/act_lib/mail.py +0 -10
  20. jaseci/extens/act_lib/maths.py +0 -168
  21. jaseci/extens/act_lib/net.py +0 -191
  22. jaseci/extens/act_lib/rand.py +0 -82
  23. jaseci/extens/act_lib/regex.py +0 -85
  24. jaseci/extens/act_lib/request.py +0 -169
  25. jaseci/extens/act_lib/std.py +0 -235
  26. jaseci/extens/act_lib/storage.py +0 -53
  27. jaseci/extens/act_lib/stripe.py +0 -337
  28. jaseci/extens/act_lib/task.py +0 -13
  29. jaseci/extens/act_lib/tests/__init__.py +0 -0
  30. jaseci/extens/act_lib/tests/std_test_code.py +0 -37
  31. jaseci/extens/act_lib/tests/test_date.py +0 -26
  32. jaseci/extens/act_lib/tests/test_elastic.py +0 -159
  33. jaseci/extens/act_lib/tests/test_file.py +0 -116
  34. jaseci/extens/act_lib/tests/test_file_lib.py +0 -40
  35. jaseci/extens/act_lib/tests/test_mail_lib.py +0 -33
  36. jaseci/extens/act_lib/tests/test_maths.py +0 -147
  37. jaseci/extens/act_lib/tests/test_net_lib.py +0 -62
  38. jaseci/extens/act_lib/tests/test_regex.py +0 -61
  39. jaseci/extens/act_lib/tests/test_std.py +0 -51
  40. jaseci/extens/act_lib/tests/test_std_lib.py +0 -36
  41. jaseci/extens/act_lib/tests/test_url.py +0 -32
  42. jaseci/extens/act_lib/tests/test_vector.py +0 -36
  43. jaseci/extens/act_lib/tests/test_webtool.py +0 -44
  44. jaseci/extens/act_lib/tests/test_zlib.py +0 -24
  45. jaseci/extens/act_lib/url.py +0 -79
  46. jaseci/extens/act_lib/vector.py +0 -157
  47. jaseci/extens/act_lib/webtool.py +0 -28
  48. jaseci/extens/act_lib/zip.py +0 -33
  49. jaseci/extens/api/__init__.py +0 -0
  50. jaseci/extens/api/actions_api.py +0 -170
  51. jaseci/extens/api/alias_api.py +0 -139
  52. jaseci/extens/api/architype_api.py +0 -196
  53. jaseci/extens/api/config_api.py +0 -129
  54. jaseci/extens/api/global_api.py +0 -84
  55. jaseci/extens/api/graph_api.py +0 -167
  56. jaseci/extens/api/health_api.py +0 -20
  57. jaseci/extens/api/interface.py +0 -268
  58. jaseci/extens/api/jac_api.py +0 -171
  59. jaseci/extens/api/jsorc_api.py +0 -316
  60. jaseci/extens/api/logger_api.py +0 -89
  61. jaseci/extens/api/master_api.py +0 -133
  62. jaseci/extens/api/object_api.py +0 -101
  63. jaseci/extens/api/prometheus_api.py +0 -74
  64. jaseci/extens/api/queue_api.py +0 -140
  65. jaseci/extens/api/sentinel_api.py +0 -270
  66. jaseci/extens/api/super_api.py +0 -64
  67. jaseci/extens/api/tests/__init__.py +0 -0
  68. jaseci/extens/api/tests/test_architype_api.py +0 -66
  69. jaseci/extens/api/tests/test_global_api.py +0 -179
  70. jaseci/extens/api/tests/test_graph_api.py +0 -64
  71. jaseci/extens/api/tests/test_logger_api.py +0 -43
  72. jaseci/extens/api/tests/test_object_api.py +0 -20
  73. jaseci/extens/api/tests/test_sentinel_api.py +0 -66
  74. jaseci/extens/api/tests/test_uncommon.py +0 -107
  75. jaseci/extens/api/tests/test_user_api.py +0 -32
  76. jaseci/extens/api/tests/test_walker_api.py +0 -316
  77. jaseci/extens/api/user_api.py +0 -144
  78. jaseci/extens/api/walker_api.py +0 -298
  79. jaseci/extens/api/webhook_api.py +0 -74
  80. jaseci/extens/svc/__init__.py +0 -0
  81. jaseci/extens/svc/elastic_svc.py +0 -366
  82. jaseci/extens/svc/kube_svc.py +0 -432
  83. jaseci/extens/svc/mail_svc.py +0 -156
  84. jaseci/extens/svc/prome_svc.py +0 -378
  85. jaseci/extens/svc/redis_svc.py +0 -63
  86. jaseci/extens/svc/storage_svc.py +0 -193
  87. jaseci/extens/svc/stripe_svc.py +0 -51
  88. jaseci/extens/svc/task_svc.py +0 -155
  89. jaseci/extens/svc/tasks.py +0 -302
  90. jaseci/jac/__init__.py +0 -0
  91. jaseci/jac/interpreter/__init__.py +0 -0
  92. jaseci/jac/interpreter/architype_interp.py +0 -214
  93. jaseci/jac/interpreter/interp.py +0 -1783
  94. jaseci/jac/interpreter/sentinel_interp.py +0 -257
  95. jaseci/jac/interpreter/tests/__init__.py +0 -0
  96. jaseci/jac/interpreter/tests/test_interp.py +0 -42
  97. jaseci/jac/interpreter/walker_interp.py +0 -248
  98. jaseci/jac/ir/__init__.py +0 -0
  99. jaseci/jac/ir/ast.py +0 -73
  100. jaseci/jac/ir/ast_builder.py +0 -249
  101. jaseci/jac/ir/jac_code.py +0 -152
  102. jaseci/jac/ir/passes/__init__.py +0 -6
  103. jaseci/jac/ir/passes/ast_prune_pass.py +0 -9
  104. jaseci/jac/ir/passes/codegen_pass.py +0 -244
  105. jaseci/jac/ir/passes/ir_pass.py +0 -29
  106. jaseci/jac/ir/passes/printer_pass.py +0 -23
  107. jaseci/jac/ir/passes/pt_prune_pass.py +0 -29
  108. jaseci/jac/ir/passes/schedule.py +0 -23
  109. jaseci/jac/ir/passes/stats_pass.py +0 -16
  110. jaseci/jac/jac.g4 +0 -450
  111. jaseci/jac/jac_parse/__init__.py +0 -0
  112. jaseci/jac/jac_parse/jacLexer.py +0 -809
  113. jaseci/jac/jac_parse/jacListener.py +0 -853
  114. jaseci/jac/jac_parse/jacParser.py +0 -9192
  115. jaseci/jac/jac_set.py +0 -119
  116. jaseci/jac/jsci_vm/__init__.py +0 -0
  117. jaseci/jac/jsci_vm/disasm.py +0 -94
  118. jaseci/jac/jsci_vm/inst_ptr.py +0 -31
  119. jaseci/jac/jsci_vm/machine.py +0 -188
  120. jaseci/jac/jsci_vm/op_codes.py +0 -82
  121. jaseci/jac/jsci_vm/tests/__init__.py +0 -0
  122. jaseci/jac/jsci_vm/tests/test_codegen.py +0 -31
  123. jaseci/jac/machine/__init__.py +0 -0
  124. jaseci/jac/machine/jac_scope.py +0 -85
  125. jaseci/jac/machine/jac_value.py +0 -226
  126. jaseci/jac/machine/machine_state.py +0 -383
  127. jaseci/jac/tests/__init__.py +0 -0
  128. jaseci/jac/tests/book_code.py +0 -624
  129. jaseci/jac/tests/test_book.py +0 -380
  130. jaseci/jac/tests/test_lang_14.py +0 -49
  131. jaseci/jsorc/__init__.py +0 -7
  132. jaseci/jsorc/jsorc.py +0 -642
  133. jaseci/jsorc/jsorc_settings.py +0 -211
  134. jaseci/jsorc/jsorc_utils.py +0 -298
  135. jaseci/jsorc/live_actions.py +0 -364
  136. jaseci/jsorc/manifests/__init__.py +0 -0
  137. jaseci/jsorc/manifests/database.yaml +0 -109
  138. jaseci/jsorc/manifests/elastic.yaml +0 -6024
  139. jaseci/jsorc/manifests/prometheus.yaml +0 -1383
  140. jaseci/jsorc/manifests/redis.yaml +0 -64
  141. jaseci/jsorc/memory.py +0 -258
  142. jaseci/jsorc/redis.py +0 -139
  143. jaseci/jsorc/remote_actions.py +0 -157
  144. jaseci/jsorc/tests/__init__.py +0 -0
  145. jaseci/jsorc/tests/test_actions.py +0 -542
  146. jaseci/jsorc/tests/test_jsorc.py +0 -112
  147. jaseci/prim/__init__.py +0 -0
  148. jaseci/prim/ability.py +0 -93
  149. jaseci/prim/architype.py +0 -89
  150. jaseci/prim/edge.py +0 -172
  151. jaseci/prim/element.py +0 -233
  152. jaseci/prim/graph.py +0 -26
  153. jaseci/prim/master.py +0 -64
  154. jaseci/prim/node.py +0 -532
  155. jaseci/prim/obj_mixins.py +0 -235
  156. jaseci/prim/sentinel.py +0 -281
  157. jaseci/prim/super_master.py +0 -31
  158. jaseci/prim/walker.py +0 -261
  159. jaseci/svc/__init__.py +0 -0
  160. jaseci/tests/__init__.py +0 -0
  161. jaseci/tests/infer.py +0 -39
  162. jaseci/tests/jac_test_code.py +0 -1293
  163. jaseci/tests/jac_test_progs.py +0 -774
  164. jaseci/tests/test_core.py +0 -153
  165. jaseci/tests/test_jac.py +0 -824
  166. jaseci/tests/test_node.py +0 -89
  167. jaseci/tests/test_progs.py +0 -702
  168. jaseci/tests/test_stack.py +0 -220
  169. jaseci/tests/test_stripe.py +0 -225
  170. jaseci/utils/__init__.py +0 -0
  171. jaseci/utils/actions/__init__.py +0 -0
  172. jaseci/utils/actions/actions_manager.py +0 -254
  173. jaseci/utils/actions/actions_optimizer.py +0 -516
  174. jaseci/utils/actions/actions_state.py +0 -95
  175. jaseci/utils/file_handler.py +0 -171
  176. jaseci/utils/gprof2dot.py +0 -3786
  177. jaseci/utils/id_list.py +0 -168
  178. jaseci/utils/json_handler.py +0 -70
  179. jaseci/utils/log_utils.py +0 -57
  180. jaseci/utils/test_core.py +0 -62
  181. jaseci/utils/utils.py +0 -387
  182. jaseci-1.4.2.5.dist-info/LICENSE +0 -21
  183. jaseci-1.4.2.5.dist-info/METADATA +0 -39
  184. jaseci-1.4.2.5.dist-info/RECORD +0 -184
  185. jaseci-1.4.2.5.dist-info/entry_points.txt +0 -3
  186. 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
- )
@@ -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()
@@ -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
- )