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.main.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 lombok.RequiredArgsConstructor;
34 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ClElementStatisticsList;
35 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantStatisticsList;
36 import org.onap.policy.clamp.controlloop.runtime.main.web.AbstractRestController;
37 import org.onap.policy.clamp.controlloop.runtime.monitoring.MonitoringProvider;
38 import org.onap.policy.models.base.PfModelException;
39 import org.springframework.http.MediaType;
40 import org.springframework.http.ResponseEntity;
41 import org.springframework.web.bind.annotation.GetMapping;
42 import org.springframework.web.bind.annotation.RequestHeader;
43 import org.springframework.web.bind.annotation.RequestParam;
44 import org.springframework.web.bind.annotation.RestController;
47 * This class handles REST endpoints for CL Statistics monitoring.
50 @RequiredArgsConstructor
51 public class MonitoringQueryController extends AbstractRestController {
53 private static final String TAGS = "Clamp Control Loop Monitoring API";
54 private final MonitoringProvider provider;
57 * Queries details of control loop participants statistics.
59 * @param requestId request ID used in ONAP logging
60 * @param name the name of the participant to get, null for all participants statistics
61 * @param version the version of the participant to get, null for all participants with the given name
62 * @param recordCount the record count to be fetched
63 * @param startTime the time from which to get statistics
64 * @param endTime the time to which to get statistics
65 * @return the participant statistics
68 @GetMapping(value = "/monitoring/participant",
69 produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML})
70 @ApiOperation(value = "Query details of the requested participant stats",
71 notes = "Queries details of the requested participant stats, returning all participant stats",
72 response = ParticipantStatisticsList.class,
74 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
77 name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
78 response = String.class),
79 @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
80 response = String.class),
81 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
82 response = String.class),
83 @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
84 response = UUID.class)},
88 name = EXTENSION_NAME,
90 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
91 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
98 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
99 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
100 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
104 public ResponseEntity<ParticipantStatisticsList> queryParticipantStatistics(
106 name = REQUEST_ID_NAME,
107 required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
108 @ApiParam(value = "Control Loop participant name") @RequestParam(
110 required = false) final String name,
111 @ApiParam(value = "Control Loop participant version", required = false) @RequestParam(
113 required = false) final String version,
114 @ApiParam(value = "Record count", required = false) @RequestParam(
115 value = "recordCount",
117 defaultValue = "0") final int recordCount,
118 @ApiParam(value = "start time", required = false) @RequestParam(
120 required = false) final String startTime,
121 @ApiParam(value = "end time", required = false) @RequestParam(
123 required = false) 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 return ResponseEntity.ok().body(
135 provider.fetchFilteredParticipantStatistics(name, version, recordCount, startTimestamp, endTimestamp));
139 * Queries details of all participant statistics per control loop.
141 * @param requestId request ID used in ONAP logging
142 * @param name the name of the control loop
143 * @param version version of the control loop
144 * @return the control loop element statistics
147 @GetMapping(value = "/monitoring/participants/controlloop",
148 produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML})
149 @ApiOperation(value = "Query details of all the participant stats in a control loop",
150 notes = "Queries details of the participant stats, returning all participant stats",
151 response = ClElementStatisticsList.class,
153 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
156 name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
157 response = String.class),
158 @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
159 response = String.class),
160 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
161 response = String.class),
162 @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
163 response = UUID.class)},
167 name = EXTENSION_NAME,
169 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
170 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
176 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
177 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
178 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
182 public ResponseEntity<ParticipantStatisticsList> queryParticipantStatisticsPerControlLoop(
184 name = REQUEST_ID_NAME,
185 required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
186 @ApiParam(value = "Control Loop name", required = true) @RequestParam(
188 required = false) final String name,
189 @ApiParam(value = "Control Loop version", required = true) @RequestParam(
191 required = false) final String version) {
193 return ResponseEntity.ok().body(provider.fetchParticipantStatsPerControlLoop(name, version));
197 * Queries details of all control loop element statistics per control loop.
199 * @param requestId request ID used in ONAP logging
200 * @param name the name of the control loop
201 * @param version version of the control loop
202 * @return the control loop element statistics
205 @GetMapping(value = "/monitoring/clelements/controlloop",
206 produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML})
207 @ApiOperation(value = "Query details of the requested cl element stats in a control loop",
208 notes = "Queries details of the requested cl element stats, returning all clElement stats",
209 response = ClElementStatisticsList.class,
211 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
214 name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
215 response = String.class),
216 @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
217 response = String.class),
218 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
219 response = String.class),
220 @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
221 response = UUID.class)},
225 name = EXTENSION_NAME,
227 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
228 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
234 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
235 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
236 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
240 public ResponseEntity<ClElementStatisticsList> queryElementStatisticsPerControlLoop(
242 name = REQUEST_ID_NAME,
243 required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
244 @ApiParam(value = "Control Loop name", required = true) @RequestParam(
246 required = false) final String name,
247 @ApiParam(value = "Control Loop version", required = true) @RequestParam(
249 required = false) final String version) {
251 return ResponseEntity.ok().body(provider.fetchClElementStatsPerControlLoop(name, version));
255 * Queries details of all control loop element statistics per control loop.
257 * @param requestId request ID used in ONAP logging
258 * @param name the name of the control loop
259 * @param version version of the control loop
260 * @param id Id of the control loop element
261 * @param recordCount the record count to be fetched
262 * @param startTime the time from which to get statistics
263 * @param endTime the time to which to get statistics
264 * @return the control loop element statistics
265 * @throws PfModelException on errors getting details of all control loop element statistics per control loop
268 @GetMapping(value = "/monitoring/clelement",
269 produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML})
270 @ApiOperation(value = "Query details of the requested cl element stats",
271 notes = "Queries details of the requested cl element stats, returning all clElement stats",
272 response = ClElementStatisticsList.class,
274 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
277 name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
278 response = String.class),
279 @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
280 response = String.class),
281 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
282 response = String.class),
283 @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
284 response = UUID.class)},
288 name = EXTENSION_NAME,
290 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
291 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
297 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
298 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
299 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
303 public ResponseEntity<ClElementStatisticsList> queryElementStatistics(
305 name = REQUEST_ID_NAME,
306 required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
307 @ApiParam(value = "Participant name", required = true) @RequestParam(
309 required = false) final String name,
310 @ApiParam(value = "Participant version", required = true) @RequestParam(
312 required = false) final String version,
313 @ApiParam(value = "Record count", required = false) @RequestParam(
314 value = "recordCount",
316 defaultValue = "0") final int recordCount,
317 @ApiParam(value = "Control Loop element id", required = false) @RequestParam(
319 required = false) final String id,
320 @ApiParam(value = "start time", required = false) @RequestParam(
322 required = false) final String startTime,
323 @ApiParam(value = "end time", required = false) @RequestParam(
325 required = false) final String endTime)
326 throws PfModelException {
328 Instant startTimestamp = null;
329 Instant endTimestamp = null;
331 if (startTime != null) {
332 startTimestamp = Instant.parse(startTime);
334 if (endTime != null) {
335 endTimestamp = Instant.parse(endTime);
337 return ResponseEntity.ok().body(provider.fetchFilteredClElementStatistics(name, version, id, startTimestamp,
338 endTimestamp, recordCount));