*/
package org.opendaylight.genius.interfacemanager.commons;
-import static org.opendaylight.controller.md.sal.binding.api.WriteTransaction.CREATE_MISSING_PARENTS;
-import static org.opendaylight.genius.infra.Datastore.OPERATIONAL;
+import static org.opendaylight.mdsal.binding.util.Datastore.OPERATIONAL;
-import com.google.common.base.Optional;
import com.google.common.util.concurrent.ListenableFuture;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
+import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import javax.inject.Inject;
import javax.inject.Singleton;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.genius.infra.Datastore.Operational;
-import org.opendaylight.genius.infra.ManagedNewTransactionRunner;
-import org.opendaylight.genius.infra.ManagedNewTransactionRunnerImpl;
-import org.opendaylight.genius.infra.TypedReadTransaction;
-import org.opendaylight.genius.infra.TypedReadWriteTransaction;
-import org.opendaylight.infrautils.utils.concurrent.ListenableFutures;
+import org.apache.aries.blueprint.annotation.service.Reference;
+import org.opendaylight.infrautils.utils.concurrent.LoggingFutures;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.util.Datastore.Operational;
+import org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunner;
+import org.opendaylight.mdsal.binding.util.ManagedNewTransactionRunnerImpl;
+import org.opendaylight.mdsal.binding.util.TypedReadTransaction;
+import org.opendaylight.mdsal.binding.util.TypedReadWriteTransaction;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.AlivenessMonitorService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileCreateInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelMonitoringTypeLldp;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.common.Uint32;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class AlivenessMonitorUtils {
private static final Logger LOG = LoggerFactory.getLogger(AlivenessMonitorUtils.class);
- private static final long FAILURE_THRESHOLD = 4;
- private static final long MONITORING_WINDOW = 4;
+ private static final Uint32 FAILURE_THRESHOLD = Uint32.valueOf(4).intern();
+ private static final Uint32 MONITORING_WINDOW = Uint32.valueOf(4).intern();
private final AlivenessMonitorService alivenessMonitorService;
private final ManagedNewTransactionRunner txRunner;
@Inject
- public AlivenessMonitorUtils(AlivenessMonitorService alivenessMonitor, DataBroker dataBroker) {
+ public AlivenessMonitorUtils(AlivenessMonitorService alivenessMonitor, @Reference DataBroker dataBroker) {
this.alivenessMonitorService = alivenessMonitor;
this.txRunner = new ManagedNewTransactionRunnerImpl(dataBroker);
}
getInterfaceForMonitoring(trunkInterfaceName, ifTunnel.getTunnelSource()))
.build())
.setMode(MonitoringMode.OneOne)
- .setProfileId(allocateProfile(FAILURE_THRESHOLD,
- ifTunnel.getMonitorInterval(), MONITORING_WINDOW, MonitorProtocolType.Lldp))
+ .setProfileId(allocateProfile(FAILURE_THRESHOLD, ifTunnel.getMonitorInterval(),
+ MONITORING_WINDOW, MonitorProtocolType.Lldp))
.build())
.build();
try {
Future<RpcResult<MonitorStartOutput>> result = alivenessMonitorService.monitorStart(lldpMonitorInput);
RpcResult<MonitorStartOutput> rpcResult = result.get();
if (rpcResult.isSuccessful()) {
- long monitorId = rpcResult.getResult().getMonitorId();
- ListenableFutures.addErrorLogging(
+ Uint32 monitorId = rpcResult.getResult().getMonitorId();
+ LoggingFutures.addErrorLogging(
txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL, tx -> {
createOrUpdateInterfaceMonitorIdMap(tx, trunkInterfaceName, monitorId);
createOrUpdateMonitorIdInterfaceMap(tx, trunkInterfaceName, monitorId);
return;
}
LOG.debug("stop LLDP monitoring for {}", trunkInterface);
- ListenableFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL, tx -> {
- List<Long> monitorIds = getMonitorIdForInterface(tx, trunkInterface);
+ LoggingFutures.addErrorLogging(txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL, tx -> {
+ List<Uint32> monitorIds = getMonitorIdForInterface(tx, trunkInterface);
if (monitorIds == null) {
LOG.error("Monitor Id doesn't exist for Interface {}", trunkInterface);
return;
}
- for (Long monitorId : monitorIds) {
+ for (Uint32 monitorId : monitorIds) {
String interfaceName = getInterfaceFromMonitorId(tx, monitorId);
if (interfaceName != null) {
MonitorStopInput input = new MonitorStopInputBuilder().setMonitorId(monitorId).build();
ListenableFuture<RpcResult<MonitorStopOutput>> future = alivenessMonitorService.monitorStop(input);
- ListenableFutures.addErrorLogging(future, LOG, "Stop LLDP monitoring for {}", trunkInterface);
+ LoggingFutures.addErrorLogging(future, LOG, "Stop LLDP monitoring for {}", trunkInterface);
removeMonitorIdInterfaceMap(tx, monitorId);
removeMonitorIdFromInterfaceMonitorIdMap(tx, interfaceName, monitorId);
}), LOG, "Error stopping LLDP monitoring for {}", trunkInterface);
}
- public static String getInterfaceFromMonitorId(TypedReadTransaction<Operational> tx, Long monitorId)
+ public static String getInterfaceFromMonitorId(TypedReadTransaction<Operational> tx, Uint32 monitorId)
throws ExecutionException, InterruptedException {
InstanceIdentifier<MonitorIdInterface> id = InstanceIdentifier.builder(MonitorIdInterfaceMap.class)
.child(MonitorIdInterface.class, new MonitorIdInterfaceKey(monitorId)).build();
- return tx.read(id).get().toJavaUtil().map(MonitorIdInterface::getInterfaceName).orElse(null);
+ return tx.read(id).get().map(MonitorIdInterface::getInterfaceName).orElse(null);
}
- private void removeMonitorIdInterfaceMap(TypedReadWriteTransaction<Operational> tx, long monitorId)
+ private void removeMonitorIdInterfaceMap(TypedReadWriteTransaction<Operational> tx, Uint32 monitorId)
throws ExecutionException, InterruptedException {
InstanceIdentifier<MonitorIdInterface> id = InstanceIdentifier.builder(MonitorIdInterfaceMap.class)
.child(MonitorIdInterface.class, new MonitorIdInterfaceKey(monitorId)).build();
}
private void removeMonitorIdFromInterfaceMonitorIdMap(TypedReadWriteTransaction<Operational> tx, String infName,
- long monitorId) throws ExecutionException, InterruptedException {
+ Uint32 monitorId) throws ExecutionException, InterruptedException {
InstanceIdentifier<InterfaceMonitorId> id = InstanceIdentifier.builder(InterfaceMonitorIdMap.class)
.child(InterfaceMonitorId.class, new InterfaceMonitorIdKey(infName)).build();
Optional<InterfaceMonitorId> interfaceMonitorIdMap = tx.read(id).get();
if (interfaceMonitorIdMap.isPresent()) {
InterfaceMonitorId interfaceMonitorIdInstance = interfaceMonitorIdMap.get();
- List<Long> existingMonitorIds = interfaceMonitorIdInstance.getMonitorId();
+ List<Uint32> existingMonitorIds = interfaceMonitorIdInstance.getMonitorId();
if (existingMonitorIds != null && existingMonitorIds.contains(monitorId)) {
existingMonitorIds.remove(monitorId);
InterfaceMonitorIdBuilder interfaceMonitorIdBuilder = new InterfaceMonitorIdBuilder();
interfaceMonitorIdInstance = interfaceMonitorIdBuilder.withKey(new InterfaceMonitorIdKey(infName))
.setMonitorId(existingMonitorIds).build();
- tx.merge(id, interfaceMonitorIdInstance, CREATE_MISSING_PARENTS);
+ tx.mergeParentStructureMerge(id, interfaceMonitorIdInstance);
}
}
}
IfTunnel ifTunnelOld = interfaceOld.augmentation(IfTunnel.class);
if (!Objects.equals(ifTunnelNew.getMonitorInterval(), ifTunnelOld.getMonitorInterval())) {
LOG.debug("deleting older monitor profile for interface {}", interfaceName);
- long profileId = allocateProfile(FAILURE_THRESHOLD, ifTunnelOld.getMonitorInterval(), MONITORING_WINDOW,
- MonitorProtocolType.Lldp);
+ Uint32 profileId = allocateProfile(FAILURE_THRESHOLD, ifTunnelOld.getMonitorInterval(),
+ MONITORING_WINDOW, MonitorProtocolType.Lldp);
MonitorProfileDeleteInput profileDeleteInput = new MonitorProfileDeleteInputBuilder()
.setProfileId(profileId).build();
ListenableFuture<RpcResult<MonitorProfileDeleteOutput>> future =
alivenessMonitorService.monitorProfileDelete(profileDeleteInput);
- ListenableFutures.addErrorLogging(future, LOG, "Delete monitor profile {}", interfaceName);
+ LoggingFutures.addErrorLogging(future, LOG, "Delete monitor profile {}", interfaceName);
}
}
}
private static void createOrUpdateInterfaceMonitorIdMap(TypedReadWriteTransaction<Operational> tx, String infName,
- long monitorId) throws ExecutionException, InterruptedException {
+ Uint32 monitorId) throws ExecutionException, InterruptedException {
InterfaceMonitorId interfaceMonitorIdInstance;
- List<Long> existingMonitorIds;
+ List<Uint32> existingMonitorIds;
InterfaceMonitorIdBuilder interfaceMonitorIdBuilder = new InterfaceMonitorIdBuilder();
InstanceIdentifier<InterfaceMonitorId> id = InstanceIdentifier.builder(InterfaceMonitorIdMap.class)
.child(InterfaceMonitorId.class, new InterfaceMonitorIdKey(infName)).build();
existingMonitorIds.add(monitorId);
interfaceMonitorIdInstance = interfaceMonitorIdBuilder.withKey(new InterfaceMonitorIdKey(infName))
.setMonitorId(existingMonitorIds).build();
- tx.merge(id, interfaceMonitorIdInstance, CREATE_MISSING_PARENTS);
+ tx.mergeParentStructureMerge(id, interfaceMonitorIdInstance);
}
} else {
existingMonitorIds = new ArrayList<>();
existingMonitorIds.add(monitorId);
interfaceMonitorIdInstance = interfaceMonitorIdBuilder.setMonitorId(existingMonitorIds)
.withKey(new InterfaceMonitorIdKey(infName)).setInterfaceName(infName).build();
- tx.merge(id, interfaceMonitorIdInstance, CREATE_MISSING_PARENTS);
+ tx.mergeParentStructureMerge(id, interfaceMonitorIdInstance);
}
}
private static void createOrUpdateMonitorIdInterfaceMap(TypedReadWriteTransaction<Operational> tx, String infName,
- long monitorId) throws ExecutionException, InterruptedException {
+ Uint32 monitorId) throws ExecutionException, InterruptedException {
MonitorIdInterface monitorIdInterfaceInstance;
String existinginterfaceName;
MonitorIdInterfaceBuilder monitorIdInterfaceBuilder = new MonitorIdInterfaceBuilder();
if (!Objects.equals(existinginterfaceName, infName)) {
monitorIdInterfaceInstance = monitorIdInterfaceBuilder.withKey(new MonitorIdInterfaceKey(monitorId))
.setInterfaceName(infName).build();
- tx.merge(id, monitorIdInterfaceInstance, CREATE_MISSING_PARENTS);
+ tx.mergeParentStructureMerge(id, monitorIdInterfaceInstance);
}
} else {
monitorIdInterfaceInstance = monitorIdInterfaceBuilder.setMonitorId(monitorId)
.withKey(new MonitorIdInterfaceKey(monitorId)).setInterfaceName(infName).build();
- tx.merge(id, monitorIdInterfaceInstance, CREATE_MISSING_PARENTS);
+ tx.mergeParentStructureMerge(id, monitorIdInterfaceInstance);
}
}
- private static List<Long> getMonitorIdForInterface(TypedReadTransaction<Operational> tx, String infName)
+ private static List<Uint32> getMonitorIdForInterface(TypedReadTransaction<Operational> tx, String infName)
throws ExecutionException, InterruptedException {
InstanceIdentifier<InterfaceMonitorId> id = InstanceIdentifier.builder(InterfaceMonitorIdMap.class)
.child(InterfaceMonitorId.class, new InterfaceMonitorIdKey(infName)).build();
- return tx.read(id).get().toJavaUtil().map(InterfaceMonitorId::getMonitorId).orElse(null);
+ return tx.read(id).get().map(InterfaceMonitorId::getMonitorId).orElse(null);
}
- public long createMonitorProfile(MonitorProfileCreateInput monitorProfileCreateInput) {
+ public Uint32 createMonitorProfile(MonitorProfileCreateInput monitorProfileCreateInput) {
try {
Future<RpcResult<MonitorProfileCreateOutput>> result = alivenessMonitorService
.monitorProfileCreate(monitorProfileCreateInput);
} catch (InterruptedException | ExecutionException e) {
LOG.warn("Exception when allocating profile Id", e);
}
- return 0;
+ return Uint32.valueOf(0);
}
- private static MonitorProfileGetInput buildMonitorGetProfile(long monitorInterval, long monitorWindow,
- long failureThreshold, MonitorProtocolType protocolType) {
- org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor
- .rev160411.monitor.profile.get.input.ProfileBuilder profileBuilder =
- new org.opendaylight.yang.gen.v1.urn.opendaylight
- .genius.alivenessmonitor.rev160411.monitor.profile.get.input.ProfileBuilder();
-
- profileBuilder.setFailureThreshold(failureThreshold);
- profileBuilder.setMonitorInterval(monitorInterval);
- profileBuilder.setMonitorWindow(monitorWindow);
- profileBuilder.setProtocolType(protocolType);
- MonitorProfileGetInputBuilder buildGetProfile = new MonitorProfileGetInputBuilder();
- buildGetProfile.setProfile(profileBuilder.build());
- return buildGetProfile.build();
+ private static MonitorProfileGetInput buildMonitorGetProfile(Uint32 monitorInterval, Uint32 monitorWindow,
+ Uint32 failureThreshold, MonitorProtocolType protocolType) {
+ return new MonitorProfileGetInputBuilder()
+ .setProfile(new org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor
+ .profile.get.input.ProfileBuilder()
+ .setFailureThreshold(failureThreshold)
+ .setMonitorInterval(monitorInterval)
+ .setMonitorWindow(monitorWindow)
+ .setProtocolType(protocolType)
+ .build())
+ .build();
}
- public long allocateProfile(long failureThreshold, long monitoringInterval, long monitoringWindow,
+ private Uint32 allocateProfile(Uint32 failureThreshold, Uint32 monitoringInterval, Uint32 monitoringWindow,
MonitorProtocolType protoType) {
MonitorProfileCreateInput input = new MonitorProfileCreateInputBuilder().setProfile(
new ProfileBuilder().setFailureThreshold(failureThreshold).setMonitorInterval(monitoringInterval)