-
Notifications
You must be signed in to change notification settings - Fork 239
/
base.py
363 lines (312 loc) · 8.45 KB
/
base.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
# Copyright 2018 Iguazio
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import warnings
from abc import ABC, abstractmethod
from typing import List, Any, Dict
from mlrun.api import schemas
class DBError(Exception):
pass
class DBInterface(ABC):
@abstractmethod
def initialize(self, session):
pass
@abstractmethod
def store_log(self, session, uid, project="", body=None, append=False):
pass
@abstractmethod
def get_log(self, session, uid, project="", offset=0, size=0):
pass
@abstractmethod
def store_run(self, session, struct, uid, project="", iter=0):
pass
@abstractmethod
def update_run(self, session, updates: dict, uid, project="", iter=0):
pass
@abstractmethod
def read_run(self, session, uid, project="", iter=0):
pass
@abstractmethod
def list_runs(
self,
session,
name="",
uid=None,
project="",
labels=None,
state="",
sort=True,
last=0,
iter=False,
start_time_from=None,
start_time_to=None,
last_update_time_from=None,
last_update_time_to=None,
):
pass
@abstractmethod
def del_run(self, session, uid, project="", iter=0):
pass
@abstractmethod
def del_runs(self, session, name="", project="", labels=None, state="", days_ago=0):
pass
@abstractmethod
def store_artifact(
self, session, key, artifact, uid, iter=None, tag="", project=""
):
pass
@abstractmethod
def read_artifact(self, session, key, tag="", iter=None, project=""):
pass
@abstractmethod
def list_artifacts(
self,
session,
name="",
project="",
tag="",
labels=None,
since=None,
until=None,
kind=None,
category: schemas.ArtifactCategories = None,
):
pass
@abstractmethod
def del_artifact(self, session, key, tag="", project=""):
pass
@abstractmethod
def del_artifacts(self, session, name="", project="", tag="", labels=None):
pass
# TODO: Make these abstract once filedb implements them
def store_metric(
self, session, uid, project="", keyvals=None, timestamp=None, labels=None
):
warnings.warn("store_metric not implemented yet")
def read_metric(self, session, keys, project="", query=""):
warnings.warn("store_metric not implemented yet")
@abstractmethod
def store_function(
self, session, function, name, project="", tag="", versioned=False
):
pass
@abstractmethod
def get_function(self, session, name, project="", tag="", hash_key=""):
pass
@abstractmethod
def delete_function(self, session, project: str, name: str):
pass
@abstractmethod
def list_functions(self, session, name=None, project="", tag="", labels=None):
pass
@abstractmethod
def create_schedule(
self,
session,
project: str,
name: str,
kind: schemas.ScheduleKinds,
scheduled_object: Any,
cron_trigger: schemas.ScheduleCronTrigger,
labels: Dict = None,
):
pass
@abstractmethod
def update_schedule(
self,
session,
project: str,
name: str,
scheduled_object: Any = None,
cron_trigger: schemas.ScheduleCronTrigger = None,
labels: Dict = None,
last_run_uri: str = None,
):
pass
@abstractmethod
def list_schedules(
self,
session,
project: str = None,
name: str = None,
labels: str = None,
kind: schemas.ScheduleKinds = None,
) -> List[schemas.ScheduleRecord]:
pass
@abstractmethod
def get_schedule(self, session, project: str, name: str) -> schemas.ScheduleRecord:
pass
@abstractmethod
def delete_schedule(self, session, project: str, name: str):
pass
@abstractmethod
def list_projects(
self,
session,
owner: str = None,
format_: schemas.Format = schemas.Format.full,
labels: List[str] = None,
state: schemas.ProjectState = None,
) -> schemas.ProjectsOutput:
pass
@abstractmethod
def get_project(
self, session, name: str = None, project_id: int = None
) -> schemas.Project:
pass
@abstractmethod
def create_project(self, session, project: schemas.Project):
pass
@abstractmethod
def store_project(self, session, name: str, project: schemas.Project):
pass
@abstractmethod
def patch_project(
self,
session,
name: str,
project: dict,
patch_mode: schemas.PatchMode = schemas.PatchMode.replace,
):
pass
@abstractmethod
def delete_project(
self,
session,
name: str,
deletion_strategy: schemas.DeletionStrategy = schemas.DeletionStrategy.default(),
):
pass
@abstractmethod
def create_feature_set(
self, session, project, feature_set: schemas.FeatureSet, versioned=True
):
pass
@abstractmethod
def store_feature_set(
self,
session,
project,
name,
feature_set: schemas.FeatureSet,
tag=None,
uid=None,
versioned=True,
always_overwrite=False,
):
pass
@abstractmethod
def get_feature_set(
self, session, project: str, name: str, tag: str = None, uid: str = None
) -> schemas.FeatureSet:
pass
@abstractmethod
def list_features(
self,
session,
project: str,
name: str = None,
tag: str = None,
entities: List[str] = None,
labels: List[str] = None,
) -> schemas.FeaturesOutput:
pass
@abstractmethod
def list_entities(
self,
session,
project: str,
name: str = None,
tag: str = None,
labels: List[str] = None,
) -> schemas.EntitiesOutput:
pass
@abstractmethod
def list_feature_sets(
self,
session,
project: str,
name: str = None,
tag: str = None,
state: str = None,
entities: List[str] = None,
features: List[str] = None,
labels: List[str] = None,
) -> schemas.FeatureSetsOutput:
pass
@abstractmethod
def patch_feature_set(
self,
session,
project,
name,
feature_set_update: dict,
tag=None,
uid=None,
patch_mode: schemas.PatchMode = schemas.PatchMode.replace,
):
pass
@abstractmethod
def delete_feature_set(self, session, project, name):
pass
@abstractmethod
def create_feature_vector(
self, session, project, feature_vector: schemas.FeatureVector, versioned=True
):
pass
@abstractmethod
def get_feature_vector(
self, session, project: str, name: str, tag: str = None, uid: str = None
) -> schemas.FeatureVector:
pass
@abstractmethod
def list_feature_vectors(
self,
session,
project: str,
name: str = None,
tag: str = None,
state: str = None,
labels: List[str] = None,
) -> schemas.FeatureVectorsOutput:
pass
@abstractmethod
def store_feature_vector(
self,
session,
project,
name,
feature_vector: schemas.FeatureVector,
tag=None,
uid=None,
versioned=True,
always_overwrite=False,
):
pass
@abstractmethod
def patch_feature_vector(
self,
session,
project,
name,
feature_vector_update: dict,
tag=None,
uid=None,
patch_mode: schemas.PatchMode = schemas.PatchMode.replace,
):
pass
@abstractmethod
def delete_feature_vector(self, session, project, name):
pass
def list_artifact_tags(self, session, project):
return []