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.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.util.Datastore;
+import org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner;
+import org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.mdsal.binding.util.TypedWriteTransaction;
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;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class ItmMonitorToggleWorker implements Callable<List<ListenableFuture<Void>>> {
- private static final Logger LOG = LoggerFactory.getLogger(ItmMonitorToggleWorker.class) ;
- private DataBroker dataBroker;
- private String tzone;
- private boolean enabled;
- private Class<? extends TunnelMonitoringTypeBase> monitorProtocol = ITMConstants.DEFAULT_MONITOR_PROTOCOL;
+public class ItmMonitorToggleWorker implements Callable<List<? extends ListenableFuture<?>>> {
- 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;
+ private final ManagedNewTransactionRunner txRunner;
+
+ public ItmMonitorToggleWorker(String tzone, boolean enabled,
+ Class<? extends TunnelMonitoringTypeBase> monitorProtocol, DataBroker dataBroker) {
this.dataBroker = dataBroker;
this.tzone = tzone;
this.enabled = enabled;
this.monitorProtocol = monitorProtocol;
+ this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
LOG.trace("ItmMonitorToggleWorker initialized with tzone {} and toggleBoolean {}",tzone,enabled);
LOG.debug("TunnelMonitorToggleWorker with monitor protocol = {} ",monitorProtocol);
}
- @Override public List<ListenableFuture<Void>> call() {
- List<ListenableFuture<Void>> futures = new ArrayList<>() ;
+ @Override
+ public List<? extends ListenableFuture<?>> call() {
LOG.debug("ItmMonitorToggleWorker invoked with tzone = {} enabled {}",tzone,enabled);
- WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
- toggleTunnelMonitoring(enabled,tzone,transaction);
- futures.add(transaction.submit());
- return futures;
+ return toggleTunnelMonitoring();
}
- private void toggleTunnelMonitoring(Boolean enabled, String tzone, WriteTransaction transaction) {
+ private List<? extends ListenableFuture<?>> toggleTunnelMonitoring() {
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()
+ InstanceIdentifier<TunnelMonitorParams> iid = InstanceIdentifier.create(TunnelMonitorParams.class);
+ TunnelMonitorParams monitorParams = 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, enabled, transaction);
- }
- }
+ List<ListenableFuture<?>> futures = new ArrayList<>();
+ futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(Datastore.OPERATIONAL,
+ tx -> tx.merge(iid, monitorParams)));
+ futures.add(txRunner.callWithNewWriteOnlyTransactionAndSubmit(Datastore.CONFIGURATION,
+ tx -> tunnelList.forEach(tunnel -> toggle(tunnel, tx))));
+ return futures;
}
- private void toggle(String tunnelInterfaceName, boolean enabled, WriteTransaction transaction) {
+ private void toggle(String tunnelInterfaceName, TypedWriteTransaction<Datastore.Configuration> tx) {
if (tunnelInterfaceName != null) {
- InstanceIdentifier<Interface> trunkIdentifier = ItmUtils.buildId(tunnelInterfaceName);
- LOG.debug("TunnelMonitorToggleWorker: tunnelInterfaceName: {}, monitorProtocol = {}, "
+ InstanceIdentifier<IfTunnel> trunkIdentifier = ItmUtils.buildTunnelId(tunnelInterfaceName);
+ LOG.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);
- transaction.merge(LogicalDatastoreType.CONFIGURATION, trunkIdentifier, builder.build());
+ IfTunnel tunnel =
+ new IfTunnelBuilder().setMonitorEnabled(enabled).setMonitorProtocol(monitorProtocol).build();
+ tx.merge(trunkIdentifier, tunnel);
}
}
}
-
-
-
-