Merge "Fetch and Delete policy API with PolicyName and PolicyVersion"
[policy/api.git] / main / src / main / java / org / onap / policy / api / main / rest / ApiStatisticsManager.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy API
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2020 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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  *
20  * SPDX-License-Identifier: Apache-2.0
21  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.policy.api.main.rest;
25
26 import lombok.Getter;
27
28 /**
29  * Class to hold statistical data for API access.
30  *
31  * @author Chenfei Gao (cgao@research.att.com)
32  */
33 public class ApiStatisticsManager {
34
35     @Getter
36     private static long totalApiCallCount;
37
38     @Getter
39     private static long apiCallSuccessCount;
40
41     @Getter
42     private static long apiCallFailureCount;
43
44     @Getter
45     private static long totalPolicyGetCount;
46
47     @Getter
48     private static long totalPolicyPostCount;
49
50     @Getter
51     private static long totalPolicyDeleteCount;
52
53     @Getter
54     private static long totalPolicyTypeGetCount;
55
56     @Getter
57     private static long totalPolicyTypePostCount;
58
59     @Getter
60     private static long totalPolicyTypeDeleteCount;
61
62     @Getter
63     private static long policyGetSuccessCount;
64
65     @Getter
66     private static long policyGetFailureCount;
67
68     @Getter
69     private static long policyPostSuccessCount;
70
71     @Getter
72     private static long policyPostFailureCount;
73
74     @Getter
75     private static long policyDeleteSuccessCount;
76
77     @Getter
78     private static long policyDeleteFailureCount;
79
80     @Getter
81     private static long policyTypeGetSuccessCount;
82
83     @Getter
84     private static long policyTypeGetFailureCount;
85
86     @Getter
87     private static long policyTypePostSuccessCount;
88
89     @Getter
90     private static long policyTypePostFailureCount;
91
92     @Getter
93     private static long policyTypeDeleteSuccessCount;
94
95     @Getter
96     private static long policyTypeDeleteFailureCount;
97
98     private ApiStatisticsManager() {
99         throw new IllegalStateException("Instantiation of the class is not allowed");
100     }
101
102     /**
103      * Method to update the total api call count.
104      *
105      * @return the updated value of totalApiCallCount
106      */
107     public static long updateTotalApiCallCount() {
108         return ++totalApiCallCount;
109     }
110
111     /**
112      * Method to update the successful api call count.
113      *
114      * @return the updated value of apiCallSuccessCount
115      */
116     public static long updateApiCallSuccessCount() {
117         return ++apiCallSuccessCount;
118     }
119
120     /**
121      * Method to update the failed api call count.
122      *
123      * @return the updated value of apiCallFailureCount
124      */
125     public static long updateApiCallFailureCount() {
126         return ++apiCallFailureCount;
127     }
128
129     /**
130      * Method to update the total policy GET count.
131      *
132      * @return the updated value of totalPolicyGetCount
133      */
134     public static long updateTotalPolicyGetCount() {
135         return ++totalPolicyGetCount;
136     }
137
138     /**
139      * Method to update the total policy POST count.
140      *
141      * @return the updated value of totalPolicyPostCount
142      */
143     public static long updateTotalPolicyPostCount() {
144         return ++totalPolicyPostCount;
145     }
146
147     /**
148      * Method to update the total policy DELETE count.
149      *
150      * @return the updated value of  totalPolicyDeleteCount
151      */
152     public static long updateTotalPolicyDeleteCount() {
153         return ++totalPolicyDeleteCount;
154     }
155
156     /**
157      * Method to update the total policyType GET count.
158      *
159      * @return the updated value of totalPolicyTypeGetCount
160      */
161     public static long updateTotalPolicyTypeGetCount() {
162         return ++totalPolicyTypeGetCount;
163     }
164
165     /**
166      * Method to update the total policyType POST count.
167      *
168      * @return the updated value of totalPolicyTypePostCount
169      */
170     public static long updateTotalPolicyTypePostCount() {
171         return ++totalPolicyTypePostCount;
172     }
173
174     /**
175      * Method to update the total policyType DELETE count.
176      *
177      * @return the updated value of totalPolicyTypeDeleteCount
178      */
179     public static long updateTotalPolicyTypeDeleteCount() {
180         return ++totalPolicyTypeDeleteCount;
181     }
182
183     /**
184      * Method to update successful policy GET count.
185      *
186      * @return the updated value of policyGetSuccessCount
187      */
188     public static long updatePolicyGetSuccessCount() {
189         return ++policyGetSuccessCount;
190     }
191
192     /**
193      * Method to update failed policy GET count.
194      *
195      * @return the updated value of policyGetFailureCount
196      */
197     public static long updatePolicyGetFailureCount() {
198         return ++policyGetFailureCount;
199     }
200
201     /**
202      * Method to update successful policy POST count.
203      *
204      * @return the updated value of policyPostSuccessCount
205      */
206     public static long updatePolicyPostSuccessCount() {
207         return ++policyPostSuccessCount;
208     }
209
210     /**
211      * Method to update failed policy POST count.
212      *
213      * @return the updated value of policyPostFailureCount
214      */
215     public static long updatePolicyPostFailureCount() {
216         return ++policyPostFailureCount;
217     }
218
219     /**
220      * Method to update successful policy DELETE count.
221      *
222      * @return the updated value of policyDeleteSuccessCount
223      */
224     public static long updatePolicyDeleteSuccessCount() {
225         return ++policyDeleteSuccessCount;
226     }
227
228     /**
229      * Method to update failed policy DELETE count.
230      *
231      * @return the updated value of policyDeleteFailureCount
232      */
233     public static long updatePolicyDeleteFailureCount() {
234         return ++policyDeleteFailureCount;
235     }
236
237     /**
238      * Method to update successful policyType GET count.
239      *
240      * @return the updated value of policyTypeGetSuccessCount
241      */
242     public static long updatePolicyTypeGetSuccessCount() {
243         return ++policyTypeGetSuccessCount;
244     }
245
246     /**
247      * Method to update failed policyType GET count.
248      *
249      * @return the updated value of policyTypeGetFailureCount
250      */
251     public static long updatePolicyTypeGetFailureCount() {
252         return ++policyTypeGetFailureCount;
253     }
254
255     /**
256      * Method to update successful policyType POST count.
257      *
258      * @return the updated value of policyTypePostSuccessCount
259      */
260     public static long updatePolicyTypePostSuccessCount() {
261         return ++policyTypePostSuccessCount;
262     }
263
264     /**
265      * Method to update failed policyType POST count.
266      *
267      * @return the updated value of policyTypePostFailureCount
268      */
269     public static long updatePolicyTypePostFailureCount() {
270         return ++policyTypePostFailureCount;
271     }
272
273     /**
274      * Method to update successful policyType DELETE count.
275      *
276      * @return the updated value of policyTypeDeleteSuccessCount
277      */
278     public static long updatePolicyTypeDeleteSuccessCount() {
279         return ++policyTypeDeleteSuccessCount;
280     }
281
282     /**
283      * Method to update failed policyType DELETE count.
284      *
285      * @return the updated value of policyTypePostFailureCount
286      */
287     public static long updatePolicyTypeDeleteFailureCount() {
288         return ++policyTypeDeleteFailureCount;
289     }
290
291     /**
292      * Reset all the statistics counts to 0.
293      */
294     public static void resetAllStatistics() {
295         totalApiCallCount = 0L;
296         apiCallSuccessCount = 0L;
297         apiCallFailureCount = 0L;
298         totalPolicyGetCount = 0L;
299         totalPolicyPostCount = 0L;
300         totalPolicyDeleteCount = 0L;
301         totalPolicyTypeGetCount = 0L;
302         totalPolicyTypePostCount = 0L;
303         totalPolicyTypeDeleteCount = 0L;
304         policyGetSuccessCount = 0L;
305         policyGetFailureCount = 0L;
306         policyPostSuccessCount = 0L;
307         policyPostFailureCount = 0L;
308         policyDeleteSuccessCount = 0L;
309         policyDeleteFailureCount = 0L;
310         policyTypeGetSuccessCount = 0L;
311         policyTypeGetFailureCount = 0L;
312         policyTypePostSuccessCount = 0L;
313         policyTypePostFailureCount = 0L;
314         policyTypeDeleteSuccessCount = 0L;
315         policyTypeDeleteFailureCount = 0L;
316
317     }
318
319 }