Use unit types in AlivenessMonitorUtils 71/92771/5
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 29 Sep 2020 11:41:35 +0000 (13:41 +0200)
committerChetan Arakere Gowdru <chetan.arakere@altencalsoftlabs.com>
Thu, 5 Nov 2020 07:54:53 +0000 (07:54 +0000)
Fix internal type propagation to retain Uint32, removing unneeded
type casts.

Change-Id: Id56f0ad181f2ef4d6c9df192e9c70097bcb60761
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
interfacemanager/interfacemanager-impl/src/main/java/org/opendaylight/genius/interfacemanager/commons/AlivenessMonitorUtils.java

index 3a66876c7b10d93c75071104c5a1118bffc7465d..26b6572d7ff4dd3e55addde0eb443bc4c534ea74 100644 (file)
@@ -69,8 +69,8 @@ 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;
@@ -91,16 +91,15 @@ public final class AlivenessMonitorUtils {
                                             getInterfaceForMonitoring(trunkInterfaceName, ifTunnel.getTunnelSource()))
                                     .build())
                             .setMode(MonitoringMode.OneOne)
-                            .setProfileId(allocateProfile(FAILURE_THRESHOLD,
-                                    ifTunnel.getMonitorInterval().toJava(), 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().toJava();
+                    Uint32 monitorId = rpcResult.getResult().getMonitorId();
                     LoggingFutures.addErrorLogging(
                         txRunner.callWithNewReadWriteTransactionAndSubmit(OPERATIONAL, tx -> {
                             createOrUpdateInterfaceMonitorIdMap(tx, trunkInterfaceName, monitorId);
@@ -203,7 +202,7 @@ public final class AlivenessMonitorUtils {
             IfTunnel ifTunnelOld = interfaceOld.augmentation(IfTunnel.class);
             if (!Objects.equals(ifTunnelNew.getMonitorInterval(), ifTunnelOld.getMonitorInterval())) {
                 LOG.debug("deleting older monitor profile for interface {}", interfaceName);
-                Uint32 profileId = allocateProfile(FAILURE_THRESHOLD, ifTunnelOld.getMonitorInterval().toJava(),
+                Uint32 profileId = allocateProfile(FAILURE_THRESHOLD, ifTunnelOld.getMonitorInterval(),
                         MONITORING_WINDOW, MonitorProtocolType.Lldp);
                 MonitorProfileDeleteInput profileDeleteInput = new MonitorProfileDeleteInputBuilder()
                         .setProfileId(profileId).build();
@@ -216,7 +215,7 @@ public final class AlivenessMonitorUtils {
     }
 
     private static void createOrUpdateInterfaceMonitorIdMap(TypedReadWriteTransaction<Operational> tx, String infName,
-        long monitorId) throws ExecutionException, InterruptedException {
+            Uint32 monitorId) throws ExecutionException, InterruptedException {
         InterfaceMonitorId interfaceMonitorIdInstance;
         List<Uint32> existingMonitorIds;
         InterfaceMonitorIdBuilder interfaceMonitorIdBuilder = new InterfaceMonitorIdBuilder();
@@ -229,15 +228,15 @@ public final class AlivenessMonitorUtils {
             if (existingMonitorIds == null) {
                 existingMonitorIds = new ArrayList<>();
             }
-            if (!existingMonitorIds.contains(Uint32.valueOf(monitorId))) {
-                existingMonitorIds.add(Uint32.valueOf(monitorId));
+            if (!existingMonitorIds.contains(monitorId)) {
+                existingMonitorIds.add(monitorId);
                 interfaceMonitorIdInstance = interfaceMonitorIdBuilder.withKey(new InterfaceMonitorIdKey(infName))
                         .setMonitorId(existingMonitorIds).build();
                 tx.mergeParentStructureMerge(id, interfaceMonitorIdInstance);
             }
         } else {
             existingMonitorIds = new ArrayList<>();
-            existingMonitorIds.add(Uint32.valueOf(monitorId));
+            existingMonitorIds.add(monitorId);
             interfaceMonitorIdInstance = interfaceMonitorIdBuilder.setMonitorId(existingMonitorIds)
                     .withKey(new InterfaceMonitorIdKey(infName)).setInterfaceName(infName).build();
             tx.mergeParentStructureMerge(id, interfaceMonitorIdInstance);
@@ -245,7 +244,7 @@ public final class AlivenessMonitorUtils {
     }
 
     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();
@@ -286,9 +285,8 @@ public final class AlivenessMonitorUtils {
                         rpcResult.getErrors());
                 Profile createProfile = monitorProfileCreateInput.getProfile();
                 Future<RpcResult<MonitorProfileGetOutput>> existingProfile = alivenessMonitorService.monitorProfileGet(
-                        buildMonitorGetProfile(createProfile.getMonitorInterval().toJava(),
-                                createProfile.getMonitorWindow().toJava(),
-                                createProfile.getFailureThreshold().toJava(), createProfile.getProtocolType()));
+                        buildMonitorGetProfile(createProfile.getMonitorInterval(), createProfile.getMonitorWindow(),
+                                createProfile.getFailureThreshold(), createProfile.getProtocolType()));
                 RpcResult<MonitorProfileGetOutput> rpcGetResult = existingProfile.get();
                 if (rpcGetResult.isSuccessful()) {
                     return rpcGetResult.getResult().getProfileId();
@@ -302,23 +300,20 @@ public final class AlivenessMonitorUtils {
         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 Uint32 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)