Add the PATCH method for the monitoring API
[pti/o2.git] / o2ims / views / alarm_route.py
index 4ca44ca..8b0af04 100644 (file)
@@ -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.
@@ -21,7 +21,8 @@ from o2common.views.route_exception import NotFoundException, \
     BadRequestException
 from o2ims.views import alarm_view
 from o2ims.views.api_ns import api_ims_monitoring as api_monitoring_v1
-from o2ims.views.alarm_dto import AlarmDTO, SubscriptionDTO
+from o2ims.views.alarm_dto import AlarmDTO, SubscriptionDTO, \
+    MonitoringApiV1DTO
 
 from o2common.helper import o2logging
 logger = o2logging.get_logger(__name__)
@@ -36,6 +37,10 @@ def configure_api_route():
 # ----------  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],
@@ -82,6 +87,7 @@ 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()
@@ -125,7 +131,7 @@ class AlarmGetRouter(Resource):
 
     model = AlarmDTO.alarm_event_record_get
 
-    @api_monitoring_v1.doc('Get AlarmEventRecord')
+    @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)
@@ -134,6 +140,15 @@ class AlarmGetRouter(Resource):
         raise NotFoundException(
             "Alarm Event Record {} doesn't exist".format(alarmEventRecordId))
 
+    @api_monitoring_v1.doc('Patch Alarm Event Record Information')
+    @api_monitoring_v1.marshal_with(model)
+    def patch(self, alarmEventRecordId):
+        result = alarm_view.alarm_event_record_ack(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("/v1/alarmSubscriptions")
@@ -142,7 +157,7 @@ class SubscriptionsListRouter(Resource):
     model = SubscriptionDTO.subscription_get
     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,
@@ -186,7 +201,7 @@ 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(
         model, code=201,
@@ -208,7 +223,7 @@ 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',
@@ -239,7 +254,7 @@ class SubscriptionGetDelRouter(Resource):
         raise NotFoundException(
             "Subscription {} doesn't exist".format(alarmSubscriptionID))
 
-    @api_monitoring_v1.doc('Delete subscription by ID')
+    @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)