1 # Copyright (C) 2021 Wind River Systems, Inc.
\r
3 # Licensed under the Apache License, Version 2.0 (the "License");
\r
4 # you may not use this file except in compliance with the License.
\r
5 # You may obtain a copy of the License at
\r
7 # http://www.apache.org/licenses/LICENSE-2.0
\r
9 # Unless required by applicable law or agreed to in writing, software
\r
10 # distributed under the License is distributed on an "AS IS" BASIS,
\r
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
12 # See the License for the specific language governing permissions and
\r
13 # limitations under the License.
\r
15 from sqlalchemy import select
\r
17 from o2common.service import messagebus
\r
18 from o2dms.domain import events
\r
19 from o2common.service import unit_of_work
\r
20 from o2dms.adapter.orm import nfDeployment
\r
21 from o2dms.api.dms_dto import DmsLcmNfDeploymentDTO
\r
22 from o2dms.domain.dms import NfDeployment
\r
23 from o2common.helper import o2logging
\r
24 logger = o2logging.get_logger(__name__)
\r
27 def lcm_nfdeployment_list(
\r
28 deploymentManagerID: str, uow: unit_of_work.AbstractUnitOfWork):
\r
30 res = uow.session.execute(select(nfDeployment).where(
\r
31 nfDeployment.c.deploymentManagerId == deploymentManagerID))
\r
32 return [dict(r) for r in res]
\r
35 def lcm_nfdeployment_one(
\r
36 nfdeploymentid: str, uow: unit_of_work.AbstractUnitOfWork):
\r
38 res = uow.session.execute(select(nfDeployment).where(
\r
39 nfDeployment.c.id == nfdeploymentid))
\r
41 return None if first is None else dict(first)
\r
44 def lcm_nfdeployment_create(
\r
45 deploymentManagerId: str,
\r
46 input: DmsLcmNfDeploymentDTO.
\r
47 NfDeployment_create,
\r
48 bus: messagebus.MessageBus):
\r
52 _check_duplication(input, uow)
\r
53 _check_dependencies(input, uow)
\r
54 id = str(uuid.uuid4())
\r
55 entity = NfDeployment(
\r
56 id, input['name'], deploymentManagerId, input['description'],
\r
57 input['descriptorId'], input['parentDeploymentId'])
\r
58 uow.nfdeployments.add(entity)
\r
61 event = events.NfDeploymentCreated(NfDeploymentId=id)
\r
68 def lcm_nfdeployment_update(
\r
69 nfdeploymentid: str,
\r
70 input: DmsLcmNfDeploymentDTO.NfDeployment_update,
\r
71 uow: unit_of_work.AbstractUnitOfWork):
\r
74 entity = uow.nfdeployments.get(nfdeploymentid)
\r
75 entity.name = input['name']
\r
76 entity.description = input['description']
\r
77 entity.outputParams = input['parentDeploymentId']
\r
82 def lcm_nfdeployment_delete(
\r
83 nfdeploymentid: str, uow: unit_of_work.AbstractUnitOfWork):
\r
86 uow.nfdeployments.delete(nfdeploymentid)
\r
91 def _check_duplication(
\r
92 input: DmsLcmNfDeploymentDTO,
\r
93 uow: unit_of_work.AbstractUnitOfWork):
\r
94 name = input['name']
\r
95 descriptorId = input['descriptorId']
\r
96 if uow.nfdeployments.count(name=name) > 0:
\r
98 "NfDeployment with name {} exists already".format(name))
\r
99 if uow.nfdeployments.count(descriptorId=descriptorId) > 0:
\r
101 "NfDeployment with descriptorId {} exists already".format(
\r
105 def _check_dependencies(
\r
106 input: DmsLcmNfDeploymentDTO,
\r
107 uow: unit_of_work.AbstractUnitOfWork):
\r
108 descriptorId = input['descriptorId']
\r
109 if uow.nfdeployment_descs.count(id=descriptorId) == 0:
\r
111 "NfDeploymentDescriptor with id {} does not exist".format(
\r