# See the License for the specific language governing permissions and\r
# limitations under the License.\r
\r
-import logging\r
import uuid\r
-from datetime import datetime\r
\r
-from o2common.service import unit_of_work, messagebus\r
-from o2ims.domain import events\r
-from o2ims.views.ocloud_dto import RegistrationDTO, SubscriptionDTO\r
-from o2ims.domain.subscription_obj import Registration, Subscription\r
+from o2common.service import unit_of_work\r
+from o2ims.views.ocloud_dto import SubscriptionDTO\r
+from o2ims.domain.subscription_obj import Subscription\r
+\r
+from o2common.helper import o2logging\r
+logger = o2logging.get_logger(__name__)\r
\r
\r
def oclouds(uow: unit_of_work.AbstractUnitOfWork):\r
return first.serialize() if first is not None else None\r
\r
\r
-def resources(resourcePoolId: str, uow: unit_of_work.AbstractUnitOfWork):\r
+def resources(resourcePoolId: str, uow: unit_of_work.AbstractUnitOfWork,\r
+ **kwargs):\r
+\r
+ filter_kwargs = {} # filter key should be the same with database name\r
+ if 'resourceTypeName' in kwargs:\r
+ resource_type_name = kwargs['resourceTypeName']\r
+ with uow:\r
+ # res_types = uow.resource_types.list()\r
+ # restype_ids = [\r
+ # restype.resourceTypeId for restype in res_types\r
+ # if resourceTypeName == restype.name]\r
+ # restype_id = '' if len(restype_ids) == 0 else restype_ids[0]\r
+ res_type = uow.resource_types.get_by_name(resource_type_name)\r
+ restype_id = '' if res_type is None else res_type.resourceTypeId\r
+ filter_kwargs['resourceTypeId'] = restype_id\r
+\r
+ # li = uow.resources.list(resourcePoolId)\r
+ # return [r.serialize() for r in li if r.resourceTypeId == restype_id]\r
+ if 'parentId' in kwargs:\r
+ filter_kwargs['parentId'] = kwargs['parentId']\r
+\r
with uow:\r
- li = uow.resources.list(resourcePoolId)\r
+ li = uow.resources.list(resourcePoolId, **filter_kwargs)\r
return [r.serialize() for r in li]\r
\r
\r
uow.subscriptions.delete(subscriptionId)\r
uow.commit()\r
return True\r
-\r
-\r
-def registrations(uow: unit_of_work.AbstractUnitOfWork):\r
- with uow:\r
- li = uow.registrations.list()\r
- return [r.serialize() for r in li]\r
-\r
-\r
-def registration_one(registrationId: str,\r
- uow: unit_of_work.AbstractUnitOfWork):\r
- with uow:\r
- first = uow.registrations.get(registrationId)\r
- return first.serialize() if first is not None else None\r
-\r
-\r
-def registration_create(registrationDto: RegistrationDTO.registration,\r
- bus: messagebus.MessageBus):\r
-\r
- reg_uuid = str(uuid.uuid4())\r
- registration = Registration(\r
- reg_uuid, registrationDto['callback'])\r
- with bus.uow as uow:\r
- uow.registrations.add(registration)\r
- logging.debug('before event length {}'.format(\r
- len(registration.events)))\r
- registration.events.append(events.RegistrationChanged(\r
- reg_uuid,\r
- datetime.now()))\r
- logging.debug('after event length {}'.format(len(registration.events)))\r
- uow.commit()\r
- _handle_events(bus)\r
- return {"registrationId": reg_uuid}\r
-\r
-\r
-def registration_delete(registrationId: str,\r
- uow: unit_of_work.AbstractUnitOfWork):\r
- with uow:\r
- uow.registrations.delete(registrationId)\r
- uow.commit()\r
- return True\r
-\r
-\r
-def _handle_events(bus: messagebus.MessageBus):\r
- # handle events\r
- events = bus.uow.collect_new_events()\r
- for event in events:\r
- bus.handle(event)\r
- return True\r