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.acm.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.acm.runtime.main.web.AbstractRestController;
35 import org.onap.policy.clamp.acm.runtime.monitoring.MonitoringProvider;
36 import org.onap.policy.clamp.models.acm.concepts.AcElementStatisticsList;
37 import org.onap.policy.clamp.models.acm.concepts.ParticipantStatisticsList;
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 ACM Statistics monitoring.
50 @RequiredArgsConstructor
51 public class MonitoringQueryController extends AbstractRestController {
53 private static final String TAGS = "Clamp Automation Composition Monitoring API";
54 private final MonitoringProvider provider;
57 * Queries details of automation composition 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(
105 @RequestHeader(name = REQUEST_ID_NAME, required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
106 @ApiParam(value = "Automation composition participant name") @RequestParam(
108 required = false) final String name,
109 @ApiParam(value = "Automation composition participant version", required = false) @RequestParam(
111 required = false) final String version,
112 @ApiParam(value = "Record count", required = false) @RequestParam(
113 value = "recordCount",
115 defaultValue = "0") final int recordCount,
116 @ApiParam(value = "start time", required = false) @RequestParam(
118 required = false) final String startTime,
119 @ApiParam(value = "end time", required = false) @RequestParam(
121 required = false) final String endTime) {
123 Instant startTimestamp = null;
124 Instant endTimestamp = null;
126 if (startTime != null) {
127 startTimestamp = Instant.parse(startTime);
129 if (endTime != null) {
130 endTimestamp = Instant.parse(endTime);
132 return ResponseEntity.ok().body(
133 provider.fetchFilteredParticipantStatistics(name, version, recordCount, startTimestamp, endTimestamp));
137 * Queries details of all participant statistics per automation composition.
139 * @param requestId request ID used in ONAP logging
140 * @param name the name of the automation composition
141 * @param version version of the automation composition
142 * @return the automation composition element statistics
145 @GetMapping(value = "/monitoring/participants/automationcomposition",
146 produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML})
147 @ApiOperation(value = "Query details of all the participant stats in a automation composition",
148 notes = "Queries details of the participant stats, returning all participant stats",
149 response = AcElementStatisticsList.class,
151 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
154 name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
155 response = String.class),
156 @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
157 response = String.class),
158 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
159 response = String.class),
160 @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
161 response = UUID.class)},
165 name = EXTENSION_NAME,
167 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
168 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
174 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
175 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
176 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
180 public ResponseEntity<ParticipantStatisticsList> queryParticipantStatisticsPerAutomationComposition(
181 @RequestHeader(name = REQUEST_ID_NAME, required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
182 @ApiParam(value = "Automation composition name", required = true) @RequestParam(
184 required = false) final String name,
185 @ApiParam(value = "Automation composition version", required = true) @RequestParam(
187 required = false) final String version) {
189 return ResponseEntity.ok().body(provider.fetchParticipantStatsPerAutomationComposition(name, version));
193 * Queries details of all automation composition element statistics per automation composition.
195 * @param requestId request ID used in ONAP logging
196 * @param name the name of the automation composition
197 * @param version version of the automation composition
198 * @return the automation composition element statistics
201 @GetMapping(value = "/monitoring/acelements/automationcomposition",
202 produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML})
203 @ApiOperation(value = "Query details of the requested acElement stats in a automation composition",
204 notes = "Queries details of the requested acElement stats, returning all acElement stats",
205 response = AcElementStatisticsList.class,
207 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
210 name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
211 response = String.class),
212 @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
213 response = String.class),
214 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
215 response = String.class),
216 @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
217 response = UUID.class)},
221 name = EXTENSION_NAME,
223 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
224 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
230 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
231 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
232 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
236 public ResponseEntity<AcElementStatisticsList> queryElementStatisticsPerAutomationComposition(
237 @RequestHeader(name = REQUEST_ID_NAME, required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
238 @ApiParam(value = "Automation composition name", required = true) @RequestParam(
240 required = false) final String name,
241 @ApiParam(value = "Automation composition version", required = true) @RequestParam(
243 required = false) final String version) {
245 return ResponseEntity.ok().body(provider.fetchAcElementStatsPerAutomationComposition(name, version));
249 * Queries details of all automation composition element statistics per automation composition.
251 * @param requestId request ID used in ONAP logging
252 * @param name the name of the automation composition
253 * @param version version of the automation composition
254 * @param id Id of the automation composition element
255 * @param recordCount the record count to be fetched
256 * @param startTime the time from which to get statistics
257 * @param endTime the time to which to get statistics
258 * @return the automation composition element statistics
259 * @throws PfModelException on errors getting details of all automation composition element statistics per
260 * automation composition
263 @GetMapping(value = "/monitoring/acelement",
264 produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML})
265 @ApiOperation(value = "Query details of the requested acElement stats",
266 notes = "Queries details of the requested acElement stats, returning all acElement stats",
267 response = AcElementStatisticsList.class,
269 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
272 name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
273 response = String.class),
274 @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
275 response = String.class),
276 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
277 response = String.class),
278 @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
279 response = UUID.class)},
283 name = EXTENSION_NAME,
285 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
286 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
292 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
293 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
294 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
298 public ResponseEntity<AcElementStatisticsList> queryElementStatistics(
299 @RequestHeader(name = REQUEST_ID_NAME, required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
300 @ApiParam(value = "Participant name", required = true) @RequestParam(
302 required = false) final String name,
303 @ApiParam(value = "Participant version", required = true) @RequestParam(
305 required = false) final String version,
306 @ApiParam(value = "Record count", required = false) @RequestParam(
307 value = "recordCount",
309 defaultValue = "0") final int recordCount,
310 @ApiParam(value = "Automation composition element id", required = false) @RequestParam(
312 required = false) final String id,
313 @ApiParam(value = "start time", required = false) @RequestParam(
315 required = false) final String startTime,
316 @ApiParam(value = "end time", required = false) @RequestParam(
318 required = false) final String endTime)
319 throws PfModelException {
321 Instant startTimestamp = null;
322 Instant endTimestamp = null;
324 if (startTime != null) {
325 startTimestamp = Instant.parse(startTime);
327 if (endTime != null) {
328 endTimestamp = Instant.parse(endTime);
330 return ResponseEntity.ok().body(
331 provider.fetchFilteredAcElementStatistics(name, version, id, startTimestamp, endTimestamp, recordCount));