| 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 VimOperationState, VimState |
| 23 | |
| 24 | |
| 25 | class UpdateVimState(BaseActivity): |
| 26 | """ |
| 27 | Changes the state of the VIM itself. Should be either |
| 28 | ENABLED or ERROR, however this activity does not validate |
| 29 | the state as no validation was done in OSM previously. |
| 30 | |
| 31 | Collaborators: |
| 32 | DB Write: vim_accounts |
| 33 | |
| 34 | Raises (Retryable): |
| 35 | DbException If the target DB record does not exist or DB is not reachable. |
| 36 | |
| 37 | Activity Lifecycle: |
| 38 | This activity will not report a heartbeat due to its |
| 39 | short-running nature. |
| 40 | |
| 41 | As this is a direct DB update, it is not recommended to have |
| 42 | any specific retry policy |
| 43 | """ |
| 44 | |
| 45 | @dataclass |
| 46 | class Input: |
| 47 | """ |
| 48 | Input dataclass for updating VIM state in the DB |
| 49 | |
| 50 | Attributes: |
| 51 | ----------- |
| 52 | vim_uuid : str |
| 53 | The UUID of the VIM account as stored in the OSM vim |
| 54 | collection in Mongo |
| 55 | |
| 56 | operational_state : VimState |
| 57 | A representation of the operational state (ENABLED or ERROR) |
| 58 | of the VIM. |
| 59 | |
| 60 | message : str |
| 61 | Human readable message providing additional details to the |
| 62 | operational state, such as the error message associated |
| 63 | with the ERROR operational_state. |
| 64 | """ |
| 65 | |
| 66 | vim_uuid: str |
| 67 | operational_state: VimState |
| 68 | message: str |
| 69 | |
| 70 | def __init__(self, db: DbBase): |
| 71 | super().__init__() |
| 72 | self.db: DbBase = db |
| 73 | |
| 74 | async def __call__(self, activity_input: Input) -> None: |
| 75 | raise NotImplementedError() |
| 76 | |
| 77 | |
| 78 | class UpdateVimOperationState(BaseActivity): |
| 79 | """ |
| 80 | Changes the state of a VIM operation task. Should be done to |
| 81 | indicate progress, or completion of the task itself. |
| 82 | |
| 83 | Collaborators: |
| 84 | DB Write: vim_accounts |
| 85 | |
| 86 | Raises (Retryable): |
| 87 | DbException If the target DB record does not exist or DB is not reachable. |
| 88 | |
| 89 | Activity Lifecycle: |
| 90 | This activity will not report a heartbeat due to its |
| 91 | short-running nature. |
| 92 | |
| 93 | As this is a direct DB update, it is not recommended to have |
| 94 | any specific retry policy |
| 95 | """ |
| 96 | |
| 97 | @dataclass |
| 98 | class Input: |
| 99 | """ |
| 100 | Input dataclass for updating VIM Operations in the Mongo VIM |
| 101 | collection. |
| 102 | |
| 103 | Attributes: |
| 104 | ----------- |
| 105 | vim_uuid : str |
| 106 | The UUID of the VIM account as stored in the OSM vim |
| 107 | collection in Mongo |
| 108 | |
| 109 | op_id: str |
| 110 | The operation (task) id for this workflow. This is used |
| 111 | to update the status of the operation in Mongo vim collection. |
| 112 | |
| 113 | op_state : VimOperationState |
| 114 | A representation of the state of the specified operation id, |
| 115 | such as COMPLETED, or FAILED. |
| 116 | |
| 117 | message : str |
| 118 | Human readable message providing additional details to the |
| 119 | operation state, such as the error message explaining why |
| 120 | the operation failed. |
| 121 | """ |
| 122 | |
| 123 | vim_uuid: str |
| 124 | op_id: str |
| 125 | op_state: VimOperationState |
| 126 | message: str |
| 127 | |
| 128 | def __init__(self, db: DbBase): |
| 129 | super().__init__() |
| 130 | self.db: DbBase = db |
| 131 | |
| 132 | async def __call__(self, activity_input: Input) -> None: |
| 133 | raise NotImplementedError() |
| 134 | |
| 135 | |
| 136 | class DeleteVimRecord(BaseActivity): |
| 137 | """ |
| 138 | Deletes the VIM record from the database. |
| 139 | |
| 140 | Collaborators: |
| 141 | DB Delete: vim_accounts |
| 142 | |
| 143 | Raises (Retryable): |
| 144 | DbException If the target DB record does not exist or DB is not reachable. |
| 145 | |
| 146 | Activity Lifecycle: |
| 147 | This activity will not report a heartbeat due to its |
| 148 | short-running nature. |
| 149 | |
| 150 | As this is a direct DB update, it is not recommended to have |
| 151 | any specific retry policy |
| 152 | """ |
| 153 | |
| 154 | @dataclass |
| 155 | class Input: |
| 156 | """ |
| 157 | Input dataclass for deleting vim record from the database |
| 158 | |
| 159 | Attributes: |
| 160 | ----------- |
| 161 | vim_uuid : str |
| 162 | The UUID of the VIM account as stored in the OSM vim |
| 163 | collection in Mongo |
| 164 | |
| 165 | """ |
| 166 | |
| 167 | vim_uuid: str |
| 168 | |
| 169 | def __init__(self, db: DbBase): |
| 170 | super().__init__() |
| 171 | self.db: DbBase = db |
| 172 | |
| 173 | async def __call__(self, activity_input: Input) -> None: |
| 174 | raise NotImplementedError() |