2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2020-2021 Bell Canada.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
20 * SPDX-License-Identifier: Apache-2.0
21 * ============LICENSE_END=========================================================
24 package org.onap.policy.api.main.rest;
27 import lombok.NoArgsConstructor;
30 * Class to hold statistical data for API access.
32 * @author Chenfei Gao (cgao@research.att.com)
36 public class ApiStatisticsManager {
38 private static ApiStatisticsManager instance = new ApiStatisticsManager();
40 private StatisticsReport report = new StatisticsReport();
41 private long totalPolicyDeleteCount;
42 private long totalPolicyTypeDeleteCount;
43 private long policyDeleteSuccessCount;
44 private long policyDeleteFailureCount;
45 private long policyTypeDeleteSuccessCount;
46 private long policyTypeDeleteFailureCount;
49 * Method to update the total api call count.
51 * @return the updated value of totalApiCallCount
53 public long updateTotalApiCallCount() {
54 return ++report.totalApiCallCount;
58 * Method to update the successful api call count.
60 * @return the updated value of apiCallSuccessCount
62 public long updateApiCallSuccessCount() {
63 return ++report.apiCallSuccessCount;
67 * Method to update the failed api call count.
69 * @return the updated value of apiCallFailureCount
71 public long updateApiCallFailureCount() {
72 return ++report.apiCallFailureCount;
76 * Method to update the total policy GET count.
78 * @return the updated value of totalPolicyGetCount
80 public long updateTotalPolicyGetCount() {
81 return ++report.totalPolicyGetCount;
85 * Method to update the total policy POST count.
87 * @return the updated value of totalPolicyPostCount
89 public long updateTotalPolicyPostCount() {
90 return ++report.totalPolicyPostCount;
94 * Method to update the total policy DELETE count.
96 * @return the updated value of totalPolicyDeleteCount
98 public long updateTotalPolicyDeleteCount() {
99 return ++totalPolicyDeleteCount;
103 * Method to update the total policyType GET count.
105 * @return the updated value of totalPolicyTypeGetCount
107 public long updateTotalPolicyTypeGetCount() {
108 return ++report.totalPolicyTypeGetCount;
112 * Method to update the total policyType POST count.
114 * @return the updated value of totalPolicyTypePostCount
116 public long updateTotalPolicyTypePostCount() {
117 return ++report.totalPolicyTypePostCount;
121 * Method to update the total policyType DELETE count.
123 * @return the updated value of totalPolicyTypeDeleteCount
125 public long updateTotalPolicyTypeDeleteCount() {
126 return ++totalPolicyTypeDeleteCount;
130 * Method to update successful policy GET count.
132 * @return the updated value of policyGetSuccessCount
134 public long updatePolicyGetSuccessCount() {
135 return ++report.policyGetSuccessCount;
139 * Method to update failed policy GET count.
141 * @return the updated value of policyGetFailureCount
143 public long updatePolicyGetFailureCount() {
144 return ++report.policyGetFailureCount;
148 * Method to update successful policy POST count.
150 * @return the updated value of policyPostSuccessCount
152 public long updatePolicyPostSuccessCount() {
153 return ++report.policyPostSuccessCount;
157 * Method to update failed policy POST count.
159 * @return the updated value of policyPostFailureCount
161 public long updatePolicyPostFailureCount() {
162 return ++report.policyPostFailureCount;
166 * Method to update successful policy DELETE count.
168 * @return the updated value of policyDeleteSuccessCount
170 public long updatePolicyDeleteSuccessCount() {
171 return ++policyDeleteSuccessCount;
175 * Method to update failed policy DELETE count.
177 * @return the updated value of policyDeleteFailureCount
179 public long updatePolicyDeleteFailureCount() {
180 return ++policyDeleteFailureCount;
184 * Method to update successful policyType GET count.
186 * @return the updated value of policyTypeGetSuccessCount
188 public long updatePolicyTypeGetSuccessCount() {
189 return ++report.policyTypeGetSuccessCount;
193 * Method to update failed policyType GET count.
195 * @return the updated value of policyTypeGetFailureCount
197 public long updatePolicyTypeGetFailureCount() {
198 return ++report.policyTypeGetFailureCount;
202 * Method to update successful policyType POST count.
204 * @return the updated value of policyTypePostSuccessCount
206 public long updatePolicyTypePostSuccessCount() {
207 return ++report.policyTypePostSuccessCount;
211 * Method to update failed policyType POST count.
213 * @return the updated value of policyTypePostFailureCount
215 public long updatePolicyTypePostFailureCount() {
216 return ++report.policyTypePostFailureCount;
220 * Method to update successful policyType DELETE count.
222 * @return the updated value of policyTypeDeleteSuccessCount
224 public long updatePolicyTypeDeleteSuccessCount() {
225 return ++policyTypeDeleteSuccessCount;
229 * Method to update failed policyType DELETE count.
231 * @return the updated value of policyTypePostFailureCount
233 public long updatePolicyTypeDeleteFailureCount() {
234 return ++policyTypeDeleteFailureCount;
238 * Resets the statistics.
240 protected static void resetAllStatistics() {
241 instance = new ApiStatisticsManager();