| Mark Beierl | 2bed607 | 2023-04-05 20:01:41 +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. |
| Dario Faccin | f5d65b5 | 2023-06-19 12:35:33 +0200 | [diff] [blame^] | 16 | |
| 17 | from temporalio import activity |
| Mark Beierl | 2bed607 | 2023-04-05 20:01:41 +0000 | [diff] [blame] | 18 | import time |
| Gulsum Atici | 50d12e0 | 2023-04-27 16:41:43 +0300 | [diff] [blame] | 19 | |
| Dario Faccin | f5d65b5 | 2023-06-19 12:35:33 +0200 | [diff] [blame^] | 20 | from osm_common.temporal.activities.lcm import ( |
| 21 | NsLcmNoOp, |
| 22 | UpdateNsLcmOperationState, |
| Mark Beierl | 2bed607 | 2023-04-05 20:01:41 +0000 | [diff] [blame] | 23 | ) |
| Mark Beierl | 2bed607 | 2023-04-05 20:01:41 +0000 | [diff] [blame] | 24 | |
| 25 | |
| Dario Faccin | f5d65b5 | 2023-06-19 12:35:33 +0200 | [diff] [blame^] | 26 | class NsLcmNoOpImpl(NsLcmNoOp): |
| 27 | @activity.defn(name=NsLcmNoOp.__name__) |
| 28 | async def __call__(self, activity_input: NsLcmNoOp.Input) -> None: |
| 29 | self.logger.debug(f"Called with: {activity_input.nslcmop}") |
| Mark Beierl | 2bed607 | 2023-04-05 20:01:41 +0000 | [diff] [blame] | 30 | |
| Mark Beierl | 2bed607 | 2023-04-05 20:01:41 +0000 | [diff] [blame] | 31 | |
| Dario Faccin | f5d65b5 | 2023-06-19 12:35:33 +0200 | [diff] [blame^] | 32 | class UpdateNsLcmOperationStateImpl(UpdateNsLcmOperationState): |
| 33 | @activity.defn(name=UpdateNsLcmOperationState.__name__) |
| 34 | async def __call__(self, activity_input: UpdateNsLcmOperationState.Input): |
| Mark Beierl | 2bed607 | 2023-04-05 20:01:41 +0000 | [diff] [blame] | 35 | now = time.time() |
| 36 | |
| 37 | update_lcm_operation = { |
| 38 | "_admin.modified": now, |
| 39 | } |
| 40 | |
| Dario Faccin | f5d65b5 | 2023-06-19 12:35:33 +0200 | [diff] [blame^] | 41 | if activity_input.op_state is not None: |
| 42 | update_lcm_operation["operationState"] = activity_input.op_state.name |
| Mark Beierl | 2bed607 | 2023-04-05 20:01:41 +0000 | [diff] [blame] | 43 | update_lcm_operation["statusEnteredTime"] = now |
| 44 | |
| Dario Faccin | f5d65b5 | 2023-06-19 12:35:33 +0200 | [diff] [blame^] | 45 | if activity_input.stage is not None: |
| 46 | update_lcm_operation["stage"] = activity_input.stage |
| Mark Beierl | 2bed607 | 2023-04-05 20:01:41 +0000 | [diff] [blame] | 47 | |
| Dario Faccin | f5d65b5 | 2023-06-19 12:35:33 +0200 | [diff] [blame^] | 48 | if activity_input.error_message is not None: |
| 49 | update_lcm_operation["errorMessage"] = activity_input.error_message |
| Mark Beierl | 2bed607 | 2023-04-05 20:01:41 +0000 | [diff] [blame] | 50 | |
| Dario Faccin | f5d65b5 | 2023-06-19 12:35:33 +0200 | [diff] [blame^] | 51 | if activity_input.detailed_status is not None: |
| 52 | update_lcm_operation["detailedStatus"] = activity_input.detailed_status |
| Mark Beierl | 2bed607 | 2023-04-05 20:01:41 +0000 | [diff] [blame] | 53 | |
| Dario Faccin | f5d65b5 | 2023-06-19 12:35:33 +0200 | [diff] [blame^] | 54 | self.db.set_one("nslcmops", {"_id": activity_input.op_id}, update_lcm_operation) |
| Mark Beierl | 2bed607 | 2023-04-05 20:01:41 +0000 | [diff] [blame] | 55 | self.logger.debug( |
| Dario Faccin | f5d65b5 | 2023-06-19 12:35:33 +0200 | [diff] [blame^] | 56 | f"Updated LCM Operation {activity_input.op_id} to {update_lcm_operation}" |
| Mark Beierl | 2bed607 | 2023-04-05 20:01:41 +0000 | [diff] [blame] | 57 | ) |