ONOS-5808: Allocate BW from ConnectivityIntentCompiler and unit tests for partial failure

Change-Id: I2eb3c16efbce619db6d0d2ba415a35752a61ece4
diff --git a/core/api/src/main/java/org/onosproject/net/intent/Key.java b/core/api/src/main/java/org/onosproject/net/intent/Key.java
index b4dab2d..e8e4af7 100644
--- a/core/api/src/main/java/org/onosproject/net/intent/Key.java
+++ b/core/api/src/main/java/org/onosproject/net/intent/Key.java
@@ -19,6 +19,8 @@
 import com.google.common.hash.HashFunction;
 import com.google.common.hash.Hashing;
 import org.onosproject.core.ApplicationId;
+import org.onosproject.net.resource.ResourceConsumer;
+import org.onosproject.net.resource.ResourceConsumerId;
 
 import java.nio.charset.StandardCharsets;
 import java.util.Objects;
@@ -28,7 +30,7 @@
  */
 // TODO maybe pull this up to utils
 @Beta
-public abstract class Key implements Comparable<Key> {
+public abstract class Key implements Comparable<Key>, ResourceConsumer {
 
     //TODO consider making this a HashCode object (worry about performance)
     private final long hash;
@@ -54,6 +56,8 @@
      * Creates a key based on the provided string.
      * <p>
      * Note: Two keys with equal value, but different appId, are not equal.
+     * Warning: it is caller responsibility to make sure the hashed value of
+     * {@code value} is unique.
      * </p>
      *
      * @param key the provided string
@@ -79,6 +83,11 @@
         return new LongKey(key, appId);
     }
 
+    @Override
+    public ResourceConsumerId consumerId() {
+        return ResourceConsumerId.of(hash(), getClass());
+    }
+
     private static final class StringKey extends Key {
 
         private final ApplicationId appId;