OSMENG-1155 Implementation of Constants and Dataclasses
[osm/common.git] / osm_common / temporal / activities / vnf.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.states import VnfInstantiationState, VnfState
23
24
25 class ChangeVnfState(BaseActivity):
26 """Updates the VNF State in VNFR.
27
28 Collaborators:
29 DB Write: vnfrs
30
31 Raises (retryable):
32 DbException: If DB access/update fails, the collection or DB record ID does not exist.
33
34 Activity Lifecycle:
35 This activity should complete relatively quickly (less than a
36 second). However, it would be reasonable to wait up to 10
37 seconds.
38
39 This activity will not report a heartbeat due to its
40 short-running nature.
41
42 It is not necessary to implement a back-off strategy for this
43 activity, the operation is idempotent.
44
45 """
46
47 @dataclass
48 class Input:
49 """
50 Input dataclass for changing VNF State.
51
52 Attributes:
53 -----------
54 vnfr_uuid : str
55 The UUID of the VNF which is stored in the OSM vnfrs
56 collection in Mongo.
57
58 state : VnfState
59 A representation of the VNF state (STOPPED or STARTED).
60 """
61
62 vnfr_uuid: str
63 state: VnfState
64
65 def __init__(self, db: DbBase):
66 super().__init__()
67 self.db: DbBase = db
68
69 async def __call__(self, activity_input: Input) -> None:
70 raise NotImplementedError()
71
72
73 class ChangeVnfInstantiationState(BaseActivity):
74 """Updates the VNF Instantiation State in VNFR.
75
76 Collaborators:
77 DB Write: vnfrs
78
79 Raises (retryable):
80 DbException: If DB access or update fails, the collection or DB record ID does not exist.
81
82 Activity Lifecycle:
83 This activity should complete relatively quickly (less than a
84 second). However, it would be reasonable to wait up to 10
85 seconds.
86
87 This activity will not report a heartbeat due to its
88 short-running nature.
89
90 It is not necessary to implement a back-off strategy for this
91 activity, the operation is idempotent.
92
93 """
94
95 @dataclass
96 class Input:
97 """
98 Input dataclass for changing VNF Instantiation State.
99
100 Attributes:
101 -----------
102 vnfr_uuid : str
103 The UUID of the VNF which is stored in the OSM vnfrs
104 collection in Mongo.
105
106 state : VnfInstantiationState
107 A representation of the VNF instantiation state (NOT_INSTANTIATED or INSTANTIATED).
108
109 """
110
111 vnfr_uuid: str
112 state: VnfInstantiationState
113
114 def __init__(self, db: DbBase):
115 super().__init__()
116 self.db: DbBase = db
117
118 async def __call__(self, activity_input: Input) -> None:
119 raise NotImplementedError()
120
121
122 class GetVnfRecord(BaseActivity):
123 """Gets the VNF record and VNF descriptor from Database.
124
125 Collaborators:
126 DB read: vnfrs, vnfds
127
128 Raises (retryable):
129 DbException: If DB read operations fail, the collection or DB record ID does not exist.
130
131 Activity Lifecycle:
132 This activity should complete relatively quickly (less than 10
133 second).
134
135 This activity will not report a heartbeat due to its
136 short-running nature.
137
138 This is an idempotent activity.
139
140 """
141
142 @dataclass
143 class Input:
144 """
145 Input dataclass for get vnf details activity.
146
147 Attributes:
148 -----------
149 vnfr_uuid : str
150 The UUID of the VNF which is stored in the OSM vnfrs
151 collection in Mongo.
152 """
153
154 vnfr_uuid: str
155
156 @dataclass
157 class Output:
158 """
159 Output dataclass for get vnf details activity.
160
161 Attributes:
162 -----------
163 vnf_details: list[(vnfr_ids: str, vnf_member_index_ref: str), .. ]
164 List of tuples including VNF details associated with the NS.
165 Tuple(VNF record IDs, vnf_member_index_ref)
166 """
167
168 vnfr: dict
169
170 def __init__(self, db: DbBase):
171 super().__init__()
172 self.db: DbBase = db
173
174 async def __call__(self, activity_input: Input) -> Output:
175 raise NotImplementedError()
176
177
178 class GetVnfDescriptor(BaseActivity):
179 """Gets the VNF record and VNF descriptor from Database.
180
181 Collaborators:
182 DB read: vnfrs
183
184 Raises (retryable):
185 DbException: If DB read operations fail, the collection or DB record ID does not exist.
186
187 Activity Lifecycle:
188 This activity should complete relatively quickly (less than 10
189 second).
190
191 This activity will not report a heartbeat due to its
192 short-running nature.
193
194 This is an idempotent activity.
195
196 """
197
198 @dataclass
199 class Input:
200 """
201 Input dataclass for get vnf descriptor activity.
202
203 Attributes:
204 -----------
205 vnfd_uuid : str
206 The UUID of the VNF descriptor which is stored in the OSM vnfds
207 collection in Mongo.
208 """
209
210 vnfd_uuid: str
211
212 @dataclass
213 class Output:
214 """
215 Output dataclass for get vnf details activity.
216
217 Attributes:
218 -----------
219 vnfd : dict
220 VNF descriptor retrieved from Database.
221 """
222
223 vnfd: dict
224
225 def __init__(self, db: DbBase):
226 super().__init__()
227 self.db: DbBase = db
228
229 async def __call__(self, activity_input: Input) -> Output:
230 raise NotImplementedError()
231
232
233 class SendNotificationForVnf(BaseActivity):
234 """Perform Notification operations."""
235
236 @dataclass
237 class Input:
238 """
239 Input dataclass for sending notifications for change in VNF Instantiation State.
240
241 Attributes:
242 -----------
243 vnfr_uuid : str
244 The UUID of the VNF which is stored in the OSM vnfrs
245 collection in Mongo.
246
247 state : VnfInstantiationState
248 A representation of the VNF instantiation state (NOT_INSTANTIATED or INSTANTIATED).
249
250 """
251
252 vnfr_uuid: str
253 state: VnfState
254
255 async def __call__(self, activity_input: Input):
256 raise NotImplementedError()
257
258
259 class GetTaskQueue(BaseActivity):
260 """Finds the appropriate task queue according to VIM type of VNF.
261
262 Collaborators:
263 DB read: vim_accounts, vnfrs
264
265 Raises (retryable):
266 DbException: If DB read operations fail, the collection or DB record ID does not exist.
267
268 Activity Lifecycle:
269 This activity should complete relatively quickly (less than a
270 second). However, it would be reasonable to wait up to 10
271 seconds.
272
273 This activity will not report a heartbeat due to its
274 short-running nature.
275
276 It is not necessary to implement a back-off strategy for this
277 activity, the operation is idempotent.
278
279 """
280
281 @dataclass
282 class Input:
283 """
284 Input dataclass for get task queue activity.
285
286 Attributes:
287 -----------
288 vnfr_uuid : str
289 The UUID of the VNF which is stored in the OSM vnfrs
290 collection in Mongo.
291
292 """
293
294 vnfr_uuid: str
295
296 @dataclass
297 class Output:
298 """
299 Output dataclass for get task queue activity.
300
301 Attributes:
302 -----------
303 task_queue : str
304 Name of the queue which is used to Deploy VNF.
305 """
306
307 task_queue: str
308
309 def __init__(self, db: DbBase):
310 super().__init__()
311 self.db: DbBase = db
312
313 async def __call__(self, activity_input: Input) -> Output:
314 raise NotImplementedError()
315
316
317 class GetVimCloud(BaseActivity):
318 """Finds the cloud by checking the VIM account of VNF.
319
320 Collaborators:
321 DB Read: vnfrs, vim_accounts
322
323 Raises (retryable):
324 DbException: If DB read operations fail, the collection or DB record ID does not exist.
325
326 Activity Lifecycle:
327 This activity should complete relatively quickly (less than a
328 second). However, it would be reasonable to wait up to 10
329 seconds.
330
331 This activity will not report a heartbeat due to its
332 short-running nature.
333
334 It is not necessary to implement a back-off strategy for this
335 activity, the operation is idempotent.
336
337 """
338
339 @dataclass
340 class Input:
341 """
342 Input dataclass for get vim cloud activity.
343
344 Attributes:
345 -----------
346 vnfr_uuid : str
347 The UUID of the VNF which is stored in the OSM vnfrs
348 collection in Mongo.
349
350 """
351
352 vnfr_uuid: str
353
354 @dataclass
355 class Output:
356 """
357 Output dataclass for get vim cloud activity.
358
359 Attributes:
360 -----------
361 cloud : str
362 Type of the cloud which is used to Deploy VNF.
363 """
364
365 cloud: str
366
367 def __init__(self, db: DbBase):
368 super().__init__()
369 self.db: DbBase = db
370
371 async def __call__(self, activity_input: Input) -> Output:
372 raise NotImplementedError()
373
374
375 class SetVnfModel(BaseActivity):
376 """Updates the model name of VNF in VNFR.
377
378 Collaborators:
379 DB Write: vnfrs
380
381 Raises (retryable):
382 DbException: If DB access or update fails, the collection or DB record ID does not exist.
383
384 Activity Lifecycle:
385 This activity should complete relatively quickly (less than a
386 second). However, it would be reasonable to wait up to 10
387 seconds.
388
389 This activity will not report a heartbeat due to its
390 short-running nature.
391
392 It is not necessary to implement a back-off strategy for this
393 activity, the operation is idempotent.
394
395 """
396
397 @dataclass
398 class Input:
399 """
400 Input dataclass for workflow that instantiates a VNF.
401
402 Attributes:
403 -----------
404 vnfr_uuid : str
405 The UUID of the VNF which is stored in the OSM vnfrs
406 collection in Mongo.
407
408 model_name: str
409
410 """
411
412 vnfr_uuid: str
413 model_name: str
414
415 def __init__(self, db: DbBase):
416 super().__init__()
417 self.db: DbBase = db
418
419 async def __call__(self, activity_input: Input) -> None:
420 raise NotImplementedError()