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
17 from datetime import datetime
\r
19 from o2common.service import unit_of_work, messagebus
\r
20 from o2ims.domain import events
\r
21 from o2ims.views.provision_dto import SmoEndpointDTO
\r
22 from o2ims.domain.configuration_obj import Configuration, ConfigurationTypeEnum
\r
25 def configurations(uow: unit_of_work.AbstractUnitOfWork):
\r
27 li = uow.configurations.list()
\r
28 return [r.serialize_smo() for r in li]
\r
31 def configuration_one(configurationId: str,
\r
32 uow: unit_of_work.AbstractUnitOfWork):
\r
34 first = uow.configurations.get(configurationId)
\r
35 return first.serialize_smo() if first is not None else None
\r
38 def configuration_create(configurationDto: SmoEndpointDTO.endpoint,
\r
39 bus: messagebus.MessageBus):
\r
41 conf_uuid = str(uuid.uuid4())
\r
42 configuration = Configuration(
\r
43 conf_uuid, configurationDto['endpoint'], ConfigurationTypeEnum.SMO)
\r
44 with bus.uow as uow:
\r
45 uow.configurations.add(configuration)
\r
46 logging.debug('before event length {}'.format(
\r
47 len(configuration.events)))
\r
48 configuration.events.append(events.ConfigurationChanged(
\r
51 logging.debug('after event length {}'.format(
\r
52 len(configuration.events)))
\r
55 return {"id": conf_uuid}
\r
58 def configuration_delete(configurationId: str,
\r
59 uow: unit_of_work.AbstractUnitOfWork):
\r
61 uow.configurations.delete(configurationId)
\r
66 def _handle_events(bus: messagebus.MessageBus):
\r
68 events = bus.uow.collect_new_events()
\r
69 for event in events:
\r