jaseci 1.4.0.9__py3-none-any.whl → 1.4.0.11__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 (87) hide show
  1. jaseci/VERSION +1 -1
  2. jaseci/__init__.py +3 -0
  3. jaseci/actions/standard/elastic.py +3 -2
  4. jaseci/actions/standard/mail.py +3 -2
  5. jaseci/actions/standard/std.py +3 -2
  6. jaseci/actions/standard/stripe.py +3 -2
  7. jaseci/actions/standard/task.py +3 -5
  8. jaseci/actions/standard/tests/test_mail_lib.py +8 -7
  9. jaseci/actions/tests/test_std.py +4 -5
  10. jaseci/actor/walker.py +6 -3
  11. jaseci/api/config_api.py +3 -2
  12. jaseci/api/jac_api.py +2 -2
  13. jaseci/api/jsorc_api.py +60 -121
  14. jaseci/api/prometheus_api.py +14 -20
  15. jaseci/api/queue_api.py +9 -5
  16. jaseci/api/tests/test_global_api.py +3 -3
  17. jaseci/api/tests/test_logger_api.py +3 -3
  18. jaseci/api/user_api.py +3 -3
  19. jaseci/api/webhook_api.py +6 -4
  20. jaseci/attr/action.py +10 -4
  21. jaseci/element/master.py +2 -0
  22. jaseci/element/super_master.py +2 -0
  23. jaseci/hook/memory.py +3 -1
  24. jaseci/hook/redis.py +5 -4
  25. jaseci/jac/interpreter/interp.py +16 -4
  26. jaseci/jac/tests/test_book.py +2 -2
  27. jaseci/jsctl/jsctl.py +48 -15
  28. jaseci/jsctl/tests/test_jsctl.py +5 -0
  29. jaseci/jsorc.py +733 -0
  30. jaseci/jsorc_settings.py +184 -0
  31. jaseci/manifests/database.yaml +107 -0
  32. jaseci/manifests/elastic.yaml +5923 -0
  33. jaseci/manifests/prometheus.yaml +1273 -0
  34. jaseci/{svc/jsorc-backup/jaseci-redis.yaml → manifests/redis.yaml} +20 -0
  35. jaseci/svc/__init__.py +0 -25
  36. jaseci/svc/{elastic/elastic.py → elastic_svc.py} +5 -16
  37. jaseci/svc/kube_svc.py +240 -0
  38. jaseci/svc/{mail/mail.py → mail_svc.py} +14 -17
  39. jaseci/svc/{prometheus/prometheus.py → prome_svc.py} +5 -16
  40. jaseci/svc/{redis/redis.py → redis_svc.py} +14 -26
  41. jaseci/svc/{stripe/stripe.py → stripe_svc.py} +4 -7
  42. jaseci/svc/{task/task.py → task_svc.py} +27 -24
  43. jaseci/svc/{task/common.py → tasks.py} +287 -293
  44. jaseci/tests/jac_test_progs.py +21 -0
  45. jaseci/tests/test_core.py +14 -15
  46. jaseci/tests/test_jac.py +59 -60
  47. jaseci/tests/test_node.py +6 -13
  48. jaseci/tests/test_progs.py +74 -52
  49. jaseci/tests/test_stripe.py +6 -10
  50. jaseci/utils/actions/actions_manager.py +254 -0
  51. jaseci/{svc/actions_optimizer → utils/actions}/actions_optimizer.py +9 -19
  52. jaseci/utils/json_handler.py +2 -3
  53. jaseci/utils/test_core.py +4 -5
  54. jaseci/utils/utils.py +12 -0
  55. {jaseci-1.4.0.9.dist-info → jaseci-1.4.0.11.dist-info}/METADATA +2 -1
  56. {jaseci-1.4.0.9.dist-info → jaseci-1.4.0.11.dist-info}/RECORD +63 -80
  57. jaseci/svc/common.py +0 -763
  58. jaseci/svc/config.py +0 -9
  59. jaseci/svc/elastic/__init__.py +0 -3
  60. jaseci/svc/elastic/config.py +0 -8
  61. jaseci/svc/elastic/manifest.py +0 -1
  62. jaseci/svc/jsorc-backup/jsorc.py +0 -182
  63. jaseci/svc/jsorc-backup/promon/__init__.py +0 -0
  64. jaseci/svc/jsorc-backup/promon/promon.py +0 -202
  65. jaseci/svc/mail/__init__.py +0 -4
  66. jaseci/svc/mail/config.py +0 -25
  67. jaseci/svc/meta.py +0 -164
  68. jaseci/svc/postgres/__init__.py +0 -0
  69. jaseci/svc/postgres/manifest.py +0 -106
  70. jaseci/svc/prometheus/__init__.py +0 -5
  71. jaseci/svc/prometheus/config.py +0 -11
  72. jaseci/svc/prometheus/manifest.py +0 -1102
  73. jaseci/svc/redis/__init__.py +0 -5
  74. jaseci/svc/redis/config.py +0 -10
  75. jaseci/svc/redis/manifest.py +0 -65
  76. jaseci/svc/state.py +0 -17
  77. jaseci/svc/stripe/__init__.py +0 -3
  78. jaseci/svc/stripe/config.py +0 -7
  79. jaseci/svc/task/__init__.py +0 -5
  80. jaseci/svc/task/config.py +0 -17
  81. /jaseci/{svc/actions_optimizer → manifests}/__init__.py +0 -0
  82. /jaseci/{svc/jsorc-backup → utils/actions}/__init__.py +0 -0
  83. /jaseci/{svc/actions_optimizer → utils/actions}/actions_state.py +0 -0
  84. {jaseci-1.4.0.9.dist-info → jaseci-1.4.0.11.dist-info}/LICENSE +0 -0
  85. {jaseci-1.4.0.9.dist-info → jaseci-1.4.0.11.dist-info}/WHEEL +0 -0
  86. {jaseci-1.4.0.9.dist-info → jaseci-1.4.0.11.dist-info}/entry_points.txt +0 -0
  87. {jaseci-1.4.0.9.dist-info → jaseci-1.4.0.11.dist-info}/top_level.txt +0 -0
