From: Mark Beierl Date: Wed, 5 Apr 2023 20:07:58 +0000 (+0000) Subject: NS LCM OP Workflow wrapper X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F60%2F13160%2F2;p=osm%2FNBI.git NS LCM OP Workflow wrapper Change-Id: Id939efeccb4c02874436fc95f164e33b1667064d Signed-off-by: Mark Beierl --- diff --git a/osm_nbi/instance_topics.py b/osm_nbi/instance_topics.py index f9539dd..c2cd9dd 100644 --- a/osm_nbi/instance_topics.py +++ b/osm_nbi/instance_topics.py @@ -48,6 +48,7 @@ from osm_nbi import utils from re import ( match, ) # For checking that additional parameter names are valid Jinja2 identifiers +from osm_nbi.temporal.nbi_temporal import NbiTemporal __author__ = "Alfonso Tierno " @@ -1173,6 +1174,7 @@ class NsLcmOpTopic(BaseTopic): def __init__(self, db, fs, msg, auth): BaseTopic.__init__(self, db, fs, msg, auth) self.nsrtopic = NsrTopic(db, fs, msg, auth) + self.temporal = NbiTemporal() def _check_ns_operation(self, session, nsr, operation, indata): """ @@ -2325,8 +2327,21 @@ class NsLcmOpTopic(BaseTopic): self.db.create("nslcmops", nslcmop_desc) rollback.append({"topic": "nslcmops", "_id": _id}) if not slice_object: + if "instantiate_params" in nsr: + if "vimAccountId" in nsr["instantiate_params"]: + vim = self._get_vim_account( + vim_id=nsr["instantiate_params"]["vimAccountId"], + session=session, + ) + if vim["vim_type"] == "paas": + self.logger.info("Starting {} workflow".format(operation)) + self.temporal.start_ns_workflow(nslcmop_desc) + return _id, None self.msg.write("ns", operation, nslcmop_desc) return _id, None + except ValidationError as e: # TODO remove try Except, it is captured at nbi.py + raise EngineException(e, HTTPStatus.UNPROCESSABLE_ENTITY) + return _id, None except ValidationError as e: # TODO remove try Except, it is captured at nbi.py raise EngineException(e, HTTPStatus.UNPROCESSABLE_ENTITY) # except DbException as e: diff --git a/osm_nbi/temporal/nbi_temporal.py b/osm_nbi/temporal/nbi_temporal.py index af654ea..9f4e4d9 100644 --- a/osm_nbi/temporal/nbi_temporal.py +++ b/osm_nbi/temporal/nbi_temporal.py @@ -14,12 +14,16 @@ # limitations under the License. import asyncio -from osm_common.dataclasses.temporal_dataclasses import VimOperationInput +from osm_common.dataclasses.temporal_dataclasses import ( + NsLcmOperationInput, + VimOperationInput, +) from osm_common.temporal_constants import ( LCM_TASK_QUEUE, WORKFLOW_VIM_CREATE, WORKFLOW_VIM_DELETE, WORKFLOW_VIM_UPDATE, + WORKFLOW_NSLCM_NO_OP, ) from osm_common.wftemporal import WFTemporal @@ -49,3 +53,38 @@ class NbiTemporal: id=vim_uuid, ) ) + + lcm_workflow_mappings = { + "instantiate": WORKFLOW_NSLCM_NO_OP, + "terminate": WORKFLOW_NSLCM_NO_OP, + "vca_status_refresh": WORKFLOW_NSLCM_NO_OP, + "action": WORKFLOW_NSLCM_NO_OP, + "update": WORKFLOW_NSLCM_NO_OP, + "scale": WORKFLOW_NSLCM_NO_OP, + "heal": WORKFLOW_NSLCM_NO_OP, + "migrate": WORKFLOW_NSLCM_NO_OP, + "verticalscale": WORKFLOW_NSLCM_NO_OP, + "deleted": WORKFLOW_NSLCM_NO_OP, + "vnf_terminated": WORKFLOW_NSLCM_NO_OP, + "policy_updated": WORKFLOW_NSLCM_NO_OP, + "terminated": WORKFLOW_NSLCM_NO_OP, + "instantiated": WORKFLOW_NSLCM_NO_OP, + "scaled": WORKFLOW_NSLCM_NO_OP, + "healed": WORKFLOW_NSLCM_NO_OP, + "actioned": WORKFLOW_NSLCM_NO_OP, + "updated": WORKFLOW_NSLCM_NO_OP, + "migrated": WORKFLOW_NSLCM_NO_OP, + "verticalscaled": WORKFLOW_NSLCM_NO_OP, + } + + def start_ns_workflow(self, nslcmop: dict) -> None: + asyncio.run( + WFTemporal(logger_name="nbi.lcm_workflow").start_workflow( + task_queue=LCM_TASK_QUEUE, + workflow_name=NbiTemporal.lcm_workflow_mappings[ + nslcmop["lcmOperationType"] + ], + workflow_data=NsLcmOperationInput(nslcmop=nslcmop), + id=nslcmop["_id"], + ) + )