From b00acbf091afd00d3fa0cd62de02997ea5f36425 Mon Sep 17 00:00:00 2001 From: Maros Marsalek Date: Mon, 21 Mar 2016 17:46:04 +0100 Subject: Add base logging to composite readers Change-Id: I6340787f39b9f88fff99190271f74e991b5a7888 Signed-off-by: Maros Marsalek --- v3po/impl/pom.xml | 6 ++++ .../trans/r/impl/AbstractCompositeVppReader.java | 35 ++++++++++++++++----- .../impl/trans/r/impl/CompositeListVppReader.java | 36 +++++++++++++--------- .../trans/r/util/DelegatingReaderRegistry.java | 10 +++++- 4 files changed, 64 insertions(+), 23 deletions(-) (limited to 'v3po/impl') diff --git a/v3po/impl/pom.xml b/v3po/impl/pom.xml index 778d81484..1498d82f8 100644 --- a/v3po/impl/pom.xml +++ b/v3po/impl/pom.xml @@ -71,5 +71,11 @@ 1.5.6 test + + org.skinny-framework + skinny-logback + 1.0.8 + test + diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/r/impl/AbstractCompositeVppReader.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/r/impl/AbstractCompositeVppReader.java index 82a365a42..456737f37 100644 --- a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/r/impl/AbstractCompositeVppReader.java +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/r/impl/AbstractCompositeVppReader.java @@ -38,11 +38,13 @@ import org.opendaylight.yangtools.yang.binding.ChildOf; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.Identifier; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @Beta abstract class AbstractCompositeVppReader> implements VppReader { - // TODO add debug + trace logs here and there + private static final Logger LOG = LoggerFactory.getLogger(AbstractCompositeVppReader.class); private final Map, ChildVppReader>> childReaders; private final Map, ChildVppReader>> augReaders; @@ -66,33 +68,40 @@ abstract class AbstractCompositeVppReader readCurrent(final InstanceIdentifier id) { + LOG.debug("{}: Reading current: {}", this, id); final B builder = getBuilder(id); // Cache empty value to determine if anything has changed later TODO cache in a field final D emptyValue = builder.build(); + LOG.trace("{}: Reading current attributes", this); readCurrentAttributes(id, builder); // TODO expect exceptions from reader for (ChildVppReader> child : childReaders.values()) { + LOG.debug("{}: Reading child from: {}", this, child); child.read(id, builder); } for (ChildVppReader> child : augReaders.values()) { + LOG.debug("{}: Reading augment from: {}", this, child); child.read(id, builder); } // Need to check whether anything was filled in to determine if data is present or not. final D built = builder.build(); - return built.equals(emptyValue) ? Collections.emptyList() : Collections.singletonList(built); + final List read = built.equals(emptyValue) + ? Collections.emptyList() + : Collections.singletonList(built); + + LOG.debug("{}: Current node read successfully. Result: {}", this, read); + return read; } @Nonnull @Override @SuppressWarnings("unchecked") public List read(@Nonnull final InstanceIdentifier id) { - // This is read for one of children, we need to read and then filter, not parent) - - // If this is target, just read + LOG.trace("{}: Reading : {}", this, id); if (id.getTargetType().equals(getManagedDataObjectType().getTargetType())) { return readCurrent((InstanceIdentifier) id); } else { @@ -101,18 +110,25 @@ abstract class AbstractCompositeVppReader readSubtree(final InstanceIdentifier id) { - // Read only specific subtree + LOG.debug("{}: Reading subtree: {}", this, id); final Class next = VppRWUtils.getNextId(id, getManagedDataObjectType()).getType(); final ChildVppReader> vppReader = childReaders.get(next); if (vppReader != null) { + LOG.debug("{}: Reading subtree: {} from: {}", this, id, vppReader); return vppReader.read(id); } else { + LOG.debug("{}: Dedicated subtree reader missing for: {}. Reading current and filtering", this, next); // If there's no dedicated reader, use read current final InstanceIdentifier currentId = VppRWUtils.cutId(id, getManagedDataObjectType()); final List current = readCurrent(currentId); // then perform post-reading filtering (return only requested sub-node) - return current.isEmpty() ? current : filterSubtree(current, id, getManagedDataObjectType().getTargetType()) ; + final List readSubtree = current.isEmpty() + ? current + : filterSubtree(current, id, getManagedDataObjectType().getTargetType()); + + LOG.debug("{}: Subtree: {} read successfully. Result: {}", this, id, readSubtree); + return readSubtree; } } @@ -203,4 +219,9 @@ abstract class AbstractCompositeVppReader, K extends Identifier, B extends Builder> extends AbstractCompositeVppReader implements ChildVppReader { + private static final Logger LOG = LoggerFactory.getLogger(CompositeListVppReader.class); + private final ListVppReaderCustomizer customizer; /** @@ -101,19 +104,22 @@ public final class CompositeListVppReader } private List readList(@Nonnull final InstanceIdentifier id) { - return Lists.transform(customizer.getAllIds(id), new Function() { - @Override - public C apply(final K key) { - final InstanceIdentifier.IdentifiableItem currentBdItem = - VppRWUtils.getCurrentIdItem(id, key); - final InstanceIdentifier keyedId = VppRWUtils.replaceLastInId(id, currentBdItem); - final List read = read(keyedId); - checkState(read.size() == 1); - final DataObject singleItem = read.get(0); - checkArgument(getManagedDataObjectType().getTargetType().isAssignableFrom(singleItem.getClass())); - return getManagedDataObjectType().getTargetType().cast(singleItem); - } - }); + LOG.trace("{}: Reading all list entries", this); + final List allIds = customizer.getAllIds(id); + LOG.debug("{}: Reading list entries for: {}", this, allIds); + + final ArrayList allEntries = new ArrayList<>(allIds.size()); + for (K key : allIds) { + final InstanceIdentifier.IdentifiableItem currentBdItem = + VppRWUtils.getCurrentIdItem(id, key); + final InstanceIdentifier keyedId = VppRWUtils.replaceLastInId(id, currentBdItem); + final List read = readCurrent(keyedId); + checkState(read.size() == 1); + final DataObject singleItem = read.get(0); + checkArgument(getManagedDataObjectType().getTargetType().isAssignableFrom(singleItem.getClass())); + allEntries.add(getManagedDataObjectType().getTargetType().cast(singleItem)); + } + return allEntries; } private boolean shouldReadAll(@Nonnull final InstanceIdentifier id) { diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/r/util/DelegatingReaderRegistry.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/r/util/DelegatingReaderRegistry.java index 9e672c92f..61435d9ed 100644 --- a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/r/util/DelegatingReaderRegistry.java +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/trans/r/util/DelegatingReaderRegistry.java @@ -27,6 +27,8 @@ import java.util.Map; import javax.annotation.Nonnull; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Simple reader registry able to perform and aggregated read (ROOT read) on top of all @@ -36,6 +38,8 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; */ public final class DelegatingReaderRegistry implements ReaderRegistry { + private static final Logger LOG = LoggerFactory.getLogger(DelegatingReaderRegistry.class); + private final Map, VppReader> rootReaders; /** @@ -50,8 +54,12 @@ public final class DelegatingReaderRegistry implements ReaderRegistry { @Override @Nonnull public List readAll() { + LOG.debug("Reading from all delegates"); + LOG.trace("Reading from all delegates: {}", rootReaders.values()); + final List objects = new ArrayList<>(rootReaders.size()); for (VppReader rootReader : rootReaders.values()) { + LOG.debug("Reading from delegate: {}", rootReader); final List read = rootReader.read(rootReader.getManagedDataObjectType()); objects.addAll(read); } @@ -66,6 +74,7 @@ public final class DelegatingReaderRegistry implements ReaderRegistry { final VppReader vppReader = rootReaders.get(first.getType()); checkNotNull(vppReader, "Unable to read %s. Missing reader. Current readers for: %s", id, rootReaders.keySet()); + LOG.debug("Reading from delegate: {}", vppReader); return vppReader.read(id); } @@ -78,5 +87,4 @@ public final class DelegatingReaderRegistry implements ReaderRegistry { public InstanceIdentifier getManagedDataObjectType() { throw new UnsupportedOperationException("Root registry has no type"); } - } -- cgit 1.2.3-korg