| Patricia Reinoso | 5243135 | 2023-04-05 15:35:48 +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 | |
| Dario Faccin | f5d65b5 | 2023-06-19 12:35:33 +0200 | [diff] [blame] | 17 | from temporalio import activity |
| Patricia Reinoso | 5243135 | 2023-04-05 15:35:48 +0000 | [diff] [blame] | 18 | from time import time |
| Daniel Arndt | c56d336 | 2023-04-18 11:26:16 -0300 | [diff] [blame] | 19 | |
| Dario Faccin | f5d65b5 | 2023-06-19 12:35:33 +0200 | [diff] [blame] | 20 | from osm_common.temporal.activities.ns import ( |
| 21 | GetNsRecord, |
| 22 | GetVnfDetails, |
| 23 | UpdateNsState, |
| Daniel Arndt | c56d336 | 2023-04-18 11:26:16 -0300 | [diff] [blame] | 24 | ) |
| Daniel Arndt | fde8513 | 2023-04-21 09:32:04 -0300 | [diff] [blame] | 25 | |
| Patricia Reinoso | 5243135 | 2023-04-05 15:35:48 +0000 | [diff] [blame] | 26 | |
| Mark Beierl | 8262942 | 2023-06-29 20:22:36 +0000 | [diff] [blame] | 27 | @activity.defn(name=GetVnfDetails.__name__) |
| Dario Faccin | f5d65b5 | 2023-06-19 12:35:33 +0200 | [diff] [blame] | 28 | class GetVnfDetailsImpl(GetVnfDetails): |
| Dario Faccin | f5d65b5 | 2023-06-19 12:35:33 +0200 | [diff] [blame] | 29 | async def __call__( |
| 30 | self, activity_input: GetVnfDetails.Input |
| 31 | ) -> GetVnfDetails.Output: |
| 32 | vnfrs = self.db.get_list("vnfrs", {"nsr-id-ref": activity_input.ns_uuid}) |
| 33 | return GetVnfDetails.Output( |
| Gulsum Atici | 50d12e0 | 2023-04-27 16:41:43 +0300 | [diff] [blame] | 34 | vnf_details=[(vnfr["id"], vnfr["member-vnf-index-ref"]) for vnfr in vnfrs] |
| Daniel Arndt | 0d2142a | 2023-04-20 17:14:58 -0300 | [diff] [blame] | 35 | ) |
| Gulsum Atici | 50d12e0 | 2023-04-27 16:41:43 +0300 | [diff] [blame] | 36 | |
| Gulsum Atici | 50d12e0 | 2023-04-27 16:41:43 +0300 | [diff] [blame] | 37 | |
| Mark Beierl | 8262942 | 2023-06-29 20:22:36 +0000 | [diff] [blame] | 38 | @activity.defn(name=GetNsRecord.__name__) |
| Dario Faccin | f5d65b5 | 2023-06-19 12:35:33 +0200 | [diff] [blame] | 39 | class GetNsRecordImpl(GetNsRecord): |
| Dario Faccin | f5d65b5 | 2023-06-19 12:35:33 +0200 | [diff] [blame] | 40 | async def __call__(self, activity_input: GetNsRecord.Input) -> GetNsRecord.Output: |
| 41 | nsr = self.db.get_one("nsrs", {"_id": activity_input.nsr_uuid}) |
| Gulsum Atici | 50d12e0 | 2023-04-27 16:41:43 +0300 | [diff] [blame] | 42 | self.logger.debug("Got the nsr from Database for VNF operations.") |
| Dario Faccin | f5d65b5 | 2023-06-19 12:35:33 +0200 | [diff] [blame] | 43 | return GetNsRecord.Output(nsr=nsr) |
| Patricia Reinoso | 5243135 | 2023-04-05 15:35:48 +0000 | [diff] [blame] | 44 | |
| 45 | |
| Mark Beierl | 8262942 | 2023-06-29 20:22:36 +0000 | [diff] [blame] | 46 | @activity.defn(name=UpdateNsState.__name__) |
| Dario Faccin | f5d65b5 | 2023-06-19 12:35:33 +0200 | [diff] [blame] | 47 | class UpdateNsStateImpl(UpdateNsState): |
| Dario Faccin | f5d65b5 | 2023-06-19 12:35:33 +0200 | [diff] [blame] | 48 | async def __call__(self, activity_input: UpdateNsState.Input) -> None: |
| Patricia Reinoso | 5243135 | 2023-04-05 15:35:48 +0000 | [diff] [blame] | 49 | update_ns_state = { |
| Dario Faccin | f5d65b5 | 2023-06-19 12:35:33 +0200 | [diff] [blame] | 50 | "nsState": activity_input.state.name, |
| Patricia Reinoso | 5243135 | 2023-04-05 15:35:48 +0000 | [diff] [blame] | 51 | # "errorDescription" : data.message, |
| Dario Faccin | f5d65b5 | 2023-06-19 12:35:33 +0200 | [diff] [blame] | 52 | "_admin.nsState": activity_input.state.name, |
| 53 | "_admin.detailed-status": activity_input.message, |
| Patricia Reinoso | 5243135 | 2023-04-05 15:35:48 +0000 | [diff] [blame] | 54 | "_admin.modified": time(), |
| 55 | } |
| Dario Faccin | f5d65b5 | 2023-06-19 12:35:33 +0200 | [diff] [blame] | 56 | self.db.set_one("nsrs", {"_id": activity_input.ns_uuid}, update_ns_state) |
| 57 | self.logger.debug( |
| 58 | f"Updated NS {activity_input.ns_uuid} to {activity_input.state.name}" |
| 59 | ) |