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.onap.policy.models.pdp.persistence.provider.PdpFilterParameters;
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";
56 * get statistics of PAP.
63 @ApiOperation(value = "Fetch current statistics",
64 notes = "Returns current statistics of the Policy Administration component",
65 response = StatisticsReport.class, authorizations = @Authorization(value = AUTHORIZATION_TYPE))
66 @ApiResponses(value = {
67 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
68 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
69 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)})
70 public Response statistics(
71 @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) final UUID requestId) {
72 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
73 .entity(new StatisticsRestProvider().fetchCurrentStatistics())
78 * get all statistics of PDP groups.
84 @Path("pdps/statistics")
85 @ApiOperation(value = "Fetch statistics for all PDP Groups and subgroups in the system",
86 notes = "Returns for all PDP Groups and subgroups statistics of the Policy Administration component",
87 response = Map.class, tags = {"PDP Statistics"},
88 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
90 @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
91 response = String.class),
92 @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
93 response = String.class),
94 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
95 response = String.class),
96 @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
97 response = UUID.class)},
99 @Extension(name = EXTENSION_NAME,
101 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
102 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
106 @ApiResponses(value = {
107 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
108 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
109 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
111 public Response pdpStatistics(
112 @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) final UUID requestId,
113 @ApiParam(value = "Record Count", required = false) @QueryParam("recordCount") final int recordCount) {
115 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
116 .entity(new StatisticsRestProvider().fetchDatabaseStatistics(
117 PdpFilterParameters.builder().recordNum(recordCount).build()))
119 } catch (final PfModelException exp) {
120 LOGGER.info(GET_STATISTICS_ERR_MSG, exp);
121 return addLoggingHeaders(
122 addVersionControlHeaders(Response.status(exp.getErrorResponse().getResponseCode())), requestId)
128 * get all statistics of a PDP group.
130 * @param groupName name of the PDP group
134 @Path("pdps/statistics/{group}")
135 @ApiOperation(value = "Fetch current statistics for given PDP Group",
136 notes = "Returns statistics for given PDP Group of the Policy Administration component",
137 response = Map.class, tags = {"PDP Statistics"},
138 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
140 @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
141 response = String.class),
142 @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
143 response = String.class),
144 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
145 response = String.class),
146 @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
147 response = UUID.class)},
149 @Extension(name = EXTENSION_NAME,
151 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
152 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
155 @ApiResponses(value = {
156 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
157 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
158 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
160 public Response pdpGroupStatistics(
161 @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) final UUID requestId,
162 @ApiParam(value = "PDP Group Name", required = true) @PathParam("group") final String groupName,
163 @ApiParam(value = "Record Count", required = false) @QueryParam("recordCount") final int recordCount) {
165 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
166 .entity(new StatisticsRestProvider().fetchDatabaseStatistics(PdpFilterParameters.builder()
167 .group(groupName).recordNum(recordCount).build()))
169 } catch (final PfModelException exp) {
170 LOGGER.info(GET_STATISTICS_ERR_MSG, exp);
171 return addLoggingHeaders(
172 addVersionControlHeaders(Response.status(exp.getErrorResponse().getResponseCode())), requestId)
178 * get all statistics of sub PDP group.
180 * @param groupName name of the PDP group
181 * @param subType type of the sub PDP group
185 @Path("pdps/statistics/{group}/{type}")
186 @ApiOperation(value = "Fetch statistics for the specified subgroup",
187 notes = "Returns statistics for the specified subgroup of the Policy Administration component",
188 response = Map.class, tags = {"PDP Statistics"},
189 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
191 @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
192 response = String.class),
193 @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
194 response = String.class),
195 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
196 response = String.class),
197 @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
198 response = UUID.class)},
200 @Extension(name = EXTENSION_NAME,
202 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
203 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
206 @ApiResponses(value = {
207 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
208 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
209 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
211 public Response pdpSubGroupStatistics(
212 @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) final UUID requestId,
213 @ApiParam(value = "PDP Group Name", required = true) @PathParam("group") final String groupName,
214 @ApiParam(value = "PDP SubGroup type", required = true) @PathParam("type") final String subType,
215 @ApiParam(value = "Record Count", required = false) @QueryParam("recordCount") final int recordCount) {
217 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
218 .entity(new StatisticsRestProvider().fetchDatabaseStatistics(PdpFilterParameters.builder()
219 .group(groupName).subGroup(subType).recordNum(recordCount).build()))
221 } catch (final PfModelException exp) {
222 LOGGER.info(GET_STATISTICS_ERR_MSG, exp);
223 return addLoggingHeaders(
224 addVersionControlHeaders(Response.status(exp.getErrorResponse().getResponseCode())), requestId)
230 * get all statistics of one PDP.
232 * @param groupName name of the PDP group
233 * @param subType type of the sub PDP group
234 * @param pdpName the name of the PDP
235 * @param recordCount the count of the query response, optional, default return all statistics stored
239 @Path("pdps/statistics/{group}/{type}/{pdp}")
240 @ApiOperation(value = "Fetch statistics for the specified pdp",
241 notes = "Returns statistics for the specified pdp of the Policy Administration component",
242 response = Map.class,
243 tags = {"PDP Statistics"},
244 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
246 @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
247 response = String.class),
248 @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
249 response = String.class),
250 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
251 response = String.class),
252 @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
253 response = UUID.class)},
255 @Extension(name = EXTENSION_NAME,
257 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
258 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
261 @ApiResponses(value = {
262 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
263 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
264 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
266 public Response pdpInstanceStatistics(
267 @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) final UUID requestId,
268 @ApiParam(value = "PDP Group Name", required = true) @PathParam("group") final String groupName,
269 @ApiParam(value = "PDP SubGroup type", required = true) @PathParam("type") final String subType,
270 @ApiParam(value = "PDP Instance name", required = true) @PathParam("pdp") final String pdpName,
271 @ApiParam(value = "Record Count", required = false) @QueryParam("recordCount") final int recordCount) {
273 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
274 .entity(new StatisticsRestProvider().fetchDatabaseStatistics(
275 PdpFilterParameters.builder().group(groupName).subGroup(subType)
276 .name(pdpName).recordNum(recordCount).build()))
278 } catch (final PfModelException exp) {
279 LOGGER.info(GET_STATISTICS_ERR_MSG, exp);
280 return addLoggingHeaders(
281 addVersionControlHeaders(Response.status(exp.getErrorResponse().getResponseCode())), requestId)