2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019-2021 Nordix Foundation.
4 * Modifications Copyright (C) 2019 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.DefaultValue;
35 import javax.ws.rs.GET;
36 import javax.ws.rs.HeaderParam;
37 import javax.ws.rs.Path;
38 import javax.ws.rs.PathParam;
39 import javax.ws.rs.QueryParam;
40 import javax.ws.rs.core.Response;
41 import org.onap.policy.models.base.PfModelException;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
46 * Class to provide REST endpoints for PAP component statistics.
48 * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
50 public class StatisticsRestControllerV1 extends PapRestControllerV1 {
52 private static final Logger LOGGER = LoggerFactory.getLogger(StatisticsRestControllerV1.class);
53 private static final String GET_STATISTICS_ERR_MSG = "get pdpStatistics failed";
54 private static final int NO_COUNT_LIMIT = 0;
57 * get statistics of PAP.
64 @ApiOperation(value = "Fetch current statistics",
65 notes = "Returns current statistics of the Policy Administration component",
66 response = StatisticsReport.class, authorizations = @Authorization(value = AUTHORIZATION_TYPE))
67 @ApiResponses(value = {
68 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
69 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
70 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)})
71 public Response statistics(
72 @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) final UUID requestId) {
73 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
74 .entity(new StatisticsRestProvider().fetchCurrentStatistics())
79 * get all statistics of PDP groups.
85 @Path("pdps/statistics")
86 @ApiOperation(value = "Fetch statistics for all PDP Groups and subgroups in the system",
87 notes = "Returns for all PDP Groups and subgroups statistics of the Policy Administration component",
88 response = Map.class, tags = {"Policy Administration (PAP) API"},
89 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
91 @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
92 response = String.class),
93 @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
94 response = String.class),
95 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
96 response = String.class),
97 @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
98 response = UUID.class)},
100 @Extension(name = EXTENSION_NAME,
102 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
103 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
107 @ApiResponses(value = {
108 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
109 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
110 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
112 public Response pdpStatistics(
113 @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) final UUID requestId) {
115 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
116 .entity(new StatisticsRestProvider().fetchDatabaseStatistics(null, null, null, NO_COUNT_LIMIT))
118 } catch (final PfModelException exp) {
119 LOGGER.info(GET_STATISTICS_ERR_MSG, exp);
120 return addLoggingHeaders(
121 addVersionControlHeaders(Response.status(exp.getErrorResponse().getResponseCode())), requestId)
127 * get all statistics of a PDP group.
129 * @param groupName name of the PDP group
133 @Path("pdps/statistics/{group}")
134 @ApiOperation(value = "Fetch current statistics for given PDP Group",
135 notes = "Returns statistics for given PDP Group of the Policy Administration component",
136 response = Map.class, tags = {"Policy Administration (PAP) API"},
137 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
139 @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
140 response = String.class),
141 @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
142 response = String.class),
143 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
144 response = String.class),
145 @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
146 response = UUID.class)},
148 @Extension(name = EXTENSION_NAME,
150 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
151 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
154 @ApiResponses(value = {
155 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
156 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
157 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
159 public Response pdpGroupStatistics(
160 @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) final UUID requestId,
161 @ApiParam(value = "PDP Group Name", required = true) @PathParam("group") final String groupName) {
163 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
164 .entity(new StatisticsRestProvider().fetchDatabaseStatistics(groupName, null, null, NO_COUNT_LIMIT))
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) {
213 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
214 .entity(new StatisticsRestProvider().fetchDatabaseStatistics(groupName, subType, null,
217 } catch (final PfModelException exp) {
218 LOGGER.info(GET_STATISTICS_ERR_MSG, exp);
219 return addLoggingHeaders(
220 addVersionControlHeaders(Response.status(exp.getErrorResponse().getResponseCode())), requestId)
226 * get all statistics of one PDP.
228 * @param groupName name of the PDP group
229 * @param subType type of the sub PDP group
230 * @param pdpName the name of the PDP
231 * @param recordCount the count of the query response, optional, default return all statistics stored
235 @Path("pdps/statistics/{group}/{type}/{pdp}")
236 @ApiOperation(value = "Fetch statistics for the specified pdp",
237 notes = "Returns statistics for the specified pdp of the Policy Administration component",
238 response = Map.class,
239 tags = {"Policy Administration (PAP) API"},
240 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
242 @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
243 response = String.class),
244 @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
245 response = String.class),
246 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
247 response = String.class),
248 @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
249 response = UUID.class)},
251 @Extension(name = EXTENSION_NAME,
253 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
254 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
257 @ApiResponses(value = {
258 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
259 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
260 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
262 public Response pdpInstanceStatistics(
263 @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) final UUID requestId,
264 @ApiParam(value = "PDP Group Name", required = true) @PathParam("group") final String groupName,
265 @ApiParam(value = "PDP SubGroup type", required = true) @PathParam("type") final String subType,
266 @ApiParam(value = "PDP Instance name", required = true) @PathParam("pdp") final String pdpName,
267 @ApiParam(value = "Record Count",
268 required = false) @DefaultValue("0") @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)