Move hasEnoughResource() to ContinuousResourceAllocation
Change-Id: I3104d115a57876a75c699f4f1a46aa7bdf66d484
diff --git a/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentContinuousResourceStore.java b/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentContinuousResourceStore.java
index 54751a6..9afc7a2 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentContinuousResourceStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentContinuousResourceStore.java
@@ -39,7 +39,7 @@
import static org.onosproject.store.resource.impl.ConsistentResourceStore.MAX_RETRIES;
import static org.onosproject.store.resource.impl.ConsistentResourceStore.RETRY_DELAY;
import static org.onosproject.store.resource.impl.ConsistentResourceStore.SERIALIZER;
-import static org.onosproject.store.resource.impl.ResourceStoreUtil.hasEnoughResource;
+import static org.onosproject.store.resource.impl.ContinuousResourceAllocation.hasEnoughResource;
class ConsistentContinuousResourceStore {
private ConsistentMap<ContinuousResourceId, ContinuousResourceAllocation> consumers;
diff --git a/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ContinuousResourceAllocation.java b/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ContinuousResourceAllocation.java
index 16488f1..c23866d 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ContinuousResourceAllocation.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ContinuousResourceAllocation.java
@@ -36,6 +36,32 @@
this.allocations = allocations;
}
+ /**
+ * Checks if there is enough resource volume to allocated the requested resource
+ * against the specified resource.
+ *
+ * @param original original resource
+ * @param request requested resource
+ * @param allocation current allocation of the resource
+ * @return true if there is enough resource volume. Otherwise, false.
+ */
+ // computational complexity: O(n) where n is the number of allocations
+ static boolean hasEnoughResource(ContinuousResource original,
+ ContinuousResource request,
+ ContinuousResourceAllocation allocation) {
+ if (allocation == null) {
+ return request.value() <= original.value();
+ }
+
+ double allocated = allocation.allocations().stream()
+ .filter(x -> x.resource() instanceof ContinuousResource)
+ .map(x -> (ContinuousResource) x.resource())
+ .mapToDouble(ContinuousResource::value)
+ .sum();
+ double left = original.value() - allocated;
+ return request.value() <= left;
+ }
+
ContinuousResource original() {
return original;
}
diff --git a/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ResourceStoreUtil.java b/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ResourceStoreUtil.java
deleted file mode 100644
index 55d5c12..0000000
--- a/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ResourceStoreUtil.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.store.resource.impl;
-
-import org.onosproject.net.resource.ContinuousResource;
-
-final class ResourceStoreUtil {
- // prohibit construction
- private ResourceStoreUtil() {}
-
- /**
- * Checks if there is enough resource volume to allocated the requested resource
- * against the specified resource.
- *
- * @param original original resource
- * @param request requested resource
- * @param allocation current allocation of the resource
- * @return true if there is enough resource volume. Otherwise, false.
- */
- // computational complexity: O(n) where n is the number of allocations
- static boolean hasEnoughResource(ContinuousResource original,
- ContinuousResource request,
- ContinuousResourceAllocation allocation) {
- if (allocation == null) {
- return request.value() <= original.value();
- }
-
- double allocated = allocation.allocations().stream()
- .filter(x -> x.resource() instanceof ContinuousResource)
- .map(x -> (ContinuousResource) x.resource())
- .mapToDouble(ContinuousResource::value)
- .sum();
- double left = original.value() - allocated;
- return request.value() <= left;
- }
-}
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 c8b6c20..34478f6 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
@@ -35,7 +35,7 @@
import static com.google.common.base.Preconditions.checkArgument;
import static org.onosproject.store.resource.impl.ConsistentResourceStore.SERIALIZER;
-import static org.onosproject.store.resource.impl.ResourceStoreUtil.hasEnoughResource;
+import static org.onosproject.store.resource.impl.ContinuousResourceAllocation.hasEnoughResource;
class TransactionalContinuousResourceStore {
private final Logger log = LoggerFactory.getLogger(getClass());