intellif-aihub 0.1.2__py3-none-any.whl → 0.1.3__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 intellif-aihub might be problematic. Click here for more details.
- aihub/__init__.py +1 -1
- aihub/client.py +91 -87
- aihub/exceptions.py +18 -18
- aihub/models/artifact.py +137 -137
- aihub/models/common.py +13 -13
- aihub/models/dataset_management.py +99 -99
- aihub/models/document_center.py +28 -28
- aihub/models/labelfree.py +31 -31
- aihub/models/model_training_platform.py +230 -0
- aihub/models/tag_resource_management.py +50 -0
- aihub/models/task_center.py +117 -117
- aihub/models/user_system.py +262 -0
- aihub/services/artifact.py +353 -332
- aihub/services/dataset_management.py +240 -240
- aihub/services/document_center.py +43 -43
- aihub/services/labelfree.py +44 -44
- aihub/services/model_training_platform.py +135 -0
- aihub/services/quota_schedule_management.py +18 -18
- aihub/services/reporter.py +20 -20
- aihub/services/tag_resource_management.py +55 -0
- aihub/services/task_center.py +190 -190
- aihub/services/user_system.py +339 -0
- aihub/utils/download.py +69 -69
- aihub/utils/http.py +13 -13
- aihub/utils/s3.py +77 -77
- {intellif_aihub-0.1.2.dist-info → intellif_aihub-0.1.3.dist-info}/METADATA +2 -2
- intellif_aihub-0.1.3.dist-info/RECORD +34 -0
- {intellif_aihub-0.1.2.dist-info → intellif_aihub-0.1.3.dist-info}/licenses/LICENSE +200 -200
- aihub/models/tag_management.py +0 -21
- aihub/models/user.py +0 -46
- aihub/services/tag_management.py +0 -35
- aihub/services/user.py +0 -47
- intellif_aihub-0.1.2.dist-info/RECORD +0 -32
- {intellif_aihub-0.1.2.dist-info → intellif_aihub-0.1.3.dist-info}/WHEEL +0 -0
- {intellif_aihub-0.1.2.dist-info → intellif_aihub-0.1.3.dist-info}/top_level.txt +0 -0
aihub/services/artifact.py
CHANGED
|
@@ -1,332 +1,353 @@
|
|
|
1
|
-
# !/usr/bin/env python
|
|
2
|
-
# -*-coding:utf-8 -*-
|
|
3
|
-
"""制品管理服务模块
|
|
4
|
-
|
|
5
|
-
该模块提供了制品管理相关的功能,包括创建制品、上传制品、获取制品信息等。
|
|
6
|
-
制品可以是数据集、模型、指标、日志、检查点、图像、预测结果等类型。
|
|
7
|
-
"""
|
|
8
|
-
from __future__ import annotations
|
|
9
|
-
|
|
10
|
-
import os
|
|
11
|
-
from pathlib import Path
|
|
12
|
-
from typing import List, Optional
|
|
13
|
-
|
|
14
|
-
import httpx
|
|
15
|
-
import minio
|
|
16
|
-
from loguru import logger
|
|
17
|
-
|
|
18
|
-
from ..exceptions import APIError
|
|
19
|
-
from ..models.artifact import (
|
|
20
|
-
CreateArtifactsReq,
|
|
21
|
-
CreateArtifactsResponseData,
|
|
22
|
-
ArtifactResp,
|
|
23
|
-
InfinityPageSize,
|
|
24
|
-
ArtifactRespData,
|
|
25
|
-
ArtifactType,
|
|
26
|
-
StsResp,
|
|
27
|
-
)
|
|
28
|
-
from ..models.common import APIWrapper
|
|
29
|
-
from ..utils.s3 import S3_path_to_info, upload_dir_to_s3, download_dir_from_s3
|
|
30
|
-
|
|
31
|
-
# 制品管理API的基础路径
|
|
32
|
-
_Base = "/artifact-management/api/v1"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
class ArtifactService:
|
|
36
|
-
"""制品管理服务类,该类提供了制品管理相关的功能,包括创建制品、上传制品、获取制品信息等。
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
Methods:
|
|
40
|
-
get_by_run_id: 使用run_id获取制品
|
|
41
|
-
create_artifact: 创建一个制品文件
|
|
42
|
-
create_artifacts: 从目录创建一个制品
|
|
43
|
-
download_artifacts: 下载制品
|
|
44
|
-
|
|
45
|
-
"""
|
|
46
|
-
|
|
47
|
-
def __init__(self, http: httpx.Client):
|
|
48
|
-
"""初始化制品管理服务
|
|
49
|
-
|
|
50
|
-
Args:
|
|
51
|
-
http: HTTP客户端实例
|
|
52
|
-
"""
|
|
53
|
-
self._http = http
|
|
54
|
-
self._Artifact = _Artifact(http)
|
|
55
|
-
self.sts =
|
|
56
|
-
self.s3_client =
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
"""
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
self.
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
Args:
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
Raises:
|
|
299
|
-
APIError: 当API调用失败时抛出
|
|
300
|
-
"""
|
|
301
|
-
resp = self._http.
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
1
|
+
# !/usr/bin/env python
|
|
2
|
+
# -*-coding:utf-8 -*-
|
|
3
|
+
"""制品管理服务模块
|
|
4
|
+
|
|
5
|
+
该模块提供了制品管理相关的功能,包括创建制品、上传制品、获取制品信息等。
|
|
6
|
+
制品可以是数据集、模型、指标、日志、检查点、图像、预测结果等类型。
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from typing import List, Optional
|
|
13
|
+
|
|
14
|
+
import httpx
|
|
15
|
+
import minio
|
|
16
|
+
from loguru import logger
|
|
17
|
+
|
|
18
|
+
from ..exceptions import APIError
|
|
19
|
+
from ..models.artifact import (
|
|
20
|
+
CreateArtifactsReq,
|
|
21
|
+
CreateArtifactsResponseData,
|
|
22
|
+
ArtifactResp,
|
|
23
|
+
InfinityPageSize,
|
|
24
|
+
ArtifactRespData,
|
|
25
|
+
ArtifactType,
|
|
26
|
+
StsResp,
|
|
27
|
+
)
|
|
28
|
+
from ..models.common import APIWrapper
|
|
29
|
+
from ..utils.s3 import S3_path_to_info, upload_dir_to_s3, download_dir_from_s3
|
|
30
|
+
|
|
31
|
+
# 制品管理API的基础路径
|
|
32
|
+
_Base = "/artifact-management/api/v1"
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class ArtifactService:
|
|
36
|
+
"""制品管理服务类,该类提供了制品管理相关的功能,包括创建制品、上传制品、获取制品信息等。
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
Methods:
|
|
40
|
+
get_by_run_id: 使用run_id获取制品
|
|
41
|
+
create_artifact: 创建一个制品文件
|
|
42
|
+
create_artifacts: 从目录创建一个制品
|
|
43
|
+
download_artifacts: 下载制品
|
|
44
|
+
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
def __init__(self, http: httpx.Client):
|
|
48
|
+
"""初始化制品管理服务
|
|
49
|
+
|
|
50
|
+
Args:
|
|
51
|
+
http: HTTP客户端实例
|
|
52
|
+
"""
|
|
53
|
+
self._http = http
|
|
54
|
+
self._Artifact = _Artifact(http)
|
|
55
|
+
self.sts = None
|
|
56
|
+
self.s3_client = None
|
|
57
|
+
|
|
58
|
+
@property
|
|
59
|
+
def _artifact(self) -> _Artifact:
|
|
60
|
+
"""获取内部制品管理实例
|
|
61
|
+
|
|
62
|
+
Returns:
|
|
63
|
+
_Artifact: 内部制品管理实例
|
|
64
|
+
"""
|
|
65
|
+
return self._Artifact
|
|
66
|
+
|
|
67
|
+
def _create(self, payload: CreateArtifactsReq) -> CreateArtifactsResponseData:
|
|
68
|
+
"""创建制品(内部方法)
|
|
69
|
+
|
|
70
|
+
Args:
|
|
71
|
+
payload: 创建制品请求参数
|
|
72
|
+
|
|
73
|
+
Returns:
|
|
74
|
+
CreateArtifactsResponseData: 创建制品响应数据
|
|
75
|
+
"""
|
|
76
|
+
return self._artifact.create(payload)
|
|
77
|
+
|
|
78
|
+
def _upload_done(self, artifact_id: int) -> None:
|
|
79
|
+
"""标记制品上传完成
|
|
80
|
+
|
|
81
|
+
Args:
|
|
82
|
+
artifact_id: 制品ID
|
|
83
|
+
"""
|
|
84
|
+
return self._artifact.upload_done(artifact_id)
|
|
85
|
+
|
|
86
|
+
def _get_sts(self) -> StsResp:
|
|
87
|
+
"""获取STS临时凭证
|
|
88
|
+
|
|
89
|
+
Returns:
|
|
90
|
+
StsResp: STS临时凭证信息
|
|
91
|
+
"""
|
|
92
|
+
return self._artifact.get_sts()
|
|
93
|
+
|
|
94
|
+
def get_by_run_id(
|
|
95
|
+
self, run_id: str, artifact_path: Optional[str] = None
|
|
96
|
+
) -> List[ArtifactResp]:
|
|
97
|
+
"""根据运行ID获取制品列表
|
|
98
|
+
|
|
99
|
+
Args:
|
|
100
|
+
run_id: 运行ID
|
|
101
|
+
artifact_path: 制品路径,如果指定则只返回匹配的制品
|
|
102
|
+
|
|
103
|
+
Returns:
|
|
104
|
+
List[ArtifactResp]: 制品列表
|
|
105
|
+
|
|
106
|
+
Raises:
|
|
107
|
+
APIError: 当API调用失败时抛出
|
|
108
|
+
"""
|
|
109
|
+
return self._artifact.get_by_run_id(run_id, artifact_path)
|
|
110
|
+
|
|
111
|
+
def create_artifact(
|
|
112
|
+
self,
|
|
113
|
+
local_path: str,
|
|
114
|
+
artifact_path: Optional[str] = None,
|
|
115
|
+
run_id: Optional[str] = None,
|
|
116
|
+
artifact_type: ArtifactType = ArtifactType.other,
|
|
117
|
+
) -> None:
|
|
118
|
+
"""创建单个文件制品并上传
|
|
119
|
+
|
|
120
|
+
该方法用于将本地文件上传为制品。过程包括:
|
|
121
|
+
1. 获取STS临时凭证
|
|
122
|
+
2. 创建S3客户端
|
|
123
|
+
3. 检查本地文件是否存在
|
|
124
|
+
4. 创建制品记录
|
|
125
|
+
5. 上传文件到S3
|
|
126
|
+
6. 标记上传完成
|
|
127
|
+
|
|
128
|
+
Args:
|
|
129
|
+
local_path (str): 本地文件路径
|
|
130
|
+
artifact_path (str): 制品路径,如果为None则使用本地文件名
|
|
131
|
+
run_id (str): 运行ID,关联制品与特定运行
|
|
132
|
+
artifact_type (ArtifactType): 制品类型,默认为other
|
|
133
|
+
|
|
134
|
+
Raises:
|
|
135
|
+
ValueError: 当本地文件不存在时抛出
|
|
136
|
+
APIError: 当API调用失败时抛出
|
|
137
|
+
"""
|
|
138
|
+
logger.info(f"log artifact: {artifact_path},local path: {local_path} ")
|
|
139
|
+
if self.s3_client is None:
|
|
140
|
+
self.sts = self._get_sts()
|
|
141
|
+
self.s3_client = minio.Minio(
|
|
142
|
+
self.sts.endpoint,
|
|
143
|
+
access_key=self.sts.access_key_id,
|
|
144
|
+
secret_key=self.sts.secret_access_key,
|
|
145
|
+
session_token=self.sts.session_token,
|
|
146
|
+
secure=False,
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
# 检查文件是否存在
|
|
150
|
+
if not os.path.exists(local_path):
|
|
151
|
+
raise ValueError(f"File {local_path} does not exist")
|
|
152
|
+
req = CreateArtifactsReq(
|
|
153
|
+
entity_id=run_id,
|
|
154
|
+
entity_type=artifact_type,
|
|
155
|
+
src_path=artifact_path,
|
|
156
|
+
is_dir=False,
|
|
157
|
+
)
|
|
158
|
+
resp = self._create(req)
|
|
159
|
+
bucket, object_name = S3_path_to_info(resp.s3_path)
|
|
160
|
+
|
|
161
|
+
self.s3_client.fput_object(bucket, object_name, local_path)
|
|
162
|
+
self._upload_done(resp.id)
|
|
163
|
+
logger.info(f"log artifact done: {artifact_path}")
|
|
164
|
+
return
|
|
165
|
+
|
|
166
|
+
def create_artifacts(
|
|
167
|
+
self,
|
|
168
|
+
local_dir: str,
|
|
169
|
+
artifact_path: Optional[str] = None,
|
|
170
|
+
run_id: Optional[str] = None,
|
|
171
|
+
artifact_type: ArtifactType = ArtifactType.other,
|
|
172
|
+
) -> None:
|
|
173
|
+
"""创建目录制品并上传
|
|
174
|
+
|
|
175
|
+
该方法用于将本地目录上传为制品。过程包括:
|
|
176
|
+
1. 获取STS临时凭证
|
|
177
|
+
2. 创建S3客户端
|
|
178
|
+
3. 检查本地目录是否存在
|
|
179
|
+
4. 创建制品记录
|
|
180
|
+
5. 上传目录内容到S3
|
|
181
|
+
6. 标记上传完成
|
|
182
|
+
|
|
183
|
+
Args:
|
|
184
|
+
local_dir (str): 本地目录路径
|
|
185
|
+
artifact_path (str): 制品路径,如果为None则使用本地目录名
|
|
186
|
+
run_id (str): 运行ID,关联制品与特定运行
|
|
187
|
+
artifact_type (ArtifactType): 制品类型,默认为other
|
|
188
|
+
|
|
189
|
+
Raises:
|
|
190
|
+
ValueError: 当本地目录不存在时抛出
|
|
191
|
+
APIError: 当API调用失败时抛出
|
|
192
|
+
"""
|
|
193
|
+
if self.s3_client is None:
|
|
194
|
+
self.sts = self._get_sts()
|
|
195
|
+
self.s3_client = minio.Minio(
|
|
196
|
+
self.sts.endpoint,
|
|
197
|
+
access_key=self.sts.access_key_id,
|
|
198
|
+
secret_key=self.sts.secret_access_key,
|
|
199
|
+
session_token=self.sts.session_token,
|
|
200
|
+
secure=False,
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
logger.info(f"log artifact: {artifact_path},local path: {local_dir} ")
|
|
204
|
+
if not os.path.exists(local_dir):
|
|
205
|
+
raise ValueError(f"File {local_dir} does not exist")
|
|
206
|
+
req = CreateArtifactsReq(
|
|
207
|
+
entity_id=run_id,
|
|
208
|
+
entity_type=artifact_type,
|
|
209
|
+
src_path=artifact_path,
|
|
210
|
+
is_dir=True,
|
|
211
|
+
)
|
|
212
|
+
resp = self._create(req)
|
|
213
|
+
bucket, object_name = S3_path_to_info(resp.s3_path)
|
|
214
|
+
upload_dir_to_s3(self.s3_client, local_dir, bucket, object_name)
|
|
215
|
+
self._upload_done(resp.id)
|
|
216
|
+
logger.info(f"log artifact done: {artifact_path}")
|
|
217
|
+
return
|
|
218
|
+
|
|
219
|
+
def download_artifacts(
|
|
220
|
+
self, run_id: str, artifact_path: Optional[str], local_dir: str
|
|
221
|
+
) -> None:
|
|
222
|
+
"""下载制品
|
|
223
|
+
|
|
224
|
+
Args:
|
|
225
|
+
run_id: 运行ID
|
|
226
|
+
artifact_path: 制品路径
|
|
227
|
+
local_dir: 本地目录路径
|
|
228
|
+
|
|
229
|
+
Raises:
|
|
230
|
+
APIError: 当API调用失败时抛出
|
|
231
|
+
"""
|
|
232
|
+
if self.s3_client is None:
|
|
233
|
+
self.sts = self._get_sts()
|
|
234
|
+
self.s3_client = minio.Minio(
|
|
235
|
+
self.sts.endpoint,
|
|
236
|
+
access_key=self.sts.access_key_id,
|
|
237
|
+
secret_key=self.sts.secret_access_key,
|
|
238
|
+
session_token=self.sts.session_token,
|
|
239
|
+
secure=False,
|
|
240
|
+
)
|
|
241
|
+
artifacts = self.get_by_run_id(run_id, artifact_path)
|
|
242
|
+
|
|
243
|
+
for artifact_item in artifacts:
|
|
244
|
+
bucket, object_name = S3_path_to_info(artifact_item.s3_path)
|
|
245
|
+
if artifact_item.is_dir:
|
|
246
|
+
download_dir_from_s3(self.s3_client, bucket, object_name, local_dir)
|
|
247
|
+
else:
|
|
248
|
+
self.s3_client.fget_object(
|
|
249
|
+
bucket, object_name, str(Path(local_dir) / artifact_item.src_path)
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
logger.info(f"download artifact done: {artifact_path}")
|
|
253
|
+
return
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
class _Artifact:
|
|
257
|
+
"""内部制品管理类
|
|
258
|
+
|
|
259
|
+
该类提供了与制品管理API交互的底层方法。
|
|
260
|
+
通常不直接使用该类,而是通过ArtifactService类访问其功能。
|
|
261
|
+
"""
|
|
262
|
+
|
|
263
|
+
def __init__(self, http: httpx.Client):
|
|
264
|
+
"""初始化内部制品管理类
|
|
265
|
+
|
|
266
|
+
Args:
|
|
267
|
+
http: HTTP客户端实例
|
|
268
|
+
"""
|
|
269
|
+
self._http = http
|
|
270
|
+
|
|
271
|
+
def create(self, payload: CreateArtifactsReq) -> CreateArtifactsResponseData:
|
|
272
|
+
"""创建制品记录
|
|
273
|
+
|
|
274
|
+
Args:
|
|
275
|
+
payload: 创建制品请求参数
|
|
276
|
+
|
|
277
|
+
Returns:
|
|
278
|
+
CreateArtifactsResponseData: 创建制品响应数据
|
|
279
|
+
|
|
280
|
+
Raises:
|
|
281
|
+
APIError: 当API调用失败时抛出
|
|
282
|
+
"""
|
|
283
|
+
resp = self._http.post(f"{_Base}/artifacts", json=payload.model_dump())
|
|
284
|
+
|
|
285
|
+
wrapper = APIWrapper[CreateArtifactsResponseData].model_validate(resp.json())
|
|
286
|
+
if wrapper.code != 0:
|
|
287
|
+
raise APIError(f"backend code {wrapper.code}: {wrapper.msg}")
|
|
288
|
+
return wrapper.data
|
|
289
|
+
|
|
290
|
+
def upload_done(self, artifact_id: int) -> None:
|
|
291
|
+
"""标记制品上传完成
|
|
292
|
+
|
|
293
|
+
在制品文件上传到S3后,需要调用此方法标记上传完成。
|
|
294
|
+
|
|
295
|
+
Args:
|
|
296
|
+
artifact_id: 制品ID
|
|
297
|
+
|
|
298
|
+
Raises:
|
|
299
|
+
APIError: 当API调用失败时抛出
|
|
300
|
+
"""
|
|
301
|
+
resp = self._http.post(f"{_Base}/artifacts/{artifact_id}/uploaded")
|
|
302
|
+
wrapper = APIWrapper.model_validate(resp.json())
|
|
303
|
+
if wrapper.code != 0:
|
|
304
|
+
raise APIError(f"backend code {wrapper.code}: {wrapper.msg}")
|
|
305
|
+
return
|
|
306
|
+
|
|
307
|
+
def get_by_run_id(
|
|
308
|
+
self, run_id: str, artifact_path: Optional[str]
|
|
309
|
+
) -> List[ArtifactResp]:
|
|
310
|
+
"""根据运行ID获取制品列表
|
|
311
|
+
|
|
312
|
+
Args:
|
|
313
|
+
run_id: 运行ID
|
|
314
|
+
artifact_path: 制品路径,如果指定则只返回匹配的制品
|
|
315
|
+
|
|
316
|
+
Returns:
|
|
317
|
+
List[ArtifactResp]: 制品列表
|
|
318
|
+
|
|
319
|
+
Raises:
|
|
320
|
+
APIError: 当API调用失败时抛出
|
|
321
|
+
"""
|
|
322
|
+
resp = self._http.get(
|
|
323
|
+
f"{_Base}/artifacts?entity_id={run_id}&page_num=1&page_size={InfinityPageSize}"
|
|
324
|
+
)
|
|
325
|
+
wrapper = APIWrapper[ArtifactRespData].model_validate(resp.json())
|
|
326
|
+
if wrapper.code != 0:
|
|
327
|
+
raise APIError(f"backend code {wrapper.code}: {wrapper.msg}")
|
|
328
|
+
if artifact_path:
|
|
329
|
+
return [
|
|
330
|
+
artifact
|
|
331
|
+
for artifact in wrapper.data.data
|
|
332
|
+
if artifact.src_path == artifact_path
|
|
333
|
+
]
|
|
334
|
+
else:
|
|
335
|
+
return wrapper.data.data
|
|
336
|
+
|
|
337
|
+
def get_sts(self) -> StsResp:
|
|
338
|
+
"""获取STS临时凭证
|
|
339
|
+
|
|
340
|
+
获取用于访问S3存储的临时凭证。
|
|
341
|
+
|
|
342
|
+
Returns:
|
|
343
|
+
StsResp: STS临时凭证信息
|
|
344
|
+
|
|
345
|
+
Raises:
|
|
346
|
+
APIError: 当API调用失败时抛出
|
|
347
|
+
"""
|
|
348
|
+
resp = self._http.get(f"{_Base}/artifacts/get-sts")
|
|
349
|
+
logger.info(f"get sts: {resp.text}")
|
|
350
|
+
wrapper = APIWrapper[StsResp].model_validate(resp.json())
|
|
351
|
+
if wrapper.code != 0:
|
|
352
|
+
raise APIError(f"backend code {wrapper.code}: {wrapper.msg}")
|
|
353
|
+
return wrapper.data
|