Refactoring of IntentId based APIs

- getIntent
- getIntentState
- getInstallableIntents

Change-Id: I6d2073dfa165e0e5adcef46fe5908b563b481a43
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java b/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java
index 3603a50..a0cc741 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/IntentManager.java
@@ -40,13 +40,13 @@
 import org.onosproject.net.intent.IntentEvent;
 import org.onosproject.net.intent.IntentException;
 import org.onosproject.net.intent.IntentExtensionService;
-import org.onosproject.net.intent.IntentId;
 import org.onosproject.net.intent.IntentInstaller;
 import org.onosproject.net.intent.IntentListener;
 import org.onosproject.net.intent.IntentService;
 import org.onosproject.net.intent.IntentState;
 import org.onosproject.net.intent.IntentStore;
 import org.onosproject.net.intent.IntentStoreDelegate;
+import org.onosproject.net.intent.Key;
 import org.slf4j.Logger;
 
 import java.util.ArrayList;
@@ -81,7 +81,7 @@
     private static final Logger log = getLogger(IntentManager.class);
 
     public static final String INTENT_NULL = "Intent cannot be null";
-    public static final String INTENT_ID_NULL = "Intent ID cannot be null";
+    public static final String INTENT_ID_NULL = "Intent key cannot be null";
 
     private static final int NUM_THREADS = 12;
 
@@ -163,6 +163,11 @@
     }
 
     @Override
+    public Intent getIntent(Key key) {
+        return store.getIntent(key);
+    }
+
+    @Override
     public Iterable<Intent> getIntents() {
         return store.getIntents();
     }
@@ -173,21 +178,15 @@
     }
 
     @Override
-    public Intent getIntent(IntentId id) {
-        checkNotNull(id, INTENT_ID_NULL);
-        return store.getIntent(id);
+    public IntentState getIntentState(Key intentKey) {
+        checkNotNull(intentKey, INTENT_ID_NULL);
+        return store.getIntentState(intentKey);
     }
 
     @Override
-    public IntentState getIntentState(IntentId id) {
-        checkNotNull(id, INTENT_ID_NULL);
-        return store.getIntentState(id);
-    }
-
-    @Override
-    public List<Intent> getInstallableIntents(IntentId intentId) {
-        checkNotNull(intentId, INTENT_ID_NULL);
-        return store.getInstallableIntents(intentId);
+    public List<Intent> getInstallableIntents(Key intentKey) {
+        checkNotNull(intentKey, INTENT_ID_NULL);
+        return store.getInstallableIntents(intentKey);
     }
 
     @Override
@@ -446,11 +445,11 @@
         }
     }
 
