X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=o2ims%2Fservice%2Fauditor%2Focloud_handler.py;h=97cca3e880f723bde14f216d22ea3c76e8b5e6ec;hb=refs%2Fchanges%2F08%2F7408%2F4;hp=554b2e1b19b54b9c9a1aafebb749b3cadf5e5659;hpb=84867b76a65efc4e9add52c86eae7e451c4a038d;p=pti%2Fo2.git diff --git a/o2ims/service/auditor/ocloud_handler.py b/o2ims/service/auditor/ocloud_handler.py index 554b2e1..97cca3e 100644 --- a/o2ims/service/auditor/ocloud_handler.py +++ b/o2ims/service/auditor/ocloud_handler.py @@ -14,17 +14,20 @@ # pylint: disable=unused-argument from __future__ import annotations +from typing import Callable -from o2ims.domain.stx_object import StxGenericModel # from dataclasses import asdict # from typing import List, Dict, Callable, Type # TYPE_CHECKING -from o2ims.domain import commands + +from o2common.config import config +# from o2common.service.messagebus import MessageBus from o2common.service.unit_of_work import AbstractUnitOfWork -from o2ims.domain.resource_type import InvalidOcloudState -from o2ims.domain.resource_type import MismatchedModel +from o2ims.domain import events, commands from o2ims.domain.ocloud import Ocloud -from o2common.config import config +from o2ims.domain.stx_object import StxGenericModel +from o2ims.domain.resource_type import InvalidOcloudState, MismatchedModel +from o2ims.domain.subscription_obj import NotificationEventEnum # if TYPE_CHECKING: # from . import unit_of_work @@ -38,14 +41,15 @@ class InvalidResourceType(Exception): def update_ocloud( cmd: commands.UpdateOCloud, - uow: AbstractUnitOfWork + uow: AbstractUnitOfWork, + publish: Callable ): stxobj = cmd.data with uow: oclouds = uow.oclouds.list() - if oclouds and len(oclouds) > 1: + if oclouds and oclouds.count() > 1: raise InvalidOcloudState("More than 1 ocloud is found") - elif not oclouds or len(oclouds) == 0: + elif not oclouds or oclouds.count() == 0: logger.info("add ocloud:" + stxobj.name + " update_at: " + str(stxobj.updatetime) + " id: " + str(stxobj.id) @@ -56,7 +60,7 @@ def update_ocloud( logger.info("Add the ocloud: " + stxobj.id + ", name: " + stxobj.name) else: - localmodel = oclouds.pop() + localmodel = oclouds.first() if is_outdated(localmodel, stxobj): logger.info("update ocloud:" + stxobj.name + " update_at: " + str(stxobj.updatetime) @@ -99,3 +103,8 @@ def update_by(ocloud: Ocloud, stxobj: StxGenericModel) -> None: # ocloud.content = stxobj.content ocloud.hash = stxobj.hash ocloud.version_number = ocloud.version_number + 1 + ocloud.events.append(events.OcloudChanged( + id=stxobj.id, + notificationEventType=NotificationEventEnum.MODIFY, + updatetime=stxobj.updatetime + ))