HONEYCOMB-236 - Unified read/write exceptions
[honeycomb.git] / v3po / v3po2vpp / src / main / java / io / fd / honeycomb / translate / v3po / interfacesstate / ip / Ipv4AddressCustomizer.java
index e2df8e2..f07ef3d 100644 (file)
@@ -23,12 +23,13 @@ import io.fd.honeycomb.translate.read.ReadContext;
 import io.fd.honeycomb.translate.read.ReadFailedException;
 import io.fd.honeycomb.translate.spi.read.ListReaderCustomizer;
 import io.fd.honeycomb.translate.util.read.cache.DumpCacheManager;
-import io.fd.honeycomb.translate.util.read.cache.exceptions.execution.DumpExecutionFailedException;
 import io.fd.honeycomb.translate.v3po.interfacesstate.ip.dump.AddressDumpExecutor;
-import io.fd.honeycomb.translate.v3po.interfacesstate.ip.dump.check.AddressDumpCheck;
 import io.fd.honeycomb.translate.v3po.interfacesstate.ip.dump.params.AddressDumpParams;
-import io.fd.honeycomb.translate.v3po.util.FutureJVppCustomizer;
-import io.fd.honeycomb.translate.v3po.util.NamingContext;
+import io.fd.honeycomb.translate.vpp.util.FutureJVppCustomizer;
+import io.fd.honeycomb.translate.vpp.util.NamingContext;
+import io.fd.vpp.jvpp.core.dto.IpAddressDetails;
+import io.fd.vpp.jvpp.core.dto.IpAddressDetailsReplyDump;
+import io.fd.vpp.jvpp.core.future.FutureJVppCore;
 import java.util.List;
 import javax.annotation.Nonnull;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
@@ -40,9 +41,6 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.ip.rev14061
 import org.opendaylight.yangtools.concepts.Builder;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.openvpp.jvpp.core.dto.IpAddressDetails;
-import org.openvpp.jvpp.core.dto.IpAddressDetailsReplyDump;
-import org.openvpp.jvpp.core.future.FutureJVppCore;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -64,7 +62,6 @@ public class Ipv4AddressCustomizer extends FutureJVppCustomizer
         this.interfaceContext = checkNotNull(interfaceContext, "interfaceContext should not be null");
         this.dumpManager = new DumpCacheManager.DumpCacheManagerBuilder<IpAddressDetailsReplyDump, AddressDumpParams>()
                 .withExecutor(new AddressDumpExecutor(futureJVppCore))
-                .withNonEmptyPredicate(new AddressDumpCheck())
                 .build();
     }
 
@@ -82,33 +79,26 @@ public class Ipv4AddressCustomizer extends FutureJVppCustomizer
 
         final String interfaceName = id.firstKeyOf(Interface.class).getName();
         final int interfaceIndex = interfaceContext.getIndex(interfaceName, ctx.getMappingContext());
-        final Optional<IpAddressDetailsReplyDump> dumpOptional;
-        try {
-            dumpOptional =
-                    dumpManager.getDump(CACHE_KEY, ctx.getModificationCache(),
-                            new AddressDumpParams(interfaceIndex, false));
-        } catch (DumpExecutionFailedException e) {
-            throw new ReadFailedException(id, e);
-        }
-
-        if (dumpOptional.isPresent()) {
-            final Optional<IpAddressDetails> ipAddressDetails =
-                    findIpAddressDetailsByIp(dumpOptional, id.firstKeyOf(Address.class).getIp());
+        final Optional<IpAddressDetailsReplyDump> dumpOptional = dumpManager
+                .getDump(id, CACHE_KEY, ctx.getModificationCache(), new AddressDumpParams(interfaceIndex, false));
 
-            if (ipAddressDetails.isPresent()) {
-                final IpAddressDetails detail = ipAddressDetails.get();
-                builder.setIp(arrayToIpv4AddressNoZone(detail.ip))
-                        .setSubnet(
-                                new PrefixLengthBuilder().setPrefixLength(Short.valueOf(detail.prefixLength)).build());
-
-                if (LOG.isDebugEnabled()) {
-                    LOG.debug("Attributes for {} interface (id={}) address {} successfully read: {}",
-                            interfaceName, interfaceIndex, id, builder.build());
-                }
+        if (!dumpOptional.isPresent() || dumpOptional.get().ipAddressDetails.isEmpty()) {
+            return;
+        }
+        final Optional<IpAddressDetails> ipAddressDetails =
+                findIpAddressDetailsByIp(dumpOptional, id.firstKeyOf(Address.class).getIp());
+
+        if (ipAddressDetails.isPresent()) {
+            final IpAddressDetails detail = ipAddressDetails.get();
+            builder.setIp(arrayToIpv4AddressNoZone(detail.ip))
+                    .setSubnet(
+                            new PrefixLengthBuilder().setPrefixLength(Short.valueOf(detail.prefixLength)).build());
+
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Attributes for {} interface (id={}) address {} successfully read: {}",
+                        interfaceName, interfaceIndex, id, builder.build());
             }
         }
-
-
     }
 
     @Override
@@ -118,14 +108,8 @@ public class Ipv4AddressCustomizer extends FutureJVppCustomizer
 
         final String interfaceName = id.firstKeyOf(Interface.class).getName();
         final int interfaceIndex = interfaceContext.getIndex(interfaceName, ctx.getMappingContext());
-        final Optional<IpAddressDetailsReplyDump> dumpOptional;
-        try {
-            dumpOptional =
-                    dumpManager.getDump(CACHE_KEY, ctx.getModificationCache(),
-                            new AddressDumpParams(interfaceIndex, false));
-        } catch (DumpExecutionFailedException e) {
-            throw new ReadFailedException(id, e);
-        }
+        final Optional<IpAddressDetailsReplyDump> dumpOptional = dumpManager
+                .getDump(id, CACHE_KEY, ctx.getModificationCache(), new AddressDumpParams(interfaceIndex, false));
 
         return getAllIpv4AddressIds(dumpOptional, AddressKey::new);
     }