2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020-2021 Nordix Foundation.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.service.engine.main;
23 import java.util.concurrent.atomic.AtomicLong;
24 import org.onap.policy.common.utils.services.Registry;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 public class ApexPolicyStatisticsManager {
29 private static final Logger LOGGER = LoggerFactory.getLogger(ApexPolicyStatisticsManager.class);
30 public static final String REG_APEX_PDP_POLICY_COUNTER = "object:pdp/statistics/policy/counter";
31 private final AtomicLong policyDeployCount = new AtomicLong(0);
32 private final AtomicLong policyDeploySuccessCount = new AtomicLong(0);
33 private final AtomicLong policyDeployFailCount = new AtomicLong(0);
34 private final AtomicLong policyUndeployCount = new AtomicLong(0);
35 private final AtomicLong policyUndeploySuccessCount = new AtomicLong(0);
36 private final AtomicLong policyUndeployFailCount = new AtomicLong(0);
37 private final AtomicLong policyExecutedCount = new AtomicLong(0);
38 private final AtomicLong policyExecutedSuccessCount = new AtomicLong(0);
39 private final AtomicLong policyExecutedFailCount = new AtomicLong(0);
42 * Constructs the object.
44 public ApexPolicyStatisticsManager() {
49 * To get the ApexPolicyStatisticsManager in Registry.
51 * @return ApexPolicyStatisticsManager The obj in Registry.
53 public static ApexPolicyStatisticsManager getInstanceFromRegistry() {
54 ApexPolicyStatisticsManager instance = null;
56 instance = Registry.get(ApexPolicyStatisticsManager.REG_APEX_PDP_POLICY_COUNTER);
57 } catch (IllegalArgumentException e) {
58 LOGGER.debug("ApexPolicyStatisticsManager is not registered yet");
65 * Update the policy deploy count.
67 public void updatePolicyDeployCounter(final boolean isSuccessful) {
68 this.updatepPolicyDeployCount();
70 this.updatePolicyDeployFailCount();
72 this.updatePolicyDeploySuccessCount();
77 * Update the policy executed count.
79 public void updatePolicyExecutedCounter(final boolean isSuccessful) {
80 this.updatePolicyExecutedCount();
82 this.updatePolicyExecutedSuccessCount();
84 this.updatePolicyExecutedFailCount();
90 * Update the policy undeploy count.
92 public void updatePolicyUndeployCounter(final boolean isSuccessful) {
93 this.policyUndeployCount.incrementAndGet();
95 this.policyUndeploySuccessCount.incrementAndGet();
97 this.policyUndeployFailCount.incrementAndGet();
102 * Method to update the total policy deploy count.
104 * @return the updated value of policyDeployCount
106 private long updatepPolicyDeployCount() {
107 return policyDeployCount.incrementAndGet();
111 * Method to update the total policy deploy failed count.
113 * @return the updated value of totalPolicyDeployCount
115 private long updatePolicyDeployFailCount() {
116 return policyDeployFailCount.incrementAndGet();
120 * Method to update the policy deploy success count.
122 * @return the updated value of policyDeploySuccessCount
124 private long updatePolicyDeploySuccessCount() {
125 return policyDeploySuccessCount.incrementAndGet();
130 * Method to update the total policy executed count.
132 * @return the updated value of policyExecutedCount
134 private long updatePolicyExecutedCount() {
135 return policyExecutedCount.incrementAndGet();
139 * Method to update the policy executed success count.
141 * @return the updated value of policyExecutedSuccessCount
143 private long updatePolicyExecutedSuccessCount() {
144 return policyExecutedSuccessCount.incrementAndGet();
148 * Method to update the policy executed failure count.
150 * @return the updated value of policyExecutedFailCount
152 private long updatePolicyExecutedFailCount() {
153 return policyExecutedFailCount.incrementAndGet();
157 * Reset all the statistics counts to 0.
159 public void resetAllStatistics() {
160 policyDeployCount.set(0L);
161 policyDeployFailCount.set(0L);
162 policyDeploySuccessCount.set(0L);
163 policyUndeployCount.set(0L);
164 policyUndeployFailCount.set(0L);
165 policyUndeploySuccessCount.set(0L);
166 policyExecutedCount.set(0L);
167 policyExecutedSuccessCount.set(0L);
168 policyExecutedFailCount.set(0L);
171 public long getPolicyDeployCount() {
172 return policyDeployCount.get();
175 public long getPolicyDeployFailCount() {
176 return policyDeployFailCount.get();
179 public long getPolicyDeploySuccessCount() {
180 return policyDeploySuccessCount.get();
183 public long getPolicyExecutedCount() {
184 return policyExecutedCount.get();
187 public long getPolicyExecutedSuccessCount() {
188 return policyExecutedSuccessCount.get();
191 public long getPolicyExecutedFailCount() {
192 return policyExecutedFailCount.get();
195 public long getPolicyUndeployCount() {
196 return policyUndeployCount.get();
199 public long getPolicyUndeploySuccessCount() {
200 return policyUndeploySuccessCount.get();
203 public long getPolicyUndeployFailCount() {
204 return policyUndeployFailCount.get();