Bug 8146:BFD tunnel monitoring interval update fix
[genius.git] / itm / itm-impl / src / main / java / org / opendaylight / genius / itm / confighelpers / ItmMonitorToggleWorker.java
index 313d559b694f06f21919d27b01beee1d04143267..82126df52817bef1cda571d93fc116e83554a75b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright (c) 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -8,14 +8,13 @@
 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;
-import org.opendaylight.genius.itm.globals.ITMConstants;
 import org.opendaylight.genius.itm.impl.ItmUtils;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnelBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelMonitoringTypeBase;
@@ -25,61 +24,58 @@ 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 Class<? extends TunnelMonitoringTypeBase> monitorProtocol = ITMConstants.DEFAULT_MONITOR_PROTOCOL;
 
-    public  ItmMonitorToggleWorker(String tzone,boolean enabled, Class<? extends TunnelMonitoringTypeBase> monitorProtocol, DataBroker dataBroker){
+    private static final Logger LOG = LoggerFactory.getLogger(ItmMonitorToggleWorker.class);
+
+    private final DataBroker dataBroker;
+    private final String tzone;
+    private final boolean enabled;
+    private final Class<? extends TunnelMonitoringTypeBase> monitorProtocol;
+
+    public ItmMonitorToggleWorker(String tzone, boolean enabled,
+            Class<? extends TunnelMonitoringTypeBase> monitorProtocol, DataBroker dataBroker) {
         this.dataBroker = dataBroker;
         this.tzone = tzone;
         this.enabled = enabled;
         this.monitorProtocol = monitorProtocol;
-        logger.trace("ItmMonitorToggleWorker initialized with  tzone {} and toggleBoolean {}",tzone,enabled );
-        logger.debug("TunnelMonitorToggleWorker with monitor protocol = {} ",monitorProtocol);
+        LOG.trace("ItmMonitorToggleWorker initialized with  tzone {} and toggleBoolean {}",tzone,enabled);
+        LOG.debug("TunnelMonitorToggleWorker with monitor protocol = {} ",monitorProtocol);
     }
 
-    @Override public List<ListenableFuture<Void>> call() throws Exception {
+    @Override public List<ListenableFuture<Void>> call() {
         List<ListenableFuture<Void>> futures = new ArrayList<>() ;
-        logger.debug("ItmMonitorToggleWorker invoked with tzone = {} enabled {}",tzone,enabled );
-        WriteTransaction t = dataBroker.newWriteOnlyTransaction();
-        toggleTunnelMonitoring(enabled,tzone,t);
-        futures.add(t.submit());
+        LOG.debug("ItmMonitorToggleWorker invoked with tzone = {} enabled {}",tzone,enabled);
+        WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
+        toggleTunnelMonitoring(transaction);
+        futures.add(transaction.submit());
         return futures;
     }
 
-    private void toggleTunnelMonitoring(Boolean enabled, String tzone, WriteTransaction t) {
-        List<String> TunnelList = ItmUtils.getInternalTunnelInterfaces(dataBroker);
-        logger.debug("toggleTunnelMonitoring: TunnelList size {}", TunnelList.size());
+    private void toggleTunnelMonitoring(WriteTransaction transaction) {
+        List<String> tunnelList = ItmUtils.getInternalTunnelInterfaces(dataBroker);
+        LOG.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);
+        TunnelMonitorParams protocolBuilder = new TunnelMonitorParamsBuilder()
+                .setEnabled(enabled).setMonitorProtocol(monitorProtocol).build();
+        LOG.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, transaction);
             }
         }
     }
 
-    private void toggle(String tunnelInterfaceName, boolean enabled, WriteTransaction t) {
-        if(tunnelInterfaceName!=null) {
-            InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(tunnelInterfaceName);
-            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());
-       }
+    private void toggle(String tunnelInterfaceName, WriteTransaction transaction) {
+        if (tunnelInterfaceName != null) {
+            InstanceIdentifier<IfTunnel> trunkIdentifier = ItmUtils.buildTunnelId(tunnelInterfaceName);
+            LOG.debug("TunnelMonitorToggleWorker: tunnelInterfaceName: {}, monitorProtocol = {},  "
+                    + "monitorEnable = {} ",tunnelInterfaceName, monitorProtocol, enabled);
+            IfTunnel tunnel = new IfTunnelBuilder().setMonitorEnabled(enabled)
+                    .setMonitorProtocol(monitorProtocol).build();
+            transaction.merge(LogicalDatastoreType.CONFIGURATION, trunkIdentifier, tunnel);
+        }
     }
 }
-
-
-
-