blob: 3400e941918dcbeacc722ff7cfaa49db7e9b6505 [file] [log] [blame]
Mark Beierl2bed6072023-04-05 20:01:41 +00001#######################################################################################
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 Faccinf5d65b52023-06-19 12:35:33 +020016
17from temporalio import activity
Mark Beierl2bed6072023-04-05 20:01:41 +000018import time
Gulsum Atici50d12e02023-04-27 16:41:43 +030019
Dario Faccinf5d65b52023-06-19 12:35:33 +020020from osm_common.temporal.activities.lcm import (
21 NsLcmNoOp,
22 UpdateNsLcmOperationState,
Mark Beierl2bed6072023-04-05 20:01:41 +000023)
Mark Beierl2bed6072023-04-05 20:01:41 +000024
25
Dario Faccinf5d65b52023-06-19 12:35:33 +020026class 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 Beierl2bed6072023-04-05 20:01:41 +000030
Mark Beierl2bed6072023-04-05 20:01:41 +000031
Dario Faccinf5d65b52023-06-19 12:35:33 +020032class UpdateNsLcmOperationStateImpl(UpdateNsLcmOperationState):
33 @activity.defn(name=UpdateNsLcmOperationState.__name__)
34 async def __call__(self, activity_input: UpdateNsLcmOperationState.Input):
Mark Beierl2bed6072023-04-05 20:01:41 +000035 now = time.time()
36
37 update_lcm_operation = {
38 "_admin.modified": now,
39 }
40
Dario Faccinf5d65b52023-06-19 12:35:33 +020041 if activity_input.op_state is not None:
42 update_lcm_operation["operationState"] = activity_input.op_state.name
Mark Beierl2bed6072023-04-05 20:01:41 +000043 update_lcm_operation["statusEnteredTime"] = now
44
Dario Faccinf5d65b52023-06-19 12:35:33 +020045 if activity_input.stage is not None:
46 update_lcm_operation["stage"] = activity_input.stage
Mark Beierl2bed6072023-04-05 20:01:41 +000047
Dario Faccinf5d65b52023-06-19 12:35:33 +020048 if activity_input.error_message is not None:
49 update_lcm_operation["errorMessage"] = activity_input.error_message
Mark Beierl2bed6072023-04-05 20:01:41 +000050
Dario Faccinf5d65b52023-06-19 12:35:33 +020051 if activity_input.detailed_status is not None:
52 update_lcm_operation["detailedStatus"] = activity_input.detailed_status
Mark Beierl2bed6072023-04-05 20:01:41 +000053
Dario Faccinf5d65b52023-06-19 12:35:33 +020054 self.db.set_one("nslcmops", {"_id": activity_input.op_id}, update_lcm_operation)
Mark Beierl2bed6072023-04-05 20:01:41 +000055 self.logger.debug(
Dario Faccinf5d65b52023-06-19 12:35:33 +020056 f"Updated LCM Operation {activity_input.op_id} to {update_lcm_operation}"
Mark Beierl2bed6072023-04-05 20:01:41 +000057 )