ONOS-6151 Add group behavior in case of device master "null" is made inline with flow subsystem. i.e. group add is allowed when master is null, this gets added to the pending audit queue and when the device is up the pending group add request gets fullfilled

Change-Id: I6e67c03213cad5e5f8dbddbed8ffee55e3c877b3
diff --git a/core/store/dist/src/main/java/org/onosproject/store/group/impl/DistributedGroupStore.java b/core/store/dist/src/main/java/org/onosproject/store/group/impl/DistributedGroupStore.java
index df8a99c..f820feb 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/group/impl/DistributedGroupStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/group/impl/DistributedGroupStore.java
@@ -446,10 +446,10 @@
             log.debug("storeGroupDescription: Device {} local role is not MASTER",
                       groupDesc.deviceId());
             if (mastershipService.getMasterFor(groupDesc.deviceId()) == null) {
-                log.error("No Master for device {}..."
-                                  + "Can not perform add group operation",
+                log.debug("No Master for device {}..."
+                                  + "Queuing Group ADD request",
                           groupDesc.deviceId());
-                //TODO: Send Group operation failure event
+                addToPendingAudit(groupDesc);
                 return;
             }
             GroupStoreMessage groupOp = GroupStoreMessage.
@@ -481,6 +481,21 @@
         storeGroupDescriptionInternal(groupDesc);
     }
 
+    private void addToPendingAudit(GroupDescription groupDesc) {
+        Integer groupIdVal = groupDesc.givenGroupId();
+        GroupId groupId = (groupIdVal != null) ? new GroupId(groupIdVal) : dummyGroupId;
+        addToPendingKeyTable(new DefaultGroup(groupId, groupDesc));
+    }
+
+    private void addToPendingKeyTable(StoredGroupEntry group) {
+        group.setState(GroupState.WAITING_AUDIT_COMPLETE);
+        Map<GroupStoreKeyMapKey, StoredGroupEntry> pendingKeyTable =
+                getPendingGroupKeyTable();
+        pendingKeyTable.put(new GroupStoreKeyMapKey(group.deviceId(),
+                        group.appCookie()),
+                group);
+    }
+
     private Group getMatchingExtraneousGroupbyId(DeviceId deviceId, Integer groupId) {
         ConcurrentMap<GroupId, Group> extraneousMap =
                 extraneousGroupEntriesById.get(deviceId);