jaseci/VERSION CHANGED
@@ -1 +1 @@
1
- 1.4.0.9
1
+ 1.4.0.11
jaseci/__init__.py CHANGED
@@ -1,4 +1,6 @@
1
1
  from os.path import dirname, join
2
+ from .jsorc_settings import JsOrcSettings
3
+ from .jsorc import State, JsOrc
2
4
 
3
5
 
4
6
  def get_ver():
@@ -9,6 +11,7 @@ def get_ver():
9
11
  __version__ = get_ver()
10
12
  __creator__ = "Jason Mars and friends"
11
13
  __url__ = "https://jaseci.org"
14
+ __all__ = ["State", "JsOrc", "JsOrcSettings"]
12
15
 
13
16
 
14
17
  def load_standard():
@@ -1,9 +1,10 @@
1
1
  from jaseci.actions.live_actions import jaseci_action
2
- from jaseci.svc import MetaService
2
+ from jaseci import JsOrc
3
+ from jaseci.svc.elastic_svc import ElasticService, Elastic
3
4
 
4
5
 
5
6
  def elastic():
6
- return MetaService().get_service("elastic").poke()
7
+ return JsOrc.svc("elastic", ElasticService).poke(Elastic)
7
8
 
8
9
 
9
10
  @jaseci_action()
@@ -1,9 +1,10 @@
1
1
  from jaseci.actions.live_actions import jaseci_action
2
- from jaseci.svc import MetaService
2
+ from jaseci import JsOrc
3
+ from jaseci.svc.mail_svc import Mailer
3
4
 
4
5
 
5
6
  @jaseci_action()
6
7
  def send(sender, recipients, subject, text, html):
