Removed IntentId which is used only for allocating resources. (ONOS-4406)

Change-Id: I9a4ee5fbb5c0e569c058f34c1271ca573c8eb2f1
diff --git a/apps/newoptical/src/main/java/org/onosproject/newoptical/OpticalConnectivity.java b/apps/newoptical/src/main/java/org/onosproject/newoptical/OpticalConnectivity.java
index db127e7..cd5a2cd 100644
--- a/apps/newoptical/src/main/java/org/onosproject/newoptical/OpticalConnectivity.java
+++ b/apps/newoptical/src/main/java/org/onosproject/newoptical/OpticalConnectivity.java
@@ -23,7 +23,6 @@
 import org.onosproject.net.ConnectPoint;
 import org.onosproject.net.Link;
 import org.onosproject.net.Path;
-import org.onosproject.net.intent.IntentId;
 
 import java.time.Duration;
 import java.util.HashSet;
@@ -48,11 +47,6 @@
 
     private final Set<PacketLinkRealizedByOptical> realizingLinks = new HashSet<>();
 
-    // TODO: This IntentId is used only to reserve bandwidth resource.
-    //       After ResourceManager is made to accept app-defined ResourceConsumer,
-    //       this Intent should be replaced with OpticalConnectivityId.
-    private IntentId intentId;
-
     private State state = State.CREATED;
 
     public enum State {
@@ -163,12 +157,4 @@
     public Set<PacketLinkRealizedByOptical> getRealizingLinks() {
         return ImmutableSet.copyOf(realizingLinks);
     }
-
-    public IntentId getIntentId() {
-        return intentId;
-    }
-
-    public void setIntentId(IntentId intentId) {
-        this.intentId = intentId;
-    }
 }
diff --git a/apps/newoptical/src/main/java/org/onosproject/newoptical/OpticalPathProvisioner.java b/apps/newoptical/src/main/java/org/onosproject/newoptical/OpticalPathProvisioner.java
index 2ff2de5..61c0c02 100644
--- a/apps/newoptical/src/main/java/org/onosproject/newoptical/OpticalPathProvisioner.java
+++ b/apps/newoptical/src/main/java/org/onosproject/newoptical/OpticalPathProvisioner.java
@@ -52,13 +52,10 @@
 import org.onosproject.net.device.DeviceService;
 import org.onosproject.net.intent.Intent;
 import org.onosproject.net.intent.IntentEvent;
-import org.onosproject.net.intent.IntentId;
 import org.onosproject.net.intent.IntentListener;
 import org.onosproject.net.intent.IntentService;
-import org.onosproject.net.intent.Key;
 import org.onosproject.net.intent.OpticalCircuitIntent;
 import org.onosproject.net.intent.OpticalConnectivityIntent;
-import org.onosproject.net.intent.PointToPointIntent;
 import org.onosproject.net.link.LinkEvent;
 import org.onosproject.net.link.LinkListener;
 import org.onosproject.net.link.LinkService;
@@ -242,18 +239,6 @@
         OpticalConnectivityId id = OpticalConnectivityId.of(idCounter.getAndIncrement());
         OpticalConnectivity connectivity = new OpticalConnectivity(id, path, bandwidth, latency);
 
-        ConnectPoint ingress = path.src();
-        ConnectPoint egress = path.dst();
-
-        Intent pktIntent = PointToPointIntent.builder()
-                .appId(appId)
-                .ingressPoint(ingress)
-                .egressPoint(egress)
-                .key(Key.of(id.id(), appId))
-                .build();
-
-        connectivity.setIntentId(pktIntent.id());
-
         // store connectivity information
         connectivities.put(connectivity.id(), connectivity);
 
@@ -470,10 +455,7 @@
      * @param connectivity Optical connectivity
      */
     private void updateBandwidthUsage(OpticalConnectivity connectivity) {
-        IntentId intentId = connectivity.getIntentId();
-        if (intentId == null) {
-            return;
-        }
+        OpticalConnectivityId connectivityId = connectivity.id();
 
         List<Link> links = connectivity.links();
 
@@ -483,14 +465,14 @@
                         Bandwidth.class).resource(connectivity.bandwidth().bps()))
                 .collect(Collectors.toList());
 
-        log.debug("allocating bandwidth for {} : {}", connectivity.getIntentId(), resources);
-        List<ResourceAllocation> allocations = resourceService.allocate(intentId, resources);
+        log.debug("allocating bandwidth for {} : {}", connectivityId, resources);
+        List<ResourceAllocation> allocations = resourceService.allocate(connectivityId, resources);
         if (allocations.isEmpty()) {
             log.warn("Failed to allocate bandwidth {} to {}",
                     connectivity.bandwidth().bps(), resources);
             // TODO any recovery?
         }
-        log.debug("Done allocating bandwidth for {}", connectivity.getIntentId());
+        log.debug("Done allocating bandwidth for {}", connectivityId);
     }
 
     /**
@@ -498,18 +480,15 @@
      * @param connectivity Optical connectivity
      */
     private void releaseBandwidthUsage(OpticalConnectivity connectivity) {
-        IntentId intentId = connectivity.getIntentId();
-        if (intentId == null) {
-            return;
-        }
+        OpticalConnectivityId connectivityId = connectivity.id();
 
-        log.debug("releasing bandwidth allocated to {}", connectivity.getIntentId());
-        if (!resourceService.release(connectivity.getIntentId())) {
+        log.debug("releasing bandwidth allocated to {}", connectivityId);
+        if (!resourceService.release(connectivityId)) {
             log.warn("Failed to release bandwidth allocated to {}",
-                    connectivity.getIntentId());
+                    connectivityId);
             // TODO any recovery?
         }
-        log.debug("DONE releasing bandwidth for {}", connectivity.getIntentId());
+        log.debug("DONE releasing bandwidth for {}", connectivityId);
     }
 
     private class BandwidthLinkWeight implements LinkWeight {
diff --git a/apps/newoptical/src/main/java/org/onosproject/newoptical/api/OpticalConnectivityId.java b/apps/newoptical/src/main/java/org/onosproject/newoptical/api/OpticalConnectivityId.java
index 4926373..df6a500 100644
--- a/apps/newoptical/src/main/java/org/onosproject/newoptical/api/OpticalConnectivityId.java
+++ b/apps/newoptical/src/main/java/org/onosproject/newoptical/api/OpticalConnectivityId.java
@@ -18,6 +18,8 @@
 import com.google.common.annotations.Beta;
 import com.google.common.base.MoreObjects;
 import org.onlab.util.Identifier;
+import org.onosproject.net.resource.ResourceConsumer;
+import org.onosproject.net.resource.ResourceConsumerId;
 
 // TODO: After ResourceManager is made to accept app-defined ResourceConsumer,
 //       this class should be implemented as ResourceConsumer.
@@ -25,7 +27,7 @@
  * ID for optical connectivity.
  */
 @Beta
-public final class OpticalConnectivityId extends Identifier<Long> {
+public final class OpticalConnectivityId extends Identifier<Long> implements ResourceConsumer {
 
     public static OpticalConnectivityId of(long value) {
         return new OpticalConnectivityId(value);
@@ -36,6 +38,11 @@
     }
 
     @Override
+    public ResourceConsumerId consumerId() {
+        return ResourceConsumerId.of(this);
+    }
+
+    @Override
     public String toString() {
         return MoreObjects.toStringHelper(this)
                 .add("value", id())