c040ae6abb9e92058fb6b24c626db6406df15e4b
[policy/xacml-pdp.git] / main / src / main / java / org / onap / policy / pdpx / main / rest / XacmlPdpStatisticsManager.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * Copyright (C) 2019, 2021-2022 AT&T Intellectual Property. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.pdpx.main.rest;
22
23 import lombok.Getter;
24 import lombok.Setter;
25 import lombok.Synchronized;
26
27 /**
28  * Class to hold statistical data for xacmlPdp component.
29  */
30 @Getter(onMethod_ = @Synchronized)
31 public class XacmlPdpStatisticsManager {
32     @Getter
33     @Setter
34     private static XacmlPdpStatisticsManager current = null;
35
36     private long totalPolicyTypesCount;
37     private long totalPoliciesCount;
38     private long errorCount;
39     private long permitDecisionsCount;
40     private long denyDecisionsCount;
41     private long deploySuccessCount;
42     private long deployFailureCount;
43     private long undeploySuccessCount;
44     private long undeployFailureCount;
45     private long indeterminantDecisionsCount;
46     private long notApplicableDecisionsCount;
47
48     /**
49      * Method to set the xacml pdp total policy types count. This
50      * doesn't really increment, it depends on the applications
51      * that are loaded. Which can be dynamic.
52      *
53      * @return the total
54      */
55     @Synchronized
56     public long setTotalPolicyTypesCount(long newCount) {
57         totalPolicyTypesCount = newCount;
58         return totalPolicyTypesCount;
59     }
60
61     /**
62      * Method to set the xacml pdp total policies count. This
63      * doesn't really increment, it depends on the applications
64      * that are loaded. Which can be dynamic.
65      *
66      * @return the total
67      */
68     @Synchronized
69     public long setTotalPolicyCount(long newCount) {
70         totalPoliciesCount = newCount;
71         return totalPoliciesCount;
72     }
73
74     /**
75      * Method to update the number of error decisions.
76      *
77      * @return the errorDecisionsCount
78      */
79     @Synchronized
80     public long updateErrorCount() {
81         return ++errorCount;
82     }
83
84     /**
85      * Method to update the number of permit decisions.
86      *
87      * @return the permitDecisionsCount
88      */
89     @Synchronized
90     public long updatePermitDecisionsCount() {
91         return ++permitDecisionsCount;
92     }
93
94     /**
95      * Method to update the number of deny decisions.
96      *
97      * @return the denyDecisionsCount
98      */
99     @Synchronized
100     public long updateDenyDecisionsCount() {
101         return ++denyDecisionsCount;
102     }
103
104     /**
105      * Method to update the number of successful deploys.
106      *
107      * @return the deploySuccessCount
108      */
109     @Synchronized
110     public long updateDeploySuccessCount() {
111         return ++deploySuccessCount;
112     }
113
114     /**
115      * Method to update the number of failed deploys.
116      *
117      * @return the deployFailureCount
118      */
119     @Synchronized
120     public long updateDeployFailureCount() {
121         return ++deployFailureCount;
122     }
123
124     /**
125      * Method to update the number of successful undeploys.
126      *
127      * @return the undeploySuccessCount
128      */
129     @Synchronized
130     public long updateUndeploySuccessCount() {
131         return ++undeploySuccessCount;
132     }
133
134     /**
135      * Method to update the number of failed undeploys.
136      *
137      * @return the undeployFailureCount
138      */
139     @Synchronized
140     public long updateUndeployFailureCount() {
141         return ++undeployFailureCount;
142     }
143
144     /**
145      * Method to update the number of indeterminant decisions.
146      *
147      * @return the indeterminantDecisionsCount
148      */
149     @Synchronized
150     public long updateIndeterminantDecisionsCount() {
151         return ++indeterminantDecisionsCount;
152     }
153
154     /**
155      * Method to update the number of not applicable decisions.
156      *
157      * @return the notApplicableDecisionsCount
158      */
159     @Synchronized
160     public long updateNotApplicableDecisionsCount() {
161         return ++notApplicableDecisionsCount;
162     }
163
164     /**
165      * Reset all the statistics counts to 0.
166      */
167     @Synchronized
168     public void resetAllStatistics() {
169         totalPolicyTypesCount = 0L;
170         totalPoliciesCount = 0L;
171         errorCount = 0L;
172         permitDecisionsCount = 0L;
173         denyDecisionsCount = 0L;
174         deploySuccessCount = 0L;
175         deployFailureCount = 0L;
176         undeploySuccessCount = 0L;
177         undeployFailureCount = 0L;
178         indeterminantDecisionsCount = 0L;
179         notApplicableDecisionsCount = 0L;
180     }
181 }