X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=o2ims%2Fviews%2Focloud_view.py;h=0436f3ae173494e853b785a4a1a9b58795bb3a84;hb=23021f6c24ad8722495fc42f98a18cc650906bca;hp=ae8b204edc74402e3ecf430cbab373bbf841cccf;hpb=3da89330f3837ac6cffd2cad4c4018c9f8c3327d;p=pti%2Fo2.git diff --git a/o2ims/views/ocloud_view.py b/o2ims/views/ocloud_view.py index ae8b204..0436f3a 100644 --- a/o2ims/views/ocloud_view.py +++ b/o2ims/views/ocloud_view.py @@ -12,14 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. -import logging import uuid -from datetime import datetime -from o2common.service import unit_of_work, messagebus -from o2ims.domain import events -from o2ims.views.ocloud_dto import RegistrationDTO, SubscriptionDTO -from o2ims.domain.subscription_obj import Registration, Subscription +from o2common.service import unit_of_work +from o2ims.views.ocloud_dto import SubscriptionDTO +from o2ims.domain.subscription_obj import Subscription + +from o2common.helper import o2logging +logger = o2logging.get_logger(__name__) def oclouds(uow: unit_of_work.AbstractUnitOfWork): @@ -60,9 +60,29 @@ def resource_pool_one(resourcePoolId: str, return first.serialize() if first is not None else None -def resources(resourcePoolId: str, uow: unit_of_work.AbstractUnitOfWork): +def resources(resourcePoolId: str, uow: unit_of_work.AbstractUnitOfWork, + **kwargs): + + filter_kwargs = {} # filter key should be the same with database name + if 'resourceTypeName' in kwargs: + resource_type_name = kwargs['resourceTypeName'] + with uow: + # res_types = uow.resource_types.list() + # restype_ids = [ + # restype.resourceTypeId for restype in res_types + # if resourceTypeName == restype.name] + # restype_id = '' if len(restype_ids) == 0 else restype_ids[0] + res_type = uow.resource_types.get_by_name(resource_type_name) + restype_id = '' if res_type is None else res_type.resourceTypeId + filter_kwargs['resourceTypeId'] = restype_id + + # li = uow.resources.list(resourcePoolId) + # return [r.serialize() for r in li if r.resourceTypeId == restype_id] + if 'parentId' in kwargs: + filter_kwargs['parentId'] = kwargs['parentId'] + with uow: - li = uow.resources.list(resourcePoolId) + li = uow.resources.list(resourcePoolId, **filter_kwargs) return [r.serialize() for r in li] @@ -118,51 +138,3 @@ def subscription_delete(subscriptionId: str, uow.subscriptions.delete(subscriptionId) uow.commit() return True - - -def registrations(uow: unit_of_work.AbstractUnitOfWork): - with uow: - li = uow.registrations.list() - return [r.serialize() for r in li] - - -def registration_one(registrationId: str, - uow: unit_of_work.AbstractUnitOfWork): - with uow: - first = uow.registrations.get(registrationId) - return first.serialize() if first is not None else None - - -def registration_create(registrationDto: RegistrationDTO.registration, - bus: messagebus.MessageBus): - - reg_uuid = str(uuid.uuid4()) - registration = Registration( - reg_uuid, registrationDto['callback']) - with bus.uow as uow: - uow.registrations.add(registration) - logging.debug('before event length {}'.format( - len(registration.events))) - registration.events.append(events.RegistrationChanged( - reg_uuid, - datetime.now())) - logging.debug('after event length {}'.format(len(registration.events))) - uow.commit() - _handle_events(bus) - return {"registrationId": reg_uuid} - - -def registration_delete(registrationId: str, - uow: unit_of_work.AbstractUnitOfWork): - with uow: - uow.registrations.delete(registrationId) - uow.commit() - return True - - -def _handle_events(bus: messagebus.MessageBus): - # handle events - events = bus.uow.collect_new_events() - for event in events: - bus.handle(event) - return True