From 54a3992118f4455b99fee8f3a648145bcf2b8e65 Mon Sep 17 00:00:00 2001 From: Maros Marsalek Date: Thu, 11 Aug 2016 13:05:32 +0200 Subject: HONEYCOMB-23 Add plugin sample and sample minimal distribution Change-Id: Idbcdc5a52a9bfd3b90c039f1a1e58c258cd01849 Signed-off-by: Maros Marsalek --- .../mapping/oper/CountersReaderCustomizer.java | 71 ++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 samples/interfaces/mapping/src/main/java/io/fd/honeycomb/samples/interfaces/mapping/oper/CountersReaderCustomizer.java (limited to 'samples/interfaces/mapping/src/main/java/io/fd/honeycomb/samples/interfaces/mapping/oper/CountersReaderCustomizer.java') diff --git a/samples/interfaces/mapping/src/main/java/io/fd/honeycomb/samples/interfaces/mapping/oper/CountersReaderCustomizer.java b/samples/interfaces/mapping/src/main/java/io/fd/honeycomb/samples/interfaces/mapping/oper/CountersReaderCustomizer.java new file mode 100644 index 000000000..b5ec2cbd9 --- /dev/null +++ b/samples/interfaces/mapping/src/main/java/io/fd/honeycomb/samples/interfaces/mapping/oper/CountersReaderCustomizer.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2016 Cisco and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fd.honeycomb.samples.interfaces.mapping.oper; + +import io.fd.honeycomb.samples.interfaces.mapping.LowerLayerAccess; +import io.fd.honeycomb.translate.read.ReadContext; +import io.fd.honeycomb.translate.read.ReadFailedException; +import io.fd.honeycomb.translate.spi.read.ReaderCustomizer; +import javax.annotation.Nonnull; +import org.opendaylight.yang.gen.v1.io.fd.honeycomb.samples.interfaces.rev160810._interface.state.Counters; +import org.opendaylight.yang.gen.v1.io.fd.honeycomb.samples.interfaces.rev160810._interface.state.CountersBuilder; +import org.opendaylight.yang.gen.v1.io.fd.honeycomb.samples.interfaces.rev160810.interfaces.state.Interface; +import org.opendaylight.yang.gen.v1.io.fd.honeycomb.samples.interfaces.rev160810.interfaces.state.InterfaceBuilder; +import org.opendaylight.yang.gen.v1.io.fd.honeycomb.samples.interfaces.rev160810.interfaces.state.InterfaceKey; +import org.opendaylight.yangtools.concepts.Builder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * This is a customizer responsible for reading Counters operational data + */ +public class CountersReaderCustomizer implements ReaderCustomizer { + + private static final Logger LOG = LoggerFactory.getLogger(CountersReaderCustomizer.class); + private final LowerLayerAccess access; + + public CountersReaderCustomizer(final LowerLayerAccess access) { + this.access = access; + } + + + @Nonnull + @Override + public CountersBuilder getBuilder(@Nonnull final InstanceIdentifier id) { + return new CountersBuilder(); + } + + @Override + public void readCurrentAttributes(@Nonnull final InstanceIdentifier id, + @Nonnull final CountersBuilder builder, @Nonnull final ReadContext ctx) + throws ReadFailedException { + // Get the information about which interface to get counters for + final InterfaceKey interfaceKey = id.firstKeyOf(Interface.class); + LOG.info("Reading counters for interface: {} at {}", interfaceKey.getInterfaceId(), id); + + // Set some random data + builder.setDroppedPackets(access.getDroppedPacketsForIfc(interfaceKey.getInterfaceId().getValue())); + builder.setTotalPackets(access.getTotalPacketsForInterface(interfaceKey.getInterfaceId().getValue())); + } + + @Override + public void merge(@Nonnull final Builder parentBuilder, @Nonnull final Counters readValue) { + ((InterfaceBuilder) parentBuilder).setCounters(readValue); + } +} -- cgit 1.2.3-korg