forked from feldera/feldera
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenums.py
More file actions
313 lines (239 loc) · 9.35 KB
/
enums.py
File metadata and controls
313 lines (239 loc) · 9.35 KB
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
from enum import Enum
from typing import Optional
class CompilationProfile(Enum):
"""
The compilation profile to use when compiling the program.
"""
SERVER_DEFAULT = None
"""
The compiler server default compilation profile.
"""
DEV = "dev"
"""
The development compilation profile.
"""
UNOPTIMIZED = "unoptimized"
"""
The unoptimized compilation profile.
"""
OPTIMIZED = "optimized"
"""
The optimized compilation profile, the default for this API.
"""
class BuildMode(Enum):
CREATE = 1
GET = 2
GET_OR_CREATE = 3
class PipelineStatus(Enum):
"""
Represents the state that this pipeline is currently in.
.. code-block:: text
Stopped ◄─────────── Stopping ◄───── All states can transition
│ ▲ to Stopping by either:
/start or /pause │ │ (1) user calling /stop?force=true, or;
▼ │ (2) pipeline encountering a fatal
⌛Provisioning Suspending resource or runtime error,
│ ▲ having the system call /stop?force=true
▼ │ /stop effectively
⌛Initializing ─────────────┤ ?force=false
│ │
┌─────────┼────────────────────┴─────┐
│ ▼ │
│ Paused ◄──────► Unavailable │
│ │ ▲ ▲ │
│ /start │ │ /pause │ │
│ ▼ │ │ │
│ Running ◄─────────────┘ │
└────────────────────────────────────┘
"""
NOT_FOUND = 0
"""
The pipeline has not been created yet.
"""
STOPPED = 1
"""
The pipeline has not (yet) been started or has been stopped either
manually by the user or automatically by the system due to a
resource or runtime error.
The pipeline remains in this state until:
1. The user starts it via `/start` or `/pause`, transitioning to `PROVISIONING`.
2. Early start fails (e.g., compilation failure), transitioning to `STOPPING`.
"""
PROVISIONING = 2
"""
Compute (and optionally storage) resources needed for running the pipeline
are being provisioned.
The pipeline remains in this state until:
1. Resources are provisioned successfully, transitioning to `INITIALIZING`.
2. Provisioning fails or times out, transitioning to `STOPPING`.
3. The user cancels the pipeline via `/stop`, transitioning to `STOPPING`.
"""
INITIALIZING = 3
"""
The pipeline is initializing its internal state and connectors.
The pipeline remains in this state until:
1. Initialization succeeds, transitioning to `PAUSED`.
2. Initialization fails or times out, transitioning to `STOPPING`.
3. The user suspends the pipeline via `/suspend`, transitioning to `SUSPENDING`.
4. The user stops the pipeline via `/stop`, transitioning to `STOPPING`.
"""
PAUSED = 4
"""
The pipeline is initialized but data processing is paused.
The pipeline remains in this state until:
1. The user starts it via `/start`, transitioning to `RUNNING`.
2. A runtime error occurs, transitioning to `STOPPING`.
3. The user suspends it via `/suspend`, transitioning to `SUSPENDING`.
4. The user stops it via `/stop`, transitioning to `STOPPING`.
"""
RUNNING = 5
"""
The pipeline is processing data.
The pipeline remains in this state until:
1. The user pauses it via `/pause`, transitioning to `PAUSED`.
2. A runtime error occurs, transitioning to `STOPPING`.
3. The user suspends it via `/suspend`, transitioning to `SUSPENDING`.
4. The user stops it via `/stop`, transitioning to `STOPPING`.
"""
UNAVAILABLE = 6
"""
The pipeline was initialized at least once but is currently unreachable
or not ready.
The pipeline remains in this state until:
1. A successful status check transitions it back to `PAUSED` or `RUNNING`.
2. A runtime error occurs, transitioning to `STOPPING`.
3. The user suspends it via `/suspend`, transitioning to `SUSPENDING`.
4. The user stops it via `/stop`, transitioning to `STOPPING`.
Note: While in this state, `/start` or `/pause` express desired state but
are only applied once the pipeline becomes reachable.
"""
SUSPENDING = 7
"""
The pipeline is being suspended to storage.
The pipeline remains in this state until:
1. Suspension succeeds, transitioning to `STOPPING`.
2. A runtime error occurs, transitioning to `STOPPING`.
"""
STOPPING = 8
"""
The pipeline's compute resources are being scaled down to zero.
The pipeline remains in this state until deallocation completes,
transitioning to `STOPPED`.
"""
@staticmethod
def from_str(value):
for member in PipelineStatus:
if member.name.lower() == value.lower():
return member
raise ValueError(f"Unknown value '{value}' for enum {PipelineStatus.__name__}")
def __eq__(self, other):
return self.value == other.value
class ProgramStatus(Enum):
Pending = 1
CompilingSql = 2
SqlCompiled = 3
CompilingRust = 4
Success = 5
SqlError = 6
RustError = 7
SystemError = 8
def __init__(self, value):
self.error: Optional[dict] = None
self._value_ = value
@staticmethod
def from_value(value):
error = None
if isinstance(value, dict):
error = value
value = list(value.keys())[0]
for member in ProgramStatus:
if member.name.lower() == value.lower():
member.error = error
return member
raise ValueError(f"Unknown value '{value}' for enum {ProgramStatus.__name__}")
def __eq__(self, other):
return self.value == other.value
def __str__(self):
return self.name + (f": ({self.error})" if self.error else "")
def get_error(self) -> Optional[dict]:
"""
Returns the compilation error, if any.
"""
return self.error
class CheckpointStatus(Enum):
Success = 1
Failure = 2
InProgress = 3
Unknown = 4
def __init__(self, value):
self.error: Optional[str] = None
self._value_ = value
def __eq__(self, other):
return self.value == other.value
def get_error(self) -> Optional[str]:
"""
Returns the error, if any.
"""
return self.error
class StorageStatus(Enum):
"""
Represents the current storage usage status of the pipeline.
"""
CLEARED = 0
"""
The pipeline has not been started before, or the user has cleared storage.
In this state, the pipeline has no storage resources bound to it.
"""
INUSE = 1
"""
The pipeline was (attempted to be) started before, transitioning from `STOPPED`
to `PROVISIONING`, which caused the storage status to become `INUSE`.
Being in the `INUSE` state restricts certain edits while the pipeline is `STOPPED`.
The pipeline remains in this state until the user invokes `/clear`, transitioning
it to `CLEARING`.
"""
CLEARING = 2
"""
The pipeline is in the process of becoming unbound from its storage resources.
If storage resources are configured to be deleted upon clearing, their deletion
occurs before transitioning to `CLEARED`. Otherwise, no actual work is required,
and the transition happens immediately.
If storage is not deleted during clearing, the responsibility to manage or delete
those resources lies with the user.
"""
@staticmethod
def from_str(value):
for member in StorageStatus:
if member.name.lower() == value.lower():
return member
raise ValueError(f"Unknown value '{value}' for enum {StorageStatus.__name__}")
def __eq__(self, other):
return self.value == other.value
class FaultToleranceModel(Enum):
"""
The fault tolerance model.
"""
AtLeastOnce = 1
"""
Each record is output at least once. Crashes may duplicate output, but
no input or output is dropped.
"""
ExactlyOnce = 2
"""
Each record is output exactly once. Crashes do not drop or duplicate
input or output.
"""
def __str__(self) -> str:
match self:
case FaultToleranceModel.AtLeastOnce:
return "at_least_once"
case FaultToleranceModel.ExactlyOnce:
return "exactly_once"
@staticmethod
def from_str(value):
for member in FaultToleranceModel:
if str(member) == value.lower():
return member
raise ValueError(
f"Unknown value '{value}' for enum {FaultToleranceModel.__name__}"
)