Fix build faliures due to OFPlugin checktyle fixes
[netvirt.git] / vpnservice / qosservice / impl / src / main / java / org / opendaylight / netvirt / qosservice / QosAlertPortData.java
index 27e812f2ce2d2f905683d15ad42836f1778557a5..73c48f448c7d007a8fcfff8fbe1b73679686bb4a 100644 (file)
@@ -9,34 +9,31 @@
 package org.opendaylight.netvirt.qosservice;
 
 import java.math.BigInteger;
-import org.opendaylight.netvirt.neutronvpn.interfaces.INeutronVpnManager;
+import java.util.function.Supplier;
+import javax.annotation.concurrent.NotThreadSafe;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.qos.rev160613.qos.attributes.qos.policies.QosPolicy;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.node.connector.statistics.and.port.number.map.NodeConnectorStatisticsAndPortNumberMap;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+@NotThreadSafe
 public class QosAlertPortData {
-    private final Port port;
-    private static INeutronVpnManager neutronVpnManager;
-    private BigInteger rxPackets;
-    private BigInteger rxDroppedPackets;
-    private static BigInteger   alertThreshold;
-    private boolean statsDataInit;
-
-    private static final BigInteger BIG_HUNDRED = new BigInteger("100");
     private static final Logger LOG = LoggerFactory.getLogger(QosAlertPortData.class);
+    private static final BigInteger BIG_HUNDRED = new BigInteger("100");
 
+    private final Port port;
+    private final QosNeutronUtils qosNeutronUtils;
+    private final Supplier<BigInteger> alertThreshold;
+    private volatile BigInteger rxPackets;
+    private volatile BigInteger rxDroppedPackets;
+    private volatile boolean statsDataInit;
 
-    public QosAlertPortData(final Port port, final INeutronVpnManager neutronVpnManager) {
+    public QosAlertPortData(final Port port, final QosNeutronUtils qosNeutronUtils,
+            final Supplier<BigInteger> alertThreshold) {
         this.port = port;
-        QosAlertPortData.neutronVpnManager = neutronVpnManager;
-        statsDataInit = false;
-    }
-
-    public static void setAlertThreshold(int threshold) {
-        alertThreshold = BigInteger.valueOf(threshold);
-        LOG.info("setAlertThreshold:{}", alertThreshold);
+        this.qosNeutronUtils = qosNeutronUtils;
+        this.alertThreshold = alertThreshold;
     }
 
     public void initPortData() {
@@ -45,6 +42,9 @@ public class QosAlertPortData {
     }
 
     public void updatePortStatistics(NodeConnectorStatisticsAndPortNumberMap statsData) {
+        LOG.trace("Port {} rx-packets {} tx-packets {} rx-dropped {} tx-dropped {}", port.getUuid(),
+                           statsData.getPackets().getReceived(), statsData.getPackets().getTransmitted(),
+                           statsData.getReceiveDrops(), statsData.getTransmitDrops());
         if (statsDataInit) {
             calculateAlertCondition(statsData);
         }
@@ -60,14 +60,14 @@ public class QosAlertPortData {
         BigInteger rxTotalDiff = rxDiff.add(rxDroppedDiff);
         LOG.trace("Port {} rxDiff:{} rxDropped diff:{} total diff:{}", port.getUuid(), rxDiff,
                                                                             rxDroppedDiff, rxTotalDiff);
-        QosPolicy qosPolicy = QosNeutronUtils.getQosPolicy(neutronVpnManager, port);
+        QosPolicy qosPolicy = qosNeutronUtils.getQosPolicy(port);
 
         if (qosPolicy == null) {
             return;
         }
 
-        if (rxDroppedDiff.multiply(BIG_HUNDRED).compareTo(rxTotalDiff.multiply(alertThreshold)) > 0) {
-            LOG.trace(QosConstants.alertMsgFormat, qosPolicy.getName(), qosPolicy.getUuid().getValue(),
+        if (rxDroppedDiff.multiply(BIG_HUNDRED).compareTo(rxTotalDiff.multiply(alertThreshold.get())) > 0) {
+            LOG.trace(QosConstants.ALERT_MSG_FORMAT, qosPolicy.getName(), qosPolicy.getUuid().getValue(),
                     port.getUuid().getValue(), port.getNetworkId().getValue(), statsData.getPackets().getReceived(),
                                                                                         statsData.getReceiveDrops());