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/jsorc/jsorc_settings.py
DELETED
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
from time import time
|
|
3
|
-
from jaseci.jsorc.jsorc_utils import load_default_yaml, get_service_map
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class JsOrcSettings:
|
|
7
|
-
###############################################################################################################
|
|
8
|
-
# ------------------------------------------------- DEFAULT ------------------------------------------------- #
|
|
9
|
-
###############################################################################################################
|
|
10
|
-
|
|
11
|
-
DEFAULT_CONFIG = {"enabled": False, "quiet": False, "automated": False}
|
|
12
|
-
|
|
13
|
-
DEFAULT_MANIFEST = {}
|
|
14
|
-
|
|
15
|
-
UNSAFE_PARAPHRASE = "I know what I'm doing!"
|
|
16
|
-
UNSAFE_KINDS = ["PersistentVolumeClaim"]
|
|
17
|
-
|
|
18
|
-
SERVICE_MANIFEST_MAP = get_service_map("database", "redis", "elastic", "prome")
|
|
19
|
-
|
|
20
|
-
###############################################################################################################
|
|
21
|
-
# -------------------------------------------------- JSORC -------------------------------------------------- #
|
|
22
|
-
###############################################################################################################
|
|
23
|
-
|
|
24
|
-
JSORC_CONFIG = {
|
|
25
|
-
"backoff_interval": 10,
|
|
26
|
-
"pre_loaded_services": [],
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
###############################################################################################################
|
|
30
|
-
# -------------------------------------------------- KUBE --------------------------------------------------- #
|
|
31
|
-
###############################################################################################################
|
|
32
|
-
|
|
33
|
-
KUBE_NAMESPACE = os.getenv("KUBE_NAMESPACE", f"jaseci-{int(time() * 100000)}")
|
|
34
|
-
|
|
35
|
-
KUBE_CONFIG = {
|
|
36
|
-
"enabled": bool(os.getenv("KUBE_NAMESPACE")),
|
|
37
|
-
"quiet": False,
|
|
38
|
-
"automated": False,
|
|
39
|
-
"namespace": KUBE_NAMESPACE,
|
|
40
|
-
"in_cluster": True,
|
|
41
|
-
"config": None,
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
###############################################################################################################
|
|
45
|
-
# -------------------------------------------------- REDIS -------------------------------------------------- #
|
|
46
|
-
###############################################################################################################
|
|
47
|
-
|
|
48
|
-
REDIS_CONFIG = {
|
|
49
|
-
"enabled": True,
|
|
50
|
-
"quiet": False,
|
|
51
|
-
"automated": False,
|
|
52
|
-
"host": os.getenv("REDIS_HOST", "localhost"),
|
|
53
|
-
"port": os.getenv("REDIS_PORT", "6379"),
|
|
54
|
-
"db": os.getenv("REDIS_DB", "1"),
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
REDIS_MANIFEST = load_default_yaml("redis")
|
|
58
|
-
|
|
59
|
-
###############################################################################################################
|
|
60
|
-
# -------------------------------------------------- TASK --------------------------------------------------- #
|
|
61
|
-
###############################################################################################################
|
|
62
|
-
|
|
63
|
-
DEFAULT_REDIS_URL = (
|
|
64
|
-
f'redis://{os.getenv("REDIS_HOST", "localhost")}'
|
|
65
|
-
f':{os.getenv("REDIS_PORT", "6379")}/{os.getenv("REDIS_DB", "1")}'
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
TASK_CONFIG = {
|
|
69
|
-
"enabled": True,
|
|
70
|
-
"quiet": False,
|
|
71
|
-
"automated": False,
|
|
72
|
-
"broker_url": DEFAULT_REDIS_URL,
|
|
73
|
-
"result_backend": DEFAULT_REDIS_URL,
|
|
74
|
-
"broker_connection_retry_on_startup": True,
|
|
75
|
-
"task_track_started": True,
|
|
76
|
-
"worker_redirect_stdouts": False,
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
###############################################################################################################
|
|
80
|
-
# -------------------------------------------------- MAIL --------------------------------------------------- #
|
|
81
|
-
###############################################################################################################
|
|
82
|
-
|
|
83
|
-
MAIL_CONFIG = {
|
|
84
|
-
"enabled": False,
|
|
85
|
-
"quiet": False,
|
|
86
|
-
"automated": False,
|
|
87
|
-
"version": 2,
|
|
88
|
-
"tls": True,
|
|
89
|
-
"host": "",
|
|
90
|
-
"port": 587,
|
|
91
|
-
"sender": "",
|
|
92
|
-
"user": "",
|
|
93
|
-
"pass": "",
|
|
94
|
-
"backend": "smtp",
|
|
95
|
-
"templates": {
|
|
96
|
-
"activation_subj": "Please activate your account!",
|
|
97
|
-
"activation_body": "Thank you for creating an account!\n\n"
|
|
98
|
-
"Activation Code: {{code}}\n"
|
|
99
|
-
"Please click below to activate:\n{{link}}",
|
|
100
|
-
"activation_html_body": "Thank you for creating an account!<br><br>"
|
|
101
|
-
"Activation Code: {{code}}<br>"
|
|
102
|
-
"Please click below to activate:<br>"
|
|
103
|
-
"{{link}}",
|
|
104
|
-
"resetpass_subj": "Password Reset for Jaseci Account",
|
|
105
|
-
"resetpass_body": "Your Jaseci password reset token is: {{token}}",
|
|
106
|
-
"resetpass_html_body": "Your Jaseci password reset" "token is: {{token}}",
|
|
107
|
-
},
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
###############################################################################################################
|
|
111
|
-
# ------------------------------------------------- STRIPE -------------------------------------------------- #
|
|
112
|
-
###############################################################################################################
|
|
113
|
-
|
|
114
|
-
STRIPE_CONFIG = {
|
|
115
|
-
"enabled": False,
|
|
116
|
-
"api_key": None,
|
|
117
|
-
"automated": False,
|
|
118
|
-
"webhook_key": None,
|
|
119
|
-
"fallback_walker": "stripe",
|
|
120
|
-
"event_walker": {},
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
###############################################################################################################
|
|
124
|
-
# ----------------------------------------------- PROMETHEUS ------------------------------------------------ #
|
|
125
|
-
###############################################################################################################
|
|
126
|
-
|
|
127
|
-
PROME_CONFIG = {
|
|
128
|
-
"enabled": bool(os.getenv("PROME_HOST")),
|
|
129
|
-
"quiet": False,
|
|
130
|
-
"automated": True,
|
|
131
|
-
"url": (
|
|
132
|
-
f'http://{os.getenv("PROME_HOST", "localhost")}'
|
|
133
|
-
f':{os.getenv("PROME_PORT", "9090")}'
|
|
134
|
-
),
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
PROME_MANIFEST = load_default_yaml("prometheus")
|
|
138
|
-
|
|
139
|
-
###############################################################################################################
|
|
140
|
-
# ------------------------------------------------ ELASTIC -------------------------------------------------- #
|
|
141
|
-
###############################################################################################################
|
|
142
|
-
|
|
143
|
-
ELASTIC_ILM_POLICY_NAME = "jaseci-logs-ilm-policy"
|
|
144
|
-
|
|
145
|
-
ELASTIC_ILM_POLICY = {
|
|
146
|
-
"policy": {
|
|
147
|
-
"phases": {
|
|
148
|
-
"hot": {"actions": {"rollover": {"max_size": "1gb", "max_age": "7d"}}},
|
|
149
|
-
"delete": {"min_age": "14d", "actions": {"delete": {}}},
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
ELASTIC_INDEX_TEMPLATE_NAME = "jaseci-logs-index-template"
|
|
155
|
-
|
|
156
|
-
ELASTIC_INDEX_TEMPLATE = {
|
|
157
|
-
"index_patterns": ["core*", "app*"],
|
|
158
|
-
"data_stream": {},
|
|
159
|
-
"composed_of": ["data-streams-mappings"],
|
|
160
|
-
"priority": 500,
|
|
161
|
-
"template": {"settings": {"index.lifecycle.name": ELASTIC_ILM_POLICY_NAME}},
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
ELASTIC_CONFIG = {
|
|
165
|
-
"enabled": bool(os.getenv("ELASTIC_HOST")),
|
|
166
|
-
"quiet": False,
|
|
167
|
-
"automated": True,
|
|
168
|
-
"url": (
|
|
169
|
-
f'https://{os.getenv("ELASTIC_HOST", "localhost")}'
|
|
170
|
-
f':{os.getenv("ELASTIC_PORT", "9200")}'
|
|
171
|
-
),
|
|
172
|
-
"auth": os.getenv("ELASTIC_AUTH"),
|
|
173
|
-
"common_index": f"{KUBE_NAMESPACE}-common",
|
|
174
|
-
"activity_index": f"{KUBE_NAMESPACE}-activity",
|
|
175
|
-
"core_log_index": "core",
|
|
176
|
-
"app_log_index": "app",
|
|
177
|
-
"ilm_policy_name": ELASTIC_ILM_POLICY_NAME,
|
|
178
|
-
"ilm_policy": ELASTIC_ILM_POLICY,
|
|
179
|
-
"index_template_name": ELASTIC_INDEX_TEMPLATE_NAME,
|
|
180
|
-
"index_template": ELASTIC_INDEX_TEMPLATE,
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
ELASTIC_MANIFEST = load_default_yaml("elastic")
|
|
184
|
-
|
|
185
|
-
###############################################################################################################
|
|
186
|
-
# ------------------------------------------------- STORAGE ------------------------------------------------- #
|
|
187
|
-
###############################################################################################################
|
|
188
|
-
|
|
189
|
-
STORE_CONFIG = {
|
|
190
|
-
"enabled": False,
|
|
191
|
-
"quiet": False,
|
|
192
|
-
"default": None,
|
|
193
|
-
"providers": {},
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
STORE_MANIFEST = {}
|
|
197
|
-
|
|
198
|
-
###############################################################################################################
|
|
199
|
-
# ------------------------------------------------ DATABASE ------------------------------------------------- #
|
|
200
|
-
###############################################################################################################
|
|
201
|
-
|
|
202
|
-
DB_REGEN_CONFIG = {
|
|
203
|
-
"enabled": os.environ.get("JSORC_DB_REGEN") == "true",
|
|
204
|
-
"host": os.environ.get("POSTGRES_HOST", "jaseci-db"),
|
|
205
|
-
"db": os.environ.get("DBNAME", "postgres"),
|
|
206
|
-
"user": os.environ.get("POSTGRES_USER"),
|
|
207
|
-
"password": os.environ.get("POSTGRES_PASSWORD"),
|
|
208
|
-
"port": os.getenv("POSTGRES_PORT", 5432),
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
DB_REGEN_MANIFEST = load_default_yaml("database")
|
jaseci/jsorc/jsorc_utils.py
DELETED
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-
import re
|
|
2
|
-
import os
|
|
3
|
-
from enum import Enum
|
|
4
|
-
from yaml import safe_load_all, YAMLError
|
|
5
|
-
from typing import TypeVar, Any, Union
|
|
6
|
-
|
|
7
|
-
from multiprocessing import Process, current_process
|
|
8
|
-
|
|
9
|
-
from jaseci.utils.utils import logger
|
|
10
|
-
|
|
11
|
-
#######################################################################################################
|
|
12
|
-
# HELPERS #
|
|
13
|
-
#######################################################################################################
|
|
14
|
-
|
|
15
|
-
T = TypeVar("T")
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
def convert_yaml_manifest(file):
|
|
19
|
-
manifest = {}
|
|
20
|
-
try:
|
|
21
|
-
for conf in safe_load_all(file):
|
|
22
|
-
kind = conf["kind"]
|
|
23
|
-
if not manifest.get(kind):
|
|
24
|
-
manifest[kind] = {}
|
|
25
|
-
manifest[kind].update({conf["metadata"]["name"]: conf})
|
|
26
|
-
except YAMLError as exc:
|
|
27
|
-
manifest = {"error": f"{exc}"}
|
|
28
|
-
|
|
29
|
-
return manifest
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
def load_default_yaml(file):
|
|
33
|
-
manifest = {}
|
|
34
|
-
with open(
|
|
35
|
-
f"{os.path.dirname(os.path.abspath(__file__))}/manifests/{file}.yaml", "r"
|
|
36
|
-
) as stream:
|
|
37
|
-
manifest = convert_yaml_manifest(stream)
|
|
38
|
-
|
|
39
|
-
return manifest
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
def get_service_map(*services):
|
|
43
|
-
service_map = {}
|
|
44
|
-
for service in services:
|
|
45
|
-
namespace = os.getenv(f"{service.upper()}_NAMESPACE")
|
|
46
|
-
if namespace:
|
|
47
|
-
service_map[service] = namespace
|
|
48
|
-
|
|
49
|
-
return service_map
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
#######################################################################################################
|
|
53
|
-
# RESOLVER #
|
|
54
|
-
#######################################################################################################
|
|
55
|
-
|
|
56
|
-
placeholder_full = re.compile(r"^\$j\{(.*?)\}$")
|
|
57
|
-
placeholder_partial = re.compile(r"\$j\{(.*?)\}")
|
|
58
|
-
placeholder_splitter = re.compile(r"\.?([^\.\[\"\]]+)(?:\[\"?([^\"\]]+)\"?\])?")
|
|
59
|
-
# original
|
|
60
|
-
# placeholder_splitter = re.compile(r"([^\.\[\"\]]+)(?:\[\"?([^\"\]]+)\"?\])?(?:\.([^\.\[\"\]]+))?")
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
def get_splitter(val: str):
|
|
64
|
-
matches = placeholder_splitter.findall(val)
|
|
65
|
-
_matches = []
|
|
66
|
-
for match in matches:
|
|
67
|
-
for m in match:
|
|
68
|
-
if m:
|
|
69
|
-
_matches.append(m)
|
|
70
|
-
return _matches
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
def get_value(source: dict, keys: list):
|
|
74
|
-
if keys:
|
|
75
|
-
key = keys.pop(0)
|
|
76
|
-
if key in source:
|
|
77
|
-
if keys:
|
|
78
|
-
if isinstance(source[key], dict):
|
|
79
|
-
return get_value(source[key], keys)
|
|
80
|
-
else:
|
|
81
|
-
return source[key]
|
|
82
|
-
return None
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
def placeholder_resolver(manifest, data: dict or list):
|
|
86
|
-
for k, d in list(data.items()) if isinstance(data, dict) else enumerate(data):
|
|
87
|
-
if isinstance(k, str):
|
|
88
|
-
pk = k
|
|
89
|
-
matcher = placeholder_full.search(k)
|
|
90
|
-
if matcher:
|
|
91
|
-
keys = get_splitter(matcher.group(1))
|
|
92
|
-
pk = get_value(manifest, keys)
|
|
93
|
-
else:
|
|
94
|
-
for matcher in placeholder_partial.findall(k):
|
|
95
|
-
keys = get_splitter(matcher)
|
|
96
|
-
pk = pk.replace("$j{" + matcher + "}", get_value(manifest, keys))
|
|
97
|
-
if pk != k:
|
|
98
|
-
d = data.pop(k)
|
|
99
|
-
k = pk
|
|
100
|
-
data[pk] = d
|
|
101
|
-
|
|
102
|
-
if isinstance(d, (dict, list)):
|
|
103
|
-
placeholder_resolver(manifest, d)
|
|
104
|
-
elif isinstance(d, str):
|
|
105
|
-
matcher = placeholder_full.search(d)
|
|
106
|
-
if matcher:
|
|
107
|
-
keys = get_splitter(matcher.group(1))
|
|
108
|
-
data[k] = get_value(manifest, keys)
|
|
109
|
-
else:
|
|
110
|
-
for matcher in placeholder_partial.findall(d):
|
|
111
|
-
keys = get_splitter(matcher)
|
|
112
|
-
data[k] = data[k].replace(
|
|
113
|
-
"$j{" + matcher + "}", get_value(manifest, keys)
|
|
114
|
-
)
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
#######################################################################################################
|
|
118
|
-
# ENUMS #
|
|
119
|
-
#######################################################################################################
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
class State(Enum):
|
|
123
|
-
RESTART = -2
|
|
124
|
-
FAILED = -1
|
|
125
|
-
NOT_STARTED = 0
|
|
126
|
-
STARTED = 1
|
|
127
|
-
RUNNING = 2
|
|
128
|
-
|
|
129
|
-
def is_ready(self):
|
|
130
|
-
return self == State.NOT_STARTED
|
|
131
|
-
|
|
132
|
-
def is_running(self):
|
|
133
|
-
return self == State.RUNNING
|
|
134
|
-
|
|
135
|
-
def has_failed(self):
|
|
136
|
-
return self == State.FAILED
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
class ManifestType(Enum):
|
|
140
|
-
SOURCE = -1
|
|
141
|
-
DEDICATED = 0
|
|
142
|
-
MANUAL = 1
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
#######################################################################################################
|
|
146
|
-
# COMMON #
|
|
147
|
-
#######################################################################################################
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
class CommonService:
|
|
151
|
-
###################################################
|
|
152
|
-
# PROPERTIES #
|
|
153
|
-
###################################################
|
|
154
|
-
|
|
155
|
-
# ------------------- DAEMON -------------------- #
|
|
156
|
-
|
|
157
|
-
_daemon = {}
|
|
158
|
-
|
|
159
|
-
@property
|
|
160
|
-
def daemon(self):
|
|
161
|
-
return __class__._daemon
|
|
162
|
-
|
|
163
|
-
###################################################
|
|
164
|
-
# INITIALIZER #
|
|
165
|
-
###################################################
|
|
166
|
-
|
|
167
|
-
def __init__(
|
|
168
|
-
self,
|
|
169
|
-
config: dict,
|
|
170
|
-
manifest: dict,
|
|
171
|
-
manifest_type: ManifestType = ManifestType.DEDICATED,
|
|
172
|
-
source: dict = {},
|
|
173
|
-
):
|
|
174
|
-
self.app = None
|
|
175
|
-
self.error = None
|
|
176
|
-
self.state = State.NOT_STARTED
|
|
177
|
-
self.source = source
|
|
178
|
-
|
|
179
|
-
# ------------------- CONFIG -------------------- #
|
|
180
|
-
|
|
181
|
-
self.config = config
|
|
182
|
-
self.enabled = config.pop("enabled", False)
|
|
183
|
-
self.quiet = config.pop("quiet", False)
|
|
184
|
-
self.automated = config.pop("automated", False)
|
|
185
|
-
|
|
186
|
-
# ------------------ MANIFEST ------------------- #
|
|
187
|
-
|
|
188
|
-
self.manifest = manifest
|
|
189
|
-
self.manifest_type = manifest_type
|
|
190
|
-
self.manifest_unsafe_paraphrase = manifest.pop("__UNSAFE_PARAPHRASE__", "")
|
|
191
|
-
|
|
192
|
-
self.start()
|
|
193
|
-
|
|
194
|
-
###################################################
|
|
195
|
-
# BUILDER #
|
|
196
|
-
###################################################
|
|
197
|
-
|
|
198
|
-
def start(self):
|
|
199
|
-
try:
|
|
200
|
-
if self.enabled and self.is_ready():
|
|
201
|
-
self.state = State.STARTED
|
|
202
|
-
self.run()
|
|
203
|
-
self.state = State.RUNNING
|
|
204
|
-
self.post_run()
|
|
205
|
-
except Exception as e:
|
|
206
|
-
if not (self.quiet):
|
|
207
|
-
logger.error(
|
|
208
|
-
f"Skipping {self.__class__.__name__} due to initialization "
|
|
209
|
-
f"failure!\n{e.__class__.__name__}: {e}"
|
|
210
|
-
)
|
|
211
|
-
self.failed(e)
|
|
212
|
-
|
|
213
|
-
return self
|
|
214
|
-
|
|
215
|
-
def run(self):
|
|
216
|
-
raise Exception(f"Not properly configured! Please override run method!")
|
|
217
|
-
|
|
218
|
-
def post_run(self):
|
|
219
|
-
pass
|
|
220
|
-
|
|
221
|
-
# ------------------- DAEMON -------------------- #
|
|
222
|
-
|
|
223
|
-
def spawn_daemon(self, **targets):
|
|
224
|
-
if current_process().name == "MainProcess":
|
|
225
|
-
for name, target in targets.items():
|
|
226
|
-
dae: Process = self.daemon.get(name)
|
|
227
|
-
if not dae or not dae.is_alive():
|
|
228
|
-
process = Process(target=target, daemon=True)
|
|
229
|
-
process.start()
|
|
230
|
-
self.daemon[name] = process
|
|
231
|
-
|
|
232
|
-
def terminate_daemon(self, *names):
|
|
233
|
-
for name in names:
|
|
234
|
-
dae: Process = self.daemon.pop(name, None)
|
|
235
|
-
if not (dae is None) and dae.is_alive():
|
|
236
|
-
logger.info(f"Terminating {name} ...")
|
|
237
|
-
dae.terminate()
|
|
238
|
-
|
|
239
|
-
###################################################
|
|
240
|
-
# COMMONS #
|
|
241
|
-
###################################################
|
|
242
|
-
|
|
243
|
-
def poke(self, cast: T = None, msg: str = None) -> Union[T, Any]:
|
|
244
|
-
if self.is_running():
|
|
245
|
-
return (
|
|
246
|
-
self if cast and cast.__name__ == self.__class__.__name__ else self.app
|
|
247
|
-
)
|
|
248
|
-
raise Exception(
|
|
249
|
-
msg or f"{self.__class__.__name__} is disabled or not yet configured!"
|
|
250
|
-
)
|
|
251
|
-
|
|
252
|
-
def is_ready(self):
|
|
253
|
-
return self.state.is_ready() and self.app is None
|
|
254
|
-
|
|
255
|
-
def is_running(self):
|
|
256
|
-
return self.state.is_running() and not (self.app is None)
|
|
257
|
-
|
|
258
|
-
def has_failed(self):
|
|
259
|
-
return self.state.has_failed()
|
|
260
|
-
|
|
261
|
-
def failed(self, error: Exception = None):
|
|
262
|
-
self.app = None
|
|
263
|
-
self.state = State.FAILED
|
|
264
|
-
self.error = error
|
|
265
|
-
|
|
266
|
-
@classmethod
|
|
267
|
-
def proxy(cls):
|
|
268
|
-
return cls({}, {})
|
|
269
|
-
|
|
270
|
-
# ---------------- PROXY EVENTS ----------------- #
|
|
271
|
-
|
|
272
|
-
def on_delete(self):
|
|
273
|
-
pass
|
|
274
|
-
|
|
275
|
-
# ------------------- EVENTS -------------------- #
|
|
276
|
-
|
|
277
|
-
def __del__(self):
|
|
278
|
-
self.on_delete()
|
|
279
|
-
|
|
280
|
-
def __getstate__(self):
|
|
281
|
-
return {}
|
|
282
|
-
|
|
283
|
-
def __setstate__(self, ignored):
|
|
284
|
-
# for build on pickle load
|
|
285
|
-
self.state = State.FAILED
|
|
286
|
-
del self
|
|
287
|
-
|
|
288
|
-
# ------------------- COMMON -------------------- #
|
|
289
|
-
|
|
290
|
-
def info(self):
|
|
291
|
-
return {
|
|
292
|
-
"enabled": self.enabled,
|
|
293
|
-
"automated": self.automated,
|
|
294
|
-
"quiet": self.quiet,
|
|
295
|
-
"state": self.state.name,
|
|
296
|
-
"config": self.config,
|
|
297
|
-
"error": str(self.error) if self.error else None,
|
|
298
|
-
}
|