2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.clamp.controlloop.runtime.monitoring.rest;
23 import io.swagger.annotations.ApiOperation;
24 import io.swagger.annotations.ApiParam;
25 import io.swagger.annotations.ApiResponse;
26 import io.swagger.annotations.ApiResponses;
27 import io.swagger.annotations.Authorization;
28 import io.swagger.annotations.Extension;
29 import io.swagger.annotations.ExtensionProperty;
30 import io.swagger.annotations.ResponseHeader;
31 import java.time.Instant;
32 import java.util.UUID;
33 import javax.ws.rs.DefaultValue;
34 import javax.ws.rs.GET;
35 import javax.ws.rs.HeaderParam;
36 import javax.ws.rs.Path;
37 import javax.ws.rs.QueryParam;
38 import javax.ws.rs.core.Response;
39 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatisticsList;
40 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantStatisticsList;
41 import org.onap.policy.clamp.controlloop.runtime.main.rest.RestController;
42 import org.onap.policy.clamp.controlloop.runtime.monitoring.MonitoringHandler;
43 import org.onap.policy.clamp.controlloop.runtime.monitoring.MonitoringProvider;
44 import org.onap.policy.models.base.PfModelException;
45 import org.onap.policy.models.base.PfModelRuntimeException;
46 import org.slf4j.Logger;
47 import org.slf4j.LoggerFactory;
50 * This class handles REST endpoints for CL Statistics monitoring.
52 public class MonitoringQueryController extends RestController {
54 private static final Logger LOGGER = LoggerFactory.getLogger(MonitoringQueryController.class);
55 private final MonitoringProvider provider;
58 * Create Monitoring Controller.
60 public MonitoringQueryController() {
61 this.provider = MonitoringHandler.getInstance().getMonitoringProvider();
66 * Queries details of control loop participants statistics.
68 * @param requestId request ID used in ONAP logging
69 * @param name the name of the participant to get, null for all participants statistics
70 * @param recordCount the record count to be fetched
71 * @return the participant statistics
75 @Path("/monitoring/participant")
76 @ApiOperation(value = "Query details of the requested participant stats",
77 notes = "Queries details of the requested participant stats, returning all participant stats",
78 response = ParticipantStatisticsList.class,
80 "Clamp control loop Monitoring API"
82 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
85 name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
86 response = String.class),
87 @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
88 response = String.class),
89 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
90 response = String.class),
91 @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
92 response = UUID.class)},
95 name = EXTENSION_NAME,
97 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
98 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
105 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
106 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
107 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
111 public Response queryParticipantStatistics(@HeaderParam(REQUEST_ID_NAME)
112 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
113 @ApiParam(value = "Control Loop participant name", required = true)
114 @QueryParam("name") final String name,
115 @ApiParam(value = "Control Loop participant version", required = true)
116 @QueryParam("version") final String version,
117 @ApiParam(value = "Record count", required = false) @DefaultValue("0")
118 @QueryParam("recordCount") final int recordCount,
119 @ApiParam(value = "start time", required = false)
120 @QueryParam("startTime") final String startTime,
121 @ApiParam(value = "end time", required = false)
122 @QueryParam("endTime") final String endTime) {
125 Instant startTimestamp = null;
126 Instant endTimestamp = null;
128 if (startTime != null) {
129 startTimestamp = Instant.parse(startTime);
131 if (endTime != null) {
132 endTimestamp = Instant.parse(endTime);
134 ParticipantStatisticsList response = provider.fetchFilteredParticipantStatistics(name, version, recordCount,
135 startTimestamp, endTimestamp);
136 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
140 } catch (PfModelRuntimeException e) {
141 LOGGER.warn("Monitoring of participants statistics failed", e);
142 return addLoggingHeaders(addVersionControlHeaders(Response.status(e.getErrorResponse().getResponseCode())),
149 * Queries details of all participant statistics per control loop.
151 * @param requestId request ID used in ONAP logging
152 * @param name the name of the control loop
153 * @param version version of the control loop
154 * @return the control loop element statistics
158 @Path("/monitoring/participants/controlloop")
159 @ApiOperation(value = "Query details of all the participant stats in a control loop",
160 notes = "Queries details of the participant stats, returning all participant stats",
161 response = ClElementStatisticsList.class,
163 "Clamp control loop Monitoring API"
165 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
168 name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
169 response = String.class),
170 @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
171 response = String.class),
172 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
173 response = String.class),
174 @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
175 response = UUID.class)},
178 name = EXTENSION_NAME,
180 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
181 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
187 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
188 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
189 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
193 public Response queryParticipantStatisticsPerControlLoop(@HeaderParam(REQUEST_ID_NAME)
194 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
195 @ApiParam(value = "Control Loop name", required = true)
196 @QueryParam("name") final String name,
197 @ApiParam(value = "Control Loop version", required = true)
198 @QueryParam("version") final String version) {
201 ParticipantStatisticsList response = provider.fetchParticipantStatsPerControlLoop(name, version);
202 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
206 } catch (PfModelRuntimeException | PfModelException e) {
207 LOGGER.warn("Monitoring of Cl participant statistics failed", e);
208 return addLoggingHeaders(addVersionControlHeaders(Response.status(e.getErrorResponse().getResponseCode())),
217 * Queries details of all control loop element statistics per control loop.
219 * @param requestId request ID used in ONAP logging
220 * @param name the name of the control loop
221 * @param version version of the control loop
222 * @return the control loop element statistics
226 @Path("/monitoring/clelements/controlloop")
227 @ApiOperation(value = "Query details of the requested cl element stats in a control loop",
228 notes = "Queries details of the requested cl element stats, returning all clElement stats",
229 response = ClElementStatisticsList.class,
231 "Clamp control loop Monitoring API"
233 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
236 name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
237 response = String.class),
238 @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
239 response = String.class),
240 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
241 response = String.class),
242 @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
243 response = UUID.class)},
246 name = EXTENSION_NAME,
248 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
249 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
255 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
256 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
257 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
261 public Response queryElementStatisticsPerControlLoop(@HeaderParam(REQUEST_ID_NAME)
262 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
263 @ApiParam(value = "Control Loop name", required = true)
264 @QueryParam("name") final String name,
265 @ApiParam(value = "Control Loop version", required = true)
266 @QueryParam("version") final String version) {
269 ClElementStatisticsList response = provider.fetchClElementStatsPerControlLoop(name, version);
270 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
274 } catch (PfModelRuntimeException | PfModelException e) {
275 LOGGER.warn("Monitoring of Cl Element statistics failed", e);
276 return addLoggingHeaders(addVersionControlHeaders(Response.status(e.getErrorResponse().getResponseCode())),
286 * Queries details of all control loop element statistics per control loop.
288 * @param requestId request ID used in ONAP logging
289 * @param name the name of the control loop
290 * @param version version of the control loop
291 * @param id Id of the control loop element
292 * @param recordCount the record count to be fetched
293 * @return the control loop element statistics
297 @Path("/monitoring/clelement")
298 @ApiOperation(value = "Query details of the requested cl element stats",
299 notes = "Queries details of the requested cl element stats, returning all clElement stats",
300 response = ClElementStatisticsList.class,
302 "Clamp control loop Monitoring API"
304 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
307 name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
308 response = String.class),
309 @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
310 response = String.class),
311 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
312 response = String.class),
313 @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
314 response = UUID.class)},
317 name = EXTENSION_NAME,
319 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
320 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
326 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
327 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
328 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
332 public Response queryElementStatistics(@HeaderParam(REQUEST_ID_NAME)
333 @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
334 @ApiParam(value = "Participant name", required = true)
335 @QueryParam("name") final String name,
336 @ApiParam(value = "Participant version", required = true)
337 @QueryParam("version") final String version,
338 @ApiParam(value = "Record count", required = false)
339 @DefaultValue("0") @QueryParam("recordCount") final int recordCount,
340 @ApiParam(value = "Control Loop element id", required = false)
341 @QueryParam("id") final String id,
342 @ApiParam(value = "start time", required = false)
343 @QueryParam("startTime") final String startTime,
344 @ApiParam(value = "end time", required = false)
345 @QueryParam("endTime") final String endTime) {
348 Instant startTimestamp = null;
349 Instant endTimestamp = null;
351 if (startTime != null) {
352 startTimestamp = Instant.parse(startTime);
354 if (endTime != null) {
355 endTimestamp = Instant.parse(endTime);
357 ClElementStatisticsList response = provider.fetchFilteredClElementStatistics(name, version, id,
358 startTimestamp, endTimestamp, recordCount);
359 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
363 } catch (PfModelRuntimeException | PfModelException e) {
364 LOGGER.warn("Monitoring of Cl Element statistics failed", e);
365 return addLoggingHeaders(addVersionControlHeaders(Response.status(e.getErrorResponse().getResponseCode())),