ITM impl Organize Imports for Checkstyle compliance
[genius.git] / itm / itm-impl / src / main / java / org / opendaylight / genius / itm / confighelpers / ItmMonitorToggleWorker.java
index f6ffb5a16cf061e81129764641076effd3b2dcef..ac65b232e8d726beb4f7e8dbc205389e7f6acb9a 100644 (file)
@@ -8,6 +8,9 @@
 package org.opendaylight.genius.itm.confighelpers;
 
 import com.google.common.util.concurrent.ListenableFuture;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Callable;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
@@ -25,25 +28,17 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.Callable;
-
 public class ItmMonitorToggleWorker implements Callable<List<ListenableFuture<Void>>> {
     private static final Logger logger = LoggerFactory.getLogger(ItmMonitorToggleWorker.class) ;
     private DataBroker dataBroker;
     private String tzone;
     private boolean enabled;
-    private List<HwVtep> hwVteps;
-    private  Boolean exists;
     private Class<? extends TunnelMonitoringTypeBase> monitorProtocol = ITMConstants.DEFAULT_MONITOR_PROTOCOL;
 
-    public  ItmMonitorToggleWorker(List<HwVtep> hwVteps,String tzone,boolean enabled, Class<? extends TunnelMonitoringTypeBase> monitorProtocol, DataBroker dataBroker, Boolean exists){
+    public  ItmMonitorToggleWorker(String tzone,boolean enabled, Class<? extends TunnelMonitoringTypeBase> monitorProtocol, DataBroker dataBroker){
         this.dataBroker = dataBroker;
         this.tzone = tzone;
         this.enabled = enabled;
-        this.hwVteps = hwVteps;
-        this.exists = exists;
         this.monitorProtocol = monitorProtocol;
         logger.trace("ItmMonitorToggleWorker initialized with  tzone {} and toggleBoolean {}",tzone,enabled );
         logger.debug("TunnelMonitorToggleWorker with monitor protocol = {} ",monitorProtocol);
@@ -51,36 +46,36 @@ public class ItmMonitorToggleWorker implements Callable<List<ListenableFuture<Vo
 
     @Override public List<ListenableFuture<Void>> call() throws Exception {
         List<ListenableFuture<Void>> futures = new ArrayList<>() ;
-        logger.debug("Invoking Tunnel Monitor Worker tzone = {} enabled {}",tzone,enabled );
+        logger.debug("ItmMonitorToggleWorker invoked with tzone = {} enabled {}",tzone,enabled );
         WriteTransaction t = dataBroker.newWriteOnlyTransaction();
-        toggleTunnelMonitoring(hwVteps,enabled,tzone,t,exists);
+        toggleTunnelMonitoring(enabled,tzone,t);
         futures.add(t.submit());
         return futures;
     }
 
-    private void toggleTunnelMonitoring(List<HwVtep> hwVteps,Boolean enabled, String tzone, WriteTransaction t,Boolean exists) {
-        //exists means hwVteps exist for this tzone
-
-        List<String> TunnelList = ItmUtils.getTunnelsofTzone(hwVteps,tzone,dataBroker,exists);
+    private void toggleTunnelMonitoring(Boolean enabled, String tzone, WriteTransaction t) {
+        List<String> TunnelList = ItmUtils.getInternalTunnelInterfaces(dataBroker);
+        logger.debug("toggleTunnelMonitoring: TunnelList size {}", TunnelList.size());
+        InstanceIdentifier<TunnelMonitorParams> iid = InstanceIdentifier.builder(TunnelMonitorParams.class).build();
+        TunnelMonitorParams protocolBuilder = new TunnelMonitorParamsBuilder().setEnabled(enabled).setMonitorProtocol(monitorProtocol).build();
+        logger.debug("toggleTunnelMonitoring: Updating Operational DS");
+        ItmUtils.asyncUpdate(LogicalDatastoreType.OPERATIONAL,iid, protocolBuilder, dataBroker, ItmUtils.DEFAULT_CALLBACK);
         if(TunnelList !=null &&!TunnelList.isEmpty()) {
-            for (String tunnel : TunnelList)
-                toggle(tunnel, enabled,t);
+            for (String tunnel : TunnelList) {
+                toggle(tunnel, enabled, t);
+            }
         }
     }
 
     private void toggle(String tunnelInterfaceName, boolean enabled, WriteTransaction t) {
         if(tunnelInterfaceName!=null) {
             InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(tunnelInterfaceName);
-            logger.debug("TunnelMonitorToggleWorker: toggle with monitor protocol = {} ",monitorProtocol);
+            logger.debug("TunnelMonitorToggleWorker: tunnelInterfaceName: {}, monitorProtocol = {},  monitorEnable = {} ",tunnelInterfaceName, monitorProtocol, enabled);
             IfTunnel tunnel = new IfTunnelBuilder().setMonitorEnabled(enabled).setMonitorProtocol(monitorProtocol).build();
             InterfaceBuilder builder = new InterfaceBuilder().setKey(new InterfaceKey(tunnelInterfaceName))
                     .addAugmentation(IfTunnel.class, tunnel);
             t.merge(LogicalDatastoreType.CONFIGURATION, trunkIdentifier, builder.build());
-            InstanceIdentifier<TunnelMonitorParams> iid = InstanceIdentifier.builder(TunnelMonitorParams.class).build();
-            TunnelMonitorParams protocolBuilder = new TunnelMonitorParamsBuilder().setEnabled(enabled).setMonitorProtocol(monitorProtocol).build();
-            ItmUtils.asyncUpdate(LogicalDatastoreType.OPERATIONAL,iid, protocolBuilder, dataBroker, ItmUtils.DEFAULT_CALLBACK);
-
-        }
+       }
     }
 }