OSMENG-1155 Implementation of Constants and Dataclasses
[osm/common.git] / osm_common / temporal / activities / ns.py
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 #######################################################################################
17
18 from dataclasses import dataclass
19 from typing import List
20
21
22 from osm_common.dbbase import DbBase
23 from osm_common.temporal.activities.base import BaseActivity
24 from osm_common.temporal.states import NsState
25
26
27 class GetVnfDetails(BaseActivity):
28 """
29 Gets the list of VNF record IDs, VNF member-index-refs for a given NS record ID.
30
31 Collaborators:
32 DB Read: vnfrs
33
34 Raises (Retryable):
35 DbException If the target DB record does not exist or DB is not reachable.
36
37 Activity Lifecycle:
38 This activity will not report a heartbeat due to its short-running nature.
39
40 Since this activity only reads from the DB, it is safe to retry, although
41 you may wish to have some back-off policy.
42 """
43
44 @dataclass
45 class Input:
46 """
47 Attributes:
48 -----------
49 ns_uuid : str
50 The UUID of the NS from which to retrieve the VNF records.
51 """
52
53 ns_uuid: str
54
55 @dataclass
56 class Output:
57 """
58 Attributes:
59 -----------
60 vnf_details: list[(vnfr_ids: str, vnf_member_index_ref: str), .. ]
61 List of tuples including VNF details associated with the NS.
62 Tuple(VNF record IDs, vnf_member_index_ref)
63 """
64
65 vnf_details: List[tuple]
66
67 def __init__(self, db: DbBase):
68 super().__init__()
69 self.db: DbBase = db
70
71 async def __call__(self, activity_input: Input) -> Output:
72 raise NotImplementedError()
73
74
75 class GetNsRecord(BaseActivity):
76 """Gets the NS record from Database.
77
78 Collaborators:
79 DB Read: nsrs
80
81 Raises (retryable):
82 DbException: If DB read operations fail, the collection or DB record ID does not exist.
83
84 Activity Lifecycle:
85 This activity should complete relatively quickly (less than 10
86 second).
87
88 This activity will not report a heartbeat due to its
89 short-running nature.
90
91 This is an idempotent activity.
92
93 """
94
95 @dataclass
96 class Input:
97 """
98 Input dataclass for getting NS record activity.
99
100 Attributes:
101 -----------
102 nsr_uuid :
103 The UUID of the NS record which is stored in the OSM nsrs
104 collection in Mongo.
105
106 """
107
108 nsr_uuid: str
109
110 @dataclass
111 class Output:
112 """
113 Output dataclass for getting NS record activity.
114
115 Attributes:
116 -----------
117 nsr : dict
118 NS record retrieved from Database..
119
120 """
121
122 nsr: dict
123
124 def __init__(self, db: DbBase):
125 super().__init__()
126 self.db: DbBase = db
127
128 async def __call__(self, activity_input: Input) -> Output:
129 raise NotImplementedError()
130
131
132 class UpdateNsState(BaseActivity):
133 """
134 Changes the state of the NS itself.
135
136 Collaborators:
137 DB Write: nsrs
138
139 Raises (Retryable):
140 DbException If the target DB record does not exist or DB is not reachable.
141
142 Activity Lifecycle:
143 This activity will not report a heartbeat due to its
144 short-running nature.
145
146 As this is a direct DB update, it is not recommended to have
147 any specific retry policy
148 """
149
150 @dataclass
151 class Input:
152 """
153 Input dataclass for updating NS state in the DB
154
155 Attributes:
156 -----------
157 ns_uuid : str
158 The UUID of the NS as stored in the OSM ns
159 collection in Mongo
160
161 operational_state : NsState
162 A representation of the operational state (ENABLED or ERROR)
163 of the NS.
164
165 message : str
166 Human readable message providing additional details to the
167 operational state, such as the error message associated
168 with the ERROR operational_state.
169 """
170
171 ns_uuid: str
172 state: NsState
173 message: str
174
175 def __init__(self, db: DbBase):
176 super().__init__()
177 self.db: DbBase = db
178
179 async def __call__(self, activity_input: Input) -> None:
180 raise NotImplementedError()