adding and removing tracked resources

Change-Id: I5030e1c21a61e54f251dbc5760783f1ac2e4d2d7
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/InstallCoordinating.java b/core/net/src/main/java/org/onosproject/net/intent/impl/InstallCoordinating.java
index f259595..abf8886 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/InstallCoordinating.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/InstallCoordinating.java
@@ -47,6 +47,8 @@
     @Override
     public Optional<IntentUpdate> execute() {
         try {
+            //FIXME we orphan flow rules that are currently on the data plane
+            // ... should either reuse them or remove them
             FlowRuleOperations flowRules = intentManager.coordinate(pending);
             return Optional.of(new Installing(intentManager, pending, flowRules));
         } catch (IntentException e) {
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/Installing.java b/core/net/src/main/java/org/onosproject/net/intent/impl/Installing.java
index 122f224..3827f6d 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/Installing.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/Installing.java
@@ -16,6 +16,7 @@
 package org.onosproject.net.intent.impl;
 
 import org.onosproject.net.flow.FlowRuleOperations;
+import org.onosproject.net.intent.Intent;
 import org.onosproject.net.intent.IntentData;
 import org.onosproject.net.intent.IntentException;
 import org.slf4j.Logger;
@@ -48,6 +49,9 @@
     public Optional<IntentUpdate> execute() {
         try {
             intentManager.flowRuleService.apply(flowRules); // FIXME we need to provide a context
+            for (Intent installable: pending.installables()) {
+                intentManager.trackerService.addTrackedResources(pending.key(), installable.resources());
+            }
             return Optional.of(new Installed(pending));
         // What kinds of exceptions are thrown by FlowRuleService.apply()?
         // Is IntentException a correct exception abstraction?
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/Withdrawing.java b/core/net/src/main/java/org/onosproject/net/intent/impl/Withdrawing.java
index 06a0ad3..a797c49 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/Withdrawing.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/Withdrawing.java
@@ -16,6 +16,7 @@
 package org.onosproject.net.intent.impl;
 
 import org.onosproject.net.flow.FlowRuleOperations;
+import org.onosproject.net.intent.Intent;
 import org.onosproject.net.intent.IntentData;
 
 import java.util.Optional;
@@ -42,6 +43,9 @@
     @Override
     public Optional<IntentUpdate> execute() {
         intentManager.flowRuleService.apply(flowRules);
+        for (Intent installable: pending.installables()) {
+            intentManager.trackerService.removeTrackedResources(pending.key(), installable.resources());
+        }
         return Optional.of(new Withdrawn(pending));
     }
 }