Topology manager - new listener for link and node changes. 87/18187/3
authorJozef Gloncak <jgloncak@cisco.com>
Mon, 13 Apr 2015 11:50:21 +0000 (13:50 +0200)
committerJozef Gloncak <jgloncak@cisco.com>
Mon, 13 Apr 2015 12:14:53 +0000 (14:14 +0200)
Listener classes for listening on node inventory data changes were added.

Change-Id: Ia7b61c5a09a7d1d40246e34b80dc466a8dc4ea4c
Signed-off-by: Jozef Gloncak <jgloncak@cisco.com>
applications/topology-manager/src/main/java/org/opendaylight/openflowplugin/applications/topology/manager/FlowCapableTopologyProvider.java
applications/topology-manager/src/main/java/org/opendaylight/openflowplugin/applications/topology/manager/LinkChangeListenerImpl.java [new file with mode: 0644]
applications/topology-manager/src/main/java/org/opendaylight/openflowplugin/applications/topology/manager/NodeChangeListenerImpl.java [new file with mode: 0644]

index 6115babf8c75d2bd29752a03e72a30e4239d0d59..9a2b7b82f0dd77e6c15d65ad94a9c172d547db99 100644 (file)
@@ -31,6 +31,8 @@ public class FlowCapableTopologyProvider extends AbstractBindingAwareProvider im
     private final static Logger LOG = LoggerFactory.getLogger(FlowCapableTopologyProvider.class);
     private ListenerRegistration<NotificationListener> listenerRegistration;
     private Thread thread;
+    private LinkChangeListenerImpl linkChangeListener;
+    private NodeChangeListenerImpl nodeChangeListener;
 
     /**
      * Gets called on start of a bundle.
@@ -51,6 +53,8 @@ public class FlowCapableTopologyProvider extends AbstractBindingAwareProvider im
         final OperationProcessor processor = new OperationProcessor(dataBroker);
         final FlowCapableTopologyExporter listener = new FlowCapableTopologyExporter(processor, path);
         this.listenerRegistration = notificationService.registerNotificationListener(listener);
+        linkChangeListener = new LinkChangeListenerImpl(dataBroker);
+        nodeChangeListener = new NodeChangeListenerImpl(dataBroker);
 
         final ReadWriteTransaction tx = dataBroker.newReadWriteTransaction();
         tx.put(LogicalDatastoreType.OPERATIONAL, path, new TopologyBuilder().setKey(key).build(), true);
@@ -77,6 +81,8 @@ public class FlowCapableTopologyProvider extends AbstractBindingAwareProvider im
             }
             listenerRegistration = null;
         }
+        unregisterListener(linkChangeListener);
+        unregisterListener(nodeChangeListener);
         if (thread != null) {
             thread.interrupt();
             thread.join();
@@ -84,6 +90,16 @@ public class FlowCapableTopologyProvider extends AbstractBindingAwareProvider im
         }
     }
 
+    private void unregisterListener(final AutoCloseable listenerToClose) {
+        if (listenerToClose != null) {
+            try {
+                listenerToClose.close();
+            } catch (Exception e) {
+                LOG.error("Failed to close listener registration", e);
+            }
+        }
+    }
+
     /**
      * Gets called during stop bundle
      *
diff --git a/applications/topology-manager/src/main/java/org/opendaylight/openflowplugin/applications/topology/manager/LinkChangeListenerImpl.java b/applications/topology-manager/src/main/java/org/opendaylight/openflowplugin/applications/topology/manager/LinkChangeListenerImpl.java
new file mode 100644 (file)
index 0000000..f6be043
--- /dev/null
@@ -0,0 +1,76 @@
+/**
+ * Copyright (c) 2015 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,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.applications.topology.manager;
+
+import java.util.Map;
+import java.util.Set;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+
+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.LogicalDatastoreType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class LinkChangeListenerImpl implements DataChangeListener, AutoCloseable {
+    private final ListenerRegistration<DataChangeListener> dataChangeListenerRegistration;
+
+    public LinkChangeListenerImpl(final DataBroker dataBroker) {
+        dataChangeListenerRegistration = dataBroker.registerDataChangeListener(
+                LogicalDatastoreType.OPERATIONAL,
+                InstanceIdentifier.builder(Nodes.class)
+                        .child(Node.class)
+                        .child(NodeConnector.class)
+                        .augmentation(FlowCapableNodeConnector.class)
+                        .build(),
+                this, AsyncDataBroker.DataChangeScope.BASE);
+    }
+
+    @Override
+    public void onDataChanged(AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
+        processAddedNodeConnectors(change.getCreatedData());
+        processUpdatedNodeConnectors(change.getUpdatedData());
+        processRemovedNodeConnectors(change.getRemovedPaths());
+    }
+
+    /**
+     * @param removedPaths
+     */
+    private void processRemovedNodeConnectors(Set<InstanceIdentifier<?>> removedPaths) {
+        // TODO Auto-generated method stub
+
+    }
+
+    /**
+     * @param updatedData
+     */
+    private void processUpdatedNodeConnectors(Map<InstanceIdentifier<?>, DataObject> updatedData) {
+        // TODO Auto-generated method stub
+
+    }
+
+    /**
+     * @param createdData
+     */
+    private void processAddedNodeConnectors(Map<InstanceIdentifier<?>, DataObject> createdData) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void close() throws Exception {
+        dataChangeListenerRegistration.close();
+    }
+
+}
diff --git a/applications/topology-manager/src/main/java/org/opendaylight/openflowplugin/applications/topology/manager/NodeChangeListenerImpl.java b/applications/topology-manager/src/main/java/org/opendaylight/openflowplugin/applications/topology/manager/NodeChangeListenerImpl.java
new file mode 100644 (file)
index 0000000..fbf29b3
--- /dev/null
@@ -0,0 +1,74 @@
+/**
+ * Copyright (c) 2015 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,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.applications.topology.manager;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import java.util.Map;
+import java.util.Set;
+import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
+
+    public class NodeChangeListenerImpl implements DataChangeListener, AutoCloseable {
+        private final ListenerRegistration<DataChangeListener> dataChangeListenerRegistration;
+
+        public NodeChangeListenerImpl(final DataBroker dataBroker) {
+            dataChangeListenerRegistration = dataBroker.registerDataChangeListener(
+                    LogicalDatastoreType.OPERATIONAL,
+                    InstanceIdentifier.builder(Nodes.class)
+                            .child(Node.class)
+                            .augmentation(FlowCapableNode.class)
+                            .build(),
+                    this, AsyncDataBroker.DataChangeScope.BASE);
+        }
+
+        @Override
+        public void onDataChanged(AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
+            processAddedNode(change.getCreatedData());
+            processUpdatedNode(change.getUpdatedData());
+            processRemovedNode(change.getRemovedPaths());
+        }
+
+        /**
+         * @param removedPaths
+         */
+        private void processRemovedNode(Set<InstanceIdentifier<?>> removedPaths) {
+            // TODO Auto-generated method stub
+
+        }
+
+        /**
+         * @param updatedData
+         */
+        private void processUpdatedNode(Map<InstanceIdentifier<?>, DataObject> updatedData) {
+            // TODO Auto-generated method stub
+
+        }
+
+        /**
+         * @param createdData
+         */
+        private void processAddedNode(Map<InstanceIdentifier<?>, DataObject> createdData) {
+            // TODO Auto-generated method stub
+
+        }
+
+        @Override
+        public void close() throws Exception {
+            dataChangeListenerRegistration.close();
+        }
+
+    }
\ No newline at end of file