OSMENG-1155 Implementation of Constants and Dataclasses
Add stubs for common elements, workflows and activities
Change-Id: If7a2aa8a6e6627df5293154bf48da742dea57e1c
Signed-off-by: Dario Faccin <dario.faccin@canonical.com>
diff --git a/osm_common/temporal/activities/vnf.py b/osm_common/temporal/activities/vnf.py
new file mode 100644
index 0000000..81f2982
--- /dev/null
+++ b/osm_common/temporal/activities/vnf.py
@@ -0,0 +1,420 @@
+#######################################################################################
+# Copyright ETSI Contributors and Others.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#######################################################################################
+
+from dataclasses import dataclass
+
+from osm_common.dbbase import DbBase
+from osm_common.temporal.activities.base import BaseActivity
+from osm_common.temporal.states import VnfInstantiationState, VnfState
+
+
+class ChangeVnfState(BaseActivity):
+ """Updates the VNF State in VNFR.
+
+ Collaborators:
+ DB Write: vnfrs
+
+ Raises (retryable):
+ DbException: If DB access/update fails, the collection or DB record ID does not exist.
+
+ Activity Lifecycle:
+ This activity should complete relatively quickly (less than a
+ second). However, it would be reasonable to wait up to 10
+ seconds.
+
+ This activity will not report a heartbeat due to its
+ short-running nature.
+
+ It is not necessary to implement a back-off strategy for this
+ activity, the operation is idempotent.
+
+ """
+
+ @dataclass
+ class Input:
+ """
+ Input dataclass for changing VNF State.
+
+ Attributes:
+ -----------
+ vnfr_uuid : str
+ The UUID of the VNF which is stored in the OSM vnfrs
+ collection in Mongo.
+
+ state : VnfState
+ A representation of the VNF state (STOPPED or STARTED).
+ """
+
+ vnfr_uuid: str
+ state: VnfState
+
+ def __init__(self, db: DbBase):
+ super().__init__()
+ self.db: DbBase = db
+
+ async def __call__(self, activity_input: Input) -> None:
+ raise NotImplementedError()
+
+
+class ChangeVnfInstantiationState(BaseActivity):
+ """Updates the VNF Instantiation State in VNFR.
+
+ Collaborators:
+ DB Write: vnfrs
+
+ Raises (retryable):
+ DbException: If DB access or update fails, the collection or DB record ID does not exist.
+
+ Activity Lifecycle:
+ This activity should complete relatively quickly (less than a
+ second). However, it would be reasonable to wait up to 10
+ seconds.
+
+ This activity will not report a heartbeat due to its
+ short-running nature.
+
+ It is not necessary to implement a back-off strategy for this
+ activity, the operation is idempotent.
+
+ """
+
+ @dataclass
+ class Input:
+ """
+ Input dataclass for changing VNF Instantiation State.
+
+ Attributes:
+ -----------
+ vnfr_uuid : str
+ The UUID of the VNF which is stored in the OSM vnfrs
+ collection in Mongo.
+
+ state : VnfInstantiationState
+ A representation of the VNF instantiation state (NOT_INSTANTIATED or INSTANTIATED).
+
+ """
+
+ vnfr_uuid: str
+ state: VnfInstantiationState
+
+ def __init__(self, db: DbBase):
+ super().__init__()
+ self.db: DbBase = db
+
+ async def __call__(self, activity_input: Input) -> None:
+ raise NotImplementedError()
+
+
+class GetVnfRecord(BaseActivity):
+ """Gets the VNF record and VNF descriptor from Database.
+
+ Collaborators:
+ DB read: vnfrs, vnfds
+
+ Raises (retryable):
+ DbException: If DB read operations fail, the collection or DB record ID does not exist.
+
+ Activity Lifecycle:
+ This activity should complete relatively quickly (less than 10
+ second).
+
+ This activity will not report a heartbeat due to its
+ short-running nature.
+
+ This is an idempotent activity.
+
+ """
+
+ @dataclass
+ class Input:
+ """
+ Input dataclass for get vnf details activity.
+
+ Attributes:
+ -----------
+ vnfr_uuid : str
+ The UUID of the VNF which is stored in the OSM vnfrs
+ collection in Mongo.
+ """
+
+ vnfr_uuid: str
+
+ @dataclass
+ class Output:
+ """
+ Output dataclass for get vnf details activity.
+
+ Attributes:
+ -----------
+ vnf_details: list[(vnfr_ids: str, vnf_member_index_ref: str), .. ]
+ List of tuples including VNF details associated with the NS.
+ Tuple(VNF record IDs, vnf_member_index_ref)
+ """
+
+ vnfr: dict
+
+ def __init__(self, db: DbBase):
+ super().__init__()
+ self.db: DbBase = db
+
+ async def __call__(self, activity_input: Input) -> Output:
+ raise NotImplementedError()
+
+
+class GetVnfDescriptor(BaseActivity):
+ """Gets the VNF record and VNF descriptor from Database.
+
+ Collaborators:
+ DB read: vnfrs
+
+ Raises (retryable):
+ DbException: If DB read operations fail, the collection or DB record ID does not exist.
+
+ Activity Lifecycle:
+ This activity should complete relatively quickly (less than 10
+ second).
+
+ This activity will not report a heartbeat due to its
+ short-running nature.
+
+ This is an idempotent activity.
+
+ """
+
+ @dataclass
+ class Input:
+ """
+ Input dataclass for get vnf descriptor activity.
+
+ Attributes:
+ -----------
+ vnfd_uuid : str
+ The UUID of the VNF descriptor which is stored in the OSM vnfds
+ collection in Mongo.
+ """
+
+ vnfd_uuid: str
+
+ @dataclass
+ class Output:
+ """
+ Output dataclass for get vnf details activity.
+
+ Attributes:
+ -----------
+ vnfd : dict
+ VNF descriptor retrieved from Database.
+ """
+
+ vnfd: dict
+
+ def __init__(self, db: DbBase):
+ super().__init__()
+ self.db: DbBase = db
+
+ async def __call__(self, activity_input: Input) -> Output:
+ raise NotImplementedError()
+
+
+class SendNotificationForVnf(BaseActivity):
+ """Perform Notification operations."""
+
+ @dataclass
+ class Input:
+ """
+ Input dataclass for sending notifications for change in VNF Instantiation State.
+
+ Attributes:
+ -----------
+ vnfr_uuid : str
+ The UUID of the VNF which is stored in the OSM vnfrs
+ collection in Mongo.
+
+ state : VnfInstantiationState
+ A representation of the VNF instantiation state (NOT_INSTANTIATED or INSTANTIATED).
+
+ """
+
+ vnfr_uuid: str
+ state: VnfState
+
+ async def __call__(self, activity_input: Input):
+ raise NotImplementedError()
+
+
+class GetTaskQueue(BaseActivity):
+ """Finds the appropriate task queue according to VIM type of VNF.
+
+ Collaborators:
+ DB read: vim_accounts, vnfrs
+
+ Raises (retryable):
+ DbException: If DB read operations fail, the collection or DB record ID does not exist.
+
+ Activity Lifecycle:
+ This activity should complete relatively quickly (less than a
+ second). However, it would be reasonable to wait up to 10
+ seconds.
+
+ This activity will not report a heartbeat due to its
+ short-running nature.
+
+ It is not necessary to implement a back-off strategy for this
+ activity, the operation is idempotent.
+
+ """
+
+ @dataclass
+ class Input:
+ """
+ Input dataclass for get task queue activity.
+
+ Attributes:
+ -----------
+ vnfr_uuid : str
+ The UUID of the VNF which is stored in the OSM vnfrs
+ collection in Mongo.
+
+ """
+
+ vnfr_uuid: str
+
+ @dataclass
+ class Output:
+ """
+ Output dataclass for get task queue activity.
+
+ Attributes:
+ -----------
+ task_queue : str
+ Name of the queue which is used to Deploy VNF.
+ """
+
+ task_queue: str
+
+ def __init__(self, db: DbBase):
+ super().__init__()
+ self.db: DbBase = db
+
+ async def __call__(self, activity_input: Input) -> Output:
+ raise NotImplementedError()
+
+
+class GetVimCloud(BaseActivity):
+ """Finds the cloud by checking the VIM account of VNF.
+
+ Collaborators:
+ DB Read: vnfrs, vim_accounts
+
+ Raises (retryable):
+ DbException: If DB read operations fail, the collection or DB record ID does not exist.
+
+ Activity Lifecycle:
+ This activity should complete relatively quickly (less than a
+ second). However, it would be reasonable to wait up to 10
+ seconds.
+
+ This activity will not report a heartbeat due to its
+ short-running nature.
+
+ It is not necessary to implement a back-off strategy for this
+ activity, the operation is idempotent.
+
+ """
+
+ @dataclass
+ class Input:
+ """
+ Input dataclass for get vim cloud activity.
+
+ Attributes:
+ -----------
+ vnfr_uuid : str
+ The UUID of the VNF which is stored in the OSM vnfrs
+ collection in Mongo.
+
+ """
+
+ vnfr_uuid: str
+
+ @dataclass
+ class Output:
+ """
+ Output dataclass for get vim cloud activity.
+
+ Attributes:
+ -----------
+ cloud : str
+ Type of the cloud which is used to Deploy VNF.
+ """
+
+ cloud: str
+
+ def __init__(self, db: DbBase):
+ super().__init__()
+ self.db: DbBase = db
+
+ async def __call__(self, activity_input: Input) -> Output:
+ raise NotImplementedError()
+
+
+class SetVnfModel(BaseActivity):
+ """Updates the model name of VNF in VNFR.
+
+ Collaborators:
+ DB Write: vnfrs
+
+ Raises (retryable):
+ DbException: If DB access or update fails, the collection or DB record ID does not exist.
+
+ Activity Lifecycle:
+ This activity should complete relatively quickly (less than a
+ second). However, it would be reasonable to wait up to 10
+ seconds.
+
+ This activity will not report a heartbeat due to its
+ short-running nature.
+
+ It is not necessary to implement a back-off strategy for this
+ activity, the operation is idempotent.
+
+ """
+
+ @dataclass
+ class Input:
+ """
+ Input dataclass for workflow that instantiates a VNF.
+
+ Attributes:
+ -----------
+ vnfr_uuid : str
+ The UUID of the VNF which is stored in the OSM vnfrs
+ collection in Mongo.
+
+ model_name: str
+
+ """
+
+ vnfr_uuid: str
+ model_name: str
+
+ def __init__(self, db: DbBase):
+ super().__init__()
+ self.db: DbBase = db
+
+ async def __call__(self, activity_input: Input) -> None:
+ raise NotImplementedError()