BUG:5179 Fixing the jenkins Merge
[vpnservice.git] / itm / itm-impl / src / main / java / org / opendaylight / vpnservice / itm / rpc / ItmManagerRpcService.java
index 34d306c7c386fa3f5f5bde534ef7836b6f124de3..cd9bb447ef7ff76f1e0e2a020718555171c7991d 100644 (file)
@@ -296,45 +296,47 @@ public class ItmManagerRpcService implements ItmRpcService {
     @Override
     public Future<RpcResult<GetInternalOrExternalInterfaceNameOutput>> getInternalOrExternalInterfaceName(
        GetInternalOrExternalInterfaceNameInput input) {
-       RpcResultBuilder<GetInternalOrExternalInterfaceNameOutput> resultBld = null;
+       RpcResultBuilder<GetInternalOrExternalInterfaceNameOutput> resultBld = RpcResultBuilder.failed();
        BigInteger srcDpn = input.getSourceDpid() ;
        IpAddress dstIp = input.getDestinationIp() ;
-       List<DPNTEPsInfo> meshedDpnList = ItmUtils.getTunnelMeshInfo(dataBroker) ;
-       // Look for external tunnels if not look for internal tunnel
-       for( DPNTEPsInfo teps : meshedDpnList) {
-           TunnelEndPoints firstEndPt = teps.getTunnelEndPoints().get(0) ;
-           if( dstIp.equals(firstEndPt.getIpAddress())) {
-              InstanceIdentifier<InternalTunnel> path = InstanceIdentifier.create(
-                       TunnelList.class)
-                           .child(InternalTunnel.class, new InternalTunnelKey(srcDpn, teps.getDPNID()));      
-               
-               Optional<InternalTunnel> tnl = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, dataBroker);
-               if( tnl != null && tnl.isPresent())
-               {
-                    InternalTunnel tunnel = tnl.get();
-                    GetInternalOrExternalInterfaceNameOutputBuilder output = new GetInternalOrExternalInterfaceNameOutputBuilder().setInterfaceName(tunnel.getTunnelInterfaceName() );
-                    resultBld = RpcResultBuilder.success();
-                    resultBld.withResult(output.build()) ;
-               }else {
-                   //resultBld = RpcResultBuilder.failed();
-                   InstanceIdentifier<ExternalTunnel> path1 = InstanceIdentifier.create(
-                           ExternalTunnelList.class)
-                               .child(ExternalTunnel.class, new ExternalTunnelKey(dstIp, srcDpn));      
-                   
-                   Optional<ExternalTunnel> ext = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path1, dataBroker);
-
-                   if( ext != null && ext.isPresent())
-                   {
-                        ExternalTunnel extTunnel = ext.get();
-                        GetInternalOrExternalInterfaceNameOutputBuilder output = new GetInternalOrExternalInterfaceNameOutputBuilder().setInterfaceName(extTunnel.getTunnelInterfaceName() );
-                        resultBld = RpcResultBuilder.success();
-                        resultBld.withResult(output.build()) ;
-                   }else {
-                       resultBld = RpcResultBuilder.failed();
-                   }
-               }
-           }
-       }
+      InstanceIdentifier<ExternalTunnel> path1 = InstanceIdentifier.create(
+          ExternalTunnelList.class)
+          .child(ExternalTunnel.class, new ExternalTunnelKey(dstIp, srcDpn));
+
+      Optional<ExternalTunnel> ext = ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path1, dataBroker);
+
+      if( ext != null && ext.isPresent())
+      {
+        ExternalTunnel extTunnel = ext.get();
+        GetInternalOrExternalInterfaceNameOutputBuilder output = new GetInternalOrExternalInterfaceNameOutputBuilder().setInterfaceName(extTunnel.getTunnelInterfaceName() );
+        resultBld = RpcResultBuilder.success();
+        resultBld.withResult(output.build()) ;
+      } else {
+        List<DPNTEPsInfo> meshedDpnList = ItmUtils.getTunnelMeshInfo(dataBroker);
+        // Look for external tunnels if not look for internal tunnel
+        for (DPNTEPsInfo teps : meshedDpnList) {
+          TunnelEndPoints firstEndPt = teps.getTunnelEndPoints().get(0);
+          if (dstIp.equals(firstEndPt.getIpAddress())) {
+            InstanceIdentifier<InternalTunnel> path = InstanceIdentifier.create(
+                TunnelList.class)
+                .child(InternalTunnel.class, new InternalTunnelKey(srcDpn, teps.getDPNID()));
+
+            Optional<InternalTunnel>
+                tnl =
+                ItmUtils.read(LogicalDatastoreType.CONFIGURATION, path, dataBroker);
+            if (tnl != null && tnl.isPresent()) {
+              InternalTunnel tunnel = tnl.get();
+              GetInternalOrExternalInterfaceNameOutputBuilder
+                  output =
+                  new GetInternalOrExternalInterfaceNameOutputBuilder()
+                      .setInterfaceName(tunnel.getTunnelInterfaceName());
+              resultBld = RpcResultBuilder.success();
+              resultBld.withResult(output.build());
+              break;
+            }
+          }
+        }
+      }
        return Futures.immediateFuture(resultBld.build());
     }