From 6a24c5ddc4aa7d2c1aacd4237844e38e9ce595f3 Mon Sep 17 00:00:00 2001 From: David Suarez Date: Sat, 2 Sep 2017 19:04:02 +0200 Subject: [PATCH] BUG8607 Fix checkstyle issues - Formatting - JavaDoc - Line lengths - Name of variables - Exception catching - Remove redundant modifiers - Add default case to switch - Move variables closer to their - Enforcement in pom.xml Change-Id: If17fcdc00e8d22818a5501027a6bb7db3f2dcba3 Signed-off-by: David Suarez --- applications/forwardingrules-manager/pom.xml | 14 +- .../frm/ForwardingRulesCommiter.java | 92 ++-- .../frm/ForwardingRulesManager.java | 74 +-- .../frm/ForwardingRulesProperty.java | 4 +- .../frm/impl/AbstractListeningCommiter.java | 44 +- .../impl/AbstractNodeConnectorCommitter.java | 9 +- .../frm/impl/DeviceMastership.java | 5 +- .../frm/impl/DeviceMastershipManager.java | 93 ++-- .../applications/frm/impl/FlowForwarder.java | 108 ++-- ...wNodeConnectorInventoryTranslatorImpl.java | 73 ++- .../frm/impl/FlowNodeReconciliationImpl.java | 467 +++++++++--------- .../frm/impl/ForwardingRulesManagerImpl.java | 45 +- .../applications/frm/impl/GroupForwarder.java | 90 ++-- .../applications/frm/impl/MeterForwarder.java | 83 ++-- .../applications/frm/impl/TableForwarder.java | 57 +-- .../frm/impl/DeviceMastershipManagerTest.java | 11 +- .../test/java/test/mock/FlowListenerTest.java | 66 ++- .../java/test/mock/GroupListenerTest.java | 23 +- .../java/test/mock/MeterListenerTest.java | 25 +- .../test/java/test/mock/NodeListenerTest.java | 9 +- .../test/mock/TableFeaturesListenerTest.java | 23 +- .../src/test/java/test/mock/util/FRMTest.java | 13 +- .../mock/util/RpcProviderRegistryMock.java | 17 +- .../test/mock/util/SalBundleServiceMock.java | 3 - .../test/mock/util/SalFlowServiceMock.java | 18 +- .../test/mock/util/SalGroupServiceMock.java | 15 +- .../test/mock/util/SalMeterServiceMock.java | 15 +- .../test/mock/util/SalTableServiceMock.java | 14 +- 28 files changed, 721 insertions(+), 789 deletions(-) diff --git a/applications/forwardingrules-manager/pom.xml b/applications/forwardingrules-manager/pom.xml index 2a45fa48e0..0589591639 100644 --- a/applications/forwardingrules-manager/pom.xml +++ b/applications/forwardingrules-manager/pom.xml @@ -1,5 +1,6 @@ - + 4.0.0 org.opendaylight.openflowplugin @@ -81,6 +82,17 @@ org.opendaylight.yangtools yang-maven-plugin + + org.opendaylight.yangtools + yang-maven-plugin + + + org.apache.maven.plugins + maven-checkstyle-plugin + + checkstyle.violationSeverity=error + + diff --git a/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/ForwardingRulesCommiter.java b/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/ForwardingRulesCommiter.java index 7f9916b186..967d3e48d8 100644 --- a/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/ForwardingRulesCommiter.java +++ b/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/ForwardingRulesCommiter.java @@ -16,71 +16,75 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.common.RpcResult; /** - * forwardingrules-manager - * org.opendaylight.openflowplugin.applications.frm + * forwardingrules-manager org.opendaylight.openflowplugin.applications.frm * - * ForwardingRulesCommiter - * It represent a contract between DataStore DataTreeModification and relevant - * SalRpcService for device. Every implementation has to be registered for - * Configurational/DS tree path. + *

+ * ForwardingRulesCommiter It represent a contract between DataStore + * DataTreeModification and relevant SalRpcService for device. Every + * implementation has to be registered for Configurational/DS tree path. */ -public interface ForwardingRulesCommiter extends AutoCloseable, - ClusteredDataTreeChangeListener { +public interface ForwardingRulesCommiter + extends AutoCloseable, ClusteredDataTreeChangeListener { /** - * Method removes DataObject which is identified by InstanceIdentifier - * from device. + * Method removes DataObject which is identified by InstanceIdentifier from + * device. * - * @param identifier - the whole path to DataObject - * @param del - DataObject for removing - * @param nodeIdent Node InstanceIdentifier + * @param identifier + * - the whole path to DataObject + * @param del + * - DataObject for removing + * @param nodeIdent + * Node InstanceIdentifier */ - void remove(InstanceIdentifier identifier, D del, - InstanceIdentifier nodeIdent); + void remove(InstanceIdentifier identifier, D del, InstanceIdentifier nodeIdent); /** - * Method updates the original DataObject to the update DataObject - * in device. Both are identified by same InstanceIdentifier + * Method updates the original DataObject to the update DataObject in device. + * Both are identified by same InstanceIdentifier * - * @param identifier - the whole path to DataObject - * @param original - original DataObject (for update) - * @param update - changed DataObject (contain updates) - * @param nodeIdent Node InstanceIdentifier + * @param identifier + * - the whole path to DataObject + * @param original + * - original DataObject (for update) + * @param update + * - changed DataObject (contain updates) + * @param nodeIdent + * Node InstanceIdentifier */ - void update(InstanceIdentifier identifier, D original, D update, - InstanceIdentifier nodeIdent); + void update(InstanceIdentifier identifier, D original, D update, InstanceIdentifier nodeIdent); /** - * Method adds the DataObject which is identified by InstanceIdentifier - * to device. + * Method adds the DataObject which is identified by InstanceIdentifier to + * device. * - * @param identifier - the whole path to new DataObject - * @param add - new DataObject - * @param nodeIdent Node InstanceIdentifier - * @return A future associated with RPC task. {@code null} is set to the - * future if this method does not invoke RPC. + * @param identifier + * - the whole path to new DataObject + * @param add + * - new DataObject + * @param nodeIdent + * Node InstanceIdentifier + * @return A future associated with RPC task. {@code null} is set to the future + * if this method does not invoke RPC. */ Future> add(InstanceIdentifier identifier, D add, InstanceIdentifier nodeIdent); - /** - * Method creates stale-marked DataObject which is identified by InstanceIdentifier - * from device. + * Method creates stale-marked DataObject which is identified by + * InstanceIdentifier from device. * - * @param identifier - the whole path to DataObject - * @param del - DataObject removed. Stale-Mark object to be created from this object - * @param nodeIdent Node InstanceIdentifier + * @param identifier + * - the whole path to DataObject + * @param del + * - DataObject removed. Stale-Mark object to be created from this + * object + * @param nodeIdent + * Node InstanceIdentifier */ - void createStaleMarkEntity(InstanceIdentifier identifier, D del, - InstanceIdentifier nodeIdent); - - + void createStaleMarkEntity(InstanceIdentifier identifier, D del, InstanceIdentifier nodeIdent); Future> removeWithResult(InstanceIdentifier identifier, D del, - InstanceIdentifier nodeIdent); - - + InstanceIdentifier nodeIdent); } - diff --git a/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/ForwardingRulesManager.java b/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/ForwardingRulesManager.java index 9f1d83f56f..27932f87e8 100644 --- a/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/ForwardingRulesManager.java +++ b/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/ForwardingRulesManager.java @@ -16,17 +16,17 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.me import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.SalGroupService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.SalBundleService; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.SalMeterService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.SalBundleService; import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.SalTableService; import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; /** - * It represent a central point for whole module. Implementation - * Flow Provider registers the link FlowChangeListener} and it holds all needed - * services for link FlowChangeListener}. + * It represent a central point for whole module. Implementation Flow Provider + * registers the link FlowChangeListener} and it holds all needed services for + * link FlowChangeListener}. * * @author Vaclav Demcak */ @@ -35,132 +35,140 @@ public interface ForwardingRulesManager extends ConfigurationListener, AutoClose void start(); /** - * Method returns information : - * "is Node with send InstanceIdentifier connected"? + * Method returns information : "is Node with send InstanceIdentifier + * connected"?. * - * @param ident - the key of the node + * @param ident + * - the key of the node * @return boolean - true if device is connected */ boolean isNodeActive(InstanceIdentifier ident); /** - * Method returns information : - * "is Node with send InstanceIdentifier present in operational data store"? + * Method returns information : "is Node with send InstanceIdentifier present in + * operational data store"?. * - * @param ident - the key of the node + * @param ident + * - the key of the node * @return boolean - true if device is present in operational data store */ boolean checkNodeInOperationalDataStore(InstanceIdentifier ident); /** - * Method returns generated transaction ID, which is unique for - * every transaction. ID is composite from prefix ("DOM") and unique number. + * Method returns generated transaction ID, which is unique for every + * transaction. ID is composite from prefix ("DOM") and unique number. * * @return String transactionID for RPC transaction identification */ String getNewTransactionId(); /** - * Method returns Read Transacion. It is need for Node reconciliation only. + * Method returns Read Transaction. It is need for Node reconciliation only. * * @return ReadOnlyTransaction */ ReadOnlyTransaction getReadTranaction(); /** - * Flow RPC service + * Flow RPC service. * - * @return */ SalFlowService getSalFlowService(); /** - * Group RPC service + * Group RPC service. * - * @return */ SalGroupService getSalGroupService(); /** - * Meter RPC service + * Meter RPC service. * - * @return */ SalMeterService getSalMeterService(); /** - * Table RPC service + * Table RPC service. * - * @return */ SalTableService getSalTableService(); /** - * Bundle RPC service + * Bundle RPC service. * * @return salBundleService */ SalBundleService getSalBundleService(); /** - * Content definition method and prevent code duplicity in Reconcil - * @return ForwardingRulesCommiter<Flow> + * Content definition method and prevent code duplicity in Reconcil. + * + * @return ForwardingRulesCommiter<Flow>. */ ForwardingRulesCommiter getFlowCommiter(); /** - * Content definition method and prevent code duplicity in Reconcil + * Content definition method and prevent code duplicity in Reconcil. + * * @return ForwardingRulesCommiter<Group> */ ForwardingRulesCommiter getGroupCommiter(); /** - * Content definition method and prevent code duplicity + * Content definition method and prevent code duplicity. + * * @return ForwardingRulesCommiter<Meter> */ ForwardingRulesCommiter getMeterCommiter(); /** - * Content definition method and prevent code duplicity + * Content definition method and prevent code duplicity. + * * @return ForwardingRulesCommiter<Table> */ ForwardingRulesCommiter getTableFeaturesCommiter(); /** * Check if reconciliation is disabled by user. + * * @return true if reconciliation is disabled, else false */ boolean isReconciliationDisabled(); /** * Check if stale marking is enabled for switch reconciliation. + * * @return true if stale marking is enabled, else false */ boolean isStaleMarkingEnabled(); /** * Return number of reconciliation retry are allowed. + * * @return number of retries. */ int getReconciliationRetryCount(); /** - * Method checks if *this* instance of openflowplugin is owner of - * the given openflow node. + * Method checks if *this* instance of openflowplugin is owner of the given + * openflow node. + * * @return True if owner, else false */ boolean isNodeOwner(InstanceIdentifier ident); /** - * Content definition method and prevent code duplicity + * Content definition method and prevent code duplicity. + * * @return FlowNodeConnectorInventoryTranslatorImpl */ FlowNodeConnectorInventoryTranslatorImpl getFlowNodeConnectorInventoryTranslatorImpl(); /** - * holds the value read from the configuration file openflowplugin.cfg file - * @return True if user enables bundle-based-reconciliation-enabled field in config file or False + * holds the value read from the configuration file openflowplugin.cfg file. + * + * @return True if user enables bundle-based-reconciliation-enabled field in + * config file or False */ boolean isBundleBasedReconciliationEnabled(); } - diff --git a/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/ForwardingRulesProperty.java b/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/ForwardingRulesProperty.java index ccfb336bb0..ef84873d1f 100644 --- a/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/ForwardingRulesProperty.java +++ b/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/ForwardingRulesProperty.java @@ -21,7 +21,7 @@ public enum ForwardingRulesProperty { private static final Map KEY_VALUE_MAP; /** - * Get property type from property key + * Get property type from property key. * * @param key the property key * @return the property type @@ -42,7 +42,7 @@ public enum ForwardingRulesProperty { } /** - * Converts enum name to property key + * Converts enum name to property key. * * @return the property key */ diff --git a/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/AbstractListeningCommiter.java b/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/AbstractListeningCommiter.java index c3df34644c..2e8864aa25 100644 --- a/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/AbstractListeningCommiter.java +++ b/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/AbstractListeningCommiter.java @@ -23,13 +23,13 @@ import org.slf4j.LoggerFactory; * AbstractChangeListner implemented basic {@link org.opendaylight.controller.md.sal.binding.api.DataTreeModification} * processing for flow node subDataObject (flows, groups and meters). */ -public abstract class AbstractListeningCommiter implements ForwardingRulesCommiter { +public abstract class AbstractListeningCommiter implements ForwardingRulesCommiter { private static final Logger LOG = LoggerFactory.getLogger(AbstractListeningCommiter.class); ForwardingRulesManager provider; private final Class clazz; - public AbstractListeningCommiter (ForwardingRulesManager provider, Class clazz) { + public AbstractListeningCommiter(ForwardingRulesManager provider, Class clazz) { this.provider = Preconditions.checkNotNull(provider, "ForwardingRulesManager can not be null!"); this.clazz = Preconditions.checkNotNull(clazz, "Class can not be null!"); } @@ -46,24 +46,23 @@ public abstract class AbstractListeningCommiter implement key.firstIdentifierOf(FlowCapableNode.class); if (preConfigurationCheck(nodeIdent)) { switch (mod.getModificationType()) { - case DELETE: - remove(key, mod.getDataBefore(), nodeIdent); - break; - case SUBTREE_MODIFIED: - update(key, mod.getDataBefore(), mod.getDataAfter(), nodeIdent); - break; - case WRITE: - if (mod.getDataBefore() == null) { - add(key, mod.getDataAfter(), nodeIdent); - } else { + case DELETE: + remove(key, mod.getDataBefore(), nodeIdent); + break; + case SUBTREE_MODIFIED: update(key, mod.getDataBefore(), mod.getDataAfter(), nodeIdent); - } - break; - default: - throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType()); + break; + case WRITE: + if (mod.getDataBefore() == null) { + add(key, mod.getDataAfter(), nodeIdent); + } else { + update(key, mod.getDataBefore(), mod.getDataAfter(), nodeIdent); + } + break; + default: + throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType()); } - } - else{ + } else { if (provider.isStaleMarkingEnabled()) { LOG.info("Stale-Marking ENABLED and switch {} is NOT connected, storing stale entities", nodeIdent.toString()); @@ -77,7 +76,8 @@ public abstract class AbstractListeningCommiter implement case WRITE: break; default: - throw new IllegalArgumentException("Unhandled modification type " + mod.getModificationType()); + throw new + IllegalArgumentException("Unhandled modification type " + mod.getModificationType()); } } } @@ -86,7 +86,7 @@ public abstract class AbstractListeningCommiter implement /** * Method return wildCardPath for Listener registration - * and for identify the correct KeyInstanceIdentifier from data; + * and for identify the correct KeyInstanceIdentifier from data. */ protected abstract InstanceIdentifier getWildCardPath(); @@ -102,7 +102,9 @@ public abstract class AbstractListeningCommiter implement // node from operational data store and if it's present it calls flowNodeConnected to explicitly // trigger the event of new node connected. - if(!provider.isNodeOwner(nodeIdent)) { return false; } + if (!provider.isNodeOwner(nodeIdent)) { + return false; + } if (!provider.isNodeActive(nodeIdent)) { if (provider.checkNodeInOperationalDataStore(nodeIdent)) { diff --git a/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/AbstractNodeConnectorCommitter.java b/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/AbstractNodeConnectorCommitter.java index 546d121642..87e9cccc09 100644 --- a/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/AbstractNodeConnectorCommitter.java +++ b/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/AbstractNodeConnectorCommitter.java @@ -18,12 +18,13 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.Fl import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -public abstract class AbstractNodeConnectorCommitter implements FlowCapableNodeConnectorCommitter { - private ForwardingRulesManager provider; +public abstract class AbstractNodeConnectorCommitter + implements FlowCapableNodeConnectorCommitter { + private final ForwardingRulesManager provider; private final Class clazz; - public AbstractNodeConnectorCommitter (ForwardingRulesManager provider, Class clazz) { + public AbstractNodeConnectorCommitter(ForwardingRulesManager provider, Class clazz) { this.provider = Preconditions.checkNotNull(provider, "ForwardingRulesManager can not be null!"); this.clazz = Preconditions.checkNotNull(clazz, "Class can not be null!"); } @@ -62,7 +63,7 @@ public abstract class AbstractNodeConnectorCommitter impl /** * Method return wildCardPath for Listener registration - * and for identify the correct KeyInstanceIdentifier from data; + * and for identify the correct KeyInstanceIdentifier from data. */ protected abstract InstanceIdentifier getWildCardPath(); diff --git a/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/DeviceMastership.java b/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/DeviceMastership.java index ebf9f3686d..10772da958 100644 --- a/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/DeviceMastership.java +++ b/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/DeviceMastership.java @@ -36,8 +36,8 @@ public class DeviceMastership implements ClusterSingletonService, AutoCloseable public DeviceMastership(final NodeId nodeId) { this.nodeId = nodeId; this.identifier = ServiceGroupIdentifier.create(nodeId.getValue()); - fcnIID = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId)).augmentation - (FlowCapableNode.class); + fcnIID = InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(nodeId)) + .augmentation(FlowCapableNode.class); } @Override @@ -69,6 +69,7 @@ public class DeviceMastership implements ClusterSingletonService, AutoCloseable public void setDeviceOperationalStatus(boolean inOperDS) { isDeviceInOperDS.set(inOperDS); } + public void reconcile() { deviceMastered.set(true); } diff --git a/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/DeviceMastershipManager.java b/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/DeviceMastershipManager.java index 7b31ef170d..2e27d69741 100644 --- a/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/DeviceMastershipManager.java +++ b/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/DeviceMastershipManager.java @@ -45,14 +45,11 @@ import org.slf4j.LoggerFactory; /** * Manager for clustering service registrations of {@link DeviceMastership}. */ -public class DeviceMastershipManager implements ClusteredDataTreeChangeListener, - OpendaylightInventoryListener, AutoCloseable{ +public class DeviceMastershipManager + implements ClusteredDataTreeChangeListener, OpendaylightInventoryListener, AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(DeviceMastershipManager.class); - private static final InstanceIdentifier II_TO_FLOW_CAPABLE_NODE - = InstanceIdentifier.builder(Nodes.class) - .child(Node.class) - .augmentation(FlowCapableNode.class) - .build(); + private static final InstanceIdentifier II_TO_FLOW_CAPABLE_NODE = InstanceIdentifier + .builder(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class).build(); private final ClusterSingletonServiceProvider clusterSingletonService; private final ListenerRegistration notifListenerRegistration; @@ -64,9 +61,8 @@ public class DeviceMastershipManager implements ClusteredDataTreeChangeListener< private Set> activeNodes = Collections.emptySet(); public DeviceMastershipManager(final ClusterSingletonServiceProvider clusterSingletonService, - final NotificationProviderService notificationService, - final FlowNodeReconciliation reconcliationAgent, - final DataBroker dataBroker) { + final NotificationProviderService notificationService, final FlowNodeReconciliation reconcliationAgent, + final DataBroker dataBroker) { this.clusterSingletonService = clusterSingletonService; this.notifListenerRegistration = notificationService.registerNotificationListener(this); this.reconcliationAgent = reconcliationAgent; @@ -91,22 +87,24 @@ public class DeviceMastershipManager implements ClusteredDataTreeChangeListener< } /** - * Temporary solution before Mastership manager from plugin. - * Remove notification after update. - * Update node notification should be send only when mastership in plugin was granted. - * @param notification received notification + * Temporary solution before Mastership manager from plugin. Remove notification + * after update. Update node notification should be send only when mastership in + * plugin was granted. + * + * @param notification + * received notification */ @Override public void onNodeUpdated(NodeUpdated notification) { LOG.debug("NodeUpdate notification received : {}", notification); - DeviceMastership membership = deviceMasterships.computeIfAbsent(notification.getId(), device -> - new DeviceMastership(notification.getId())); + DeviceMastership membership = deviceMasterships.computeIfAbsent(notification.getId(), + device -> new DeviceMastership(notification.getId())); membership.reconcile(); } @Override public void onNodeConnectorUpdated(NodeConnectorUpdated notification) { - //Not published by plugin + // Not published by plugin } @Override @@ -122,7 +120,7 @@ public class DeviceMastershipManager implements ClusteredDataTreeChangeListener< @Override public void onNodeConnectorRemoved(NodeConnectorRemoved notification) { - //Not published by plugin + // Not published by plugin } @Override @@ -132,8 +130,7 @@ public class DeviceMastershipManager implements ClusteredDataTreeChangeListener< for (DataTreeModification change : changes) { final InstanceIdentifier key = change.getRootPath().getRootIdentifier(); final DataObjectModification mod = change.getRootNode(); - final InstanceIdentifier nodeIdent = - key.firstIdentifierOf(FlowCapableNode.class); + final InstanceIdentifier nodeIdent = key.firstIdentifierOf(FlowCapableNode.class); switch (mod.getModificationType()) { case DELETE: @@ -142,7 +139,7 @@ public class DeviceMastershipManager implements ClusteredDataTreeChangeListener< } break; case SUBTREE_MODIFIED: - //NO-OP since we do not need to reconcile on Node-updated + // NO-OP since we do not need to reconcile on Node-updated break; case WRITE: if (mod.getDataBefore() == null) { @@ -156,21 +153,20 @@ public class DeviceMastershipManager implements ClusteredDataTreeChangeListener< } public void remove(InstanceIdentifier identifier, FlowCapableNode del, - InstanceIdentifier nodeIdent) { - if(compareInstanceIdentifierTail(identifier,II_TO_FLOW_CAPABLE_NODE)){ + InstanceIdentifier nodeIdent) { + if (compareInstanceIdentifierTail(identifier, II_TO_FLOW_CAPABLE_NODE)) { if (LOG.isDebugEnabled()) { - LOG.debug("Node removed: {}",nodeIdent.firstKeyOf(Node.class).getId().getValue()); + LOG.debug("Node removed: {}", nodeIdent.firstKeyOf(Node.class).getId().getValue()); } - if ( ! nodeIdent.isWildcarded()) { + if (!nodeIdent.isWildcarded()) { if (activeNodes.contains(nodeIdent)) { synchronized (lockObj) { if (activeNodes.contains(nodeIdent)) { - Set> set = - Sets.newHashSet(activeNodes); + Set> set = Sets.newHashSet(activeNodes); set.remove(nodeIdent); activeNodes = Collections.unmodifiableSet(set); - setNodeOperationalStatus(nodeIdent,false); + setNodeOperationalStatus(nodeIdent, false); } } } @@ -180,20 +176,20 @@ public class DeviceMastershipManager implements ClusteredDataTreeChangeListener< } public void add(InstanceIdentifier identifier, FlowCapableNode add, - InstanceIdentifier nodeIdent) { - if(compareInstanceIdentifierTail(identifier,II_TO_FLOW_CAPABLE_NODE)){ + InstanceIdentifier nodeIdent) { + if (compareInstanceIdentifierTail(identifier, II_TO_FLOW_CAPABLE_NODE)) { if (LOG.isDebugEnabled()) { - LOG.debug("Node added: {}",nodeIdent.firstKeyOf(Node.class).getId().getValue()); + LOG.debug("Node added: {}", nodeIdent.firstKeyOf(Node.class).getId().getValue()); } - if ( ! nodeIdent.isWildcarded()) { + if (!nodeIdent.isWildcarded()) { if (!activeNodes.contains(nodeIdent)) { synchronized (lockObj) { if (!activeNodes.contains(nodeIdent)) { Set> set = Sets.newHashSet(activeNodes); set.add(nodeIdent); activeNodes = Collections.unmodifiableSet(set); - setNodeOperationalStatus(nodeIdent,true); + setNodeOperationalStatus(nodeIdent, true); } } } @@ -204,12 +200,7 @@ public class DeviceMastershipManager implements ClusteredDataTreeChangeListener< @Override public void close() { if (listenerRegistration != null) { - try { - listenerRegistration.close(); - } catch (Exception e) { - LOG.warn("Error occurred while closing operational Node listener: {}", e.getMessage()); - LOG.debug("Error occurred while closing operational Node listener", e); - } + listenerRegistration.close(); listenerRegistration = null; } if (notifListenerRegistration != null) { @@ -217,35 +208,37 @@ public class DeviceMastershipManager implements ClusteredDataTreeChangeListener< } } - private boolean compareInstanceIdentifierTail(InstanceIdentifier identifier1, - InstanceIdentifier identifier2) { - return Iterables.getLast(identifier1.getPathArguments()).equals(Iterables.getLast(identifier2.getPathArguments())); + InstanceIdentifier identifier2) { + return Iterables.getLast(identifier1.getPathArguments()) + .equals(Iterables.getLast(identifier2.getPathArguments())); } private void setNodeOperationalStatus(InstanceIdentifier nodeIid, boolean status) { NodeId nodeId = nodeIid.firstKeyOf(Node.class).getId(); - if (nodeId != null ) { - if (deviceMasterships.containsKey(nodeId) ) { + if (nodeId != null) { + if (deviceMasterships.containsKey(nodeId)) { deviceMasterships.get(nodeId).setDeviceOperationalStatus(status); - LOG.debug("Operational status of device {} is set to {}",nodeId, status); + LOG.debug("Operational status of device {} is set to {}", nodeId, status); } } } - private void registerNodeListener(){ + + @SuppressWarnings("IllegalCatch") + private void registerNodeListener() { final InstanceIdentifier flowNodeWildCardIdentifier = InstanceIdentifier.create(Nodes.class) .child(Node.class).augmentation(FlowCapableNode.class); - final DataTreeIdentifier treeId = - new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, flowNodeWildCardIdentifier); + final DataTreeIdentifier treeId = new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, + flowNodeWildCardIdentifier); try { SimpleTaskRetryLooper looper = new SimpleTaskRetryLooper(ForwardingRulesManagerImpl.STARTUP_LOOP_TICK, ForwardingRulesManagerImpl.STARTUP_LOOP_MAX_RETRIES); - listenerRegistration = looper.loopUntilNoException(() -> - dataBroker.registerDataTreeChangeListener(treeId, DeviceMastershipManager.this)); + listenerRegistration = looper.loopUntilNoException( + () -> dataBroker.registerDataTreeChangeListener(treeId, DeviceMastershipManager.this)); } catch (Exception e) { LOG.warn("Data listener registration failed: {}", e.getMessage()); LOG.debug("Data listener registration failed ", e); diff --git a/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/FlowForwarder.java b/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/FlowForwarder.java index 28fe152d2f..23d124a1d5 100644 --- a/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/FlowForwarder.java +++ b/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/FlowForwarder.java @@ -12,7 +12,6 @@ import com.google.common.util.concurrent.CheckedFuture; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.SettableFuture; -import java.util.concurrent.Callable; import java.util.concurrent.Future; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier; @@ -49,10 +48,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * FlowForwarder - * It implements {@link org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener} - * for WildCardedPath to {@link Flow} and ForwardingRulesCommiter interface for methods: - * add, update and remove {@link Flow} processing for + * FlowForwarder It implements + * {@link org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener} + * for WildCardedPath to {@link Flow} and ForwardingRulesCommiter interface for + * methods: add, update and remove {@link Flow} processing for * {@link org.opendaylight.controller.md.sal.binding.api.DataTreeModification}. */ public class FlowForwarder extends AbstractListeningCommiter { @@ -61,23 +60,21 @@ public class FlowForwarder extends AbstractListeningCommiter { private final DataBroker dataBroker; private ListenerRegistration listenerRegistration; - public FlowForwarder (final ForwardingRulesManager manager, final DataBroker db) { + public FlowForwarder(final ForwardingRulesManager manager, final DataBroker db) { super(manager, Flow.class); dataBroker = Preconditions.checkNotNull(db, "DataBroker can not be null!"); registrationListener(db); } + @SuppressWarnings("IllegalCatch") private void registrationListener(final DataBroker db) { - final DataTreeIdentifier treeId = new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, getWildCardPath()); + final DataTreeIdentifier treeId = new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, + getWildCardPath()); try { SimpleTaskRetryLooper looper = new SimpleTaskRetryLooper(ForwardingRulesManagerImpl.STARTUP_LOOP_TICK, ForwardingRulesManagerImpl.STARTUP_LOOP_MAX_RETRIES); - listenerRegistration = looper.loopUntilNoException(new Callable>() { - @Override - public ListenerRegistration call() throws Exception { - return db.registerDataTreeChangeListener(treeId, FlowForwarder.this); - } - }); + listenerRegistration = looper + .loopUntilNoException(() -> db.registerDataTreeChangeListener(treeId, FlowForwarder.this)); } catch (final Exception e) { LOG.warn("FRM Flow DataTreeChange listener registration fail!"); LOG.debug("FRM Flow DataTreeChange listener registration fail ..", e); @@ -88,20 +85,14 @@ public class FlowForwarder extends AbstractListeningCommiter { @Override public void close() { if (listenerRegistration != null) { - try { - listenerRegistration.close(); - } catch (final Exception e) { - LOG.warn("Error by stop FRM FlowChangeListener: {}", e.getMessage()); - LOG.debug("Error by stop FRM FlowChangeListener..", e); - } + listenerRegistration.close(); listenerRegistration = null; } } @Override - public void remove(final InstanceIdentifier identifier, - final Flow removeDataObj, - final InstanceIdentifier nodeIdent) { + public void remove(final InstanceIdentifier identifier, final Flow removeDataObj, + final InstanceIdentifier nodeIdent) { final TableKey tableKey = identifier.firstKeyOf(Table.class, TableKey.class); if (tableIdValidationPrecondition(tableKey, removeDataObj)) { @@ -114,21 +105,16 @@ public class FlowForwarder extends AbstractListeningCommiter { // removed from datastore. So FRM always needs to set strict flag // into remove-flow input so that only a flow entry associated with // a given flow object is removed. - builder.setTransactionUri(new Uri(provider.getNewTransactionId())). - setStrict(Boolean.TRUE); + builder.setTransactionUri(new Uri(provider.getNewTransactionId())).setStrict(Boolean.TRUE); provider.getSalFlowService().removeFlow(builder.build()); } } - - - - //TODO: Pull this into ForwardingRulesCommiter and override it here + // TODO: Pull this into ForwardingRulesCommiter and override it here @Override public Future> removeWithResult(final InstanceIdentifier identifier, - final Flow removeDataObj, - final InstanceIdentifier nodeIdent) { + final Flow removeDataObj, final InstanceIdentifier nodeIdent) { Future> resultFuture = SettableFuture.create(); final TableKey tableKey = identifier.firstKeyOf(Table.class, TableKey.class); @@ -142,20 +128,16 @@ public class FlowForwarder extends AbstractListeningCommiter { // removed from datastore. So FRM always needs to set strict flag // into remove-flow input so that only a flow entry associated with // a given flow object is removed. - builder.setTransactionUri(new Uri(provider.getNewTransactionId())). - setStrict(Boolean.TRUE); + builder.setTransactionUri(new Uri(provider.getNewTransactionId())).setStrict(Boolean.TRUE); resultFuture = provider.getSalFlowService().removeFlow(builder.build()); } return resultFuture; } - - @Override - public void update(final InstanceIdentifier identifier, - final Flow original, final Flow update, - final InstanceIdentifier nodeIdent) { + public void update(final InstanceIdentifier identifier, final Flow original, final Flow update, + final InstanceIdentifier nodeIdent) { final TableKey tableKey = identifier.firstKeyOf(Table.class, TableKey.class); if (tableIdValidationPrecondition(tableKey, update)) { @@ -169,17 +151,16 @@ public class FlowForwarder extends AbstractListeningCommiter { // has been updated. So FRM always needs to set strict flag into // update-flow input so that only a flow entry associated with // a given flow object is updated. - builder.setUpdatedFlow((new UpdatedFlowBuilder(update)).setStrict(Boolean.TRUE).build()); - builder.setOriginalFlow((new OriginalFlowBuilder(original)).setStrict(Boolean.TRUE).build()); + builder.setUpdatedFlow(new UpdatedFlowBuilder(update).setStrict(Boolean.TRUE).build()); + builder.setOriginalFlow(new OriginalFlowBuilder(original).setStrict(Boolean.TRUE).build()); provider.getSalFlowService().updateFlow(builder.build()); } } @Override - public Future> add( - final InstanceIdentifier identifier, final Flow addDataObj, - final InstanceIdentifier nodeIdent) { + public Future> add(final InstanceIdentifier identifier, final Flow addDataObj, + final InstanceIdentifier nodeIdent) { Future> future; final TableKey tableKey = identifier.firstKeyOf(Table.class, TableKey.class); @@ -199,7 +180,8 @@ public class FlowForwarder extends AbstractListeningCommiter { } @Override - public void createStaleMarkEntity(InstanceIdentifier identifier, Flow del, InstanceIdentifier nodeIdent) { + public void createStaleMarkEntity(InstanceIdentifier identifier, Flow del, + InstanceIdentifier nodeIdent) { LOG.debug("Creating Stale-Mark entry for the switch {} for flow {} ", nodeIdent.toString(), del.toString()); StaleFlow staleFlow = makeStaleFlow(identifier, del, nodeIdent); @@ -207,33 +189,33 @@ public class FlowForwarder extends AbstractListeningCommiter { } - - @Override protected InstanceIdentifier getWildCardPath() { - return InstanceIdentifier.create(Nodes.class).child(Node.class) - .augmentation(FlowCapableNode.class).child(Table.class).child(Flow.class); + return InstanceIdentifier.create(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class) + .child(Table.class).child(Flow.class); } - private static boolean tableIdValidationPrecondition (final TableKey tableKey, final Flow flow) { + private static boolean tableIdValidationPrecondition(final TableKey tableKey, final Flow flow) { Preconditions.checkNotNull(tableKey, "TableKey can not be null or empty!"); Preconditions.checkNotNull(flow, "Flow can not be null or empty!"); - if (! tableKey.getId().equals(flow.getTableId())) { - LOG.warn("TableID in URI tableId={} and in palyload tableId={} is not same.", - flow.getTableId(), tableKey.getId()); + if (!tableKey.getId().equals(flow.getTableId())) { + LOG.warn("TableID in URI tableId={} and in palyload tableId={} is not same.", flow.getTableId(), + tableKey.getId()); return false; } return true; } - private StaleFlow makeStaleFlow(InstanceIdentifier identifier, Flow del, InstanceIdentifier nodeIdent){ - StaleFlowBuilder staleFlowBuilder = new StaleFlowBuilder(del); + private StaleFlow makeStaleFlow(InstanceIdentifier identifier, Flow del, + InstanceIdentifier nodeIdent) { + StaleFlowBuilder staleFlowBuilder = new StaleFlowBuilder(del); return staleFlowBuilder.setId(del.getId()).build(); } - private void persistStaleFlow(StaleFlow staleFlow, InstanceIdentifier nodeIdent){ + private void persistStaleFlow(StaleFlow staleFlow, InstanceIdentifier nodeIdent) { WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction(); - writeTransaction.put(LogicalDatastoreType.CONFIGURATION, getStaleFlowInstanceIdentifier(staleFlow, nodeIdent), staleFlow, false); + writeTransaction.put(LogicalDatastoreType.CONFIGURATION, getStaleFlowInstanceIdentifier(staleFlow, nodeIdent), + staleFlow, false); CheckedFuture submitFuture = writeTransaction.submit(); handleStaleFlowResultFuture(submitFuture); @@ -247,18 +229,18 @@ public class FlowForwarder extends AbstractListeningCommiter { } @Override - public void onFailure(Throwable t) { - LOG.error("Stale Flow creation failed {}", t); + public void onFailure(Throwable throwable) { + LOG.error("Stale Flow creation failed {}", throwable); } }); } - private InstanceIdentifier getStaleFlowInstanceIdentifier(StaleFlow staleFlow, InstanceIdentifier nodeIdent) { - return nodeIdent - .child(Table.class, new TableKey(staleFlow.getTableId())) - .child(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.StaleFlow.class, - new StaleFlowKey(new FlowId(staleFlow.getId()))); + private InstanceIdentifier getStaleFlowInstanceIdentifier( + StaleFlow staleFlow, InstanceIdentifier nodeIdent) { + return nodeIdent.child(Table.class, new TableKey(staleFlow.getTableId())).child( + org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.StaleFlow.class, + new StaleFlowKey(new FlowId(staleFlow.getId()))); } } - diff --git a/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/FlowNodeConnectorInventoryTranslatorImpl.java b/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/FlowNodeConnectorInventoryTranslatorImpl.java index d6cbb5c922..95d7a4ebf1 100644 --- a/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/FlowNodeConnectorInventoryTranslatorImpl.java +++ b/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/FlowNodeConnectorInventoryTranslatorImpl.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. + * Copyright (c) 2015, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -14,7 +14,6 @@ import com.google.common.collect.Iterables; import com.google.common.collect.Multimap; import com.google.common.collect.Multimaps; import java.math.BigInteger; -import java.util.concurrent.Callable; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; @@ -31,7 +30,8 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class FlowNodeConnectorInventoryTranslatorImpl extends AbstractNodeConnectorCommitter implements FlowNodeConnectorInventoryTranslator { +public class FlowNodeConnectorInventoryTranslatorImpl extends AbstractNodeConnectorCommitter + implements FlowNodeConnectorInventoryTranslator { private static final Logger LOG = LoggerFactory.getLogger(FlowNodeConnectorInventoryTranslatorImpl.class); @@ -46,9 +46,11 @@ public class FlowNodeConnectorInventoryTranslatorImpl extends AbstractNodeConnec .augmentation(FlowCapableNodeConnector.class) .build(); - private Multimap dpnToPortMultiMap = Multimaps.synchronizedListMultimap(ArrayListMultimap.create()); + private final Multimap dpnToPortMultiMap = Multimaps + .synchronizedListMultimap(ArrayListMultimap.create()); - public FlowNodeConnectorInventoryTranslatorImpl(final ForwardingRulesManager manager, final DataBroker dataBroker){ + @SuppressWarnings("IllegalCatch") + public FlowNodeConnectorInventoryTranslatorImpl(final ForwardingRulesManager manager, final DataBroker dataBroker) { super(manager, FlowCapableNodeConnector.class); Preconditions.checkNotNull(dataBroker, "DataBroker can not be null!"); @@ -57,21 +59,18 @@ public class FlowNodeConnectorInventoryTranslatorImpl extends AbstractNodeConnec try { SimpleTaskRetryLooper looper = new SimpleTaskRetryLooper(ForwardingRulesManagerImpl.STARTUP_LOOP_TICK, ForwardingRulesManagerImpl.STARTUP_LOOP_MAX_RETRIES); - dataTreeChangeListenerRegistration = looper.loopUntilNoException(new Callable>() { - @Override - public ListenerRegistration call() throws Exception { - return dataBroker.registerDataTreeChangeListener(treeId, FlowNodeConnectorInventoryTranslatorImpl.this); - } - }); + dataTreeChangeListenerRegistration = looper.loopUntilNoException(() -> dataBroker + .registerDataTreeChangeListener(treeId, FlowNodeConnectorInventoryTranslatorImpl.this)); } catch (final Exception e) { LOG.warn(" FlowNodeConnectorInventoryTranslatorImpl listener registration fail!"); LOG.debug("FlowNodeConnectorInventoryTranslatorImpl DataTreeChangeListener registration fail ..", e); - throw new IllegalStateException("FlowNodeConnectorInventoryTranslatorImpl startup fail! System needs restart.", e); + throw new + IllegalStateException("FlowNodeConnectorInventoryTranslatorImpl startup fail! System needs restart.", e); } } @Override - protected InstanceIdentifier getWildCardPath(){ + protected InstanceIdentifier getWildCardPath() { return InstanceIdentifier.create(Nodes.class) .child(Node.class) .child(NodeConnector.class) @@ -81,46 +80,45 @@ public class FlowNodeConnectorInventoryTranslatorImpl extends AbstractNodeConnec @Override public void close() { if (dataTreeChangeListenerRegistration != null) { - try { - dataTreeChangeListenerRegistration.close(); - } catch (final Exception e) { - LOG.warn("Error by stop FRM FlowNodeConnectorInventoryTranslatorImpl: {}", e.getMessage()); - LOG.debug("Error by stop FRM FlowNodeConnectorInventoryTranslatorImpl..", e); - } + dataTreeChangeListenerRegistration.close(); dataTreeChangeListenerRegistration = null; } } + @Override - public void remove(InstanceIdentifier identifier, FlowCapableNodeConnector del, InstanceIdentifier nodeConnIdent) { - if(compareInstanceIdentifierTail(identifier,II_TO_FLOW_CAPABLE_NODE_CONNECTOR)){ + public void remove(InstanceIdentifier identifier, FlowCapableNodeConnector del, + InstanceIdentifier nodeConnIdent) { + if (compareInstanceIdentifierTail(identifier, II_TO_FLOW_CAPABLE_NODE_CONNECTOR)) { LOG.debug("Node Connector removed"); - String sNodeConnectorIdentifier = nodeConnIdent - .firstKeyOf(NodeConnector.class, NodeConnectorKey.class).getId().getValue(); - BigInteger nDpId = getDpIdFromPortName(sNodeConnectorIdentifier); + String nodeConnectorIdentifier = nodeConnIdent.firstKeyOf(NodeConnector.class, NodeConnectorKey.class) + .getId().getValue(); + BigInteger dpId = getDpIdFromPortName(nodeConnectorIdentifier); - dpnToPortMultiMap.remove(nDpId, sNodeConnectorIdentifier); + dpnToPortMultiMap.remove(dpId, nodeConnectorIdentifier); } } @Override - public void update(InstanceIdentifier identifier, FlowCapableNodeConnector original, FlowCapableNodeConnector update, InstanceIdentifier nodeConnIdent) { - if(compareInstanceIdentifierTail(identifier,II_TO_FLOW_CAPABLE_NODE_CONNECTOR)){ + public void update(InstanceIdentifier identifier, FlowCapableNodeConnector original, + FlowCapableNodeConnector update, InstanceIdentifier nodeConnIdent) { + if (compareInstanceIdentifierTail(identifier, II_TO_FLOW_CAPABLE_NODE_CONNECTOR)) { LOG.debug("Node Connector updated"); - //Don't need to do anything as we are not considering updates here + // Don't need to do anything as we are not considering updates here } } @Override - public void add(InstanceIdentifier identifier, FlowCapableNodeConnector add, InstanceIdentifier nodeConnIdent) { - if(compareInstanceIdentifierTail(identifier,II_TO_FLOW_CAPABLE_NODE_CONNECTOR)){ + public void add(InstanceIdentifier identifier, FlowCapableNodeConnector add, + InstanceIdentifier nodeConnIdent) { + if (compareInstanceIdentifierTail(identifier, II_TO_FLOW_CAPABLE_NODE_CONNECTOR)) { LOG.debug("Node Connector added"); - String sNodeConnectorIdentifier = nodeConnIdent + String nodeConnectorIdentifier = nodeConnIdent .firstKeyOf(NodeConnector.class, NodeConnectorKey.class).getId().getValue(); - BigInteger nDpId = getDpIdFromPortName(sNodeConnectorIdentifier); + BigInteger dpId = getDpIdFromPortName(nodeConnectorIdentifier); - if(!dpnToPortMultiMap.containsEntry(nDpId,sNodeConnectorIdentifier)) { - dpnToPortMultiMap.put(nDpId, sNodeConnectorIdentifier); - }else{ + if (!dpnToPortMultiMap.containsEntry(dpId, nodeConnectorIdentifier)) { + dpnToPortMultiMap.put(dpId, nodeConnectorIdentifier); + } else { LOG.error("Duplicate Event.Node Connector already added"); } } @@ -128,11 +126,12 @@ public class FlowNodeConnectorInventoryTranslatorImpl extends AbstractNodeConnec private boolean compareInstanceIdentifierTail(InstanceIdentifier identifier1, InstanceIdentifier identifier2) { - return Iterables.getLast(identifier1.getPathArguments()).equals(Iterables.getLast(identifier2.getPathArguments())); + return Iterables.getLast(identifier1.getPathArguments()) + .equals(Iterables.getLast(identifier2.getPathArguments())); } @Override - public boolean isNodeConnectorUpdated(BigInteger dpId, String portName){ + public boolean isNodeConnectorUpdated(BigInteger dpId, String portName) { return dpnToPortMultiMap.containsEntry(dpId,portName) ; } diff --git a/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/FlowNodeReconciliationImpl.java b/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/FlowNodeReconciliationImpl.java index 0e4780d8d3..f3110ed80b 100644 --- a/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/FlowNodeReconciliationImpl.java +++ b/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/FlowNodeReconciliationImpl.java @@ -102,27 +102,28 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Default implementation of {@link ForwardingRulesManager} + * Default implementation of {@link ForwardingRulesManager}. * * @author Vaclav Demcak */ public class FlowNodeReconciliationImpl implements FlowNodeReconciliation { - private static final Logger LOG = LoggerFactory.getLogger(FlowNodeReconciliationImpl.class); - //The number of nanoseconds to wait for a single group to be added. - private static final long ADD_GROUP_TIMEOUT = TimeUnit.SECONDS.toNanos(3); + private static final Logger LOG = LoggerFactory.getLogger(FlowNodeReconciliationImpl.class); - //The maximum number of nanoseconds to wait for completion of add-group RPCs. - private static final long MAX_ADD_GROUP_TIMEOUT = TimeUnit.SECONDS.toNanos(20); + // The number of nanoseconds to wait for a single group to be added. + private static final long ADD_GROUP_TIMEOUT = TimeUnit.SECONDS.toNanos(3); + + // The maximum number of nanoseconds to wait for completion of add-group RPCs. + private static final long MAX_ADD_GROUP_TIMEOUT = TimeUnit.SECONDS.toNanos(20); private static final String SEPARATOR = ":"; private static final int THREAD_POOL_SIZE = 4; private final DataBroker dataBroker; private final ForwardingRulesManager provider; private final String serviceName; - final private int priority; - final private ResultState resultState; - private Map> futureMap = new HashMap<>(); + private final int priority; + private final ResultState resultState; + private final Map> futureMap = new HashMap<>(); private final ExecutorService executor = Executors.newFixedThreadPool(THREAD_POOL_SIZE); @@ -131,14 +132,15 @@ public class FlowNodeReconciliationImpl implements FlowNodeReconciliation { private static final AtomicLong BUNDLE_ID = new AtomicLong(); private static final BundleFlags BUNDLE_FLAGS = new BundleFlags(true, true); - public FlowNodeReconciliationImpl (final ForwardingRulesManager manager, final DataBroker db, + public FlowNodeReconciliationImpl(final ForwardingRulesManager manager, final DataBroker db, final String serviceName, final int priority, final ResultState resultState) { this.provider = Preconditions.checkNotNull(manager, "ForwardingRulesManager can not be null!"); dataBroker = Preconditions.checkNotNull(db, "DataBroker can not be null!"); this.serviceName = serviceName; this.priority = priority; this.resultState = resultState; - salBundleService = Preconditions.checkNotNull(manager.getSalBundleService(),"salBundleService can not be null!"); + salBundleService = Preconditions.checkNotNull(manager.getSalBundleService(), + "salBundleService can not be null!"); } @Override @@ -151,12 +153,12 @@ public class FlowNodeReconciliationImpl implements FlowNodeReconciliation { private ListenableFuture reconcileConfiguration(InstanceIdentifier connectedNode) { LOG.info("Triggering reconciliation for device {}", connectedNode.firstKeyOf(Node.class)); if (provider.isStaleMarkingEnabled()) { - LOG.info("Stale-Marking is ENABLED and proceeding with deletion of " - + "stale-marked entities on switch {}", + LOG.info("Stale-Marking is ENABLED and proceeding with deletion of " + "stale-marked entities on switch {}", connectedNode.toString()); reconciliationPreProcess(connectedNode); } - LOG.debug("Bundle based reconciliation status : {}", provider.isBundleBasedReconciliationEnabled()?"Enable":"Disable"); + LOG.debug("Bundle based reconciliation status : {}", + provider.isBundleBasedReconciliationEnabled() ? "Enable" : "Disable"); if (provider.isBundleBasedReconciliationEnabled()) { BundleBasedReconciliationTask bundleBasedReconTask = new BundleBasedReconciliationTask(connectedNode); return JdkFutureAdapters.listenInPoolThread(executor.submit(bundleBasedReconTask)); @@ -169,98 +171,89 @@ public class FlowNodeReconciliationImpl implements FlowNodeReconciliation { private class BundleBasedReconciliationTask implements Callable { final InstanceIdentifier nodeIdentity; - public BundleBasedReconciliationTask(final InstanceIdentifier nodeIdent) { + BundleBasedReconciliationTask(final InstanceIdentifier nodeIdent) { nodeIdentity = nodeIdent; } @Override public Boolean call() { - String sNode = nodeIdentity.firstKeyOf(Node.class, NodeKey.class).getId().getValue(); + String node = nodeIdentity.firstKeyOf(Node.class, NodeKey.class).getId().getValue(); Optional flowNode = Optional.absent(); BundleId bundleIdValue = new BundleId(BUNDLE_ID.getAndIncrement()); - BigInteger nDpId = getDpnIdFromNodeName(sNode); - LOG.debug("Triggering bundle based reconciliation for device :{}", nDpId); + BigInteger dpnId = getDpnIdFromNodeName(node); + LOG.debug("Triggering bundle based reconciliation for device :{}", dpnId); ReadOnlyTransaction trans = provider.getReadTranaction(); try { flowNode = trans.read(LogicalDatastoreType.CONFIGURATION, nodeIdentity).get(); - } catch (Exception e) { + } catch (ExecutionException | InterruptedException e) { LOG.error("Error occurred while reading the configuration data store for node {}", nodeIdentity, e); } if (flowNode.isPresent()) { - LOG.debug("FlowNode present for Datapath ID {}", nDpId); + LOG.debug("FlowNode present for Datapath ID {}", dpnId); final NodeRef nodeRef = new NodeRef(nodeIdentity.firstIdentifierOf(Node.class)); - final ControlBundleInput openBundleInput = new ControlBundleInputBuilder() - .setNode(nodeRef) - .setBundleId(bundleIdValue) - .setFlags(BUNDLE_FLAGS) - .setType(BundleControlType.ONFBCTOPENREQUEST) + final ControlBundleInput openBundleInput = new ControlBundleInputBuilder().setNode(nodeRef) + .setBundleId(bundleIdValue).setFlags(BUNDLE_FLAGS).setType(BundleControlType.ONFBCTOPENREQUEST) .build(); - final ControlBundleInput commitBundleInput = new ControlBundleInputBuilder() - .setNode(nodeRef) - .setBundleId(bundleIdValue) - .setFlags(BUNDLE_FLAGS) - .setType(BundleControlType.ONFBCTCOMMITREQUEST) - .build(); + final ControlBundleInput commitBundleInput = new ControlBundleInputBuilder().setNode(nodeRef) + .setBundleId(bundleIdValue).setFlags(BUNDLE_FLAGS) + .setType(BundleControlType.ONFBCTCOMMITREQUEST).build(); final AddBundleMessagesInput addBundleMessagesInput = new AddBundleMessagesInputBuilder() - .setNode(nodeRef) - .setBundleId(bundleIdValue) - .setFlags(BUNDLE_FLAGS) - .setMessages(createMessages(nodeRef, flowNode)) - .build(); + .setNode(nodeRef).setBundleId(bundleIdValue).setFlags(BUNDLE_FLAGS) + .setMessages(createMessages(nodeRef, flowNode)).build(); Future> openBundle = salBundleService.controlBundle(openBundleInput); - ListenableFuture> addBundleMessagesFuture = - Futures.transformAsync(JdkFutureAdapters.listenInPoolThread(openBundle), rpcResult -> { - if (rpcResult.isSuccessful()) { - return JdkFutureAdapters.listenInPoolThread( - salBundleService.addBundleMessages(addBundleMessagesInput)); - } - return Futures.immediateFuture(null); - }); - - ListenableFuture> commitBundleFuture = - Futures.transformAsync(addBundleMessagesFuture, rpcResult -> { + ListenableFuture> addBundleMessagesFuture = Futures + .transformAsync(JdkFutureAdapters.listenInPoolThread(openBundle), rpcResult -> { if (rpcResult.isSuccessful()) { - return JdkFutureAdapters.listenInPoolThread( - salBundleService.controlBundle(commitBundleInput)); + return JdkFutureAdapters + .listenInPoolThread(salBundleService.addBundleMessages(addBundleMessagesInput)); } return Futures.immediateFuture(null); }); - /* Bundles not supported for meters*/ - List meters = flowNode.get().getMeter() != null - ? flowNode.get().getMeter() : Collections.emptyList(); - ListenableFuture> meterFuture = - Futures.transformAsync(commitBundleFuture, rpcResult -> { - if (rpcResult.isSuccessful()) { - for (Meter meter : meters) { - final KeyedInstanceIdentifier meterIdent = - nodeIdentity.child(Meter.class, meter.getKey()); - provider.getMeterCommiter().add(meterIdent, meter, nodeIdentity); - } - } - return Futures.immediateFuture(null); - }); - - trans.close(); - try { - if(commitBundleFuture.get().isSuccessful()) { - LOG.debug("Completing bundle based reconciliation for device ID:{}", nDpId); - return true; - } else { - return false; + ListenableFuture> commitBundleFuture = Futures.transformAsync(addBundleMessagesFuture, + rpcResult -> { + if (rpcResult.isSuccessful()) { + return JdkFutureAdapters + .listenInPoolThread(salBundleService.controlBundle(commitBundleInput)); + } + return Futures.immediateFuture(null); + }); + + /* Bundles not supported for meters */ + List meters = flowNode.get().getMeter() != null ? flowNode.get().getMeter() + : Collections.emptyList(); + ListenableFuture> meterFuture = Futures.transformAsync(commitBundleFuture, + rpcResult -> { + if (rpcResult.isSuccessful()) { + for (Meter meter : meters) { + final KeyedInstanceIdentifier meterIdent = nodeIdentity + .child(Meter.class, meter.getKey()); + provider.getMeterCommiter().add(meterIdent, meter, nodeIdentity); } - } catch (InterruptedException | ExecutionException e) { - LOG.error("Error while doing bundle based reconciliation for device ID:{}", nodeIdentity); - return false; } + return Futures.immediateFuture(null); + }); + + trans.close(); + try { + if (commitBundleFuture.get().isSuccessful()) { + LOG.debug("Completing bundle based reconciliation for device ID:{}", dpnId); + return true; + } else { + return false; + } + } catch (InterruptedException | ExecutionException e) { + LOG.error("Error while doing bundle based reconciliation for device ID:{}", nodeIdentity); + return false; + } } - LOG.error("FlowNode not present for Datapath ID {}", nDpId); + LOG.error("FlowNode not present for Datapath ID {}", dpnId); return false; } } @@ -298,51 +291,57 @@ public class FlowNodeReconciliationImpl implements FlowNodeReconciliation { InstanceIdentifier nodeIdentity; - public ReconciliationTask(final InstanceIdentifier nodeIdent) { - nodeIdentity = nodeIdent; + ReconciliationTask(final InstanceIdentifier nodeIdent) { + nodeIdentity = nodeIdent; } + @Override public Boolean call() { - String sNode = nodeIdentity.firstKeyOf(Node.class, NodeKey.class).getId().getValue(); - BigInteger nDpId = getDpnIdFromNodeName(sNode); + String node = nodeIdentity.firstKeyOf(Node.class, NodeKey.class).getId().getValue(); + BigInteger dpnId = getDpnIdFromNodeName(node); ReadOnlyTransaction trans = provider.getReadTranaction(); Optional flowNode = Optional.absent(); - //initialize the counter + // initialize the counter int counter = 0; try { flowNode = trans.read(LogicalDatastoreType.CONFIGURATION, nodeIdentity).get(); - } catch (Exception e) { + } catch (ExecutionException | InterruptedException e) { LOG.warn("Fail with read Config/DS for Node {} !", nodeIdentity, e); return false; } if (flowNode.isPresent()) { - /* Tables - have to be pushed before groups */ - // CHECK if while pusing the update, updateTableInput can be null to emulate a table add + /* Tables - have to be pushed before groups */ + // CHECK if while pusing the update, updateTableInput can be null to emulate a + // table add List tableList = flowNode.get().getTableFeatures() != null - ? flowNode.get().getTableFeatures() : Collections.emptyList(); + ? flowNode.get().getTableFeatures() + : Collections.emptyList(); for (TableFeatures tableFeaturesItem : tableList) { TableFeaturesKey tableKey = tableFeaturesItem.getKey(); - KeyedInstanceIdentifier tableFeaturesII - = nodeIdentity.child(TableFeatures.class, new TableFeaturesKey(tableKey.getTableId())); + KeyedInstanceIdentifier tableFeaturesII = nodeIdentity + .child(TableFeatures.class, new TableFeaturesKey(tableKey.getTableId())); provider.getTableFeaturesCommiter().update(tableFeaturesII, tableFeaturesItem, null, nodeIdentity); } - /* Groups - have to be first */ - List groups = flowNode.get().getGroup() != null - ? flowNode.get().getGroup() : Collections.emptyList(); + /* Groups - have to be first */ + List groups = flowNode.get().getGroup() != null ? flowNode.get().getGroup() + : Collections.emptyList(); List toBeInstalledGroups = new ArrayList<>(); toBeInstalledGroups.addAll(groups); - //new list for suspected groups pointing to ports .. when the ports come up late + // new list for suspected groups pointing to ports .. when the ports come up + // late List suspectedGroups = new ArrayList<>(); Map> groupFutures = new HashMap<>(); - while ((!(toBeInstalledGroups.isEmpty()) || !(suspectedGroups.isEmpty())) && - (counter <= provider.getReconciliationRetryCount())) { //also check if the counter has not crossed the threshold + while ((!toBeInstalledGroups.isEmpty() || !suspectedGroups.isEmpty()) + && counter <= provider.getReconciliationRetryCount()) { // also check if the counter has not + // crossed the threshold if (toBeInstalledGroups.isEmpty() && !suspectedGroups.isEmpty()) { - LOG.debug("These Groups are pointing to node-connectors that are not up yet {}", suspectedGroups.toString()); + LOG.debug("These Groups are pointing to node-connectors that are not up yet {}", + suspectedGroups.toString()); toBeInstalledGroups.addAll(suspectedGroups); break; } @@ -352,8 +351,7 @@ public class FlowNodeReconciliationImpl implements FlowNodeReconciliation { Group group = iterator.next(); boolean okToInstall = true; Buckets buckets = group.getBuckets(); - List bucketList = (buckets == null) - ? null : buckets.getBucket(); + List bucketList = buckets == null ? null : buckets.getBucket(); if (bucketList == null) { bucketList = Collections.emptyList(); } @@ -363,54 +361,52 @@ public class FlowNodeReconciliationImpl implements FlowNodeReconciliation { actions = Collections.emptyList(); } for (Action action : actions) { - //chained-port + // chained-port if (action.getAction().getImplementedInterface().getName() - .equals("org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCase")) { - String nodeConnectorUri = ((OutputActionCase) (action.getAction())) - .getOutputAction().getOutputNodeConnector().getValue(); + .equals("org.opendaylight.yang.gen.v1.urn.opendaylight" + + ".action.types.rev131112.action.action.OutputActionCase")) { + String nodeConnectorUri = ((OutputActionCase) action.getAction()).getOutputAction() + .getOutputNodeConnector().getValue(); LOG.debug("Installing the group for node connector {}", nodeConnectorUri); - //check if the nodeconnector is there in the multimap + // check if the nodeconnector is there in the multimap boolean isPresent = provider.getFlowNodeConnectorInventoryTranslatorImpl() - .isNodeConnectorUpdated(nDpId, nodeConnectorUri); - //if yes set okToInstall = true + .isNodeConnectorUpdated(dpnId, nodeConnectorUri); + // if yes set okToInstall = true if (isPresent) { break; - }//else put it in a different list and still set okToInstall = true - else { + } else { + // else put it in a different list and still set okToInstall = true suspectedGroups.add(group); - LOG.debug("Not yet received the node-connector updated for {} " + - "for the group with id {}", nodeConnectorUri, group.getGroupId().toString()); + LOG.debug( + "Not yet received the node-connector updated for {} " + + "for the group with id {}", + nodeConnectorUri, group.getGroupId().toString()); break; } - - - } - //chained groups - else if (action.getAction().getImplementedInterface().getName() - .equals("org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.GroupActionCase")) { - Long groupId = ((GroupActionCase) (action.getAction())).getGroupAction().getGroupId(); - ListenableFuture future = - groupFutures.get(groupId); + } else if (action.getAction().getImplementedInterface().getName() + .equals("org.opendaylight.yang.gen.v1.urn.opendaylight" + + ".action.types.rev131112.action.action.GroupActionCase")) { + // chained groups + Long groupId = ((GroupActionCase) action.getAction()).getGroupAction().getGroupId(); + ListenableFuture future = groupFutures.get(groupId); if (future == null) { okToInstall = false; break; } - // Need to ensure that the group specified // by group-action is already installed. - awaitGroup(sNode, future); + awaitGroup(node, future); } } if (!okToInstall) { - //increment retry counter value + // increment retry counter value counter++; break; } } - if (okToInstall) { addGroup(groupFutures, group); iterator.remove(); @@ -420,77 +416,76 @@ public class FlowNodeReconciliationImpl implements FlowNodeReconciliation { } } - /* installation of suspected groups*/ + /* installation of suspected groups */ if (!toBeInstalledGroups.isEmpty()) { for (Group group : toBeInstalledGroups) { - LOG.debug("Installing the group {} finally although the port is not up after checking for {} times " - , group.getGroupId().toString(), provider.getReconciliationRetryCount()); + LOG.debug( + "Installing the group {} finally although " + + "the port is not up after checking for {} times ", + group.getGroupId().toString(), provider.getReconciliationRetryCount()); addGroup(groupFutures, group); } } - /* Meters */ - List meters = flowNode.get().getMeter() != null - ? flowNode.get().getMeter() : Collections.emptyList(); + /* Meters */ + List meters = flowNode.get().getMeter() != null ? flowNode.get().getMeter() + : Collections.emptyList(); for (Meter meter : meters) { - final KeyedInstanceIdentifier meterIdent = - nodeIdentity.child(Meter.class, meter.getKey()); + final KeyedInstanceIdentifier meterIdent = nodeIdentity.child(Meter.class, + meter.getKey()); provider.getMeterCommiter().add(meterIdent, meter, nodeIdentity); } // Need to wait for all groups to be installed before adding // flows. - awaitGroups(sNode, groupFutures.values()); + awaitGroups(node, groupFutures.values()); - /* Flows */ - List tables = flowNode.get().getTable() != null - ? flowNode.get().getTable() : Collections.
emptyList(); + /* Flows */ + List
tables = flowNode.get().getTable() != null ? flowNode.get().getTable() + : Collections.
emptyList(); for (Table table : tables) { - final KeyedInstanceIdentifier tableIdent = - nodeIdentity.child(Table.class, table.getKey()); + final KeyedInstanceIdentifier tableIdent = nodeIdentity.child(Table.class, + table.getKey()); List flows = table.getFlow() != null ? table.getFlow() : Collections.emptyList(); for (Flow flow : flows) { - final KeyedInstanceIdentifier flowIdent = - tableIdent.child(Flow.class, flow.getKey()); + final KeyedInstanceIdentifier flowIdent = tableIdent.child(Flow.class, + flow.getKey()); provider.getFlowCommiter().add(flowIdent, flow, nodeIdentity); } } } - /* clean transaction */ + /* clean transaction */ trans.close(); return true; } /** - * Invoke add-group RPC, and put listenable future associated with the - * RPC into the given map. + * Invoke add-group RPC, and put listenable future associated with the RPC into + * the given map. * - * @param map The map to store listenable futures associated with - * add-group RPC. - * @param group The group to add. + * @param map + * The map to store listenable futures associated with add-group RPC. + * @param group + * The group to add. */ private void addGroup(Map> map, Group group) { - KeyedInstanceIdentifier groupIdent = - nodeIdentity.child(Group.class, group.getKey()); + KeyedInstanceIdentifier groupIdent = nodeIdentity.child(Group.class, group.getKey()); final Long groupId = group.getGroupId().getValue(); - ListenableFuture future = JdkFutureAdapters.listenInPoolThread( - provider.getGroupCommiter().add( - groupIdent, group, nodeIdentity)); + ListenableFuture future = JdkFutureAdapters + .listenInPoolThread(provider.getGroupCommiter().add(groupIdent, group, nodeIdentity)); Futures.addCallback(future, new FutureCallback() { @Override public void onSuccess(Object result) { if (LOG.isTraceEnabled()) { LOG.trace("add-group RPC completed: node={}, id={}", - nodeIdentity.firstKeyOf(Node.class).getId(). - getValue(), groupId); + nodeIdentity.firstKeyOf(Node.class).getId().getValue(), groupId); } } @Override public void onFailure(Throwable cause) { - String msg = "add-group RPC failed: node=" + - nodeIdentity.firstKeyOf(Node.class).getId().getValue() + - ", id=" + groupId; + String msg = "add-group RPC failed: node=" + nodeIdentity.firstKeyOf(Node.class).getId().getValue() + + ", id=" + groupId; LOG.debug(msg, cause); } }); @@ -501,9 +496,11 @@ public class FlowNodeReconciliationImpl implements FlowNodeReconciliation { /** * Wait for completion of add-group RPC. * - * @param nodeId The identifier for the target node. - * @param future Future associated with add-group RPC that installs - * the target group. + * @param nodeId + * The identifier for the target node. + * @param future + * Future associated with add-group RPC that installs the target + * group. */ private void awaitGroup(String nodeId, ListenableFuture future) { awaitGroups(nodeId, Collections.singleton(future)); @@ -512,25 +509,19 @@ public class FlowNodeReconciliationImpl implements FlowNodeReconciliation { /** * Wait for completion of add-group RPCs. * - * @param nodeId The identifier for the target node. - * @param futures A collection of futures associated with add-group - * RPCs. + * @param nodeId + * The identifier for the target node. + * @param futures + * A collection of futures associated with add-group RPCs. */ - private void awaitGroups(String nodeId, - Collection> futures) { + private void awaitGroups(String nodeId, Collection> futures) { if (!futures.isEmpty()) { - long timeout = Math.min( - ADD_GROUP_TIMEOUT * futures.size(), MAX_ADD_GROUP_TIMEOUT); + long timeout = Math.min(ADD_GROUP_TIMEOUT * futures.size(), MAX_ADD_GROUP_TIMEOUT); try { - Futures.successfulAsList(futures). - get(timeout, TimeUnit.NANOSECONDS); + Futures.successfulAsList(futures).get(timeout, TimeUnit.NANOSECONDS); LOG.trace("awaitGroups() completed: node={}", nodeId); - } catch (TimeoutException e) { - LOG.debug("add-group RPCs did not complete: node={}", - nodeId); - } catch (Exception e) { - LOG.debug("Unhandled exception while waiting for group installation on node {}", - nodeId, e); + } catch (TimeoutException | InterruptedException | ExecutionException e) { + LOG.debug("add-group RPCs did not complete: node={}", nodeId); } } } @@ -543,19 +534,16 @@ public class FlowNodeReconciliationImpl implements FlowNodeReconciliation { } private void reconciliationPreProcess(final InstanceIdentifier nodeIdent) { - List> staleFlowsToBeBulkDeleted = Lists.newArrayList(); List> staleGroupsToBeBulkDeleted = Lists.newArrayList(); List> staleMetersToBeBulkDeleted = Lists.newArrayList(); - ReadOnlyTransaction trans = provider.getReadTranaction(); Optional flowNode = Optional.absent(); try { flowNode = trans.read(LogicalDatastoreType.CONFIGURATION, nodeIdent).get(); - } - catch (Exception e) { + } catch (ExecutionException | InterruptedException e) { LOG.warn("Reconciliation Pre-Processing Fail with read Config/DS for Node {} !", nodeIdent, e); } @@ -564,20 +552,20 @@ public class FlowNodeReconciliationImpl implements FlowNodeReconciliation { LOG.debug("Proceeding with deletion of stale-marked Flows on switch {} using Openflow interface", nodeIdent.toString()); /* Stale-Flows - Stale-marked Flows have to be removed first for safety */ - List
tables = flowNode.get().getTable() != null - ? flowNode.get().getTable() : Collections.
emptyList(); + List
tables = flowNode.get().getTable() != null ? flowNode.get().getTable() + : Collections.
emptyList(); for (Table table : tables) { - final KeyedInstanceIdentifier tableIdent = - nodeIdent.child(Table.class, table.getKey()); - List staleFlows = table.getStaleFlow() != null ? table.getStaleFlow() : Collections. emptyList(); + final KeyedInstanceIdentifier tableIdent = nodeIdent.child(Table.class, + table.getKey()); + List staleFlows = table.getStaleFlow() != null ? table.getStaleFlow() + : Collections.emptyList(); for (StaleFlow staleFlow : staleFlows) { FlowBuilder flowBuilder = new FlowBuilder(staleFlow); Flow toBeDeletedFlow = flowBuilder.setId(staleFlow.getId()).build(); - final KeyedInstanceIdentifier flowIdent = - tableIdent.child(Flow.class, toBeDeletedFlow.getKey()); - + final KeyedInstanceIdentifier flowIdent = tableIdent.child(Flow.class, + toBeDeletedFlow.getKey()); this.provider.getFlowCommiter().remove(flowIdent, toBeDeletedFlow, nodeIdent); @@ -585,23 +573,23 @@ public class FlowNodeReconciliationImpl implements FlowNodeReconciliation { } } - LOG.debug("Proceeding with deletion of stale-marked Groups for switch {} using Openflow interface", nodeIdent.toString()); - // TODO: Should we collate the futures of RPC-calls to be sure that groups are Flows are fully deleted + // TODO: Should we collate the futures of RPC-calls to be sure that groups are + // Flows are fully deleted // before attempting to delete groups - just in case there are references /* Stale-marked Groups - Can be deleted after flows */ - List staleGroups = flowNode.get().getStaleGroup() != null - ? flowNode.get().getStaleGroup() : Collections. emptyList(); + List staleGroups = flowNode.get().getStaleGroup() != null ? flowNode.get().getStaleGroup() + : Collections.emptyList(); for (StaleGroup staleGroup : staleGroups) { GroupBuilder groupBuilder = new GroupBuilder(staleGroup); Group toBeDeletedGroup = groupBuilder.setGroupId(staleGroup.getGroupId()).build(); - final KeyedInstanceIdentifier groupIdent = - nodeIdent.child(Group.class, toBeDeletedGroup.getKey()); + final KeyedInstanceIdentifier groupIdent = nodeIdent.child(Group.class, + toBeDeletedGroup.getKey()); this.provider.getGroupCommiter().remove(groupIdent, toBeDeletedGroup, nodeIdent); @@ -611,17 +599,16 @@ public class FlowNodeReconciliationImpl implements FlowNodeReconciliation { LOG.debug("Proceeding with deletion of stale-marked Meters for switch {} using Openflow interface", nodeIdent.toString()); /* Stale-marked Meters - can be deleted anytime - so least priority */ - List staleMeters = flowNode.get().getStaleMeter() != null - ? flowNode.get().getStaleMeter() : Collections. emptyList(); + List staleMeters = flowNode.get().getStaleMeter() != null ? flowNode.get().getStaleMeter() + : Collections.emptyList(); for (StaleMeter staleMeter : staleMeters) { MeterBuilder meterBuilder = new MeterBuilder(staleMeter); Meter toBeDeletedMeter = meterBuilder.setMeterId(staleMeter.getMeterId()).build(); - final KeyedInstanceIdentifier meterIdent = - nodeIdent.child(Meter.class, toBeDeletedMeter.getKey()); - + final KeyedInstanceIdentifier meterIdent = nodeIdent.child(Meter.class, + toBeDeletedMeter.getKey()); this.provider.getMeterCommiter().remove(meterIdent, toBeDeletedMeter, nodeIdent); @@ -634,20 +621,18 @@ public class FlowNodeReconciliationImpl implements FlowNodeReconciliation { LOG.debug("Deleting all stale-marked flows/groups/meters of for switch {} in Configuration DS", nodeIdent.toString()); - // Now, do the bulk deletions - deleteDSStaleFlows(staleFlowsToBeBulkDeleted); + // Now, do the bulk deletions + deleteDSStaleFlows(staleFlowsToBeBulkDeleted); deleteDSStaleGroups(staleGroupsToBeBulkDeleted); deleteDSStaleMeters(staleMetersToBeBulkDeleted); - } - - private void deleteDSStaleFlows(List> flowsForBulkDelete){ + private void deleteDSStaleFlows(List> flowsForBulkDelete) { ImmutableList.Builder> builder = ImmutableList.builder(); WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction(); - for (InstanceIdentifier staleFlowIId : flowsForBulkDelete){ + for (InstanceIdentifier staleFlowIId : flowsForBulkDelete) { writeTransaction.delete(LogicalDatastoreType.CONFIGURATION, staleFlowIId); } @@ -655,56 +640,54 @@ public class FlowNodeReconciliationImpl implements FlowNodeReconciliation { handleStaleEntityDeletionResultFuture(submitFuture); } - private void deleteDSStaleGroups(List> groupsForBulkDelete){ + private void deleteDSStaleGroups(List> groupsForBulkDelete) { ImmutableList.Builder> builder = ImmutableList.builder(); WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction(); - for (InstanceIdentifier staleGroupIId : groupsForBulkDelete){ + for (InstanceIdentifier staleGroupIId : groupsForBulkDelete) { writeTransaction.delete(LogicalDatastoreType.CONFIGURATION, staleGroupIId); } CheckedFuture submitFuture = writeTransaction.submit(); handleStaleEntityDeletionResultFuture(submitFuture); - } - private void deleteDSStaleMeters(List> metersForBulkDelete){ + private void deleteDSStaleMeters(List> metersForBulkDelete) { ImmutableList.Builder> builder = ImmutableList.builder(); WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction(); - for (InstanceIdentifier staleMeterIId : metersForBulkDelete){ + for (InstanceIdentifier staleMeterIId : metersForBulkDelete) { writeTransaction.delete(LogicalDatastoreType.CONFIGURATION, staleMeterIId); } CheckedFuture submitFuture = writeTransaction.submit(); handleStaleEntityDeletionResultFuture(submitFuture); - - } - - private InstanceIdentifier getStaleFlowInstanceIdentifier(StaleFlow staleFlow, InstanceIdentifier nodeIdent) { - return nodeIdent - .child(Table.class, new TableKey(staleFlow.getTableId())) - .child(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.StaleFlow.class, - new StaleFlowKey(new FlowId(staleFlow.getId()))); + private InstanceIdentifier getStaleFlowInstanceIdentifier( + StaleFlow staleFlow, InstanceIdentifier nodeIdent) { + return nodeIdent.child(Table.class, new TableKey(staleFlow.getTableId())).child( + org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.StaleFlow.class, + new StaleFlowKey(new FlowId(staleFlow.getId()))); } - private InstanceIdentifier getStaleGroupInstanceIdentifier(StaleGroup staleGroup, InstanceIdentifier nodeIdent) { - return nodeIdent - .child(StaleGroup.class, new StaleGroupKey(new GroupId(staleGroup.getGroupId()))); + private InstanceIdentifier getStaleGroupInstanceIdentifier( + StaleGroup staleGroup, InstanceIdentifier nodeIdent) { + return nodeIdent.child(StaleGroup.class, new StaleGroupKey(new GroupId(staleGroup.getGroupId()))); } - - private InstanceIdentifier getStaleMeterInstanceIdentifier(StaleMeter staleMeter, InstanceIdentifier nodeIdent) { - return nodeIdent - .child(StaleMeter.class, new StaleMeterKey(new MeterId(staleMeter.getMeterId()))); + private InstanceIdentifier getStaleMeterInstanceIdentifier( + StaleMeter staleMeter, InstanceIdentifier nodeIdent) { + return nodeIdent.child(StaleMeter.class, new StaleMeterKey(new MeterId(staleMeter.getMeterId()))); } - - private void handleStaleEntityDeletionResultFuture(CheckedFuture submitFuture) { + private void handleStaleEntityDeletionResultFuture( + CheckedFuture submitFuture) { Futures.addCallback(submitFuture, new FutureCallback() { @Override public void onSuccess(Void result) { @@ -712,49 +695,52 @@ public class FlowNodeReconciliationImpl implements FlowNodeReconciliation { } @Override - public void onFailure(Throwable t) { - LOG.debug("Stale entity removal failed {}", t); + public void onFailure(Throwable throwable) { + LOG.debug("Stale entity removal failed {}", throwable); } }); } - private Flow getDeleteAllFlow(){ + private Flow getDeleteAllFlow() { final FlowBuilder flowBuilder = new FlowBuilder(); flowBuilder.setTableId(OFConstants.OFPTT_ALL); return flowBuilder.build(); } - private Group getDeleteAllGroup(){ + private Group getDeleteAllGroup() { final GroupBuilder groupBuilder = new GroupBuilder(); groupBuilder.setGroupType(GroupTypes.GroupAll); groupBuilder.setGroupId(new GroupId(OFConstants.OFPG_ALL)); return groupBuilder.build(); } - private Messages createMessages(final NodeRef nodeRef , final Optional flowNode) { - final List messages = new ArrayList<>(); - messages.add(new MessageBuilder().setNode(nodeRef).setBundleInnerMessage( - new BundleRemoveFlowCaseBuilder() - .setRemoveFlowCaseData(new RemoveFlowCaseDataBuilder(getDeleteAllFlow()).build()).build()).build()); + private Messages createMessages(final NodeRef nodeRef, final Optional flowNode) { + final List messages = new ArrayList<>(); + messages.add(new MessageBuilder().setNode(nodeRef) + .setBundleInnerMessage(new BundleRemoveFlowCaseBuilder() + .setRemoveFlowCaseData(new RemoveFlowCaseDataBuilder(getDeleteAllFlow()).build()).build()) + .build()); - messages.add(new MessageBuilder().setNode(nodeRef).setBundleInnerMessage( - new BundleRemoveGroupCaseBuilder() - .setRemoveGroupCaseData(new RemoveGroupCaseDataBuilder(getDeleteAllGroup()).build()).build()).build()); + messages.add(new MessageBuilder().setNode(nodeRef) + .setBundleInnerMessage(new BundleRemoveGroupCaseBuilder() + .setRemoveGroupCaseData(new RemoveGroupCaseDataBuilder(getDeleteAllGroup()).build()).build()) + .build()); - if(flowNode.get().getGroup()!= null) { + if (flowNode.get().getGroup() != null) { for (Group gr : flowNode.get().getGroup()) { - messages.add(new MessageBuilder().setNode(nodeRef).setBundleInnerMessage( - new BundleAddGroupCaseBuilder() - .setAddGroupCaseData(new AddGroupCaseDataBuilder(gr).build()).build()).build()); + messages.add(new MessageBuilder().setNode(nodeRef).setBundleInnerMessage(new BundleAddGroupCaseBuilder() + .setAddGroupCaseData(new AddGroupCaseDataBuilder(gr).build()).build()).build()); } } - if(flowNode.get().getTable()!= null) { + if (flowNode.get().getTable() != null) { for (Table table : flowNode.get().getTable()) { for (Flow flow : table.getFlow()) { - messages.add(new MessageBuilder().setNode(nodeRef).setBundleInnerMessage( - new BundleAddFlowCaseBuilder() - .setAddFlowCaseData(new AddFlowCaseDataBuilder(flow).build()).build()).build()); + messages.add( + new MessageBuilder().setNode(nodeRef) + .setBundleInnerMessage(new BundleAddFlowCaseBuilder() + .setAddFlowCaseData(new AddFlowCaseDataBuilder(flow).build()).build()) + .build()); } } } @@ -763,4 +749,3 @@ public class FlowNodeReconciliationImpl implements FlowNodeReconciliation { return new MessagesBuilder().setMessage(messages).build(); } } - diff --git a/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/ForwardingRulesManagerImpl.java b/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/ForwardingRulesManagerImpl.java index c20badaf8c..ad6a4dec61 100644 --- a/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/ForwardingRulesManagerImpl.java +++ b/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/ForwardingRulesManagerImpl.java @@ -16,7 +16,6 @@ import java.util.Optional; import java.util.concurrent.atomic.AtomicLong; import javax.annotation.Nonnull; -import com.google.common.util.concurrent.Futures; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; @@ -49,11 +48,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * forwardingrules-manager - * org.opendaylight.openflowplugin.applications.frm.impl + * forwardingrules-manager org.opendaylight.openflowplugin.applications.frm.impl * - * Manager and middle point for whole module. - * It contains ActiveNodeHolder and provide all RPC services. + *

+ * Manager and middle point for whole module. It contains ActiveNodeHolder and + * provide all RPC services. * */ public class ForwardingRulesManagerImpl implements ForwardingRulesManager { @@ -89,13 +88,10 @@ public class ForwardingRulesManagerImpl implements ForwardingRulesManager { private int reconciliationRetryCount; private boolean isBundleBasedReconciliationEnabled; - public ForwardingRulesManagerImpl(final DataBroker dataBroker, - final RpcConsumerRegistry rpcRegistry, - final ForwardingRulesManagerConfig config, - final ClusterSingletonServiceProvider clusterSingletonService, - final NotificationProviderService notificationService, - final ConfigurationService configurationService, - final ReconciliationManager reconciliationManager) { + public ForwardingRulesManagerImpl(final DataBroker dataBroker, final RpcConsumerRegistry rpcRegistry, + final ForwardingRulesManagerConfig config, final ClusterSingletonServiceProvider clusterSingletonService, + final NotificationProviderService notificationService, final ConfigurationService configurationService, + final ReconciliationManager reconciliationManager) { disableReconciliation = config.isDisableReconciliation(); staleMarkingEnabled = config.isStaleMarkingEnabled(); reconciliationRetryCount = config.getReconciliationRetryCount(); @@ -104,8 +100,8 @@ public class ForwardingRulesManagerImpl implements ForwardingRulesManager { this.dataService = Preconditions.checkNotNull(dataBroker, "DataBroker can not be null!"); this.clusterSingletonServiceProvider = Preconditions.checkNotNull(clusterSingletonService, "ClusterSingletonService provider can not be null"); - this.notificationService = Preconditions.checkNotNull(notificationService, "Notification publisher configurationService is" + - " not available"); + this.notificationService = Preconditions.checkNotNull(notificationService, + "Notification publisher configurationService is" + " not available"); this.reconciliationManager = reconciliationManager; Preconditions.checkArgument(rpcRegistry != null, "RpcConsumerRegistry can not be null !"); @@ -124,19 +120,17 @@ public class ForwardingRulesManagerImpl implements ForwardingRulesManager { @Override public void start() { - this.nodeListener = new FlowNodeReconciliationImpl(this,dataService, - SERVICE_NAME, FRM_RECONCILIATION_PRIORITY, ResultState.DONOTHING); + this.nodeListener = new FlowNodeReconciliationImpl(this, dataService, SERVICE_NAME, FRM_RECONCILIATION_PRIORITY, + ResultState.DONOTHING); if (this.isReconciliationDisabled()) { LOG.debug("Reconciliation is disabled by user"); } else { this.reconciliationNotificationRegistration = reconciliationManager.registerService(this.nodeListener); LOG.debug("Reconciliation is enabled by user and successfully registered to the reconciliation framework"); } - this.deviceMastershipManager = new DeviceMastershipManager(clusterSingletonServiceProvider, - notificationService, - this.nodeListener, - dataService); - flowNodeConnectorInventoryTranslatorImpl = new FlowNodeConnectorInventoryTranslatorImpl(this,dataService); + this.deviceMastershipManager = new DeviceMastershipManager(clusterSingletonServiceProvider, notificationService, + this.nodeListener, dataService); + flowNodeConnectorInventoryTranslatorImpl = new FlowNodeConnectorInventoryTranslatorImpl(this, dataService); this.flowListener = new FlowForwarder(this, dataService); this.groupListener = new GroupForwarder(this, dataService); @@ -198,14 +192,14 @@ public class ForwardingRulesManagerImpl implements ForwardingRulesManager { boolean result = false; InstanceIdentifier nodeIid = ident.firstIdentifierOf(Node.class); final ReadOnlyTransaction transaction = dataService.newReadOnlyTransaction(); - CheckedFuture, ReadFailedException> future = transaction.read(LogicalDatastoreType.OPERATIONAL, nodeIid); + CheckedFuture, ReadFailedException> future = transaction + .read(LogicalDatastoreType.OPERATIONAL, nodeIid); try { com.google.common.base.Optional optionalDataObject = future.checkedGet(); if (optionalDataObject.isPresent()) { result = true; } else { - LOG.debug("{}: Failed to read {}", - Thread.currentThread().getStackTrace()[1], nodeIid); + LOG.debug("{}: Failed to read {}", Thread.currentThread().getStackTrace()[1], nodeIid); } } catch (ReadFailedException e) { LOG.warn("Failed to read {} ", nodeIid, e); @@ -311,6 +305,9 @@ public class ForwardingRulesManagerImpl implements ForwardingRulesManager { case BUNDLE_BASED_RECONCILIATION_ENABLED: isBundleBasedReconciliationEnabled = Boolean.valueOf(propertyValue); break; + default: + LOG.warn("Not forwarding rule property found."); + break; } }); } diff --git a/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/GroupForwarder.java b/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/GroupForwarder.java index bb55b50b68..f9ee0feafd 100644 --- a/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/GroupForwarder.java +++ b/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/GroupForwarder.java @@ -11,7 +11,6 @@ import com.google.common.base.Preconditions; import com.google.common.util.concurrent.CheckedFuture; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; -import java.util.concurrent.Callable; import java.util.concurrent.Future; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier; @@ -45,10 +44,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * GroupForwarder - * It implements {@link org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener} - * for WildCardedPath to {@link Group} and ForwardingRulesCommiter interface for methods: - * add, update and remove {@link Group} processing for + * GroupForwarder It implements + * {@link org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener} + * for WildCardedPath to {@link Group} and ForwardingRulesCommiter interface for + * methods: add, update and remove {@link Group} processing for * {@link org.opendaylight.controller.md.sal.binding.api.DataTreeModification}. */ public class GroupForwarder extends AbstractListeningCommiter { @@ -57,20 +56,18 @@ public class GroupForwarder extends AbstractListeningCommiter { private final DataBroker dataBroker; private ListenerRegistration listenerRegistration; - public GroupForwarder (final ForwardingRulesManager manager, final DataBroker db) { + @SuppressWarnings("IllegalCatch") + public GroupForwarder(final ForwardingRulesManager manager, final DataBroker db) { super(manager, Group.class); dataBroker = Preconditions.checkNotNull(db, "DataBroker can not be null!"); - final DataTreeIdentifier treeId = new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, getWildCardPath()); + final DataTreeIdentifier treeId = new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, + getWildCardPath()); try { SimpleTaskRetryLooper looper = new SimpleTaskRetryLooper(ForwardingRulesManagerImpl.STARTUP_LOOP_TICK, ForwardingRulesManagerImpl.STARTUP_LOOP_MAX_RETRIES); - listenerRegistration = looper.loopUntilNoException(new Callable>() { - @Override - public ListenerRegistration call() throws Exception { - return db.registerDataTreeChangeListener(treeId, GroupForwarder.this); - } - }); + listenerRegistration = looper + .loopUntilNoException(() -> db.registerDataTreeChangeListener(treeId, GroupForwarder.this)); } catch (final Exception e) { LOG.warn("FRM Group DataTreeChange listener registration fail!"); LOG.debug("FRM Group DataTreeChange listener registration fail ..", e); @@ -81,27 +78,22 @@ public class GroupForwarder extends AbstractListeningCommiter { @Override public void close() { if (listenerRegistration != null) { - try { - listenerRegistration.close(); - } catch (Exception e) { - LOG.warn("Error by stop FRM GroupChangeListener: {}", e.getMessage()); - LOG.debug("Error by stop FRM GroupChangeListener..", e); - } + listenerRegistration.close(); listenerRegistration = null; } } @Override protected InstanceIdentifier getWildCardPath() { - return InstanceIdentifier.create(Nodes.class).child(Node.class) - .augmentation(FlowCapableNode.class).child(Group.class); + return InstanceIdentifier.create(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class) + .child(Group.class); } @Override public void remove(final InstanceIdentifier identifier, final Group removeDataObj, - final InstanceIdentifier nodeIdent) { + final InstanceIdentifier nodeIdent) { - final Group group = (removeDataObj); + final Group group = removeDataObj; final RemoveGroupInputBuilder builder = new RemoveGroupInputBuilder(group); builder.setNode(new NodeRef(nodeIdent.firstIdentifierOf(Node.class))); @@ -110,12 +102,12 @@ public class GroupForwarder extends AbstractListeningCommiter { this.provider.getSalGroupService().removeGroup(builder.build()); } - //TODO: Pull this into ForwardingRulesCommiter and override it here + // TODO: Pull this into ForwardingRulesCommiter and override it here @Override - public Future> removeWithResult(final InstanceIdentifier identifier, final Group removeDataObj, - final InstanceIdentifier nodeIdent) { + public Future> removeWithResult(final InstanceIdentifier identifier, + final Group removeDataObj, final InstanceIdentifier nodeIdent) { - final Group group = (removeDataObj); + final Group group = removeDataObj; final RemoveGroupInputBuilder builder = new RemoveGroupInputBuilder(group); builder.setNode(new NodeRef(nodeIdent.firstIdentifierOf(Node.class))); @@ -125,29 +117,27 @@ public class GroupForwarder extends AbstractListeningCommiter { } @Override - public void update(final InstanceIdentifier identifier, - final Group original, final Group update, - final InstanceIdentifier nodeIdent) { + public void update(final InstanceIdentifier identifier, final Group original, final Group update, + final InstanceIdentifier nodeIdent) { - final Group originalGroup = (original); - final Group updatedGroup = (update); + final Group originalGroup = original; + final Group updatedGroup = update; final UpdateGroupInputBuilder builder = new UpdateGroupInputBuilder(); builder.setNode(new NodeRef(nodeIdent.firstIdentifierOf(Node.class))); builder.setGroupRef(new GroupRef(identifier)); builder.setTransactionUri(new Uri(provider.getNewTransactionId())); - builder.setUpdatedGroup((new UpdatedGroupBuilder(updatedGroup)).build()); - builder.setOriginalGroup((new OriginalGroupBuilder(originalGroup)).build()); + builder.setUpdatedGroup(new UpdatedGroupBuilder(updatedGroup).build()); + builder.setOriginalGroup(new OriginalGroupBuilder(originalGroup).build()); this.provider.getSalGroupService().updateGroup(builder.build()); } @Override - public Future> add( - final InstanceIdentifier identifier, final Group addDataObj, - final InstanceIdentifier nodeIdent) { + public Future> add(final InstanceIdentifier identifier, final Group addDataObj, + final InstanceIdentifier nodeIdent) { - final Group group = (addDataObj); + final Group group = addDataObj; final AddGroupInputBuilder builder = new AddGroupInputBuilder(group); builder.setNode(new NodeRef(nodeIdent.firstIdentifierOf(Node.class))); @@ -157,22 +147,24 @@ public class GroupForwarder extends AbstractListeningCommiter { } @Override - public void createStaleMarkEntity(InstanceIdentifier identifier, Group del, InstanceIdentifier nodeIdent) { + public void createStaleMarkEntity(InstanceIdentifier identifier, Group del, + InstanceIdentifier nodeIdent) { LOG.debug("Creating Stale-Mark entry for the switch {} for Group {} ", nodeIdent.toString(), del.toString()); StaleGroup staleGroup = makeStaleGroup(identifier, del, nodeIdent); persistStaleGroup(staleGroup, nodeIdent); } - - private StaleGroup makeStaleGroup(InstanceIdentifier identifier, Group del, InstanceIdentifier nodeIdent){ + private StaleGroup makeStaleGroup(InstanceIdentifier identifier, Group del, + InstanceIdentifier nodeIdent) { StaleGroupBuilder staleGroupBuilder = new StaleGroupBuilder(del); return staleGroupBuilder.setGroupId(del.getGroupId()).build(); } - private void persistStaleGroup(StaleGroup staleGroup, InstanceIdentifier nodeIdent){ + private void persistStaleGroup(StaleGroup staleGroup, InstanceIdentifier nodeIdent) { WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction(); - writeTransaction.put(LogicalDatastoreType.CONFIGURATION, getStaleGroupInstanceIdentifier(staleGroup, nodeIdent), staleGroup, false); + writeTransaction.put(LogicalDatastoreType.CONFIGURATION, getStaleGroupInstanceIdentifier(staleGroup, nodeIdent), + staleGroup, false); CheckedFuture submitFuture = writeTransaction.submit(); handleStaleGroupResultFuture(submitFuture); @@ -186,17 +178,17 @@ public class GroupForwarder extends AbstractListeningCommiter { } @Override - public void onFailure(Throwable t) { - LOG.error("Stale Group creation failed {}", t); + public void onFailure(Throwable throwable) { + LOG.error("Stale Group creation failed {}", throwable); } }); } - private InstanceIdentifier getStaleGroupInstanceIdentifier(StaleGroup staleGroup, InstanceIdentifier nodeIdent) { - return nodeIdent - .child(StaleGroup.class, new StaleGroupKey(new GroupId(staleGroup.getGroupId()))); + private InstanceIdentifier getStaleGroupInstanceIdentifier( + StaleGroup staleGroup, InstanceIdentifier nodeIdent) { + return nodeIdent.child(StaleGroup.class, new StaleGroupKey(new GroupId(staleGroup.getGroupId()))); } } - diff --git a/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/MeterForwarder.java b/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/MeterForwarder.java index 531e858cb2..08b4d5742f 100644 --- a/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/MeterForwarder.java +++ b/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/MeterForwarder.java @@ -11,7 +11,6 @@ import com.google.common.base.Preconditions; import com.google.common.util.concurrent.CheckedFuture; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; -import java.util.concurrent.Callable; import java.util.concurrent.Future; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier; @@ -45,10 +44,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * MeterForwarder - * It implements {@link org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener} - * for WildCardedPath to {@link Meter} and ForwardingRulesCommiter interface for methods: - * add, update and remove {@link Meter} processing for + * MeterForwarder It implements + * {@link org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener} + * for WildCardedPath to {@link Meter} and ForwardingRulesCommiter interface for + * methods: add, update and remove {@link Meter} processing for * {@link org.opendaylight.controller.md.sal.binding.api.DataTreeModification}. * */ @@ -58,20 +57,18 @@ public class MeterForwarder extends AbstractListeningCommiter { private final DataBroker dataBroker; private ListenerRegistration listenerRegistration; - public MeterForwarder (final ForwardingRulesManager manager, final DataBroker db) { + @SuppressWarnings("IllegalCatch") + public MeterForwarder(final ForwardingRulesManager manager, final DataBroker db) { super(manager, Meter.class); dataBroker = Preconditions.checkNotNull(db, "DataBroker can not be null!"); - final DataTreeIdentifier treeId = new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, getWildCardPath()); + final DataTreeIdentifier treeId = new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, + getWildCardPath()); try { SimpleTaskRetryLooper looper = new SimpleTaskRetryLooper(ForwardingRulesManagerImpl.STARTUP_LOOP_TICK, ForwardingRulesManagerImpl.STARTUP_LOOP_MAX_RETRIES); - listenerRegistration = looper.loopUntilNoException(new Callable>() { - @Override - public ListenerRegistration call() throws Exception { - return db.registerDataTreeChangeListener(treeId, MeterForwarder.this); - } - }); + listenerRegistration = looper + .loopUntilNoException(() -> db.registerDataTreeChangeListener(treeId, MeterForwarder.this)); } catch (final Exception e) { LOG.warn("FRM Meter DataTreeChange listener registration fail!"); LOG.debug("FRM Meter DataTreeChange listener registration fail ..", e); @@ -82,25 +79,20 @@ public class MeterForwarder extends AbstractListeningCommiter { @Override public void close() { if (listenerRegistration != null) { - try { - listenerRegistration.close(); - } catch (Exception e) { - LOG.warn("Error by stop FRM MeterChangeListener.{}", e.getMessage()); - LOG.debug("Error by stop FRM MeterChangeListener..", e); - } + listenerRegistration.close(); listenerRegistration = null; } } @Override protected InstanceIdentifier getWildCardPath() { - return InstanceIdentifier.create(Nodes.class).child(Node.class) - .augmentation(FlowCapableNode.class).child(Meter.class); + return InstanceIdentifier.create(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class) + .child(Meter.class); } @Override public void remove(final InstanceIdentifier identifier, final Meter removeDataObj, - final InstanceIdentifier nodeIdent) { + final InstanceIdentifier nodeIdent) { final RemoveMeterInputBuilder builder = new RemoveMeterInputBuilder(removeDataObj); @@ -110,10 +102,9 @@ public class MeterForwarder extends AbstractListeningCommiter { this.provider.getSalMeterService().removeMeter(builder.build()); } - @Override - public Future> removeWithResult(final InstanceIdentifier identifier, final Meter removeDataObj, - final InstanceIdentifier nodeIdent) { + public Future> removeWithResult(final InstanceIdentifier identifier, + final Meter removeDataObj, final InstanceIdentifier nodeIdent) { final RemoveMeterInputBuilder builder = new RemoveMeterInputBuilder(removeDataObj); @@ -124,25 +115,23 @@ public class MeterForwarder extends AbstractListeningCommiter { } @Override - public void update(final InstanceIdentifier identifier, - final Meter original, final Meter update, - final InstanceIdentifier nodeIdent) { + public void update(final InstanceIdentifier identifier, final Meter original, final Meter update, + final InstanceIdentifier nodeIdent) { final UpdateMeterInputBuilder builder = new UpdateMeterInputBuilder(); builder.setNode(new NodeRef(nodeIdent.firstIdentifierOf(Node.class))); builder.setMeterRef(new MeterRef(identifier)); builder.setTransactionUri(new Uri(provider.getNewTransactionId())); - builder.setUpdatedMeter((new UpdatedMeterBuilder(update)).build()); - builder.setOriginalMeter((new OriginalMeterBuilder(original)).build()); + builder.setUpdatedMeter(new UpdatedMeterBuilder(update).build()); + builder.setOriginalMeter(new OriginalMeterBuilder(original).build()); this.provider.getSalMeterService().updateMeter(builder.build()); } @Override - public Future> add( - final InstanceIdentifier identifier, final Meter addDataObj, - final InstanceIdentifier nodeIdent) { + public Future> add(final InstanceIdentifier identifier, final Meter addDataObj, + final InstanceIdentifier nodeIdent) { final AddMeterInputBuilder builder = new AddMeterInputBuilder(addDataObj); @@ -153,29 +142,31 @@ public class MeterForwarder extends AbstractListeningCommiter { } @Override - public void createStaleMarkEntity(InstanceIdentifier identifier, Meter del, InstanceIdentifier nodeIdent) { + public void createStaleMarkEntity(InstanceIdentifier identifier, Meter del, + InstanceIdentifier nodeIdent) { LOG.debug("Creating Stale-Mark entry for the switch {} for meter {} ", nodeIdent.toString(), del.toString()); StaleMeter staleMeter = makeStaleMeter(identifier, del, nodeIdent); persistStaleMeter(staleMeter, nodeIdent); } - private StaleMeter makeStaleMeter(InstanceIdentifier identifier, Meter del, InstanceIdentifier nodeIdent){ + private StaleMeter makeStaleMeter(InstanceIdentifier identifier, Meter del, + InstanceIdentifier nodeIdent) { StaleMeterBuilder staleMeterBuilder = new StaleMeterBuilder(del); return staleMeterBuilder.setMeterId(del.getMeterId()).build(); } - private void persistStaleMeter(StaleMeter staleMeter, InstanceIdentifier nodeIdent){ + private void persistStaleMeter(StaleMeter staleMeter, InstanceIdentifier nodeIdent) { WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction(); - writeTransaction.put(LogicalDatastoreType.CONFIGURATION, getStaleMeterInstanceIdentifier(staleMeter, nodeIdent), staleMeter, false); + writeTransaction.put(LogicalDatastoreType.CONFIGURATION, getStaleMeterInstanceIdentifier(staleMeter, nodeIdent), + staleMeter, false); CheckedFuture submitFuture = writeTransaction.submit(); handleStaleMeterResultFuture(submitFuture); - } - private void handleStaleMeterResultFuture(CheckedFuture submitFuture){ + private void handleStaleMeterResultFuture(CheckedFuture submitFuture) { Futures.addCallback(submitFuture, new FutureCallback() { @Override public void onSuccess(Void result) { @@ -183,19 +174,17 @@ public class MeterForwarder extends AbstractListeningCommiter { } @Override - public void onFailure(Throwable t) { - LOG.error("Stale Meter creation failed {}", t); + public void onFailure(Throwable throwable) { + LOG.error("Stale Meter creation failed {}", throwable); } }); - } - - private InstanceIdentifier getStaleMeterInstanceIdentifier(StaleMeter staleMeter, InstanceIdentifier nodeIdent) { - return nodeIdent - .child(StaleMeter.class, new StaleMeterKey(new MeterId(staleMeter.getMeterId()))); + private InstanceIdentifier getStaleMeterInstanceIdentifier( + StaleMeter staleMeter, InstanceIdentifier nodeIdent) { + return nodeIdent.child(StaleMeter.class, new StaleMeterKey(new MeterId(staleMeter.getMeterId()))); } } - diff --git a/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/TableForwarder.java b/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/TableForwarder.java index 4b25dd618a..2ed93b95ee 100644 --- a/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/TableForwarder.java +++ b/applications/forwardingrules-manager/src/main/java/org/opendaylight/openflowplugin/applications/frm/impl/TableForwarder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -38,15 +38,18 @@ public class TableForwarder extends AbstractListeningCommiter { private static final Logger LOG = LoggerFactory.getLogger(TableForwarder.class); private ListenerRegistration listenerRegistration; + @SuppressWarnings("IllegalCatch") public TableForwarder(final ForwardingRulesManager manager, final DataBroker db) { super(manager, TableFeatures.class); Preconditions.checkNotNull(db, "DataBroker can not be null!"); - final DataTreeIdentifier treeId = new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, getWildCardPath()); + final DataTreeIdentifier treeId = new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, + getWildCardPath()); try { SimpleTaskRetryLooper looper = new SimpleTaskRetryLooper(ForwardingRulesManagerImpl.STARTUP_LOOP_TICK, ForwardingRulesManagerImpl.STARTUP_LOOP_MAX_RETRIES); - listenerRegistration = looper.loopUntilNoException(() -> db.registerDataTreeChangeListener(treeId, TableForwarder.this)); + listenerRegistration = looper + .loopUntilNoException(() -> db.registerDataTreeChangeListener(treeId, TableForwarder.this)); } catch (final Exception e) { LOG.warn("FRM Table DataTreeChangeListener registration fail!"); LOG.debug("FRM Table DataTreeChangeListener registration fail ..", e); @@ -57,70 +60,63 @@ public class TableForwarder extends AbstractListeningCommiter { @Override public void close() { if (listenerRegistration != null) { - try { - listenerRegistration.close(); - } catch (Exception e) { - LOG.warn("Error by stop FRM TableChangeListener: {}", e.getMessage()); - LOG.debug("Error by stop FRM TableChangeListener..", e); - } + listenerRegistration.close(); listenerRegistration = null; } } @Override protected InstanceIdentifier getWildCardPath() { - return InstanceIdentifier.create(Nodes.class).child(Node.class) - .augmentation(FlowCapableNode.class).child(TableFeatures.class); + return InstanceIdentifier.create(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class) + .child(TableFeatures.class); } @Override public void remove(final InstanceIdentifier identifier, final TableFeatures removeDataObj, - final InstanceIdentifier nodeIdent) { + final InstanceIdentifier nodeIdent) { // DO Nothing } @Override - public void update(final InstanceIdentifier identifier, - final TableFeatures original, final TableFeatures update, - final InstanceIdentifier nodeIdent) { - LOG.debug("Received the Table Update request [Tbl id, node Id, original, upd" + - " " + identifier + " " + nodeIdent + " " + original + " " + update); + public void update(final InstanceIdentifier identifier, final TableFeatures original, + final TableFeatures update, final InstanceIdentifier nodeIdent) { + LOG.debug("Received the Table Update request [Tbl id, node Id, original, upd" + " " + identifier + " " + + nodeIdent + " " + original + " " + update); final TableFeatures originalTableFeatures = original; TableFeatures updatedTableFeatures; if (null == update) { updatedTableFeatures = original; - } - else { + } else { updatedTableFeatures = update; } final UpdateTableInputBuilder builder = new UpdateTableInputBuilder(); builder.setNode(new NodeRef(nodeIdent.firstIdentifierOf(Node.class))); - // TODO: reconsider model - this particular field is not used in service implementation + // TODO: reconsider model - this particular field is not used in service + // implementation builder.setTableRef(new TableRef(identifier)); builder.setTransactionUri(new Uri(provider.getNewTransactionId())); - builder.setUpdatedTable(new UpdatedTableBuilder().setTableFeatures( - Collections.singletonList(updatedTableFeatures)).build()); + builder.setUpdatedTable( + new UpdatedTableBuilder().setTableFeatures(Collections.singletonList(updatedTableFeatures)).build()); - builder.setOriginalTable(new OriginalTableBuilder().setTableFeatures( - Collections.singletonList(originalTableFeatures)).build()); + builder.setOriginalTable( + new OriginalTableBuilder().setTableFeatures(Collections.singletonList(originalTableFeatures)).build()); LOG.debug("Invoking SalTableService "); - if (this.provider.getSalTableService() != null) + if (this.provider.getSalTableService() != null) { LOG.debug(" Handle to SalTableServices" + this.provider.getSalTableService()); + } this.provider.getSalTableService().updateTable(builder.build()); } @Override - public Future> add( - final InstanceIdentifier identifier, - final TableFeatures addDataObj, - final InstanceIdentifier nodeIdent) { + public Future> add(final InstanceIdentifier identifier, + final TableFeatures addDataObj, final InstanceIdentifier nodeIdent) { return Futures.immediateFuture(null); } @@ -128,7 +124,6 @@ public class TableForwarder extends AbstractListeningCommiter { public void createStaleMarkEntity(InstanceIdentifier identifier, TableFeatures del, InstanceIdentifier nodeIdent) { LOG.debug("NO-OP"); - } @Override @@ -136,6 +131,4 @@ public class TableForwarder extends AbstractListeningCommiter { TableFeatures del, InstanceIdentifier nodeIdent) { return null; } - - } diff --git a/applications/forwardingrules-manager/src/test/java/org/opendaylight/openflowplugin/applications/frm/impl/DeviceMastershipManagerTest.java b/applications/forwardingrules-manager/src/test/java/org/opendaylight/openflowplugin/applications/frm/impl/DeviceMastershipManagerTest.java index 68b63744bb..b66ed0651d 100644 --- a/applications/forwardingrules-manager/src/test/java/org/opendaylight/openflowplugin/applications/frm/impl/DeviceMastershipManagerTest.java +++ b/applications/forwardingrules-manager/src/test/java/org/opendaylight/openflowplugin/applications/frm/impl/DeviceMastershipManagerTest.java @@ -51,8 +51,8 @@ public class DeviceMastershipManagerTest { @Before public void setUp() throws Exception { - deviceMastershipManager = new DeviceMastershipManager(clusterSingletonService, - notificationService, reconciliationAgent, dataBroker); + deviceMastershipManager = new DeviceMastershipManager(clusterSingletonService, notificationService, + reconciliationAgent, dataBroker); Mockito.when(clusterSingletonService.registerClusterSingletonService(Matchers.any())) .thenReturn(registration); } @@ -69,8 +69,8 @@ public class DeviceMastershipManagerTest { // destroy context - unregister Assert.assertNotNull(deviceMastershipManager.getDeviceMasterships().get(NODE_ID)); NodeRemovedBuilder nodeRemovedBuilder = new NodeRemovedBuilder(); - InstanceIdentifier nodeIId = InstanceIdentifier.create(Nodes.class). - child(Node.class, new NodeKey(NODE_ID)); + InstanceIdentifier nodeIId = InstanceIdentifier.create(Nodes.class).child(Node.class, + new NodeKey(NODE_ID)); nodeRemovedBuilder.setNodeRef(new NodeRef(nodeIId)); deviceMastershipManager.onNodeRemoved(nodeRemovedBuilder.build()); Assert.assertNull(deviceMastershipManager.getDeviceMasterships().get(NODE_ID)); @@ -90,5 +90,4 @@ public class DeviceMastershipManagerTest { deviceMastershipManager.getDeviceMasterships().get(NODE_ID).closeServiceInstance(); Assert.assertFalse(deviceMastershipManager.isDeviceMastered(NODE_ID)); } - -} \ No newline at end of file +} diff --git a/applications/forwardingrules-manager/src/test/java/test/mock/FlowListenerTest.java b/applications/forwardingrules-manager/src/test/java/test/mock/FlowListenerTest.java index 91daacb940..78b26ec8e9 100644 --- a/applications/forwardingrules-manager/src/test/java/test/mock/FlowListenerTest.java +++ b/applications/forwardingrules-manager/src/test/java/test/mock/FlowListenerTest.java @@ -57,8 +57,8 @@ import test.mock.util.SalFlowServiceMock; @RunWith(MockitoJUnitRunner.class) public class FlowListenerTest extends FRMTest { private ForwardingRulesManagerImpl forwardingRulesManager; - private final static NodeId NODE_ID = new NodeId("testnode:1"); - private final static NodeKey s1Key = new NodeKey(NODE_ID); + private static final NodeId NODE_ID = new NodeId("testnode:1"); + private static final NodeKey NODE_KEY = new NodeKey(NODE_ID); RpcProviderRegistry rpcProviderRegistryMock = new RpcProviderRegistryMock(); TableKey tableKey = new TableKey((short) 2); @Mock @@ -72,14 +72,8 @@ public class FlowListenerTest extends FRMTest { @Before public void setUp() { - forwardingRulesManager = new ForwardingRulesManagerImpl( - getDataBroker(), - rpcProviderRegistryMock, - getConfig(), - clusterSingletonService, - notificationService, - getConfigurationService(), - reconciliationManager); + forwardingRulesManager = new ForwardingRulesManagerImpl(getDataBroker(), rpcProviderRegistryMock, getConfig(), + clusterSingletonService, notificationService, getConfigurationService(), reconciliationManager); forwardingRulesManager.start(); // TODO consider tests rewrite (added because of complicated access) @@ -89,12 +83,12 @@ public class FlowListenerTest extends FRMTest { @Test public void addTwoFlowsTest() throws Exception { - addFlowCapableNode(s1Key); + addFlowCapableNode(NODE_KEY); FlowKey flowKey = new FlowKey(new FlowId("test_Flow")); - InstanceIdentifier

tableII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key) + InstanceIdentifier
tableII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY) .augmentation(FlowCapableNode.class).child(Table.class, tableKey); - InstanceIdentifier flowII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key) + InstanceIdentifier flowII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY) .augmentation(FlowCapableNode.class).child(Table.class, tableKey).child(Flow.class, flowKey); Table table = new TableBuilder().setKey(tableKey).setFlow(Collections.emptyList()).build(); Flow flow = new FlowBuilder().setKey(flowKey).setTableId((short) 2).build(); @@ -109,8 +103,8 @@ public class FlowListenerTest extends FRMTest { assertEquals("DOM-0", addFlowCalls.get(0).getTransactionUri().getValue()); flowKey = new FlowKey(new FlowId("test_Flow2")); - flowII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key) - .augmentation(FlowCapableNode.class).child(Table.class, tableKey).child(Flow.class, flowKey); + flowII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY).augmentation(FlowCapableNode.class) + .child(Table.class, tableKey).child(Flow.class, flowKey); flow = new FlowBuilder().setKey(flowKey).setTableId((short) 2).build(); writeTx = getDataBroker().newWriteOnlyTransaction(); writeTx.put(LogicalDatastoreType.CONFIGURATION, flowII, flow); @@ -121,16 +115,16 @@ public class FlowListenerTest extends FRMTest { assertEquals("DOM-1", addFlowCalls.get(1).getTransactionUri().getValue()); assertEquals(2, addFlowCalls.get(1).getTableId().intValue()); assertEquals(flowII, addFlowCalls.get(1).getFlowRef().getValue()); -} + } @Test public void updateFlowTest() throws Exception { - addFlowCapableNode(s1Key); + addFlowCapableNode(NODE_KEY); FlowKey flowKey = new FlowKey(new FlowId("test_Flow")); - InstanceIdentifier
tableII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key) + InstanceIdentifier
tableII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY) .augmentation(FlowCapableNode.class).child(Table.class, tableKey); - InstanceIdentifier flowII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key) + InstanceIdentifier flowII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY) .augmentation(FlowCapableNode.class).child(Table.class, tableKey).child(Flow.class, flowKey); Table table = new TableBuilder().setKey(tableKey).setFlow(Collections.emptyList()).build(); Flow flow = new FlowBuilder().setKey(flowKey).setTableId((short) 2).build(); @@ -145,8 +139,8 @@ public class FlowListenerTest extends FRMTest { assertEquals("DOM-0", addFlowCalls.get(0).getTransactionUri().getValue()); flowKey = new FlowKey(new FlowId("test_Flow")); - flowII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key) - .augmentation(FlowCapableNode.class).child(Table.class, tableKey).child(Flow.class, flowKey); + flowII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY).augmentation(FlowCapableNode.class) + .child(Table.class, tableKey).child(Flow.class, flowKey); flow = new FlowBuilder().setKey(flowKey).setTableId((short) 2).setOutGroup((long) 5).build(); writeTx = getDataBroker().newWriteOnlyTransaction(); writeTx.put(LogicalDatastoreType.CONFIGURATION, flowII, flow); @@ -162,15 +156,15 @@ public class FlowListenerTest extends FRMTest { @Test public void updateFlowScopeTest() throws Exception { - addFlowCapableNode(s1Key); + addFlowCapableNode(NODE_KEY); FlowKey flowKey = new FlowKey(new FlowId("test_Flow")); - InstanceIdentifier
tableII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key) + InstanceIdentifier
tableII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY) .augmentation(FlowCapableNode.class).child(Table.class, tableKey); - InstanceIdentifier flowII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key) + InstanceIdentifier flowII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY) .augmentation(FlowCapableNode.class).child(Table.class, tableKey).child(Flow.class, flowKey); Table table = new TableBuilder().setKey(tableKey).setFlow(Collections.emptyList()).build(); - IpMatch ipMatch = new IpMatchBuilder().setIpDscp(new Dscp((short)4)).build(); + IpMatch ipMatch = new IpMatchBuilder().setIpDscp(new Dscp((short) 4)).build(); Match match = new MatchBuilder().setIpMatch(ipMatch).build(); Flow flow = new FlowBuilder().setMatch(match).setKey(flowKey).setTableId((short) 2).build(); @@ -184,9 +178,9 @@ public class FlowListenerTest extends FRMTest { assertEquals("DOM-0", addFlowCalls.get(0).getTransactionUri().getValue()); flowKey = new FlowKey(new FlowId("test_Flow")); - flowII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key) - .augmentation(FlowCapableNode.class).child(Table.class, tableKey).child(Flow.class, flowKey); - ipMatch = new IpMatchBuilder().setIpDscp(new Dscp((short)5)).build(); + flowII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY).augmentation(FlowCapableNode.class) + .child(Table.class, tableKey).child(Flow.class, flowKey); + ipMatch = new IpMatchBuilder().setIpDscp(new Dscp((short) 5)).build(); match = new MatchBuilder().setIpMatch(ipMatch).build(); flow = new FlowBuilder().setMatch(match).setKey(flowKey).setTableId((short) 2).build(); writeTx = getDataBroker().newWriteOnlyTransaction(); @@ -202,12 +196,12 @@ public class FlowListenerTest extends FRMTest { @Test public void deleteFlowTest() throws Exception { - addFlowCapableNode(s1Key); + addFlowCapableNode(NODE_KEY); FlowKey flowKey = new FlowKey(new FlowId("test_Flow")); - InstanceIdentifier
tableII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key) + InstanceIdentifier
tableII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY) .augmentation(FlowCapableNode.class).child(Table.class, tableKey); - InstanceIdentifier flowII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key) + InstanceIdentifier flowII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY) .augmentation(FlowCapableNode.class).child(Table.class, tableKey).child(Flow.class, flowKey); Table table = new TableBuilder().setKey(tableKey).setFlow(Collections.emptyList()).build(); Flow flow = new FlowBuilder().setKey(flowKey).setTableId((short) 2).build(); @@ -232,16 +226,15 @@ public class FlowListenerTest extends FRMTest { assertEquals(Boolean.TRUE, removeFlowCalls.get(0).isStrict()); } - @Test - public void staleMarkedFlowCreationTest() throws Exception{ + public void staleMarkedFlowCreationTest() throws Exception { - addFlowCapableNode(s1Key); + addFlowCapableNode(NODE_KEY); StaleFlowKey flowKey = new StaleFlowKey(new FlowId("stale_Flow")); - InstanceIdentifier
tableII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key) + InstanceIdentifier
tableII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY) .augmentation(FlowCapableNode.class).child(Table.class, tableKey); - InstanceIdentifier flowII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key) + InstanceIdentifier flowII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY) .augmentation(FlowCapableNode.class).child(Table.class, tableKey).child(StaleFlow.class, flowKey); Table table = new TableBuilder().setKey(tableKey).setStaleFlow(Collections.emptyList()).build(); StaleFlow flow = new StaleFlowBuilder().setKey(flowKey).setTableId((short) 2).build(); @@ -256,5 +249,4 @@ public class FlowListenerTest extends FRMTest { public void tearDown() throws Exception { forwardingRulesManager.close(); } - } diff --git a/applications/forwardingrules-manager/src/test/java/test/mock/GroupListenerTest.java b/applications/forwardingrules-manager/src/test/java/test/mock/GroupListenerTest.java index 2da1b844b9..4a6bc51e6a 100644 --- a/applications/forwardingrules-manager/src/test/java/test/mock/GroupListenerTest.java +++ b/applications/forwardingrules-manager/src/test/java/test/mock/GroupListenerTest.java @@ -48,8 +48,8 @@ import test.mock.util.SalGroupServiceMock; @RunWith(MockitoJUnitRunner.class) public class GroupListenerTest extends FRMTest { private ForwardingRulesManagerImpl forwardingRulesManager; - private final static NodeId NODE_ID = new NodeId("testnode:1"); - private final static NodeKey s1Key = new NodeKey(NODE_ID); + private static final NodeId NODE_ID = new NodeId("testnode:1"); + private static final NodeKey NODE_KEY = new NodeKey(NODE_ID); RpcProviderRegistry rpcProviderRegistryMock = new RpcProviderRegistryMock(); @Mock ClusterSingletonServiceProvider clusterSingletonService; @@ -80,10 +80,10 @@ public class GroupListenerTest extends FRMTest { @Test public void addTwoGroupsTest() throws Exception { - addFlowCapableNode(s1Key); + addFlowCapableNode(NODE_KEY); GroupKey groupKey = new GroupKey(new GroupId((long) 255)); - InstanceIdentifier groupII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key) + InstanceIdentifier groupII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY) .augmentation(FlowCapableNode.class).child(Group.class, groupKey); Group group = new GroupBuilder().setKey(groupKey).setGroupName("Group1").build(); @@ -96,7 +96,7 @@ public class GroupListenerTest extends FRMTest { assertEquals("DOM-0", addGroupCalls.get(0).getTransactionUri().getValue()); groupKey = new GroupKey(new GroupId((long) 256)); - groupII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key) + groupII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY) .augmentation(FlowCapableNode.class).child(Group.class, groupKey); group = new GroupBuilder().setKey(groupKey).setGroupName("Group1").build(); writeTx = getDataBroker().newWriteOnlyTransaction(); @@ -110,10 +110,10 @@ public class GroupListenerTest extends FRMTest { @Test public void updateGroupTest() throws Exception { - addFlowCapableNode(s1Key); + addFlowCapableNode(NODE_KEY); GroupKey groupKey = new GroupKey(new GroupId((long) 255)); - InstanceIdentifier groupII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key) + InstanceIdentifier groupII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY) .augmentation(FlowCapableNode.class).child(Group.class, groupKey); Group group = new GroupBuilder().setKey(groupKey).setGroupName("Group1").build(); @@ -137,10 +137,10 @@ public class GroupListenerTest extends FRMTest { @Test public void removeGroupTest() throws Exception { - addFlowCapableNode(s1Key); + addFlowCapableNode(NODE_KEY); GroupKey groupKey = new GroupKey(new GroupId((long) 255)); - InstanceIdentifier groupII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key) + InstanceIdentifier groupII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY) .augmentation(FlowCapableNode.class).child(Group.class, groupKey); Group group = new GroupBuilder().setKey(groupKey).setGroupName("Group1").build(); @@ -163,10 +163,10 @@ public class GroupListenerTest extends FRMTest { @Test public void staleGroupCreationTest() throws Exception { - addFlowCapableNode(s1Key); + addFlowCapableNode(NODE_KEY); StaleGroupKey groupKey = new StaleGroupKey(new GroupId((long) 255)); - InstanceIdentifier groupII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key) + InstanceIdentifier groupII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY) .augmentation(FlowCapableNode.class).child(StaleGroup.class, groupKey); StaleGroup group = new StaleGroupBuilder().setKey(groupKey).setGroupName("Stale_Group1").build(); @@ -179,5 +179,4 @@ public class GroupListenerTest extends FRMTest { public void tearDown() throws Exception { forwardingRulesManager.close(); } - } diff --git a/applications/forwardingrules-manager/src/test/java/test/mock/MeterListenerTest.java b/applications/forwardingrules-manager/src/test/java/test/mock/MeterListenerTest.java index d5f1351e9c..12a88c4104 100644 --- a/applications/forwardingrules-manager/src/test/java/test/mock/MeterListenerTest.java +++ b/applications/forwardingrules-manager/src/test/java/test/mock/MeterListenerTest.java @@ -48,8 +48,8 @@ import test.mock.util.SalMeterServiceMock; @RunWith(MockitoJUnitRunner.class) public class MeterListenerTest extends FRMTest { private ForwardingRulesManagerImpl forwardingRulesManager; - private final static NodeId NODE_ID = new NodeId("testnode:1"); - private final static NodeKey s1Key = new NodeKey(NODE_ID); + private static final NodeId NODE_ID = new NodeId("testnode:1"); + private static final NodeKey NODE_KEY = new NodeKey(NODE_ID); RpcProviderRegistry rpcProviderRegistryMock = new RpcProviderRegistryMock(); @Mock ClusterSingletonServiceProvider clusterSingletonService; @@ -60,7 +60,6 @@ public class MeterListenerTest extends FRMTest { @Mock private ReconciliationManager reconciliationManager; - @Before public void setUp() { forwardingRulesManager = new ForwardingRulesManagerImpl( @@ -80,10 +79,10 @@ public class MeterListenerTest extends FRMTest { @Test public void addTwoMetersTest() throws Exception { - addFlowCapableNode(s1Key); + addFlowCapableNode(NODE_KEY); MeterKey meterKey = new MeterKey(new MeterId((long) 2000)); - InstanceIdentifier meterII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key) + InstanceIdentifier meterII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY) .augmentation(FlowCapableNode.class).child(Meter.class, meterKey); Meter meter = new MeterBuilder().setKey(meterKey).setMeterName("meter_one").build(); @@ -96,7 +95,7 @@ public class MeterListenerTest extends FRMTest { assertEquals("DOM-0", addMeterCalls.get(0).getTransactionUri().getValue()); meterKey = new MeterKey(new MeterId((long) 2001)); - meterII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key) + meterII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY) .augmentation(FlowCapableNode.class).child(Meter.class, meterKey); meter = new MeterBuilder().setKey(meterKey).setMeterName("meter_two").setBarrier(true).build(); writeTx = getDataBroker().newWriteOnlyTransaction(); @@ -111,10 +110,10 @@ public class MeterListenerTest extends FRMTest { @Test public void updateMeterTest() throws Exception { - addFlowCapableNode(s1Key); + addFlowCapableNode(NODE_KEY); MeterKey meterKey = new MeterKey(new MeterId((long) 2000)); - InstanceIdentifier meterII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key) + InstanceIdentifier meterII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY) .augmentation(FlowCapableNode.class).child(Meter.class, meterKey); Meter meter = new MeterBuilder().setKey(meterKey).setMeterName("meter_one").setBarrier(false).build(); @@ -139,10 +138,10 @@ public class MeterListenerTest extends FRMTest { @Test public void removeMeterTest() throws Exception { - addFlowCapableNode(s1Key); + addFlowCapableNode(NODE_KEY); MeterKey meterKey = new MeterKey(new MeterId((long) 2000)); - InstanceIdentifier meterII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key) + InstanceIdentifier meterII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY) .augmentation(FlowCapableNode.class).child(Meter.class, meterKey); Meter meter = new MeterBuilder().setKey(meterKey).setMeterName("meter_one").build(); @@ -164,13 +163,12 @@ public class MeterListenerTest extends FRMTest { assertEquals(meterII, removeMeterCalls.get(0).getMeterRef().getValue()); } - @Test public void staleMeterCreationTest() throws Exception { - addFlowCapableNode(s1Key); + addFlowCapableNode(NODE_KEY); StaleMeterKey meterKey = new StaleMeterKey(new MeterId((long) 2000)); - InstanceIdentifier meterII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key) + InstanceIdentifier meterII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY) .augmentation(FlowCapableNode.class).child(StaleMeter.class, meterKey); StaleMeter meter = new StaleMeterBuilder().setKey(meterKey).setMeterName("stale_meter_one").build(); @@ -183,5 +181,4 @@ public class MeterListenerTest extends FRMTest { public void tearDown() throws Exception { forwardingRulesManager.close(); } - } diff --git a/applications/forwardingrules-manager/src/test/java/test/mock/NodeListenerTest.java b/applications/forwardingrules-manager/src/test/java/test/mock/NodeListenerTest.java index 76d4debf05..3dcb631ee1 100644 --- a/applications/forwardingrules-manager/src/test/java/test/mock/NodeListenerTest.java +++ b/applications/forwardingrules-manager/src/test/java/test/mock/NodeListenerTest.java @@ -33,7 +33,7 @@ import test.mock.util.RpcProviderRegistryMock; @RunWith(MockitoJUnitRunner.class) public class NodeListenerTest extends FRMTest { private ForwardingRulesManagerImpl forwardingRulesManager; - private final static NodeKey s1Key = new NodeKey(new NodeId("testnode:1")); + private static final NodeKey NODE_KEY = new NodeKey(new NodeId("testnode:1")); RpcProviderRegistry rpcProviderRegistryMock = new RpcProviderRegistryMock(); @Mock ClusterSingletonServiceProvider clusterSingletonService; @@ -59,13 +59,13 @@ public class NodeListenerTest extends FRMTest { @Test public void addRemoveNodeTest() throws Exception { - addFlowCapableNode(s1Key); + addFlowCapableNode(NODE_KEY); - InstanceIdentifier nodeII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key) + InstanceIdentifier nodeII = InstanceIdentifier.create(Nodes.class).child(Node.class, NODE_KEY) .augmentation(FlowCapableNode.class); boolean nodeActive = forwardingRulesManager.isNodeActive(nodeII); assertTrue(nodeActive); - removeNode(s1Key); + removeNode(NODE_KEY); nodeActive = forwardingRulesManager.isNodeActive(nodeII); assertFalse(nodeActive); } @@ -74,5 +74,4 @@ public class NodeListenerTest extends FRMTest { public void tearDown() throws Exception { forwardingRulesManager.close(); } - } diff --git a/applications/forwardingrules-manager/src/test/java/test/mock/TableFeaturesListenerTest.java b/applications/forwardingrules-manager/src/test/java/test/mock/TableFeaturesListenerTest.java index 0d4f033291..ddaa0e68a8 100644 --- a/applications/forwardingrules-manager/src/test/java/test/mock/TableFeaturesListenerTest.java +++ b/applications/forwardingrules-manager/src/test/java/test/mock/TableFeaturesListenerTest.java @@ -43,8 +43,8 @@ import test.mock.util.SalTableServiceMock; @RunWith(MockitoJUnitRunner.class) public class TableFeaturesListenerTest extends FRMTest { private ForwardingRulesManagerImpl forwardingRulesManager; - private final static NodeId NODE_ID = new NodeId("testnode:1"); - private final static NodeKey s1Key = new NodeKey(NODE_ID); + private static final NodeId NODE_ID = new NodeId("testnode:1"); + private static final NodeKey NODE_KEY = new NodeKey(NODE_ID); RpcProviderRegistry rpcProviderRegistryMock = new RpcProviderRegistryMock(); @Mock ClusterSingletonServiceProvider clusterSingletonService; @@ -55,17 +55,10 @@ public class TableFeaturesListenerTest extends FRMTest { @Mock private ReconciliationManager reconciliationManager; - @Before public void setUp() { - forwardingRulesManager = new ForwardingRulesManagerImpl( - getDataBroker(), - rpcProviderRegistryMock, - getConfig(), - clusterSingletonService, - notificationService, - getConfigurationService(), - reconciliationManager); + forwardingRulesManager = new ForwardingRulesManagerImpl(getDataBroker(), rpcProviderRegistryMock, getConfig(), + clusterSingletonService, notificationService, getConfigurationService(), reconciliationManager); forwardingRulesManager.start(); // TODO consider tests rewrite (added because of complicated access) @@ -78,11 +71,12 @@ public class TableFeaturesListenerTest extends FRMTest { TableKey tableKey = new TableKey((short) 2); TableFeaturesKey tableFeaturesKey = new TableFeaturesKey(tableKey.getId()); - addTable(tableKey, s1Key); + addTable(tableKey, NODE_KEY); TableFeatures tableFeaturesData = new TableFeaturesBuilder().setKey(tableFeaturesKey).build(); - InstanceIdentifier tableFeaturesII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key) - .augmentation(FlowCapableNode.class).child(TableFeatures.class, tableFeaturesKey); + InstanceIdentifier tableFeaturesII = InstanceIdentifier.create(Nodes.class) + .child(Node.class, NODE_KEY).augmentation(FlowCapableNode.class) + .child(TableFeatures.class, tableFeaturesKey); WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction(); writeTx.put(LogicalDatastoreType.CONFIGURATION, tableFeaturesII, tableFeaturesData); assertCommit(writeTx.submit()); @@ -102,5 +96,4 @@ public class TableFeaturesListenerTest extends FRMTest { public void tearDown() throws Exception { forwardingRulesManager.close(); } - } diff --git a/applications/forwardingrules-manager/src/test/java/test/mock/util/FRMTest.java b/applications/forwardingrules-manager/src/test/java/test/mock/util/FRMTest.java index a81201368d..8156b1a67c 100644 --- a/applications/forwardingrules-manager/src/test/java/test/mock/util/FRMTest.java +++ b/applications/forwardingrules-manager/src/test/java/test/mock/util/FRMTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2016 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2014, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -33,8 +33,6 @@ public abstract class FRMTest extends AbstractDataBrokerTest { public void addFlowCapableNode(NodeKey nodeKey) { Nodes nodes = new NodesBuilder().setNode(Collections.emptyList()).build(); - InstanceIdentifier flowNodeIdentifier = InstanceIdentifier.create(Nodes.class) - .child(Node.class, nodeKey); FlowCapableNodeBuilder fcnBuilder = new FlowCapableNodeBuilder(); NodeBuilder nodeBuilder = new NodeBuilder(); @@ -43,6 +41,8 @@ public abstract class FRMTest extends AbstractDataBrokerTest { WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction(); writeTx.put(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(Nodes.class), nodes); + + InstanceIdentifier flowNodeIdentifier = InstanceIdentifier.create(Nodes.class).child(Node.class, nodeKey); writeTx.put(LogicalDatastoreType.OPERATIONAL, flowNodeIdentifier, nodeBuilder.build()); writeTx.put(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(Nodes.class), nodes); writeTx.put(LogicalDatastoreType.CONFIGURATION, flowNodeIdentifier, nodeBuilder.build()); @@ -51,7 +51,8 @@ public abstract class FRMTest extends AbstractDataBrokerTest { public void removeNode(NodeKey nodeKey) throws ExecutionException, InterruptedException { WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction(); - writeTx.delete(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(Nodes.class).child(Node.class, nodeKey)); + writeTx.delete(LogicalDatastoreType.OPERATIONAL, + InstanceIdentifier.create(Nodes.class).child(Node.class, nodeKey)); writeTx.submit().get(); } @@ -78,7 +79,8 @@ public abstract class FRMTest extends AbstractDataBrokerTest { final ConfigurationService configurationService = Mockito.mock(ConfigurationService.class); final ForwardingRulesManagerConfig config = getConfig(); - Mockito.when(configurationService.registerListener(Mockito.any())).thenReturn(() -> {}); + Mockito.when(configurationService.registerListener(Mockito.any())).thenReturn(() -> { + }); Mockito.when(configurationService.getProperty(Mockito.eq("disable-reconciliation"), Mockito.any())) .thenReturn(config.isDisableReconciliation()); @@ -94,5 +96,4 @@ public abstract class FRMTest extends AbstractDataBrokerTest { return configurationService; } - } diff --git a/applications/forwardingrules-manager/src/test/java/test/mock/util/RpcProviderRegistryMock.java b/applications/forwardingrules-manager/src/test/java/test/mock/util/RpcProviderRegistryMock.java index 40a466b808..b57858ea0f 100644 --- a/applications/forwardingrules-manager/src/test/java/test/mock/util/RpcProviderRegistryMock.java +++ b/applications/forwardingrules-manager/src/test/java/test/mock/util/RpcProviderRegistryMock.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2016 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2014, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -7,9 +7,6 @@ */ package test.mock.util; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.SalBundleService; -import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.SalTableService; - import org.opendaylight.controller.md.sal.common.api.routing.RouteChangeListener; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; @@ -17,23 +14,29 @@ import org.opendaylight.controller.sal.binding.api.rpc.RpcContextIdentifier; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.SalGroupService; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.SalMeterService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.SalBundleService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.SalTableService; import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.RpcService; public class RpcProviderRegistryMock implements RpcProviderRegistry { @Override - public BindingAwareBroker.RpcRegistration addRpcImplementation(Class serviceInterface, T implementation) throws IllegalStateException { + public BindingAwareBroker.RpcRegistration addRpcImplementation(Class serviceInterface, + T implementation) throws IllegalStateException { return null; } @Override - public BindingAwareBroker.RoutedRpcRegistration addRoutedRpcImplementation(Class serviceInterface, T implementation) throws IllegalStateException { + public BindingAwareBroker.RoutedRpcRegistration addRoutedRpcImplementation( + Class serviceInterface, T implementation) throws IllegalStateException { return null; } @Override - public >> ListenerRegistration registerRouteChangeListener(L listener) { + public >> ListenerRegistration registerRouteChangeListener( + L listener) { return null; } diff --git a/applications/forwardingrules-manager/src/test/java/test/mock/util/SalBundleServiceMock.java b/applications/forwardingrules-manager/src/test/java/test/mock/util/SalBundleServiceMock.java index 2445d56ddc..66013b1b81 100644 --- a/applications/forwardingrules-manager/src/test/java/test/mock/util/SalBundleServiceMock.java +++ b/applications/forwardingrules-manager/src/test/java/test/mock/util/SalBundleServiceMock.java @@ -22,7 +22,6 @@ public class SalBundleServiceMock implements SalBundleService { private final List controlBundleInput = new ArrayList<>(); private final List addBundleMessagesInput = new ArrayList<>(); - @Override public Future> controlBundle(ControlBundleInput input) { getControlBundleInput().add(input); @@ -42,6 +41,4 @@ public class SalBundleServiceMock implements SalBundleService { public List getAddBundleMessagesInput() { return addBundleMessagesInput; } - - } diff --git a/applications/forwardingrules-manager/src/test/java/test/mock/util/SalFlowServiceMock.java b/applications/forwardingrules-manager/src/test/java/test/mock/util/SalFlowServiceMock.java index 1e4f8f07d1..63062df3dc 100644 --- a/applications/forwardingrules-manager/src/test/java/test/mock/util/SalFlowServiceMock.java +++ b/applications/forwardingrules-manager/src/test/java/test/mock/util/SalFlowServiceMock.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2016 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2014, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -7,6 +7,9 @@ */ package test.mock.util; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Future; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInput; @@ -16,14 +19,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.Upda import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput; import org.opendaylight.yangtools.yang.common.RpcResult; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.Future; - -public class SalFlowServiceMock implements SalFlowService{ - private List addFlowCalls = new ArrayList<>(); - private List removeFlowCalls = new ArrayList<>(); - private List updateFlowCalls = new ArrayList<>(); +public class SalFlowServiceMock implements SalFlowService { + private final List addFlowCalls = new ArrayList<>(); + private final List removeFlowCalls = new ArrayList<>(); + private final List updateFlowCalls = new ArrayList<>(); @Override public Future> addFlow(AddFlowInput input) { @@ -31,7 +30,6 @@ public class SalFlowServiceMock implements SalFlowService{ return null; } - @Override public Future> removeFlow(RemoveFlowInput input) { removeFlowCalls.add(input); diff --git a/applications/forwardingrules-manager/src/test/java/test/mock/util/SalGroupServiceMock.java b/applications/forwardingrules-manager/src/test/java/test/mock/util/SalGroupServiceMock.java index 08319b029b..958285d511 100644 --- a/applications/forwardingrules-manager/src/test/java/test/mock/util/SalGroupServiceMock.java +++ b/applications/forwardingrules-manager/src/test/java/test/mock/util/SalGroupServiceMock.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2016 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2014, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -7,6 +7,9 @@ */ package test.mock.util; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Future; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput; @@ -16,14 +19,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.Upd import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutput; import org.opendaylight.yangtools.yang.common.RpcResult; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.Future; - public class SalGroupServiceMock implements SalGroupService { - private List addGroupCalls = new ArrayList<>(); - private List removeGroupCalls = new ArrayList<>(); - private List updateGroupCalls = new ArrayList<>(); + private final List addGroupCalls = new ArrayList<>(); + private final List removeGroupCalls = new ArrayList<>(); + private final List updateGroupCalls = new ArrayList<>(); @Override public Future> addGroup(AddGroupInput input) { diff --git a/applications/forwardingrules-manager/src/test/java/test/mock/util/SalMeterServiceMock.java b/applications/forwardingrules-manager/src/test/java/test/mock/util/SalMeterServiceMock.java index c7a27c10b0..42dd312314 100644 --- a/applications/forwardingrules-manager/src/test/java/test/mock/util/SalMeterServiceMock.java +++ b/applications/forwardingrules-manager/src/test/java/test/mock/util/SalMeterServiceMock.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2016 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2014, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -7,6 +7,9 @@ */ package test.mock.util; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Future; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInput; @@ -16,14 +19,10 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.Upd import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput; import org.opendaylight.yangtools.yang.common.RpcResult; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.Future; - public class SalMeterServiceMock implements SalMeterService { - private List addMeterCalls = new ArrayList<>(); - private List removeMeterCalls = new ArrayList<>(); - private List updateMeterCalls = new ArrayList<>(); + private final List addMeterCalls = new ArrayList<>(); + private final List removeMeterCalls = new ArrayList<>(); + private final List updateMeterCalls = new ArrayList<>(); @Override public Future> addMeter(AddMeterInput input) { diff --git a/applications/forwardingrules-manager/src/test/java/test/mock/util/SalTableServiceMock.java b/applications/forwardingrules-manager/src/test/java/test/mock/util/SalTableServiceMock.java index c8e9e5cdcb..ced07fc235 100644 --- a/applications/forwardingrules-manager/src/test/java/test/mock/util/SalTableServiceMock.java +++ b/applications/forwardingrules-manager/src/test/java/test/mock/util/SalTableServiceMock.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2016 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2014, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -7,18 +7,16 @@ */ package test.mock.util; -import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput; -import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput; - -import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.SalTableService; -import org.opendaylight.yangtools.yang.common.RpcResult; import java.util.ArrayList; import java.util.List; import java.util.concurrent.Future; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.SalTableService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput; +import org.opendaylight.yangtools.yang.common.RpcResult; public class SalTableServiceMock implements SalTableService { - private List updateTableInput = new ArrayList<>(); - + private final List updateTableInput = new ArrayList<>(); public List getUpdateTableInput() { return updateTableInput; -- 2.36.6