From c7d114768fd36ac88988f9a85387f10f6dd756a5 Mon Sep 17 00:00:00 2001 From: Sam Hague Date: Tue, 5 May 2015 08:07:03 -0400 Subject: [PATCH] Remove FlowCapableNodeDataChangeListener Change-Id: I737cef9874c5ac15a2805d2e4b08aba5b371c1d6 Signed-off-by: Sam Hague --- .../FlowCapableNodeDataChangeListener.java | 177 ------------------ .../openflow13/MdsalConsumerImpl.java | 8 - ...FlowCapableNodeDataChangeListenerTest.java | 151 --------------- .../openflow13/MdsalConsumerImplTest.java | 31 +-- 4 files changed, 1 insertion(+), 366 deletions(-) delete mode 100644 openstack/net-virt-providers/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/providers/openflow13/FlowCapableNodeDataChangeListener.java delete mode 100644 openstack/net-virt-providers/src/test/java/org/opendaylight/ovsdb/openstack/netvirt/providers/openflow13/FlowCapableNodeDataChangeListenerTest.java diff --git a/openstack/net-virt-providers/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/providers/openflow13/FlowCapableNodeDataChangeListener.java b/openstack/net-virt-providers/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/providers/openflow13/FlowCapableNodeDataChangeListener.java deleted file mode 100644 index 7edaca02b..000000000 --- a/openstack/net-virt-providers/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/providers/openflow13/FlowCapableNodeDataChangeListener.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright (C) 2015 Red Hat, Inc. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - * - * Authors : Sam Hague - */ -package org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13; - -import com.google.common.collect.Lists; -import java.util.List; -import java.util.Map; - -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.DataChangeListener; -import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker; -import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.ovsdb.openstack.netvirt.api.Action; -import org.opendaylight.ovsdb.openstack.netvirt.api.NetworkingProviderManager; -import org.opendaylight.ovsdb.openstack.netvirt.api.NodeCacheManager; -import org.opendaylight.ovsdb.utils.mdsal.node.NodeUtils; -import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; -import org.opendaylight.yangtools.concepts.ListenerRegistration; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class FlowCapableNodeDataChangeListener implements DataChangeListener, AutoCloseable { - private static final Logger LOG = LoggerFactory.getLogger(FlowCapableNodeDataChangeListener.class); - private ListenerRegistration registration; - private final Object nodeCacheLock = new Object(); - private List nodeCache = Lists.newArrayList(); - private PipelineOrchestrator pipelineOrchestrator = null; - private NodeCacheManager nodeCacheManager = null; - - public static final InstanceIdentifier createFlowCapableNodePath () { - return InstanceIdentifier.builder(Nodes.class) - .child(Node.class) - .augmentation(FlowCapableNode.class) - .build(); - } - - public FlowCapableNodeDataChangeListener (DataBroker dataBroker) { - LOG.info("Registering FlowCapableNodeChangeListener"); - registration = dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, - createFlowCapableNodePath(), this, AsyncDataBroker.DataChangeScope.BASE); - } - - @Override - public void close () throws Exception { - registration.close(); - } - - @Override - public void onDataChanged (AsyncDataChangeEvent, DataObject> changes) { - LOG.debug(">>>> onDataChanged: {}", changes); - checkMemberInitialization(); - - for (InstanceIdentifier instanceIdentifier : changes.getRemovedPaths()) { - DataObject originalDataObject = changes.getOriginalData().get(instanceIdentifier); - if (originalDataObject instanceof Node) { - Node node = (Node) originalDataObject; - String openflowId = node.getId().getValue(); - LOG.info(">>>>> removed iiD: {} - NodeKey: {}", instanceIdentifier, openflowId); - Node openFlowNode = NodeUtils.getOpenFlowNode(openflowId); - if (removeNodeFromCache(openFlowNode)) { - notifyNodeRemoved(openFlowNode); - } - } - } - - for (Map.Entry, DataObject> created : changes.getCreatedData().entrySet()) { - InstanceIdentifier iID = created.getKey(); - String openflowId = iID.firstKeyOf(Node.class, NodeKey.class).getId().getValue(); - LOG.info(">>>>> created iiD: {} - first: {} - NodeKey: {}", - iID, iID.firstIdentifierOf(Node.class), openflowId); - Node openFlowNode = NodeUtils.getOpenFlowNode(openflowId); - if (addNodeToCache(openFlowNode)) { - notifyNodeCreated(openFlowNode); - } else { - notifyNodeUpdated(openFlowNode); - } - } - - for (Map.Entry, DataObject> updated : changes.getUpdatedData().entrySet()) { - InstanceIdentifier iID = updated.getKey(); - String openflowId = iID.firstKeyOf(Node.class, NodeKey.class).getId().getValue(); - LOG.info(">>>>> updated iiD: {} - first: {} - NodeKey: {}", - iID, iID.firstIdentifierOf(Node.class), openflowId); - Node openFlowNode = NodeUtils.getOpenFlowNode(openflowId); - if (addNodeToCache(openFlowNode)) { - notifyNodeCreated(openFlowNode); - } else { - notifyNodeUpdated(openFlowNode); - } - } - } - - /** - * This method returns the true if node was added to the nodeCache. If param node - * is already in the cache, this method is expected to return false. - * - * @param openFlowNode the node to be added to the cache, if needed - * @return whether new node entry was added to cache - */ - private Boolean addNodeToCache (Node openFlowNode) { - synchronized (nodeCacheLock) { - if (nodeCache.contains(openFlowNode)) { - return false; - } - return nodeCache.add(openFlowNode); - } - } - - /** - * This method returns the true if node was removed from the nodeCache. If param node - * is not in the cache, this method is expected to return false. - * - * @param openFlowNode the node to be removed from the cache, if needed - * @return whether new node entry was removed from cache - */ - private Boolean removeNodeFromCache (Node openFlowNode) { - synchronized (nodeCacheLock) { - return nodeCache.remove(openFlowNode); - } - } - - private void notifyNodeUpdated (Node openFlowNode) { - final String openflowId = openFlowNode.getId().getValue(); - LOG.debug("notifyNodeUpdated: Node {} from Controller's inventory Service", openflowId); - - // TODO: will do something amazing here, someday - } - - private void notifyNodeCreated (Node openFlowNode) { - final String openflowId = openFlowNode.getId().getValue(); - LOG.info("notifyNodeCreated: Node {} from Controller's inventory Service", openflowId); - - if (pipelineOrchestrator != null) { - //pipelineOrchestrator.enqueue(openflowId); - } - if (nodeCacheManager != null) { - //nodeCacheManager.nodeAdded(openflowId); - } - } - - private void notifyNodeRemoved (Node openFlowNode) { - LOG.info("notifyNodeRemoved: Node {} from Controller's inventory Service", - openFlowNode.getId().getValue()); - - if (nodeCacheManager != null) { - //nodeCacheManager.nodeRemoved(openFlowNode); - } - } - - private void checkMemberInitialization () { - /** - * Obtain local ref to members, if needed. Having these local saves us from calling getGlobalInstance - * upon every event. - */ - if (pipelineOrchestrator == null) { - pipelineOrchestrator = - (PipelineOrchestrator) ServiceHelper.getGlobalInstance(PipelineOrchestrator.class, this); - } - if (nodeCacheManager == null) { - nodeCacheManager = (NodeCacheManager) ServiceHelper.getGlobalInstance(NodeCacheManager.class, this); - } - } -} diff --git a/openstack/net-virt-providers/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/providers/openflow13/MdsalConsumerImpl.java b/openstack/net-virt-providers/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/providers/openflow13/MdsalConsumerImpl.java index b0e34590d..4db1ebd13 100644 --- a/openstack/net-virt-providers/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/providers/openflow13/MdsalConsumerImpl.java +++ b/openstack/net-virt-providers/src/main/java/org/opendaylight/ovsdb/openstack/netvirt/providers/openflow13/MdsalConsumerImpl.java @@ -29,7 +29,6 @@ public class MdsalConsumerImpl implements BindingAwareConsumer, MdsalConsumer, B private ConsumerContext consumerContext = null; private DataBroker dataBroker; private NotificationProviderService notificationService; - private FlowCapableNodeDataChangeListener flowCapableNodeChangeListener; static final Logger logger = LoggerFactory.getLogger(MdsalConsumerImpl.class); @@ -49,18 +48,11 @@ public class MdsalConsumerImpl implements BindingAwareConsumer, MdsalConsumer, B } } - void start() { - } - - void stop() { - } - @Override public void onSessionInitialized(ConsumerContext session) { this.consumerContext = session; dataBroker = session.getSALService(DataBroker.class); logger.info("OVSDB Neutron Session Initialized with CONSUMER CONTEXT {}", session.toString()); - //flowCapableNodeChangeListener = new FlowCapableNodeDataChangeListener(dataBroker); } @Override diff --git a/openstack/net-virt-providers/src/test/java/org/opendaylight/ovsdb/openstack/netvirt/providers/openflow13/FlowCapableNodeDataChangeListenerTest.java b/openstack/net-virt-providers/src/test/java/org/opendaylight/ovsdb/openstack/netvirt/providers/openflow13/FlowCapableNodeDataChangeListenerTest.java deleted file mode 100644 index d3811fc78..000000000 --- a/openstack/net-virt-providers/src/test/java/org/opendaylight/ovsdb/openstack/netvirt/providers/openflow13/FlowCapableNodeDataChangeListenerTest.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (c) 2015 Inocybe Technologies. 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, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.same; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.lang.reflect.Field; -import java.util.List; - -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.DataChangeListener; -import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; -import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker; -import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; -import org.opendaylight.yangtools.concepts.ListenerRegistration; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.opendaylight.neutron.spi.INeutronPortCRUD; -import org.opendaylight.neutron.spi.INeutronSubnetCRUD; -import org.opendaylight.ovsdb.openstack.netvirt.NeutronCacheUtils; -import org.opendaylight.ovsdb.openstack.netvirt.api.Action; -import org.opendaylight.ovsdb.openstack.netvirt.api.NodeCacheManager; -import org.opendaylight.ovsdb.openstack.netvirt.impl.EventDispatcherImpl; -import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper; - -/** - * Unit test for {@link FlowCapableNodeDataChangeListener} - */ -/* TODO SB_MIGRATION */ -@Ignore -@RunWith(PowerMockRunner.class) -@PrepareForTest(ServiceHelper.class) -public class FlowCapableNodeDataChangeListenerTest { - - @InjectMocks - private FlowCapableNodeDataChangeListener nodeListener; - - @Mock - private DataBroker dataBroker; - - @Mock - private ListenerRegistration registration; - - @Mock - private NodeCacheManager nodeCacheManager; - - @Mock - private PipelineOrchestrator orchestrator; - - @Before - public void setUp() { - - DataBroker dataBroker = mock(DataBroker.class); - registration = dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, - FlowCapableNodeDataChangeListener.createFlowCapableNodePath() - , nodeListener - , AsyncDataBroker.DataChangeScope.BASE); - - when(dataBroker.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL, - FlowCapableNodeDataChangeListener.createFlowCapableNodePath() - , nodeListener - , AsyncDataBroker.DataChangeScope.BASE)).thenReturn(registration); - - nodeListener = new FlowCapableNodeDataChangeListener(dataBroker); - orchestrator = Mockito.mock(PipelineOrchestrator.class); - nodeCacheManager = Mockito.mock(NodeCacheManager.class); - - - PowerMockito.mockStatic(ServiceHelper.class); - - Mockito.when(ServiceHelper.getGlobalInstance(PipelineOrchestrator.class, nodeListener)).thenReturn(orchestrator); - Mockito.when(ServiceHelper.getGlobalInstance(NodeCacheManager.class, nodeListener)).thenReturn(nodeCacheManager); - - } - - - /** - * Test method {@link FlowCapableNodeDataChangeListener#notifyFlowCapableNodeEventTest(String,Action)} - */ - /* TODO SB_MIGRATION *//* - @Test - public void notifyFlowCapableNodeEventTest() throws Exception{ - - List nodeCache = (List) getClassField(nodeListener, "nodeCache"); - - nodeListener.notifyFlowCapableNodeEvent("flowid1", Action.ADD); - nodeListener.notifyFlowCapableNodeEvent("flowid2", Action.ADD); - assertEquals("Error, notifyFlowCapableNodeEvent() - Controller's node inventory size after an ADD operation is incorrect", 2, nodeCache.size()); - verify(nodeCacheManager,times(1)).nodeAdded("flowid1"); - verify(nodeCacheManager,times(1)).nodeAdded("flowid2"); - verify(orchestrator, times(1)).enqueue("flowid1"); - - nodeListener.notifyFlowCapableNodeEvent("flowid1", Action.UPDATE); - assertEquals("Error, notifyFlowCapableNodeEvent() - Controller's node inventory size after an UPDATE operation is incorrect", 2, nodeCache.size()); - verify(nodeCacheManager, times(1)).nodeAdded("flowid1"); - verify(orchestrator, times(1)).enqueue("flowid1"); - - nodeListener.notifyFlowCapableNodeEvent("flowid1", Action.DELETE); - assertEquals("Error, notifyFlowCapableNodeEvent() - Controller's node inventory size after a DELETE operation is incorrect", 2, nodeCache.size()); - verify(nodeCacheManager, times(1)).nodeAdded("flowid1"); - verify(nodeCacheManager, times(1)).nodeRemoved("flowid1"); - verify(orchestrator, times(1)).enqueue("flowid1"); - - }*/ - - /** - * Get the specified field from FlowCapableNodeDataChangeListener using reflection - * @param instance - the class instance - * @param fieldName - the field to retrieve - * - * @return the desired field - */ - private Object getClassField(FlowCapableNodeDataChangeListener instance, String fieldName) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException{ - Field field = FlowCapableNodeDataChangeListener.class.getDeclaredField(fieldName); - field.setAccessible(true); - return field.get(instance); - } - -} diff --git a/openstack/net-virt-providers/src/test/java/org/opendaylight/ovsdb/openstack/netvirt/providers/openflow13/MdsalConsumerImplTest.java b/openstack/net-virt-providers/src/test/java/org/opendaylight/ovsdb/openstack/netvirt/providers/openflow13/MdsalConsumerImplTest.java index a68f58b8e..6641e09b9 100644 --- a/openstack/net-virt-providers/src/test/java/org/opendaylight/ovsdb/openstack/netvirt/providers/openflow13/MdsalConsumerImplTest.java +++ b/openstack/net-virt-providers/src/test/java/org/opendaylight/ovsdb/openstack/netvirt/providers/openflow13/MdsalConsumerImplTest.java @@ -114,24 +114,9 @@ public class MdsalConsumerImplTest { } - /** - * Test method {@link MdsalConsumerImpl#notifyFlowCapableNodeCreateEvent(String, Action)} - */ - @Test - public void notifyFlowCapableNodeCreateEventTest() throws Exception{ - - FlowCapableNodeDataChangeListener nodeChangeListener = (FlowCapableNodeDataChangeListener) getClassField(mdsalConsumer, "flowCapableNodeChangeListener"); - - //Send a notification - //mdsalConsumer.notifyFlowCapableNodeCreateEvent("flowId1", Action.ADD); - - List nodeCache = (List) getClassField(nodeChangeListener, "nodeCache"); - assertEquals("Error, notifyFlowCapableNodeEvent() - MdsalConsumerImpl NodeDataChangeLister inventory size after an ADD operation is incorrect", 1, nodeCache.size()); - } - /** * Get the specified field from MdsalConsumerImpl using reflection - * @param instancee - the class instance + * @param instance - the class instance * @param fieldName - the field to retrieve * * @return the desired field @@ -141,18 +126,4 @@ public class MdsalConsumerImplTest { field.setAccessible(true); return field.get(instance); } - - /** - * Get the specified field from FlowCapableNodeDataChangeListener using reflection - * @param instancee - the class instance - * @param fieldName - the field to retrieve - * - * @return the desired field - */ - private Object getClassField(FlowCapableNodeDataChangeListener instance, String fieldName) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException{ - Field field = FlowCapableNodeDataChangeListener.class.getDeclaredField(fieldName); - field.setAccessible(true); - return field.get(instance); - } - } -- 2.36.6