fc08af2fef4759d20612f0698389a8361d77eb69
[osm/common.git] / osm_common / temporal / activities / paas.py
1 #######################################################################################
2 # Copyright ETSI Contributors and Others.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 # implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #######################################################################################
17
18 from dataclasses import dataclass
19
20 from osm_common.dbbase import DbBase
21 from osm_common.temporal.activities.base import BaseActivity
22 from osm_common.temporal.dataclasses_common import CharmInfo, VduComputeConstraints
23
24
25 class TestVimConnectivity(BaseActivity):
26 """Validates the credentials by attempting to connect to the given Juju Controller.
27
28 Collaborators:
29 Juju Controller: Connect only
30
31 Raises (Retryable):
32 ApplicationError If any of password, cacert, cloud_credentials is invalid
33 or Juju controller is not reachable
34
35 Activity Lifecycle:
36 This activity should complete relatively quickly (in a few seconds).
37 However, it would be reasonable to wait more than 72 seconds (network timeout)
38 incase there are network issues.
39
40 This activity will not report a heartbeat due to its
41 short-running nature.
42
43 It is recommended, although not necessary to implement a
44 back-off strategy for this activity, as it will naturally block
45 and wait on each connection attempt.
46 """
47
48 @dataclass
49 class Input:
50 """
51 Input dataclass for the Test Vim Connectivity Ativity
52
53 Attributes:
54 -----------
55 vim_uuid : str
56 The UUID of the VIM account as stored in the OSM vim
57 collection in Mongo
58 """
59
60 vim_uuid: str
61
62 def __init__(self, juju_controller):
63 super().__init__()
64 self.juju_controller = juju_controller
65
66 async def __call__(self, activity_input: Input) -> None:
67 raise NotImplementedError()
68
69
70 class CreateModel(BaseActivity):
71 """Connects to Juju Controller. Creates a new model.
72
73 Collaborators:
74 DB Read: vim_accounts
75 Juju Controller: Connect and create model.
76
77 Raises (Retryable):
78 ApplicationError If Juju controller is not reachable.
79 If the model already exists.
80
81 Activity Lifecycle:
82 This activity should complete relatively quickly (in a few seconds).
83 However, it would be reasonable to wait more than 72 seconds (network timeout)
84 incase there are network issues.
85
86 This activity will not report a heartbeat due to its
87 short-running nature.
88
89 It is recommended, although not necessary to implement a
90 back-off strategy for this activity, as it will naturally block
91 and wait on each connection attempt.
92 """
93
94 @dataclass
95 class Input:
96 """
97 Contains the information related to a model.
98
99 Attributes:
100 -----------
101 vim_uuid : str
102 The UUID of the VIM as stored in the OSM vim_accounts
103 collection in Mongo.
104
105 model_name : str
106 Name of the Juju model used to deploy charms.
107 """
108
109 vim_uuid: str
110 model_name: str
111
112 def __init__(self, db: DbBase, juju_controller):
113 super().__init__()
114 self.db: DbBase = db
115 self.juju_controller = juju_controller
116
117 async def __call__(self, activity_input: Input) -> None:
118 raise NotImplementedError()
119
120
121 class DeployCharm(BaseActivity):
122 """Deploys a charm.
123
124 Collaborators:
125 Juju Controller: Connect and deploy charm
126
127 Raises (Retryable):
128 ApplicationError If Juju controller is not reachable
129 If application already exists
130
131 Activity Lifecycle:
132 This activity should complete relatively quickly (in a few seconds).
133 However, it would be reasonable to wait more than 72 seconds (network timeout)
134 incase there are network issues.
135
136 This activity will not report a heartbeat due to its
137 short-running nature.
138
139 It is recommended, although not necessary to implement a
140 back-off strategy for this activity, as it will naturally block
141 and wait on each connection attempt.
142 """
143
144 @dataclass
145 class Input:
146 """
147 Input dataclass for workflow that instantiates a VDU.
148
149 vim_uuid: str
150
151 model_name: str
152
153 charm_info : CharmInfo
154
155 constraints: VduComputeConstraints
156
157 cloud: VIM cloud type
158
159 config: Config details of application
160 """
161
162 vim_uuid: str
163 model_name: str
164 charm_info: CharmInfo
165 constraints: VduComputeConstraints
166 cloud: str
167 config: dict
168
169 def __init__(self, juju_controller):
170 super().__init__()
171 self.juju_controller = juju_controller
172
173 async def __call__(self, activity_input: Input) -> None:
174 raise NotImplementedError()
175
176
177 class CheckCharmStatus(BaseActivity):
178 """Checks the ready status of the charm. This activity will block until the status of
179 the application is either "active" or "blocked". Additionally, it also blocks until
180 the workload status of each of its units is also either "active" or "blocked".
181
182 Collaborators:
183 Juju Controller: Connect to controller and check charm status.
184
185 Raises (Retryable):
186 ApplicationError If any of password, cacert, cloud_credentials is invalid
187 or Juju controller is not reachable
188
189 Activity Lifecycle:
190 This activity will continue indefinitely until the specified charm deployment
191 has reached a ready state. Heartbeats are performed to ensure this activity
192 does not time out.
193
194 A start-to-close of something reasonable (such as 5 minutes) should be implemented
195 at the workflow level and such a timeout shall trigger workflow failure logic.
196 """
197
198 @dataclass
199 class Input:
200 """
201 Input dataclass for checking on a specific charm's deployment
202 status
203
204 Attributes:
205 -----------
206 vim_uuid : str
207 The UUID of the VIM as stored in the OSM vim_accounts
208 collection in Mongo.
209
210 model_name : str
211 Name of the model to create in Juju.
212
213 application_name : str
214 Name of the application that the state is going to be
215 awaited.
216
217 poll_interval : int (optional)
218 Time, in seconds, to wait between status checks.
219 """
220
221 vim_uuid: str
222 model_name: str
223 application_name: str
224 poll_interval: int = 1
225
226 def __init__(self, juju_controller):
227 super().__init__()
228 self.juju_controller = juju_controller
229
230 async def __call__(self, activity_input: Input) -> None:
231 raise NotImplementedError()
232
233
234 class RemoveCharm(BaseActivity):
235 """Removes the given charm from the given model.
236
237 Collaborators:
238 Juju Controller: Connect to controller and remove charm.
239
240 Raises (Retryable):
241 ApplicationError If any of password, cacert, cloud_credentials is invalid
242 or Juju controller is not reachable
243
244 Activity Lifecycle:
245 This activity should complete relatively quickly (in a few seconds).
246 However, it would be reasonable to wait more than 72 seconds (network timeout)
247 incase there are network issues.
248
249 This activity will not report a heartbeat due to its
250 short-running nature.
251
252 It is recommended, although not necessary to implement a
253 back-off strategy for this activity, as it will naturally block
254 and wait on each connection attempt.
255 """
256
257 @dataclass
258 class Input:
259 """
260 Input dataclass for removing a specific charm
261
262 Attributes:
263 -----------
264 vim_uuid : str
265 The UUID of the VIM as stored in the OSM vim_accounts
266 collection in Mongo.
267
268 model_name : str
269 Name of the model in Juju where the charm is deployed.
270
271 application_name : str
272 Name of the application to be removed.
273
274 force_remove : bool
275 If application has to be forcefully removed.
276
277 """
278
279 vim_uuid: str
280 model_name: str
281 application_name: str
282 force_remove: bool
283
284 def __init__(self, juju_controller):
285 super().__init__()
286 self.juju_controller = juju_controller
287
288 async def __call__(self, activity_input: Input) -> None:
289 raise NotImplementedError()
290
291
292 class CheckCharmIsRemoved(BaseActivity):
293 """Checks the removal of the charm. This activity will block until the application
294 is not present in the specified model.
295
296 Collaborators:
297 Juju Controller: Connect to controller and check charm status.
298
299 Raises (Retryable):
300 ApplicationError If any of password, cacert, cloud_credentials is invalid
301 or Juju controller is not reachable
302
303 Activity Lifecycle:
304 This activity will continue indefinitely until the specified charm is removed.
305 Heartbeats are performed to ensure this activity does not time out.
306
307 A start-to-close of something reasonable (such as 5 minutes) should be implemented
308 at the workflow level and such a timeout shall trigger workflow failure logic.
309 """
310
311 @dataclass
312 class Input:
313 """
314 Input dataclass for checking on a specific charm's removal
315 status
316
317 Attributes:
318 -----------
319 vim_uuid : str
320 The UUID of the VIM as stored in the OSM vim_accounts
321 collection in Mongo.
322
323 model_name : str
324 Name of the model in Juju where the charm is deployed.
325
326 application_name : str
327 Name of the application for which the removal is going
328 to be awaited.
329
330 poll_interval : int (optional)
331 Time, in seconds, to wait between status checks.
332 """
333
334 vim_uuid: str
335 model_name: str
336 application_name: str
337 poll_interval: int = 1
338
339 def __init__(self, juju_controller):
340 super().__init__()
341 self.juju_controller = juju_controller
342
343 async def __call__(self, activity_input: Input) -> None:
344 raise NotImplementedError()
345
346
347 class RemoveModel(BaseActivity):
348 """Removes the given model from the given controller.
349
350 Collaborators:
351 Juju Controller: Connect to controller and remove model.
352
353 Raises (Retryable):
354 ApplicationError If any of password, cacert, cloud_credentials is invalid
355 or Juju controller is not reachable
356
357 Activity Lifecycle:
358 This activity should complete relatively quickly (in a few seconds).
359 However, it would be reasonable to wait more than 72 seconds (network timeout)
360 incase there are network issues.
361
362 This activity will not report a heartbeat due to its
363 short-running nature.
364
365 It is recommended, although not necessary to implement a
366 back-off strategy for this activity, as it will naturally block
367 and wait on each connection attempt.
368 """
369
370 @dataclass
371 class Input:
372 """
373 Input dataclass for removing a specific model
374
375 Attributes:
376 -----------
377 vim_uuid : str
378 The UUID of the VIM as stored in the OSM vim_accounts
379 collection in Mongo.
380
381 model_name : str
382 Name of the model in Juju to be removed.
383
384 force_remove : bool
385 If model has to be forcefully removed.
386
387 """
388
389 vim_uuid: str
390 model_name: str
391 force_remove: bool
392
393 def __init__(self, juju_controller):
394 super().__init__()
395 self.juju_controller = juju_controller
396
397 async def __call__(self, activity_input: Input) -> None:
398 raise NotImplementedError()
399
400
401 class CheckModelIsRemoved(BaseActivity):
402 """Checks the removal of the model. This activity will block until the model
403 is not present in the specified controller.
404
405 Collaborators:
406 Juju Controller: Connect to controller and check model removal status.
407
408 Raises (Retryable):
409 ApplicationError If any of password, cacert, cloud_credentials is invalid
410 or Juju controller is not reachable
411
412 Activity Lifecycle:
413 This activity will continue indefinitely until the specified model is removed.
414 Heartbeats are performed to ensure this activity does not time out.
415
416 A start-to-close of something reasonable (such as 5 minutes) should be implemented
417 at the workflow level and such a timeout shall trigger workflow failure logic.
418 """
419
420 @dataclass
421 class Input:
422 """
423 Input dataclass for checking on a specific model's removal
424 status
425
426 Attributes:
427 -----------
428 vim_uuid : str
429 The UUID of the VIM as stored in the OSM vim_accounts
430 collection in Mongo.
431
432 model_name : str
433 Name of the model in Juju for which the removal is going
434 to be awaited.
435
436 poll_interval : int (optional)
437 Time, in seconds, to wait between status checks.
438 """
439
440 vim_uuid: str
441 model_name: str
442 poll_interval: int = 1
443
444 def __init__(self, juju_controller):
445 super().__init__()
446 self.juju_controller = juju_controller
447
448 async def __call__(self, activity_input: Input) -> None:
449 raise NotImplementedError()