7
- MetaService().get_service("mail").poke().send_custom_email(
8
+ JsOrc.svc("mail").poke(Mailer).send_custom_email(
8
9
  sender, recipients, subject, (text, html)
9
10
  )
@@ -6,7 +6,8 @@ from jaseci.jac.machine.jac_value import jac_wrap_value as jwv
6
6
  from jaseci.actions.live_actions import jaseci_action
7
7
  from jaseci.utils.utils import master_from_meta
8
8
  from jaseci.element.element import Element
9
- from jaseci.svc import MetaService
9
+ from jaseci import JsOrc
10
+ from jaseci.svc.elastic_svc import Elastic
10
11
 
11
12
  import sys
12
13
  import json
@@ -214,7 +215,7 @@ def clear_report(meta):
214
215
  def log_activity(
215
216
  log: dict, action: str = "", query: str = "", suffix: str = "", meta: dict = {}
216
217
  ):
217
- elastic = MetaService().get_service("elastic").poke()
218
+ elastic = JsOrc.svc("elastic").poke(Elastic)
218
219
  activity = elastic.generate_from_meta(meta, log)
219
220
 
220
221
  return elastic.doc_activity(activity, query, suffix)
@@ -1,13 +1,14 @@
1
1
  """Built in actions for Jaseci"""
2
2
  import stripe as s
3
3
 
4
- from jaseci.svc import MetaService
4
+ from jaseci import JsOrc
5
+ from jaseci.svc.stripe_svc import StripeService
5
6
  from datetime import datetime
6
7
  from jaseci.actions.live_actions import jaseci_action
7
8
 
8
9
 
9
10
  def stripe() -> s:
10
- return MetaService().get_service("stripe").poke()
11
+ return JsOrc.svc("stripe", StripeService).poke()
11
12
 
12
13
 
13
14
  @jaseci_action()
@@ -1,5 +1,7 @@
1
1
  """Built in actions for Jaseci"""
2
+ from jaseci import JsOrc
2
3
  from jaseci.actions.live_actions import jaseci_action
4
+ from jaseci.svc.task_svc import TaskService
3
5
 
4
6
 
5
7
  @jaseci_action()
@@ -7,9 +9,5 @@ def get_result(task_id, wait, meta):
7
9
  """
8
10
  Get task result by task_id
9
11
  """
10
- task = meta["h"].task
11
12
 
12
- if not task.is_running():
13
- raise Exception("Task hook is not yet initialized!")
14
-
15
- return task.get_by_task_id(task_id, wait)
13
+ return JsOrc.svc("task").poke(TaskService).get_by_task_id(task_id, wait)
@@ -1,7 +1,7 @@
1
1
  from unittest.mock import MagicMock, Mock
2
2
 
3
- from jaseci.svc import MailService
4
- from jaseci.svc.mail import MAIL_CONFIG
3
+ from jaseci import JsOrc
4
+ from jaseci.svc.mail_svc import MailService
5
5
  from jaseci.utils.test_core import CoreTest
6
6
 
7
7
 
@@ -11,22 +11,23 @@ class MailLibTest(CoreTest):
11
11
  fixture_src = __file__
12
12
 
13
13
  def __init__(self, *args, **kwargs):
14
- MAIL_CONFIG["enabled"] = True
14
+ JsOrc.settings("MAIL_CONFIG")["enabled"] = True
15
15
  MailService.connect = MagicMock(return_value=Mock())
16
16
  super(MailLibTest, self).__init__(*args, **kwargs)
17
17
 
18
18
  def setUp(self):
19
- super().setUp(True)
19
+ super().setUp()
20
20
 
21
- def test_send_mail(self):
21
+ @JsOrc.inject(services=["mail"])
22
+ def test_send_mail(self, mail: MailService):
22
23
  self.call(
23
24
  self.mast,
24
25
  ["sentinel_register", {"code": self.load_jac("mail_test.jac")}],
25
26
  )
26
27
  ret = self.call(self.mast, ["walker_run", {"name": "send_mail"}])
27
28
  self.assertTrue(ret["success"])
28
- self.assertTrue(self.mast._h.mail.connect.called)
29
+ self.assertTrue(mail.connect.called)
29
30
  self.assertEqual(
30
- self.mast._h.mail.app.method_calls[0].args,
31
+ mail.app.method_calls[0].args,
31
32
  (None, ["jaseci.dev@gmail.com"], "Test Subject", ("Test", "<h1>Test</h1>")),
32
33
  )
@@ -3,7 +3,7 @@ from unittest import TestCase
3
3
  import jaseci.actions.tests.std_test_code as stc
4
4
  from jaseci.actor.sentinel import Sentinel
5
5
  from jaseci.graph.graph import Graph
6
- from jaseci.svc import MetaService
6
+ from jaseci import JsOrc
7
7
  from jaseci.utils.utils import TestCaseHelper
8
8
 
9
9
 
@@ -12,13 +12,12 @@ class JacTests(TestCaseHelper, TestCase):
12
12
 
13
13
  def setUp(self):
14
14
  super().setUp()
15
- self.meta = MetaService()
16
15
 
17
16
  def tearDown(self):
18
17
  super().tearDown()
19
18
 
20
19
  def test_rand_std(self):
21
- sent = Sentinel(m_id=0, h=self.meta.build_hook())
20
+ sent = Sentinel(m_id=0, h=JsOrc.hook())
22
21
  gph = Graph(m_id=0, h=sent._h)
23
22
  sent.register_code(stc.rand_std)
24
23
  test_walker = sent.run_architype("init")
@@ -31,7 +30,7 @@ class JacTests(TestCaseHelper, TestCase):
31
30
  self.assertGreater(len(report[3]), len(report[2]))
32
31
 
33
32
  def test_file_io(self):
34
- sent = Sentinel(m_id=0, h=self.meta.build_hook())
33
+ sent = Sentinel(m_id=0, h=JsOrc.hook())
35
34
  gph = Graph(m_id=0, h=sent._h)
36
35
  sent.register_code(stc.file_io)
37
36
  test_walker = sent.run_architype("init")
@@ -41,7 +40,7 @@ class JacTests(TestCaseHelper, TestCase):
41
40
  self.assertEqual(report, ['{"a": 10}{"a": 10}'])
42
41
 
43
42
  def test_std_used_in_node_has_var(self):
44
- sent = Sentinel(m_id=0, h=self.meta.build_hook())
43
+ sent = Sentinel(m_id=0, h=JsOrc.hook())
45
44
  gph = Graph(m_id=0, h=sent._h)
46
45
  sent.register_code(stc.std_used_in_node_has_var)
47
46
  test_walker = sent.run_architype("init")
jaseci/actor/walker.py CHANGED
@@ -20,6 +20,9 @@ from jaseci.jac.interpreter.walker_interp import WalkerInterp
20
20
  import uuid
21
21
  import hashlib
22
22
 
23
+ from jaseci import JsOrc
24
+ from jaseci.svc.task_svc import TaskService
25
+
23
26
 
24
27
  class Walker(Element, WalkerInterp, Anchored):
25
28
  """Walker class for Jaseci"""
@@ -130,7 +133,7 @@ class Walker(Element, WalkerInterp, Anchored):
130
133
 
131
134
  def run(self, start_node=None, prime_ctx=None, request_ctx=None, profiling=False):
132
135
  """Executes Walker to completion"""
133
- if self.for_queue() and self._h.task.is_running():
136
+ if self.for_queue() and JsOrc.svc("task").is_running():
134
137
  start_node = (
135
138
  start_node
136
139
  if not (start_node is None)
@@ -143,7 +146,7 @@ class Walker(Element, WalkerInterp, Anchored):
143
146
 
144
147
  return {
145
148
  "is_queued": True,
146
- "result": self._h.task.add_queue(
149
+ "result": JsOrc.svc("task", TaskService).add_queue(
147
150
  self,
148
151
  start_node,
149
152
  prime_ctx or self.context,
@@ -228,7 +231,7 @@ class Walker(Element, WalkerInterp, Anchored):
228
231
  """
229
232
  Destroys self from memory and persistent storage
230
233
  """
231
- if not self.for_queue() or not self._h.task.is_running():
234
+ if not self.for_queue() or not JsOrc.svc("task").is_running():
232
235
  WalkerInterp.destroy(self)
233
236
  super().destroy()
234
237
 
jaseci/api/config_api.py CHANGED
@@ -20,10 +20,11 @@ class ConfigApi:
20
20
  "REDIS_CONFIG",
21
21
  "TASK_CONFIG",
22
22
  "MAIL_CONFIG",
23
- "PROMON_CONFIG",
23
+ "PROME_CONFIG",
24
24
  "ELASTIC_CONFIG",
25
25
  "STRIPE_CONFIG",
26
- "META_CONFIG",
26
+ "KUBE_CONFIG",
27
+ "JSORC_CONFIG",
27
28
  ]
28
29
 
29
30
  @Interface.admin_api(cli_args=["name"])
jaseci/api/jac_api.py CHANGED
@@ -6,7 +6,7 @@ import json
6
6
  import os
7
7
 
8
8
  from jaseci.api.interface import Interface
9
- from jaseci.svc import MetaService
9
+ from jaseci import JsOrc
10
10
 
11
11
 
12
12
  class JacApi:
@@ -158,7 +158,7 @@ class JacApi:
158
158
  return faux.graph_get(nd=faux.active_gph(), mode="dot", detailed=detailed)
159
159
 
160
160
  def faux_master(self):
161
- faux = MetaService(run_svcs=False).build_super_master()
161
+ faux = JsOrc.super_master()
162
162
  faux._h.mem["global"] = deepcopy(self._h.mem["global"])
163
163
  return faux
164
164
 
jaseci/api/jsorc_api.py CHANGED
@@ -7,8 +7,12 @@ import json
7
7
  from json import dumps, loads
8
8
  from time import time
9
9
  from base64 import b64decode
10
- from jaseci.svc import CommonService
11
- from jaseci.svc.common import Kube, UNSAFE_PARAPHRASE
10
+
11
+ from jaseci import JsOrc
12
+ from jaseci.utils.utils import logger
13
+ from jaseci.svc.kube_svc import KubeService
14
+ from jaseci.utils.actions.actions_manager import ActionManager
15
+
12
16
  from jaseci.api.interface import Interface
13
17
 
14
18
 
@@ -18,27 +22,28 @@ class JsOrcApi:
18
22
  """
19
23
 
20
24
  @Interface.admin_api()
21
- def load_yaml(self, files: list, namespace: str = "default"):
25
+ def load_yaml(self, files: list, namespace: str = None):
22
26
  """
23
27
  applying list of yaml files without associating to any modules/services
24
28
  """
25
29
 
26
- if self._h.meta.is_automated():
27
- kube = self._h.meta.app.kubernetes
28
- kube: Kube
30
+ try:
31
+ kube = JsOrc.svc("kube").poke(KubeService)
29
32
 
30
33
  res = {}
31
-
32
34
  for file in files:
33
35
  for conf in yaml.safe_load_all(b64decode(file["base64"])):
34
36
  kind = conf["kind"]
35
- kube.create(kind, namespace, conf)
37
+ kube.create(
38
+ kind, conf["metadata"]["name"], conf, namespace=namespace
39
+ )
36
40
  if not res.get(kind):
37
41
  res[kind] = []
38
42
  res[kind].append(conf)
39
43
 
40
44
  return res
41
- else:
45
+ except Exception:
46
+ logger.exception("Error loading yaml!")
42
47
  return {"message": "load_yaml is not supported on non automated JsOrc!"}
43
48
 
44
49
  @Interface.admin_api(cli_args=["name"])
@@ -64,16 +69,16 @@ class JsOrcApi:
64
69
  old_config = self._h.get_glob(name)
65
70
  if old_config:
66
71
  old_config = loads(old_config)
67
- old_config.pop("__OLD_CONFIG__", None)
72
+ old_config.pop("__OLD_CONFIG__", {})
68
73
  for kind, confs in old_config.items():
69
- names = []
74
+ _confs = {}
70
75
  for conf in confs:
71
- names.append(conf["metadata"]["name"])
72
- old_config[kind] = names
76
+ _confs.update({conf["metadata"]["name"]: conf})
77
+ old_config[kind] = _confs
73
78
 
74
79
  new_config["__OLD_CONFIG__"] = old_config
75
80
 
76
- if unsafe_paraphrase == UNSAFE_PARAPHRASE:
81
+ if unsafe_paraphrase == JsOrc.settings("UNSAFE_PARAPHRASE"):
77
82
  new_config["__UNSAFE_PARAPHRASE__"] = unsafe_paraphrase
78
83
 
79
84
  self._h.save_glob(name, dumps(new_config))
@@ -86,23 +91,10 @@ class JsOrcApi:
86
91
  refreshing service's config. If JsOrc is not automated, service will restart else JsOrc will handle the rest
87
92
  """
88
93
 
89
- hook = self._h
90
-
91
- to_start = not hook.meta.is_automated()
94
+ # will throw exception if not existing
95
+ JsOrc.svc_reset(name)
92
96
 
93
- service = getattr(hook, name, None)
94
-
95
- response = {"success": False}
96
-
97
- if isinstance(service, CommonService):
98
- service.reset(hook, to_start)
99
- response["success"] = True
100
- else:
101
- response[
102
- "message"
103
- ] = f"{name} is not a valid service. Can not refresh config."
104
-
105
- return response
97
+ return {"success": True}
106
98
 
107
99
  @Interface.admin_api(cli_args=["name"])
108
100
  def service_call(self, svc: str, attrs: list = []):
@@ -110,12 +102,7 @@ class JsOrcApi:
110
102
  temporary api for retreiving/calling attributes of specific instance.
111
103
  """
112
104
 
113
- from jaseci.svc import MetaService
114
-
115
- meta = self._h.meta
116
- meta: MetaService
117
-
118
- svc = meta.get_service(svc)
105
+ svc = JsOrc.svc(svc)
119
106
 
120
107
  if not svc:
121
108
  return "Service (svc) field is required!"
@@ -148,25 +135,19 @@ class JsOrcApi:
148
135
  JSORC will load the corresponding module or start a microservice if needed.
149
136
  Return the current status of the action.
150
137
  """
151
- hook = self._h
152
- if hook.meta.run_svcs:
153
- hook.meta.app.load_actions(name, mode)
154
- status = hook.meta.app.get_actions_status(name)
155
- return {"success": True, "action_status": status}
156
- else:
157
- return {"success": False, "message": "No running JSORC service."}
138
+ action_manager = JsOrc.get("action_manager", ActionManager)
139
+ action_manager.load_actions(name, mode)
140
+ status = action_manager.get_actions_status(name)
141
+
142
+ return {"success": True, "action_status": status}
158
143
 
159
144
  @Interface.admin_api(cli_args=["name"])
160
145
  def jsorc_actions_status(self, name: str):
161
146
  """
162
147
  Get the current status of an action
163
148
  """
164
- hook = self._h
165
- if hook.meta.run_svcs:
166
- status = hook.meta.app.get_actions_status(name)
167
- return {"success": True, "action_status": status}
168
- else:
169
- return {"success": False, "message": "No running JSORC service."}
149
+ status = JsOrc.get("action_manager", ActionManager).get_actions_status(name)
150
+ return {"success": True, "action_status": status}
170
151
 
171
152
  @Interface.admin_api(cli_args=["name"])
172
153
  def jsorc_actions_unload(
@@ -176,12 +157,10 @@ class JsOrcApi:
176
157
  Unload an action through JSORC.
177
158
  If retire_svc is set to True (true by default), it will also retire the corresponding microservice.
178
159
  """
179
- hook = self._h
180
- if hook.meta.run_svcs:
181
- res = hook.meta.app.unload_actions(name, mode, retire_svc)
182
- return {"success": res[0], "message": res[1]}
183
- else:
184
- return {"success": False, "message": "No running JSORC service."}
160
+ res = JsOrc.get("action_manager", ActionManager).unload_actions(
161
+ name, mode, retire_svc
162
+ )
163
+ return {"success": res[0], "message": res[1]}
185
164
 
186
165
  @Interface.admin_api(cli_args=["config", "name"])
187
166
  def jsorc_actions_config(self, config: str, name: str):
@@ -190,133 +169,93 @@ class JsOrcApi:
190
169
  config: name of the ai kit package (e.g. jac_nlp.config, jac_vision.config)
191
170
  name: name of the action module (e.g. use_enc, bi_enc)
192
171
  """
193
- hook = self._h
194
- if hook.meta.run_svcs:
195
- res = hook.meta.app.load_action_config(config, name)
196
- return {"success": res}
197
- else:
198
- return {"success": False, "message": "No running JSORC service."}
172
+ res = JsOrc.get("action_manager", ActionManager).load_action_config(
173
+ config, name
174
+ )
175
+ return {"success": res}
199
176
 
200
177
  @Interface.admin_api()
201
178
  def jsorc_trackact_start(self):
202
179
  """ "
203
180
  Instruct JSORC to start tracking any changes in actions state
204
181
  """
205
- hook = self._h
206
- if hook.meta.run_svcs:
207
- hook.meta.app.actions_tracking_start()
208
- return {"success": True}
209
- else:
210
- return {"success": False, "message": "No running JSORC service."}
182
+ JsOrc.get("action_manager", ActionManager).actions_tracking_start()
183
+ return {"success": True}
211
184
 
212
185
  @Interface.admin_api()
213
186
  def jsorc_trackact_stop(self):
214
187
  """ "
215
188
  Instruct JSORC to start tracking any changes in actions state
216
189
  """
217
- hook = self._h
218
- if hook.meta.run_svcs:
219
- return hook.meta.app.actions_tracking_stop()
220
- else:
221
- return {"success": False, "message": "No running JSORC service."}
190
+ return JsOrc.get("action_manager", ActionManager).actions_tracking_stop()
222
191
 
223
192
  @Interface.admin_api()
224
193
  def jsorc_benchmark_start(self):
225
194
  """
226
195
  Tell JSORC to start collecting request performance metrics
227
196
  """
228
- hook = self._h
229
- if hook.meta.run_svcs:
230
- hook.meta.app.benchmark_start()
231
- return {"success": True}
232
- else:
233
- return {"success": False, "message": "No running JSORC service."}
197
+ JsOrc.get("action_manager", ActionManager).benchmark_start()
198
+ return {"success": True}
234
199
 
235
200
  @Interface.admin_api()
236
201
  def jsorc_benchmark_report(self):
237
202
  """
238
203
  Report the collected request performance metrics of the currently ongoing benchmark
239
204
  """
240
- hook = self._h
241
- if hook.meta.run_svcs:
242
- return hook.meta.app.benchmark_report()
243
- else:
244
- return {"success": False, "message": "No running JSORC service."}
205
+ return JsOrc.get("action_manager", ActionManager).benchmark_report()
245
206
 
246
207
  @Interface.admin_api()
247
208
  def jsorc_benchmark_stop(self, report: bool = True):
248
209
  """
249
210
  End the benchmark period and report performance metrics
250
211
  """
251
- hook = self._h
252
- if hook.meta.run_svcs:
253
- return hook.meta.app.benchmark_stop(report)
254
- else:
255
- return {"success": False, "message": "No running JSORC service."}
212
+ return JsOrc.get("action_manager", ActionManager).benchmark_stop(report)
256
213
 
257
214
  @Interface.admin_api()
258
215
  def jsorc_tracksys_start(self):
259
216
  """
260
217
  Ask JSORC to start tracking the state of the system as observed by JSORC on every interval.
261
218
  """
262
- hook = self._h
263
- if hook.meta.run_svcs:
264
- hook.meta.app.state_tracking_start()
265
- return {"success": True}
266
- else:
267
- return {"success": False, "message": "No running JSORC service."}
219
+ JsOrc.get("action_manager", ActionManager).state_tracking_start()
220
+ return {"success": True}
268
221
 
269
222
  @Interface.admin_api()
270
223
  def jsorc_tracksys_report(self):
271
224
  """
272
225
  Report the tracked system states so far
273
226
  """
274
- hook = self._h
275
- if hook.meta.run_svcs:
276
- return hook.meta.app.state_tracking_report()
277
- else:
278
- return {"success": False, "message": "No running JSORC service."}
227
+ return JsOrc.get("action_manager", ActionManager).state_tracking_report()
279
228
 
280
229
  @Interface.admin_api()
281
230
  def jsorc_tracksys_stop(self):
282
231
  """
283
232
  Stop state tracking for JSORC
284
233
  """
285
- hook = self._h
286
- if hook.meta.run_svcs:
287
- return hook.meta.app.state_tracking_stop()
288
- else:
289
- return {"success": False, "message": "No running JSORC service."}
234
+ return JsOrc.get("action_manager", ActionManager).state_tracking_stop()
290
235
 
291
236
  @Interface.admin_api()
292
237
  def jsorc_actionpolicy_set(self, policy_name: str, policy_params: dict = {}):
293
238
  """
294
239
  Set an action optimization policy for JSORC
295
240
  """
296
- hook = self._h
297
- if hook.meta.run_svcs:
298
- res = hook.meta.app.set_action_policy(policy_name, policy_params)
299
- if res is True:
300
- return {
301
- "success": True,
302
- "message": f"Action optimization policy configured as {policy_name} with params {policy_params}",
303
- }
304
- else:
305
- return {"success": False, "message": res}
241
+ res = JsOrc.get("action_manager", ActionManager).set_action_policy(
242
+ policy_name, policy_params
243
+ )
244
+ if res is True:
245
+ return {
246
+ "success": True,
247
+ "message": f"Action optimization policy configured as {policy_name} with params {policy_params}",
248
+ }
306
249
  else:
307
- return {"success": False, "message": "No running JSORC service."}
250
+ return {"success": False, "message": res}
308
251
 
309
252
  @Interface.admin_api()
310
253
  def jsorc_actionpolicy_get(self):
311
254
  """
312
255
  Get the current active action optimization policy
313
256
  """
314
- hook = self._h
315
- if hook.meta.run_svcs:
316
- policy = hook.meta.app.get_action_policy()
317
- return {"success": True, "policy": policy}
318
- else:
319
- return {"success": False, "message": "No running JSORC service."}
257
+ policy = JsOrc.get("action_manager", ActionManager).get_action_policy()
258
+ return {"success": True, "policy": policy}
320
259
 
321
260
  @Interface.admin_api()
322
261
  def jsorc_loadtest(self, test: str, experiment: str = "", mem: int = 0):
@@ -2,6 +2,12 @@
2
2
  Prometheus APIs
3
3
  """
4
4
  from jaseci.api.interface import Interface
5
+ from jaseci import JsOrc
6
+ from jaseci.svc.prome_svc import PrometheusService
7
+
8
+
9
+ def prome():
10
+ return JsOrc.svc("prome").poke(PrometheusService)
5
11
 
6
12
 
7
13
  class PrometheusApi:
@@ -14,22 +20,14 @@ class PrometheusApi:
14
20
  """
15
21
  Return list of availabel metrics
16
22
  """
17
- hook = self._h
18
- if hook.meta.run_svcs:
19
- return hook.promon.all_metrics()
20
- else:
21
- return {"success": False, "message": "No runnning Prometheus service."}
23
+ return prome().all_metrics()
22
24
 
23
25
  @Interface.admin_api()
24
26
  def prometheus_pod_list(self, namespace: str = "", exclude_prom: bool = False):
25
27
  """
26
28
  Return list of pods. If exclude_prom,
27
29
  """
28
- hook = self._h
29
- if hook.meta.run_svcs:
30
- return hook.promon.pods(namespace=namespace, exclude_prom=exclude_prom)
31
- else:
32
- return {"success": False, "message": "No runnning Prometheus service."}
30
+ return prome().pods(namespace=namespace, exclude_prom=exclude_prom)
33
31
 
34
32
  @Interface.admin_api()
35
33
  def prometheus_pod_info(
@@ -42,13 +40,9 @@ class PrometheusApi:
42
40
  """
43
41
  Return pods info and metrics
44
42
  """
45
- hook = self._h
46
- if hook.meta.run_svcs:
47
- return hook.promon.info(
48
- namespace=namespace,
49
- exclude_prom=exclude_prom,
50
- timestamp=timestamp,
51
- duration=duration,
52
- )
53
- else:
54
- return {"success": False, "message": "No runnning Prometheus service."}
43
+ return prome().info(
44
+ namespace=namespace,
45
+ exclude_prom=exclude_prom,
46
+ timestamp=timestamp,
47
+ duration=duration,
48
+ )