dataops-sdk 0.3.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 dataops-sdk might be problematic. Click here for more details.
- dataops_sdk/__init__.py +84 -0
- dataops_sdk/constants.py +6 -0
- dataops_sdk/exceptions.py +31 -0
- dataops_sdk/runner/__init__.py +46 -0
- dataops_sdk/runner/datasource_factory.py +83 -0
- dataops_sdk/runner/schemas/nacos/__init__.py +5 -0
- dataops_sdk/runner/schemas/nacos/config.py +40 -0
- dataops_sdk/runner/schemas/nacos/constants.py +235 -0
- dataops_sdk/runner/schemas/nacos/instance.py +103 -0
- dataops_sdk/runner/schemas/nacos/nacos_exception.py +44 -0
- dataops_sdk/runner/schemas/nacos/naming_param.py +62 -0
- dataops_sdk/runner/schemas/nacos/naming_request.py +84 -0
- dataops_sdk/runner/schemas/nacos/naming_response.py +50 -0
- dataops_sdk/runner/schemas/nacos/preserved_metadata_key.py +10 -0
- dataops_sdk/runner/schemas/nacos/service.py +119 -0
- dataops_sdk/runner/utils/__init__.py +42 -0
- dataops_sdk/runner/utils/common.py +209 -0
- dataops_sdk/runner/utils/dbConn_base.py +256 -0
- dataops_sdk/runner/utils/dbConn_sync.py +485 -0
- dataops_sdk/runner/utils/duckdb_manager.py +203 -0
- dataops_sdk/runner/utils/file_transfer_base.py +307 -0
- dataops_sdk/runner/utils/ftp_file_transfer.py +242 -0
- dataops_sdk/runner/utils/log.py +50 -0
- dataops_sdk/runner/utils/nacos.py +96 -0
- dataops_sdk/runner/utils/neo4j_sync.py +236 -0
- dataops_sdk/runner/utils/queue_base.py +224 -0
- dataops_sdk/runner/utils/queue_kafka.py +150 -0
- dataops_sdk/runner/utils/sftp_file_transfer.py +243 -0
- dataops_sdk/schemas/__init__.py +32 -0
- dataops_sdk/schemas/alarm.py +38 -0
- dataops_sdk/schemas/api.py +37 -0
- dataops_sdk/schemas/data_table.py +437 -0
- dataops_sdk/schemas/datasource.py +26 -0
- dataops_sdk/schemas/dict_.py +13 -0
- dataops_sdk/schemas/enums.py +120 -0
- dataops_sdk/schemas/group.py +40 -0
- dataops_sdk/schemas/hazard.py +151 -0
- dataops_sdk/schemas/meta.py +175 -0
- dataops_sdk/schemas/query.py +175 -0
- dataops_sdk/schemas/report.py +22 -0
- dataops_sdk/schemas/skill.py +70 -0
- dataops_sdk/schemas/table.py +65 -0
- dataops_sdk/schemas/user.py +52 -0
- dataops_sdk/schemas/widget.py +651 -0
- dataops_sdk/schemas/workflow.py +63 -0
- dataops_sdk/services/__init__.py +110 -0
- dataops_sdk/services/alarm.py +324 -0
- dataops_sdk/services/api.py +28 -0
- dataops_sdk/services/auth.py +120 -0
- dataops_sdk/services/data_table.py +485 -0
- dataops_sdk/services/dataset.py +127 -0
- dataops_sdk/services/datasource.py +57 -0
- dataops_sdk/services/dict_.py +69 -0
- dataops_sdk/services/hazard.py +260 -0
- dataops_sdk/services/meta.py +523 -0
- dataops_sdk/services/metrics.py +42 -0
- dataops_sdk/services/ref.py +66 -0
- dataops_sdk/services/report.py +36 -0
- dataops_sdk/services/skill.py +276 -0
- dataops_sdk/services/table.py +340 -0
- dataops_sdk/services/widget.py +143 -0
- dataops_sdk/services/workflow.py +102 -0
- dataops_sdk/session.py +292 -0
- dataops_sdk/tiptap/__init__.py +30 -0
- dataops_sdk/tiptap/builder.py +75 -0
- dataops_sdk/tiptap/constants.py +133 -0
- dataops_sdk/tiptap/markdown_parser.py +294 -0
- dataops_sdk/tiptap/models.py +43 -0
- dataops_sdk/tiptap/parse_utils.py +889 -0
- dataops_sdk/tiptap/render_utils.py +846 -0
- dataops_sdk/tiptap/renderers.py +51 -0
- dataops_sdk/tiptap/tool.py +629 -0
- dataops_sdk/utils/__init__.py +15 -0
- dataops_sdk/utils/common.py +211 -0
- dataops_sdk/utils/utils.py +120 -0
- dataops_sdk-0.3.0.dist-info/METADATA +25 -0
- dataops_sdk-0.3.0.dist-info/RECORD +79 -0
- dataops_sdk-0.3.0.dist-info/WHEEL +5 -0
- dataops_sdk-0.3.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
from dataops_sdk.schemas import DataDict, Meta, MetaRelease, MetaType, SqlQueryParam
|
|
2
|
+
from dataops_sdk.services.meta import (
|
|
3
|
+
release_list_get_by_code,
|
|
4
|
+
release_list_get_by_name,
|
|
5
|
+
release_list_list,
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
"service_list_dicts",
|
|
10
|
+
"service_get_dict_detail_by_name",
|
|
11
|
+
"service_get_dict_detail_by_code",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def service_list_dicts(datasource: str) -> list[MetaRelease]:
|
|
16
|
+
"""搜索数据源中的字典.
|
|
17
|
+
|
|
18
|
+
Args:
|
|
19
|
+
datasource: 数据源名称
|
|
20
|
+
|
|
21
|
+
Returns:
|
|
22
|
+
MetaRelease 对象列表
|
|
23
|
+
|
|
24
|
+
Raises:
|
|
25
|
+
DataOpsError: API 请求失败时
|
|
26
|
+
AuthenticationError: 未认证时
|
|
27
|
+
"""
|
|
28
|
+
headers = {"x-sub-system": datasource}
|
|
29
|
+
filters = (SqlQueryParam().add_eq("sub_system", datasource, "mrl"),)
|
|
30
|
+
return release_list_list(MetaType.DICT, filters=filters, headers=headers)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def service_get_dict_detail_by_name(datasource: str, name: str) -> Meta[DataDict]:
|
|
34
|
+
"""指定数据源字典详情.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
datasource: 数据源名称
|
|
38
|
+
name: 字典名称
|
|
39
|
+
|
|
40
|
+
Returns:
|
|
41
|
+
数据源 DDL 模型
|
|
42
|
+
|
|
43
|
+
Raises:
|
|
44
|
+
ValueError: 无效类型
|
|
45
|
+
NotFoundError: 数据源不存在
|
|
46
|
+
DataOpsError: API 请求失败
|
|
47
|
+
AuthenticationError: 未认证
|
|
48
|
+
"""
|
|
49
|
+
meta = release_list_get_by_name(MetaType.DICT, name, _class=DataDict, datasource=datasource)
|
|
50
|
+
return meta
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def service_get_dict_detail_by_code(code: str) -> Meta[DataDict]:
|
|
54
|
+
"""指定数据源字典详情.
|
|
55
|
+
|
|
56
|
+
Args:
|
|
57
|
+
code: 字典编码
|
|
58
|
+
|
|
59
|
+
Returns:
|
|
60
|
+
数据源 DDL 模型
|
|
61
|
+
|
|
62
|
+
Raises:
|
|
63
|
+
ValueError: 无效类型
|
|
64
|
+
NotFoundError: 数据源不存在
|
|
65
|
+
DataOpsError: API 请求失败
|
|
66
|
+
AuthenticationError: 未认证
|
|
67
|
+
"""
|
|
68
|
+
meta = release_list_get_by_code(MetaType.DICT, code, _class=DataDict)
|
|
69
|
+
return meta
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
"""隐患服务模块.
|
|
2
|
+
|
|
3
|
+
提供隐患任务触发、日志查询与记录管理能力,覆盖后端 /hazard/task/* 与 /hazard/record/* 接口。
|
|
4
|
+
|
|
5
|
+
- 服务层函数 (service_*):纯 Python 接口,返回原始数据
|
|
6
|
+
- CLI 命令:基于服务层的薄包装,负责格式化输出
|
|
7
|
+
|
|
8
|
+
后端协议约定(FMIND-base64 解码后):
|
|
9
|
+
|
|
10
|
+
- POST /hazard/task/trigger/{code} body: {triggerTime?, sync?}
|
|
11
|
+
- POST /hazard/task/logs/{taskCode} body: {pageParam?, count?}
|
|
12
|
+
- POST /hazard/task/log/records/{id} body: {pageParam?, count?}
|
|
13
|
+
- POST /hazard/record/list body: {pageParam?, queryParam?, count?}
|
|
14
|
+
- POST /hazard/record/his/list body: {pageParam?, queryParam?, count?}
|
|
15
|
+
- POST /hazard/record/dispatch/callback body: {cuid, orderNo, dispatchStatus}
|
|
16
|
+
- POST /hazard/record/his/clear body: {cuid, clearNotifyStatus?}
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
from collections.abc import Mapping
|
|
20
|
+
from datetime import datetime
|
|
21
|
+
from typing import Any
|
|
22
|
+
|
|
23
|
+
from pydantic import JsonValue
|
|
24
|
+
from pydantic_core import to_json
|
|
25
|
+
|
|
26
|
+
from dataops_sdk.exceptions import AuthenticationError, DataOpsError
|
|
27
|
+
from dataops_sdk.schemas.query import PageParam, SqlQueryParam
|
|
28
|
+
from dataops_sdk.session import get_session
|
|
29
|
+
from dataops_sdk.utils import encrypt_body
|
|
30
|
+
|
|
31
|
+
__all__ = [
|
|
32
|
+
"service_clear_hazard_history_records",
|
|
33
|
+
"service_dispatch_hazard_callback",
|
|
34
|
+
"service_get_hazard_task_log_records",
|
|
35
|
+
"service_get_hazard_task_logs",
|
|
36
|
+
"service_list_hazard_history_records",
|
|
37
|
+
"service_list_hazard_records",
|
|
38
|
+
"service_trigger_hazard_task",
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _post_hazard(url: str, body: Mapping[str, JsonValue] | None = None) -> Any:
|
|
43
|
+
"""隐患模块 POST 请求,返回 ``resp_body['data']``.
|
|
44
|
+
|
|
45
|
+
Raises:
|
|
46
|
+
DataOpsError: API 返回错误时
|
|
47
|
+
AuthenticationError: 未认证或认证失败时
|
|
48
|
+
"""
|
|
49
|
+
payload = dict(body) if body else {}
|
|
50
|
+
try:
|
|
51
|
+
with get_session() as session:
|
|
52
|
+
resp = session.post(url, content=to_json(encrypt_body(payload)))
|
|
53
|
+
resp_body = resp.json()
|
|
54
|
+
if resp.status_code == 401:
|
|
55
|
+
raise AuthenticationError("认证失败,请先登录")
|
|
56
|
+
if resp.status_code != 200:
|
|
57
|
+
raise DataOpsError(
|
|
58
|
+
resp_body.get("msg", f"HTTP {resp.status_code}"), resp.status_code
|
|
59
|
+
)
|
|
60
|
+
except SystemExit as e:
|
|
61
|
+
raise AuthenticationError("认证失败,请先登录") from e
|
|
62
|
+
return resp_body.get("data")
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _build_list_body(
|
|
66
|
+
page_param: PageParam | None,
|
|
67
|
+
query_param: SqlQueryParam | None,
|
|
68
|
+
*,
|
|
69
|
+
count: bool,
|
|
70
|
+
) -> dict:
|
|
71
|
+
"""构造 list / his-list / logs 接口的标准 body."""
|
|
72
|
+
body: dict = {"count": count}
|
|
73
|
+
if page_param is not None:
|
|
74
|
+
body["pageParam"] = page_param
|
|
75
|
+
if query_param is not None:
|
|
76
|
+
body["queryParam"] = query_param
|
|
77
|
+
return body
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def service_trigger_hazard_task(
|
|
81
|
+
code: str,
|
|
82
|
+
*,
|
|
83
|
+
trigger_time: datetime | None = None,
|
|
84
|
+
sync: bool = False,
|
|
85
|
+
) -> bool:
|
|
86
|
+
"""触发指定编码的隐患任务.
|
|
87
|
+
|
|
88
|
+
Args:
|
|
89
|
+
code: 隐患任务编码.
|
|
90
|
+
trigger_time: 可选触发时间;为空时立即触发;提供后定时触发.
|
|
91
|
+
sync: 是否同步执行(默认异步,通过 Job 模板).
|
|
92
|
+
|
|
93
|
+
Returns:
|
|
94
|
+
后端是否接受触发(业务成功/失败需根据任务日志判断).
|
|
95
|
+
|
|
96
|
+
Raises:
|
|
97
|
+
DataOpsError: API 请求失败时
|
|
98
|
+
AuthenticationError: 未认证或认证失败时
|
|
99
|
+
"""
|
|
100
|
+
body: dict = {}
|
|
101
|
+
if trigger_time is not None:
|
|
102
|
+
body["triggerTime"] = trigger_time.isoformat()
|
|
103
|
+
if sync:
|
|
104
|
+
body["sync"] = True
|
|
105
|
+
return bool(_post_hazard(f"/hazard/task/trigger/{code}", body))
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def service_get_hazard_task_logs(
|
|
109
|
+
task_code: str,
|
|
110
|
+
page_param: PageParam | None = None,
|
|
111
|
+
*,
|
|
112
|
+
count: bool = False,
|
|
113
|
+
) -> list[dict] | int:
|
|
114
|
+
"""获取隐患任务日志列表或总数.
|
|
115
|
+
|
|
116
|
+
后端固定按 ``task_code`` 与 ``START_TIME DESC`` 过滤排序,调用方只能指定分页.
|
|
117
|
+
|
|
118
|
+
Args:
|
|
119
|
+
task_code: 隐患任务编码.
|
|
120
|
+
page_param: 分页参数(默认 ``PageParam(0, 20)``).
|
|
121
|
+
count: 为 True 时返回记录数,否则返回记录列表.
|
|
122
|
+
|
|
123
|
+
Returns:
|
|
124
|
+
``count=True`` 时返回 ``int``,否则返回 ``list[dict]``.
|
|
125
|
+
|
|
126
|
+
Raises:
|
|
127
|
+
DataOpsError: API 请求失败时
|
|
128
|
+
AuthenticationError: 未认证或认证失败时
|
|
129
|
+
"""
|
|
130
|
+
body = _build_list_body(page_param, None, count=count)
|
|
131
|
+
data = _post_hazard(f"/hazard/task/logs/{task_code}", body)
|
|
132
|
+
return data if count else (data or [])
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def service_get_hazard_task_log_records(
|
|
136
|
+
task_id: str,
|
|
137
|
+
page_param: PageParam | None = None,
|
|
138
|
+
*,
|
|
139
|
+
count: bool = False,
|
|
140
|
+
) -> list[dict] | int:
|
|
141
|
+
"""获取隐患任务结果记录或总数.
|
|
142
|
+
|
|
143
|
+
后端固定按 ``task_id`` 与 ``CREATE_TIME DESC`` 过滤排序.
|
|
144
|
+
|
|
145
|
+
Args:
|
|
146
|
+
task_id: 隐患任务实例 ID.
|
|
147
|
+
page_param: 分页参数.
|
|
148
|
+
count: 为 True 时返回记录数.
|
|
149
|
+
|
|
150
|
+
Returns:
|
|
151
|
+
``count=True`` 时返回 ``int``,否则返回 ``list[dict]``.
|
|
152
|
+
|
|
153
|
+
Raises:
|
|
154
|
+
DataOpsError: API 请求失败时
|
|
155
|
+
AuthenticationError: 未认证或认证失败时
|
|
156
|
+
"""
|
|
157
|
+
body = _build_list_body(page_param, None, count=count)
|
|
158
|
+
data = _post_hazard(f"/hazard/task/log/records/{task_id}", body)
|
|
159
|
+
return data if count else (data or [])
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def service_list_hazard_records(
|
|
163
|
+
page_param: PageParam | None = None,
|
|
164
|
+
query_param: SqlQueryParam | None = None,
|
|
165
|
+
*,
|
|
166
|
+
count: bool = False,
|
|
167
|
+
) -> list[dict] | int:
|
|
168
|
+
"""分页查询活动隐患记录.
|
|
169
|
+
|
|
170
|
+
Args:
|
|
171
|
+
page_param: 分页参数.
|
|
172
|
+
query_param: SQL 查询条件(如按 status、hazardLevel 等过滤).
|
|
173
|
+
count: 为 True 时返回记录数.
|
|
174
|
+
|
|
175
|
+
Returns:
|
|
176
|
+
``count=True`` 时返回 ``int``,否则返回 ``list[dict]``.
|
|
177
|
+
|
|
178
|
+
Raises:
|
|
179
|
+
DataOpsError: API 请求失败时
|
|
180
|
+
AuthenticationError: 未认证或认证失败时
|
|
181
|
+
"""
|
|
182
|
+
body = _build_list_body(page_param, query_param, count=count)
|
|
183
|
+
data = _post_hazard("/hazard/record/list", body)
|
|
184
|
+
return data if count else (data or [])
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def service_list_hazard_history_records(
|
|
188
|
+
page_param: PageParam | None = None,
|
|
189
|
+
query_param: SqlQueryParam | None = None,
|
|
190
|
+
*,
|
|
191
|
+
count: bool = False,
|
|
192
|
+
) -> list[dict] | int:
|
|
193
|
+
"""分页查询归档隐患记录.
|
|
194
|
+
|
|
195
|
+
Args:
|
|
196
|
+
page_param: 分页参数.
|
|
197
|
+
query_param: SQL 查询条件.
|
|
198
|
+
count: 为 True 时返回记录数.
|
|
199
|
+
|
|
200
|
+
Returns:
|
|
201
|
+
``count=True`` 时返回 ``int``,否则返回 ``list[dict]``.
|
|
202
|
+
|
|
203
|
+
Raises:
|
|
204
|
+
DataOpsError: API 请求失败时
|
|
205
|
+
AuthenticationError: 未认证或认证失败时
|
|
206
|
+
"""
|
|
207
|
+
body = _build_list_body(page_param, query_param, count=count)
|
|
208
|
+
data = _post_hazard("/hazard/record/his/list", body)
|
|
209
|
+
return data if count else (data or [])
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def service_clear_hazard_history_records(
|
|
213
|
+
cuid: str,
|
|
214
|
+
*,
|
|
215
|
+
clear_notify_status: int | None = None,
|
|
216
|
+
) -> bool:
|
|
217
|
+
"""清理指定归档隐患记录.
|
|
218
|
+
|
|
219
|
+
Args:
|
|
220
|
+
cuid: 隐患记录的 meta ID.
|
|
221
|
+
clear_notify_status: 可选清除通知状态码.
|
|
222
|
+
|
|
223
|
+
Returns:
|
|
224
|
+
后端是否成功清除.
|
|
225
|
+
|
|
226
|
+
Raises:
|
|
227
|
+
DataOpsError: API 请求失败时
|
|
228
|
+
AuthenticationError: 未认证或认证失败时
|
|
229
|
+
"""
|
|
230
|
+
body: dict = {"cuid": cuid}
|
|
231
|
+
if clear_notify_status is not None:
|
|
232
|
+
body["clearNotifyStatus"] = clear_notify_status
|
|
233
|
+
return bool(_post_hazard("/hazard/record/his/clear", body))
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
def service_dispatch_hazard_callback(
|
|
237
|
+
cuid: str,
|
|
238
|
+
order_no: str,
|
|
239
|
+
dispatch_status: int,
|
|
240
|
+
) -> bool:
|
|
241
|
+
"""隐患派单结果回调(外部工单系统回写派遣状态).
|
|
242
|
+
|
|
243
|
+
Args:
|
|
244
|
+
cuid: 隐患记录的 meta ID.
|
|
245
|
+
order_no: 外部工单号.
|
|
246
|
+
dispatch_status: 派遣状态码(具体枚举由业务约定,如 1=成功 / 2=失败).
|
|
247
|
+
|
|
248
|
+
Returns:
|
|
249
|
+
后端是否成功写入回调.
|
|
250
|
+
|
|
251
|
+
Raises:
|
|
252
|
+
DataOpsError: API 请求失败(如 cuid 不存在)时
|
|
253
|
+
AuthenticationError: 未认证或认证失败时
|
|
254
|
+
"""
|
|
255
|
+
body = {
|
|
256
|
+
"cuid": cuid,
|
|
257
|
+
"orderNo": order_no,
|
|
258
|
+
"dispatchStatus": dispatch_status,
|
|
259
|
+
}
|
|
260
|
+
return bool(_post_hazard("/hazard/record/dispatch/callback", body))
|