| Dario Faccin | 989602b | 2023-06-20 16:12:29 +0200 | [diff] [blame] | 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: |
| Daniel Arndt | 63c7ce8 | 2023-07-07 12:28:25 -0300 | [diff] [blame] | 126 | DB read: vnfrs |
| Dario Faccin | 989602b | 2023-06-20 16:12:29 +0200 | [diff] [blame] | 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 | ----------- |
| Daniel Arndt | 63c7ce8 | 2023-07-07 12:28:25 -0300 | [diff] [blame] | 163 | vnfr: dict |
| 164 | The VNF record |
| Dario Faccin | 989602b | 2023-06-20 16:12:29 +0200 | [diff] [blame] | 165 | """ |
| 166 | |
| 167 | vnfr: dict |
| 168 | |
| 169 | def __init__(self, db: DbBase): |
| 170 | super().__init__() |
| 171 | self.db: DbBase = db |
| 172 | |
| 173 | async def __call__(self, activity_input: Input) -> Output: |
| 174 | raise NotImplementedError() |
| 175 | |
| 176 | |
| 177 | class GetVnfDescriptor(BaseActivity): |
| 178 | """Gets the VNF record and VNF descriptor from Database. |
| 179 | |
| 180 | Collaborators: |
| 181 | DB read: vnfrs |
| 182 | |
| 183 | Raises (retryable): |
| 184 | DbException: If DB read operations fail, the collection or DB record ID does not exist. |
| 185 | |
| 186 | Activity Lifecycle: |
| 187 | This activity should complete relatively quickly (less than 10 |
| 188 | second). |
| 189 | |
| 190 | This activity will not report a heartbeat due to its |
| 191 | short-running nature. |
| 192 | |
| 193 | This is an idempotent activity. |
| 194 | |
| 195 | """ |
| 196 | |
| 197 | @dataclass |
| 198 | class Input: |
| 199 | """ |
| 200 | Input dataclass for get vnf descriptor activity. |
| 201 | |
| 202 | Attributes: |
| 203 | ----------- |
| 204 | vnfd_uuid : str |
| 205 | The UUID of the VNF descriptor which is stored in the OSM vnfds |
| 206 | collection in Mongo. |
| 207 | """ |
| 208 | |
| 209 | vnfd_uuid: str |
| 210 | |
| 211 | @dataclass |
| 212 | class Output: |
| 213 | """ |
| 214 | Output dataclass for get vnf details activity. |
| 215 | |
| 216 | Attributes: |
| 217 | ----------- |
| 218 | vnfd : dict |
| 219 | VNF descriptor retrieved from Database. |
| 220 | """ |
| 221 | |
| 222 | vnfd: dict |
| 223 | |
| 224 | def __init__(self, db: DbBase): |
| 225 | super().__init__() |
| 226 | self.db: DbBase = db |
| 227 | |
| 228 | async def __call__(self, activity_input: Input) -> Output: |
| 229 | raise NotImplementedError() |
| 230 | |
| 231 | |
| 232 | class SendNotificationForVnf(BaseActivity): |
| 233 | """Perform Notification operations.""" |
| 234 | |
| 235 | @dataclass |
| 236 | class Input: |
| 237 | """ |
| 238 | Input dataclass for sending notifications for change in VNF Instantiation State. |
| 239 | |
| 240 | Attributes: |
| 241 | ----------- |
| 242 | vnfr_uuid : str |
| 243 | The UUID of the VNF which is stored in the OSM vnfrs |
| 244 | collection in Mongo. |
| 245 | |
| 246 | state : VnfInstantiationState |
| 247 | A representation of the VNF instantiation state (NOT_INSTANTIATED or INSTANTIATED). |
| 248 | |
| 249 | """ |
| 250 | |
| 251 | vnfr_uuid: str |
| 252 | state: VnfState |
| 253 | |
| 254 | async def __call__(self, activity_input: Input): |
| 255 | raise NotImplementedError() |
| 256 | |
| 257 | |
| 258 | class GetTaskQueue(BaseActivity): |
| 259 | """Finds the appropriate task queue according to VIM type of VNF. |
| 260 | |
| 261 | Collaborators: |
| 262 | DB read: vim_accounts, vnfrs |
| 263 | |
| 264 | Raises (retryable): |
| 265 | DbException: If DB read operations fail, the collection or DB record ID does not exist. |
| 266 | |
| 267 | Activity Lifecycle: |
| 268 | This activity should complete relatively quickly (less than a |
| 269 | second). However, it would be reasonable to wait up to 10 |
| 270 | seconds. |
| 271 | |
| 272 | This activity will not report a heartbeat due to its |
| 273 | short-running nature. |
| 274 | |
| 275 | It is not necessary to implement a back-off strategy for this |
| 276 | activity, the operation is idempotent. |
| 277 | |
| 278 | """ |
| 279 | |
| 280 | @dataclass |
| 281 | class Input: |
| 282 | """ |
| 283 | Input dataclass for get task queue activity. |
| 284 | |
| 285 | Attributes: |
| 286 | ----------- |
| 287 | vnfr_uuid : str |
| 288 | The UUID of the VNF which is stored in the OSM vnfrs |
| 289 | collection in Mongo. |
| 290 | |
| 291 | """ |
| 292 | |
| 293 | vnfr_uuid: str |
| 294 | |
| 295 | @dataclass |
| 296 | class Output: |
| 297 | """ |
| 298 | Output dataclass for get task queue activity. |
| 299 | |
| 300 | Attributes: |
| 301 | ----------- |
| 302 | task_queue : str |
| 303 | Name of the queue which is used to Deploy VNF. |
| 304 | """ |
| 305 | |
| 306 | task_queue: str |
| 307 | |
| 308 | def __init__(self, db: DbBase): |
| 309 | super().__init__() |
| 310 | self.db: DbBase = db |
| 311 | |
| 312 | async def __call__(self, activity_input: Input) -> Output: |
| 313 | raise NotImplementedError() |
| 314 | |
| 315 | |
| 316 | class GetVimCloud(BaseActivity): |
| 317 | """Finds the cloud by checking the VIM account of VNF. |
| 318 | |
| 319 | Collaborators: |
| 320 | DB Read: vnfrs, vim_accounts |
| 321 | |
| 322 | Raises (retryable): |
| 323 | DbException: If DB read operations fail, the collection or DB record ID does not exist. |
| 324 | |
| 325 | Activity Lifecycle: |
| 326 | This activity should complete relatively quickly (less than a |
| 327 | second). However, it would be reasonable to wait up to 10 |
| 328 | seconds. |
| 329 | |
| 330 | This activity will not report a heartbeat due to its |
| 331 | short-running nature. |
| 332 | |
| 333 | It is not necessary to implement a back-off strategy for this |
| 334 | activity, the operation is idempotent. |
| 335 | |
| 336 | """ |
| 337 | |
| 338 | @dataclass |
| 339 | class Input: |
| 340 | """ |
| 341 | Input dataclass for get vim cloud activity. |
| 342 | |
| 343 | Attributes: |
| 344 | ----------- |
| 345 | vnfr_uuid : str |
| 346 | The UUID of the VNF which is stored in the OSM vnfrs |
| 347 | collection in Mongo. |
| 348 | |
| 349 | """ |
| 350 | |
| 351 | vnfr_uuid: str |
| 352 | |
| 353 | @dataclass |
| 354 | class Output: |
| 355 | """ |
| 356 | Output dataclass for get vim cloud activity. |
| 357 | |
| 358 | Attributes: |
| 359 | ----------- |
| 360 | cloud : str |
| 361 | Type of the cloud which is used to Deploy VNF. |
| 362 | """ |
| 363 | |
| 364 | cloud: str |
| 365 | |
| 366 | def __init__(self, db: DbBase): |
| 367 | super().__init__() |
| 368 | self.db: DbBase = db |
| 369 | |
| 370 | async def __call__(self, activity_input: Input) -> Output: |
| 371 | raise NotImplementedError() |
| 372 | |
| 373 | |
| 374 | class SetVnfModel(BaseActivity): |
| 375 | """Updates the model name of VNF in VNFR. |
| 376 | |
| 377 | Collaborators: |
| 378 | DB Write: vnfrs |
| 379 | |
| 380 | Raises (retryable): |
| 381 | DbException: If DB access or update fails, the collection or DB record ID does not exist. |
| 382 | |
| 383 | Activity Lifecycle: |
| 384 | This activity should complete relatively quickly (less than a |
| 385 | second). However, it would be reasonable to wait up to 10 |
| 386 | seconds. |
| 387 | |
| 388 | This activity will not report a heartbeat due to its |
| 389 | short-running nature. |
| 390 | |
| 391 | It is not necessary to implement a back-off strategy for this |
| 392 | activity, the operation is idempotent. |
| 393 | |
| 394 | """ |
| 395 | |
| 396 | @dataclass |
| 397 | class Input: |
| 398 | """ |
| 399 | Input dataclass for workflow that instantiates a VNF. |
| 400 | |
| 401 | Attributes: |
| 402 | ----------- |
| 403 | vnfr_uuid : str |
| 404 | The UUID of the VNF which is stored in the OSM vnfrs |
| 405 | collection in Mongo. |
| 406 | |
| 407 | model_name: str |
| 408 | |
| 409 | """ |
| 410 | |
| 411 | vnfr_uuid: str |
| 412 | model_name: str |
| 413 | |
| 414 | def __init__(self, db: DbBase): |
| 415 | super().__init__() |
| 416 | self.db: DbBase = db |
| 417 | |
| 418 | async def __call__(self, activity_input: Input) -> None: |
| 419 | raise NotImplementedError() |
| Daniel Arndt | 0a28d98 | 2023-07-10 09:49:38 -0300 | [diff] [blame] | 420 | |
| 421 | |
| 422 | class GetModelNames(BaseActivity): |
| 423 | """Gets the models of VNFs associated with the NS. |
| 424 | |
| 425 | Collaborators: |
| 426 | DB read: vnfrs |
| 427 | |
| 428 | Raises (retryable): |
| 429 | DbException: If DB read operations fail |
| 430 | |
| 431 | Activity Lifecycle: |
| 432 | This activity should complete relatively quickly (less than a second). |
| 433 | |
| 434 | This activity will not report a heartbeat due to its |
| 435 | short-running nature. |
| 436 | |
| 437 | This is an idempotent activity. |
| 438 | """ |
| 439 | |
| 440 | @dataclass |
| 441 | class Input: |
| 442 | """ |
| 443 | Attributes: |
| 444 | ----------- |
| 445 | ns_uuid : str |
| 446 | The UUID of the NS from which we are looking for the model names. |
| 447 | """ |
| 448 | |
| 449 | ns_uuid: str |
| 450 | |
| 451 | @dataclass |
| 452 | class Output: |
| 453 | """ |
| 454 | Attributes: |
| 455 | ----------- |
| 456 | model_names: set[str] |
| 457 | The set of model names associated with the NS. |
| 458 | """ |
| 459 | |
| 460 | model_names: set[str] |
| 461 | |
| 462 | def __init__(self, db: DbBase): |
| 463 | super().__init__() |
| 464 | self.db: DbBase = db |
| 465 | |
| 466 | async def __call__(self, activity_input: Input) -> Output: |
| 467 | raise NotImplementedError() |