2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 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 policyExecutedCount = new AtomicLong(0);
35 private final AtomicLong policyExecutedSuccessCount = new AtomicLong(0);
36 private final AtomicLong policyExecutedFailCount = new AtomicLong(0);
39 * Constructs the object.
41 public ApexPolicyStatisticsManager() {
46 * To get the ApexPolicyStatisticsManager in Registry.
48 * @return ApexPolicyStatisticsManager The obj in Registry.
50 public static ApexPolicyStatisticsManager getInstanceFromRegistry() {
51 ApexPolicyStatisticsManager instance = null;
53 instance = Registry.get(ApexPolicyStatisticsManager.REG_APEX_PDP_POLICY_COUNTER);
54 } catch (IllegalArgumentException e) {
55 LOGGER.debug("ApexPolicyStatisticsManager is not registered yet");
62 * Update the policy deploy count.
64 public void updatePolicyDeployCounter(final boolean isSuccessful) {
65 this.updatepPolicyDeployCount();
67 this.updatePolicyDeployFailCount();
69 this.updatePolicyDeploySuccessCount();
74 * Update the policy executed count.
76 public void updatePolicyExecutedCounter(final boolean isSuccessful) {
77 this.updatePolicyExecutedCount();
79 this.updatePolicyExecutedSuccessCount();
81 this.updatePolicyExecutedFailCount();
86 * Method to update the total policy deploy count.
88 * @return the updated value of policyDeployCount
90 private long updatepPolicyDeployCount() {
91 return policyDeployCount.incrementAndGet();
95 * Method to update the total policy deploy failed count.
97 * @return the updated value of totalPolicyDeployCount
99 private long updatePolicyDeployFailCount() {
100 return policyDeployFailCount.incrementAndGet();
104 * Method to update the policy deploy success count.
106 * @return the updated value of policyDeploySuccessCount
108 private long updatePolicyDeploySuccessCount() {
109 return policyDeploySuccessCount.incrementAndGet();
114 * Method to update the total policy executed count.
116 * @return the updated value of policyExecutedCount
118 private long updatePolicyExecutedCount() {
119 return policyExecutedCount.incrementAndGet();
123 * Method to update the policy executed success count.
125 * @return the updated value of policyExecutedSuccessCount
127 private long updatePolicyExecutedSuccessCount() {
128 return policyExecutedSuccessCount.incrementAndGet();
132 * Method to update the policy executed failure count.
134 * @return the updated value of policyExecutedFailCount
136 private long updatePolicyExecutedFailCount() {
137 return policyExecutedFailCount.incrementAndGet();
141 * Reset all the statistics counts to 0.
143 public void resetAllStatistics() {
144 policyDeployCount.set(0L);
145 policyDeployFailCount.set(0L);
146 policyDeploySuccessCount.set(0L);
147 policyExecutedCount.set(0L);
148 policyExecutedSuccessCount.set(0L);
149 policyExecutedFailCount.set(0L);
152 public long getPolicyDeployCount() {
153 return policyDeployCount.get();
156 public long getPolicyDeployFailCount() {
157 return policyDeployFailCount.get();
160 public long getPolicyDeploySuccessCount() {
161 return policyDeploySuccessCount.get();
164 public long getPolicyExecutedCount() {
165 return policyExecutedCount.get();
168 public long getPolicyExecutedSuccessCount() {
169 return policyExecutedSuccessCount.get();
172 public long getPolicyExecutedFailCount() {
173 return policyExecutedFailCount.get();