NETVIRT-1630 migrate to md-sal APIs
[netvirt.git] / vpnmanager / api / src / main / java / org / opendaylight / netvirt / vpnmanager / api / intervpnlink / InterVpnLinkDataComposite.java
index d5ec93616e453c7da88e1bd0b51101c2bb35da09..3ec633f6b6d2b9976a5c43afee804962d6fd1632 100755 (executable)
@@ -8,14 +8,17 @@
 
 package org.opendaylight.netvirt.vpnmanager.api.intervpnlink;
 
-import com.google.common.base.Optional;
+import static java.util.Collections.emptyList;
+
 import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 import java.util.Objects;
+import java.util.Optional;
+import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.link.states.InterVpnLinkState;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netvirt.inter.vpn.link.rev160311.inter.vpn.links.InterVpnLink;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint64;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -66,8 +69,8 @@ public class InterVpnLinkDataComposite {
     }
 
     public Optional<InterVpnLinkState.State> getState() {
-        return this.interVpnLinkState == null ? Optional.absent()
-                                              : Optional.fromNullable(this.interVpnLinkState.getState());
+        return this.interVpnLinkState == null ? Optional.empty()
+                                              : Optional.ofNullable(this.interVpnLinkState.getState());
     }
 
     public boolean isActive() {
@@ -75,7 +78,8 @@ public class InterVpnLinkDataComposite {
     }
 
     public boolean stepsOnDpn(BigInteger dpnId) {
-        return getFirstEndpointDpns().contains(dpnId) || getSecondEndpointDpns().contains(dpnId);
+        return getFirstEndpointDpns().contains(Uint64.valueOf(dpnId))
+                    || getSecondEndpointDpns().contains(Uint64.valueOf(dpnId));
     }
 
     public boolean isBgpRoutesLeaking() {
@@ -115,206 +119,212 @@ public class InterVpnLinkDataComposite {
     }
 
     public boolean isIpAddrTheOtherVpnEndpoint(String ipAddr, String vpnUuid) {
-        return (vpnUuid.equals(getFirstEndpointVpnUuid().orNull())
-                    && ipAddr.equals(getSecondEndpointIpAddr().orNull()))
-               || (vpnUuid.equals(getSecondEndpointVpnUuid().orNull())
-                     && ipAddr.equals(getFirstEndpointIpAddr().orNull()));
+        return (vpnUuid.equals(getFirstEndpointVpnUuid().orElse(null))
+                    && ipAddr.equals(getSecondEndpointIpAddr().orElse(null)))
+               || (vpnUuid.equals(getSecondEndpointVpnUuid().orElse(null))
+                     && ipAddr.equals(getFirstEndpointIpAddr().orElse(null)));
     }
 
+    @Nullable
     public String getInterVpnLinkName() {
         return (interVpnLinkCfg != null) ? interVpnLinkCfg.getName() : interVpnLinkState.getInterVpnLinkName();
     }
 
     public Optional<String> getFirstEndpointVpnUuid() {
         if (this.interVpnLinkCfg == null) {
-            return Optional.absent();
+            return Optional.empty();
         }
         return Optional.of(this.interVpnLinkCfg.getFirstEndpoint().getVpnUuid().getValue());
     }
 
     public Optional<String> getFirstEndpointIpAddr() {
         if (this.interVpnLinkCfg == null) {
-            return Optional.absent();
+            return Optional.empty();
         }
         return Optional.of(this.interVpnLinkCfg.getFirstEndpoint().getIpAddress().getValue());
     }
 
-    public Optional<Long> getFirstEndpointLportTag() {
+    public Optional<Uint32> getFirstEndpointLportTag() {
         return (!isComplete() || this.interVpnLinkState.getFirstEndpointState().getLportTag() == null)
-                   ? Optional.absent()
+                   ? Optional.empty()
                    : Optional.of(this.interVpnLinkState.getFirstEndpointState().getLportTag());
     }
 
-    public List<BigInteger> getFirstEndpointDpns() {
+    public List<Uint64> getFirstEndpointDpns() {
         return (!isComplete() || this.interVpnLinkState.getFirstEndpointState().getDpId() == null)
-                   ? Collections.emptyList()
+                   ? emptyList()
                    : this.interVpnLinkState.getFirstEndpointState().getDpId();
     }
 
     public Optional<String> getSecondEndpointVpnUuid() {
         if (!isComplete()) {
-            return Optional.absent();
+            return Optional.empty();
         }
         return Optional.of(this.interVpnLinkCfg.getSecondEndpoint().getVpnUuid().getValue());
     }
 
     public Optional<String> getSecondEndpointIpAddr() {
         if (!isComplete()) {
-            return Optional.absent();
+            return Optional.empty();
         }
         return Optional.of(this.interVpnLinkCfg.getSecondEndpoint().getIpAddress().getValue());
     }
 
-    public Optional<Long> getSecondEndpointLportTag() {
+    public Optional<Uint32> getSecondEndpointLportTag() {
         return (!isComplete() || this.interVpnLinkState.getSecondEndpointState().getLportTag() == null)
-            ? Optional.absent()
+            ? Optional.empty()
             : Optional.of(this.interVpnLinkState.getSecondEndpointState().getLportTag());
     }
 
-    public List<BigInteger> getSecondEndpointDpns() {
+    public List<Uint64> getSecondEndpointDpns() {
         return (!isComplete() || this.interVpnLinkState.getSecondEndpointState().getDpId() == null)
-                    ? Collections.emptyList()
+                    ? emptyList()
                     : this.interVpnLinkState.getSecondEndpointState().getDpId();
     }
 
+    @Nullable
     public String getVpnNameByIpAddress(String endpointIpAddr) {
         if (!isFirstEndpointIpAddr(endpointIpAddr) && !isSecondEndpointIpAddr(endpointIpAddr)) {
             LOG.debug("Endpoint IpAddress {} does not participate in InterVpnLink {}",
                       endpointIpAddr, getInterVpnLinkName());
             return null;
         }
-        return isFirstEndpointIpAddr(endpointIpAddr) ? getFirstEndpointVpnUuid().get()
-                                                     : getSecondEndpointVpnUuid().get();
+        return isFirstEndpointIpAddr(endpointIpAddr) ? getFirstEndpointVpnUuid().orElse(null)
+                                                     : getSecondEndpointVpnUuid().orElse(null);
     }
 
+    @Nullable
     public String getOtherEndpoint(String vpnUuid) {
         if (!isFirstEndpointVpnName(vpnUuid) && !isSecondEndpointVpnName(vpnUuid)) {
             LOG.debug("VPN {} does not participate in InterVpnLink {}", vpnUuid, getInterVpnLinkName());
             return null;
         }
 
-        Optional<String> optEndpointIpAddr = isFirstEndpointVpnName(vpnUuid) ? getSecondEndpointIpAddr()
-                                                                             : getFirstEndpointIpAddr();
-        return optEndpointIpAddr.orNull();
+        return isFirstEndpointVpnName(vpnUuid) ? getSecondEndpointIpAddr().orElse(null)
+                                               : getFirstEndpointIpAddr().orElse(null);
     }
 
+    @Nullable
     public String getOtherVpnNameByIpAddress(String endpointIpAddr) {
         if (!isFirstEndpointIpAddr(endpointIpAddr) && !isSecondEndpointIpAddr(endpointIpAddr)) {
             LOG.debug("Endpoint IpAddress {} does not participate in InterVpnLink {}",
                       endpointIpAddr, getInterVpnLinkName());
             return null;
         }
-        return isFirstEndpointIpAddr(endpointIpAddr) ? getSecondEndpointVpnUuid().get()
-                                                     : getFirstEndpointVpnUuid().get();
+        return isFirstEndpointIpAddr(endpointIpAddr) ? getSecondEndpointVpnUuid().orElse(null)
+                                                     : getFirstEndpointVpnUuid().orElse(null);
     }
 
-    public Optional<Long> getEndpointLportTagByVpnName(String vpnName) {
+    public Optional<Uint32> getEndpointLportTagByVpnName(String vpnName) {
         if (!isComplete()) {
-            return Optional.absent();
+            return Optional.empty();
         }
 
         return isFirstEndpointVpnName(vpnName) ? Optional.of(interVpnLinkState.getFirstEndpointState().getLportTag())
                                                : Optional.of(interVpnLinkState.getSecondEndpointState().getLportTag());
     }
 
-    public Optional<Long> getEndpointLportTagByIpAddr(String endpointIp) {
+    public Optional<Uint32> getEndpointLportTagByIpAddr(String endpointIp) {
         if (!isComplete()) {
-            return Optional.absent();
+            return Optional.empty();
         }
 
         return isFirstEndpointIpAddr(endpointIp)
-                    ? Optional.fromNullable(interVpnLinkState.getFirstEndpointState().getLportTag())
-                    : Optional.fromNullable(interVpnLinkState.getSecondEndpointState().getLportTag());
+                    ? Optional.ofNullable(interVpnLinkState.getFirstEndpointState().getLportTag())
+                    : Optional.ofNullable(interVpnLinkState.getSecondEndpointState().getLportTag());
     }
 
-    public Optional<Long> getOtherEndpointLportTagByVpnName(String vpnName) {
+    public Optional<Uint32> getOtherEndpointLportTagByVpnName(String vpnName) {
         if (!isComplete()) {
-            return Optional.absent();
+            return Optional.empty();
         }
 
         return isFirstEndpointVpnName(vpnName) ? Optional.of(interVpnLinkState.getSecondEndpointState().getLportTag())
                                                : Optional.of(interVpnLinkState.getFirstEndpointState().getLportTag());
     }
 
+    @Nullable
     public String getOtherVpnName(String vpnName) {
         if (!isFirstEndpointVpnName(vpnName) && !isSecondEndpointVpnName(vpnName)) {
             LOG.debug("VPN {} does not participate in InterVpnLink {}", vpnName, getInterVpnLinkName());
             return null;
         }
 
-        Optional<String> optOtherVpnName = isFirstEndpointVpnName(vpnName) ? getSecondEndpointVpnUuid()
-                                                                           : getFirstEndpointVpnUuid();
-        return optOtherVpnName.orNull();
+        return isFirstEndpointVpnName(vpnName) ? getSecondEndpointVpnUuid().orElse(null)
+                                               : getFirstEndpointVpnUuid().orElse(null);
     }
 
+    @Nullable
     public String getOtherEndpointIpAddr(String vpnUuid) {
         if (!isFirstEndpointVpnName(vpnUuid) && !isSecondEndpointVpnName(vpnUuid)) {
             LOG.debug("VPN {} does not participate in InterVpnLink {}", vpnUuid, getInterVpnLinkName());
             return null;
         }
 
-        Optional<String> optEndpointIpAddr = isFirstEndpointVpnName(vpnUuid) ? getSecondEndpointIpAddr()
-                                                                             : getFirstEndpointIpAddr();
-        return optEndpointIpAddr.orNull();
+        return isFirstEndpointVpnName(vpnUuid) ? getSecondEndpointIpAddr().orElse(null)
+                                               : getFirstEndpointIpAddr().orElse(null);
     }
 
+    @Nullable
     public String getEndpointIpAddr(String vpnUuid) {
         if (!isFirstEndpointVpnName(vpnUuid) && !isSecondEndpointVpnName(vpnUuid)) {
             LOG.debug("VPN {} does not participate in InterVpnLink {}", vpnUuid, getInterVpnLinkName());
             return null;
         }
 
-        Optional<String> optEndpointIpAddr = isFirstEndpointVpnName(vpnUuid) ? getFirstEndpointIpAddr()
-                                                                             : getSecondEndpointIpAddr();
-        return optEndpointIpAddr.orNull();
+        return isFirstEndpointVpnName(vpnUuid) ? getFirstEndpointIpAddr().orElse(null)
+                                               : getSecondEndpointIpAddr().orElse(null);
     }
 
-    public List<BigInteger> getEndpointDpnsByVpnName(String vpnUuid) {
+    public List<Uint64> getEndpointDpnsByVpnName(String vpnUuid) {
         if (!isComplete()) {
-            return new ArrayList<>();
+            return emptyList();
         }
 
-        return isFirstEndpointVpnName(vpnUuid) ? interVpnLinkState.getFirstEndpointState().getDpId()
-                                               : interVpnLinkState.getSecondEndpointState().getDpId();
+        List<Uint64> dpns = isFirstEndpointVpnName(vpnUuid) ? interVpnLinkState.getFirstEndpointState().getDpId()
+                                                                : interVpnLinkState.getSecondEndpointState().getDpId();
+        return dpns == null ? emptyList() : dpns;
     }
 
-    public List<BigInteger> getOtherEndpointDpnsByVpnName(String vpnUuid) {
-        List<BigInteger> result = new ArrayList<>();
+    public List<Uint64> getOtherEndpointDpnsByVpnName(String vpnUuid) {
         if (!isComplete()) {
-            return result;
+            return emptyList();
         }
 
-        return isFirstEndpointVpnName(vpnUuid) ? interVpnLinkState.getSecondEndpointState().getDpId()
-                                               : interVpnLinkState.getFirstEndpointState().getDpId();
+        List<Uint64> dpns = isFirstEndpointVpnName(vpnUuid) ? interVpnLinkState.getSecondEndpointState().getDpId()
+                                                                : interVpnLinkState.getFirstEndpointState().getDpId();
+        return dpns == null ? emptyList() : dpns;
     }
 
-    public List<BigInteger> getEndpointDpnsByIpAddr(String endpointIp) {
-        List<BigInteger> result = new ArrayList<>();
+    public List<Uint64> getEndpointDpnsByIpAddr(String endpointIp) {
         if (!isComplete()) {
-            return result;
+            return emptyList();
         }
 
-        return isFirstEndpointIpAddr(endpointIp) ? this.interVpnLinkState.getFirstEndpointState().getDpId()
-                                                 : this.interVpnLinkState.getSecondEndpointState().getDpId();
+        List<Uint64> dpns =
+            isFirstEndpointIpAddr(endpointIp) ? this.interVpnLinkState.getFirstEndpointState().getDpId()
+                                              : this.interVpnLinkState.getSecondEndpointState().getDpId();
+        return dpns == null ? emptyList() : dpns;
     }
 
-    public List<BigInteger> getOtherEndpointDpnsByIpAddr(String endpointIp) {
-        List<BigInteger> result = new ArrayList<>();
+    public List<Uint64> getOtherEndpointDpnsByIpAddr(String endpointIp) {
         if (!isComplete()) {
-            return result;
+            return emptyList();
         }
 
-        return isFirstEndpointIpAddr(endpointIp) ? this.interVpnLinkState.getSecondEndpointState().getDpId()
-                                                 : this.interVpnLinkState.getFirstEndpointState().getDpId();
+        List<Uint64> dpns =
+            isFirstEndpointIpAddr(endpointIp) ? this.interVpnLinkState.getSecondEndpointState().getDpId()
+                                              : this.interVpnLinkState.getFirstEndpointState().getDpId();
+        return dpns == null ? emptyList() : dpns;
     }
 
     @Override
     public String toString() {
         final String ns = "Not specified";
-        return "InterVpnLink " + getInterVpnLinkName() + " 1stEndpoint=[vpn=" + getFirstEndpointVpnUuid().or(ns)
-            + " ipAddr=" + getFirstEndpointIpAddr().or(ns) + " dpn=" + getFirstEndpointDpns() + "]  2ndEndpoint=[vpn="
-            + getSecondEndpointVpnUuid().or(ns) + " ipAddr=" + getSecondEndpointIpAddr().or(ns) + " dpn="
-            + getSecondEndpointDpns() + "]";
+        return "InterVpnLink " + getInterVpnLinkName() + " 1stEndpoint=[vpn=" + getFirstEndpointVpnUuid().orElse(ns)
+            + " ipAddr=" + getFirstEndpointIpAddr().orElse(ns) + " dpn=" + getFirstEndpointDpns() + "]  "
+            + "2ndEndpoint=[vpn=" + getSecondEndpointVpnUuid().orElse(ns) + " ipAddr="
+            + getSecondEndpointIpAddr().orElse(ns) + " dpn=" + getSecondEndpointDpns() + "]";
     }
 
     @Override
@@ -331,8 +341,8 @@ public class InterVpnLinkDataComposite {
         InterVpnLinkDataComposite other = (InterVpnLinkDataComposite) obj;
         String none = "";
         return getInterVpnLinkName().equals(other.getInterVpnLinkName())
-            && getFirstEndpointVpnUuid().or(none).equals(other.getFirstEndpointVpnUuid().or(none))
-            && getFirstEndpointIpAddr().or(none).equals(other.getFirstEndpointIpAddr().or(none));
+            && getFirstEndpointVpnUuid().orElse(none).equals(other.getFirstEndpointVpnUuid().orElse(none))
+            && getFirstEndpointIpAddr().orElse(none).equals(other.getFirstEndpointIpAddr().orElse(none));
     }
 
     @Override