-    private void buildAndSubmitBatches(Iterable<IntentId> intentIds,
+    private void buildAndSubmitBatches(Iterable<Key> intentKeys,
                                        boolean compileAllFailed) {
         // Attempt recompilation of the specified intents first.
-        for (IntentId id : intentIds) {
-            Intent intent = store.getIntent(id);
+        for (Key key : intentKeys) {
+            Intent intent = store.getIntent(key);
             if (intent == null) {
                 continue;
             }
@@ -460,7 +459,7 @@
         if (compileAllFailed) {
             // If required, compile all currently failed intents.
             for (Intent intent : getIntents()) {
-                IntentState state = getIntentState(intent.id());
+                IntentState state = getIntentState(intent.key());
                 if (RECOMPILE.contains(state)) {
                     if (state == WITHDRAW_REQ) {
                         withdraw(intent);
@@ -482,9 +481,9 @@
     // Topology change delegate
     private class InternalTopoChangeDelegate implements TopologyChangeDelegate {
         @Override
-        public void triggerCompile(Iterable<IntentId> intentIds,
+        public void triggerCompile(Iterable<Key> intentKeys,
                                    boolean compileAllFailed) {
-            buildAndSubmitBatches(intentIds, compileAllFailed);
+            buildAndSubmitBatches(intentKeys, compileAllFailed);
         }
     }
 
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/ObjectiveTracker.java b/core/net/src/main/java/org/onosproject/net/intent/impl/ObjectiveTracker.java
index aabcc28..3c7b733 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/ObjectiveTracker.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/ObjectiveTracker.java
@@ -29,8 +29,8 @@
 import org.onosproject.net.Link;
 import org.onosproject.net.LinkKey;
 import org.onosproject.net.NetworkResource;
-import org.onosproject.net.intent.IntentId;
 import org.onosproject.net.intent.IntentService;
+import org.onosproject.net.intent.Key;
 import org.onosproject.net.link.LinkEvent;
 import org.onosproject.net.resource.LinkResourceEvent;
 import org.onosproject.net.resource.LinkResourceListener;
@@ -65,8 +65,8 @@
 
     private final Logger log = getLogger(getClass());
 
-    private final SetMultimap<LinkKey, IntentId> intentsByLink =
-            synchronizedSetMultimap(HashMultimap.<LinkKey, IntentId>create());
+    private final SetMultimap<LinkKey, Key> intentsByLink =
+            synchronizedSetMultimap(HashMultimap.<LinkKey, Key>create());
 
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
     protected TopologyService topologyService;
@@ -126,21 +126,21 @@
     }
 
     @Override
-    public void addTrackedResources(IntentId intentId,
+    public void addTrackedResources(Key intentKey,
                                     Collection<NetworkResource> resources) {
         for (NetworkResource resource : resources) {
             if (resource instanceof Link) {
-                intentsByLink.put(linkKey((Link) resource), intentId);
+                intentsByLink.put(linkKey((Link) resource), intentKey);
             }
         }
     }
 
     @Override
-    public void removeTrackedResources(IntentId intentId,
+    public void removeTrackedResources(Key intentKey,
                                        Collection<NetworkResource> resources) {
         for (NetworkResource resource : resources) {
             if (resource instanceof Link) {
-                intentsByLink.remove(linkKey((Link) resource), intentId);
+                intentsByLink.remove(linkKey((Link) resource), intentKey);
             }
         }
     }
@@ -170,10 +170,10 @@
             }
 
             if (event.reasons() == null || event.reasons().isEmpty()) {
-                delegate.triggerCompile(new HashSet<IntentId>(), true);
+                delegate.triggerCompile(new HashSet<Key>(), true);
 
             } else {
-                Set<IntentId> toBeRecompiled = new HashSet<>();
+                Set<Key> toBeRecompiled = new HashSet<>();
                 boolean recompileOnly = true;
 
                 // Scan through the list of reasons and keep accruing all
@@ -186,9 +186,9 @@
                                         linkEvent.subject().isDurable())) {
                             final LinkKey linkKey = linkKey(linkEvent.subject());
                             synchronized (intentsByLink) {
-                                Set<IntentId> intentIds = intentsByLink.get(linkKey);
-                                log.debug("recompile triggered by LinkDown {} {}", linkKey, intentIds);
-                                toBeRecompiled.addAll(intentIds);
+                                Set<Key> intentKeys = intentsByLink.get(linkKey);
+                                log.debug("recompile triggered by LinkDown {} {}", linkKey, intentKeys);
+                                toBeRecompiled.addAll(intentKeys);
                             }
                         }
                         recompileOnly = recompileOnly &&
@@ -243,15 +243,15 @@
         }
         intentService.getIntents().forEach(intent -> {
             if (intent.appId().equals(appId)) {
-                IntentId id = intent.id();
+                Key key = intent.key();
                 Collection<NetworkResource> resources = Lists.newArrayList();
-                intentService.getInstallableIntents(id).stream()
+                intentService.getInstallableIntents(key).stream()
                         .map(installable -> installable.resources())
                         .forEach(resources::addAll);
                 if (track) {
-                    addTrackedResources(id, resources);
+                    addTrackedResources(key, resources);
                 } else {
-                    removeTrackedResources(id, resources);
+                    removeTrackedResources(key, resources);
                 }
             }
         });
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/ObjectiveTrackerService.java b/core/net/src/main/java/org/onosproject/net/intent/impl/ObjectiveTrackerService.java
index 404af9b..f1dfb94 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/ObjectiveTrackerService.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/ObjectiveTrackerService.java
@@ -15,11 +15,11 @@
  */
 package org.onosproject.net.intent.impl;
 
-import org.onosproject.net.NetworkResource;
-import org.onosproject.net.intent.IntentId;
-
 import java.util.Collection;
 
+import org.onosproject.net.NetworkResource;
+import org.onosproject.net.intent.Key;
+
 /**
  * Auxiliary service for tracking intent path flows and for notifying the
  * intent service of environment changes via topology change delegate.
@@ -43,19 +43,20 @@
     /**
      * Adds a path flow to be tracked.
      *
-     * @param intentId  intent identity on whose behalf the path is being tracked
+     * @param intentKey  intent identity on whose behalf the path is being tracked
      * @param resources resources to track
      */
-    public void addTrackedResources(IntentId intentId,
+    // TODO consider using the IntentData here rather than just the key
+    public void addTrackedResources(Key intentKey,
                                     Collection<NetworkResource> resources);
 
     /**
      * Removes a path flow to be tracked.
      *
-     * @param intentId  intent identity on whose behalf the path is being tracked
+     * @param intentKey  intent identity on whose behalf the path is being tracked
      * @param resources resources to stop tracking
      */
-    public void removeTrackedResources(IntentId intentId,
+    public void removeTrackedResources(Key intentKey,
                                        Collection<NetworkResource> resources);
 
 }
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/TopologyChangeDelegate.java b/core/net/src/main/java/org/onosproject/net/intent/impl/TopologyChangeDelegate.java
index 5eeb7c2..3cc0f2a 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/TopologyChangeDelegate.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/TopologyChangeDelegate.java
@@ -15,7 +15,7 @@
  */
 package org.onosproject.net.intent.impl;
 
-import org.onosproject.net.intent.IntentId;
+import org.onosproject.net.intent.Key;
 
 /**
  * Auxiliary delegate for integration of intent manager and flow trackerService.
@@ -32,6 +32,6 @@
      * @param compileAllFailed true implies full compile of all failed intents
      *                         is required; false for selective recompile only
      */
-    void triggerCompile(Iterable<IntentId> intentIds, boolean compileAllFailed);
+    void triggerCompile(Iterable<Key> intentIds, boolean compileAllFailed);
 
 }