From 2587e78199bbff4cf1b9bd9758edd66a92c0938b Mon Sep 17 00:00:00 2001 From: "Zhang Rong(Jon)" Date: Mon, 7 Nov 2022 14:31:43 +0800 Subject: [PATCH] Fix INF-332 and INF-333 that the response of the POST Issue-ID: INF-332 Issue-ID: INF-333 Signed-off-by: Zhang Rong(Jon) Change-Id: I462c4ad58786bdfe93572ac291ea1d0302a7b258 --- o2common/views/route.py | 4 ++-- o2ims/views/alarm_dto.py | 14 +++----------- o2ims/views/alarm_route.py | 7 ++++--- o2ims/views/alarm_view.py | 5 +++-- o2ims/views/ocloud_dto.py | 10 +--------- o2ims/views/ocloud_route.py | 7 ++++--- o2ims/views/ocloud_view.py | 5 +++-- 7 files changed, 20 insertions(+), 32 deletions(-) diff --git a/o2common/views/route.py b/o2common/views/route.py index 08621ff..9366a32 100644 --- a/o2common/views/route.py +++ b/o2common/views/route.py @@ -98,8 +98,8 @@ class o2_marshal_with(marshal_with): req_args = request.args mask = self._gen_mask_from_selector(**req_args) - - # mask = self.mask + if mask == '': + mask = self.mask # if has_request_context(): # mask_header = current_app.config["RESTX_MASK_HEADER"] diff --git a/o2ims/views/alarm_dto.py b/o2ims/views/alarm_dto.py index da95a55..823268f 100644 --- a/o2ims/views/alarm_dto.py +++ b/o2ims/views/alarm_dto.py @@ -45,10 +45,11 @@ class SubscriptionDTO: 'callback': fields.String, 'consumerSubscriptionId': fields.String, 'filter': fields.String, - } + }, + mask='{alarmSubscriptionId,callback}' ) - subscription = api_monitoring_v1.model( + subscription_create = api_monitoring_v1.model( "AlarmSubscriptionCreateDto", { 'callback': fields.String( @@ -58,12 +59,3 @@ class SubscriptionDTO: 'filter': fields.String, } ) - - subscription_post_resp = api_monitoring_v1.model( - "AlarmSubscriptionCreatedRespDto", - { - 'alarmSubscriptionId': fields.String( - required=True, - description='Alarm Subscription ID'), - } - ) diff --git a/o2ims/views/alarm_route.py b/o2ims/views/alarm_route.py index 8b03880..11fad03 100644 --- a/o2ims/views/alarm_route.py +++ b/o2ims/views/alarm_route.py @@ -139,8 +139,7 @@ class AlarmGetRouter(Resource): class SubscriptionsListRouter(Resource): model = SubscriptionDTO.subscription_get - expect = SubscriptionDTO.subscription - post_resp = SubscriptionDTO.subscription_post_resp + expect = SubscriptionDTO.subscription_create @api_monitoring_v1.doc('List alarm subscriptions') @api_monitoring_v1.marshal_list_with(model) @@ -188,7 +187,9 @@ class SubscriptionsListRouter(Resource): @api_monitoring_v1.doc('Create a alarm subscription') @api_monitoring_v1.expect(expect) - @api_monitoring_v1.marshal_with(post_resp, code=201) + @api_monitoring_v1.marshal_with( + model, code=201, + mask='{alarmSubscriptionId,callback,consumerSubscriptionId,filter}') def post(self): data = api_monitoring_v1.payload result = alarm_view.subscription_create(data, bus.uow) diff --git a/o2ims/views/alarm_view.py b/o2ims/views/alarm_view.py index f5e6b8b..b3a9e4a 100644 --- a/o2ims/views/alarm_view.py +++ b/o2ims/views/alarm_view.py @@ -59,7 +59,7 @@ def subscription_one(subscriptionId: str, return first.serialize() if first is not None else None -def subscription_create(subscriptionDto: SubscriptionDTO.subscription, +def subscription_create(subscriptionDto: SubscriptionDTO.subscription_create, uow: unit_of_work.AbstractUnitOfWork): sub_uuid = str(uuid.uuid4()) @@ -70,7 +70,8 @@ def subscription_create(subscriptionDto: SubscriptionDTO.subscription, with uow: uow.alarm_subscriptions.add(subscription) uow.commit() - return {"alarmSubscriptionId": sub_uuid} + first = uow.alarm_subscriptions.get(sub_uuid) + return first.serialize() def subscription_delete(subscriptionId: str, diff --git a/o2ims/views/ocloud_dto.py b/o2ims/views/ocloud_dto.py index 14d9873..478a513 100644 --- a/o2ims/views/ocloud_dto.py +++ b/o2ims/views/ocloud_dto.py @@ -215,7 +215,7 @@ class SubscriptionDTO: mask='{subscriptionId,callback}' ) - subscription = api_ims_inventory_v1.model( + subscription_create = api_ims_inventory_v1.model( "SubscriptionCreateDto", { 'callback': fields.String( @@ -224,11 +224,3 @@ class SubscriptionDTO: 'filter': fields.String, } ) - - subscription_post_resp = api_ims_inventory_v1.model( - "SubscriptionCreatedRespDto", - { - 'subscriptionId': fields.String(required=True, - description='Subscription ID'), - } - ) diff --git a/o2ims/views/ocloud_route.py b/o2ims/views/ocloud_route.py index 7616b25..1e2a6f2 100644 --- a/o2ims/views/ocloud_route.py +++ b/o2ims/views/ocloud_route.py @@ -464,8 +464,7 @@ class DeploymentManagerGetRouter(Resource): class SubscriptionsListRouter(Resource): model = SubscriptionDTO.subscription_get - expect = SubscriptionDTO.subscription - post_resp = SubscriptionDTO.subscription_post_resp + expect = SubscriptionDTO.subscription_create @api_ims_inventory_v1.doc('List subscriptions') @api_ims_inventory_v1.marshal_list_with(model) @@ -513,7 +512,9 @@ class SubscriptionsListRouter(Resource): @api_ims_inventory_v1.doc('Create a subscription') @api_ims_inventory_v1.expect(expect) - @api_ims_inventory_v1.marshal_with(post_resp, code=201) + @api_ims_inventory_v1.marshal_with( + model, code=201, + mask='{subscriptionId,callback,consumerSubscriptionId,filter}') def post(self): data = api_ims_inventory_v1.payload result = ocloud_view.subscription_create(data, bus.uow) diff --git a/o2ims/views/ocloud_view.py b/o2ims/views/ocloud_view.py index 441c938..953adc9 100644 --- a/o2ims/views/ocloud_view.py +++ b/o2ims/views/ocloud_view.py @@ -218,7 +218,7 @@ def subscription_one(subscriptionId: str, return first.serialize() if first is not None else None -def subscription_create(subscriptionDto: SubscriptionDTO.subscription, +def subscription_create(subscriptionDto: SubscriptionDTO.subscription_create, uow: unit_of_work.AbstractUnitOfWork): sub_uuid = str(uuid.uuid4()) @@ -229,7 +229,8 @@ def subscription_create(subscriptionDto: SubscriptionDTO.subscription, with uow: uow.subscriptions.add(subscription) uow.commit() - return {"subscriptionId": sub_uuid} + first = uow.subscriptions.get(sub_uuid) + return first.serialize() def subscription_delete(subscriptionId: str, -- 2.16.6