diff options
author | Tibor Sirovatka <tsirovat@cisco.com> | 2016-06-10 15:42:30 +0200 |
---|---|---|
committer | Tibor Sirovatka <tsirovat@cisco.com> | 2016-06-14 14:45:30 +0200 |
commit | 8dbdffd7d25174dd8032fc80141f27a94225d984 (patch) | |
tree | 840e5a86cf293e577b3dd81cf20776ce4a2b8454 /v3po/v3po2vpp/src/main/java/io | |
parent | 28e9f043e7e6f5e73a2988789f644233bae6810f (diff) |
HONEYCOMB-67: Minor corrections in tests, styles
Removed unnecessary calls from tests
Sonar corrections
Change-Id: Ib182d66fd47a4feb9686989d086482ffe188470f
Signed-off-by: Tibor Sirovatka <tsirovat@cisco.com>
Diffstat (limited to 'v3po/v3po2vpp/src/main/java/io')
7 files changed, 55 insertions, 48 deletions
diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/InterfaceCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/InterfaceCustomizer.java index 81f5c7dd2..9f96bb75e 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/InterfaceCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfaces/InterfaceCustomizer.java @@ -23,6 +23,9 @@ import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext; import io.fd.honeycomb.v3po.translate.v3po.util.TranslateUtils; import io.fd.honeycomb.v3po.translate.write.WriteContext; import io.fd.honeycomb.v3po.translate.write.WriteFailedException; +import java.util.List; +import java.util.concurrent.CompletionStage; +import javax.annotation.Nonnull; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey; @@ -35,10 +38,6 @@ import org.openvpp.jvpp.future.FutureJVpp; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.annotation.Nonnull; -import java.util.List; -import java.util.concurrent.CompletionStage; - /** * Ietf interface write customizer that only caches interface objects for child writers */ diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceCustomizer.java index 7aa0e86b0..18079e6e4 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceCustomizer.java @@ -49,13 +49,14 @@ import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; /** - * Customizer for reading ietf-interfaces:interfaces-state/interface + * Customizer for reading ietf-interfaces:interfaces-state/interface. */ public class InterfaceCustomizer extends FutureJVppCustomizer implements ListReaderCustomizer<Interface, InterfaceKey, InterfaceBuilder> { private static final Logger LOG = LoggerFactory.getLogger(InterfaceCustomizer.class); - public static final String DUMPED_IFCS_CONTEXT_KEY = InterfaceCustomizer.class.getName() + "dumpedInterfacesDuringGetAllIds"; + public static final String DUMPED_IFCS_CONTEXT_KEY = + InterfaceCustomizer.class.getName() + "dumpedInterfacesDuringGetAllIds"; private final NamingContext interfaceContext; @@ -78,14 +79,18 @@ public class InterfaceCustomizer extends FutureJVppCustomizer // Pass cached details from getAllIds to getDetails to avoid additional dumps final SwInterfaceDetails iface = InterfaceUtils.getVppInterfaceDetails(getFutureJVpp(), id, key.getName(), - interfaceContext.getIndex(key.getName(), ctx.getMappingContext()), ctx.getModificationCache()); + interfaceContext.getIndex(key.getName(), ctx.getMappingContext()), ctx.getModificationCache()); LOG.debug("Interface details for interface: {}, details: {}", key.getName(), iface); builder.setName(key.getName()); builder.setType(InterfaceUtils.getInterfaceType(new String(iface.interfaceName).intern())); builder.setIfIndex(InterfaceUtils.vppIfIndexToYang(iface.swIfIndex)); - builder.setAdminStatus(1 == iface.adminUpDown ? AdminStatus.Up : AdminStatus.Down); - builder.setOperStatus(1 == iface.linkUpDown ? OperStatus.Up : OperStatus.Down); + builder.setAdminStatus(1 == iface.adminUpDown + ? AdminStatus.Up + : AdminStatus.Down); + builder.setOperStatus(1 == iface.linkUpDown + ? OperStatus.Up + : OperStatus.Down); if (0 != iface.linkSpeed) { builder.setSpeed(InterfaceUtils.vppInterfaceSpeedToYang(iface.linkSpeed)); } @@ -97,10 +102,11 @@ public class InterfaceCustomizer extends FutureJVppCustomizer @Nonnull @SuppressWarnings("unchecked") - public static Map<Integer, SwInterfaceDetails> getCachedInterfaceDump(final @Nonnull ModificationCache ctx) { + public static Map<Integer, SwInterfaceDetails> getCachedInterfaceDump(@Nonnull final ModificationCache ctx) { return ctx.get(DUMPED_IFCS_CONTEXT_KEY) == null - ? new HashMap<>() // allow customizers to update the cache - : (Map<Integer, SwInterfaceDetails>) ctx.get(DUMPED_IFCS_CONTEXT_KEY); + ? new HashMap<>() + // allow customizers to update the cache + : (Map<Integer, SwInterfaceDetails>) ctx.get(DUMPED_IFCS_CONTEXT_KEY); } @Nonnull @@ -117,42 +123,45 @@ public class InterfaceCustomizer extends FutureJVppCustomizer final CompletableFuture<SwInterfaceDetailsReplyDump> swInterfaceDetailsReplyDumpCompletableFuture = getFutureJVpp().swInterfaceDump(request).toCompletableFuture(); - final SwInterfaceDetailsReplyDump ifaces = TranslateUtils.getReply(swInterfaceDetailsReplyDumpCompletableFuture); + final SwInterfaceDetailsReplyDump ifaces = + TranslateUtils.getReply(swInterfaceDetailsReplyDumpCompletableFuture); if (null == ifaces || null == ifaces.swInterfaceDetails) { - LOG.debug("No interfaces found in VPP"); + LOG.debug("No interfaces for :{} found in VPP", id); return Collections.emptyList(); } // Cache interfaces dump in per-tx context to later be used in readCurrentAttributes context.getModificationCache().put(DUMPED_IFCS_CONTEXT_KEY, ifaces.swInterfaceDetails.stream() - .collect(Collectors.toMap(t -> t.swIfIndex, swInterfaceDetails -> swInterfaceDetails))); + .collect(Collectors.toMap(t -> t.swIfIndex, swInterfaceDetails -> swInterfaceDetails))); interfacesKeys = ifaces.swInterfaceDetails.stream() - .filter(elt -> elt != null) - .map((elt) -> { - // Store interface name from VPP in context if not yet present - if (!interfaceContext.containsName(elt.swIfIndex, context.getMappingContext())) { - interfaceContext.addName(elt.swIfIndex, TranslateUtils.toString(elt.interfaceName), context.getMappingContext()); - } - LOG.trace("Interface with name: {}, VPP name: {} and index: {} found in VPP", - interfaceContext.getName(elt.swIfIndex, context.getMappingContext()), elt.interfaceName, elt.swIfIndex); - - return new InterfaceKey(interfaceContext.getName(elt.swIfIndex, context.getMappingContext())); - }) - .collect(Collectors.toList()); + .filter(elt -> elt != null) + .map((elt) -> { + // Store interface name from VPP in context if not yet present + if (!interfaceContext.containsName(elt.swIfIndex, context.getMappingContext())) { + interfaceContext.addName(elt.swIfIndex, TranslateUtils.toString(elt.interfaceName), + context.getMappingContext()); + } + LOG.trace("Interface with name: {}, VPP name: {} and index: {} found in VPP", + interfaceContext.getName(elt.swIfIndex, context.getMappingContext()), elt.interfaceName, + elt.swIfIndex); + + return new InterfaceKey(interfaceContext.getName(elt.swIfIndex, context.getMappingContext())); + }) + .collect(Collectors.toList()); LOG.debug("Interfaces found in VPP: {}", interfacesKeys); return interfacesKeys; } catch (VppBaseCallException e) { - LOG.warn("Unable to get all interface IDs", e); - throw new ReadFailedException( id, e); + LOG.warn("getAllIds for id :{} failed with exception ", id, e); + throw new ReadFailedException(id, e); } } @Override public void merge(@Nonnull final org.opendaylight.yangtools.concepts.Builder<? extends DataObject> builder, - @Nonnull final List<Interface> readData) { + @Nonnull final List<Interface> readData) { ((InterfacesStateBuilder) builder).setInterface(readData); } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceUtils.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceUtils.java index a2c14fe04..b9a25974b 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceUtils.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/InterfaceUtils.java @@ -210,8 +210,8 @@ public final class InterfaceUtils { throw new IllegalArgumentException("Unable to find interface " + name); } } catch (VppBaseCallException e) { - LOG.warn("getVppInterfaceDetails exception :", e); - throw new ReadFailedException(id); + LOG.warn("getVppInterfaceDetails for id :{} and name :{} failed with exception :", id, name, e); + throw new ReadFailedException(id, e); } // SwInterfaceDump's name filter does prefix match, so we need additional filtering: diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/TapCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/TapCustomizer.java index a206f2559..f4d4a7ad2 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/TapCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/TapCustomizer.java @@ -114,8 +114,8 @@ public class TapCustomizer extends FutureJVppCustomizer builder.setTapName(TranslateUtils.toString(swInterfaceTapDetails.devName)); LOG.debug("Tap interface: {}, id: {} attributes read as: {}", key.getName(), index, builder); } catch (VppBaseCallException e) { - LOG.warn("Failed to readCurrentAttributes for: {}", id); - throw new ReadFailedException(id); + LOG.warn("Failed to readCurrentAttributes for: {}", id, e); + throw new ReadFailedException(id, e); } } } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/VhostUserCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/VhostUserCustomizer.java index 8023bb1df..65f08fee2 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/VhostUserCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/interfacesstate/VhostUserCustomizer.java @@ -123,8 +123,8 @@ public class VhostUserCustomizer extends FutureJVppCustomizer LOG.debug("Vhost user interface: {}, id: {} attributes read as: {}", key.getName(), index, builder); } catch (VppBaseCallException e) { - LOG.warn("Failed to readCurrentAttributes for: {}", id); - throw new ReadFailedException(id); + LOG.warn("Failed to readCurrentAttributes for: {}", id, e); + throw new ReadFailedException(id, e); } } } diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/vpp/BridgeDomainCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/vpp/BridgeDomainCustomizer.java index a8f13c635..371e39471 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/vpp/BridgeDomainCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/vpp/BridgeDomainCustomizer.java @@ -16,6 +16,9 @@ package io.fd.honeycomb.v3po.translate.v3po.vpp; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.base.Optional; import com.google.common.base.Preconditions; import io.fd.honeycomb.v3po.translate.spi.write.ListWriterCustomizer; @@ -24,6 +27,9 @@ import io.fd.honeycomb.v3po.translate.v3po.util.NamingContext; import io.fd.honeycomb.v3po.translate.v3po.util.TranslateUtils; import io.fd.honeycomb.v3po.translate.write.WriteContext; import io.fd.honeycomb.v3po.translate.write.WriteFailedException; +import java.util.List; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.BridgeDomains; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomain; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev150105.vpp.bridge.domains.BridgeDomainKey; @@ -36,13 +42,6 @@ import org.openvpp.jvpp.future.FutureJVpp; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.util.List; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - public class BridgeDomainCustomizer extends FutureJVppCustomizer implements ListWriterCustomizer<BridgeDomain, BridgeDomainKey> { @@ -84,12 +83,14 @@ public class BridgeDomainCustomizer @Override public void writeCurrentAttributes(@Nonnull final InstanceIdentifier<BridgeDomain> id, @Nonnull final BridgeDomain dataBefore, - @Nonnull final WriteContext ctx) throws WriteFailedException.CreateFailedException { + @Nonnull final WriteContext ctx) + throws WriteFailedException.CreateFailedException { LOG.debug("writeCurrentAttributes: id={}, current={}, ctx={}", id, dataBefore, ctx); final String bdName = dataBefore.getName(); try { - // FIXME we need the bd index to be returned by VPP or we should have a counter field (maybe in context similar to artificial name) + // FIXME we need the bd index to be returned by VPP or we should have a counter field + // (maybe in context similar to artificial name) // Here we assign the next available ID from bdContext's perspective int index = 1; while(bdContext.containsName(index, ctx.getMappingContext())) { diff --git a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/VersionCustomizer.java b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/VersionCustomizer.java index 5dc6596ad..2673e8e3d 100644 --- a/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/VersionCustomizer.java +++ b/v3po/v3po2vpp/src/main/java/io/fd/honeycomb/v3po/translate/v3po/vppstate/VersionCustomizer.java @@ -30,8 +30,6 @@ import org.opendaylight.yangtools.concepts.Builder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.openvpp.jvpp.VppBaseCallException; -import org.openvpp.jvpp.VppCallbackException; -import org.openvpp.jvpp.VppInvocationException; import org.openvpp.jvpp.dto.ShowVersion; import org.openvpp.jvpp.dto.ShowVersionReply; import org.openvpp.jvpp.future.FutureJVpp; @@ -74,7 +72,7 @@ public final class VersionCustomizer builder.setBuildDate(TranslateUtils.toString(reply.buildDate)); builder.setBuildDirectory(TranslateUtils.toString(reply.buildDirectory)); } catch (VppBaseCallException e) { - throw new ReadFailedException(id); + throw new ReadFailedException(id, e); } } |