Fix Bug 2308: Incorrect status update for user update
[osm/NBI.git] / temporal / nbi_temporal.py
1 # -*- coding: utf-8 -*-
2
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12 # implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 import asyncio
17 from osm_common.dataclasses.temporal_dataclasses import (
18 NsLcmOperationInput,
19 VimOperationInput,
20 )
21 from osm_common.temporal_constants import (
22 LCM_TASK_QUEUE,
23 WORKFLOW_VIM_CREATE,
24 WORKFLOW_VIM_DELETE,
25 WORKFLOW_VIM_UPDATE,
26 WORKFLOW_NSLCM_NO_OP,
27 )
28 from osm_common.wftemporal import WFTemporal
29
30
31 class NbiTemporal:
32 workflow_mappings = {
33 "created": WORKFLOW_VIM_CREATE,
34 "edited": WORKFLOW_VIM_UPDATE,
35 "delete": WORKFLOW_VIM_DELETE,
36 }
37
38 def start_vim_workflow(self, action: str, content: dict) -> None:
39 vim_uuid = content["_id"]
40 # Derive the operation id (although for a create it will always be 0)
41 op_id = content["op_id"].split(":")[1]
42
43 workflow = NbiTemporal.workflow_mappings[action]
44
45 if workflow is not None:
46 workflow_data = VimOperationInput(vim_uuid, op_id)
47
48 asyncio.run(
49 WFTemporal(logger_name="nbi.vim_workflow").start_workflow(
50 task_queue=LCM_TASK_QUEUE,
51 workflow_name=workflow,
52 workflow_data=workflow_data,
53 id=vim_uuid,
54 )
55 )
56
57 lcm_workflow_mappings = {
58 "instantiate": WORKFLOW_NSLCM_NO_OP,
59 "terminate": WORKFLOW_NSLCM_NO_OP,
60 "vca_status_refresh": WORKFLOW_NSLCM_NO_OP,
61 "action": WORKFLOW_NSLCM_NO_OP,
62 "update": WORKFLOW_NSLCM_NO_OP,
63 "scale": WORKFLOW_NSLCM_NO_OP,
64 "heal": WORKFLOW_NSLCM_NO_OP,
65 "migrate": WORKFLOW_NSLCM_NO_OP,
66 "verticalscale": WORKFLOW_NSLCM_NO_OP,
67 "deleted": WORKFLOW_NSLCM_NO_OP,
68 "vnf_terminated": WORKFLOW_NSLCM_NO_OP,
69 "policy_updated": WORKFLOW_NSLCM_NO_OP,
70 "terminated": WORKFLOW_NSLCM_NO_OP,
71 "instantiated": WORKFLOW_NSLCM_NO_OP,
72 "scaled": WORKFLOW_NSLCM_NO_OP,
73 "healed": WORKFLOW_NSLCM_NO_OP,
74 "actioned": WORKFLOW_NSLCM_NO_OP,
75 "updated": WORKFLOW_NSLCM_NO_OP,
76 "migrated": WORKFLOW_NSLCM_NO_OP,
77 "verticalscaled": WORKFLOW_NSLCM_NO_OP,
78 }
79
80 def start_ns_workflow(self, nslcmop: dict) -> None:
81 asyncio.run(
82 WFTemporal(logger_name="nbi.lcm_workflow").start_workflow(
83 task_queue=LCM_TASK_QUEUE,
84 workflow_name=NbiTemporal.lcm_workflow_mappings[
85 nslcmop["lcmOperationType"]
86 ],
87 workflow_data=NsLcmOperationInput(nslcmop=nslcmop),
88 id=nslcmop["_id"],
89 )
90 )