X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=o2ims%2Fviews%2Falarm_route.py;h=7b0c03e36bded6e375c1bd11dbc3ee8e20b489ce;hb=face7ded891f079361dc37656a0fe3f54585d303;hp=21fed6d9d51ebb8cd718ea9a44cabacabfd8a8b2;hpb=7e4dd62aa6df26c97dc2596bacacedebb16f7e13;p=pti%2Fo2.git diff --git a/o2ims/views/alarm_route.py b/o2ims/views/alarm_route.py index 21fed6d..7b0c03e 100644 --- a/o2ims/views/alarm_route.py +++ b/o2ims/views/alarm_route.py @@ -1,4 +1,4 @@ -# Copyright (C) 2021 Wind River Systems, Inc. +# Copyright (C) 2021-2024 Wind River Systems, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,9 +17,13 @@ from flask_restx import Resource, reqparse from o2common.service.messagebus import MessageBus from o2common.views.pagination_route import link_header, PAGE_PARAM +from o2common.views.route_exception import NotFoundException, \ + BadRequestException +from o2ims.domain.alarm_obj import PerceivedSeverityEnum from o2ims.views import alarm_view -from o2ims.views.api_ns import api_monitoring_v1 -from o2ims.views.alarm_dto import AlarmDTO, SubscriptionDTO +from o2ims.views.api_ns import api_ims_monitoring as api_monitoring_v1 +from o2ims.views.alarm_dto import AlarmDTO, SubscriptionDTO, \ + MonitoringApiV1DTO from o2common.helper import o2logging logger = o2logging.get_logger(__name__) @@ -31,8 +35,26 @@ def configure_api_route(): bus = MessageBus.get_instance() +# ---------- API versions ---------- # +@api_monitoring_v1.route("/v1/api_versions") +class VersionRouter(Resource): + model = MonitoringApiV1DTO.api_version_info_get + + @api_monitoring_v1.doc('Get Monitoring API version') + @api_monitoring_v1.marshal_list_with(model) + def get(self): + return { + 'uriPrefix': request.base_url.rsplit('/', 1)[0], + 'apiVersions': [{ + 'version': '1.0.0', + # 'isDeprecated': 'False', + # 'retirementDate': '' + }] + } + + # ---------- Alarm Event Record ---------- # -@api_monitoring_v1.route("/alarms") +@api_monitoring_v1.route("/v1/alarms") @api_monitoring_v1.param(PAGE_PARAM, 'Page number of the results to fetch.' + ' Default: 1', @@ -59,13 +81,14 @@ def configure_api_route(): 'Exclude showing all default fields, Set "true" to enable.', _in='query') @api_monitoring_v1.param( - 'exclude_default', - 'Exclude showing all default fields, Set "true" to enable.', + 'filter', + 'Filter of the query.', _in='query') class AlarmListRouter(Resource): model = AlarmDTO.alarm_event_record_get + @api_monitoring_v1.doc('Get Alarm Event Record List') @api_monitoring_v1.marshal_list_with(model) def get(self): parser = reqparse.RequestParser() @@ -81,7 +104,7 @@ class AlarmListRouter(Resource): return link_header(request.full_path, ret) -@api_monitoring_v1.route("/alarms/") +@api_monitoring_v1.route("/v1/alarms/") @api_monitoring_v1.param('alarmEventRecordId', 'ID of the alarm event record') @api_monitoring_v1.response(404, 'Alarm Event Record not found') @api_monitoring_v1.param( @@ -108,26 +131,59 @@ class AlarmListRouter(Resource): class AlarmGetRouter(Resource): model = AlarmDTO.alarm_event_record_get + patch = AlarmDTO.alarm_event_record_patch - @api_monitoring_v1.doc('Get resource type') + @api_monitoring_v1.doc('Get Alarm Event Record Information') @api_monitoring_v1.marshal_with(model) def get(self, alarmEventRecordId): result = alarm_view.alarm_event_record_one(alarmEventRecordId, bus.uow) if result is not None: return result - api_monitoring_v1.abort( - 404, "Resource type {} doesn't exist".format(alarmEventRecordId)) + raise NotFoundException( + "Alarm Event Record {} doesn't exist".format(alarmEventRecordId)) + + @api_monitoring_v1.doc('Patch Alarm Event Record Information') + @api_monitoring_v1.expect(patch) + @api_monitoring_v1.marshal_with(patch) + def patch(self, alarmEventRecordId): + data = api_monitoring_v1.payload + ack_action = data.get('alarmAcknowledged', None) + clear_action = data.get('perceivedSeverity', None) + + ack_is_none = ack_action is None + clear_is_none = clear_action is None + if (ack_is_none and clear_is_none) or (not ack_is_none and + not clear_is_none): + raise BadRequestException('Either "alarmAcknowledged" or ' + '"perceivedSeverity" shall be included ' + 'in a request, but not both.') + if ack_action: + result = alarm_view.alarm_event_record_ack(alarmEventRecordId, + bus.uow) + if result is not None: + return result + elif clear_action: + if clear_action != PerceivedSeverityEnum.CLEARED: + raise BadRequestException( + 'Only the value "5" for "CLEARED" is permitted of ' + '"perceivedSeverity".') + + result = alarm_view.alarm_event_record_clear(alarmEventRecordId, + bus.uow) + if result is not None: + return result + raise NotFoundException( + "Alarm Event Record {} doesn't exist".format(alarmEventRecordId)) # ---------- Alarm Subscriptions ---------- # -@api_monitoring_v1.route("/alarmSubscriptions") +@api_monitoring_v1.route("/v1/alarmSubscriptions") 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.doc('Get Alarm Subscription List') @api_monitoring_v1.marshal_list_with(model) @api_monitoring_v1.param( PAGE_PARAM, @@ -155,8 +211,8 @@ class SubscriptionsListRouter(Resource): 'Exclude showing all default fields, Set "true" to enable.', _in='query') @api_monitoring_v1.param( - 'exclude_default', - 'Exclude showing all default fields, Set "true" to enable.', + 'filter', + 'Filter of the query.', _in='query') def get(self): parser = reqparse.RequestParser() @@ -171,23 +227,29 @@ class SubscriptionsListRouter(Resource): ret = alarm_view.subscriptions(bus.uow, **kwargs) return link_header(request.full_path, ret) - @api_monitoring_v1.doc('Create a alarm subscription') + @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 + callback = data.get('callback', None) + if not callback: + raise BadRequestException('The callback parameter is required') + result = alarm_view.subscription_create(data, bus.uow) return result, 201 -@api_monitoring_v1.route("/alarmSubscriptions/") +@api_monitoring_v1.route("/v1/alarmSubscriptions/") @api_monitoring_v1.param('alarmSubscriptionID', 'ID of the Alarm Subscription') @api_monitoring_v1.response(404, 'Alarm Subscription not found') class SubscriptionGetDelRouter(Resource): model = SubscriptionDTO.subscription_get - @api_monitoring_v1.doc('Get Alarm Subscription by ID') + @api_monitoring_v1.doc('Get Alarm Subscription Information') @api_monitoring_v1.marshal_with(model) @api_monitoring_v1.param( 'all_fields', @@ -215,11 +277,11 @@ class SubscriptionGetDelRouter(Resource): alarmSubscriptionID, bus.uow) if result is not None: return result - api_monitoring_v1.abort(404, "Subscription {} doesn't exist".format( - alarmSubscriptionID)) + raise NotFoundException( + "Subscription {} doesn't exist".format(alarmSubscriptionID)) - @api_monitoring_v1.doc('Delete subscription by ID') - @api_monitoring_v1.response(204, 'Subscription deleted') + @api_monitoring_v1.doc('Delete an Alarm Subscription') + @api_monitoring_v1.response(200, 'Subscription deleted') def delete(self, alarmSubscriptionID): result = alarm_view.subscription_delete(alarmSubscriptionID, bus.uow) - return result, 204 + return result, 200