summaryrefslogtreecommitdiffstats
path: root/resource-assignment/provider
diff options
context:
space:
mode:
Diffstat (limited to 'resource-assignment/provider')
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/alloc/DbAllocationRule.java267
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/EndPointAllocatorImpl.java3
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/rule/dao/RangeRuleDaoImpl.java50
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/rule/data/RangeRule.java7
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/comp/AllocationFunction.java86
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/data/Range.java28
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/data/RangeAllocationRequest.java4
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/util/RangeUtil.java43
-rw-r--r--resource-assignment/provider/src/test/resources/sql/data.sql42
-rw-r--r--resource-assignment/provider/src/test/resources/sql/schema.sql4
10 files changed, 321 insertions, 213 deletions
diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/alloc/DbAllocationRule.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/alloc/DbAllocationRule.java
index e9f6e0d3..af6a2801 100644
--- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/alloc/DbAllocationRule.java
+++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/alloc/DbAllocationRule.java
@@ -36,6 +36,7 @@ import org.onap.ccsdk.sli.adaptors.rm.data.AllocationAction;
import org.onap.ccsdk.sli.adaptors.rm.data.AllocationRequest;
import org.onap.ccsdk.sli.adaptors.rm.data.LimitAllocationRequest;
import org.onap.ccsdk.sli.adaptors.rm.data.MultiResourceAllocationRequest;
+import org.onap.ccsdk.sli.adaptors.rm.data.Range;
import org.onap.ccsdk.sli.adaptors.rm.data.RangeAllocationRequest;
import org.onap.ccsdk.sli.adaptors.util.expr.ExpressionEvaluator;
import org.onap.ccsdk.sli.adaptors.util.str.StrUtil;
@@ -44,127 +45,147 @@ import org.slf4j.LoggerFactory;
public class DbAllocationRule implements AllocationRule {
- private static final Logger log = LoggerFactory.getLogger(DbAllocationRule.class);
-
- private ResourceRuleDao resourceRuleDao;
- private RangeRuleDao rangeRuleDao;
-
- @Override
- public AllocationRequest buildAllocationRequest(String serviceModel, ResourceEntity resourceEntity,
- ResourceTarget resourceTarget, ResourceRequest resourceRequest, boolean checkOnly, boolean change) {
- List<ResourceRule> resourceRuleList = resourceRuleDao.getResourceRules(serviceModel,
- resourceTarget.resourceTargetType);
- List<RangeRule> rangeRuleList = rangeRuleDao.getRangeRules(serviceModel, resourceTarget.resourceTargetType);
-
- List<AllocationRequest> arlist = new ArrayList<>();
-
- for (ResourceRule rr : resourceRuleList) {
- if (resourceRequest.resourceName != null && !resourceRequest.resourceName.equals(rr.resourceName)) {
- continue;
- }
-
- boolean matches = ExpressionEvaluator.evalBoolean(rr.serviceExpression, resourceEntity.data);
- matches = matches && ExpressionEvaluator.evalBoolean(rr.equipmentExpression, resourceTarget.data);
-
- if (matches) {
- AllocationRequest ar1 = buildAllocationRequest(rr, resourceEntity, resourceTarget, resourceRequest,
- checkOnly, change);
- arlist.add(ar1);
- }
- }
-
- for (RangeRule rr : rangeRuleList) {
- if (resourceRequest.resourceName != null && !resourceRequest.resourceName.equals(rr.rangeName)) {
- continue;
- }
- if (resourceRequest.endPointPosition != null
- && !resourceRequest.endPointPosition.equals(rr.endPointPosition)) {
- continue;
- }
-
- AllocationRequest ar1 = buildAllocationRequest(rr, resourceEntity, resourceTarget, resourceRequest,
- checkOnly, change);
- arlist.add(ar1);
- }
-
- if (arlist.isEmpty()) {
- return null;
- }
-
- if (arlist.size() == 1) {
- return arlist.get(0);
- }
-
- MultiResourceAllocationRequest ar = new MultiResourceAllocationRequest();
- ar.stopOnFirstFailure = false;
- ar.allocationRequestList = arlist;
- return ar;
- }
-
- private AllocationRequest buildAllocationRequest(ResourceRule resourceRule, ResourceEntity resourceEntity,
- ResourceTarget resourceTarget, ResourceRequest resourceRequest, boolean checkOnly, boolean change) {
- StrUtil.info(log, resourceRule);
-
- LimitAllocationRequest ar = new LimitAllocationRequest();
- ar.applicationId = resourceRequest.applicationId;
- ar.resourceUnionId = resourceEntity.resourceEntityType + "::" + resourceEntity.resourceEntityId;
- ar.resourceSetId = ar.resourceUnionId + "::" + resourceEntity.resourceEntityVersion;
- ar.resourceName = resourceRule.resourceName;
- if (resourceRequest.resourceShareGroup != null) {
- ar.resourceShareGroupList = Collections.singleton(resourceRequest.resourceShareGroup);
- }
- ar.assetId = resourceTarget.resourceTargetType + "::" + resourceTarget.resourceTargetId;
- ar.missingResourceAction = AllocationAction.Succeed_Allocate;
- ar.expiredResourceAction = AllocationAction.Succeed_Allocate;
- ar.replace = resourceRequest.replace;
- ar.strict = false;
- ar.checkLimit = ExpressionEvaluator.evalLong(
- change ? resourceRule.hardLimitExpression : resourceRule.softLimitExpression, resourceTarget.data);
- ar.checkCount = ExpressionEvaluator.evalLong(resourceRule.allocationExpression, resourceEntity.data);
- ar.allocateCount = checkOnly ? 0 : ar.checkCount;
- return ar;
- }
-
- private AllocationRequest buildAllocationRequest(RangeRule rangeRule, ResourceEntity resourceEntity,
- ResourceTarget resourceTarget, ResourceRequest resourceRequest, boolean checkOnly, boolean change) {
- StrUtil.info(log, rangeRule);
-
- RangeAllocationRequest ar = new RangeAllocationRequest();
- ar.applicationId = resourceRequest.applicationId;
- if (resourceRequest.endPointPosition != null) {
- ar.resourceUnionId = resourceEntity.resourceEntityType + "::" + resourceEntity.resourceEntityId + "::"
- + resourceRequest.endPointPosition;
- ar.endPointPosition = resourceRequest.endPointPosition;
- }else
- ar.resourceUnionId = resourceEntity.resourceEntityType + "::" + resourceEntity.resourceEntityId;
- ar.resourceSetId = ar.resourceUnionId + "::" + resourceEntity.resourceEntityVersion;
- ar.resourceName = rangeRule.rangeName;
- if (resourceRequest.resourceShareGroup != null) {
- ar.resourceShareGroupList = Collections.singleton(resourceRequest.resourceShareGroup);
- }
- ar.assetId = resourceTarget.resourceTargetType + "::" + resourceTarget.resourceTargetId;
- ar.requestedNumbers = StrUtil.listInt(resourceRequest.rangeRequestedNumbers,
- "Invalid value for requested-numbers");
- if (ar.requestedNumbers != null) {
- ar.requestedCount = ar.requestedNumbers.size();
- }
- ar.excludeNumbers = StrUtil.listInt(resourceRequest.rangeExcludeNumbers, "Invalid value for exclude-numbers");
- ar.reverseOrder = resourceRequest.rangeReverseOrder;
- ar.missingResourceAction = AllocationAction.Succeed_Allocate;
- ar.expiredResourceAction = AllocationAction.Succeed_Allocate;
- ar.replace = resourceRequest.replace;
- ar.check = true;
- ar.allocate = !checkOnly;
- ar.checkMin = resourceRequest.rangeMinOverride >= 0 ? resourceRequest.rangeMinOverride : rangeRule.minValue;
- ar.checkMax = resourceRequest.rangeMaxOverride >= 0 ? resourceRequest.rangeMaxOverride : rangeRule.maxValue;
- return ar;
- }
-
- public void setResourceRuleDao(ResourceRuleDao resourceRuleDao) {
- this.resourceRuleDao = resourceRuleDao;
- }
-
- public void setRangeRuleDao(RangeRuleDao rangeRuleDao) {
- this.rangeRuleDao = rangeRuleDao;
- }
+ private static final Logger log = LoggerFactory.getLogger(DbAllocationRule.class);
+
+ private ResourceRuleDao resourceRuleDao;
+ private RangeRuleDao rangeRuleDao;
+
+ @Override
+ public AllocationRequest buildAllocationRequest(String serviceModel, ResourceEntity resourceEntity,
+ ResourceTarget resourceTarget, ResourceRequest resourceRequest, boolean checkOnly, boolean change) {
+ List<ResourceRule> resourceRuleList = resourceRuleDao.getResourceRules(serviceModel,
+ resourceTarget.resourceTargetType);
+ List<RangeRule> rangeRuleList = rangeRuleDao.getRangeRules(serviceModel, resourceTarget.resourceTargetType);
+
+ List<AllocationRequest> arlist = new ArrayList<>();
+
+ for (ResourceRule rr : resourceRuleList) {
+ if (resourceRequest.resourceName != null && !resourceRequest.resourceName.equals(rr.resourceName)) {
+ continue;
+ }
+
+ boolean matches = ExpressionEvaluator.evalBoolean(rr.serviceExpression, resourceEntity.data);
+ matches = matches && ExpressionEvaluator.evalBoolean(rr.equipmentExpression, resourceTarget.data);
+
+ if (matches) {
+ AllocationRequest ar1 = buildAllocationRequest(rr, resourceEntity, resourceTarget, resourceRequest,
+ checkOnly, change);
+ arlist.add(ar1);
+ }
+ }
+
+ for (RangeRule rr : rangeRuleList) {
+ if (resourceRequest.resourceName != null && !resourceRequest.resourceName.equals(rr.rangeName)) {
+ continue;
+ }
+ if (resourceRequest.endPointPosition != null
+ && !resourceRequest.endPointPosition.equals(rr.endPointPosition)) {
+ continue;
+ }
+
+ if (!ExpressionEvaluator.evalBoolean(rr.equipmentExpression, resourceTarget.data)) {
+ continue;
+ }
+
+ AllocationRequest ar1 = buildAllocationRequest(rr, resourceEntity, resourceTarget, resourceRequest,
+ checkOnly, change);
+ arlist.add(ar1);
+ }
+
+ if (arlist.isEmpty()) {
+ return null;
+ }
+
+ if (arlist.size() == 1) {
+ return arlist.get(0);
+ }
+
+ MultiResourceAllocationRequest ar = new MultiResourceAllocationRequest();
+ ar.stopOnFirstFailure = false;
+ ar.allocationRequestList = arlist;
+ return ar;
+ }
+
+ private AllocationRequest buildAllocationRequest(ResourceRule resourceRule, ResourceEntity resourceEntity,
+ ResourceTarget resourceTarget, ResourceRequest resourceRequest, boolean checkOnly, boolean change) {
+ StrUtil.info(log, resourceRule);
+
+ LimitAllocationRequest ar = new LimitAllocationRequest();
+ ar.applicationId = resourceRequest.applicationId;
+ ar.resourceUnionId = resourceEntity.resourceEntityType + "::" + resourceEntity.resourceEntityId;
+ ar.resourceSetId = ar.resourceUnionId + "::" + resourceEntity.resourceEntityVersion;
+ ar.resourceName = resourceRule.resourceName;
+ if (resourceRequest.resourceShareGroup != null) {
+ ar.resourceShareGroupList = Collections.singleton(resourceRequest.resourceShareGroup);
+ }
+ ar.assetId = resourceTarget.resourceTargetType + "::" + resourceTarget.resourceTargetId;
+ ar.missingResourceAction = AllocationAction.Succeed_Allocate;
+ ar.expiredResourceAction = AllocationAction.Succeed_Allocate;
+ ar.replace = resourceRequest.replace;
+ ar.strict = false;
+ ar.checkLimit = ExpressionEvaluator.evalLong(
+ change ? resourceRule.hardLimitExpression : resourceRule.softLimitExpression, resourceTarget.data);
+ ar.checkCount = ExpressionEvaluator.evalLong(resourceRule.allocationExpression, resourceEntity.data);
+ ar.allocateCount = checkOnly ? 0 : ar.checkCount;
+ return ar;
+ }
+
+ private AllocationRequest buildAllocationRequest(RangeRule rangeRule, ResourceEntity resourceEntity,
+ ResourceTarget resourceTarget, ResourceRequest resourceRequest, boolean checkOnly, boolean change) {
+ StrUtil.info(log, rangeRule);
+
+ RangeAllocationRequest ar = new RangeAllocationRequest();
+ ar.applicationId = resourceRequest.applicationId;
+ if (resourceRequest.endPointPosition != null) {
+ ar.resourceUnionId = resourceEntity.resourceEntityType + "::" + resourceEntity.resourceEntityId + "::"
+ + resourceRequest.endPointPosition;
+ ar.endPointPosition = resourceRequest.endPointPosition;
+ } else {
+ ar.resourceUnionId = resourceEntity.resourceEntityType + "::" + resourceEntity.resourceEntityId;
+ }
+ ar.resourceSetId = ar.resourceUnionId + "::" + resourceEntity.resourceEntityVersion;
+ ar.resourceName = rangeRule.rangeName;
+ if (resourceRequest.resourceShareGroup != null) {
+ ar.resourceShareGroupList = Collections.singleton(resourceRequest.resourceShareGroup);
+ }
+ ar.assetId = resourceTarget.resourceTargetType + "::" + resourceTarget.resourceTargetId;
+ ar.requestedNumbers = StrUtil.listInt(resourceRequest.rangeRequestedNumbers,
+ "Invalid value for requested-numbers");
+ if (ar.requestedNumbers != null) {
+ ar.requestedCount = ar.requestedNumbers.size();
+ }
+ ar.excludeNumbers = StrUtil.listInt(resourceRequest.rangeExcludeNumbers, "Invalid value for exclude-numbers");
+ ar.reverseOrder = resourceRequest.rangeReverseOrder;
+ ar.missingResourceAction = AllocationAction.Succeed_Allocate;
+ ar.expiredResourceAction = AllocationAction.Succeed_Allocate;
+ ar.replace = resourceRequest.replace;
+ ar.check = true;
+ ar.allocate = !checkOnly;
+ ar.rangeList = rangeRule.rangeList;
+ if (ar.rangeList == null || ar.rangeList.isEmpty()) {
+ if (resourceRequest.rangeMinOverride >= 0 && resourceRequest.rangeMaxOverride >= resourceRequest.rangeMinOverride) {
+ ar.rangeList = new ArrayList<>();
+ Range range = new Range();
+ range.min = resourceRequest.rangeMinOverride;
+ range.max = resourceRequest.rangeMaxOverride;
+ ar.rangeList.add(range);
+ }
+ } else {
+ if (resourceRequest.rangeMinOverride >= 0) {
+ ar.rangeList.get(0).min = resourceRequest.rangeMinOverride;
+ }
+ if (resourceRequest.rangeMaxOverride >= 0) {
+ ar.rangeList.get(ar.rangeList.size() - 1).max = resourceRequest.rangeMaxOverride;
+ }
+ }
+ return ar;
+ }
+
+ public void setResourceRuleDao(ResourceRuleDao resourceRuleDao) {
+ this.resourceRuleDao = resourceRuleDao;
+ }
+
+ public void setRangeRuleDao(RangeRuleDao rangeRuleDao) {
+ this.rangeRuleDao = rangeRuleDao;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/EndPointAllocatorImpl.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/EndPointAllocatorImpl.java
index e904035b..952ceb6b 100644
--- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/EndPointAllocatorImpl.java
+++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/EndPointAllocatorImpl.java
@@ -46,9 +46,8 @@ import org.slf4j.LoggerFactory;
public class EndPointAllocatorImpl implements EndPointAllocator {
- @SuppressWarnings("unused")
private static final Logger log = LoggerFactory.getLogger(EndPointAllocatorImpl.class);
-
+
private ResourceManager resourceManager;
private Map<String, List<AllocationRule>> allocationRuleMap;
diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/rule/dao/RangeRuleDaoImpl.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/rule/dao/RangeRuleDaoImpl.java
index 825261ef..caac1c96 100644
--- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/rule/dao/RangeRuleDaoImpl.java
+++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/rule/dao/RangeRuleDaoImpl.java
@@ -21,10 +21,10 @@
package org.onap.ccsdk.sli.adaptors.ra.rule.dao;
-import java.sql.ResultSet;
-import java.sql.SQLException;
+import java.util.ArrayList;
import java.util.List;
import org.onap.ccsdk.sli.adaptors.ra.rule.data.RangeRule;
+import org.onap.ccsdk.sli.adaptors.rm.data.Range;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
@@ -42,20 +42,42 @@ public class RangeRuleDaoImpl implements RangeRuleDao {
@Override
public List<RangeRule> getRangeRules(String serviceModel, String equipLevel) {
List<RangeRule> rangeRuleList =
- jdbcTemplate.query(GET_SQL, new Object[] {serviceModel, equipLevel}, new RowMapper<RangeRule>() {
+ jdbcTemplate.query(GET_SQL, new Object[] {serviceModel, equipLevel}, (RowMapper<RangeRule>) (rs, rowNum) -> {
+ RangeRule rl = new RangeRule();
+ rl.id = rs.getLong("range_rule_id");
+ rl.rangeName = rs.getString("range_name");
+ rl.serviceModel = rs.getString("service_model");
+ rl.endPointPosition = rs.getString("end_point_position");
+ rl.equipmentLevel = rs.getString("equipment_level");
+ rl.equipmentExpression = rs.getString("equipment_expression");
- @Override
- public RangeRule mapRow(ResultSet rs, int rowNum) throws SQLException {
- RangeRule rl = new RangeRule();
- rl.id = rs.getLong("range_rule_id");
- rl.rangeName = rs.getString("range_name");
- rl.serviceModel = rs.getString("service_model");
- rl.endPointPosition = rs.getString("end_point_position");
- rl.equipmentLevel = rs.getString("equipment_level");
- rl.minValue = rs.getInt("min_value");
- rl.maxValue = rs.getInt("max_value");
- return rl;
+ String rangesStr = rs.getString("ranges");
+ String[] ranges = rangesStr.split(",");
+ rl.rangeList = new ArrayList<>();
+ for (String rangeStr : ranges) {
+ Range range = new Range();
+ String[] nn = rangeStr.split("-");
+ if (nn.length >= 1) {
+ try {
+ range.min = range.max = Integer.parseInt(nn[0]);
+ } catch (NumberFormatException e) {
+ log.warn("Invalid value found in DB for range: " + rangeStr, e);
+ }
+ }
+ if (nn.length >= 2) {
+ try {
+ range.max = Integer.parseInt(nn[1]);
+ } catch (NumberFormatException e) {
+ log.warn("Invalid value found in DB for range: " + rangeStr, e);
+ }
+ }
+ if (nn.length > 2) {
+ log.warn("Invalid value found in DB for range: " + rangeStr);
+ }
+ rl.rangeList.add(range);
}
+
+ return rl;
});
return rangeRuleList;
}
diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/rule/data/RangeRule.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/rule/data/RangeRule.java
index 383c2830..c1ccd819 100644
--- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/rule/data/RangeRule.java
+++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/rule/data/RangeRule.java
@@ -21,6 +21,9 @@
package org.onap.ccsdk.sli.adaptors.ra.rule.data;
+import java.util.List;
+import org.onap.ccsdk.sli.adaptors.rm.data.Range;
+
public class RangeRule {
public long id;
@@ -28,6 +31,6 @@ public class RangeRule {
public String serviceModel;
public String endPointPosition;
public String equipmentLevel;
- public int minValue;
- public int maxValue;
+ public String equipmentExpression;
+ public List<Range> rangeList;
}
diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/comp/AllocationFunction.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/comp/AllocationFunction.java
index 3544075f..9cae5fee 100644
--- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/comp/AllocationFunction.java
+++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/comp/AllocationFunction.java
@@ -46,6 +46,7 @@ import org.onap.ccsdk.sli.adaptors.rm.data.MultiAssetAllocationOutcome;
import org.onap.ccsdk.sli.adaptors.rm.data.MultiAssetAllocationRequest;
import org.onap.ccsdk.sli.adaptors.rm.data.MultiResourceAllocationOutcome;
import org.onap.ccsdk.sli.adaptors.rm.data.MultiResourceAllocationRequest;
+import org.onap.ccsdk.sli.adaptors.rm.data.Range;
import org.onap.ccsdk.sli.adaptors.rm.data.RangeAllocationOutcome;
import org.onap.ccsdk.sli.adaptors.rm.data.RangeAllocationRequest;
import org.onap.ccsdk.sli.adaptors.rm.data.RangeResource;
@@ -283,24 +284,40 @@ class AllocationFunction extends SynchronizedFunction {
// alignBlockSize and alignModulus are ignored. It would be harder
// to take them into account, and currently it is not needed.
- int uumin = uu.first() - 1;
- int uumax = uu.last() + 1;
- foundNumbers.addAll(uu);
- foundCount = uu.size();
- for (int n = uumin; foundCount < req.requestedCount && n >= req.checkMin; n--) {
- if (RangeUtil.checkRange(rr, req, n)) {
- foundNumbers.add(n);
- foundCount++;
- } else if (req.sequential) {
- break;
+ // Request may contain multiple ranges. We will find the range from the request
+ // that contains the currently used numbers (the first one). We will only look
+ // for additional numbers in that range.
+
+ Range range = null;
+ if (req.rangeList != null) {
+ for (Range range1 : req.rangeList) {
+ if (uu.first() >= range1.min && uu.first() <= range1.max) {
+ range = range1;
+ break;
+ }
}
}
- for (int n = uumax; foundCount < req.requestedCount && n <= req.checkMax; n++) {
- if (RangeUtil.checkRange(rr, req, n)) {
- foundNumbers.add(n);
- foundCount++;
- } else if (req.sequential) {
- break;
+
+ if (range != null) {
+ int uumin = uu.first() - 1;
+ int uumax = uu.last() + 1;
+ foundNumbers.addAll(uu);
+ foundCount = uu.size();
+ for (int n = uumin; foundCount < req.requestedCount && n >= range.min; n--) {
+ if (RangeUtil.checkRange(rr, req, n)) {
+ foundNumbers.add(n);
+ foundCount++;
+ } else if (req.sequential) {
+ break;
+ }
+ }
+ for (int n = uumax; foundCount < req.requestedCount && n <= range.max; n++) {
+ if (RangeUtil.checkRange(rr, req, n)) {
+ foundNumbers.add(n);
+ foundCount++;
+ } else if (req.sequential) {
+ break;
+ }
}
}
@@ -314,22 +331,29 @@ class AllocationFunction extends SynchronizedFunction {
}
}
- if (req.reverseOrder) {
- for (int n = req.checkMax; foundCount < req.requestedCount && n >= req.checkMin; n--) {
- if (RangeUtil.checkRange(rr, req, n)) {
- foundNumbers.add(n);
- foundCount++;
- } else if (req.sequential) {
- foundCount = 0;
+ if (req.rangeList != null) {
+ if (req.reverseOrder) {
+ for (int i = req.rangeList.size() - 1; i >= 0; i--) {
+ Range range = req.rangeList.get(i);
+ for (int n = range.max; foundCount < req.requestedCount && n >= range.min; n--) {
+ if (RangeUtil.checkRange(rr, req, n)) {
+ foundNumbers.add(n);
+ foundCount++;
+ } else if (req.sequential) {
+ foundCount = 0;
+ }
+ }
}
- }
- } else {
- for (int n = req.checkMin; foundCount < req.requestedCount && n <= req.checkMax; n++) {
- if (RangeUtil.checkRange(rr, req, n)) {
- foundNumbers.add(n);
- foundCount++;
- } else if (req.sequential) {
- foundCount = 0;
+ } else {
+ for (Range range : req.rangeList) {
+ for (int n = range.min; foundCount < req.requestedCount && n <= range.max; n++) {
+ if (RangeUtil.checkRange(rr, req, n)) {
+ foundNumbers.add(n);
+ foundCount++;
+ } else if (req.sequential) {
+ foundCount = 0;
+ }
+ }
}
}
}
diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/data/Range.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/data/Range.java
new file mode 100644
index 00000000..16be77f5
--- /dev/null
+++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/data/Range.java
@@ -0,0 +1,28 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.ccsdk.sli.adaptors.rm.data;
+
+public class Range {
+
+ public int min = 0;
+ public int max = 0;
+}
diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/data/RangeAllocationRequest.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/data/RangeAllocationRequest.java
index 9581244b..d87469fd 100644
--- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/data/RangeAllocationRequest.java
+++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/data/RangeAllocationRequest.java
@@ -21,12 +21,12 @@
package org.onap.ccsdk.sli.adaptors.rm.data;
+import java.util.List;
import java.util.SortedSet;
public class RangeAllocationRequest extends AllocationRequest {
- public int checkMin = 0;
- public int checkMax = 0;
+ public List<Range> rangeList = null;
public boolean check = false;
public boolean allocate = false;
public boolean replace = false;
diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/util/RangeUtil.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/util/RangeUtil.java
index 04f6e8c5..4685233d 100644
--- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/util/RangeUtil.java
+++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/util/RangeUtil.java
@@ -27,6 +27,7 @@ import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import org.onap.ccsdk.sli.adaptors.rm.data.AllocationItem;
+import org.onap.ccsdk.sli.adaptors.rm.data.Range;
import org.onap.ccsdk.sli.adaptors.rm.data.RangeAllocationItem;
import org.onap.ccsdk.sli.adaptors.rm.data.RangeAllocationRequest;
import org.onap.ccsdk.sli.adaptors.rm.data.RangeResource;
@@ -48,27 +49,43 @@ public class RangeUtil {
}
public static boolean checkRange(RangeResource r, RangeAllocationRequest req, int num) {
- if (num < req.checkMin || num > req.checkMax) {
- return false;
- }
-
if (req.excludeNumbers != null && req.excludeNumbers.contains(num)) {
return false;
}
- if (r.allocationItems != null) {
- for (AllocationItem ai : r.allocationItems) {
- RangeAllocationItem rai = (RangeAllocationItem) ai;
- if (!eq(req.resourceUnionId, rai.resourceUnionId) && rai.used != null && rai.used.contains(num)) {
- if (!overlap(rai.resourceShareGroupList, req.resourceShareGroupList)) {
- return false;
+ if (req.rangeList != null && !req.rangeList.isEmpty()) {
+ boolean good = false;
+ for (Range range : req.rangeList) {
+ if (num < range.min || num > range.min) {
+ continue;
+ }
+
+ boolean found = false;
+ if (r.allocationItems != null) {
+ for (AllocationItem ai : r.allocationItems) {
+ RangeAllocationItem rai = (RangeAllocationItem) ai;
+ if (!eq(req.resourceUnionId, rai.resourceUnionId) && rai.used != null
+ && rai.used.contains(num)) {
+ if (!overlap(rai.resourceShareGroupList, req.resourceShareGroupList)) {
+ found = true;
+ break;
+ }
+ }
+ if (!req.replace && eq(req.resourceSetId, rai.resourceSetId) && rai.used != null
+ && rai.used.contains(num)) {
+ found = true;
+ break;
+ }
}
}
- if (!req.replace && eq(req.resourceSetId, rai.resourceSetId) && rai.used != null
- && rai.used.contains(num)) {
- return false;
+
+ if (!found) {
+ good = true;
+ break;
}
}
+
+ return good;
}
return true;
diff --git a/resource-assignment/provider/src/test/resources/sql/data.sql b/resource-assignment/provider/src/test/resources/sql/data.sql
index 681a9c45..236a16d1 100644
--- a/resource-assignment/provider/src/test/resources/sql/data.sql
+++ b/resource-assignment/provider/src/test/resources/sql/data.sql
@@ -80,19 +80,19 @@ values (
'The provisioned access bandwidth is at or exceeds 70% of the total server capacity.');
INSERT INTO RANGE_RULE (
- range_name, service_model, end_point_position, equipment_level, min_value, max_value)
+ range_name, service_model, end_point_position, equipment_level, equipment_expression, ranges)
VALUES (
- 'subinterface-id', 'L3AVPN-EVC', 'VPE-Cust', 'Port', 100, 3999);
+ 'subinterface-id', 'L3AVPN-EVC', 'VPE-Cust', 'Port', 'true', '100-3999');
INSERT INTO RANGE_RULE (
- range_name, service_model, end_point_position, equipment_level, min_value, max_value)
+ range_name, service_model, end_point_position, equipment_level, equipment_expression, ranges)
VALUES (
- 'vlan-id-inner', 'L3AVPN-EVC', 'VPE-Cust', 'Port', 2, 4091);
+ 'vlan-id-inner', 'L3AVPN-EVC', 'VPE-Cust', 'Port', 'true', '2-4091');
INSERT INTO RANGE_RULE (
- range_name, service_model, end_point_position, equipment_level, min_value, max_value)
+ range_name, service_model, end_point_position, equipment_level, equipment_expression, ranges)
VALUES (
- 'bundle-id', 'L3AVPN-PORT', 'VPE-Cust', 'Port', 1, 99999);
+ 'bundle-id', 'L3AVPN-PORT', 'VPE-Cust', 'Port', 'true', '1-99999');
INSERT INTO MAX_PORT_SPEED (
image_file_name, end_point_position, interface_name, max_speed, unit)
@@ -148,39 +148,33 @@ VALUES (
'1', '200', '200');
INSERT INTO RANGE_RULE (
- range_name, service_model, end_point_position, equipment_level, min_value,
- max_value)
+ range_name, service_model, end_point_position, equipment_level, equipment_expression, ranges)
VALUES (
- 'cust-vlan-id', 'ADIG', 'VPE', 'VNF', '2', '1000');
+ 'cust-vlan-id', 'ADIG', 'VPE', 'VNF', 'true', '2-1000');
INSERT INTO RANGE_RULE (
- range_name, service_model, end_point_position, equipment_level, min_value,
- max_value)
+ range_name, service_model, end_point_position, equipment_level, equipment_expression, ranges)
VALUES (
- 'vlan-id-inner', 'ADIG', 'VPE', 'VNF', '1002', '2000');
+ 'vlan-id-inner', 'ADIG', 'VPE', 'VNF', 'true', '1002-2000');
INSERT INTO RANGE_RULE (
- range_name, service_model, end_point_position, equipment_level, min_value,
- max_value)
+ range_name, service_model, end_point_position, equipment_level, equipment_expression, ranges)
VALUES (
- 'vlan-id-outer', 'MY-SERV-MODEL', 'VPE-Cust', 'Site', '2', '1000');
+ 'vlan-id-outer', 'MY-SERV-MODEL', 'VPE-Cust', 'Site', 'true', '2-1000');
INSERT INTO RANGE_RULE (
- range_name, service_model, end_point_position, equipment_level, min_value,
- max_value)
+ range_name, service_model, end_point_position, equipment_level, equipment_expression, ranges)
VALUES (
- 'vlan-id-filter', 'MY-SERV-MODEL', 'VPE-Core1', 'Site', '1002', '2000');
+ 'vlan-id-filter', 'MY-SERV-MODEL', 'VPE-Core1', 'Site', 'true', '1002-2000');
INSERT INTO RANGE_RULE (
- range_name, service_model, end_point_position, equipment_level, min_value,
- max_value)
+ range_name, service_model, end_point_position, equipment_level, equipment_expression, ranges)
VALUES (
- 'vlan-id-filter', 'MY-SERV-MODEL', 'VPE-Core2', 'Site', '1002', '2000');
+ 'vlan-id-filter', 'MY-SERV-MODEL', 'VPE-Core2', 'Site', 'true', '1002-2000,2200-4000');
INSERT INTO RANGE_RULE (
- range_name, service_model, end_point_position, equipment_level, min_value,
- max_value)
+ range_name, service_model, end_point_position, equipment_level, equipment_expression, ranges)
VALUES (
- 'vlan-id-filter', 'MY-SERV-MODEL', 'VPE-Core3', 'Site', '400', '600');
+ 'vlan-id-filter', 'MY-SERV-MODEL', 'VPE-Core3', 'Site', 'true', '400-600');
\ No newline at end of file
diff --git a/resource-assignment/provider/src/test/resources/sql/schema.sql b/resource-assignment/provider/src/test/resources/sql/schema.sql
index 40761de4..ed123ddd 100644
--- a/resource-assignment/provider/src/test/resources/sql/schema.sql
+++ b/resource-assignment/provider/src/test/resources/sql/schema.sql
@@ -96,8 +96,8 @@ CREATE TABLE RANGE_RULE (
service_model VARCHAR(50) NOT NULL,
end_point_position VARCHAR(50) NOT NULL,
equipment_level VARCHAR(50) NOT NULL,
- min_value INT NOT NULL,
- max_value INT NOT NULL
+ equipment_expression VARCHAR(2000) NOT NULL,
+ ranges VARCHAR(100) NOT NULL
);
CREATE TABLE MAX_PORT_SPEED (