2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019-2020 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 = {@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 = {"Policy Administration (PAP) API"},
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)},
98 extensions = {@Extension(name = EXTENSION_NAME,
99 properties = {@ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
100 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)})})
102 @ApiResponses(value = {@ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
103 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
104 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)})
105 public Response pdpStatistics(
106 @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) final UUID requestId) {
108 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
109 .entity(new StatisticsRestProvider().fetchDatabaseStatistics(null, null, null, NO_COUNT_LIMIT))
111 } catch (final PfModelException exp) {
112 LOGGER.info(GET_STATISTICS_ERR_MSG, exp);
113 return addLoggingHeaders(
114 addVersionControlHeaders(Response.status(exp.getErrorResponse().getResponseCode())), requestId)
120 * get all statistics of a PDP group.
122 * @param groupName name of the PDP group
126 @Path("pdps/statistics/{group}")
127 @ApiOperation(value = "Fetch current statistics for given PDP Group",
128 notes = "Returns statistics for given PDP Group of the Policy Administration component",
129 response = Map.class, tags = {"Policy Administration (PAP) API"},
130 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
132 @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
133 response = String.class),
134 @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
135 response = String.class),
136 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
137 response = String.class),
138 @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
139 response = UUID.class)},
140 extensions = {@Extension(name = EXTENSION_NAME,
141 properties = {@ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
142 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)})})
143 @ApiResponses(value = {@ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
144 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
145 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)})
146 public Response pdpGroupStatistics(
147 @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) final UUID requestId,
148 @ApiParam(value = "PDP Group Name", required = true) @PathParam("group") final String groupName) {
150 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
151 .entity(new StatisticsRestProvider().fetchDatabaseStatistics(groupName, null, null, NO_COUNT_LIMIT))
153 } catch (final PfModelException exp) {
154 LOGGER.info(GET_STATISTICS_ERR_MSG, exp);
155 return addLoggingHeaders(
156 addVersionControlHeaders(Response.status(exp.getErrorResponse().getResponseCode())), requestId)
162 * get all statistics of sub PDP group.
164 * @param groupName name of the PDP group
165 * @param subType type of the sub PDP group
169 @Path("pdps/statistics/{group}/{type}")
170 @ApiOperation(value = "Fetch statistics for the specified subgroup",
171 notes = "Returns statistics for the specified subgroup of the Policy Administration component",
172 response = Map.class, tags = {"Policy Administration (PAP) API"},
173 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
175 @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
176 response = String.class),
177 @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
178 response = String.class),
179 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
180 response = String.class),
181 @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
182 response = UUID.class)},
183 extensions = {@Extension(name = EXTENSION_NAME,
184 properties = {@ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
185 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)})})
186 @ApiResponses(value = {@ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
187 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
188 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)})
189 public Response pdpSubGroupStatistics(
190 @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) final UUID requestId,
191 @ApiParam(value = "PDP Group Name", required = true) @PathParam("group") final String groupName,
192 @ApiParam(value = "PDP SubGroup type", required = true) @PathParam("type") final String subType) {
194 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
195 .entity(new StatisticsRestProvider().fetchDatabaseStatistics(groupName, subType, null,
198 } catch (final PfModelException exp) {
199 LOGGER.info(GET_STATISTICS_ERR_MSG, exp);
200 return addLoggingHeaders(
201 addVersionControlHeaders(Response.status(exp.getErrorResponse().getResponseCode())), requestId)
207 * get all statistics of one PDP.
209 * @param groupName name of the PDP group
210 * @param subType type of the sub PDP group
211 * @param pdpName the name of the PDP
212 * @param recordCount the count of the query response, optional, default return all statistics stored
216 @Path("pdps/statistics/{group}/{type}/{pdp}")
217 @ApiOperation(value = "Fetch statistics for the specified pdp",
218 notes = "Returns statistics for the specified pdp of the Policy Administration component",
219 response = Map.class,
220 tags = {"Policy Administration (PAP) API"},
221 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
223 @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
224 response = String.class),
225 @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
226 response = String.class),
227 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
228 response = String.class),
229 @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
230 response = UUID.class)},
231 extensions = {@Extension(name = EXTENSION_NAME,
232 properties = {@ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
233 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)})})
234 @ApiResponses(value = {@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)})
238 public Response pdpInstanceStatistics(
239 @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) final UUID requestId,
240 @ApiParam(value = "PDP Group Name", required = true) @PathParam("group") final String groupName,
241 @ApiParam(value = "PDP SubGroup type", required = true) @PathParam("type") final String subType,
242 @ApiParam(value = "PDP Instance name", required = true) @PathParam("pdp") final String pdpName,
243 @ApiParam(value = "Record Count",
244 required = false) @DefaultValue("0") @QueryParam("recordCount") final int recordCount) {
246 return addLoggingHeaders(addVersionControlHeaders(Response.status(Response.Status.OK)), requestId)
247 .entity(new StatisticsRestProvider().fetchDatabaseStatistics(groupName, subType, pdpName,
250 } catch (final PfModelException exp) {
251 LOGGER.info(GET_STATISTICS_ERR_MSG, exp);
252 return addLoggingHeaders(
253 addVersionControlHeaders(Response.status(exp.getErrorResponse().getResponseCode())), requestId)