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/ConsistentResourceStore.java b/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentResourceStore.java
index c20384b..0be8a37 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentResourceStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentResourceStore.java
@@ -173,23 +173,7 @@
         Map<DiscreteResourceId, List<Resource>> resourceMap = resources.stream()
                 .collect(Collectors.groupingBy(x -> x.parent().get().id(), LinkedHashMap::new, Collectors.toList()));
 
-        // even if one of the resources is allocated to a consumer,
-        // all unregistrations are regarded as failure
         for (Map.Entry<DiscreteResourceId, List<Resource>> entry : resourceMap.entrySet()) {
-            boolean allocated = entry.getValue().stream().anyMatch(x -> {
-                if (x instanceof DiscreteResource) {
-                    return discreteTxStore.isAllocated(((DiscreteResource) x).id());
-                } else if (x instanceof ContinuousResource) {
-                    return continuousTxStore.isAllocated(((ContinuousResource) x).id());
-                } else {
-                    return false;
-                }
-            });
-            if (allocated) {
-                log.warn("Failed to unregister {}: allocation exists", entry.getKey());
-                return abortTransaction(tx);
-            }
-
             if (!unregister(discreteTxStore, continuousTxStore, entry.getKey(), entry.getValue())) {
                 log.warn("Failed to unregister {}: Failed to remove {} values.",
                         entry.getKey(), entry.getValue().size());
diff --git a/core/store/dist/src/main/java/org/onosproject/store/resource/impl/TransactionalContinuousResourceStore.java b/core/store/dist/src/main/java/org/onosproject/store/resource/impl/TransactionalContinuousResourceStore.java
index c7a7d6e..c8c91c8 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/resource/impl/TransactionalContinuousResourceStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/resource/impl/TransactionalContinuousResourceStore.java
@@ -102,6 +102,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<ContinuousResource> oldValues = childMap.putIfAbsent(key, new LinkedHashSet<>());
         if (oldValues == null) {
             log.trace("No-Op removing values. key {} did not exist", key);
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);