\r
from o2app import bootstrap\r
from o2ims.views import ocloud_route as ims_route\r
-from o2dms.views import configure_namespace as dms_route_configure_namespace\r
+from o2dms.api import configure_namespace as dms_route_configure_namespace\r
\r
\r
# apibase = config.get_o2ims_api_base()\r
# limitations under the License.
# import json
+from logging import log
import redis
-
+import json
from o2app import bootstrap
from o2common.config import config
# from o2common.domain import commands
+from o2dms.domain import commands
+from o2dms.domain import events
from o2common.helper import o2logging
logger = o2logging.get_logger(__name__)
logger.info("Redis pubsub starting")
bus = bootstrap.bootstrap()
pubsub = r.pubsub(ignore_subscribe_messages=True)
- pubsub.subscribe("dms_changed")
+ pubsub.subscribe("NfDeploymentCreated")
for m in pubsub.listen():
- handle_dms_changed(m, bus)
+ try:
+ handle_dms_changed(m, bus)
+ except Exception as ex:
+ logger.warning("{}".format(str(ex)))
+ continue
def handle_dms_changed(m, bus):
logger.info("handling %s", m)
+ channel = m['channel'].decode("UTF-8")
+ if channel == "NfDeploymentCreated":
+ datastr = m['data']
+ data = json.loads(datastr)
+ logger.info('InstallNfDeployment with cmd:{}'.format(data))
+ cmd = commands.InstallNfDeployment(NfDeploymentId = data['NfDeploymentId'])
+ bus.handle(cmd)
+ else:
+ logger.info("unhandled:{}".format(channel))
# data = json.loads(m["data"])
# cmd = commands.UpdateDms(ref=data["dmsid"])
# bus.handle(cmd)
from typing import List, Dict, Callable, Type
# TYPE_CHECKING
from o2ims.domain import commands, events
+
+from o2dms.domain import commands as o2dms_cmmands
+from o2dms.domain import events as o2dms_events
from o2ims.service.auditor import ocloud_handler, dms_handler, \
resourcepool_handler, pserver_handler, pserver_cpu_handler, \
pserver_mem_handler, pserver_port_handler, pserver_if_handler
+from o2dms.service.nfdeployment_handler import publish_nfdeployment_created
+from o2dms.service.nfdeployment_handler import install_nfdeployment
# if TYPE_CHECKING:
# from . import unit_of_work
EVENT_HANDLERS = {
-} # type: Dict[Type[events.Event], List[Callable]]
+ o2dms_events.NfDeploymentCreated: [publish_nfdeployment_created]
+}
COMMAND_HANDLERS = {
commands.UpdatePserverMem: pserver_mem_handler.update_pserver_mem,
commands.UpdatePserverIf: pserver_if_handler.update_pserver_if,
commands.UpdatePserverPort: pserver_port_handler.update_pserver_port,
+ o2dms_cmmands.InstallNfDeployment: install_nfdeployment
+
} # type: Dict[Type[commands.Command], Callable]
id=nfdeployment_desc_id
).delete()
+ def _count(self, **kwargs):
+ return self.session.query(
+ dms.NfDeploymentDesc).filter_by(**kwargs).count()
+
class NfDeploymentSqlAlchemyRepository(
dms_repo.NfDeploymentRepository):
id=nfdeployment_id
).delete()
+ def _count(self, **kwargs):
+ return self.session.query(
+ dms.NfDeployment).filter_by(**kwargs).count()
+
class NfOCloudVResourceSqlAlchemyRepository(
dms_repo.NfOCloudVResourceRepository):
Column("description", String(255)),\r
Column("inputParams", String(255)),\r
Column("outputParams", String(255)),\r
+ Column("artifactUrl", String(255)),\r
# Column("extensions", String(1024))\r
)\r
\r
--- /dev/null
+# Copyright (C) 2021 Wind River Systems, Inc.\r
+#\r
+# Licensed under the Apache License, Version 2.0 (the "License");\r
+# you may not use this file except in compliance with the License.\r
+# You may obtain a copy of the License at\r
+#\r
+# http://www.apache.org/licenses/LICENSE-2.0\r
+#\r
+# Unless required by applicable law or agreed to in writing, software\r
+# distributed under the License is distributed on an "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+# See the License for the specific language governing permissions and\r
+# limitations under the License.\r
+\r
+from o2dms.api.dms_api_ns import api_dms_lcm_v1\r
+from . import dms_route\r
+from . import nfdeployment_desc_route\r
+from . import nfdeployment_route\r
+from o2common.config import config\r
+\r
+from o2common.helper import o2logging\r
+logger = o2logging.get_logger(__name__)\r
+\r
+\r
+def configure_namespace(app):\r
+ apibase = config.get_o2dms_api_base()\r
+ logger.info(\r
+ "Expose O2DMS API:{}".format(apibase))\r
+\r
+ dms_route.configure_api_route()\r
+ nfdeployment_desc_route.configure_api_route()\r
+ nfdeployment_route.configure_api_route()\r
+ app.add_namespace(api_dms_lcm_v1, path=apibase)\r
--- /dev/null
+from flask_restx import Namespace\r
+\r
+\r
+api_dms_lcm_v1 = Namespace(\r
+ "O2DMS_LCM", description='DMS LCM related operations.')\r
# limitations under the License.
from flask_restx import fields
-from o2dms.views import api_dms_lcm_v1
+from o2dms.api.dms_api_ns import api_dms_lcm_v1
+from o2common.helper import o2logging
+logger = o2logging.get_logger(__name__)
class DmsDTO:
'name': fields.String,
'description': fields.String,
'inputParams': fields.String,
- 'outputParams': fields.String
+ 'outputParams': fields.String,
+ 'artifactUrl': fields.String
}
)
{
'name': fields.String,
'description': fields.String,
+ 'artifactUrl': fields.String,
'inputParams': fields.String,
'outputParams': fields.String
}
{
'name': fields.String,
'description': fields.String,
+ 'artifactUrl': fields.String,
'inputParams': fields.String,
'outputParams': fields.String
}
{
'name': fields.String,
'description': fields.String,
- 'descriptorId': fields.String,
'parentDeploymentId': fields.String
}
)
--- /dev/null
+# Copyright (C) 2021 Wind River Systems, Inc.\r
+#\r
+# Licensed under the Apache License, Version 2.0 (the "License");\r
+# you may not use this file except in compliance with the License.\r
+# You may obtain a copy of the License at\r
+#\r
+# http://www.apache.org/licenses/LICENSE-2.0\r
+#\r
+# Unless required by applicable law or agreed to in writing, software\r
+# distributed under the License is distributed on an "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+# See the License for the specific language governing permissions and\r
+# limitations under the License.\r
+\r
+from sqlalchemy import select\r
+import uuid\r
+from o2common.service import messagebus\r
+from o2dms.domain import events\r
+from o2common.service import unit_of_work\r
+from o2dms.adapter.orm import nfDeployment\r
+from o2dms.api.dms_dto import DmsLcmNfDeploymentDTO\r
+from o2dms.domain.dms import NfDeployment\r
+from o2common.helper import o2logging\r
+logger = o2logging.get_logger(__name__)\r
+\r
+\r
+def lcm_nfdeployment_list(\r
+ deploymentManagerID: str, uow: unit_of_work.AbstractUnitOfWork):\r
+ with uow:\r
+ res = uow.session.execute(select(nfDeployment).where(\r
+ nfDeployment.c.deploymentManagerId == deploymentManagerID))\r
+ return [dict(r) for r in res]\r
+\r
+\r
+def lcm_nfdeployment_one(\r
+ nfdeploymentid: str, uow: unit_of_work.AbstractUnitOfWork):\r
+ with uow:\r
+ res = uow.session.execute(select(nfDeployment).where(\r
+ nfDeployment.c.id == nfdeploymentid))\r
+ first = res.first()\r
+ return None if first is None else dict(first)\r
+\r
+\r
+def lcm_nfdeployment_create(\r
+ deploymentManagerId: str,\r
+ input: DmsLcmNfDeploymentDTO.\r
+ NfDeployment_create,\r
+ bus: messagebus.MessageBus):\r
+\r
+ uow = bus.uow\r
+ with uow:\r
+ _check_duplication(input, uow)\r
+ _check_dependencies(input, uow)\r
+ id = str(uuid.uuid4())\r
+ entity = NfDeployment(\r
+ id, input['name'], deploymentManagerId, input['description'],\r
+ input['descriptorId'], input['parentDeploymentId'])\r
+ uow.nfdeployments.add(entity)\r
+\r
+ # publish event\r
+ event = events.NfDeploymentCreated(NfDeploymentId=id)\r
+ uow.commit()\r
+ bus.handle(event)\r
+\r
+ return id\r
+\r
+\r
+def lcm_nfdeployment_update(\r
+ nfdeploymentid: str,\r
+ input: DmsLcmNfDeploymentDTO.NfDeployment_update,\r
+ uow: unit_of_work.AbstractUnitOfWork):\r
+\r
+ with uow:\r
+ entity = uow.nfdeployments.get(nfdeploymentid)\r
+ entity.name = input['name']\r
+ entity.description = input['description']\r
+ entity.outputParams = input['parentDeploymentId']\r
+ uow.commit()\r
+ return True\r
+\r
+\r
+def lcm_nfdeployment_delete(\r
+ nfdeploymentid: str, uow: unit_of_work.AbstractUnitOfWork):\r
+\r
+ with uow:\r
+ uow.nfdeployments.delete(nfdeploymentid)\r
+ uow.commit()\r
+ return True\r
+\r
+\r
+def _check_duplication(\r
+ input: DmsLcmNfDeploymentDTO,\r
+ uow: unit_of_work.AbstractUnitOfWork):\r
+ name = input['name']\r
+ descriptorId = input['descriptorId']\r
+ if uow.nfdeployments.count(name=name) > 0:\r
+ raise Exception(\r
+ "NfDeployment with name {} exists already".format(name))\r
+ if uow.nfdeployments.count(descriptorId=descriptorId) > 0:\r
+ raise Exception(\r
+ "NfDeployment with descriptorId {} exists already".format(\r
+ descriptorId))\r
+\r
+\r
+def _check_dependencies(\r
+ input: DmsLcmNfDeploymentDTO,\r
+ uow: unit_of_work.AbstractUnitOfWork):\r
+ descriptorId = input['descriptorId']\r
+ if uow.nfdeployment_descs.count(id=descriptorId) == 0:\r
+ raise Exception(\r
+ "NfDeploymentDescriptor with id {} does not exist".format(\r
+ descriptorId))\r
--- /dev/null
+# Copyright (C) 2021 Wind River Systems, Inc.\r
+#\r
+# Licensed under the Apache License, Version 2.0 (the "License");\r
+# you may not use this file except in compliance with the License.\r
+# You may obtain a copy of the License at\r
+#\r
+# http://www.apache.org/licenses/LICENSE-2.0\r
+#\r
+# Unless required by applicable law or agreed to in writing, software\r
+# distributed under the License is distributed on an "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+# See the License for the specific language governing permissions and\r
+# limitations under the License.\r
+\r
+from sqlalchemy import select\r
+from o2common.service import unit_of_work\r
+from o2dms.adapter.orm import nfOCloudVResource\r
+from o2common.helper import o2logging\r
+logger = o2logging.get_logger(__name__)\r
+\r
+\r
+def lcm_nfocloudvresource_list(\r
+ nfDeploymentId: str, uow: unit_of_work.AbstractUnitOfWork):\r
+ with uow:\r
+ res = uow.session.execute(select(nfOCloudVResource).where(\r
+ nfOCloudVResource.c.nfDeploymentId == nfDeploymentId))\r
+ return [dict(r) for r in res]\r
+\r
+\r
+def lcm_nfocloudvresource_one(\r
+ ocloudvresourceId: str, uow: unit_of_work.AbstractUnitOfWork):\r
+ with uow:\r
+ res = uow.session.execute(select(nfOCloudVResource).where(\r
+ nfOCloudVResource.c.id == ocloudvresourceId))\r
+ first = res.first()\r
+ return None if first is None else dict(first)\r
--- /dev/null
+# Copyright (C) 2021 Wind River Systems, Inc.\r
+#\r
+# Licensed under the Apache License, Version 2.0 (the "License");\r
+# you may not use this file except in compliance with the License.\r
+# You may obtain a copy of the License at\r
+#\r
+# http://www.apache.org/licenses/LICENSE-2.0\r
+#\r
+# Unless required by applicable law or agreed to in writing, software\r
+# distributed under the License is distributed on an "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+# See the License for the specific language governing permissions and\r
+# limitations under the License.\r
+\r
+from sqlalchemy import select\r
+import uuid\r
+from o2common.service import unit_of_work\r
+from o2dms.adapter.orm import nfDeploymentDesc\r
+from o2dms.api.dms_dto import DmsLcmNfDeploymentDescriptorDTO\r
+from o2dms.domain.dms import NfDeploymentDesc\r
+from o2common.helper import o2logging\r
+logger = o2logging.get_logger(__name__)\r
+\r
+\r
+def lcm_nfdeploymentdesc_list(deploymentManagerID: str,\r
+ uow: unit_of_work.AbstractUnitOfWork):\r
+ with uow:\r
+ res = uow.session.execute(select(nfDeploymentDesc).where(\r
+ nfDeploymentDesc.c.deploymentManagerId == deploymentManagerID))\r
+ return [dict(r) for r in res]\r
+\r
+\r
+def lcm_nfdeploymentdesc_one(nfdeploymentdescriptorid: str,\r
+ uow: unit_of_work.AbstractUnitOfWork):\r
+ with uow:\r
+ res = uow.session.execute(select(nfDeploymentDesc).where(\r
+ nfDeploymentDesc.c.id == nfdeploymentdescriptorid))\r
+ first = res.first()\r
+ return None if first is None else dict(first)\r
+\r
+\r
+def _check_duplication(name: str, uow: unit_of_work.AbstractUnitOfWork):\r
+ if uow.nfdeployment_descs.count(name=name) > 0:\r
+ raise Exception(\r
+ "NfDeploymentDescriptor with name {} exists already".format(name))\r
+\r
+\r
+def lcm_nfdeploymentdesc_create(\r
+ deploymentManagerId: str,\r
+ input: DmsLcmNfDeploymentDescriptorDTO.\r
+ NfDeploymentDescriptor_create,\r
+ uow: unit_of_work.AbstractUnitOfWork):\r
+\r
+ with uow:\r
+ _check_duplication(input['name'], uow)\r
+ id = str(uuid.uuid4())\r
+ entity = NfDeploymentDesc(\r
+ id, input['name'], deploymentManagerId, input['description'],\r
+ input['inputParams'], input['outputParams'], input['artifactUrl'])\r
+ uow.nfdeployment_descs.add(entity)\r
+ uow.commit()\r
+ return id\r
+\r
+\r
+def lcm_nfdeploymentdesc_update(\r
+ nfdeploymentdescriptorid: str,\r
+ input: DmsLcmNfDeploymentDescriptorDTO.NfDeploymentDescriptor_update,\r
+ uow: unit_of_work.AbstractUnitOfWork):\r
+\r
+ with uow:\r
+ entity = uow.nfdeployment_descs.get(nfdeploymentdescriptorid)\r
+ entity.name = input['name']\r
+ entity.description = input['description']\r
+ entity.inputParams = input['inputParams']\r
+ entity.outputParams = input['outputParams']\r
+ entity.artifactUrl = input['artifactUrl']\r
+ uow.commit()\r
+ return True\r
+\r
+\r
+def lcm_nfdeploymentdesc_delete(\r
+ nfdeploymentdescriptorid: str, uow: unit_of_work.AbstractUnitOfWork):\r
+\r
+ with uow:\r
+ # check dependency\r
+ _check_dependencies(nfdeploymentdescriptorid, uow)\r
+ uow.nfdeployment_descs.delete(nfdeploymentdescriptorid)\r
+ uow.commit()\r
+ return True\r
+\r
+\r
+def _check_dependencies(\r
+ descriptorId: str, uow: unit_of_work.AbstractUnitOfWork\r
+):\r
+ # check if nfdeployment depends on it\r
+ if uow.nfdeployments.count(descriptorId=descriptorId) > 0:\r
+ raise Exception(\r
+ "NfDeployment with descriptorId {} exists".format(\r
+ descriptorId))\r
--- /dev/null
+# Copyright (C) 2021 Wind River Systems, Inc.\r
+#\r
+# Licensed under the Apache License, Version 2.0 (the "License");\r
+# you may not use this file except in compliance with the License.\r
+# You may obtain a copy of the License at\r
+#\r
+# http://www.apache.org/licenses/LICENSE-2.0\r
+#\r
+# Unless required by applicable law or agreed to in writing, software\r
+# distributed under the License is distributed on an "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+# See the License for the specific language governing permissions and\r
+# limitations under the License.\r
+\r
+from sqlalchemy import select\r
+from o2common.service import unit_of_work\r
+from o2ims.adapter.orm import deploymentmanager\r
+from o2common.helper import o2logging\r
+logger = o2logging.get_logger(__name__)\r
+\r
+\r
+def deployment_managers(uow: unit_of_work.AbstractUnitOfWork):\r
+ with uow:\r
+ res = uow.session.execute(select(deploymentmanager))\r
+ return [dict(r) for r in res]\r
+\r
+\r
+def deployment_manager_one(deploymentManagerId: str,\r
+ uow: unit_of_work.AbstractUnitOfWork):\r
+ with uow:\r
+ res = uow.session.execute(select(deploymentmanager).where(\r
+ deploymentmanager.c.deploymentManagerId == deploymentManagerId))\r
+ first = res.first()\r
+ return None if first is None else dict(first)\r
# from flask import jsonify
from flask_restx import Resource
-from o2dms.views.dms_dto import DmsDTO
-from o2dms.views import dms_lcm_view, api_dms_lcm_v1
+from o2dms.api.dms_dto import DmsDTO
+from o2dms.api import dms_lcm_view
+from o2dms.api.dms_api_ns import api_dms_lcm_v1
+
from o2common.service.messagebus import MessageBus
+from o2common.helper import o2logging
+logger = o2logging.get_logger(__name__)
+
+
+def configure_api_route():
+ pass
# ---------- DeploymentManagers ---------- #
@api_dms_lcm_v1.doc('Get deployment manager')
@api_dms_lcm_v1.marshal_with(model)
def get(self, deploymentManagerID):
+ logger.debug("get o2dms info:{}".format(
+ deploymentManagerID
+ ))
bus = MessageBus.get_instance()
result = dms_lcm_view.deployment_manager_one(
deploymentManagerID, bus.uow)
# from flask import jsonify
from flask_restx import Resource
-from o2common.config import config
-from o2dms.views.dms_dto import DmsLcmNfDeploymentDescriptorDTO
-from o2dms.views import dms_lcm_view, api_dms_lcm_v1
+from o2dms.api.dms_dto import DmsLcmNfDeploymentDescriptorDTO
+from o2dms.api import dms_lcm_nfdeploymentdesc as dms_lcm_view
+from o2dms.api.dms_api_ns import api_dms_lcm_v1
+
from o2common.service.messagebus import MessageBus
+from o2common.helper import o2logging
+logger = o2logging.get_logger(__name__)
+
-apibase = config.get_o2dms_api_base()
+def configure_api_route():
+ pass
# LCM services #
@api_dms_lcm_v1.expect(createdto)
@api_dms_lcm_v1.marshal_with(post_resp, code=201)
def post(self, deploymentManagerID):
- bus = MessageBus.get_instance()
- data = api_dms_lcm_v1.payload
- id = dms_lcm_view.lcm_nfdeploymentdesc_create(
- deploymentManagerID, data, bus.uow)
- return {"id": id}, 201
+ try:
+ logger.debug("create deployment desc:{}".format(
+ api_dms_lcm_v1.payload
+ ))
+ bus = MessageBus.get_instance()
+ data = api_dms_lcm_v1.payload
+ id = dms_lcm_view.lcm_nfdeploymentdesc_create(
+ deploymentManagerID, data, bus.uow)
+ return {"id": id}, 201
+ except Exception as ex:
+ logger.warning("{}".format(str(ex)))
+ api_dms_lcm_v1.abort(400, str(ex))
@api_dms_lcm_v1\
@api_dms_lcm_v1.doc('Update a NfDeploymentDescriptor')
@api_dms_lcm_v1.expect(updatedto)
def put(self, nfDeploymentDescriptorId, deploymentManagerID):
+ logger.debug("update deployment desc:{}".format(
+ api_dms_lcm_v1.payload
+ ))
bus = MessageBus.get_instance()
data = api_dms_lcm_v1.payload
dms_lcm_view.lcm_nfdeploymentdesc_update(
# from flask import jsonify
from flask_restx import Resource
-from o2common.config import config
-from o2dms.views.dms_dto import DmsLcmNfDeploymentDTO
-from o2dms.views import dms_lcm_view, api_dms_lcm_v1
+from o2dms.api.dms_dto import DmsLcmNfDeploymentDTO
+from o2dms.api import dms_lcm_nfdeployment as dms_lcm_view
+from o2dms.api.dms_api_ns import api_dms_lcm_v1
+
from o2common.service.messagebus import MessageBus
+from o2common.helper import o2logging
+logger = o2logging.get_logger(__name__)
+
-apibase = config.get_o2dms_api_base()
+def configure_api_route():
+ pass
# LCM services #
@api_dms_lcm_v1.expect(createdto)
@api_dms_lcm_v1.marshal_with(post_resp, code=201)
def post(self, deploymentManagerID):
- bus = MessageBus.get_instance()
- data = api_dms_lcm_v1.payload
- id = dms_lcm_view.lcm_nfdeployment_create(
- deploymentManagerID, data, bus.uow)
- return {"id": id}, 201
+ try:
+ logger.debug("create deployment:{}".format(
+ api_dms_lcm_v1.payload
+ ))
+ bus = MessageBus.get_instance()
+ data = api_dms_lcm_v1.payload
+ id = dms_lcm_view.lcm_nfdeployment_create(
+ deploymentManagerID, data, bus)
+ return {"id": id}, 201
+ except Exception as ex:
+ logger.warning("{}".format(str(ex)))
+ api_dms_lcm_v1.abort(400, str(ex))
@api_dms_lcm_v1\
updatedto = DmsLcmNfDeploymentDTO.\
NfDeployment_update
- @api_dms_lcm_v1.doc('Get a NfDeploymentDescriptor')
+ @api_dms_lcm_v1.doc('Get a NfDeployment')
@api_dms_lcm_v1.marshal_with(model)
def get(self, nfDeploymentId, deploymentManagerID):
bus = MessageBus.get_instance()
if result is not None:
return result
api_dms_lcm_v1.abort(
- 404, "NfDeploymentDescriptor {} doesn't exist".format(
+ 404, "NfDeployment {} doesn't exist".format(
nfDeploymentId))
@api_dms_lcm_v1.doc('Update a NfDeployment')
@api_dms_lcm_v1.expect(updatedto)
def put(self, nfDeploymentId, deploymentManagerID):
- bus = MessageBus.get_instance()
- data = api_dms_lcm_v1.payload
- dms_lcm_view.lcm_nfdeployment_update(
- nfDeploymentId, data, bus.uow)
- return {}, 201
+ try:
+ logger.debug("update deployment:{},{}".format(
+ nfDeploymentId,
+ api_dms_lcm_v1.payload
+ ))
+ bus = MessageBus.get_instance()
+ data = api_dms_lcm_v1.payload
+ dms_lcm_view.lcm_nfdeployment_update(
+ nfDeploymentId, data, bus.uow)
+ return {}, 201
+ except Exception as ex:
+ logger.warning("{}".format(str(ex)))
+ api_dms_lcm_v1.abort(400, str(ex))
@api_dms_lcm_v1.doc('Delete NfDeployment by ID')
@api_dms_lcm_v1.response(204, 'NfDeployment deleted')
# from flask import jsonify
from flask_restx import Resource
-from o2common.config import config
-from o2dms.views.dms_dto import DmsLcmNfOCloudVResourceDTO
-from o2dms.views import dms_lcm_view, api_dms_lcm_v1
+from o2dms.api.dms_dto import DmsLcmNfOCloudVResourceDTO
+from o2dms.api import dms_lcm_nfdeployment_vres as dms_lcm_view
+from o2dms.api.dms_api_ns import api_dms_lcm_v1
+
from o2common.service.messagebus import MessageBus
+from o2common.helper import o2logging
+logger = o2logging.get_logger(__name__)
+
-apibase = config.get_o2dms_api_base()
+def configure_api_route():
+ pass
# LCM services #
--- /dev/null
+# Copyright (C) 2021 Wind River Systems, Inc.
+#
+# 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.
+
+# pylint: disable=too-few-public-methods
+# from datetime import date
+# from typing import Optional
+from dataclasses import dataclass
+# from datetime import datetime
+# from o2ims.domain.resource_type import ResourceTypeEnum
+
+from o2common.domain.commands import Command
+
+
+@dataclass
+class InstallNfDeployment(Command):
+ NfDeploymentId: str
\r
class NfDeploymentDesc(AgRoot):\r
def __init__(self, id: str, name: str, dmsId: str, description: str = '',\r
- inputParams: str = '', outputParams: str = '',) -> None:\r
+ inputParams: str = '', outputParams: str = '',\r
+ artifacturl: str = '') -> None:\r
super().__init__()\r
self.id = id\r
self.version_number = 0\r
self.description = description\r
self.inputParams = inputParams\r
self.outputParams = outputParams\r
+ self.artifactUrl = artifacturl\r
# self.extensions = []\r
\r
\r
def delete(self, nfdeployment_id):\r
self._delete(nfdeployment_id)\r
\r
+ def count(self, **kwargs):\r
+ return self._count(**kwargs)\r
+\r
@abc.abstractmethod\r
def _add(self, nfdeployment: dms.NfDeployment):\r
raise NotImplementedError\r
def _delete(self, nfdeployment_id):\r
raise NotImplementedError\r
\r
+ @abc.abstractmethod\r
+ def _count(self, **kwargs):\r
+ raise NotImplementedError\r
+\r
\r
class NfDeploymentDescRepository(abc.ABC):\r
def __init__(self):\r
def delete(self, nfdeployment_descriptor_id):\r
self._delete(nfdeployment_descriptor_id)\r
\r
+ def count(self, **kwargs):\r
+ return self._count(**kwargs)\r
+\r
@abc.abstractmethod\r
def _add(self, nfdeployment_descriptor: dms.NfDeploymentDesc):\r
raise NotImplementedError\r
def _delete(self, nfdeployment_descriptor_id):\r
raise NotImplementedError\r
\r
+ @abc.abstractmethod\r
+ def _count(self, **kwargs):\r
+ raise NotImplementedError\r
+\r
\r
class NfOCloudVResourceRepository(abc.ABC):\r
def __init__(self):\r
-# Copyright (C) 2021 Wind River Systems, Inc.\r
-#\r
-# Licensed under the Apache License, Version 2.0 (the "License");\r
-# you may not use this file except in compliance with the License.\r
-# You may obtain a copy of the License at\r
-#\r
-# http://www.apache.org/licenses/LICENSE-2.0\r
-#\r
-# Unless required by applicable law or agreed to in writing, software\r
-# distributed under the License is distributed on an "AS IS" BASIS,\r
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-# See the License for the specific language governing permissions and\r
-# limitations under the License.\r
-\r
-from flask_restx import Namespace\r
-from o2common.config import config\r
-\r
-\r
-api_dms_lcm_v1 = Namespace(\r
- "O2DMS_LCM", description='DMS LCM related operations.')\r
-apibase = config.get_o2dms_api_base()\r
-\r
-\r
-def configure_namespace(app):\r
- app.add_namespace(api_dms_lcm_v1, path=apibase)\r
+# Copyright (C) 2021 Wind River Systems, Inc.
+#
+# 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.
+
+# pylint: disable=too-few-public-methods
+from dataclasses import dataclass
+from o2common.domain.events import Event
+
+
+@dataclass
+class NfDeploymentCreated(Event):
+ NfDeploymentId: str
+
+
+@dataclass
+class NfDeploymentDeleted(Event):
+ NfDeploymentId: str
--- /dev/null
+# Copyright (C) 2021 Wind River Systems, Inc.
+#
+# 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.
+
+# pylint: disable=unused-argument
+from __future__ import annotations
+from o2dms.domain.commands import InstallNfDeployment
+from typing import Callable
+
+from o2dms.domain import events
+from o2common.service.unit_of_work import AbstractUnitOfWork
+# if TYPE_CHECKING:
+# from . import unit_of_work
+
+from o2common.helper import o2logging
+logger = o2logging.get_logger(__name__)
+
+
+def publish_nfdeployment_created(
+ event: events.NfDeploymentCreated,
+ publish: Callable,
+):
+ publish("NfDeploymentCreated", event)
+ logger.debug("published NfDeploymentCreated: {}".format(
+ event.NfDeploymentId))
+
+
+def install_nfdeployment(
+ cmd: InstallNfDeployment,
+ uow: AbstractUnitOfWork
+):
+ logger.info("install with NfDeploymentId: {}".format(
+ cmd.NfDeploymentId))
+++ /dev/null
-# Copyright (C) 2021 Wind River Systems, Inc.\r
-#\r
-# Licensed under the Apache License, Version 2.0 (the "License");\r
-# you may not use this file except in compliance with the License.\r
-# You may obtain a copy of the License at\r
-#\r
-# http://www.apache.org/licenses/LICENSE-2.0\r
-#\r
-# Unless required by applicable law or agreed to in writing, software\r
-# distributed under the License is distributed on an "AS IS" BASIS,\r
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-# See the License for the specific language governing permissions and\r
-# limitations under the License.\r
-\r
-from sqlalchemy import select\r
-import uuid\r
-from o2common.service import unit_of_work\r
-from o2ims.adapter.orm import deploymentmanager\r
-from o2dms.adapter.orm import nfDeploymentDesc, nfDeployment, nfOCloudVResource\r
-from o2dms.views.dms_dto import DmsLcmNfDeploymentDescriptorDTO\r
-from o2dms.views.dms_dto import DmsLcmNfDeploymentDTO\r
-from o2dms.domain.dms import NfDeploymentDesc, NfDeployment\r
-\r
-\r
-def deployment_managers(uow: unit_of_work.AbstractUnitOfWork):\r
- with uow:\r
- res = uow.session.execute(select(deploymentmanager))\r
- return [dict(r) for r in res]\r
-\r
-\r
-def deployment_manager_one(deploymentManagerId: str,\r
- uow: unit_of_work.AbstractUnitOfWork):\r
- with uow:\r
- res = uow.session.execute(select(deploymentmanager).where(\r
- deploymentmanager.c.deploymentManagerId == deploymentManagerId))\r
- first = res.first()\r
- return None if first is None else dict(first)\r
-\r
-\r
-def lcm_nfdeploymentdesc_list(deploymentManagerID: str,\r
- uow: unit_of_work.AbstractUnitOfWork):\r
- with uow:\r
- res = uow.session.execute(select(nfDeploymentDesc).where(\r
- nfDeploymentDesc.c.deploymentManagerId == deploymentManagerID))\r
- return [dict(r) for r in res]\r
-\r
-\r
-def lcm_nfdeploymentdesc_one(nfdeploymentdescriptorid: str,\r
- uow: unit_of_work.AbstractUnitOfWork):\r
- with uow:\r
- res = uow.session.execute(select(nfDeploymentDesc).where(\r
- nfDeploymentDesc.c.id == nfdeploymentdescriptorid))\r
- first = res.first()\r
- return None if first is None else dict(first)\r
-\r
-\r
-def lcm_nfdeploymentdesc_create(\r
- deploymentManagerId: str,\r
- input: DmsLcmNfDeploymentDescriptorDTO.\r
- NfDeploymentDescriptor_create,\r
- uow: unit_of_work.AbstractUnitOfWork):\r
-\r
- id = str(uuid.uuid4())\r
- entity = NfDeploymentDesc(\r
- id, input['name'], deploymentManagerId, input['description'],\r
- input['inputParams'], input['outputParams'])\r
- with uow:\r
- uow.nfdeployment_descs.add(entity)\r
- uow.commit()\r
- return id\r
-\r
-\r
-def lcm_nfdeploymentdesc_update(\r
- nfdeploymentdescriptorid: str,\r
- input: DmsLcmNfDeploymentDescriptorDTO.NfDeploymentDescriptor_update,\r
- uow: unit_of_work.AbstractUnitOfWork):\r
-\r
- with uow:\r
- entity = uow.nfdeployment_descs.get(nfdeploymentdescriptorid)\r
- entity.name = input['name']\r
- entity.description = input['description']\r
- entity.inputParams = input['inputParams']\r
- entity.outputParams = input['outputParams']\r
- uow.commit()\r
- return True\r
-\r
-\r
-def lcm_nfdeploymentdesc_delete(\r
- nfdeploymentdescriptorid: str, uow: unit_of_work.AbstractUnitOfWork):\r
-\r
- with uow:\r
- uow.nfdeployment_descs.delete(nfdeploymentdescriptorid)\r
- uow.commit()\r
- return True\r
-\r
-\r
-def lcm_nfdeployment_list(\r
- deploymentManagerID: str, uow: unit_of_work.AbstractUnitOfWork):\r
- with uow:\r
- res = uow.session.execute(select(nfDeployment).where(\r
- nfDeployment.c.deploymentManagerId == deploymentManagerID))\r
- return [dict(r) for r in res]\r
-\r
-\r
-def lcm_nfdeployment_one(\r
- nfdeploymentid: str, uow: unit_of_work.AbstractUnitOfWork):\r
- with uow:\r
- res = uow.session.execute(select(nfDeployment).where(\r
- nfDeployment.c.id == nfdeploymentid))\r
- first = res.first()\r
- return None if first is None else dict(first)\r
-\r
-\r
-def lcm_nfdeployment_create(\r
- deploymentManagerId: str,\r
- input: DmsLcmNfDeploymentDTO.\r
- NfDeployment_create,\r
- uow: unit_of_work.AbstractUnitOfWork):\r
-\r
- id = str(uuid.uuid4())\r
- entity = NfDeployment(\r
- id, input['name'], deploymentManagerId, input['description'],\r
- input['descriptorId'], input['parentDeploymentId'])\r
- with uow:\r
- uow.nfdeployments.add(entity)\r
- uow.commit()\r
- return id\r
-\r
-\r
-def lcm_nfdeployment_update(\r
- nfdeploymentdescriptorid: str,\r
- input: DmsLcmNfDeploymentDTO.NfDeployment_update,\r
- uow: unit_of_work.AbstractUnitOfWork):\r
-\r
- with uow:\r
- entity = uow.nfdeployments.get(nfdeploymentdescriptorid)\r
- entity.name = input['name']\r
- entity.description = input['description']\r
- entity.inputParams = input['descriptorId']\r
- entity.outputParams = input['parentDeploymentId']\r
- uow.commit()\r
- return True\r
-\r
-\r
-def lcm_nfdeployment_delete(\r
- nfdeploymentdescriptorid: str, uow: unit_of_work.AbstractUnitOfWork):\r
-\r
- with uow:\r
- uow.nfdeployments.delete(nfdeploymentdescriptorid)\r
- uow.commit()\r
- return True\r
-\r
-\r
-def lcm_nfocloudvresource_list(\r
- nfDeploymentId: str, uow: unit_of_work.AbstractUnitOfWork):\r
- with uow:\r
- res = uow.session.execute(select(nfOCloudVResource).where(\r
- nfOCloudVResource.c.nfDeploymentId == nfDeploymentId))\r
- return [dict(r) for r in res]\r
-\r
-\r
-def lcm_nfocloudvresource_one(\r
- ocloudvresourceId: str, uow: unit_of_work.AbstractUnitOfWork):\r
- with uow:\r
- res = uow.session.execute(select(nfOCloudVResource).where(\r
- nfOCloudVResource.c.id == ocloudvresourceId))\r
- first = res.first()\r
- return None if first is None else dict(first)\r