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