2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019-2021 Nordix Foundation.
4 * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.pap.main.rest;
24 import io.swagger.annotations.ApiOperation;
25 import io.swagger.annotations.ApiParam;
26 import io.swagger.annotations.ApiResponse;
27 import io.swagger.annotations.ApiResponses;
28 import io.swagger.annotations.Authorization;
29 import io.swagger.annotations.Extension;
30 import io.swagger.annotations.ExtensionProperty;
31 import io.swagger.annotations.ResponseHeader;
33 import java.util.UUID;
34 import javax.ws.rs.GET;
35 import javax.ws.rs.HeaderParam;
36 import javax.ws.rs.Path;
37 import javax.ws.rs.PathParam;
38 import javax.ws.rs.QueryParam;
39 import javax.ws.rs.core.Response;
40 import org.onap.policy.models.base.PfModelException;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
45 * Class to provide REST endpoints for PAP component statistics.
47 * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
49 public class StatisticsRestControllerV1 extends PapRestControllerV1 {
51 private static final Logger LOGGER = LoggerFactory.getLogger(StatisticsRestControllerV1.class);
52 private static final String GET_STATISTICS_ERR_MSG = "get pdpStatistics failed";
55 * get statistics of PAP.
62 @ApiOperation(value = "Fetch current statistics",
63 notes = "Returns current statistics of the Policy Administration component",
64 response = StatisticsReport.class, authorizations = @Authorization(value = AUTHORIZATION_TYPE))
65 @ApiResponses(value = {
66 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
67 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
68 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)})
69 public Response statistics(
70 @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) final UUID requestId) {
71 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
72 .entity(new StatisticsRestProvider().fetchCurrentStatistics())
77 * get all statistics of PDP groups.
83 @Path("pdps/statistics")
84 @ApiOperation(value = "Fetch statistics for all PDP Groups and subgroups in the system",
85 notes = "Returns for all PDP Groups and subgroups statistics of the Policy Administration component",
86 response = Map.class, tags = {"Policy Administration (PAP) API"},
87 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
89 @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
90 response = String.class),
91 @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
92 response = String.class),
93 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
94 response = String.class),
95 @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
96 response = UUID.class)},
98 @Extension(name = EXTENSION_NAME,
100 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
101 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
105 @ApiResponses(value = {
106 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
107 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
108 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
110 public Response pdpStatistics(
111 @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) final UUID requestId,
112 @ApiParam(value = "Record Count", required = false) @QueryParam("recordCount") final int recordCount) {
114 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
115 .entity(new StatisticsRestProvider().fetchDatabaseStatistics(null, null, null, recordCount))
117 } catch (final PfModelException exp) {
118 LOGGER.info(GET_STATISTICS_ERR_MSG, exp);
119 return addLoggingHeaders(
120 addVersionControlHeaders(Response.status(exp.getErrorResponse().getResponseCode())), requestId)
126 * get all statistics of a PDP group.
128 * @param groupName name of the PDP group
132 @Path("pdps/statistics/{group}")
133 @ApiOperation(value = "Fetch current statistics for given PDP Group",
134 notes = "Returns statistics for given PDP Group of the Policy Administration component",
135 response = Map.class, tags = {"Policy Administration (PAP) API"},
136 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
138 @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
139 response = String.class),
140 @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
141 response = String.class),
142 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
143 response = String.class),
144 @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
145 response = UUID.class)},
147 @Extension(name = EXTENSION_NAME,
149 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
150 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
153 @ApiResponses(value = {
154 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
155 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
156 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
158 public Response pdpGroupStatistics(
159 @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) final UUID requestId,
160 @ApiParam(value = "PDP Group Name", required = true) @PathParam("group") final String groupName,
161 @ApiParam(value = "Record Count", required = false) @QueryParam("recordCount") final int recordCount) {
163 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
164 .entity(new StatisticsRestProvider().fetchDatabaseStatistics(groupName, null, null, recordCount))
166 } catch (final PfModelException exp) {
167 LOGGER.info(GET_STATISTICS_ERR_MSG, exp);
168 return addLoggingHeaders(
169 addVersionControlHeaders(Response.status(exp.getErrorResponse().getResponseCode())), requestId)
175 * get all statistics of sub PDP group.
177 * @param groupName name of the PDP group
178 * @param subType type of the sub PDP group
182 @Path("pdps/statistics/{group}/{type}")
183 @ApiOperation(value = "Fetch statistics for the specified subgroup",
184 notes = "Returns statistics for the specified subgroup of the Policy Administration component",
185 response = Map.class, tags = {"Policy Administration (PAP) API"},
186 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
188 @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
189 response = String.class),
190 @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
191 response = String.class),
192 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
193 response = String.class),
194 @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
195 response = UUID.class)},
197 @Extension(name = EXTENSION_NAME,
199 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
200 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
203 @ApiResponses(value = {
204 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
205 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
206 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
208 public Response pdpSubGroupStatistics(
209 @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) final UUID requestId,
210 @ApiParam(value = "PDP Group Name", required = true) @PathParam("group") final String groupName,
211 @ApiParam(value = "PDP SubGroup type", required = true) @PathParam("type") final String subType,
212 @ApiParam(value = "Record Count", required = false) @QueryParam("recordCount") final int recordCount) {
214 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
215 .entity(new StatisticsRestProvider().fetchDatabaseStatistics(groupName, subType, null,
218 } catch (final PfModelException exp) {
219 LOGGER.info(GET_STATISTICS_ERR_MSG, exp);
220 return addLoggingHeaders(
221 addVersionControlHeaders(Response.status(exp.getErrorResponse().getResponseCode())), requestId)
227 * get all statistics of one PDP.
229 * @param groupName name of the PDP group
230 * @param subType type of the sub PDP group
231 * @param pdpName the name of the PDP
232 * @param recordCount the count of the query response, optional, default return all statistics stored
236 @Path("pdps/statistics/{group}/{type}/{pdp}")
237 @ApiOperation(value = "Fetch statistics for the specified pdp",
238 notes = "Returns statistics for the specified pdp of the Policy Administration component",
239 response = Map.class,
240 tags = {"Policy Administration (PAP) API"},
241 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
243 @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
244 response = String.class),
245 @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
246 response = String.class),
247 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
248 response = String.class),
249 @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
250 response = UUID.class)},
252 @Extension(name = EXTENSION_NAME,
254 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
255 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
258 @ApiResponses(value = {
259 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
260 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
261 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
263 public Response pdpInstanceStatistics(
264 @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) final UUID requestId,
265 @ApiParam(value = "PDP Group Name", required = true) @PathParam("group") final String groupName,
266 @ApiParam(value = "PDP SubGroup type", required = true) @PathParam("type") final String subType,
267 @ApiParam(value = "PDP Instance name", required = true) @PathParam("pdp") final String pdpName,
268 @ApiParam(value = "Record Count", required = false) @QueryParam("recordCount") final int recordCount) {
270 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
271 .entity(new StatisticsRestProvider().fetchDatabaseStatistics(groupName, subType, pdpName,
274 } catch (final PfModelException exp) {
275 LOGGER.info(GET_STATISTICS_ERR_MSG, exp);
276 return addLoggingHeaders(
277 addVersionControlHeaders(Response.status(exp.getErrorResponse().getResponseCode())), requestId)