Fix license header violations in plugin-mdsal-adapter
[ovsdb.git] / plugin-mdsal-adapter / src / main / java / org / opendaylight / ovsdb / plugin / md / OvsdbInventoryManager.java
old mode 100644 (file)
new mode 100755 (executable)
index c4623ac..7e7f57e
@@ -1,3 +1,11 @@
+/*
+ * Copyright (c) 2013, 2015 Red Hat, 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.ovsdb.plugin.md;
 
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
@@ -46,7 +54,7 @@ public class OvsdbInventoryManager implements OvsdbInventoryListener {
     static final String OVS_NODE_PREFIX = "openvswitch:";
     static final String OPENFLOW_NODE_PREFIX = "openflow:";
 
-    static final Logger logger = LoggerFactory.getLogger(OvsdbInventoryManager.class);
+    static final Logger LOGGER = LoggerFactory.getLogger(OvsdbInventoryManager.class);
 
 
     /**
@@ -94,9 +102,9 @@ public class OvsdbInventoryManager implements OvsdbInventoryListener {
         tx.put(LogicalDatastoreType.CONFIGURATION, path, newNode, true);
         try {
             tx.submit().get();
-            logger.debug("Removed Node {}", path.toString());
+            LOGGER.debug("Removed Node {}", path.toString());
         } catch (InterruptedException | ExecutionException e) {
-            logger.error(e.getMessage(), e);
+            LOGGER.error(e.getMessage(), e);
         }
     }
 
@@ -121,9 +129,9 @@ public class OvsdbInventoryManager implements OvsdbInventoryListener {
         tx.delete(LogicalDatastoreType.CONFIGURATION, path);
         try {
             tx.submit().get();
-            logger.debug("Removed Node {}", path.toString());
+            LOGGER.debug("Removed Node {}", path.toString());
         } catch (InterruptedException | ExecutionException e) {
-            logger.error(e.getMessage(), e);
+            LOGGER.error(e.getMessage(), e);
         }
     }
 
@@ -143,7 +151,7 @@ public class OvsdbInventoryManager implements OvsdbInventoryListener {
                                         Row row,
                                         Object context) {
         if (tableName.equalsIgnoreCase(ovsdbConfigurationService.getTableName(node, Bridge.class))) {
-            logger.debug("OVSDB Bridge Row removed on node {}", node.toString());
+            LOGGER.debug("OVSDB Bridge Row removed on node {}", node.toString());
             DataBroker dataBroker = provider.getDataBroker();
             Preconditions.checkNotNull(dataBroker);
 
@@ -171,9 +179,13 @@ public class OvsdbInventoryManager implements OvsdbInventoryListener {
             OvsdbCapableNode ovsdbNode;
             try {
                 Optional<OvsdbCapableNode> data = tx.read(LogicalDatastoreType.CONFIGURATION, ovsdbNodePath).get();
+                if (!data.isPresent()) {
+                    LOGGER.error("OVSDB node not updated. Parent node for {} does not exist", ovsdbNodePath.toString());
+                    return;
+                }
                 ovsdbNode = data.get();
             } catch (InterruptedException | ExecutionException e) {
-                logger.error("OVSDB node not updated. Parent node for {} does not exist", ovsdbNodePath.toString());
+                LOGGER.error("OVSDB node not updated. Parent node for {} does not exist", ovsdbNodePath.toString());
                 return;
             }
 
@@ -190,11 +202,11 @@ public class OvsdbInventoryManager implements OvsdbInventoryListener {
 
             try {
                 tx.submit().get();
-                logger.debug("Transaction success for delete of {} and update of {}",
+                LOGGER.debug("Transaction success for delete of {} and update of {}",
                              openflowNodePath.toString(),
                              ovsdbNodePath.toString());
             } catch (InterruptedException | ExecutionException e) {
-                logger.error(e.getMessage(), e);
+                LOGGER.error(e.getMessage(), e);
             }
         }
     }
@@ -215,7 +227,7 @@ public class OvsdbInventoryManager implements OvsdbInventoryListener {
                                         String uuid,
                                         Row old,
                                         Row row) {
-        logger.debug("OVSDB Bridge Row updated on node {}", node.toString());
+        LOGGER.debug("OVSDB Bridge Row updated on node {}", node.toString());
         if (tableName.equalsIgnoreCase(ovsdbConfigurationService.getTableName(node, Bridge.class))) {
             DataBroker dataBroker = provider.getDataBroker();
             Bridge bridge = ovsdbConfigurationService.getTypedRow(node, Bridge.class, row);
@@ -260,8 +272,11 @@ public class OvsdbInventoryManager implements OvsdbInventoryListener {
             ReadWriteTransaction tx = dataBroker.newReadWriteTransaction();
             OvsdbCapableNode ovsdbNode;
             try {
-                Optional<OvsdbCapableNode>
-                        data = tx.read(LogicalDatastoreType.CONFIGURATION, ovsdbNodePath).get();
+                Optional<OvsdbCapableNode> data = tx.read(LogicalDatastoreType.CONFIGURATION, ovsdbNodePath).get();
+                if (!data.isPresent()) {
+                    LOGGER.error("OVSDB node not updated. Parent node for {} does not exist", ovsdbNodePath.toString());
+                    return;
+                }
                 ovsdbNode = data.get();
             } catch (InterruptedException | ExecutionException e) {
                 throw new RuntimeException("Node does not exist");
@@ -282,11 +297,11 @@ public class OvsdbInventoryManager implements OvsdbInventoryListener {
 
             try {
                 tx.submit().get();
-                logger.debug("Transaction success for addition of {} and update of {}",
+                LOGGER.debug("Transaction success for addition of {} and update of {}",
                              openflowNodepath.toString(),
                              ovsdbNodePath.toString());
             } catch (InterruptedException | ExecutionException e) {
-                logger.error(e.getMessage(), e);
+                LOGGER.error(e.getMessage(), e);
             }
         }
     }