2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020-2021 Nordix Foundation.
4 * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.apex.service.engine.main;
24 import java.util.concurrent.atomic.AtomicLong;
25 import lombok.NoArgsConstructor;
26 import org.onap.policy.common.utils.services.Registry;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
31 public class ApexPolicyStatisticsManager {
32 private static final Logger LOGGER = LoggerFactory.getLogger(ApexPolicyStatisticsManager.class);
33 public static final String REG_APEX_PDP_POLICY_COUNTER = "object:pdp/statistics/policy/counter";
34 private final AtomicLong policyDeployCount = new AtomicLong(0);
35 private final AtomicLong policyDeploySuccessCount = new AtomicLong(0);
36 private final AtomicLong policyDeployFailCount = new AtomicLong(0);
37 private final AtomicLong policyUndeployCount = new AtomicLong(0);
38 private final AtomicLong policyUndeploySuccessCount = new AtomicLong(0);
39 private final AtomicLong policyUndeployFailCount = new AtomicLong(0);
40 private final AtomicLong policyExecutedCount = new AtomicLong(0);
41 private final AtomicLong policyExecutedSuccessCount = new AtomicLong(0);
42 private final AtomicLong policyExecutedFailCount = new AtomicLong(0);
45 * To get the ApexPolicyStatisticsManager in Registry.
47 * @return ApexPolicyStatisticsManager The obj in Registry.
49 public static ApexPolicyStatisticsManager getInstanceFromRegistry() {
50 ApexPolicyStatisticsManager instance = null;
52 instance = Registry.get(ApexPolicyStatisticsManager.REG_APEX_PDP_POLICY_COUNTER);
53 } catch (IllegalArgumentException e) {
54 LOGGER.debug("ApexPolicyStatisticsManager is not registered yet");
61 * Update the policy deploy count.
63 public void updatePolicyDeployCounter(final boolean isSuccessful) {
64 this.updatepPolicyDeployCount();
66 this.updatePolicyDeployFailCount();
68 this.updatePolicyDeploySuccessCount();
73 * Update the policy executed count.
75 public void updatePolicyExecutedCounter(final boolean isSuccessful) {
76 this.updatePolicyExecutedCount();
78 this.updatePolicyExecutedSuccessCount();
80 this.updatePolicyExecutedFailCount();
86 * Update the policy undeploy count.
88 public void updatePolicyUndeployCounter(final boolean isSuccessful) {
89 this.policyUndeployCount.incrementAndGet();
91 this.policyUndeploySuccessCount.incrementAndGet();
93 this.policyUndeployFailCount.incrementAndGet();
98 * Method to update the total policy deploy count.
100 * @return the updated value of policyDeployCount
102 private long updatepPolicyDeployCount() {
103 return policyDeployCount.incrementAndGet();
107 * Method to update the total policy deploy failed count.
109 * @return the updated value of totalPolicyDeployCount
111 private long updatePolicyDeployFailCount() {
112 return policyDeployFailCount.incrementAndGet();
116 * Method to update the policy deploy success count.
118 * @return the updated value of policyDeploySuccessCount
120 private long updatePolicyDeploySuccessCount() {
121 return policyDeploySuccessCount.incrementAndGet();
126 * Method to update the total policy executed count.
128 * @return the updated value of policyExecutedCount
130 private long updatePolicyExecutedCount() {
131 return policyExecutedCount.incrementAndGet();
135 * Method to update the policy executed success count.
137 * @return the updated value of policyExecutedSuccessCount
139 private long updatePolicyExecutedSuccessCount() {
140 return policyExecutedSuccessCount.incrementAndGet();
144 * Method to update the policy executed failure count.
146 * @return the updated value of policyExecutedFailCount
148 private long updatePolicyExecutedFailCount() {
149 return policyExecutedFailCount.incrementAndGet();
153 * Reset all the statistics counts to 0.
155 public void resetAllStatistics() {
156 policyDeployCount.set(0L);
157 policyDeployFailCount.set(0L);
158 policyDeploySuccessCount.set(0L);
159 policyUndeployCount.set(0L);
160 policyUndeployFailCount.set(0L);
161 policyUndeploySuccessCount.set(0L);
162 policyExecutedCount.set(0L);
163 policyExecutedSuccessCount.set(0L);
164 policyExecutedFailCount.set(0L);
167 public long getPolicyDeployCount() {
168 return policyDeployCount.get();
171 public long getPolicyDeployFailCount() {
172 return policyDeployFailCount.get();
175 public long getPolicyDeploySuccessCount() {
176 return policyDeploySuccessCount.get();
179 public long getPolicyExecutedCount() {
180 return policyExecutedCount.get();
183 public long getPolicyExecutedSuccessCount() {
184 return policyExecutedSuccessCount.get();
187 public long getPolicyExecutedFailCount() {
188 return policyExecutedFailCount.get();
191 public long getPolicyUndeployCount() {
192 return policyUndeployCount.get();
195 public long getPolicyUndeploySuccessCount() {
196 return policyUndeploySuccessCount.get();
199 public long getPolicyUndeployFailCount() {
200 return policyUndeployFailCount.get();