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.Map.Entry;
27 import java.util.concurrent.atomic.AtomicLong;
28 import java.util.concurrent.atomic.AtomicReference;
29 import java.util.function.BinaryOperator;
31 import org.openecomp.policy.xacml.util.MetricsUtil.AvgLatency;
32 import org.openecomp.policy.xacml.util.MetricsUtil.MaxLatency;
33 import org.openecomp.policy.xacml.util.MetricsUtil.MinLatency;
35 public class PdpRestMonitor implements PdpRestMonitorMBean {
36 public static PdpRestMonitor singleton = new PdpRestMonitor();
38 private final AtomicLong pdpEvaluationAttempts = new AtomicLong();
39 private final AtomicLong pdpEvaluationSuccesses = new AtomicLong();
40 private final AtomicLong pdpEvaluationNA = new AtomicLong();
41 private final AtomicLong pdpEvaluationPermit = new AtomicLong();
42 private final AtomicLong pdpEvaluationDeny = new AtomicLong();
43 private final Map<String, Integer> policyCount = new HashMap<>();
45 private final MinLatency pdpEngineDecisionMinLatency = new MinLatency();
46 private final MaxLatency pdpEngineDecisionMaxLatency = new MaxLatency();
47 private final AvgLatency pdpEngineDecisionAvgLatency = new AvgLatency();
49 private volatile long lastDecisionLatency = 0;
52 public long getPdpEvaluationAttempts() {
53 return pdpEvaluationAttempts.longValue();
56 public long getPdpEvaluationPermit() {
57 return pdpEvaluationPermit.longValue();
60 public long getPdpEvaluationDeny() {
61 return pdpEvaluationDeny.longValue();
64 public long getPdpEvaluationSuccesses() {
65 return pdpEvaluationSuccesses.longValue();
69 public long getpdpEvaluationNA() {
70 return pdpEvaluationNA.longValue();
73 public long getLastDecisionLatency() {
74 return lastDecisionLatency;
78 * @return the pdpEngineDecisionMinLatency
81 public long getPdpEngineDecisionMinLatency() {
82 return pdpEngineDecisionMinLatency.min();
86 * @return the pdpEngineDecisionMaxLatency
89 public long getPdpEngineDecisionMaxLatency() {
90 return pdpEngineDecisionMaxLatency.max();
94 * @return the pdpEngineDecisionAvgLatency
97 public long getPdpEngineDecisionAvgLatency() {
98 return pdpEngineDecisionAvgLatency.avg();
102 public synchronized void resetLatency() {
103 this.lastDecisionLatency = 0;
104 this.pdpEngineDecisionMinLatency.reset();
105 this.pdpEngineDecisionMaxLatency.reset();
106 this.pdpEngineDecisionAvgLatency.reset();
110 public synchronized void resetCounters() {
111 this.pdpEvaluationAttempts.set(0);
112 this.pdpEvaluationSuccesses.set(0);
113 this.pdpEvaluationNA.set(0);
114 this.policyCount.clear();
117 public void pdpEvaluationAttempts() {
118 pdpEvaluationAttempts.incrementAndGet();
121 public void pdpEvaluationSuccess() {
122 pdpEvaluationSuccesses.incrementAndGet();
125 public void pdpEvaluationNA(){
126 pdpEvaluationNA.incrementAndGet();
128 public void pdpEvaluationPermit(){
129 pdpEvaluationPermit.incrementAndGet();
131 public void pdpEvaluationDeny(){
132 pdpEvaluationDeny.incrementAndGet();
135 public synchronized void computeLatency(long latency) {
136 this.lastDecisionLatency = latency;
137 this.pdpEngineDecisionMinLatency.compute(latency);
138 this.pdpEngineDecisionMaxLatency.compute(latency);
139 this.pdpEngineDecisionAvgLatency.compute(latency);
142 public void policyCountAdd(String policyID, Integer count){
143 if (policyCount.containsKey(policyID)){
144 count = count + policyCount.get(policyID);
146 policyCount.put(policyID, count);
148 public Map<String, Integer> getpolicyMap() {
151 public Integer getpolicyCount(String policyID) {
152 // TODO Auto-generated method stub
153 if (policyCount.containsKey(policyID)){
154 return policyCount.get(policyID);