Change the flow-path installation check logic

Note: this commit is an ad-hoc hack to fix the hack made at the commit f911165b.

- originally, the flow-installed switch dpids are maintained
  on the map object using parent-intent ID as a key of the entry.
- this commit changes the key of the map to use path-intent ID.
- this commit may relax the rerouting problem when getting the simultaneous
  massive event notifications including intent state changes, topology changes
  and switch mastership changes.

Change-Id: I6f49ab5bb4c1440ec6829c5c4c6939c8b842bcec
diff --git a/src/main/java/net/onrc/onos/core/intent/runtime/PathCalcRuntimeModule.java b/src/main/java/net/onrc/onos/core/intent/runtime/PathCalcRuntimeModule.java
index 5776f26..2f820a0 100644
--- a/src/main/java/net/onrc/onos/core/intent/runtime/PathCalcRuntimeModule.java
+++ b/src/main/java/net/onrc/onos/core/intent/runtime/PathCalcRuntimeModule.java
@@ -644,6 +644,7 @@
                         !(parentIntent instanceof ShortestPathIntent)) {
                     continue;
                 }
+                String parentIntentId = parentIntent.getId();
 
                 boolean isChildIntent = ((ShortestPathIntent) parentIntent).getPathIntentId().equals(pathIntentId);
 
@@ -651,12 +652,12 @@
                 // When the PathIntent(=isChildIntent) transitioned to INST_{ACK/NACK}
                 // but was marked as stale (e.g., has been requested to reroute by Topology event),
                 // then immediately enqueue the re-computation of parent intent.
-                if (isChildIntent && staleIntents.containsKey(parentIntent.getId()) && (
+                if (isChildIntent && staleIntents.containsKey(parentIntentId) && (
                         nextPathIntentState.equals(IntentState.INST_ACK) ||
                         nextPathIntentState.equals(IntentState.INST_NACK))) {
                     opList.add(Operator.ADD, parentIntent);
-                    staleIntents.remove(parentIntent.getId());
-                    log.debug("retrying intent execution for intent ID:{}", parentIntent.getId());
+                    staleIntents.remove(parentIntentId);
+                    log.debug("retrying intent execution for intent ID:{}", parentIntentId);
                 }
 
                 switch (nextPathIntentState) {
@@ -671,8 +672,8 @@
                     case DEL_PENDING:
                         if (isChildIntent) {
                             log.debug("put the state highLevelIntentStates ID {}, state {}",
-                                    parentIntent.getId(), nextPathIntentState);
-                            highLevelIntentStates.put(parentIntent.getId(), nextPathIntentState);
+                                    parentIntentId, nextPathIntentState);
+                            highLevelIntentStates.put(parentIntentId, nextPathIntentState);
                         }
                         log.debug("put the state pathIntentStates ID {}, state {}",
                                 pathIntentId, nextPathIntentState);
@@ -680,12 +681,12 @@
                         break;
                     case DEL_ACK:
                         if (isChildIntent) {
-                            if (intentInstalledMap.containsKey(parentIntent.getId())) {
-                                 intentInstalledMap.remove(parentIntent.getId());
+                            if (intentInstalledMap.containsKey(pathIntentId)) {
+                                 intentInstalledMap.remove(pathIntentId);
                             }
                             log.debug("put the state highLevelIntentStates ID {}, state {}",
-                                    parentIntent.getId(), nextPathIntentState);
-                            highLevelIntentStates.put(parentIntent.getId(), nextPathIntentState);
+                                    parentIntentId, nextPathIntentState);
+                            highLevelIntentStates.put(parentIntentId, nextPathIntentState);
                         }
                         log.debug("put the state pathIntentStates ID {}, state {}",
                                 pathIntentId, nextPathIntentState);
@@ -720,16 +721,15 @@
      * @return The result of whether a pathIntent has been installed or not.
      */
     private boolean isFlowInstalled(PathIntent pathIntent, Set<Long> installedDpids) {
-        String parentIntentId = pathIntent.getParentIntent().getId();
-        log.debug("parentIntentId {}", parentIntentId);
+        String pathIntentId = pathIntent.getId();
 
-        if (intentInstalledMap.containsKey(parentIntentId)) {
+        if (intentInstalledMap.containsKey(pathIntentId)) {
             if (!installedDpids.isEmpty()) {
-                intentInstalledMap.get(parentIntentId).addAll(installedDpids);
+                intentInstalledMap.get(pathIntentId).addAll(installedDpids);
             }
         } else {
             // This is the creation of an entry.
-            intentInstalledMap.put(parentIntentId, installedDpids);
+            intentInstalledMap.put(pathIntentId, installedDpids);
         }
 
         Set<Long> allSwitchesForPath = new HashSet<Long>();
@@ -741,13 +741,15 @@
         }
         allSwitchesForPath.add(spfIntent.getDstSwitchDpid());
 
-        if (log.isTraceEnabled()) {
-            log.trace("All switches {}, installed installedDpids {}",
-                    allSwitchesForPath, intentInstalledMap.get(parentIntentId));
+        if (log.isDebugEnabled()) {
+            log.debug("checking flow installation. ID:{}, dpids:{}, installed:{}",
+                    pathIntentId,
+                    allSwitchesForPath,
+                    intentInstalledMap.get(pathIntentId));
         }
 
-        if (allSwitchesForPath.equals(intentInstalledMap.get(parentIntentId))) {
-            intentInstalledMap.remove(parentIntentId);
+        if (allSwitchesForPath.equals(intentInstalledMap.get(pathIntentId))) {
+            intentInstalledMap.remove(pathIntentId);
             return true;
         }