Use singleton for api statistics
[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, 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
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 import lombok.NoArgsConstructor;
28
29 /**
30  * Class to hold statistical data for API access.
31  *
32  * @author Chenfei Gao (cgao@research.att.com)
33  */
34 @Getter
35 @NoArgsConstructor
36 public class ApiStatisticsManager {
37     @Getter
38     private static ApiStatisticsManager instance = new ApiStatisticsManager();
39
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;
47
48     /**
49      * Method to update the total api call count.
50      *
51      * @return the updated value of totalApiCallCount
52      */
53     public long updateTotalApiCallCount() {
54         return ++report.totalApiCallCount;
55     }
56
57     /**
58      * Method to update the successful api call count.
59      *
60      * @return the updated value of apiCallSuccessCount
61      */
62     public long updateApiCallSuccessCount() {
63         return ++report.apiCallSuccessCount;
64     }
65
66     /**
67      * Method to update the failed api call count.
68      *
69      * @return the updated value of apiCallFailureCount
70      */
71     public long updateApiCallFailureCount() {
72         return ++report.apiCallFailureCount;
73     }
74
75     /**
76      * Method to update the total policy GET count.
77      *
78      * @return the updated value of totalPolicyGetCount
79      */
80     public long updateTotalPolicyGetCount() {
81         return ++report.totalPolicyGetCount;
82     }
83
84     /**
85      * Method to update the total policy POST count.
86      *
87      * @return the updated value of totalPolicyPostCount
88      */
89     public long updateTotalPolicyPostCount() {
90         return ++report.totalPolicyPostCount;
91     }
92
93     /**
94      * Method to update the total policy DELETE count.
95      *
96      * @return the updated value of  totalPolicyDeleteCount
97      */
98     public long updateTotalPolicyDeleteCount() {
99         return ++totalPolicyDeleteCount;
100     }
101
102     /**
103      * Method to update the total policyType GET count.
104      *
105      * @return the updated value of totalPolicyTypeGetCount
106      */
107     public long updateTotalPolicyTypeGetCount() {
108         return ++report.totalPolicyTypeGetCount;
109     }
110
111     /**
112      * Method to update the total policyType POST count.
113      *
114      * @return the updated value of totalPolicyTypePostCount
115      */
116     public long updateTotalPolicyTypePostCount() {
117         return ++report.totalPolicyTypePostCount;
118     }
119
120     /**
121      * Method to update the total policyType DELETE count.
122      *
123      * @return the updated value of totalPolicyTypeDeleteCount
124      */
125     public long updateTotalPolicyTypeDeleteCount() {
126         return ++totalPolicyTypeDeleteCount;
127     }
128
129     /**
130      * Method to update successful policy GET count.
131      *
132      * @return the updated value of policyGetSuccessCount
133      */
134     public long updatePolicyGetSuccessCount() {
135         return ++report.policyGetSuccessCount;
136     }
137
138     /**
139      * Method to update failed policy GET count.
140      *
141      * @return the updated value of policyGetFailureCount
142      */
143     public long updatePolicyGetFailureCount() {
144         return ++report.policyGetFailureCount;
145     }
146
147     /**
148      * Method to update successful policy POST count.
149      *
150      * @return the updated value of policyPostSuccessCount
151      */
152     public long updatePolicyPostSuccessCount() {
153         return ++report.policyPostSuccessCount;
154     }
155
156     /**
157      * Method to update failed policy POST count.
158      *
159      * @return the updated value of policyPostFailureCount
160      */
161     public long updatePolicyPostFailureCount() {
162         return ++report.policyPostFailureCount;
163     }
164
165     /**
166      * Method to update successful policy DELETE count.
167      *
168      * @return the updated value of policyDeleteSuccessCount
169      */
170     public long updatePolicyDeleteSuccessCount() {
171         return ++policyDeleteSuccessCount;
172     }
173
174     /**
175      * Method to update failed policy DELETE count.
176      *
177      * @return the updated value of policyDeleteFailureCount
178      */
179     public long updatePolicyDeleteFailureCount() {
180         return ++policyDeleteFailureCount;
181     }
182
183     /**
184      * Method to update successful policyType GET count.
185      *
186      * @return the updated value of policyTypeGetSuccessCount
187      */
188     public long updatePolicyTypeGetSuccessCount() {
189         return ++report.policyTypeGetSuccessCount;
190     }
191
192     /**
193      * Method to update failed policyType GET count.
194      *
195      * @return the updated value of policyTypeGetFailureCount
196      */
197     public long updatePolicyTypeGetFailureCount() {
198         return ++report.policyTypeGetFailureCount;
199     }
200
201     /**
202      * Method to update successful policyType POST count.
203      *
204      * @return the updated value of policyTypePostSuccessCount
205      */
206     public long updatePolicyTypePostSuccessCount() {
207         return ++report.policyTypePostSuccessCount;
208     }
209
210     /**
211      * Method to update failed policyType POST count.
212      *
213      * @return the updated value of policyTypePostFailureCount
214      */
215     public long updatePolicyTypePostFailureCount() {
216         return ++report.policyTypePostFailureCount;
217     }
218
219     /**
220      * Method to update successful policyType DELETE count.
221      *
222      * @return the updated value of policyTypeDeleteSuccessCount
223      */
224     public long updatePolicyTypeDeleteSuccessCount() {
225         return ++policyTypeDeleteSuccessCount;
226     }
227
228     /**
229      * Method to update failed policyType DELETE count.
230      *
231      * @return the updated value of policyTypePostFailureCount
232      */
233     public long updatePolicyTypeDeleteFailureCount() {
234         return ++policyTypeDeleteFailureCount;
235     }
236
237     /**
238      * Resets the statistics.
239      */
240     protected static void resetAllStatistics() {
241         instance = new ApiStatisticsManager();
242     }
243 }