Don't reinstall flow rules for existing nodes when network cfg updated

Change-Id: I94ee88249bf4473d01a5467ff0c0f2c436b7f26b
diff --git a/apps/openstacknode/src/main/java/org/onosproject/openstacknode/OpenstackNodeManager.java b/apps/openstacknode/src/main/java/org/onosproject/openstacknode/OpenstackNodeManager.java
index d435833..4f3e5e7 100644
--- a/apps/openstacknode/src/main/java/org/onosproject/openstacknode/OpenstackNodeManager.java
+++ b/apps/openstacknode/src/main/java/org/onosproject/openstacknode/OpenstackNodeManager.java
@@ -17,6 +17,7 @@
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
@@ -82,7 +83,6 @@
 import org.slf4j.Logger;
 
 import java.util.Dictionary;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
@@ -98,6 +98,7 @@
 import static org.onosproject.net.Device.Type.SWITCH;
 import static org.onosproject.net.behaviour.TunnelDescription.Type.VXLAN;
 import static org.onosproject.openstacknode.Constants.*;
+import static org.onosproject.openstacknode.OpenstackNode.getUpdatedNode;
 import static org.onosproject.openstacknode.OpenstackNodeEvent.NodeState.*;
 import static org.slf4j.LoggerFactory.getLogger;
 
@@ -236,8 +237,10 @@
 
     @Override
     public void addOrUpdateNode(OpenstackNode node) {
-        nodeStore.put(node.hostname(),
-                OpenstackNode.getUpdatedNode(node, nodeState(node)));
+        nodeStore.computeIf(node.hostname(),
+                v -> v == null || (!v.equals(node) || v.state() != COMPLETE),
+                (k, v) -> getUpdatedNode(node, nodeState(node))
+        );
     }
 
     @Override
@@ -438,7 +441,7 @@
     }
 
     private void setNodeState(OpenstackNode node, NodeState newState) {
-        nodeStore.put(node.hostname(), OpenstackNode.getUpdatedNode(node, newState));
+        nodeStore.put(node.hostname(), getUpdatedNode(node, newState));
     }
 
     private NodeState nodeState(OpenstackNode node) {
@@ -478,9 +481,7 @@
 
         BridgeConfig bridgeConfig =  device.as(BridgeConfig.class);
         return bridgeConfig.getPorts().stream()
-                .filter(port -> port.annotations().value(PORT_NAME).equals(ifaceName))
-                .findAny()
-                .isPresent();
+                .anyMatch(port -> port.annotations().value(PORT_NAME).equals(ifaceName));
     }
 
     private boolean isBridgeCreated(DeviceId deviceId, String bridgeName) {
@@ -491,9 +492,7 @@
 
         BridgeConfig bridgeConfig =  device.as(BridgeConfig.class);
         return bridgeConfig.getBridges().stream()
-                .filter(bridge -> bridge.name().equals(bridgeName))
-                .findAny()
-                .isPresent();
+                .anyMatch(bridge -> bridge.name().equals(bridgeName));
     }
 
     private void createBridge(OpenstackNode node, String bridgeName, DeviceId deviceId) {
@@ -631,7 +630,7 @@
     private Set<String> systemIfaces(OpenstackNode node) {
         Set<String> ifaces = Sets.newHashSet();
         node.dataIp().ifPresent(ip -> ifaces.add(DEFAULT_TUNNEL));
-        node.vlanPort().ifPresent(p -> ifaces.add(p));
+        node.vlanPort().ifPresent(ifaces::add);
         if (node.type().equals(NodeType.GATEWAY)) {
             ifaces.add(PATCH_INTG_BRIDGE);
             ifaces.add(PATCH_ROUT_BRIDGE);
@@ -788,7 +787,7 @@
             return;
         }
 
-        Map<String, OpenstackNode> prevNodeMap = new HashMap(nodeStore.asJavaMap());
+        Map<String, OpenstackNode> prevNodeMap = Maps.newHashMap(nodeStore.asJavaMap());
         config.openstackNodes().forEach(node -> {
             prevNodeMap.remove(node.hostname());
             addOrUpdateNode(node);