blob: 265a9c149460aa7da61df7306eab2d201cfeff4f [file] [log] [blame]
Dario Faccin989602b2023-06-20 16:12:29 +02001#######################################################################################
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
18from dataclasses import dataclass
19from typing import List
20
21
22from osm_common.dbbase import DbBase
23from osm_common.temporal.activities.base import BaseActivity
24from osm_common.temporal.states import NsState
25
26
27class 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
75class 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
132class 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()
gaticie56853b2023-07-26 15:07:09 +0300181
182
183class DeleteNsRecord(BaseActivity):
184 """Delete a NS record from DB.
185
186 Collaborators:
187 DB Write: nsrs
188
189 Raises (retryable):
190 DbException: If DB access fails, the collection does not exist.
191
192 Activity Lifecycle:
193 This activity should complete relatively quickly (less than a
194 second). However, it would be reasonable to wait up to 10
195 seconds.
196
197 This activity will not report a heartbeat due to its
198 short-running nature.
199
200 This operation is idempotent.
201
202 """
203
204 @dataclass
205 class Input:
206 """
207 Input dataclass for activity that deletes a NS record.
208
209 Attributes:
210 -----------
211 ns_uuid : str
212 The UUID of the NS to be deleted from the nsrs
213 collection in Mongo.
214 """
215
216 ns_uuid: str
217
218 def __init__(self, db: DbBase):
219 super().__init__()
220 self.db: DbBase = db
221
222 async def __call__(self, activity_input: Input) -> None:
223 raise NotImplementedError()