Resource group to share resources between intents

Change-Id: I5bf7d4261197449924d07dabac841cf8ccbe9389
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/IntentCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/IntentCodec.java
index 11429d4..7686a55 100644
--- a/core/common/src/main/java/org/onosproject/codec/impl/IntentCodec.java
+++ b/core/common/src/main/java/org/onosproject/codec/impl/IntentCodec.java
@@ -19,6 +19,7 @@
 import org.onosproject.codec.JsonCodec;
 import org.onosproject.core.CoreService;
 import org.onosproject.net.NetworkResource;
+import org.onosproject.net.ResourceGroup;
 import org.onosproject.net.intent.PointToPointIntent;
 import org.onosproject.net.intent.Intent;
 import org.onosproject.net.intent.IntentService;
@@ -45,6 +46,7 @@
     protected static final String STATE = "state";
     protected static final String PRIORITY = "priority";
     protected static final String RESOURCES = "resources";
+    protected static final String RESOURCE_GROUP = "resourceGroup";
     protected static final String MISSING_MEMBER_MESSAGE =
             " member is required in Intent";
     private static final String E_APP_ID_NOT_FOUND =
@@ -59,6 +61,9 @@
                 .put(ID, intent.id().toString())
                 .put(APP_ID, UrlEscapers.urlPathSegmentEscaper()
                         .escape(intent.appId().name()));
+        if (intent.resourceGroup() != null) {
+            result.put(RESOURCE_GROUP, intent.resourceGroup().toString());
+        }
 
         final ArrayNode jsonResources = result.putArray(RESOURCES);
 
@@ -113,5 +118,13 @@
         if (priorityJson != null) {
             builder.priority(priorityJson.asInt());
         }
+
+        JsonNode resourceGroup = json.get(IntentCodec.RESOURCE_GROUP);
+        if (resourceGroup != null) {
+            String resourceGroupId = resourceGroup.asText();
+            builder.resourceGroup(ResourceGroup.of(
+                    Long.parseUnsignedLong(resourceGroupId.substring(2), 16)
+            ));
+        }
     }
 }