| Patricia Reinoso | 02a39fd | 2023-03-08 17:13:56 +0000 | [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 | |
| Gulsum Atici | 50d12e0 | 2023-04-27 16:41:43 +0300 | [diff] [blame] | 17 | from temporalio import activity |
| Dario Faccin | f5d65b5 | 2023-06-19 12:35:33 +0200 | [diff] [blame] | 18 | from time import time |
| 19 | from osm_common.temporal.activities.vim import ( |
| 20 | UpdateVimState, |
| 21 | UpdateVimOperationState, |
| 22 | DeleteVimRecord, |
| 23 | ) |
| Patricia Reinoso | 02a39fd | 2023-03-08 17:13:56 +0000 | [diff] [blame] | 24 | |
| Patricia Reinoso | 02a39fd | 2023-03-08 17:13:56 +0000 | [diff] [blame] | 25 | |
| Mark Beierl | 8262942 | 2023-06-29 20:22:36 +0000 | [diff] [blame] | 26 | @activity.defn(name=UpdateVimState.__name__) |
| Dario Faccin | f5d65b5 | 2023-06-19 12:35:33 +0200 | [diff] [blame] | 27 | class UpdateVimStateImpl(UpdateVimState): |
| Dario Faccin | f5d65b5 | 2023-06-19 12:35:33 +0200 | [diff] [blame] | 28 | async def __call__(self, activity_input: UpdateVimState.Input) -> None: |
| Patricia Reinoso | 02a39fd | 2023-03-08 17:13:56 +0000 | [diff] [blame] | 29 | update_vim_state = { |
| Dario Faccin | f5d65b5 | 2023-06-19 12:35:33 +0200 | [diff] [blame] | 30 | "_admin.operationalState": activity_input.operational_state.name, |
| 31 | "_admin.detailed-status": activity_input.message, |
| Patricia Reinoso | 02a39fd | 2023-03-08 17:13:56 +0000 | [diff] [blame] | 32 | "_admin.modified": time(), |
| 33 | } |
| 34 | |
| Dario Faccin | f5d65b5 | 2023-06-19 12:35:33 +0200 | [diff] [blame] | 35 | self.db.set_one( |
| 36 | "vim_accounts", {"_id": activity_input.vim_uuid}, update_vim_state |
| 37 | ) |
| Mark Beierl | 0c202d2 | 2023-04-06 13:58:31 +0000 | [diff] [blame] | 38 | self.logger.debug( |
| Dario Faccin | f5d65b5 | 2023-06-19 12:35:33 +0200 | [diff] [blame] | 39 | f"Updated VIM {activity_input.vim_uuid} to {activity_input.operational_state.name}" |
| Patricia Reinoso | 02a39fd | 2023-03-08 17:13:56 +0000 | [diff] [blame] | 40 | ) |
| 41 | |
| Patricia Reinoso | 02a39fd | 2023-03-08 17:13:56 +0000 | [diff] [blame] | 42 | |
| Mark Beierl | 8262942 | 2023-06-29 20:22:36 +0000 | [diff] [blame] | 43 | @activity.defn(name=UpdateVimOperationState.__name__) |
| Dario Faccin | f5d65b5 | 2023-06-19 12:35:33 +0200 | [diff] [blame] | 44 | class UpdateVimOperationStateImpl(UpdateVimOperationState): |
| Dario Faccin | f5d65b5 | 2023-06-19 12:35:33 +0200 | [diff] [blame] | 45 | async def __call__(self, activity_input: UpdateVimOperationState.Input) -> None: |
| Patricia Reinoso | 02a39fd | 2023-03-08 17:13:56 +0000 | [diff] [blame] | 46 | update_operation_state = { |
| Dario Faccin | f5d65b5 | 2023-06-19 12:35:33 +0200 | [diff] [blame] | 47 | f"_admin.operations.{format(activity_input.op_id)}.operationState": activity_input.op_state.name, |
| 48 | f"_admin.operations.{format(activity_input.op_id)}.detailed-status": activity_input.message, |
| Patricia Reinoso | 02a39fd | 2023-03-08 17:13:56 +0000 | [diff] [blame] | 49 | "_admin.current_operation": None, |
| 50 | } |
| 51 | |
| Dario Faccin | f5d65b5 | 2023-06-19 12:35:33 +0200 | [diff] [blame] | 52 | self.db.set_one( |
| 53 | "vim_accounts", {"_id": activity_input.vim_uuid}, update_operation_state |
| 54 | ) |
| Mark Beierl | 0c202d2 | 2023-04-06 13:58:31 +0000 | [diff] [blame] | 55 | self.logger.debug( |
| Dario Faccin | f5d65b5 | 2023-06-19 12:35:33 +0200 | [diff] [blame] | 56 | f"Updated VIM {activity_input.vim_uuid} OP ID {activity_input.op_id} to {activity_input.op_state.name}" |
| Patricia Reinoso | 02a39fd | 2023-03-08 17:13:56 +0000 | [diff] [blame] | 57 | ) |
| 58 | |
| Patricia Reinoso | 02a39fd | 2023-03-08 17:13:56 +0000 | [diff] [blame] | 59 | |
| Mark Beierl | 8262942 | 2023-06-29 20:22:36 +0000 | [diff] [blame] | 60 | @activity.defn(name=DeleteVimRecord.__name__) |
| Dario Faccin | f5d65b5 | 2023-06-19 12:35:33 +0200 | [diff] [blame] | 61 | class DeleteVimRecordImpl(DeleteVimRecord): |
| Dario Faccin | f5d65b5 | 2023-06-19 12:35:33 +0200 | [diff] [blame] | 62 | async def __call__(self, activity_input: DeleteVimRecord.Input) -> None: |
| 63 | self.db.del_one("vim_accounts", {"_id": activity_input.vim_uuid}) |
| 64 | self.logger.debug(f"Removed VIM {activity_input.vim_uuid}") |