2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.policy.pdp.rest.jmx;
23 import java.util.HashMap;
25 import java.util.concurrent.atomic.AtomicLong;
27 import org.openecomp.policy.xacml.util.MetricsUtil.AvgLatency;
28 import org.openecomp.policy.xacml.util.MetricsUtil.MaxLatency;
29 import org.openecomp.policy.xacml.util.MetricsUtil.MinLatency;
31 public class PdpRestMonitor implements PdpRestMonitorMBean {
32 private static PdpRestMonitor singleton = new PdpRestMonitor();
34 private final AtomicLong pdpEvaluationAttempts = new AtomicLong();
35 private final AtomicLong pdpEvaluationSuccesses = new AtomicLong();
36 private final AtomicLong pdpEvaluationNA = new AtomicLong();
37 private final AtomicLong pdpEvaluationPermit = new AtomicLong();
38 private final AtomicLong pdpEvaluationDeny = new AtomicLong();
39 private final Map<String, Integer> policyCount = new HashMap<>();
41 private final MinLatency pdpEngineDecisionMinLatency = new MinLatency();
42 private final MaxLatency pdpEngineDecisionMaxLatency = new MaxLatency();
43 private final AvgLatency pdpEngineDecisionAvgLatency = new AvgLatency();
45 private volatile long lastDecisionLatency = 0;
48 public long getPdpEvaluationAttempts() {
49 return pdpEvaluationAttempts.longValue();
52 public long getPdpEvaluationPermit() {
53 return pdpEvaluationPermit.longValue();
56 public long getPdpEvaluationDeny() {
57 return pdpEvaluationDeny.longValue();
60 public long getPdpEvaluationSuccesses() {
61 return pdpEvaluationSuccesses.longValue();
65 public long getpdpEvaluationNA() {
66 return pdpEvaluationNA.longValue();
69 public long getLastDecisionLatency() {
70 return lastDecisionLatency;
74 * @return the pdpEngineDecisionMinLatency
77 public long getPdpEngineDecisionMinLatency() {
78 return pdpEngineDecisionMinLatency.min();
82 * @return the pdpEngineDecisionMaxLatency
85 public long getPdpEngineDecisionMaxLatency() {
86 return pdpEngineDecisionMaxLatency.max();
90 * @return the pdpEngineDecisionAvgLatency
93 public long getPdpEngineDecisionAvgLatency() {
94 return pdpEngineDecisionAvgLatency.avg();
98 public synchronized void resetLatency() {
99 this.lastDecisionLatency = 0;
100 this.pdpEngineDecisionMinLatency.reset();
101 this.pdpEngineDecisionMaxLatency.reset();
102 this.pdpEngineDecisionAvgLatency.reset();
106 public synchronized void resetCounters() {
107 this.pdpEvaluationAttempts.set(0);
108 this.pdpEvaluationSuccesses.set(0);
109 this.pdpEvaluationNA.set(0);
110 this.policyCount.clear();
113 public void pdpEvaluationAttempts() {
114 pdpEvaluationAttempts.incrementAndGet();
117 public void pdpEvaluationSuccess() {
118 pdpEvaluationSuccesses.incrementAndGet();
121 public void pdpEvaluationNA(){
122 pdpEvaluationNA.incrementAndGet();
124 public void pdpEvaluationPermit(){
125 pdpEvaluationPermit.incrementAndGet();
127 public void pdpEvaluationDeny(){
128 pdpEvaluationDeny.incrementAndGet();
131 public synchronized void computeLatency(long latency) {
132 this.lastDecisionLatency = latency;
133 this.pdpEngineDecisionMinLatency.compute(latency);
134 this.pdpEngineDecisionMaxLatency.compute(latency);
135 this.pdpEngineDecisionAvgLatency.compute(latency);
138 public void policyCountAdd(String policyID, Integer count){
139 int countValue = count;
140 if (policyCount.containsKey(policyID)){
141 countValue = countValue + policyCount.get(policyID);
143 policyCount.put(policyID, countValue);
145 public Map<String, Integer> getpolicyMap() {
148 public Integer getpolicyCount(String policyID) {
149 if (policyCount.containsKey(policyID)){
150 return policyCount.get(policyID);
155 public static PdpRestMonitor getSingleton() {
158 public static void setSingleton(PdpRestMonitor singleton) {
159 PdpRestMonitor.singleton = singleton;