From f957783fce814c1d5815743be92926a3774679fb Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Fri, 12 Feb 2016 18:04:37 +0100 Subject: Fixup logging and static methods Methods which can be static are made static. Also fixes string concat in logging. Next we share a single instance of the VppState identifier. Finally fixup the LoggingFuturesCallback. Change-Id: I4f5076bfcbf782ecf4452e00726d49b46e15628c Signed-off-by: Robert Varga --- .../v3po/impl/LoggingFuturesCallBack.java | 15 +- .../io/fd/honeycomb/v3po/impl/V3poApiRequest.java | 14 +- .../v3po/impl/VppIetfInterfaceListener.java | 217 ++++++++++----------- .../honeycomb/v3po/impl/VppPollOperDataImpl.java | 7 +- 4 files changed, 115 insertions(+), 138 deletions(-) diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/LoggingFuturesCallBack.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/LoggingFuturesCallBack.java index 35795cb7b..33c395d1f 100644 --- a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/LoggingFuturesCallBack.java +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/LoggingFuturesCallBack.java @@ -21,22 +21,21 @@ import org.slf4j.Logger; public class LoggingFuturesCallBack implements FutureCallback { - private static Logger LOG; - private String message; + private final Logger log; + private final String message; - public LoggingFuturesCallBack(String message, Logger log) { + public LoggingFuturesCallBack(final String message, final Logger log) { this.message = message; - this.LOG = log; + this.log = log; } @Override - public void onFailure(Throwable err) { - LOG.warn(message,err); - + public void onFailure(final Throwable err) { + log.warn(message,err); } @Override - public void onSuccess(V arg0) { + public void onSuccess(final V arg0) { /* suppress success messages if (arg0 == null) { LOG.info("Success!"); diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/V3poApiRequest.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/V3poApiRequest.java index 21541d96e..9eb9d3a08 100644 --- a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/V3poApiRequest.java +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/V3poApiRequest.java @@ -82,16 +82,16 @@ public class V3poApiRequest extends V3poRequest { caller = vppPollOperData; } - private InstanceIdentifier getStateInterfaceIid(final String interfaceName) { + private static InstanceIdentifier getStateInterfaceIid(final String interfaceName) { return InstanceIdentifier.create(InterfacesState.class).child(Interface.class, new InterfaceKey(interfaceName)); } - private InstanceIdentifier getStateInterfaceIpId(final InstanceIdentifier iid) { + private static InstanceIdentifier getStateInterfaceIpId(final InstanceIdentifier iid) { return iid.augmentation(Interface2.class); } - private InstanceIdentifier getStateInterfaceStatsId(final InstanceIdentifier iid) { + private static InstanceIdentifier getStateInterfaceStatsId(final InstanceIdentifier iid) { return iid.child(Statistics.class); } @@ -103,7 +103,7 @@ public class V3poApiRequest extends V3poRequest { return new Counter32(num); } - private Statistics buildInterfaceStatistics(final vppInterfaceCounters ifCounters) { + private static Statistics buildInterfaceStatistics(final vppInterfaceCounters ifCounters) { if (ifCounters == null) { return null; } @@ -331,7 +331,7 @@ public class V3poApiRequest extends V3poRequest { return ifBuilder.build(); } - private void setStateInterfaceL2( + private static void setStateInterfaceL2( final VppInterfaceStateAugmentationBuilder augBuilder, final boolean isL2BridgeBased, final boolean isXconnect, final String xconnectOutgoingInterface, @@ -356,7 +356,7 @@ public class V3poApiRequest extends V3poRequest { augBuilder.setL2(l2Builder.build()); } - private void setStateInterfaceEthernet( + private static void setStateInterfaceEthernet( final VppInterfaceStateAugmentationBuilder augBuilder, final boolean isFullDuplex, final String manufacturerDesc, final Integer mtu) { @@ -368,7 +368,7 @@ public class V3poApiRequest extends V3poRequest { augBuilder.setEthernet(ethBuilder.build()); } - private void setStateInterfaceVxlan( + private static void setStateInterfaceVxlan( final VppInterfaceStateAugmentationBuilder augBuilder, final int srcAddress, final int dstAddress, final int vni, final int encapVrfId) { diff --git a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/VppIetfInterfaceListener.java b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/VppIetfInterfaceListener.java index c9ad348ee..9b84a00f4 100644 --- a/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/VppIetfInterfaceListener.java +++ b/v3po/impl/src/main/java/io/fd/honeycomb/v3po/impl/VppIetfInterfaceListener.java @@ -17,7 +17,6 @@ package io.fd.honeycomb.v3po.impl; import java.util.Collection; - import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.DataObjectModification; import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener; @@ -52,12 +51,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class VppIetfInterfaceListener implements DataTreeChangeListener, AutoCloseable { - private static final Logger LOG = - LoggerFactory.getLogger(VppIetfInterfaceListener.class); - - private ListenerRegistration registration; - private DataBroker db; - private vppApi api; + private static final Logger LOG = LoggerFactory.getLogger(VppIetfInterfaceListener.class); + + private final ListenerRegistration registration; + private final DataBroker db; + private final vppApi api; private enum DataChangeType { CREATE, UPDATE, DELETE @@ -66,27 +64,27 @@ public class VppIetfInterfaceListener implements DataTreeChangeListener iid = InstanceIdentifier .create(Interfaces.class) .child(Interface.class); LOG.info("VPPCFG-INFO: Register listener for VPP Ietf Interface data changes"); - - DataTreeIdentifier path = + + DataTreeIdentifier path = new DataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, iid); - + registration = this.db.registerDataTreeChangeListener(path, this); } - - @Override - public void onDataTreeChanged(Collection> changes) { + + @Override + public void onDataTreeChanged(final Collection> changes) { LOG.info("VPPCFG-INFO: swIf onDataTreeChanged()"); for (DataTreeModification change: changes) { InstanceIdentifier iid = change.getRootPath().getRootIdentifier(); DataObjectModification changeDiff = change.getRootNode(); - + switch (changeDiff.getModificationType()) { case SUBTREE_MODIFIED: case WRITE: @@ -101,17 +99,17 @@ public class VppIetfInterfaceListener implements DataTreeChangeListener"); LOG.info("VPPCFG-INFO: swIfIndex = {}", swIfIndex); LOG.info("VPPCFG-INFO: swIfName = {}", swIfName); @@ -120,11 +118,11 @@ public class VppIetfInterfaceListener implements DataTreeChangeListener 0) { - byte bvi = + byte bvi = bb.isBridgedVirtualInterface() ? (byte) 1 : (byte) 0; byte shg = bb.getSplitHorizonGroup().byteValue(); - + LOG.info("VPPCFG-INFO: BridgeBased"); LOG.info("VPPCFG-INFO: BridgeDomain = {}, bdId = {}", bdName, bdId); @@ -182,14 +180,13 @@ public class VppIetfInterfaceListener implements DataTreeChangeListener", type); - LOG.info("VPPCFG-INFO: Name: " + swIf.getName()); - LOG.info("VPPCFG-INFO: Desc: " + swIf.getDescription()); - java.lang.Class ifType = swIf.getType(); if (ifType != null) { - LOG.info("VPPCFG-INFO: Type: " + swIf.getType().getSimpleName()); + LOG.info("VPPCFG-INFO: Type: {}", swIf.getType().getSimpleName()); } LOG.info("VPPCFG-INFO: {} ", type); - + String swIfName = swIf.getName(); int swIfIndex = api.swIfIndexFromName(swIfName); if ((ifType != null) && ifType.isAssignableFrom(EthernetCsmacd.class)) { if (swIfIndex != -1) { - LOG.info("VPPCFG-INFO: {} : swIfIndex = {}", - swIfName, swIfIndex); - + LOG.info("VPPCFG-INFO: {} : swIfIndex = {}", swIfName, swIfIndex); + /* set vpp ethernet and l2 containers */ vppSetVppInterfaceEthernetAndL2(swIfIndex, swIfName, vppInterface); - + byte enabled = swIf.isEnabled() ? (byte) 1 : (byte) 0; apiName = "api.swInterfaceSetFlags"; - ctxId = api.swInterfaceSetFlags((int)swIfIndex, - (byte)enabled, - (byte)enabled, + ctxId = api.swInterfaceSetFlags(swIfIndex, + enabled, + enabled, (byte)0 /* deleted */); - LOG.info("VPPCFG-INFO: {}({} ([]), enabled ([]), ...) : " - + "ctxId = {}", apiName, swIfName, swIfIndex, + LOG.info("VPPCFG-INFO: {}({} ([]), enabled ([]), ...) : ctxId = {}", apiName, swIfName, swIfIndex, enabled, ctxId); cnt = 0; rv = -77; @@ -328,18 +319,14 @@ public class VppIetfInterfaceListener implements DataTreeChangeListener 0) { apiName = "api.swInterfaceSetTable"; - ctxId = api.swInterfaceSetTable((int)swIfIndex, + ctxId = api.swInterfaceSetTable(swIfIndex, (byte)0, /* isIpv6 */ vrfId); LOG.info("VPPCFG-INFO: {}({} ([]), 0 /* isIpv6 */, {} /* vrfId */)" @@ -445,13 +430,13 @@ public class VppIetfInterfaceListener implements DataTreeChangeListener 0) && (addr != null)) { apiName = "api.swInterfaceAddDelAddress"; - ctxId = - api.swInterfaceAddDelAddress((int)swIfIndex, + ctxId = + api.swInterfaceAddDelAddress(swIfIndex, (byte)1 /* isAdd */, (byte)0 /* isIpv6 */, (byte)0 /* delAll */, plen.byteValue(), addr); - LOG.info("VPPCFG-INFO: {}({}/{}) to {} ({}): {}()" - + " returned ctxId = {}", apiName, addr, + LOG.info("VPPCFG-INFO: {}({}/{}) to {} ({}): {}() returned ctxId = {}", apiName, addr, plen, swIfName, swIfIndex, ctxId); cnt = 0; rv = -77; @@ -484,13 +468,11 @@ public class VppIetfInterfaceListener implements DataTreeChangeListener changeDiff) { + private void createOrUpdateInterface(final DataObjectModification changeDiff) { if (changeDiff.getDataBefore() == null) { // create vppSetInterface(changeDiff.getDataAfter(), DataChangeType.CREATE, null); } else { // update - vppSetInterface(changeDiff.getDataAfter(), - DataChangeType.UPDATE, + vppSetInterface(changeDiff.getDataAfter(), + DataChangeType.UPDATE, changeDiff.getDataBefore()); } } - - private void deleteInterface(DataObjectModification changeDiff) { + + private static void deleteInterface(final DataObjectModification changeDiff) { Interface swIf = changeDiff.getDataBefore(); LOG.info("VPPCFG-INFO: "); - LOG.info("VPPCFG-INFO: Name: " + swIf.getName()); - LOG.info("VPPCFG-INFO: Desc: " + swIf.getDescription()); - LOG.info("VPPCFG-INFO: Type: " + swIf.getType().getSimpleName()); + LOG.info("VPPCFG-INFO: Name: {},", swIf.getName()); + LOG.info("VPPCFG-INFO: Desc: {}", swIf.getDescription()); + LOG.info("VPPCFG-INFO: Type: {}", swIf.getType().getSimpleName()); LOG.info("VPPCFG-INFO: "); if (swIf.getType().isAssignableFrom(EthernetCsmacd.class)) { @@ -546,16 +528,15 @@ public class VppIetfInterfaceListener implements DataTreeChangeListener VPP_STATE = InstanceIdentifier.create(VppState.class); private vppVersion version; private final DataBroker db; private int[] bdIds; @@ -114,7 +115,7 @@ public class VppPollOperDataImpl implements V3poService { stateBuilder.setVersion(version); // write to oper - writeVppState(getVppStateIid(), stateBuilder.build()); + writeVppState(VPP_STATE, stateBuilder.build()); return req.ifNames; } @@ -130,10 +131,6 @@ public class VppPollOperDataImpl implements V3poService { return RpcResultBuilder.success(output).buildFuture(); } - private InstanceIdentifier getVppStateIid() { - return (InstanceIdentifier.create(VppState.class)); - } - private void writeVppState(final InstanceIdentifier iid, final VppState vppState) { WriteTransaction transaction = db.newWriteOnlyTransaction(); -- cgit 1.2.3-korg