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.
- 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.6.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 -118
- jaseci/extens/act_lib/elastic.py +0 -87
- jaseci/extens/act_lib/file.py +0 -77
- jaseci/extens/act_lib/file_handler.py +0 -190
- jaseci/extens/act_lib/internal.py +0 -19
- jaseci/extens/act_lib/jaseci.py +0 -62
- jaseci/extens/act_lib/mail.py +0 -10
- jaseci/extens/act_lib/maths.py +0 -168
- jaseci/extens/act_lib/net.py +0 -192
- jaseci/extens/act_lib/rand.py +0 -83
- jaseci/extens/act_lib/regex.py +0 -85
- jaseci/extens/act_lib/request.py +0 -170
- jaseci/extens/act_lib/std.py +0 -236
- jaseci/extens/act_lib/storage.py +0 -53
- jaseci/extens/act_lib/stripe.py +0 -338
- jaseci/extens/act_lib/task.py +0 -14
- 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 -80
- jaseci/extens/act_lib/vector.py +0 -158
- jaseci/extens/act_lib/webtool.py +0 -29
- jaseci/extens/act_lib/zip.py +0 -34
- jaseci/extens/api/__init__.py +0 -0
- jaseci/extens/api/actions_api.py +0 -171
- jaseci/extens/api/alias_api.py +0 -140
- jaseci/extens/api/architype_api.py +0 -197
- jaseci/extens/api/config_api.py +0 -129
- jaseci/extens/api/global_api.py +0 -85
- jaseci/extens/api/graph_api.py +0 -168
- jaseci/extens/api/health_api.py +0 -21
- jaseci/extens/api/interface.py +0 -269
- jaseci/extens/api/jac_api.py +0 -172
- jaseci/extens/api/jsorc_api.py +0 -317
- jaseci/extens/api/logger_api.py +0 -90
- jaseci/extens/api/master_api.py +0 -134
- jaseci/extens/api/object_api.py +0 -102
- jaseci/extens/api/prometheus_api.py +0 -75
- jaseci/extens/api/queue_api.py +0 -141
- jaseci/extens/api/sentinel_api.py +0 -271
- jaseci/extens/api/share_api.py +0 -64
- jaseci/extens/api/super_api.py +0 -65
- 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 -166
- jaseci/extens/api/walker_api.py +0 -299
- jaseci/extens/api/webhook_api.py +0 -77
- 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 -219
- jaseci/jac/interpreter/interp.py +0 -1784
- jaseci/jac/interpreter/sentinel_interp.py +0 -260
- jaseci/jac/interpreter/tests/__init__.py +0 -0
- jaseci/jac/interpreter/tests/test_interp.py +0 -42
- jaseci/jac/interpreter/walker_interp.py +0 -249
- 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 -151
- 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 -120
- 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 -86
- jaseci/jac/machine/jac_value.py +0 -227
- jaseci/jac/machine/machine_state.py +0 -386
- 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 -365
- jaseci/jsorc/manifests/__init__.py +0 -0
- jaseci/jsorc/manifests/database.yaml +0 -109
- jaseci/jsorc/manifests/elastic.yaml +0 -6029
- 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 -140
- jaseci/jsorc/remote_actions.py +0 -158
- 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 -94
- jaseci/prim/architype.py +0 -90
- jaseci/prim/edge.py +0 -173
- jaseci/prim/element.py +0 -233
- jaseci/prim/graph.py +0 -27
- jaseci/prim/master.py +0 -67
- jaseci/prim/node.py +0 -533
- jaseci/prim/obj_mixins.py +0 -238
- jaseci/prim/sentinel.py +0 -282
- 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 -517
- 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 -169
- 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.6.dist-info/LICENSE +0 -21
- jaseci-1.4.2.6.dist-info/METADATA +0 -39
- jaseci-1.4.2.6.dist-info/RECORD +0 -185
- jaseci-1.4.2.6.dist-info/entry_points.txt +0 -3
- jaseci-1.4.2.6.dist-info/top_level.txt +0 -1
jaseci/extens/api/jsorc_api.py
DELETED
|
@@ -1,317 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
JSORC APIs
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
import json
|
|
6
|
-
from json import dumps
|
|
7
|
-
from time import time
|
|
8
|
-
|
|
9
|
-
from jaseci.jsorc.jsorc import JsOrc
|
|
10
|
-
from jaseci.jsorc.jsorc_utils import convert_yaml_manifest, ManifestType
|
|
11
|
-
from jaseci.utils.utils import logger
|
|
12
|
-
from jaseci.extens.svc.kube_svc import KubeService
|
|
13
|
-
from jaseci.utils.file_handler import FileHandler
|
|
14
|
-
from jaseci.utils.actions.actions_manager import ActionManager
|
|
15
|
-
|
|
16
|
-
from jaseci.extens.api.interface import Interface
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
class JsOrcApi:
|
|
20
|
-
"""
|
|
21
|
-
API for managing JsOrc
|
|
22
|
-
"""
|
|
23
|
-
|
|
24
|
-
@Interface.admin_api()
|
|
25
|
-
def load_yaml(
|
|
26
|
-
self,
|
|
27
|
-
files: list,
|
|
28
|
-
manifest_type: str = "DEDICATED",
|
|
29
|
-
manual_namespace: str = "default",
|
|
30
|
-
):
|
|
31
|
-
"""
|
|
32
|
-
applying list of yaml files without associating to any modules/services
|
|
33
|
-
"""
|
|
34
|
-
|
|
35
|
-
try:
|
|
36
|
-
kube = JsOrc.svc("kube").poke(KubeService)
|
|
37
|
-
|
|
38
|
-
res = {}
|
|
39
|
-
for file in files:
|
|
40
|
-
file: FileHandler = self._h.get_file_handler(file)
|
|
41
|
-
file.open()
|
|
42
|
-
|
|
43
|
-
for kind, confs in kube.resolve_manifest(
|
|
44
|
-
convert_yaml_manifest(file.buffer),
|
|
45
|
-
ManifestType[manifest_type],
|
|
46
|
-
manual_namespace,
|
|
47
|
-
).items():
|
|
48
|
-
for name, conf in confs.items():
|
|
49
|
-
metadata: dict = conf["metadata"]
|
|
50
|
-
kube.create(
|
|
51
|
-
kind,
|
|
52
|
-
metadata["name"],
|
|
53
|
-
conf,
|
|
54
|
-
metadata.get("namespace"),
|
|
55
|
-
)
|
|
56
|
-
if not res.get(kind):
|
|
57
|
-
res[kind] = {}
|
|
58
|
-
res[kind].update({name: conf})
|
|
59
|
-
|
|
60
|
-
file.close()
|
|
61
|
-
return res
|
|
62
|
-
except Exception:
|
|
63
|
-
logger.exception("Error loading yaml!")
|
|
64
|
-
return {"message": "load_yaml is not supported on non automated JsOrc!"}
|
|
65
|
-
|
|
66
|
-
@Interface.admin_api(cli_args=["service"])
|
|
67
|
-
def apply_yaml(self, service: str, file: list, unsafe_paraphrase: str = ""):
|
|
68
|
-
"""
|
|
69
|
-
apply manifest yaml to specific service
|
|
70
|
-
"""
|
|
71
|
-
svc = JsOrc.svc(service)
|
|
72
|
-
|
|
73
|
-
new_config = {}
|
|
74
|
-
|
|
75
|
-
config_version = str(time())
|
|
76
|
-
|
|
77
|
-
file: FileHandler = self._h.get_file_handler(file[0])
|
|
78
|
-
file.open()
|
|
79
|
-
|
|
80
|
-
for kind, confs in convert_yaml_manifest(file.buffer).items():
|
|
81
|
-
for name, conf in confs.items():
|
|
82
|
-
metadata = conf["metadata"]
|
|
83
|
-
labels: dict = metadata.get("labels", {})
|
|
84
|
-
if not labels.get("config_version"):
|
|
85
|
-
labels["config_version"] = config_version
|
|
86
|
-
metadata["labels"] = labels
|
|
87
|
-
|
|
88
|
-
if not new_config.get(kind):
|
|
89
|
-
new_config[kind] = {}
|
|
90
|
-
new_config[kind].update({name: conf})
|
|
91
|
-
|
|
92
|
-
file.close()
|
|
93
|
-
|
|
94
|
-
if unsafe_paraphrase == JsOrc.settings("UNSAFE_PARAPHRASE"):
|
|
95
|
-
new_config["__UNSAFE_PARAPHRASE__"] = unsafe_paraphrase
|
|
96
|
-
|
|
97
|
-
self._h.save_glob(svc.source["manifest"], dumps(new_config))
|
|
98
|
-
JsOrc.add_regeneration_queue(service)
|
|
99
|
-
|
|
100
|
-
return new_config
|
|
101
|
-
|
|
102
|
-
@Interface.admin_api()
|
|
103
|
-
def jsorc_refresh(self):
|
|
104
|
-
"""
|
|
105
|
-
refreshing jsorc's config.
|
|
106
|
-
"""
|
|
107
|
-
|
|
108
|
-
JsOrc.configure()
|
|
109
|
-
|
|
110
|
-
return {
|
|
111
|
-
"running_interval": JsOrc._running_interval,
|
|
112
|
-
"config": JsOrc._config,
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
@Interface.admin_api(cli_args=["name"])
|
|
116
|
-
def service_info(self, name: str):
|
|
117
|
-
"""
|
|
118
|
-
getting service's info.
|
|
119
|
-
"""
|
|
120
|
-
|
|
121
|
-
# will throw exception if not existing
|
|
122
|
-
return JsOrc.svc(name).info()
|
|
123
|
-
|
|
124
|
-
@Interface.admin_api(cli_args=["name"])
|
|
125
|
-
def service_config_set(self, name: str, config: dict):
|
|
126
|
-
"""
|
|
127
|
-
Set a service config
|
|
128
|
-
"""
|
|
129
|
-
return JsOrc.svc_conf_set(name, config, self._h)
|
|
130
|
-
|
|
131
|
-
@Interface.admin_api(cli_args=["name"])
|
|
132
|
-
def service_refresh(self, name: str):
|
|
133
|
-
"""
|
|
134
|
-
refreshing service's config. If JsOrc is not automated, service will restart else JsOrc will handle the rest
|
|
135
|
-
"""
|
|
136
|
-
|
|
137
|
-
# will throw exception if not existing
|
|
138
|
-
JsOrc.svc_reset(name)
|
|
139
|
-
|
|
140
|
-
return {"success": True}
|
|
141
|
-
|
|
142
|
-
@Interface.admin_api(cli_args=["name"])
|
|
143
|
-
def service_call(self, svc: str, attrs: list = []):
|
|
144
|
-
"""
|
|
145
|
-
temporary api for retreiving/calling attributes of specific instance.
|
|
146
|
-
"""
|
|
147
|
-
|
|
148
|
-
svc = JsOrc.svc(svc)
|
|
149
|
-
|
|
150
|
-
if not svc:
|
|
151
|
-
return "Service (svc) field is required!"
|
|
152
|
-
|
|
153
|
-
if not attrs:
|
|
154
|
-
return "Attributes (attrs) field is required!"
|
|
155
|
-
|
|
156
|
-
res = svc
|
|
157
|
-
for at in attrs:
|
|
158
|
-
attr = at.get("attr", False)
|
|
159
|
-
if attr:
|
|
160
|
-
res = getattr(res, attr)
|
|
161
|
-
|
|
162
|
-
if at.get("callable", False):
|
|
163
|
-
args = at.get("args", [])
|
|
164
|
-
kwargs = at.get("kwargs", {})
|
|
165
|
-
res = res(*args, **kwargs)
|
|
166
|
-
|
|
167
|
-
try:
|
|
168
|
-
# test if json serializable
|
|
169
|
-
json.dumps(res)
|
|
170
|
-
return res
|
|
171
|
-
except Exception:
|
|
172
|
-
return {"error": f"Not JSON Serializable! class {res.__class__.__name__}"}
|
|
173
|
-
|
|
174
|
-
@Interface.admin_api(cli_args=["name"])
|
|
175
|
-
def jsorc_actions_load(self, name: str, mode: str):
|
|
176
|
-
"""
|
|
177
|
-
Load an action as remote or local mode through JSORC.
|
|
178
|
-
JSORC will load the corresponding module or start a microservice if needed.
|
|
179
|
-
Return the current status of the action.
|
|
180
|
-
"""
|
|
181
|
-
action_manager = JsOrc.get("action_manager", ActionManager)
|
|
182
|
-
action_manager.load_actions(name, mode)
|
|
183
|
-
status = action_manager.get_actions_status(name)
|
|
184
|
-
|
|
185
|
-
return {"success": True, "action_status": status}
|
|
186
|
-
|
|
187
|
-
@Interface.admin_api(cli_args=["name"])
|
|
188
|
-
def jsorc_actions_status(self, name: str):
|
|
189
|
-
"""
|
|
190
|
-
Get the current status of an action
|
|
191
|
-
"""
|
|
192
|
-
status = JsOrc.get("action_manager", ActionManager).get_actions_status(name)
|
|
193
|
-
return {"success": True, "action_status": status}
|
|
194
|
-
|
|
195
|
-
@Interface.admin_api(cli_args=["name"])
|
|
196
|
-
def jsorc_actions_unload(
|
|
197
|
-
self, name: str, mode: str = "auto", retire_svc: bool = True
|
|
198
|
-
):
|
|
199
|
-
"""
|
|
200
|
-
Unload an action through JSORC.
|
|
201
|
-
If retire_svc is set to True (true by default), it will also retire the corresponding microservice.
|
|
202
|
-
"""
|
|
203
|
-
res = JsOrc.get("action_manager", ActionManager).unload_actions(
|
|
204
|
-
name, mode, retire_svc
|
|
205
|
-
)
|
|
206
|
-
return {"success": res[0], "message": res[1]}
|
|
207
|
-
|
|
208
|
-
@Interface.admin_api(cli_args=["config", "name"])
|
|
209
|
-
def jsorc_actions_config(self, config: str, name: str):
|
|
210
|
-
"""
|
|
211
|
-
Loading the config of an action module
|
|
212
|
-
config: name of the ai kit package (e.g. jac_nlp.config, jac_vision.config)
|
|
213
|
-
name: name of the action module (e.g. use_enc, bi_enc)
|
|
214
|
-
"""
|
|
215
|
-
res = JsOrc.get("action_manager", ActionManager).load_action_config(
|
|
216
|
-
config, name
|
|
217
|
-
)
|
|
218
|
-
return {"success": res}
|
|
219
|
-
|
|
220
|
-
@Interface.admin_api()
|
|
221
|
-
def jsorc_trackact_start(self):
|
|
222
|
-
""" "
|
|
223
|
-
Instruct JSORC to start tracking any changes in actions state
|
|
224
|
-
"""
|
|
225
|
-
JsOrc.get("action_manager", ActionManager).actions_tracking_start()
|
|
226
|
-
return {"success": True}
|
|
227
|
-
|
|
228
|
-
@Interface.admin_api()
|
|
229
|
-
def jsorc_trackact_stop(self):
|
|
230
|
-
""" "
|
|
231
|
-
Instruct JSORC to start tracking any changes in actions state
|
|
232
|
-
"""
|
|
233
|
-
return JsOrc.get("action_manager", ActionManager).actions_tracking_stop()
|
|
234
|
-
|
|
235
|
-
@Interface.admin_api()
|
|
236
|
-
def jsorc_benchmark_start(self):
|
|
237
|
-
"""
|
|
238
|
-
Tell JSORC to start collecting request performance metrics
|
|
239
|
-
"""
|
|
240
|
-
JsOrc.get("action_manager", ActionManager).benchmark_start()
|
|
241
|
-
return {"success": True}
|
|
242
|
-
|
|
243
|
-
@Interface.admin_api()
|
|
244
|
-
def jsorc_benchmark_report(self):
|
|
245
|
-
"""
|
|
246
|
-
Report the collected request performance metrics of the currently ongoing benchmark
|
|
247
|
-
"""
|
|
248
|
-
return JsOrc.get("action_manager", ActionManager).benchmark_report()
|
|
249
|
-
|
|
250
|
-
@Interface.admin_api()
|
|
251
|
-
def jsorc_benchmark_stop(self, report: bool = True):
|
|
252
|
-
"""
|
|
253
|
-
End the benchmark period and report performance metrics
|
|
254
|
-
"""
|
|
255
|
-
return JsOrc.get("action_manager", ActionManager).benchmark_stop(report)
|
|
256
|
-
|
|
257
|
-
@Interface.admin_api()
|
|
258
|
-
def jsorc_tracksys_start(self):
|
|
259
|
-
"""
|
|
260
|
-
Ask JSORC to start tracking the state of the system as observed by JSORC on every interval.
|
|
261
|
-
"""
|
|
262
|
-
JsOrc.get("action_manager", ActionManager).state_tracking_start()
|
|
263
|
-
return {"success": True}
|
|
264
|
-
|
|
265
|
-
@Interface.admin_api()
|
|
266
|
-
def jsorc_tracksys_report(self):
|
|
267
|
-
"""
|
|
268
|
-
Report the tracked system states so far
|
|
269
|
-
"""
|
|
270
|
-
return JsOrc.get("action_manager", ActionManager).state_tracking_report()
|
|
271
|
-
|
|
272
|
-
@Interface.admin_api()
|
|
273
|
-
def jsorc_tracksys_stop(self):
|
|
274
|
-
"""
|
|
275
|
-
Stop state tracking for JSORC
|
|
276
|
-
"""
|
|
277
|
-
return JsOrc.get("action_manager", ActionManager).state_tracking_stop()
|
|
278
|
-
|
|
279
|
-
@Interface.admin_api()
|
|
280
|
-
def jsorc_actionpolicy_set(self, policy_name: str, policy_params: dict = {}):
|
|
281
|
-
"""
|
|
282
|
-
Set an action optimization policy for JSORC
|
|
283
|
-
"""
|
|
284
|
-
res = JsOrc.get("action_manager", ActionManager).set_action_policy(
|
|
285
|
-
policy_name, policy_params
|
|
286
|
-
)
|
|
287
|
-
if res is True:
|
|
288
|
-
return {
|
|
289
|
-
"success": True,
|
|
290
|
-
"message": f"Action optimization policy configured as {policy_name} with params {policy_params}",
|
|
291
|
-
}
|
|
292
|
-
else:
|
|
293
|
-
return {"success": False, "message": res}
|
|
294
|
-
|
|
295
|
-
@Interface.admin_api()
|
|
296
|
-
def jsorc_actionpolicy_get(self):
|
|
297
|
-
"""
|
|
298
|
-
Get the current active action optimization policy
|
|
299
|
-
"""
|
|
300
|
-
policy = JsOrc.get("action_manager", ActionManager).get_action_policy()
|
|
301
|
-
return {"success": True, "policy": policy}
|
|
302
|
-
|
|
303
|
-
@Interface.admin_api()
|
|
304
|
-
def jsorc_loadtest(
|
|
305
|
-
self,
|
|
306
|
-
test: str,
|
|
307
|
-
experiment: str = "",
|
|
308
|
-
mem: int = 0,
|
|
309
|
-
policy: str = "all_local",
|
|
310
|
-
experiment_duration: int = 180,
|
|
311
|
-
eval_phase: int = 10,
|
|
312
|
-
perf_phase: int = 100,
|
|
313
|
-
):
|
|
314
|
-
"""
|
|
315
|
-
load test API. overwritten in jaseci_serv
|
|
316
|
-
"""
|
|
317
|
-
pass
|
jaseci/extens/api/logger_api.py
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Logger api as a mixin
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
import re
|
|
6
|
-
from jaseci.extens.api.interface import Interface
|
|
7
|
-
from jaseci.utils.log_utils import parse_logs
|
|
8
|
-
from jaseci.utils.utils import logger, app_logger, logs
|
|
9
|
-
from jaseci.utils.utils import connect_logger_handler
|
|
10
|
-
from logging.handlers import HTTPHandler
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class LoggerApi:
|
|
14
|
-
"""
|
|
15
|
-
APIs for Jaseci Logging configuration
|
|
16
|
-
"""
|
|
17
|
-
|
|
18
|
-
@Interface.admin_api(cli_args=["host"])
|
|
19
|
-
def logger_http_connect(self, host: str, port: int, url: str, log: str = "all"):
|
|
20
|
-
"""
|
|
21
|
-
Connects internal logging to http(s) (log msgs sent via POSTs)
|
|
22
|
-
Valid log params: {sys, app, all }
|
|
23
|
-
"""
|
|
24
|
-
num = 0
|
|
25
|
-
if log == "sys" or log == "all":
|
|
26
|
-
connect_logger_handler(
|
|
27
|
-
logger, HTTPHandler(host=f"{host}:{port}", url=url, method="POST")
|
|
28
|
-
)
|
|
29
|
-
num += 1
|
|
30
|
-
if log == "app" or log == "all":
|
|
31
|
-
connect_logger_handler(
|
|
32
|
-
app_logger, HTTPHandler(host=f"{host}:{port}", url=url, method="POST")
|
|
33
|
-
)
|
|
34
|
-
num += 1
|
|
35
|
-
return [f"{num} http handlers added!"]
|
|
36
|
-
|
|
37
|
-
@Interface.admin_api()
|
|
38
|
-
def logger_http_clear(self, log: str = "all"):
|
|
39
|
-
"""
|
|
40
|
-
Connects internal logging to http(s) (log msgs sent via POSTs)
|
|
41
|
-
Valid log params: {sys, app, all }
|
|
42
|
-
"""
|
|
43
|
-
num = 0
|
|
44
|
-
if log == "sys" or log == "all":
|
|
45
|
-
for i in logger.handlers:
|
|
46
|
-
if i.__class__.__name__ == "HTTPHandler":
|
|
47
|
-
logger.removeHandler(i)
|
|
48
|
-
num += 1
|
|
49
|
-
if log == "app" or log == "all":
|
|
50
|
-
for i in app_logger.handlers:
|
|
51
|
-
if i.__class__.__name__ == "HTTPHandler":
|
|
52
|
-
app_logger.removeHandler(i)
|
|
53
|
-
num += 1
|
|
54
|
-
return [f"{num} http handlers removed!"]
|
|
55
|
-
|
|
56
|
-
@Interface.admin_api()
|
|
57
|
-
def logger_get(self, search: str = "", level: str = None):
|
|
58
|
-
"""Get logs across loggers"""
|
|
59
|
-
result = []
|
|
60
|
-
for log in logs.getvalue().splitlines():
|
|
61
|
-
# skip logs produced by calling this endpoint
|
|
62
|
-
if re.search("Incoming call to logger_get", log):
|
|
63
|
-
continue
|
|
64
|
-
|
|
65
|
-
if search:
|
|
66
|
-
if re.search(search, log):
|
|
67
|
-
result.append(log)
|
|
68
|
-
continue
|
|
69
|
-
|
|
70
|
-
result.append(log)
|
|
71
|
-
|
|
72
|
-
result = parse_logs(result)
|
|
73
|
-
|
|
74
|
-
if level:
|
|
75
|
-
result = list(filter(lambda item: level and item["level"] == level, result))
|
|
76
|
-
|
|
77
|
-
return result
|
|
78
|
-
|
|
79
|
-
@Interface.admin_api()
|
|
80
|
-
def logger_list(self):
|
|
81
|
-
"""
|
|
82
|
-
Check active loggers
|
|
83
|
-
"""
|
|
84
|
-
core = []
|
|
85
|
-
app = []
|
|
86
|
-
for i in logger.handlers:
|
|
87
|
-
core.append(str(type(i)))
|
|
88
|
-
for i in app_logger.handlers:
|
|
89
|
-
app.append(str(type(i)))
|
|
90
|
-
return {"core": core, "app": app}
|
jaseci/extens/api/master_api.py
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Master api as a mixin
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
from jaseci.extens.api.interface import Interface
|
|
6
|
-
from jaseci.utils.id_list import IdList
|
|
7
|
-
import uuid
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class MasterApi:
|
|
11
|
-
"""
|
|
12
|
-
Master APIs for users creating and managing groups of sub users
|
|
13
|
-
|
|
14
|
-
These APIs
|
|
15
|
-
"""
|
|
16
|
-
|
|
17
|
-
def __init__(self, head_master):
|
|
18
|
-
self.caller = None
|
|
19
|
-
self.head_master_id = head_master
|
|
20
|
-
self.sub_master_ids = IdList(self)
|
|
21
|
-
|
|
22
|
-
@Interface.private_api(cli_args=["name"])
|
|
23
|
-
def master_create(
|
|
24
|
-
self,
|
|
25
|
-
name: str,
|
|
26
|
-
password: str = "",
|
|
27
|
-
global_init: str = "",
|
|
28
|
-
global_init_ctx: dict = {},
|
|
29
|
-
other_fields: dict = {},
|
|
30
|
-
):
|
|
31
|
-
"""
|
|
32
|
-
Create a master instance and return root node master object
|
|
33
|
-
|
|
34
|
-
other_fields used for additional feilds for overloaded interfaces
|
|
35
|
-
(i.e., Dango interface)
|
|
36
|
-
"""
|
|
37
|
-
if self.sub_master_ids.has_obj_by_name(name):
|
|
38
|
-
return {"response": f"{name} already exists", "success": False}
|
|
39
|
-
ret = {}
|
|
40
|
-
mast = self.user_creator(name, password, other_fields)
|
|
41
|
-
ret["user"] = mast.serialize()
|
|
42
|
-
if len(global_init):
|
|
43
|
-
ret["global_init"] = self.user_global_init(
|
|
44
|
-
mast, global_init, global_init_ctx
|
|
45
|
-
)
|
|
46
|
-
self.take_ownership(mast)
|
|
47
|
-
ret["success"] = True
|
|
48
|
-
return ret
|
|
49
|
-
|
|
50
|
-
@Interface.private_api(cli_args=["name"])
|
|
51
|
-
def master_get(self, name: str, mode: str = "default", detailed: bool = False):
|
|
52
|
-
"""
|
|
53
|
-
Return the content of the master with mode
|
|
54
|
-
Valid modes: {default, }
|
|
55
|
-
"""
|
|
56
|
-
mas = self.sub_master_ids.get_obj_by_name(name)
|
|
57
|
-
if not mas:
|
|
58
|
-
return {"response": f"{name} not found"}
|
|
59
|
-
else:
|
|
60
|
-
return mas.serialize(detailed=detailed)
|
|
61
|
-
|
|
62
|
-
@Interface.private_api()
|
|
63
|
-
def master_list(self, detailed: bool = False):
|
|
64
|
-
"""
|
|
65
|
-
Provide complete list of all master objects (list of root node objects)
|
|
66
|
-
"""
|
|
67
|
-
masts = []
|
|
68
|
-
for i in self.sub_master_ids.obj_list():
|
|
69
|
-
masts.append(i.serialize(detailed=detailed))
|
|
70
|
-
return masts
|
|
71
|
-
|
|
72
|
-
@Interface.private_api(cli_args=["name"])
|
|
73
|
-
def master_active_set(self, name: str):
|
|
74
|
-
"""
|
|
75
|
-
Sets the default master master should use
|
|
76
|
-
NOTE: Special handler included in general_interface_to_api
|
|
77
|
-
"""
|
|
78
|
-
mas = self.sub_master_ids.get_obj_by_name(name)
|
|
79
|
-
if not mas:
|
|
80
|
-
return {"response": f"{name} not found"}
|
|
81
|
-
self.caller = mas.jid
|
|
82
|
-
return {"response": f"You are now {mas.name}"}
|
|
83
|
-
|
|
84
|
-
@Interface.private_api()
|
|
85
|
-
def master_active_unset(self):
|
|
86
|
-
"""
|
|
87
|
-
Unsets the default sentinel master should use
|
|
88
|
-
"""
|
|
89
|
-
self.caller = None
|
|
90
|
-
return {"response": f"You are now {self.name}"}
|
|
91
|
-
|
|
92
|
-
@Interface.private_api()
|
|
93
|
-
def master_active_get(self, detailed: bool = False):
|
|
94
|
-
"""
|
|
95
|
-
Returns the default master master is using
|
|
96
|
-
"""
|
|
97
|
-
if self.caller:
|
|
98
|
-
return self._h.get_obj(self._m_id, self.caller).serialize(detailed=detailed)
|
|
99
|
-
else:
|
|
100
|
-
return self.serialize(detailed=detailed)
|
|
101
|
-
|
|
102
|
-
@Interface.private_api()
|
|
103
|
-
def master_self(self, detailed: bool = False):
|
|
104
|
-
"""
|
|
105
|
-
Returns the masters object
|
|
106
|
-
"""
|
|
107
|
-
return self.serialize(detailed=detailed)
|
|
108
|
-
|
|
109
|
-
@Interface.private_api(cli_args=["name"])
|
|
110
|
-
def master_delete(self, name: str):
|
|
111
|
-
"""
|
|
112
|
-
Permanently delete master with given id
|
|
113
|
-
"""
|
|
114
|
-
if not self.sub_master_ids.has_obj_by_name(name):
|
|
115
|
-
return {"response": f"{name} not found", "success": False}
|
|
116
|
-
self.sub_master_ids.destroy_obj_by_name(name)
|
|
117
|
-
self.user_destroyer(name)
|
|
118
|
-
return {"response": f"{name} has been destroyed", "success": True}
|
|
119
|
-
|
|
120
|
-
def take_ownership(self, m):
|
|
121
|
-
"""
|
|
122
|
-
Assumes owenership over another master
|
|
123
|
-
"""
|
|
124
|
-
m.head_master_id = self.jid
|
|
125
|
-
m.give_access(self)
|
|
126
|
-
m.save()
|
|
127
|
-
self.sub_master_ids.add_obj(m)
|
|
128
|
-
|
|
129
|
-
def destroy(self):
|
|
130
|
-
"""
|
|
131
|
-
Destroys self from memory and persistent storage
|
|
132
|
-
"""
|
|
133
|
-
for i in self.sub_master_ids.obj_list():
|
|
134
|
-
i.destroy()
|
jaseci/extens/api/object_api.py
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Object api as a mixin
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
from jaseci.extens.api.interface import Interface
|
|
6
|
-
from jaseci.prim.element import Element
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class ObjectApi:
|
|
10
|
-
"""Object APIs for generalized operations on Jaseci objects
|
|
11
|
-
|
|
12
|
-
...
|
|
13
|
-
"""
|
|
14
|
-
|
|
15
|
-
def __init__(self):
|
|
16
|
-
self.perm_default = "private"
|
|
17
|
-
self._valid_perms = ["public", "private", "read_only"]
|
|
18
|
-
|
|
19
|
-
@Interface.private_api(cli_args=["name"])
|
|
20
|
-
def global_get(self, name: str):
|
|
21
|
-
"""
|
|
22
|
-
Get a global var
|
|
23
|
-
"""
|
|
24
|
-
return {"value": self._h.get_glob(name)}
|
|
25
|
-
|
|
26
|
-
@Interface.private_api(cli_args=["obj"])
|
|
27
|
-
def object_get(self, obj: Element, depth: int = 0, detailed: bool = False):
|
|
28
|
-
"""Returns object details for any Jaseci object."""
|
|
29
|
-
ret = obj.serialize(deep=depth, detailed=detailed)
|
|
30
|
-
return ret
|
|
31
|
-
|
|
32
|
-
@Interface.private_api(cli_args=["obj"])
|
|
33
|
-
def object_set(
|
|
34
|
-
self, obj: Element, ctx: dict, depth: int = 0, detailed: bool = False
|
|
35
|
-
):
|
|
36
|
-
"""Update a field in an object."""
|
|
37
|
-
if "jid" in ctx:
|
|
38
|
-
del ctx["jid"]
|
|
39
|
-
for i in ctx.keys():
|
|
40
|
-
if i in dir(obj) and not callable(getattr(obj, i)):
|
|
41
|
-
setattr(obj, i, ctx[i])
|
|
42
|
-
return obj.serialize(deep=depth, detailed=detailed)
|
|
43
|
-
|
|
44
|
-
@Interface.private_api(cli_args=["obj"])
|
|
45
|
-
def object_perms_get(self, obj: Element):
|
|
46
|
-
"""Returns object access mode for any Jaseci object."""
|
|
47
|
-
return {"access": obj.j_access}
|
|
48
|
-
|
|
49
|
-
@Interface.private_api(cli_args=["obj"])
|
|
50
|
-
def object_perms_set(self, obj: Element, mode: str):
|
|
51
|
-
"""Sets object access mode for any Jaseci object."""
|
|
52
|
-
ret = {}
|
|
53
|
-
if mode not in self._valid_perms:
|
|
54
|
-
ret["success"] = False
|
|
55
|
-
ret["response"] = f"{mode} not valid, must be in {self._valid_perms}"
|
|
56
|
-
else:
|
|
57
|
-
getattr(obj, "make_" + mode)()
|
|
58
|
-
ret["success"] = True
|
|
59
|
-
ret["response"] = f"{obj} set to {mode}"
|
|
60
|
-
return ret
|
|
61
|
-
|
|
62
|
-
@Interface.private_api(cli_args=["mode"])
|
|
63
|
-
def object_perms_default(self, mode: str):
|
|
64
|
-
"""Sets object access mode for any Jaseci object."""
|
|
65
|
-
ret = {}
|
|
66
|
-
if mode not in self._valid_perms:
|
|
67
|
-
ret["success"] = False
|
|
68
|
-
ret["response"] = f"{mode} not valid, must be in {self._valid_perms}"
|
|
69
|
-
else:
|
|
70
|
-
self.perm_default = mode
|
|
71
|
-
ret["success"] = True
|
|
72
|
-
ret["response"] = f"Default access for future objects set to {mode}"
|
|
73
|
-
return ret
|
|
74
|
-
|
|
75
|
-
@Interface.private_api(cli_args=["obj"])
|
|
76
|
-
def object_perms_grant(self, obj: Element, mast: Element, read_only: bool = False):
|
|
77
|
-
"""Grants another user permissions to access a Jaseci object."""
|
|
78
|
-
granted = obj.give_access(mast, read_only=read_only)
|
|
79
|
-
ret = {"success": granted}
|
|
80
|
-
if granted:
|
|
81
|
-
ret["response"] = f"Access to {obj} granted to {mast}"
|
|
82
|
-
else:
|
|
83
|
-
ret["response"] = f"Cannot grant {mast} access to {obj}"
|
|
84
|
-
return ret
|
|
85
|
-
|
|
86
|
-
@Interface.private_api(cli_args=["obj"])
|
|
87
|
-
def object_perms_revoke(self, obj: Element, mast: Element):
|
|
88
|
-
"""Remove permissions for user to access a Jaseci object."""
|
|
89
|
-
revoked = obj.remove_access(mast)
|
|
90
|
-
ret = {"success": revoked}
|
|
91
|
-
if revoked:
|
|
92
|
-
ret["response"] = f"Access to {obj} revoked from {mast}"
|
|
93
|
-
else:
|
|
94
|
-
ret["response"] = f"{mast} did not have access to {obj}"
|
|
95
|
-
return ret
|
|
96
|
-
|
|
97
|
-
@Interface.public_api()
|
|
98
|
-
def info(self):
|
|
99
|
-
"""Provide information about this instance of Jaseci"""
|
|
100
|
-
from jaseci import __version__, __creator__, __url__
|
|
101
|
-
|
|
102
|
-
return {"Version": __version__, "Creator": __creator__, "URL": __url__}
|