Refactor: Move allocation check into transactional store implementation

Change-Id: Id2381d6789f12c8a0c0730b17e3395d144265f14
diff --git a/core/store/dist/src/main/java/org/onosproject/store/resource/impl/TransactionalDiscreteResourceStore.java b/core/store/dist/src/main/java/org/onosproject/store/resource/impl/TransactionalDiscreteResourceStore.java
index 7aad6a6..796ea49 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/resource/impl/TransactionalDiscreteResourceStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/resource/impl/TransactionalDiscreteResourceStore.java
@@ -92,6 +92,14 @@
             return true;
         }
 
+        // even if one of the resources is allocated to a consumer,
+        // all unregistrations are regarded as failure
+        boolean allocated = values.stream().anyMatch(x -> isAllocated(x.id()));
+        if (allocated) {
+            log.warn("Failed to unregister {}: allocation exists", key);
+            return false;
+        }
+
         Set<DiscreteResource> oldValues = childMap.putIfAbsent(key, new LinkedHashSet<>());
         if (oldValues == null) {
             log.trace("No-Op removing values. key {} did not exist", key);