summaryrefslogtreecommitdiffstats
path: root/resource-assignment/provider/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'resource-assignment/provider/src/main/java/org')
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/lock/comp/LockHelper.java10
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/lock/comp/LockHelperImpl.java264
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/lock/comp/ResourceLockedException.java26
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/lock/comp/SynchronizedFunction.java54
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/lock/dao/ResourceLockDao.java16
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/lock/dao/ResourceLockDaoImpl.java156
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/lock/data/ResourceLock.java14
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/ReleaseRequestType.java36
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/ReserveRequestType.java32
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/ResourceAllocator.java1892
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/alloc/AffinityAllocationRule.java62
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/alloc/DbAllocationRule.java218
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/alloc/ServingSiteAllocationRule.java76
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/alloc/VrfAllocationRule.java128
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/AnyVrfPresentCheck.java62
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/ExcludeVpeCheck.java48
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/HubWithRgCheck.java138
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/OneMVrfCheck.java104
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/ProvStatusCheck.java30
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/VlanSpeedCheck.java32
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/VpeLockCheck.java148
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/AllocationRule.java18
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointAllocationDefinition.java50
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointAllocator.java14
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointAllocatorImpl.java336
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointData.java12
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EquipmentCheck.java12
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/PreferenceRule.java6
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/ServiceData.java18
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/comp/EquipmentReader.java4
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/ServerDao.java4
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/ServerDaoImpl.java46
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/VpePortDao.java6
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/VpePortDaoImpl.java74
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/VplspePortDao.java4
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/VplspePortDaoImpl.java58
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/data/EquipmentData.java8
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/data/EquipmentLevel.java4
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/pref/AffinityLinkPref.java76
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/pref/EvcExistingVrfPref.java42
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/reader/AicSiteReader.java24
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/reader/UplinkCircuitReader.java42
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/reader/VnfReader.java24
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/reader/VpePortReader.java60
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/comp/AllocationRequestBuilder.java20
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/comp/AllocationRequestBuilderImpl.java250
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/MaxPortSpeedDao.java6
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/MaxPortSpeedDaoImpl.java78
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/MaxServerSpeedDao.java6
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/MaxServerSpeedDaoImpl.java80
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/ParameterDao.java4
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/ParameterDaoImpl.java36
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/RangeRuleDao.java4
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/RangeRuleDaoImpl.java58
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/ResourceRuleDao.java14
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/ResourceRuleDaoImpl.java160
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/VpeLockDao.java4
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/VpeLockDaoImpl.java26
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/data/RangeRule.java16
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/data/ResourceRule.java24
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/data/ResourceThreshold.java6
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/data/ThresholdStatus.java14
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/service/dao/ServiceResourceDao.java12
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/service/dao/ServiceResourceDaoImpl.java148
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/service/data/ServiceResource.java14
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/service/data/ServiceStatus.java4
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/comp/AllocationFunction.java534
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/comp/ReleaseFunction.java84
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/comp/ResourceLoader.java12
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/comp/ResourceManager.java12
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/comp/ResourceManagerImpl.java178
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/ResourceDao.java12
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/AllocationItem.java20
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/AllocationItemJdbcDao.java10
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/AllocationItemJdbcDaoImpl.java170
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/Resource.java14
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/ResourceDaoImpl.java660
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/ResourceJdbcDao.java14
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/ResourceJdbcDaoImpl.java206
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/ResourceLoad.java12
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/ResourceLoadJdbcDao.java10
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/ResourceLoadJdbcDaoImpl.java142
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/AllocationAction.java4
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/AllocationItem.java16
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/AllocationOutcome.java6
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/AllocationRequest.java16
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/AllocationStatus.java4
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/InitAction.java18
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LabelAllocationItem.java4
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LabelAllocationOutcome.java6
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LabelAllocationRequest.java8
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LabelResource.java8
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LimitAllocationItem.java4
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LimitAllocationOutcome.java8
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LimitAllocationRequest.java12
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LimitResource.java4
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/MultiAssetAllocationOutcome.java6
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/MultiAssetAllocationRequest.java10
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/MultiResourceAllocationOutcome.java4
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/MultiResourceAllocationRequest.java6
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/RangeAllocationItem.java4
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/RangeAllocationOutcome.java6
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/RangeAllocationRequest.java18
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/RangeResource.java4
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/Resource.java10
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/ResourceKey.java44
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/ResourceLoad.java10
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/ResourceType.java4
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/util/LabelUtil.java104
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/util/LimitUtil.java586
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/util/RangeUtil.java126
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/util/ResourceUtil.java32
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/db/CachedDataSourceWrap.java174
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/db/ConnectionWrap.java588
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/db/DataSourceWrap.java96
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/expr/ExpressionEvaluator.java360
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/speed/SpeedUtil.java28
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/str/StrUtil.java532
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/vrf/VpnParam.java10
-rw-r--r--resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/vrf/VrfUtil.java84
120 files changed, 5263 insertions, 5263 deletions
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/lock/comp/LockHelper.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/lock/comp/LockHelper.java
index acdce65ec..5e179dc48 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/lock/comp/LockHelper.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/lock/comp/LockHelper.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,11 +25,11 @@ import java.util.Collection;
public interface LockHelper {
- void lock(String resourceName, String lockRequester, int lockTimeout /* Seconds */);
+ void lock(String resourceName, String lockRequester, int lockTimeout /* Seconds */);
- void unlock(String resourceName, boolean force);
+ void unlock(String resourceName, boolean force);
- void lock(Collection<String> resourceNameList, String lockRequester, int lockTimeout /* Seconds */);
+ void lock(Collection<String> resourceNameList, String lockRequester, int lockTimeout /* Seconds */);
- void unlock(Collection<String> resourceNameList, boolean force);
+ void unlock(Collection<String> resourceNameList, boolean force);
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/lock/comp/LockHelperImpl.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/lock/comp/LockHelperImpl.java
index 306fc162d..62b88c67a 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/lock/comp/LockHelperImpl.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/lock/comp/LockHelperImpl.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,135 +32,135 @@ import org.openecomp.sdnc.lock.data.ResourceLock;
public class LockHelperImpl implements LockHelper {
- private ResourceLockDao resourceLockDao;
- private int retryCount = 10;
- private int lockWait = 5; // Seconds
-
- @Override
- public void lock(String resourceName, String lockRequester, int lockTimeout /* Seconds */) {
- lock(Collections.singleton(resourceName), lockRequester, lockTimeout);
- }
-
- @Override
- public void unlock(String resourceName, boolean force) {
- unlock(Collections.singleton(resourceName), force);
- }
-
- @Override
- public void lock(Collection<String> resourceNameList, String lockRequester, int lockTimeout /* Seconds */) {
- for (int i = 0; true; i++) {
- try {
- tryLock(resourceNameList, lockRequester, lockTimeout);
- return;
- } catch (ResourceLockedException e) {
- if (i > retryCount)
- throw e;
- try {
- Thread.sleep(lockWait * 1000);
- } catch (InterruptedException ex) {
- }
- }
- }
- }
-
- @Override
- public void unlock(Collection<String> lockNames, boolean force) {
- if (lockNames == null || lockNames.size() == 0)
- return;
-
- resourceLockDao.lockTable();
-
- try {
- for (String name : lockNames) {
- ResourceLock l = resourceLockDao.getByResourceName(name);
- if (l != null)
- if (force || l.lockCount == 1)
- resourceLockDao.delete(l.id);
- else
- resourceLockDao.decrementLockCount(l.id);
- }
- } finally {
- resourceLockDao.unlockTable();
- }
- }
-
- public void tryLock(Collection<String> resourceNameList, String lockRequester, int lockTimeout /* Seconds */) {
- if (resourceNameList == null || resourceNameList.size() == 0)
- return;
-
- lockRequester = generateLockRequester(lockRequester, 100);
-
- resourceLockDao.lockTable();
-
- try {
- // First check if all requested records are available to lock
-
- Date now = new Date();
-
- List<ResourceLock> dbLockList = new ArrayList<ResourceLock>();
- List<String> insertLockNameList = new ArrayList<String>();
- for (String name : resourceNameList) {
- ResourceLock l = resourceLockDao.getByResourceName(name);
-
- boolean canLock =
- l == null || now.getTime() > l.expirationTime.getTime() || lockRequester != null &&
- lockRequester.equals(l.lockHolder) || l.lockCount <= 0;
- if (!canLock)
- throw new ResourceLockedException(l.resourceName, l.lockHolder, lockRequester);
-
- if (l != null)
- dbLockList.add(l);
- else
- insertLockNameList.add(name);
- }
-
- // Update the lock info in DB
- for (ResourceLock l : dbLockList)
- resourceLockDao.update(l.id, now, new Date(now.getTime() + lockTimeout * 1000), l.lockCount + 1);
-
- // Insert records for those that are not yet there
- for (String lockName : insertLockNameList) {
- ResourceLock l = new ResourceLock();
- l.resourceName = lockName;
- l.lockHolder = lockRequester;
- l.lockTime = now;
- l.expirationTime = new Date(now.getTime() + lockTimeout * 1000);
- l.lockCount = 1;
- resourceLockDao.add(l);
- }
- } finally {
- resourceLockDao.unlockTable();
- }
- }
-
- private static String generateLockRequester(String name, int maxLength) {
- if (name == null)
- name = "";
- int l1 = name.length();
- String tname = Thread.currentThread().getName();
- int l2 = tname.length();
- if (l1 + l2 + 1 > maxLength) {
- int maxl1 = maxLength / 2;
- if (l1 > maxl1) {
- name = name.substring(0, maxl1);
- l1 = maxl1;
- }
- int maxl2 = maxLength - l1 - 1;
- if (l2 > maxl2)
- tname = tname.substring(0, 6) + "..." + tname.substring(l2 - maxl2 + 9);
- }
- return tname + '-' + name;
- }
-
- public void setResourceLockDao(ResourceLockDao resourceLockDao) {
- this.resourceLockDao = resourceLockDao;
- }
-
- public void setRetryCount(int retryCount) {
- this.retryCount = retryCount;
- }
-
- public void setLockWait(int lockWait /* Seconds */) {
- this.lockWait = lockWait;
- }
+ private ResourceLockDao resourceLockDao;
+ private int retryCount = 10;
+ private int lockWait = 5; // Seconds
+
+ @Override
+ public void lock(String resourceName, String lockRequester, int lockTimeout /* Seconds */) {
+ lock(Collections.singleton(resourceName), lockRequester, lockTimeout);
+ }
+
+ @Override
+ public void unlock(String resourceName, boolean force) {
+ unlock(Collections.singleton(resourceName), force);
+ }
+
+ @Override
+ public void lock(Collection<String> resourceNameList, String lockRequester, int lockTimeout /* Seconds */) {
+ for (int i = 0; true; i++) {
+ try {
+ tryLock(resourceNameList, lockRequester, lockTimeout);
+ return;
+ } catch (ResourceLockedException e) {
+ if (i > retryCount)
+ throw e;
+ try {
+ Thread.sleep(lockWait * 1000);
+ } catch (InterruptedException ex) {
+ }
+ }
+ }
+ }
+
+ @Override
+ public void unlock(Collection<String> lockNames, boolean force) {
+ if (lockNames == null || lockNames.size() == 0)
+ return;
+
+ resourceLockDao.lockTable();
+
+ try {
+ for (String name : lockNames) {
+ ResourceLock l = resourceLockDao.getByResourceName(name);
+ if (l != null)
+ if (force || l.lockCount == 1)
+ resourceLockDao.delete(l.id);
+ else
+ resourceLockDao.decrementLockCount(l.id);
+ }
+ } finally {
+ resourceLockDao.unlockTable();
+ }
+ }
+
+ public void tryLock(Collection<String> resourceNameList, String lockRequester, int lockTimeout /* Seconds */) {
+ if (resourceNameList == null || resourceNameList.size() == 0)
+ return;
+
+ lockRequester = generateLockRequester(lockRequester, 100);
+
+ resourceLockDao.lockTable();
+
+ try {
+ // First check if all requested records are available to lock
+
+ Date now = new Date();
+
+ List<ResourceLock> dbLockList = new ArrayList<ResourceLock>();
+ List<String> insertLockNameList = new ArrayList<String>();
+ for (String name : resourceNameList) {
+ ResourceLock l = resourceLockDao.getByResourceName(name);
+
+ boolean canLock =
+ l == null || now.getTime() > l.expirationTime.getTime() || lockRequester != null &&
+ lockRequester.equals(l.lockHolder) || l.lockCount <= 0;
+ if (!canLock)
+ throw new ResourceLockedException(l.resourceName, l.lockHolder, lockRequester);
+
+ if (l != null)
+ dbLockList.add(l);
+ else
+ insertLockNameList.add(name);
+ }
+
+ // Update the lock info in DB
+ for (ResourceLock l : dbLockList)
+ resourceLockDao.update(l.id, now, new Date(now.getTime() + lockTimeout * 1000), l.lockCount + 1);
+
+ // Insert records for those that are not yet there
+ for (String lockName : insertLockNameList) {
+ ResourceLock l = new ResourceLock();
+ l.resourceName = lockName;
+ l.lockHolder = lockRequester;
+ l.lockTime = now;
+ l.expirationTime = new Date(now.getTime() + lockTimeout * 1000);
+ l.lockCount = 1;
+ resourceLockDao.add(l);
+ }
+ } finally {
+ resourceLockDao.unlockTable();
+ }
+ }
+
+ private static String generateLockRequester(String name, int maxLength) {
+ if (name == null)
+ name = "";
+ int l1 = name.length();
+ String tname = Thread.currentThread().getName();
+ int l2 = tname.length();
+ if (l1 + l2 + 1 > maxLength) {
+ int maxl1 = maxLength / 2;
+ if (l1 > maxl1) {
+ name = name.substring(0, maxl1);
+ l1 = maxl1;
+ }
+ int maxl2 = maxLength - l1 - 1;
+ if (l2 > maxl2)
+ tname = tname.substring(0, 6) + "..." + tname.substring(l2 - maxl2 + 9);
+ }
+ return tname + '-' + name;
+ }
+
+ public void setResourceLockDao(ResourceLockDao resourceLockDao) {
+ this.resourceLockDao = resourceLockDao;
+ }
+
+ public void setRetryCount(int retryCount) {
+ this.retryCount = retryCount;
+ }
+
+ public void setLockWait(int lockWait /* Seconds */) {
+ this.lockWait = lockWait;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/lock/comp/ResourceLockedException.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/lock/comp/ResourceLockedException.java
index 8e3142cc0..eb3f33418 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/lock/comp/ResourceLockedException.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/lock/comp/ResourceLockedException.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,19 +23,19 @@ package org.openecomp.sdnc.lock.comp;
public class ResourceLockedException extends RuntimeException {
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 1L;
- private String lockName, lockHolder, lockRequester;
+ private String lockName, lockHolder, lockRequester;
- public ResourceLockedException(String lockName, String lockHolder, String lockRequester) {
- this.lockName = lockName;
- this.lockHolder = lockHolder;
- this.lockRequester = lockRequester;
- }
+ public ResourceLockedException(String lockName, String lockHolder, String lockRequester) {
+ this.lockName = lockName;
+ this.lockHolder = lockHolder;
+ this.lockRequester = lockRequester;
+ }
- @Override
- public String getMessage() {
- return "Failed to lock [" + lockName + "] for [" + lockRequester + "]. Currently locked by [" + lockHolder +
- "].";
- }
+ @Override
+ public String getMessage() {
+ return "Failed to lock [" + lockName + "] for [" + lockRequester + "]. Currently locked by [" + lockHolder +
+ "].";
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/lock/comp/SynchronizedFunction.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/lock/comp/SynchronizedFunction.java
index a76fca11c..c3e35b700 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/lock/comp/SynchronizedFunction.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/lock/comp/SynchronizedFunction.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,30 +27,30 @@ import java.util.Set;
public abstract class SynchronizedFunction {
- private Set<String> synchset;
- private String lockRequester;
- private int lockTimeout; // Seconds
- private LockHelper lockHelper;
-
- protected SynchronizedFunction(LockHelper lockHelper, Collection<String> synchset, int lockTimeout) {
- this.lockHelper = lockHelper;
- this.synchset = new HashSet<String>(synchset);
- this.lockRequester = generateLockRequester();
- this.lockTimeout = lockTimeout;
- }
-
- protected abstract void _exec();
-
- public void exec() {
- lockHelper.lock(synchset, lockRequester, lockTimeout);
- try {
- _exec();
- } finally {
- lockHelper.unlock(synchset, true);
- }
- }
-
- private static String generateLockRequester() {
- return "SynchronizedFunction-" + (int) (Math.random() * 1000000);
- }
+ private Set<String> synchset;
+ private String lockRequester;
+ private int lockTimeout; // Seconds
+ private LockHelper lockHelper;
+
+ protected SynchronizedFunction(LockHelper lockHelper, Collection<String> synchset, int lockTimeout) {
+ this.lockHelper = lockHelper;
+ this.synchset = new HashSet<String>(synchset);
+ this.lockRequester = generateLockRequester();
+ this.lockTimeout = lockTimeout;
+ }
+
+ protected abstract void _exec();
+
+ public void exec() {
+ lockHelper.lock(synchset, lockRequester, lockTimeout);
+ try {
+ _exec();
+ } finally {
+ lockHelper.unlock(synchset, true);
+ }
+ }
+
+ private static String generateLockRequester() {
+ return "SynchronizedFunction-" + (int) (Math.random() * 1000000);
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/lock/dao/ResourceLockDao.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/lock/dao/ResourceLockDao.java
index 014765dfb..5ccde824a 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/lock/dao/ResourceLockDao.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/lock/dao/ResourceLockDao.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,17 +27,17 @@ import org.openecomp.sdnc.lock.data.ResourceLock;
public interface ResourceLockDao {
- void lockTable();
+ void lockTable();
- void unlockTable();
+ void unlockTable();
- void add(ResourceLock l);
+ void add(ResourceLock l);
- void update(long id, Date lockTime, Date expirationTime, int lockCount);
+ void update(long id, Date lockTime, Date expirationTime, int lockCount);
- ResourceLock getByResourceName(String resourceName);
+ ResourceLock getByResourceName(String resourceName);
- void delete(long id);
+ void delete(long id);
- void decrementLockCount(long id);
+ void decrementLockCount(long id);
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/lock/dao/ResourceLockDaoImpl.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/lock/dao/ResourceLockDaoImpl.java
index f4819b837..9a619763c 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/lock/dao/ResourceLockDaoImpl.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/lock/dao/ResourceLockDaoImpl.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,81 +35,81 @@ import org.springframework.jdbc.core.RowMapper;
public class ResourceLockDaoImpl implements ResourceLockDao {
- private static final Logger log = LoggerFactory.getLogger(ResourceLockDaoImpl.class);
-
- private JdbcTemplate jdbcTemplate;
- private boolean testing = false;
-
- @Override
- public void lockTable() {
- if (!testing) {
- jdbcTemplate.update("LOCK TABLES RESOURCE_LOCK WRITE");
- log.info("Table RESOURCE_LOCK locked.");
- }
- }
-
- @Override
- public void unlockTable() {
- if (!testing) {
- jdbcTemplate.update("UNLOCK TABLES");
- log.info("Table RESOURCE_LOCK unlocked.");
-
- CachedDataSourceWrap ds = (CachedDataSourceWrap) jdbcTemplate.getDataSource();
- ds.releaseConnection();
- }
- }
-
- @Override
- public void add(ResourceLock l) {
- jdbcTemplate.update(
- "INSERT INTO RESOURCE_LOCK (resource_name, lock_holder, lock_count, lock_time, expiration_time)\n" +
- "VALUES (?, ?, ?, ?, ?)",
- new Object[] { l.resourceName, l.lockHolder, l.lockCount, l.lockTime, l.expirationTime });
- }
-
- @Override
- public void update(long id, Date lockTime, Date expirationTime, int lockCount) {
- jdbcTemplate.update(
- "UPDATE RESOURCE_LOCK SET lock_time = ?, expiration_time = ?, lock_count = ? WHERE resource_lock_id = ?",
- new Object[] { lockTime, expirationTime, lockCount, id });
- }
-
- @Override
- public ResourceLock getByResourceName(String resourceName) {
- List<ResourceLock> ll = jdbcTemplate.query("SELECT * FROM RESOURCE_LOCK WHERE resource_name = ?",
- new Object[] { resourceName }, new RowMapper<ResourceLock>() {
-
- @Override
- public ResourceLock mapRow(ResultSet rs, int rowNum) throws SQLException {
- ResourceLock rl = new ResourceLock();
- rl.id = rs.getLong("resource_lock_id");
- rl.resourceName = rs.getString("resource_name");
- rl.lockHolder = rs.getString("lock_holder");
- rl.lockCount = rs.getInt("lock_count");
- rl.lockTime = rs.getTimestamp("lock_time");
- rl.expirationTime = rs.getTimestamp("expiration_time");
- return rl;
- }
- });
- return ll != null && !ll.isEmpty() ? ll.get(0) : null;
- }
-
- @Override
- public void delete(long id) {
- jdbcTemplate.update("DELETE FROM RESOURCE_LOCK WHERE resource_lock_id = ?", new Object[] { id });
- }
-
- @Override
- public void decrementLockCount(long id) {
- jdbcTemplate.update("UPDATE RESOURCE_LOCK SET lock_count = lock_count - 1 WHERE resource_lock_id = ?",
- new Object[] { id });
- }
-
- public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
- this.jdbcTemplate = jdbcTemplate;
- }
-
- public void setTesting(boolean testing) {
- this.testing = testing;
- }
+ private static final Logger log = LoggerFactory.getLogger(ResourceLockDaoImpl.class);
+
+ private JdbcTemplate jdbcTemplate;
+ private boolean testing = false;
+
+ @Override
+ public void lockTable() {
+ if (!testing) {
+ jdbcTemplate.update("LOCK TABLES RESOURCE_LOCK WRITE");
+ log.info("Table RESOURCE_LOCK locked.");
+ }
+ }
+
+ @Override
+ public void unlockTable() {
+ if (!testing) {
+ jdbcTemplate.update("UNLOCK TABLES");
+ log.info("Table RESOURCE_LOCK unlocked.");
+
+ CachedDataSourceWrap ds = (CachedDataSourceWrap) jdbcTemplate.getDataSource();
+ ds.releaseConnection();
+ }
+ }
+
+ @Override
+ public void add(ResourceLock l) {
+ jdbcTemplate.update(
+ "INSERT INTO RESOURCE_LOCK (resource_name, lock_holder, lock_count, lock_time, expiration_time)\n" +
+ "VALUES (?, ?, ?, ?, ?)",
+ new Object[] { l.resourceName, l.lockHolder, l.lockCount, l.lockTime, l.expirationTime });
+ }
+
+ @Override
+ public void update(long id, Date lockTime, Date expirationTime, int lockCount) {
+ jdbcTemplate.update(
+ "UPDATE RESOURCE_LOCK SET lock_time = ?, expiration_time = ?, lock_count = ? WHERE resource_lock_id = ?",
+ new Object[] { lockTime, expirationTime, lockCount, id });
+ }
+
+ @Override
+ public ResourceLock getByResourceName(String resourceName) {
+ List<ResourceLock> ll = jdbcTemplate.query("SELECT * FROM RESOURCE_LOCK WHERE resource_name = ?",
+ new Object[] { resourceName }, new RowMapper<ResourceLock>() {
+
+ @Override
+ public ResourceLock mapRow(ResultSet rs, int rowNum) throws SQLException {
+ ResourceLock rl = new ResourceLock();
+ rl.id = rs.getLong("resource_lock_id");
+ rl.resourceName = rs.getString("resource_name");
+ rl.lockHolder = rs.getString("lock_holder");
+ rl.lockCount = rs.getInt("lock_count");
+ rl.lockTime = rs.getTimestamp("lock_time");
+ rl.expirationTime = rs.getTimestamp("expiration_time");
+ return rl;
+ }
+ });
+ return ll != null && !ll.isEmpty() ? ll.get(0) : null;
+ }
+
+ @Override
+ public void delete(long id) {
+ jdbcTemplate.update("DELETE FROM RESOURCE_LOCK WHERE resource_lock_id = ?", new Object[] { id });
+ }
+
+ @Override
+ public void decrementLockCount(long id) {
+ jdbcTemplate.update("UPDATE RESOURCE_LOCK SET lock_count = lock_count - 1 WHERE resource_lock_id = ?",
+ new Object[] { id });
+ }
+
+ public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
+ this.jdbcTemplate = jdbcTemplate;
+ }
+
+ public void setTesting(boolean testing) {
+ this.testing = testing;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/lock/data/ResourceLock.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/lock/data/ResourceLock.java
index 561fd82a4..4e27fd954 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/lock/data/ResourceLock.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/lock/data/ResourceLock.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,10 +25,10 @@ import java.util.Date;
public class ResourceLock {
- public long id;
- public String resourceName;
- public String lockHolder;
- public int lockCount;
- public Date lockTime;
- public Date expirationTime;
+ public long id;
+ public String resourceName;
+ public String lockHolder;
+ public int lockCount;
+ public Date lockTime;
+ public Date expirationTime;
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/ReleaseRequestType.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/ReleaseRequestType.java
index 52104ec5f..0e3754527 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/ReleaseRequestType.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/ReleaseRequestType.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,24 +22,24 @@
package org.openecomp.sdnc.ra;
public enum ReleaseRequestType {
- Cancel, Activate, Disconnect;
+ Cancel, Activate, Disconnect;
- public static ReleaseRequestType convert(Object o) {
- if (o == null)
- return null;
- String s = o.toString();
- s = s.trim();
- if (s.length() == 0)
- return null;
+ public static ReleaseRequestType convert(Object o) {
+ if (o == null)
+ return null;
+ String s = o.toString();
+ s = s.trim();
+ if (s.length() == 0)
+ return null;
- if (s.equalsIgnoreCase("Cancel"))
- return Cancel;
- if (s.equalsIgnoreCase("Activate"))
- return Activate;
- if (s.equalsIgnoreCase("Disconnect"))
- return Disconnect;
+ if (s.equalsIgnoreCase("Cancel"))
+ return Cancel;
+ if (s.equalsIgnoreCase("Activate"))
+ return Activate;
+ if (s.equalsIgnoreCase("Disconnect"))
+ return Disconnect;
- throw new IllegalArgumentException("Invalid request-type: " + s +
- ". Supported values are Cancel, Activate, Disconnect.");
- }
+ throw new IllegalArgumentException("Invalid request-type: " + s +
+ ". Supported values are Cancel, Activate, Disconnect.");
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/ReserveRequestType.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/ReserveRequestType.java
index d9964331e..b0d0a50c4 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/ReserveRequestType.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/ReserveRequestType.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,22 +22,22 @@
package org.openecomp.sdnc.ra;
public enum ReserveRequestType {
- New, Change;
+ New, Change;
- public static ReserveRequestType convert(Object o) {
- if (o == null)
- return null;
- String s = o.toString();
- s = s.trim();
- if (s.length() == 0)
- return null;
+ public static ReserveRequestType convert(Object o) {
+ if (o == null)
+ return null;
+ String s = o.toString();
+ s = s.trim();
+ if (s.length() == 0)
+ return null;
- if (s.equalsIgnoreCase("New"))
- return New;
- if (s.equalsIgnoreCase("Change"))
- return Change;
+ if (s.equalsIgnoreCase("New"))
+ return New;
+ if (s.equalsIgnoreCase("Change"))
+ return Change;
- throw new IllegalArgumentException("Invalid request-type: " + s +
- ". Supported values are New, Change.");
- }
+ throw new IllegalArgumentException("Invalid request-type: " + s +
+ ". Supported values are New, Change.");
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/ResourceAllocator.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/ResourceAllocator.java
index ae281cf1f..e6a2c80cc 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/ResourceAllocator.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/ResourceAllocator.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -68,949 +68,949 @@ import org.slf4j.LoggerFactory;
public class ResourceAllocator implements SvcLogicResource {
- private static final Logger log = LoggerFactory.getLogger(ResourceAllocator.class);
-
- public ResourceAllocator() {
- log.info("ResourceAllocator created.");
- }
-
- private ServerDao serverDao;
- private VpePortDao vpePortDao;
- private VplspePortDao vplspePortDao;
- private MaxPortSpeedDao maxPortSpeedDao;
- private MaxServerSpeedDao maxServerSpeedDao;
- private ServiceResourceDao serviceResourceDao;
- private ParameterDao parameterDao;
-
- private AllocationRequestBuilder allocationRequestBuilder;
- private ResourceManager resourceManager;
- private SpeedUtil speedUtil;
-
- private EndPointAllocator endPointAllocator;
-
- @Override
- public QueryStatus notify(String resource, String action, String key, SvcLogicContext ctx)
- throws SvcLogicException {
- return (QueryStatus.SUCCESS);
- }
-
- @Override
- public QueryStatus update(
- String resource,
- String key,
- Map<String, String> parms,
- String prefix,
- SvcLogicContext ctx) throws SvcLogicException {
-
- return QueryStatus.SUCCESS;
- }
-
- @Override
- public QueryStatus exists(String resource, String key, String prefix, SvcLogicContext ctx)
- throws SvcLogicException {
- return QueryStatus.SUCCESS;
- }
-
- @Override
- public QueryStatus delete(String arg0, String arg1, SvcLogicContext arg2) throws SvcLogicException {
- return QueryStatus.SUCCESS;
- }
-
- @Override
- public QueryStatus save(
- String arg0,
- boolean arg1,
- boolean arg2,
- String arg3,
- Map<String, String> arg4,
- String arg5,
- SvcLogicContext arg6) throws SvcLogicException {
- return QueryStatus.SUCCESS;
- }
-
- @Override
- public QueryStatus isAvailable(String resource, String key, String prefix, SvcLogicContext ctx)
- throws SvcLogicException {
- String serviceModel = ctx.getAttribute("tmp.resource-allocator.service-model");
- if (serviceModel != null && serviceModel.trim().length() > 0)
- return allocateResources(serviceModel, ctx, true, prefix);
- return allocateResourcesL3SDN(ctx, true, prefix);
- }
-
- @Override
- public QueryStatus query(
- String resource,
- boolean localOnly,
- String select,
- String key,
- String prefix,
- String orderBy,
- SvcLogicContext ctx) throws SvcLogicException {
-
- prefix = prefix == null ? "" : prefix + '.';
-
- if (!resource.equals("NetworkCapacity")) {
- log.info("resource: " + resource);
- log.info("key: " + key);
-
- Resource r = resourceManager.getResource(resource, key);
- if (r == null)
- return QueryStatus.NOT_FOUND;
-
- if (r instanceof LimitResource) {
- ctx.setAttribute(prefix + "used", String.valueOf(((LimitResource) r).used));
-
- log.info("Added context attr: " + prefix + "used: " + String.valueOf(((LimitResource) r).used));
- }
-
- return QueryStatus.SUCCESS;
- }
-
- log.info("key: " + key);
- log.info("prefix: " + prefix);
-
- if (key == null)
- return QueryStatus.SUCCESS;
-
- if (key.startsWith("'") && key.endsWith("'"))
- key = key.substring(1, key.length() - 1);
-
- String endPointPosition = "VPE-Cust";
-
- String resourceUnionId = key + '/' + endPointPosition;
- List<Resource> rlist = resourceManager.getResourceUnion(resourceUnionId);
-
- log.info("Resources found for " + resourceUnionId + ": " + rlist.size());
-
- String assetId = null;
- for (Resource r : rlist) {
- log.info("Resource: " + r.resourceKey.resourceName);
-
- if (r instanceof RangeResource) {
- RangeResource rr = (RangeResource) r;
- for (AllocationItem ai : r.allocationItems)
- if (ai.resourceUnionId.equals(resourceUnionId)) {
- RangeAllocationItem rai = (RangeAllocationItem) ai;
- ctx.setAttribute(prefix + r.resourceKey.resourceName, String.valueOf(rai.used.first()));
-
- log.info("Added context attr: " + prefix + r.resourceKey.resourceName + ": " +
- String.valueOf(rr.used.first()));
-
- assetId = r.resourceKey.assetId;
- String vpeName = assetId;
- int i1 = assetId.indexOf('/');
- if (i1 > 0)
- vpeName = assetId.substring(0, i1);
- ctx.setAttribute(prefix + "vpe-name", vpeName);
-
- log.info("Added context attr: " + prefix + "vpe-name: " + vpeName);
- }
- }
- }
-
- String affinityLink = "1";
- if (assetId != null) {
- for (Resource r : rlist) {
- if (r instanceof LimitResource) {
- LimitResource ll = (LimitResource) r;
- if (ll.resourceKey.assetId.startsWith(assetId + '-')) {
- int i1 = ll.resourceKey.assetId.lastIndexOf('-');
- affinityLink = ll.resourceKey.assetId.substring(i1 + 1);
- break;
- }
- }
- }
- }
-
- ctx.setAttribute(prefix + "affinity-link", affinityLink);
-
- log.info("Added context attr: " + prefix + "affinity-link: " + affinityLink);
-
- return QueryStatus.SUCCESS;
- }
-
- @Override
- public QueryStatus reserve(String resource, String select, String key, String prefix, SvcLogicContext ctx)
- throws SvcLogicException {
- String serviceModel = ctx.getAttribute("tmp.resource-allocator.service-model");
- if (serviceModel != null && serviceModel.trim().length() > 0)
- return allocateResources(serviceModel, ctx, false, prefix);
- return allocateResourcesL3SDN(ctx, false, prefix);
- }
-
- @Override
- public QueryStatus release(String resource, String key, SvcLogicContext ctx) throws SvcLogicException {
- String serviceInstanceId = ctx.getAttribute("tmp.resource-allocator.service-instance-id");
- if (serviceInstanceId == null)
- throw new SvcLogicException("tmp.resource-allocator.service-instance-id is required in ResourceAllocator");
-
- String requestTypeStr = ctx.getAttribute("tmp.resource-allocator.request-type");
- if (requestTypeStr == null)
- throw new SvcLogicException("tmp.resource-allocator.request-type is required in ResourceAllocator");
-
- ReleaseRequestType requestType = null;
- try {
- requestType = ReleaseRequestType.convert(requestTypeStr);
- } catch (IllegalArgumentException e) {
- throw new SvcLogicException("Invalid tmp.resource-allocator.request-type: " + requestTypeStr +
- ". Supported values are Cancel, Activate, Disconnect.");
- }
-
- log.info("Starting release: " + requestType + " for: " + serviceInstanceId);
-
- ServiceResource activeServiceResource =
- serviceResourceDao.getServiceResource(serviceInstanceId, ServiceStatus.Active);
- ServiceResource pendingServiceResource =
- serviceResourceDao.getServiceResource(serviceInstanceId, ServiceStatus.Pending);
-
- log.info("Active ServiceResource: ");
- StrUtil.info(log, activeServiceResource);
- log.info("Pending ServiceResource: ");
- StrUtil.info(log, pendingServiceResource);
-
- if (requestType == ReleaseRequestType.Cancel) {
- if (pendingServiceResource != null) {
- log.info("Releasing pending resources: " + pendingServiceResource.resourceSetId);
-
- resourceManager.releaseResourceSet(pendingServiceResource.resourceSetId);
- serviceResourceDao.deleteServiceResource(serviceInstanceId, ServiceStatus.Pending);
- } else {
- log.info("Pending record not found for service instance: " + serviceInstanceId + ". Nothing to do.");
- }
-
- } else if (requestType == ReleaseRequestType.Activate) {
- if (pendingServiceResource != null) {
- if (activeServiceResource != null) {
- log.info("Releasing active resources: " + activeServiceResource.resourceSetId);
-
- resourceManager.releaseResourceSet(activeServiceResource.resourceSetId);
- serviceResourceDao.deleteServiceResource(serviceInstanceId, ServiceStatus.Active);
- }
-
- log.info("Updating the status of the pending record to active.");
-
- serviceResourceDao.updateServiceStatus(serviceInstanceId, ServiceStatus.Pending, ServiceStatus.Active);
- } else {
- log.info("Pending record not found for service instance: " + serviceInstanceId + ". Nothing to do.");
- }
-
- } else if (requestType == ReleaseRequestType.Disconnect) {
- if (pendingServiceResource != null) {
- log.info("Releasing pending resources: " + pendingServiceResource.resourceSetId);
-
- resourceManager.releaseResourceSet(pendingServiceResource.resourceSetId);
- serviceResourceDao.deleteServiceResource(serviceInstanceId, ServiceStatus.Pending);
- }
- if (activeServiceResource != null) {
- log.info("Releasing active resources: " + activeServiceResource.resourceSetId);
-
- resourceManager.releaseResourceSet(activeServiceResource.resourceSetId);
- serviceResourceDao.deleteServiceResource(serviceInstanceId, ServiceStatus.Active);
- }
- }
-
- return QueryStatus.SUCCESS;
- }
-
- private QueryStatus allocateResourcesL3SDN(SvcLogicContext ctx, boolean checkOnly, String prefix)
- throws SvcLogicException {
- prefix = prefix == null ? "" : prefix + '.';
-
- String aicSiteId = getAicSiteId(ctx);
- Map<String, Object> service = getServiceData(ctx);
-
- String requestTypeStr = ctx.getAttribute("tmp.resource-allocator.request-type");
- if (requestTypeStr == null)
- requestTypeStr = "New";
-
- ReserveRequestType requestType = null;
- try {
- requestType = ReserveRequestType.convert(requestTypeStr);
- } catch (IllegalArgumentException e) {
- throw new SvcLogicException("Invalid tmp.resource-allocator.request-type: " + requestTypeStr +
- ". Supported values are New, Change.");
- }
-
- String serviceInstanceId = String.valueOf(service.get("service-instance-id"));
-
- ServiceResource activeServiceResource =
- serviceResourceDao.getServiceResource(serviceInstanceId, ServiceStatus.Active);
- ServiceResource pendingServiceResource =
- serviceResourceDao.getServiceResource(serviceInstanceId, ServiceStatus.Pending);
-
- log.info("Active ServiceResource: ");
- StrUtil.info(log, activeServiceResource);
- log.info("Pending ServiceResource: ");
- StrUtil.info(log, pendingServiceResource);
-
- ServiceResource sr = new ServiceResource();
- sr.serviceInstanceId = serviceInstanceId;
- sr.serviceStatus = ServiceStatus.Pending;
- sr.serviceChangeNumber = 1;
- if (pendingServiceResource != null)
- sr.serviceChangeNumber = pendingServiceResource.serviceChangeNumber + 1;
- else if (activeServiceResource != null)
- sr.serviceChangeNumber = activeServiceResource.serviceChangeNumber + 1;
- sr.resourceSetId = serviceInstanceId + "/" + sr.serviceChangeNumber;
- sr.resourceUnionId = serviceInstanceId;
-
- log.info("New ServiceResource: ");
- StrUtil.info(log, sr);
-
- List<Map<String, Object>> vpePortData = vpePortDao.getVpePortData(aicSiteId);
- List<Map<String, Object>> vplspePortData = vplspePortDao.getVplspePortData(aicSiteId);
- List<Map<String, Object>> serverData = serverDao.getServerData(aicSiteId);
-
- vpePortData = orderVpe(vpePortData);
-
- long maxAvailableSpeedVpePort = 0;
- boolean vpePortFound = false;
-
- for (Map<String, Object> vpe : vpePortData) {
- String vpeId = String.valueOf(vpe.get("vpe-id"));
- String interfaceName = String.valueOf(vpe.get("physical-interface-name"));
- String portId = vpeId + "/" + interfaceName;
-
- log.info("Checking VPE port: " + portId);
-
- String provStatus = String.valueOf(vpe.get("provisioning-status"));
- if (!provStatus.equals("PROV")) {
- log.info("Skipping port " + portId + ": Provisioning status is not PROV.");
- continue;
- }
-
- String imageFile = String.valueOf(vpe.get("image-file-name"));
- String endPointPosition = "VPE-Cust";
- long maxPortSpeed = maxPortSpeedDao.getMaxPortSpeed(imageFile, endPointPosition, interfaceName);
- vpe.put("max-port-speed", maxPortSpeed);
-
- EquipmentData ed = new EquipmentData();
- ed.data = vpe;
- ed.equipmentId = portId;
- ed.equipmentLevel = EquipmentLevel.Port;
-
- ServiceData sd = new ServiceData();
- sd.data = service;
- sd.serviceModel = "L3SDN";
- sd.endPointPosition = endPointPosition;
- sd.resourceUnionId = sr.resourceUnionId;
- sd.resourceSetId = sr.resourceSetId;
-
- StrUtil.info(log, ed);
- StrUtil.info(log, sd);
-
- AllocationRequest ar = allocationRequestBuilder.buildAllocationRequest(sd, ed, checkOnly,
- requestType == ReserveRequestType.Change);
- AllocationOutcome ao = resourceManager.allocateResources(ar);
-
- if (ao.status == AllocationStatus.Success) {
-
- // Assign affinity link
- if (!checkOnly) {
- List<String> affinityLinkIdList = new ArrayList<>();
- affinityLinkIdList.add("0");
- affinityLinkIdList.add("1");
- affinityLinkIdList.add("2");
- affinityLinkIdList.add("3");
-
- String preferedAffinityLinkId = "0";
- long lowestAssignedBw = Long.MAX_VALUE;
- for (String affinityLinkId : affinityLinkIdList) {
- long used = 0;
- String assetId = ed.equipmentId + "-" + affinityLinkId;
- Resource r = resourceManager.getResource("Bandwidth", assetId);
- if (r != null) {
- LimitResource ll = (LimitResource) r;
- used = ll.used;
- }
- if (used < lowestAssignedBw) {
- lowestAssignedBw = used;
- preferedAffinityLinkId = affinityLinkId;
- }
- log.info("Assigned bandwidth on affinity link: " + assetId + ": " + used);
- }
-
- log.info("Prefered affinity link for " + ed.equipmentId + ": " + preferedAffinityLinkId);
-
- ctx.setAttribute(prefix + "affinity-link", preferedAffinityLinkId);
-
- LimitAllocationRequest ar1 = new LimitAllocationRequest();
- ar1.resourceSetId = sd.resourceSetId;
- ar1.resourceUnionId = sd.resourceUnionId;
- ar1.resourceShareGroupList = null;
- ar1.resourceName = "Bandwidth";
- ar1.assetId = ed.equipmentId + "-" + preferedAffinityLinkId;
- ar1.missingResourceAction = AllocationAction.Succeed_Allocate;
- ar1.expiredResourceAction = AllocationAction.Succeed_Allocate;
- ar1.replace = true;
- ar1.strict = false;
- ar1.checkLimit = Long.MAX_VALUE;
- ar1.checkCount = 0;
- ar1.allocateCount = (Long) sd.data.get("service-speed-kbps");
-
- resourceManager.allocateResources(ar1);
- }
-
- ctx.setAttribute(prefix + "vpe-name", vpeId);
-
- vpePortFound = true;
- break;
- }
-
- if (ao instanceof LimitAllocationOutcome) {
- LimitAllocationOutcome lao = (LimitAllocationOutcome) ao;
- long available = lao.limit - lao.used;
- if (available > maxAvailableSpeedVpePort)
- maxAvailableSpeedVpePort = available;
- }
- }
-
- long maxAvailableSpeedVplspePort = 0;
- boolean vplspePortFound = false;
-
- for (Map<String, Object> vplspe : vplspePortData) {
- String vplspeId = String.valueOf(vplspe.get("vplspe-id"));
- String interfaceName = String.valueOf(vplspe.get("physical-interface-name"));
- String portId = vplspeId + "/" + interfaceName;
-
- log.info("Checking VPLSPE port: " + portId);
-
- String provStatus = String.valueOf(vplspe.get("provisioning-status"));
- if (!provStatus.equals("PROV")) {
- log.info("Skipping port " + portId + ": Provisioning status is not PROV.");
- continue;
- }
-
- long physicalSpeed = (Long) vplspe.get("physical-interface-speed");
- String physicalSpeedUnit = String.valueOf(vplspe.get("physical-interface-speed-unit"));
- long maxPortSpeed = speedUtil.convertToKbps(physicalSpeed, physicalSpeedUnit);
- vplspe.put("max-port-speed", maxPortSpeed);
-
- EquipmentData ed = new EquipmentData();
- ed.data = vplspe;
- ed.equipmentId = portId;
- ed.equipmentLevel = EquipmentLevel.Port;
-
- ServiceData sd = new ServiceData();
- sd.data = service;
- sd.serviceModel = "L3SDN";
- sd.endPointPosition = "IPAG-TOA";
- sd.resourceUnionId = sr.resourceUnionId;
- sd.resourceSetId = sr.resourceSetId;
-
- StrUtil.info(log, ed);
- StrUtil.info(log, sd);
-
- AllocationRequest ar = allocationRequestBuilder.buildAllocationRequest(sd, ed, checkOnly,
- requestType == ReserveRequestType.Change);
- AllocationOutcome ao = resourceManager.allocateResources(ar);
-
- if (ao.status == AllocationStatus.Success) {
- vplspePortFound = true;
- break;
- }
-
- if (ao instanceof LimitAllocationOutcome) {
- LimitAllocationOutcome lao = (LimitAllocationOutcome) ao;
- long available = lao.limit - lao.used;
- if (available > maxAvailableSpeedVplspePort)
- maxAvailableSpeedVplspePort = available;
- }
- }
-
- long maxAvailableSpeedServer = 0;
- boolean serverFound = false;
-
- for (Map<String, Object> server : serverData) {
- String serverId = String.valueOf(server.get("server-id"));
- String serverModel = String.valueOf(server.get("server-model"));
-
- log.info("Checking Server: " + serverId);
-
- String endPointPosition = "VCE-Cust";
-
- int serverCount = (Integer) server.get("server-count");
- if (serverCount == 0)
- serverCount = 1;
- String ratioString = parameterDao.getParameter("homing.pserver.sparing.ratio");
- if (ratioString == null || ratioString.length() == 0)
- ratioString = "1:1";
- int primaryServerCount = calculatePrimaryServerCount(serverCount, ratioString);
- server.put("number-primary-servers", primaryServerCount);
-
- int evcCount = getEvcCountOnServer(serverId);
- int evcCountPerServer = (evcCount + primaryServerCount - 1) / primaryServerCount;
- long maxServerSpeed = maxServerSpeedDao.getMaxServerSpeed(serverModel, evcCountPerServer);
- server.put("max-server-speed", maxServerSpeed);
- server.put("evc-count", evcCount);
- server.put("evc-count-per-server", evcCountPerServer);
-
- EquipmentData ed = new EquipmentData();
- ed.data = server;
- ed.equipmentId = serverId;
- ed.equipmentLevel = EquipmentLevel.Server;
-
- ServiceData sd = new ServiceData();
- sd.data = service;
- sd.serviceModel = "L3SDN";
- sd.endPointPosition = endPointPosition;
- sd.resourceUnionId = sr.resourceUnionId;
- sd.resourceSetId = sr.resourceSetId;
-
- StrUtil.info(log, ed);
- StrUtil.info(log, sd);
-
- AllocationRequest ar = allocationRequestBuilder.buildAllocationRequest(sd, ed, checkOnly,
- requestType == ReserveRequestType.Change);
- AllocationOutcome ao = resourceManager.allocateResources(ar);
-
- if (ao.status == AllocationStatus.Success) {
- serverFound = true;
-
- if (ao instanceof MultiResourceAllocationOutcome) {
- MultiResourceAllocationOutcome mrao = (MultiResourceAllocationOutcome) ao;
- for (AllocationOutcome ao1 : mrao.allocationOutcomeList) {
- if (ao1 instanceof LimitAllocationOutcome) {
- LimitAllocationOutcome lao = (LimitAllocationOutcome) ao1;
- if (lao.request.resourceName.equals("Bandwidth")) {
- ThresholdStatus th = allocationRequestBuilder.getThresholdStatus(sd, ed, lao);
- setThresholdData(ctx, th, sd, ed);
- }
- }
- }
- }
-
- break;
- }
-
- if (ao instanceof MultiResourceAllocationOutcome) {
- MultiResourceAllocationOutcome mrao = (MultiResourceAllocationOutcome) ao;
- for (AllocationOutcome ao1 : mrao.allocationOutcomeList) {
- if (ao1 instanceof LimitAllocationOutcome) {
- LimitAllocationOutcome lao = (LimitAllocationOutcome) ao1;
- if (lao.status == AllocationStatus.Failure && lao.request.resourceName.equals("Bandwidth")) {
- long available = lao.limit - lao.used;
- if (available > maxAvailableSpeedServer)
- maxAvailableSpeedServer = available;
- }
- if (lao.status == AllocationStatus.Failure && lao.request.resourceName.equals("Connection")) {
- maxAvailableSpeedServer = 0;
- break;
- }
-
- ThresholdStatus th = allocationRequestBuilder.getThresholdStatus(sd, ed, lao);
- setThresholdData(ctx, th, sd, ed);
- }
- }
- }
- }
-
- if (vpePortFound && vplspePortFound && serverFound) {
- if (!checkOnly) {
- if (pendingServiceResource == null) {
- log.info("Adding the pending service resource record to DB.");
- serviceResourceDao.addServiceResource(sr);
- } else {
- log.info("Releasing previously allocated resources for resource set id: " +
- pendingServiceResource.resourceSetId);
- resourceManager.releaseResourceSet(pendingServiceResource.resourceSetId);
-
- log.info("Updating the pending service resource record in DB with service change number: " +
- sr.serviceChangeNumber);
- serviceResourceDao.updateServiceResource(sr);
- }
- }
-
- return QueryStatus.SUCCESS;
- }
-
- log.info("Releasing allocated resources (if any) for resource set id: " + sr.resourceSetId);
- resourceManager.releaseResourceSet(sr.resourceSetId);
-
- long maxAvailableSpeed = Long.MAX_VALUE;
- if (!vpePortFound && maxAvailableSpeedVpePort < maxAvailableSpeed)
- maxAvailableSpeed = maxAvailableSpeedVpePort;
- if (!vplspePortFound && maxAvailableSpeedVplspePort < maxAvailableSpeed)
- maxAvailableSpeed = maxAvailableSpeedVplspePort;
- if (!serverFound && maxAvailableSpeedServer < maxAvailableSpeed)
- maxAvailableSpeed = maxAvailableSpeedServer;
-
- setOutputContext(ctx, maxAvailableSpeed, "kbps");
- return QueryStatus.NOT_FOUND;
- }
-
- private List<Map<String, Object>> orderVpe(List<Map<String, Object>> vpePortData) {
- for (Map<String, Object> vpe : vpePortData) {
- String vpeId = String.valueOf(vpe.get("vpe-id"));
- String interfaceName = String.valueOf(vpe.get("physical-interface-name"));
- String portId = vpeId + "/" + interfaceName;
- Resource r = resourceManager.getResource("Bandwidth", portId);
- long used = 0;
- if (r != null) {
- LimitResource ll = (LimitResource) r;
- used = ll.used;
- }
- vpe.put("used-bandwidth", used);
-
- log.info("Used bandwidth on VPE: " + vpeId + ": " + used);
- }
-
- Collections.sort(vpePortData, new Comparator<Map<String, Object>>() {
-
- @Override
- public int compare(Map<String, Object> o1, Map<String, Object> o2) {
- long used1 = (Long) o1.get("used-bandwidth");
- long used2 = (Long) o2.get("used-bandwidth");
- if (used1 < used2)
- return -1;
- if (used1 > used2)
- return 1;
- return 0;
- }
- });
-
- return vpePortData;
- }
-
- private void setThresholdData(SvcLogicContext ctx, ThresholdStatus th, ServiceData sd, EquipmentData ed) {
- if (th == null)
- return;
-
- String pp = "tmp.resource-allocator-output.threshold-notification-list.threshold-hotification[0].";
- ctx.setAttribute("tmp.resource-allocator-output.threshold-notification-list.threshold-hotification_length",
- "1");
- ctx.setAttribute(pp + "message", th.resourceThreshold.message);
- ctx.setAttribute(pp + "resource-rule.service-model", th.resourceRule.serviceModel);
- ctx.setAttribute(pp + "resource-rule.endpoint-position", th.resourceRule.endPointPosition);
- ctx.setAttribute(pp + "resource-rule.resource-name", th.resourceRule.resourceName);
- ctx.setAttribute(pp + "resource-rule.equipment-level", th.resourceRule.equipmentLevel);
- ctx.setAttribute(pp + "resource-rule.soft-limit-expression", th.resourceRule.softLimitExpression);
- ctx.setAttribute(pp + "resource-rule.hard-limit-expression", th.resourceRule.hardLimitExpression);
- ctx.setAttribute(pp + "resource-state.used", String.valueOf(th.used));
- ctx.setAttribute(pp + "resource-state.limit-value", String.valueOf(th.limitValue));
- ctx.setAttribute(pp + "resource-state.threshold-value", String.valueOf(th.thresholdValue));
- ctx.setAttribute(pp + "resource-state.last-added", String.valueOf(th.lastAdded));
- ctx.setAttribute(pp + "equipment-data.equipment-id", ed.equipmentId);
- for (String edKey : ed.data.keySet())
- ctx.setAttribute(pp + "equipment-data." + edKey, String.valueOf(ed.data.get(edKey)));
- }
-
- private QueryStatus allocateResources(String serviceModel, SvcLogicContext ctx, boolean checkOnly, String prefix)
- throws SvcLogicException {
- prefix = prefix == null ? "" : prefix + '.';
-
- Map<String, Object> service = getServiceData(ctx);
- Map<String, Object> ec = getEquipConstraints(ctx);
-
- String requestTypeStr = ctx.getAttribute("tmp.resource-allocator.request-type");
- if (requestTypeStr == null)
- requestTypeStr = "New";
-
- ReserveRequestType requestType = null;
- try {
- requestType = ReserveRequestType.convert(requestTypeStr);
- } catch (IllegalArgumentException e) {
- throw new SvcLogicException("Invalid tmp.resource-allocator.request-type: " + requestTypeStr +
- ". Supported values are New, Change.");
- }
-
- String serviceInstanceId = String.valueOf(service.get("service-instance-id"));
-
- log.info("Starting reserve: " + requestType + ", service-instance-id: " + serviceInstanceId);
-
- ServiceResource activeServiceResource =
- serviceResourceDao.getServiceResource(serviceInstanceId, ServiceStatus.Active);
- ServiceResource pendingServiceResource =
- serviceResourceDao.getServiceResource(serviceInstanceId, ServiceStatus.Pending);
-
- log.info("Active ServiceResource: ");
- StrUtil.info(log, activeServiceResource);
- log.info("Pending ServiceResource: ");
- StrUtil.info(log, pendingServiceResource);
-
- int changeNumber = 1;
- if (pendingServiceResource != null)
- changeNumber = pendingServiceResource.serviceChangeNumber + 1;
- else if (activeServiceResource != null)
- changeNumber = activeServiceResource.serviceChangeNumber + 1;
-
- ServiceData sd = new ServiceData();
- sd.data = service;
- sd.serviceModel = serviceModel;
- sd.endPointPosition = (String) service.get("end-point-position");
- sd.resourceShareGroup = (String) service.get("resource-share-group");
- sd.resourceName = (String) service.get("resource-name");
- sd.serviceInstanceId = serviceInstanceId;
-
- StrUtil.info(log, sd);
-
- List<EndPointData> epList = endPointAllocator.allocateEndPoints(sd, ec, checkOnly,
- requestType == ReserveRequestType.Change, changeNumber);
-
- if (epList != null && !epList.isEmpty()) {
- if (!checkOnly) {
- EndPointData ep = epList.get(0);
-
- if (sd.resourceName == null) {
- ServiceResource sr = new ServiceResource();
- sr.serviceInstanceId = serviceInstanceId;
- sr.serviceStatus = ServiceStatus.Pending;
- sr.serviceChangeNumber = changeNumber;
- sr.resourceSetId = ep.resourceSetId;
- sr.resourceUnionId = ep.resourceUnionId;
-
- log.info("New ServiceResource: ");
- StrUtil.info(log, sr);
-
- if (pendingServiceResource == null) {
- log.info("Adding the pending service resource record to DB.");
- serviceResourceDao.addServiceResource(sr);
- } else {
- log.info("Releasing previously allocated resources for resource set id: " +
- pendingServiceResource.resourceSetId);
- resourceManager.releaseResourceSet(pendingServiceResource.resourceSetId);
-
- log.info("Updating the pending service resource record in DB with service change number: " +
- sr.serviceChangeNumber);
- serviceResourceDao.updateServiceResource(sr);
- }
- }
-
- for (EndPointData ep1 : epList)
- if (ep1.data != null && !ep1.data.isEmpty())
- for (String key : ep1.data.keySet()) {
- String value = String.valueOf(ep1.data.get(key));
- ctx.setAttribute(prefix + key, value);
-
- log.info("Added context attr: " + prefix + key + ": " + value);
- }
- }
-
- return QueryStatus.SUCCESS;
- }
-
- log.info("Capacity not found for EVC: " + serviceInstanceId);
-
- return QueryStatus.NOT_FOUND;
- }
-
- private int getEvcCountOnServer(String serverId) {
- LimitResource l = (LimitResource) resourceManager.getResource("Connection", serverId);
- if (l != null)
- return (int) l.used;
- return 0;
- }
-
- private String getAicSiteId(SvcLogicContext ctx) throws SvcLogicException {
- String aicSiteId = ctx.getAttribute("tmp.resource-allocator.aic-site-id");
- if (aicSiteId == null)
- throw new SvcLogicException("tmp.resource-allocator.aic-site-id is required in ResourceAllocator");
- return aicSiteId;
- }
-
- private Map<String, Object> getServiceData(SvcLogicContext ctx) throws SvcLogicException {
- Map<String, Object> sd = new HashMap<String, Object>();
-
- String endPointPosition = ctx.getAttribute("tmp.resource-allocator.end-point-position");
- if (endPointPosition != null && endPointPosition.trim().length() > 0)
- sd.put("end-point-position", endPointPosition.trim());
-
- String resourceName = ctx.getAttribute("tmp.resource-allocator.resource-name");
- if (resourceName != null && resourceName.trim().length() > 0)
- sd.put("resource-name", resourceName.trim());
-
- String resourceShareGroup = ctx.getAttribute("tmp.resource-allocator.resource-share-group");
- if (resourceShareGroup != null && resourceShareGroup.trim().length() > 0)
- sd.put("resource-share-group", resourceShareGroup.trim());
-
- String serviceInstanceId = ctx.getAttribute("tmp.resource-allocator.service-instance-id");
- if (serviceInstanceId == null)
- serviceInstanceId = "checkServiceInstance";
- sd.put("service-instance-id", serviceInstanceId);
-
- String speedStr = ctx.getAttribute("tmp.resource-allocator.speed");
- if (speedStr != null && speedStr.trim().length() > 0) {
- long speed = 0;
- try {
- speed = Long.parseLong(speedStr);
- } catch (NumberFormatException e) {
- throw new SvcLogicException("Invalid tmp.resource-allocator.speed. Must be a number.");
- }
- String unit = ctx.getAttribute("tmp.resource-allocator.speed-unit");
- if (unit == null || unit.trim().length() == 0)
- throw new SvcLogicException("tmp.resource-allocator.speed-unit is required in ResourceAllocator");
- long serviceSpeedKbps = speedUtil.convertToKbps(speed, unit);
-
- sd.put("service-speed-kbps", serviceSpeedKbps);
- }
-
- String vpnId = ctx.getAttribute("tmp.resource-allocator.vpn-id");
- if (vpnId != null && vpnId.trim().length() > 0)
- sd.put("vpn-id", vpnId.trim());
-
- String vpnIdList = ctx.getAttribute("tmp.resource-allocator.vpn-id-list");
- if (vpnIdList != null && vpnIdList.trim().length() > 0)
- sd.put("vpn-id-list", vpnIdList.trim());
-
- String vrfName = ctx.getAttribute("tmp.resource-allocator.vrf-name");
- if (vrfName != null && vrfName.trim().length() > 0)
- sd.put("vrf-name", vrfName.trim());
-
- String vrfNameList = ctx.getAttribute("tmp.resource-allocator.vrf-name-list");
- if (vrfNameList != null && vrfNameList.trim().length() > 0)
- sd.put("vrf-name-list", vrfNameList.trim());
-
- String v4multicast = ctx.getAttribute("tmp.resource-allocator.v4-multicast");
- if (v4multicast != null && v4multicast.trim().length() > 0)
- sd.put("v4-multicast", v4multicast.trim());
-
- String v6multicast = ctx.getAttribute("tmp.resource-allocator.v6-multicast");
- if (v6multicast != null && v6multicast.trim().length() > 0)
- sd.put("v6-multicast", v6multicast.trim());
-
- String v4ServingSite = ctx.getAttribute("tmp.resource-allocator.v4-serving-site");
- if (v4ServingSite != null && v4ServingSite.trim().length() > 0)
- sd.put("v4-serving-site", v4ServingSite.trim());
-
- String v6ServingSite = ctx.getAttribute("tmp.resource-allocator.v6-serving-site");
- if (v6ServingSite != null && v6ServingSite.trim().length() > 0)
- sd.put("v6-serving-site", v6ServingSite.trim());
-
- return sd;
- }
-
- private Map<String, Object> getEquipConstraints(SvcLogicContext ctx) throws SvcLogicException {
- Map<String, Object> mm = new HashMap<String, Object>();
-
- String vrfRequired = ctx.getAttribute("tmp.resource-allocator.vrf-required");
- if (vrfRequired != null && vrfRequired.trim().length() > 0)
- mm.put("vrf-required", vrfRequired.trim());
-
- String clli = ctx.getAttribute("tmp.resource-allocator.clli");
- if (clli == null || clli.trim().length() == 0)
- clli = ctx.getAttribute("tmp.resource-allocator.aic-site-id");
- if (clli != null) {
- mm.put("clli", clli.trim());
- mm.put("aic-site-id", clli.trim());
- }
-
- String vpeName = ctx.getAttribute("tmp.resource-allocator.vpe-name");
- if (vpeName != null && vpeName.trim().length() > 0)
- mm.put("vpe-name", vpeName.trim());
-
- String vnfName = ctx.getAttribute("tmp.resource-allocator.device-name");
- if (vnfName != null && vnfName.trim().length() > 0)
- mm.put("vnf-name", vnfName.trim());
-
- String excludeVpeList = ctx.getAttribute("tmp.resource-allocator.exclude-vpe-list");
- if (excludeVpeList != null && excludeVpeList.trim().length() > 0)
- mm.put("exclude-vpe-list", excludeVpeList.trim());
-
- String uplinkCircuitCountStr =
- ctx.getAttribute("tmp.resource-allocator.uplink-circuit-list.uplink-circuit_length");
- if (uplinkCircuitCountStr != null) {
- long uplinkCircuitCount = 0;
- try {
- uplinkCircuitCount = Long.parseLong(uplinkCircuitCountStr);
- } catch (NumberFormatException e) {
- throw new SvcLogicException(
- "Invalid tmp.resource-allocator.uplink-circuit-list.uplink-circuit_length. Must be a number.");
- }
- List<Map<String, Object>> uplinkCircuitList = new ArrayList<>();
- for (int i = 0; i < uplinkCircuitCount; i++) {
- String uplinkCircuitId = ctx.getAttribute(
- "tmp.resource-allocator.uplink-circuit-list.uplink-circuit[" + i + "].uplink-circuit-id");
- String uplinkCircuitBandwidthStr =
- ctx.getAttribute("tmp.resource-allocator.uplink-circuit-list.uplink-circuit[" + i +
- "].uplink-circuit-bandwidth");
- String uplinkCircuitBandwidthUnit =
- ctx.getAttribute("tmp.resource-allocator.uplink-circuit-list.uplink-circuit[" + i +
- "].uplink-circuit-bandwidth-unit");
-
- long uplinkCircuitBandwidth = 0;
- try {
- uplinkCircuitBandwidth = Long.parseLong(uplinkCircuitBandwidthStr);
- } catch (NumberFormatException e) {
- throw new SvcLogicException("Invalid tmp.resource-allocator.uplink-circuit-list.uplink-circuit[" +
- i + "].uplink-circuit-id. Must be a number.");
- }
-
- long uplinkCircuitBandwidthKbps =
- speedUtil.convertToKbps(uplinkCircuitBandwidth, uplinkCircuitBandwidthUnit);
-
- Map<String, Object> uplinkCircuit = new HashMap<String, Object>();
- uplinkCircuit.put("uplink-circuit-id", uplinkCircuitId);
- uplinkCircuit.put("uplink-circuit-bandwidth", uplinkCircuitBandwidthKbps);
- uplinkCircuitList.add(uplinkCircuit);
- }
- mm.put("uplink-circuit-list", uplinkCircuitList);
- }
-
- return mm;
- }
-
- private void setOutputContext(SvcLogicContext ctx, long maxAvailableSpeed, String unit) {
- ctx.setAttribute("tmp.resource-allocator-output.max-available-speed", String.valueOf(maxAvailableSpeed));
- ctx.setAttribute("tmp.resource-allocator-output.speed-unit", unit);
- }
-
- private int calculatePrimaryServerCount(int serverCount, String ratioString) throws SvcLogicException {
- String[] ss = ratioString.split(":");
- if (ss.length != 2)
- throw new SvcLogicException("Invalid value for homing.pserver.sparing.ratio: " + ratioString);
-
- int n = 1, m = 1;
- try {
- n = Integer.parseInt(ss[0]);
- m = Integer.parseInt(ss[1]);
- } catch (Exception e) {
- throw new SvcLogicException("Invalid value for homing.pserver.sparing.ratio: " + ratioString);
- }
-
- return (serverCount - 1) * n / (n + m) + 1;
- }
-
- public void setServerDao(ServerDao serverDao) {
- this.serverDao = serverDao;
- }
-
- public void setVpePortDao(VpePortDao vpePortDao) {
- this.vpePortDao = vpePortDao;
- }
-
- public void setVplspePortDao(VplspePortDao vplspePortDao) {
- this.vplspePortDao = vplspePortDao;
- }
-
- public void setMaxPortSpeedDao(MaxPortSpeedDao maxPortSpeedDao) {
- this.maxPortSpeedDao = maxPortSpeedDao;
- }
-
- public void setMaxServerSpeedDao(MaxServerSpeedDao maxServerSpeedDao) {
- this.maxServerSpeedDao = maxServerSpeedDao;
- }
-
- public void setAllocationRequestBuilder(AllocationRequestBuilder allocationRequestBuilder) {
- this.allocationRequestBuilder = allocationRequestBuilder;
- }
-
- public void setResourceManager(ResourceManager resourceManager) {
- this.resourceManager = resourceManager;
- }
-
- public void setSpeedUtil(SpeedUtil speedUtil) {
- this.speedUtil = speedUtil;
- }
-
- public void setServiceResourceDao(ServiceResourceDao serviceResourceDao) {
- this.serviceResourceDao = serviceResourceDao;
- }
-
- public void setEndPointAllocator(EndPointAllocator endPointAllocator) {
- this.endPointAllocator = endPointAllocator;
- }
-
- public void setParameterDao(ParameterDao parameterDao) {
- this.parameterDao = parameterDao;
- }
+ private static final Logger log = LoggerFactory.getLogger(ResourceAllocator.class);
+
+ public ResourceAllocator() {
+ log.info("ResourceAllocator created.");
+ }
+
+ private ServerDao serverDao;
+ private VpePortDao vpePortDao;
+ private VplspePortDao vplspePortDao;
+ private MaxPortSpeedDao maxPortSpeedDao;
+ private MaxServerSpeedDao maxServerSpeedDao;
+ private ServiceResourceDao serviceResourceDao;
+ private ParameterDao parameterDao;
+
+ private AllocationRequestBuilder allocationRequestBuilder;
+ private ResourceManager resourceManager;
+ private SpeedUtil speedUtil;
+
+ private EndPointAllocator endPointAllocator;
+
+ @Override
+ public QueryStatus notify(String resource, String action, String key, SvcLogicContext ctx)
+ throws SvcLogicException {
+ return (QueryStatus.SUCCESS);
+ }
+
+ @Override
+ public QueryStatus update(
+ String resource,
+ String key,
+ Map<String, String> parms,
+ String prefix,
+ SvcLogicContext ctx) throws SvcLogicException {
+
+ return QueryStatus.SUCCESS;
+ }
+
+ @Override
+ public QueryStatus exists(String resource, String key, String prefix, SvcLogicContext ctx)
+ throws SvcLogicException {
+ return QueryStatus.SUCCESS;
+ }
+
+ @Override
+ public QueryStatus delete(String arg0, String arg1, SvcLogicContext arg2) throws SvcLogicException {
+ return QueryStatus.SUCCESS;
+ }
+
+ @Override
+ public QueryStatus save(
+ String arg0,
+ boolean arg1,
+ boolean arg2,
+ String arg3,
+ Map<String, String> arg4,
+ String arg5,
+ SvcLogicContext arg6) throws SvcLogicException {
+ return QueryStatus.SUCCESS;
+ }
+
+ @Override
+ public QueryStatus isAvailable(String resource, String key, String prefix, SvcLogicContext ctx)
+ throws SvcLogicException {
+ String serviceModel = ctx.getAttribute("tmp.resource-allocator.service-model");
+ if (serviceModel != null && serviceModel.trim().length() > 0)
+ return allocateResources(serviceModel, ctx, true, prefix);
+ return allocateResourcesL3SDN(ctx, true, prefix);
+ }
+
+ @Override
+ public QueryStatus query(
+ String resource,
+ boolean localOnly,
+ String select,
+ String key,
+ String prefix,
+ String orderBy,
+ SvcLogicContext ctx) throws SvcLogicException {
+
+ prefix = prefix == null ? "" : prefix + '.';
+
+ if (!resource.equals("NetworkCapacity")) {
+ log.info("resource: " + resource);
+ log.info("key: " + key);
+
+ Resource r = resourceManager.getResource(resource, key);
+ if (r == null)
+ return QueryStatus.NOT_FOUND;
+
+ if (r instanceof LimitResource) {
+ ctx.setAttribute(prefix + "used", String.valueOf(((LimitResource) r).used));
+
+ log.info("Added context attr: " + prefix + "used: " + String.valueOf(((LimitResource) r).used));
+ }
+
+ return QueryStatus.SUCCESS;
+ }
+
+ log.info("key: " + key);
+ log.info("prefix: " + prefix);
+
+ if (key == null)
+ return QueryStatus.SUCCESS;
+
+ if (key.startsWith("'") && key.endsWith("'"))
+ key = key.substring(1, key.length() - 1);
+
+ String endPointPosition = "VPE-Cust";
+
+ String resourceUnionId = key + '/' + endPointPosition;
+ List<Resource> rlist = resourceManager.getResourceUnion(resourceUnionId);
+
+ log.info("Resources found for " + resourceUnionId + ": " + rlist.size());
+
+ String assetId = null;
+ for (Resource r : rlist) {
+ log.info("Resource: " + r.resourceKey.resourceName);
+
+ if (r instanceof RangeResource) {
+ RangeResource rr = (RangeResource) r;
+ for (AllocationItem ai : r.allocationItems)
+ if (ai.resourceUnionId.equals(resourceUnionId)) {
+ RangeAllocationItem rai = (RangeAllocationItem) ai;
+ ctx.setAttribute(prefix + r.resourceKey.resourceName, String.valueOf(rai.used.first()));
+
+ log.info("Added context attr: " + prefix + r.resourceKey.resourceName + ": " +
+ String.valueOf(rr.used.first()));
+
+ assetId = r.resourceKey.assetId;
+ String vpeName = assetId;
+ int i1 = assetId.indexOf('/');
+ if (i1 > 0)
+ vpeName = assetId.substring(0, i1);
+ ctx.setAttribute(prefix + "vpe-name", vpeName);
+
+ log.info("Added context attr: " + prefix + "vpe-name: " + vpeName);
+ }
+ }
+ }
+
+ String affinityLink = "1";
+ if (assetId != null) {
+ for (Resource r : rlist) {
+ if (r instanceof LimitResource) {
+ LimitResource ll = (LimitResource) r;
+ if (ll.resourceKey.assetId.startsWith(assetId + '-')) {
+ int i1 = ll.resourceKey.assetId.lastIndexOf('-');
+ affinityLink = ll.resourceKey.assetId.substring(i1 + 1);
+ break;
+ }
+ }
+ }
+ }
+
+ ctx.setAttribute(prefix + "affinity-link", affinityLink);
+
+ log.info("Added context attr: " + prefix + "affinity-link: " + affinityLink);
+
+ return QueryStatus.SUCCESS;
+ }
+
+ @Override
+ public QueryStatus reserve(String resource, String select, String key, String prefix, SvcLogicContext ctx)
+ throws SvcLogicException {
+ String serviceModel = ctx.getAttribute("tmp.resource-allocator.service-model");
+ if (serviceModel != null && serviceModel.trim().length() > 0)
+ return allocateResources(serviceModel, ctx, false, prefix);
+ return allocateResourcesL3SDN(ctx, false, prefix);
+ }
+
+ @Override
+ public QueryStatus release(String resource, String key, SvcLogicContext ctx) throws SvcLogicException {
+ String serviceInstanceId = ctx.getAttribute("tmp.resource-allocator.service-instance-id");
+ if (serviceInstanceId == null)
+ throw new SvcLogicException("tmp.resource-allocator.service-instance-id is required in ResourceAllocator");
+
+ String requestTypeStr = ctx.getAttribute("tmp.resource-allocator.request-type");
+ if (requestTypeStr == null)
+ throw new SvcLogicException("tmp.resource-allocator.request-type is required in ResourceAllocator");
+
+ ReleaseRequestType requestType = null;
+ try {
+ requestType = ReleaseRequestType.convert(requestTypeStr);
+ } catch (IllegalArgumentException e) {
+ throw new SvcLogicException("Invalid tmp.resource-allocator.request-type: " + requestTypeStr +
+ ". Supported values are Cancel, Activate, Disconnect.");
+ }
+
+ log.info("Starting release: " + requestType + " for: " + serviceInstanceId);
+
+ ServiceResource activeServiceResource =
+ serviceResourceDao.getServiceResource(serviceInstanceId, ServiceStatus.Active);
+ ServiceResource pendingServiceResource =
+ serviceResourceDao.getServiceResource(serviceInstanceId, ServiceStatus.Pending);
+
+ log.info("Active ServiceResource: ");
+ StrUtil.info(log, activeServiceResource);
+ log.info("Pending ServiceResource: ");
+ StrUtil.info(log, pendingServiceResource);
+
+ if (requestType == ReleaseRequestType.Cancel) {
+ if (pendingServiceResource != null) {
+ log.info("Releasing pending resources: " + pendingServiceResource.resourceSetId);
+
+ resourceManager.releaseResourceSet(pendingServiceResource.resourceSetId);
+ serviceResourceDao.deleteServiceResource(serviceInstanceId, ServiceStatus.Pending);
+ } else {
+ log.info("Pending record not found for service instance: " + serviceInstanceId + ". Nothing to do.");
+ }
+
+ } else if (requestType == ReleaseRequestType.Activate) {
+ if (pendingServiceResource != null) {
+ if (activeServiceResource != null) {
+ log.info("Releasing active resources: " + activeServiceResource.resourceSetId);
+
+ resourceManager.releaseResourceSet(activeServiceResource.resourceSetId);
+ serviceResourceDao.deleteServiceResource(serviceInstanceId, ServiceStatus.Active);
+ }
+
+ log.info("Updating the status of the pending record to active.");
+
+ serviceResourceDao.updateServiceStatus(serviceInstanceId, ServiceStatus.Pending, ServiceStatus.Active);
+ } else {
+ log.info("Pending record not found for service instance: " + serviceInstanceId + ". Nothing to do.");
+ }
+
+ } else if (requestType == ReleaseRequestType.Disconnect) {
+ if (pendingServiceResource != null) {
+ log.info("Releasing pending resources: " + pendingServiceResource.resourceSetId);
+
+ resourceManager.releaseResourceSet(pendingServiceResource.resourceSetId);
+ serviceResourceDao.deleteServiceResource(serviceInstanceId, ServiceStatus.Pending);
+ }
+ if (activeServiceResource != null) {
+ log.info("Releasing active resources: " + activeServiceResource.resourceSetId);
+
+ resourceManager.releaseResourceSet(activeServiceResource.resourceSetId);
+ serviceResourceDao.deleteServiceResource(serviceInstanceId, ServiceStatus.Active);
+ }
+ }
+
+ return QueryStatus.SUCCESS;
+ }
+
+ private QueryStatus allocateResourcesL3SDN(SvcLogicContext ctx, boolean checkOnly, String prefix)
+ throws SvcLogicException {
+ prefix = prefix == null ? "" : prefix + '.';
+
+ String aicSiteId = getAicSiteId(ctx);
+ Map<String, Object> service = getServiceData(ctx);
+
+ String requestTypeStr = ctx.getAttribute("tmp.resource-allocator.request-type");
+ if (requestTypeStr == null)
+ requestTypeStr = "New";
+
+ ReserveRequestType requestType = null;
+ try {
+ requestType = ReserveRequestType.convert(requestTypeStr);
+ } catch (IllegalArgumentException e) {
+ throw new SvcLogicException("Invalid tmp.resource-allocator.request-type: " + requestTypeStr +
+ ". Supported values are New, Change.");
+ }
+
+ String serviceInstanceId = String.valueOf(service.get("service-instance-id"));
+
+ ServiceResource activeServiceResource =
+ serviceResourceDao.getServiceResource(serviceInstanceId, ServiceStatus.Active);
+ ServiceResource pendingServiceResource =
+ serviceResourceDao.getServiceResource(serviceInstanceId, ServiceStatus.Pending);
+
+ log.info("Active ServiceResource: ");
+ StrUtil.info(log, activeServiceResource);
+ log.info("Pending ServiceResource: ");
+ StrUtil.info(log, pendingServiceResource);
+
+ ServiceResource sr = new ServiceResource();
+ sr.serviceInstanceId = serviceInstanceId;
+ sr.serviceStatus = ServiceStatus.Pending;
+ sr.serviceChangeNumber = 1;
+ if (pendingServiceResource != null)
+ sr.serviceChangeNumber = pendingServiceResource.serviceChangeNumber + 1;
+ else if (activeServiceResource != null)
+ sr.serviceChangeNumber = activeServiceResource.serviceChangeNumber + 1;
+ sr.resourceSetId = serviceInstanceId + "/" + sr.serviceChangeNumber;
+ sr.resourceUnionId = serviceInstanceId;
+
+ log.info("New ServiceResource: ");
+ StrUtil.info(log, sr);
+
+ List<Map<String, Object>> vpePortData = vpePortDao.getVpePortData(aicSiteId);
+ List<Map<String, Object>> vplspePortData = vplspePortDao.getVplspePortData(aicSiteId);
+ List<Map<String, Object>> serverData = serverDao.getServerData(aicSiteId);
+
+ vpePortData = orderVpe(vpePortData);
+
+ long maxAvailableSpeedVpePort = 0;
+ boolean vpePortFound = false;
+
+ for (Map<String, Object> vpe : vpePortData) {
+ String vpeId = String.valueOf(vpe.get("vpe-id"));
+ String interfaceName = String.valueOf(vpe.get("physical-interface-name"));
+ String portId = vpeId + "/" + interfaceName;
+
+ log.info("Checking VPE port: " + portId);
+
+ String provStatus = String.valueOf(vpe.get("provisioning-status"));
+ if (!provStatus.equals("PROV")) {
+ log.info("Skipping port " + portId + ": Provisioning status is not PROV.");
+ continue;
+ }
+
+ String imageFile = String.valueOf(vpe.get("image-file-name"));
+ String endPointPosition = "VPE-Cust";
+ long maxPortSpeed = maxPortSpeedDao.getMaxPortSpeed(imageFile, endPointPosition, interfaceName);
+ vpe.put("max-port-speed", maxPortSpeed);
+
+ EquipmentData ed = new EquipmentData();
+ ed.data = vpe;
+ ed.equipmentId = portId;
+ ed.equipmentLevel = EquipmentLevel.Port;
+
+ ServiceData sd = new ServiceData();
+ sd.data = service;
+ sd.serviceModel = "L3SDN";
+ sd.endPointPosition = endPointPosition;
+ sd.resourceUnionId = sr.resourceUnionId;
+ sd.resourceSetId = sr.resourceSetId;
+
+ StrUtil.info(log, ed);
+ StrUtil.info(log, sd);
+
+ AllocationRequest ar = allocationRequestBuilder.buildAllocationRequest(sd, ed, checkOnly,
+ requestType == ReserveRequestType.Change);
+ AllocationOutcome ao = resourceManager.allocateResources(ar);
+
+ if (ao.status == AllocationStatus.Success) {
+
+ // Assign affinity link
+ if (!checkOnly) {
+ List<String> affinityLinkIdList = new ArrayList<>();
+ affinityLinkIdList.add("0");
+ affinityLinkIdList.add("1");
+ affinityLinkIdList.add("2");
+ affinityLinkIdList.add("3");
+
+ String preferedAffinityLinkId = "0";
+ long lowestAssignedBw = Long.MAX_VALUE;
+ for (String affinityLinkId : affinityLinkIdList) {
+ long used = 0;
+ String assetId = ed.equipmentId + "-" + affinityLinkId;
+ Resource r = resourceManager.getResource("Bandwidth", assetId);
+ if (r != null) {
+ LimitResource ll = (LimitResource) r;
+ used = ll.used;
+ }
+ if (used < lowestAssignedBw) {
+ lowestAssignedBw = used;
+ preferedAffinityLinkId = affinityLinkId;
+ }
+ log.info("Assigned bandwidth on affinity link: " + assetId + ": " + used);
+ }
+
+ log.info("Prefered affinity link for " + ed.equipmentId + ": " + preferedAffinityLinkId);
+
+ ctx.setAttribute(prefix + "affinity-link", preferedAffinityLinkId);
+
+ LimitAllocationRequest ar1 = new LimitAllocationRequest();
+ ar1.resourceSetId = sd.resourceSetId;
+ ar1.resourceUnionId = sd.resourceUnionId;
+ ar1.resourceShareGroupList = null;
+ ar1.resourceName = "Bandwidth";
+ ar1.assetId = ed.equipmentId + "-" + preferedAffinityLinkId;
+ ar1.missingResourceAction = AllocationAction.Succeed_Allocate;
+ ar1.expiredResourceAction = AllocationAction.Succeed_Allocate;
+ ar1.replace = true;
+ ar1.strict = false;
+ ar1.checkLimit = Long.MAX_VALUE;
+ ar1.checkCount = 0;
+ ar1.allocateCount = (Long) sd.data.get("service-speed-kbps");
+
+ resourceManager.allocateResources(ar1);
+ }
+
+ ctx.setAttribute(prefix + "vpe-name", vpeId);
+
+ vpePortFound = true;
+ break;
+ }
+
+ if (ao instanceof LimitAllocationOutcome) {
+ LimitAllocationOutcome lao = (LimitAllocationOutcome) ao;
+ long available = lao.limit - lao.used;
+ if (available > maxAvailableSpeedVpePort)
+ maxAvailableSpeedVpePort = available;
+ }
+ }
+
+ long maxAvailableSpeedVplspePort = 0;
+ boolean vplspePortFound = false;
+
+ for (Map<String, Object> vplspe : vplspePortData) {
+ String vplspeId = String.valueOf(vplspe.get("vplspe-id"));
+ String interfaceName = String.valueOf(vplspe.get("physical-interface-name"));
+ String portId = vplspeId + "/" + interfaceName;
+
+ log.info("Checking VPLSPE port: " + portId);
+
+ String provStatus = String.valueOf(vplspe.get("provisioning-status"));
+ if (!provStatus.equals("PROV")) {
+ log.info("Skipping port " + portId + ": Provisioning status is not PROV.");
+ continue;
+ }
+
+ long physicalSpeed = (Long) vplspe.get("physical-interface-speed");
+ String physicalSpeedUnit = String.valueOf(vplspe.get("physical-interface-speed-unit"));
+ long maxPortSpeed = speedUtil.convertToKbps(physicalSpeed, physicalSpeedUnit);
+ vplspe.put("max-port-speed", maxPortSpeed);
+
+ EquipmentData ed = new EquipmentData();
+ ed.data = vplspe;
+ ed.equipmentId = portId;
+ ed.equipmentLevel = EquipmentLevel.Port;
+
+ ServiceData sd = new ServiceData();
+ sd.data = service;
+ sd.serviceModel = "L3SDN";
+ sd.endPointPosition = "IPAG-TOA";
+ sd.resourceUnionId = sr.resourceUnionId;
+ sd.resourceSetId = sr.resourceSetId;
+
+ StrUtil.info(log, ed);
+ StrUtil.info(log, sd);
+
+ AllocationRequest ar = allocationRequestBuilder.buildAllocationRequest(sd, ed, checkOnly,
+ requestType == ReserveRequestType.Change);
+ AllocationOutcome ao = resourceManager.allocateResources(ar);
+
+ if (ao.status == AllocationStatus.Success) {
+ vplspePortFound = true;
+ break;
+ }
+
+ if (ao instanceof LimitAllocationOutcome) {
+ LimitAllocationOutcome lao = (LimitAllocationOutcome) ao;
+ long available = lao.limit - lao.used;
+ if (available > maxAvailableSpeedVplspePort)
+ maxAvailableSpeedVplspePort = available;
+ }
+ }
+
+ long maxAvailableSpeedServer = 0;
+ boolean serverFound = false;
+
+ for (Map<String, Object> server : serverData) {
+ String serverId = String.valueOf(server.get("server-id"));
+ String serverModel = String.valueOf(server.get("server-model"));
+
+ log.info("Checking Server: " + serverId);
+
+ String endPointPosition = "VCE-Cust";
+
+ int serverCount = (Integer) server.get("server-count");
+ if (serverCount == 0)
+ serverCount = 1;
+ String ratioString = parameterDao.getParameter("homing.pserver.sparing.ratio");
+ if (ratioString == null || ratioString.length() == 0)
+ ratioString = "1:1";
+ int primaryServerCount = calculatePrimaryServerCount(serverCount, ratioString);
+ server.put("number-primary-servers", primaryServerCount);
+
+ int evcCount = getEvcCountOnServer(serverId);
+ int evcCountPerServer = (evcCount + primaryServerCount - 1) / primaryServerCount;
+ long maxServerSpeed = maxServerSpeedDao.getMaxServerSpeed(serverModel, evcCountPerServer);
+ server.put("max-server-speed", maxServerSpeed);
+ server.put("evc-count", evcCount);
+ server.put("evc-count-per-server", evcCountPerServer);
+
+ EquipmentData ed = new EquipmentData();
+ ed.data = server;
+ ed.equipmentId = serverId;
+ ed.equipmentLevel = EquipmentLevel.Server;
+
+ ServiceData sd = new ServiceData();
+ sd.data = service;
+ sd.serviceModel = "L3SDN";
+ sd.endPointPosition = endPointPosition;
+ sd.resourceUnionId = sr.resourceUnionId;
+ sd.resourceSetId = sr.resourceSetId;
+
+ StrUtil.info(log, ed);
+ StrUtil.info(log, sd);
+
+ AllocationRequest ar = allocationRequestBuilder.buildAllocationRequest(sd, ed, checkOnly,
+ requestType == ReserveRequestType.Change);
+ AllocationOutcome ao = resourceManager.allocateResources(ar);
+
+ if (ao.status == AllocationStatus.Success) {
+ serverFound = true;
+
+ if (ao instanceof MultiResourceAllocationOutcome) {
+ MultiResourceAllocationOutcome mrao = (MultiResourceAllocationOutcome) ao;
+ for (AllocationOutcome ao1 : mrao.allocationOutcomeList) {
+ if (ao1 instanceof LimitAllocationOutcome) {
+ LimitAllocationOutcome lao = (LimitAllocationOutcome) ao1;
+ if (lao.request.resourceName.equals("Bandwidth")) {
+ ThresholdStatus th = allocationRequestBuilder.getThresholdStatus(sd, ed, lao);
+ setThresholdData(ctx, th, sd, ed);
+ }
+ }
+ }
+ }
+
+ break;
+ }
+
+ if (ao instanceof MultiResourceAllocationOutcome) {
+ MultiResourceAllocationOutcome mrao = (MultiResourceAllocationOutcome) ao;
+ for (AllocationOutcome ao1 : mrao.allocationOutcomeList) {
+ if (ao1 instanceof LimitAllocationOutcome) {
+ LimitAllocationOutcome lao = (LimitAllocationOutcome) ao1;
+ if (lao.status == AllocationStatus.Failure && lao.request.resourceName.equals("Bandwidth")) {
+ long available = lao.limit - lao.used;
+ if (available > maxAvailableSpeedServer)
+ maxAvailableSpeedServer = available;
+ }
+ if (lao.status == AllocationStatus.Failure && lao.request.resourceName.equals("Connection")) {
+ maxAvailableSpeedServer = 0;
+ break;
+ }
+
+ ThresholdStatus th = allocationRequestBuilder.getThresholdStatus(sd, ed, lao);
+ setThresholdData(ctx, th, sd, ed);
+ }
+ }
+ }
+ }
+
+ if (vpePortFound && vplspePortFound && serverFound) {
+ if (!checkOnly) {
+ if (pendingServiceResource == null) {
+ log.info("Adding the pending service resource record to DB.");
+ serviceResourceDao.addServiceResource(sr);
+ } else {
+ log.info("Releasing previously allocated resources for resource set id: " +
+ pendingServiceResource.resourceSetId);
+ resourceManager.releaseResourceSet(pendingServiceResource.resourceSetId);
+
+ log.info("Updating the pending service resource record in DB with service change number: " +
+ sr.serviceChangeNumber);
+ serviceResourceDao.updateServiceResource(sr);
+ }
+ }
+
+ return QueryStatus.SUCCESS;
+ }
+
+ log.info("Releasing allocated resources (if any) for resource set id: " + sr.resourceSetId);
+ resourceManager.releaseResourceSet(sr.resourceSetId);
+
+ long maxAvailableSpeed = Long.MAX_VALUE;
+ if (!vpePortFound && maxAvailableSpeedVpePort < maxAvailableSpeed)
+ maxAvailableSpeed = maxAvailableSpeedVpePort;
+ if (!vplspePortFound && maxAvailableSpeedVplspePort < maxAvailableSpeed)
+ maxAvailableSpeed = maxAvailableSpeedVplspePort;
+ if (!serverFound && maxAvailableSpeedServer < maxAvailableSpeed)
+ maxAvailableSpeed = maxAvailableSpeedServer;
+
+ setOutputContext(ctx, maxAvailableSpeed, "kbps");
+ return QueryStatus.NOT_FOUND;
+ }
+
+ private List<Map<String, Object>> orderVpe(List<Map<String, Object>> vpePortData) {
+ for (Map<String, Object> vpe : vpePortData) {
+ String vpeId = String.valueOf(vpe.get("vpe-id"));
+ String interfaceName = String.valueOf(vpe.get("physical-interface-name"));
+ String portId = vpeId + "/" + interfaceName;
+ Resource r = resourceManager.getResource("Bandwidth", portId);
+ long used = 0;
+ if (r != null) {
+ LimitResource ll = (LimitResource) r;
+ used = ll.used;
+ }
+ vpe.put("used-bandwidth", used);
+
+ log.info("Used bandwidth on VPE: " + vpeId + ": " + used);
+ }
+
+ Collections.sort(vpePortData, new Comparator<Map<String, Object>>() {
+
+ @Override
+ public int compare(Map<String, Object> o1, Map<String, Object> o2) {
+ long used1 = (Long) o1.get("used-bandwidth");
+ long used2 = (Long) o2.get("used-bandwidth");
+ if (used1 < used2)
+ return -1;
+ if (used1 > used2)
+ return 1;
+ return 0;
+ }
+ });
+
+ return vpePortData;
+ }
+
+ private void setThresholdData(SvcLogicContext ctx, ThresholdStatus th, ServiceData sd, EquipmentData ed) {
+ if (th == null)
+ return;
+
+ String pp = "tmp.resource-allocator-output.threshold-notification-list.threshold-hotification[0].";
+ ctx.setAttribute("tmp.resource-allocator-output.threshold-notification-list.threshold-hotification_length",
+ "1");
+ ctx.setAttribute(pp + "message", th.resourceThreshold.message);
+ ctx.setAttribute(pp + "resource-rule.service-model", th.resourceRule.serviceModel);
+ ctx.setAttribute(pp + "resource-rule.endpoint-position", th.resourceRule.endPointPosition);
+ ctx.setAttribute(pp + "resource-rule.resource-name", th.resourceRule.resourceName);
+ ctx.setAttribute(pp + "resource-rule.equipment-level", th.resourceRule.equipmentLevel);
+ ctx.setAttribute(pp + "resource-rule.soft-limit-expression", th.resourceRule.softLimitExpression);
+ ctx.setAttribute(pp + "resource-rule.hard-limit-expression", th.resourceRule.hardLimitExpression);
+ ctx.setAttribute(pp + "resource-state.used", String.valueOf(th.used));
+ ctx.setAttribute(pp + "resource-state.limit-value", String.valueOf(th.limitValue));
+ ctx.setAttribute(pp + "resource-state.threshold-value", String.valueOf(th.thresholdValue));
+ ctx.setAttribute(pp + "resource-state.last-added", String.valueOf(th.lastAdded));
+ ctx.setAttribute(pp + "equipment-data.equipment-id", ed.equipmentId);
+ for (String edKey : ed.data.keySet())
+ ctx.setAttribute(pp + "equipment-data." + edKey, String.valueOf(ed.data.get(edKey)));
+ }
+
+ private QueryStatus allocateResources(String serviceModel, SvcLogicContext ctx, boolean checkOnly, String prefix)
+ throws SvcLogicException {
+ prefix = prefix == null ? "" : prefix + '.';
+
+ Map<String, Object> service = getServiceData(ctx);
+ Map<String, Object> ec = getEquipConstraints(ctx);
+
+ String requestTypeStr = ctx.getAttribute("tmp.resource-allocator.request-type");
+ if (requestTypeStr == null)
+ requestTypeStr = "New";
+
+ ReserveRequestType requestType = null;
+ try {
+ requestType = ReserveRequestType.convert(requestTypeStr);
+ } catch (IllegalArgumentException e) {
+ throw new SvcLogicException("Invalid tmp.resource-allocator.request-type: " + requestTypeStr +
+ ". Supported values are New, Change.");
+ }
+
+ String serviceInstanceId = String.valueOf(service.get("service-instance-id"));
+
+ log.info("Starting reserve: " + requestType + ", service-instance-id: " + serviceInstanceId);
+
+ ServiceResource activeServiceResource =
+ serviceResourceDao.getServiceResource(serviceInstanceId, ServiceStatus.Active);
+ ServiceResource pendingServiceResource =
+ serviceResourceDao.getServiceResource(serviceInstanceId, ServiceStatus.Pending);
+
+ log.info("Active ServiceResource: ");
+ StrUtil.info(log, activeServiceResource);
+ log.info("Pending ServiceResource: ");
+ StrUtil.info(log, pendingServiceResource);
+
+ int changeNumber = 1;
+ if (pendingServiceResource != null)
+ changeNumber = pendingServiceResource.serviceChangeNumber + 1;
+ else if (activeServiceResource != null)
+ changeNumber = activeServiceResource.serviceChangeNumber + 1;
+
+ ServiceData sd = new ServiceData();
+ sd.data = service;
+ sd.serviceModel = serviceModel;
+ sd.endPointPosition = (String) service.get("end-point-position");
+ sd.resourceShareGroup = (String) service.get("resource-share-group");
+ sd.resourceName = (String) service.get("resource-name");
+ sd.serviceInstanceId = serviceInstanceId;
+
+ StrUtil.info(log, sd);
+
+ List<EndPointData> epList = endPointAllocator.allocateEndPoints(sd, ec, checkOnly,
+ requestType == ReserveRequestType.Change, changeNumber);
+
+ if (epList != null && !epList.isEmpty()) {
+ if (!checkOnly) {
+ EndPointData ep = epList.get(0);
+
+ if (sd.resourceName == null) {
+ ServiceResource sr = new ServiceResource();
+ sr.serviceInstanceId = serviceInstanceId;
+ sr.serviceStatus = ServiceStatus.Pending;
+ sr.serviceChangeNumber = changeNumber;
+ sr.resourceSetId = ep.resourceSetId;
+ sr.resourceUnionId = ep.resourceUnionId;
+
+ log.info("New ServiceResource: ");
+ StrUtil.info(log, sr);
+
+ if (pendingServiceResource == null) {
+ log.info("Adding the pending service resource record to DB.");
+ serviceResourceDao.addServiceResource(sr);
+ } else {
+ log.info("Releasing previously allocated resources for resource set id: " +
+ pendingServiceResource.resourceSetId);
+ resourceManager.releaseResourceSet(pendingServiceResource.resourceSetId);
+
+ log.info("Updating the pending service resource record in DB with service change number: " +
+ sr.serviceChangeNumber);
+ serviceResourceDao.updateServiceResource(sr);
+ }
+ }
+
+ for (EndPointData ep1 : epList)
+ if (ep1.data != null && !ep1.data.isEmpty())
+ for (String key : ep1.data.keySet()) {
+ String value = String.valueOf(ep1.data.get(key));
+ ctx.setAttribute(prefix + key, value);
+
+ log.info("Added context attr: " + prefix + key + ": " + value);
+ }
+ }
+
+ return QueryStatus.SUCCESS;
+ }
+
+ log.info("Capacity not found for EVC: " + serviceInstanceId);
+
+ return QueryStatus.NOT_FOUND;
+ }
+
+ private int getEvcCountOnServer(String serverId) {
+ LimitResource l = (LimitResource) resourceManager.getResource("Connection", serverId);
+ if (l != null)
+ return (int) l.used;
+ return 0;
+ }
+
+ private String getAicSiteId(SvcLogicContext ctx) throws SvcLogicException {
+ String aicSiteId = ctx.getAttribute("tmp.resource-allocator.aic-site-id");
+ if (aicSiteId == null)
+ throw new SvcLogicException("tmp.resource-allocator.aic-site-id is required in ResourceAllocator");
+ return aicSiteId;
+ }
+
+ private Map<String, Object> getServiceData(SvcLogicContext ctx) throws SvcLogicException {
+ Map<String, Object> sd = new HashMap<String, Object>();
+
+ String endPointPosition = ctx.getAttribute("tmp.resource-allocator.end-point-position");
+ if (endPointPosition != null && endPointPosition.trim().length() > 0)
+ sd.put("end-point-position", endPointPosition.trim());
+
+ String resourceName = ctx.getAttribute("tmp.resource-allocator.resource-name");
+ if (resourceName != null && resourceName.trim().length() > 0)
+ sd.put("resource-name", resourceName.trim());
+
+ String resourceShareGroup = ctx.getAttribute("tmp.resource-allocator.resource-share-group");
+ if (resourceShareGroup != null && resourceShareGroup.trim().length() > 0)
+ sd.put("resource-share-group", resourceShareGroup.trim());
+
+ String serviceInstanceId = ctx.getAttribute("tmp.resource-allocator.service-instance-id");
+ if (serviceInstanceId == null)
+ serviceInstanceId = "checkServiceInstance";
+ sd.put("service-instance-id", serviceInstanceId);
+
+ String speedStr = ctx.getAttribute("tmp.resource-allocator.speed");
+ if (speedStr != null && speedStr.trim().length() > 0) {
+ long speed = 0;
+ try {
+ speed = Long.parseLong(speedStr);
+ } catch (NumberFormatException e) {
+ throw new SvcLogicException("Invalid tmp.resource-allocator.speed. Must be a number.");
+ }
+ String unit = ctx.getAttribute("tmp.resource-allocator.speed-unit");
+ if (unit == null || unit.trim().length() == 0)
+ throw new SvcLogicException("tmp.resource-allocator.speed-unit is required in ResourceAllocator");
+ long serviceSpeedKbps = speedUtil.convertToKbps(speed, unit);
+
+ sd.put("service-speed-kbps", serviceSpeedKbps);
+ }
+
+ String vpnId = ctx.getAttribute("tmp.resource-allocator.vpn-id");
+ if (vpnId != null && vpnId.trim().length() > 0)
+ sd.put("vpn-id", vpnId.trim());
+
+ String vpnIdList = ctx.getAttribute("tmp.resource-allocator.vpn-id-list");
+ if (vpnIdList != null && vpnIdList.trim().length() > 0)
+ sd.put("vpn-id-list", vpnIdList.trim());
+
+ String vrfName = ctx.getAttribute("tmp.resource-allocator.vrf-name");
+ if (vrfName != null && vrfName.trim().length() > 0)
+ sd.put("vrf-name", vrfName.trim());
+
+ String vrfNameList = ctx.getAttribute("tmp.resource-allocator.vrf-name-list");
+ if (vrfNameList != null && vrfNameList.trim().length() > 0)
+ sd.put("vrf-name-list", vrfNameList.trim());
+
+ String v4multicast = ctx.getAttribute("tmp.resource-allocator.v4-multicast");
+ if (v4multicast != null && v4multicast.trim().length() > 0)
+ sd.put("v4-multicast", v4multicast.trim());
+
+ String v6multicast = ctx.getAttribute("tmp.resource-allocator.v6-multicast");
+ if (v6multicast != null && v6multicast.trim().length() > 0)
+ sd.put("v6-multicast", v6multicast.trim());
+
+ String v4ServingSite = ctx.getAttribute("tmp.resource-allocator.v4-serving-site");
+ if (v4ServingSite != null && v4ServingSite.trim().length() > 0)
+ sd.put("v4-serving-site", v4ServingSite.trim());
+
+ String v6ServingSite = ctx.getAttribute("tmp.resource-allocator.v6-serving-site");
+ if (v6ServingSite != null && v6ServingSite.trim().length() > 0)
+ sd.put("v6-serving-site", v6ServingSite.trim());
+
+ return sd;
+ }
+
+ private Map<String, Object> getEquipConstraints(SvcLogicContext ctx) throws SvcLogicException {
+ Map<String, Object> mm = new HashMap<String, Object>();
+
+ String vrfRequired = ctx.getAttribute("tmp.resource-allocator.vrf-required");
+ if (vrfRequired != null && vrfRequired.trim().length() > 0)
+ mm.put("vrf-required", vrfRequired.trim());
+
+ String clli = ctx.getAttribute("tmp.resource-allocator.clli");
+ if (clli == null || clli.trim().length() == 0)
+ clli = ctx.getAttribute("tmp.resource-allocator.aic-site-id");
+ if (clli != null) {
+ mm.put("clli", clli.trim());
+ mm.put("aic-site-id", clli.trim());
+ }
+
+ String vpeName = ctx.getAttribute("tmp.resource-allocator.vpe-name");
+ if (vpeName != null && vpeName.trim().length() > 0)
+ mm.put("vpe-name", vpeName.trim());
+
+ String vnfName = ctx.getAttribute("tmp.resource-allocator.device-name");
+ if (vnfName != null && vnfName.trim().length() > 0)
+ mm.put("vnf-name", vnfName.trim());
+
+ String excludeVpeList = ctx.getAttribute("tmp.resource-allocator.exclude-vpe-list");
+ if (excludeVpeList != null && excludeVpeList.trim().length() > 0)
+ mm.put("exclude-vpe-list", excludeVpeList.trim());
+
+ String uplinkCircuitCountStr =
+ ctx.getAttribute("tmp.resource-allocator.uplink-circuit-list.uplink-circuit_length");
+ if (uplinkCircuitCountStr != null) {
+ long uplinkCircuitCount = 0;
+ try {
+ uplinkCircuitCount = Long.parseLong(uplinkCircuitCountStr);
+ } catch (NumberFormatException e) {
+ throw new SvcLogicException(
+ "Invalid tmp.resource-allocator.uplink-circuit-list.uplink-circuit_length. Must be a number.");
+ }
+ List<Map<String, Object>> uplinkCircuitList = new ArrayList<>();
+ for (int i = 0; i < uplinkCircuitCount; i++) {
+ String uplinkCircuitId = ctx.getAttribute(
+ "tmp.resource-allocator.uplink-circuit-list.uplink-circuit[" + i + "].uplink-circuit-id");
+ String uplinkCircuitBandwidthStr =
+ ctx.getAttribute("tmp.resource-allocator.uplink-circuit-list.uplink-circuit[" + i +
+ "].uplink-circuit-bandwidth");
+ String uplinkCircuitBandwidthUnit =
+ ctx.getAttribute("tmp.resource-allocator.uplink-circuit-list.uplink-circuit[" + i +
+ "].uplink-circuit-bandwidth-unit");
+
+ long uplinkCircuitBandwidth = 0;
+ try {
+ uplinkCircuitBandwidth = Long.parseLong(uplinkCircuitBandwidthStr);
+ } catch (NumberFormatException e) {
+ throw new SvcLogicException("Invalid tmp.resource-allocator.uplink-circuit-list.uplink-circuit[" +
+ i + "].uplink-circuit-id. Must be a number.");
+ }
+
+ long uplinkCircuitBandwidthKbps =
+ speedUtil.convertToKbps(uplinkCircuitBandwidth, uplinkCircuitBandwidthUnit);
+
+ Map<String, Object> uplinkCircuit = new HashMap<String, Object>();
+ uplinkCircuit.put("uplink-circuit-id", uplinkCircuitId);
+ uplinkCircuit.put("uplink-circuit-bandwidth", uplinkCircuitBandwidthKbps);
+ uplinkCircuitList.add(uplinkCircuit);
+ }
+ mm.put("uplink-circuit-list", uplinkCircuitList);
+ }
+
+ return mm;
+ }
+
+ private void setOutputContext(SvcLogicContext ctx, long maxAvailableSpeed, String unit) {
+ ctx.setAttribute("tmp.resource-allocator-output.max-available-speed", String.valueOf(maxAvailableSpeed));
+ ctx.setAttribute("tmp.resource-allocator-output.speed-unit", unit);
+ }
+
+ private int calculatePrimaryServerCount(int serverCount, String ratioString) throws SvcLogicException {
+ String[] ss = ratioString.split(":");
+ if (ss.length != 2)
+ throw new SvcLogicException("Invalid value for homing.pserver.sparing.ratio: " + ratioString);
+
+ int n = 1, m = 1;
+ try {
+ n = Integer.parseInt(ss[0]);
+ m = Integer.parseInt(ss[1]);
+ } catch (Exception e) {
+ throw new SvcLogicException("Invalid value for homing.pserver.sparing.ratio: " + ratioString);
+ }
+
+ return (serverCount - 1) * n / (n + m) + 1;
+ }
+
+ public void setServerDao(ServerDao serverDao) {
+ this.serverDao = serverDao;
+ }
+
+ public void setVpePortDao(VpePortDao vpePortDao) {
+ this.vpePortDao = vpePortDao;
+ }
+
+ public void setVplspePortDao(VplspePortDao vplspePortDao) {
+ this.vplspePortDao = vplspePortDao;
+ }
+
+ public void setMaxPortSpeedDao(MaxPortSpeedDao maxPortSpeedDao) {
+ this.maxPortSpeedDao = maxPortSpeedDao;
+ }
+
+ public void setMaxServerSpeedDao(MaxServerSpeedDao maxServerSpeedDao) {
+ this.maxServerSpeedDao = maxServerSpeedDao;
+ }
+
+ public void setAllocationRequestBuilder(AllocationRequestBuilder allocationRequestBuilder) {
+ this.allocationRequestBuilder = allocationRequestBuilder;
+ }
+
+ public void setResourceManager(ResourceManager resourceManager) {
+ this.resourceManager = resourceManager;
+ }
+
+ public void setSpeedUtil(SpeedUtil speedUtil) {
+ this.speedUtil = speedUtil;
+ }
+
+ public void setServiceResourceDao(ServiceResourceDao serviceResourceDao) {
+ this.serviceResourceDao = serviceResourceDao;
+ }
+
+ public void setEndPointAllocator(EndPointAllocator endPointAllocator) {
+ this.endPointAllocator = endPointAllocator;
+ }
+
+ public void setParameterDao(ParameterDao parameterDao) {
+ this.parameterDao = parameterDao;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/alloc/AffinityAllocationRule.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/alloc/AffinityAllocationRule.java
index b77df92a7..7245216f3 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/alloc/AffinityAllocationRule.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/alloc/AffinityAllocationRule.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,37 +32,37 @@ import org.slf4j.LoggerFactory;
public class AffinityAllocationRule implements AllocationRule {
- @SuppressWarnings("unused")
- private static final Logger log = LoggerFactory.getLogger(AffinityAllocationRule.class);
+ @SuppressWarnings("unused")
+ private static final Logger log = LoggerFactory.getLogger(AffinityAllocationRule.class);
- @Override
- public AllocationRequest buildAllocationRequest(
- String resourceUnionId,
- String resourceSetId,
- String endPointPosition,
- ServiceData serviceData,
- EquipmentData equipmentData,
- boolean checkOnly,
- boolean change) {
- String affinityLink = (String) equipmentData.data.get("affinity-link");
- if (affinityLink == null)
- affinityLink = "1";
+ @Override
+ public AllocationRequest buildAllocationRequest(
+ String resourceUnionId,
+ String resourceSetId,
+ String endPointPosition,
+ ServiceData serviceData,
+ EquipmentData equipmentData,
+ boolean checkOnly,
+ boolean change) {
+ String affinityLink = (String) equipmentData.data.get("affinity-link");
+ if (affinityLink == null)
+ affinityLink = "1";
- long serviceSpeed = (Long) serviceData.data.get("service-speed-kbps");
+ long serviceSpeed = (Long) serviceData.data.get("service-speed-kbps");
- LimitAllocationRequest ar = new LimitAllocationRequest();
- ar.resourceSetId = resourceSetId;
- ar.resourceUnionId = resourceUnionId;
- ar.resourceShareGroupList = null;
- ar.resourceName = "Bandwidth";
- ar.assetId = equipmentData.equipmentId + "-" + affinityLink;
- ar.missingResourceAction = AllocationAction.Succeed_Allocate;
- ar.expiredResourceAction = AllocationAction.Succeed_Allocate;
- ar.replace = true;
- ar.strict = false;
- ar.checkLimit = Long.MAX_VALUE;
- ar.checkCount = 0;
- ar.allocateCount = serviceSpeed;
- return ar;
- }
+ LimitAllocationRequest ar = new LimitAllocationRequest();
+ ar.resourceSetId = resourceSetId;
+ ar.resourceUnionId = resourceUnionId;
+ ar.resourceShareGroupList = null;
+ ar.resourceName = "Bandwidth";
+ ar.assetId = equipmentData.equipmentId + "-" + affinityLink;
+ ar.missingResourceAction = AllocationAction.Succeed_Allocate;
+ ar.expiredResourceAction = AllocationAction.Succeed_Allocate;
+ ar.replace = true;
+ ar.strict = false;
+ ar.checkLimit = Long.MAX_VALUE;
+ ar.checkCount = 0;
+ ar.allocateCount = serviceSpeed;
+ return ar;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/alloc/DbAllocationRule.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/alloc/DbAllocationRule.java
index a066378ac..847883957 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/alloc/DbAllocationRule.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/alloc/DbAllocationRule.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,112 +44,112 @@ 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 resourceUnionId,
- String resourceSetId,
- String endPointPosition,
- ServiceData serviceData,
- EquipmentData equipmentData,
- boolean checkOnly,
- boolean change) {
- List<ResourceRule> resourceRuleList = resourceRuleDao.getResourceRules(serviceData.serviceModel,
- endPointPosition, equipmentData.equipmentLevel);
- List<RangeRule> rangeRuleList =
- rangeRuleDao.getRangeRules(serviceData.serviceModel, endPointPosition, equipmentData.equipmentLevel);
-
- List<AllocationRequest> arlist = new ArrayList<AllocationRequest>();
-
- for (ResourceRule rr : resourceRuleList) {
- if (serviceData.resourceName != null && !serviceData.resourceName.equals(rr.resourceName))
- continue;
- AllocationRequest ar1 = buildAllocationRequest(rr, resourceUnionId, resourceSetId, serviceData,
- equipmentData, checkOnly, change);
- arlist.add(ar1);
- }
- for (RangeRule rr : rangeRuleList) {
- if (serviceData.resourceName != null && !serviceData.resourceName.equals(rr.rangeName))
- continue;
- AllocationRequest ar1 = buildAllocationRequest(rr, resourceUnionId, resourceSetId, serviceData,
- equipmentData, 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,
- String resourceUnionId,
- String resourceSetId,
- ServiceData serviceData,
- EquipmentData equipmentData,
- boolean checkOnly,
- boolean change) {
- StrUtil.info(log, resourceRule);
-
- LimitAllocationRequest ar = new LimitAllocationRequest();
- ar.resourceSetId = resourceSetId;
- ar.resourceUnionId = resourceUnionId;
- ar.resourceName = resourceRule.resourceName;
- if (serviceData.resourceShareGroup != null)
- ar.resourceShareGroupList = Collections.singleton(serviceData.resourceShareGroup);
- ar.assetId = equipmentData.equipmentId;
- ar.missingResourceAction = AllocationAction.Succeed_Allocate;
- ar.expiredResourceAction = AllocationAction.Succeed_Allocate;
- ar.replace = true;
- ar.strict = false;
- ar.checkLimit = ExpressionEvaluator.evalLong(
- change ? resourceRule.hardLimitExpression : resourceRule.softLimitExpression, equipmentData.data);;
- ar.checkCount = ExpressionEvaluator.evalLong(resourceRule.allocationExpression, serviceData.data);
- ar.allocateCount = checkOnly ? 0 : ar.checkCount;
- return ar;
- }
-
- private AllocationRequest buildAllocationRequest(
- RangeRule rangeRule,
- String resourceUnionId,
- String resourceSetId,
- ServiceData serviceData,
- EquipmentData equipmentData,
- boolean checkOnly,
- boolean change) {
- StrUtil.info(log, rangeRule);
-
- RangeAllocationRequest ar = new RangeAllocationRequest();
- ar.resourceSetId = resourceSetId;
- ar.resourceUnionId = resourceUnionId;
- ar.resourceName = rangeRule.rangeName;
- ar.assetId = equipmentData.equipmentId;
- ar.missingResourceAction = AllocationAction.Succeed_Allocate;
- ar.expiredResourceAction = AllocationAction.Succeed_Allocate;
- ar.replace = true;
- ar.check = true;
- ar.allocate = !checkOnly;
- ar.checkMin = rangeRule.minValue;
- ar.checkMax = 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 resourceUnionId,
+ String resourceSetId,
+ String endPointPosition,
+ ServiceData serviceData,
+ EquipmentData equipmentData,
+ boolean checkOnly,
+ boolean change) {
+ List<ResourceRule> resourceRuleList = resourceRuleDao.getResourceRules(serviceData.serviceModel,
+ endPointPosition, equipmentData.equipmentLevel);
+ List<RangeRule> rangeRuleList =
+ rangeRuleDao.getRangeRules(serviceData.serviceModel, endPointPosition, equipmentData.equipmentLevel);
+
+ List<AllocationRequest> arlist = new ArrayList<AllocationRequest>();
+
+ for (ResourceRule rr : resourceRuleList) {
+ if (serviceData.resourceName != null && !serviceData.resourceName.equals(rr.resourceName))
+ continue;
+ AllocationRequest ar1 = buildAllocationRequest(rr, resourceUnionId, resourceSetId, serviceData,
+ equipmentData, checkOnly, change);
+ arlist.add(ar1);
+ }
+ for (RangeRule rr : rangeRuleList) {
+ if (serviceData.resourceName != null && !serviceData.resourceName.equals(rr.rangeName))
+ continue;
+ AllocationRequest ar1 = buildAllocationRequest(rr, resourceUnionId, resourceSetId, serviceData,
+ equipmentData, 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,
+ String resourceUnionId,
+ String resourceSetId,
+ ServiceData serviceData,
+ EquipmentData equipmentData,
+ boolean checkOnly,
+ boolean change) {
+ StrUtil.info(log, resourceRule);
+
+ LimitAllocationRequest ar = new LimitAllocationRequest();
+ ar.resourceSetId = resourceSetId;
+ ar.resourceUnionId = resourceUnionId;
+ ar.resourceName = resourceRule.resourceName;
+ if (serviceData.resourceShareGroup != null)
+ ar.resourceShareGroupList = Collections.singleton(serviceData.resourceShareGroup);
+ ar.assetId = equipmentData.equipmentId;
+ ar.missingResourceAction = AllocationAction.Succeed_Allocate;
+ ar.expiredResourceAction = AllocationAction.Succeed_Allocate;
+ ar.replace = true;
+ ar.strict = false;
+ ar.checkLimit = ExpressionEvaluator.evalLong(
+ change ? resourceRule.hardLimitExpression : resourceRule.softLimitExpression, equipmentData.data);;
+ ar.checkCount = ExpressionEvaluator.evalLong(resourceRule.allocationExpression, serviceData.data);
+ ar.allocateCount = checkOnly ? 0 : ar.checkCount;
+ return ar;
+ }
+
+ private AllocationRequest buildAllocationRequest(
+ RangeRule rangeRule,
+ String resourceUnionId,
+ String resourceSetId,
+ ServiceData serviceData,
+ EquipmentData equipmentData,
+ boolean checkOnly,
+ boolean change) {
+ StrUtil.info(log, rangeRule);
+
+ RangeAllocationRequest ar = new RangeAllocationRequest();
+ ar.resourceSetId = resourceSetId;
+ ar.resourceUnionId = resourceUnionId;
+ ar.resourceName = rangeRule.rangeName;
+ ar.assetId = equipmentData.equipmentId;
+ ar.missingResourceAction = AllocationAction.Succeed_Allocate;
+ ar.expiredResourceAction = AllocationAction.Succeed_Allocate;
+ ar.replace = true;
+ ar.check = true;
+ ar.allocate = !checkOnly;
+ ar.checkMin = rangeRule.minValue;
+ ar.checkMax = rangeRule.maxValue;
+ 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/openecomp/sdnc/ra/alloc/ServingSiteAllocationRule.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/alloc/ServingSiteAllocationRule.java
index cb36a8bef..cf1dd8f8e 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/alloc/ServingSiteAllocationRule.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/alloc/ServingSiteAllocationRule.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,47 +34,47 @@ import org.slf4j.LoggerFactory;
public class ServingSiteAllocationRule implements AllocationRule {
- private static final Logger log = LoggerFactory.getLogger(ServingSiteAllocationRule.class);
+ private static final Logger log = LoggerFactory.getLogger(ServingSiteAllocationRule.class);
- @Override
- public AllocationRequest buildAllocationRequest(
- String resourceUnionId,
- String resourceSetId,
- String endPointPosition,
- ServiceData serviceData,
- EquipmentData equipmentData,
- boolean checkOnly,
- boolean change) {
- String vrfName = (String) serviceData.data.get("vrf-name");
- if (vrfName == null)
- return null;
+ @Override
+ public AllocationRequest buildAllocationRequest(
+ String resourceUnionId,
+ String resourceSetId,
+ String endPointPosition,
+ ServiceData serviceData,
+ EquipmentData equipmentData,
+ boolean checkOnly,
+ boolean change) {
+ String vrfName = (String) serviceData.data.get("vrf-name");
+ if (vrfName == null)
+ return null;
- log.info("vrfName: " + vrfName);
+ log.info("vrfName: " + vrfName);
- String v4ServingSiteStr = (String) serviceData.data.get("v4-serving-site");
- String v6ServingSiteStr = (String) serviceData.data.get("v6-serving-site");
- boolean v4ServingSite = v4ServingSiteStr != null &&
- (v4ServingSiteStr.equalsIgnoreCase("Y") || v4ServingSiteStr.equalsIgnoreCase("true"));
- boolean v6ServingSite = v6ServingSiteStr != null &&
- (v6ServingSiteStr.equalsIgnoreCase("Y") || v6ServingSiteStr.equalsIgnoreCase("true"));
- if (!v4ServingSite && !v6ServingSite)
- return null;
+ String v4ServingSiteStr = (String) serviceData.data.get("v4-serving-site");
+ String v6ServingSiteStr = (String) serviceData.data.get("v6-serving-site");
+ boolean v4ServingSite = v4ServingSiteStr != null &&
+ (v4ServingSiteStr.equalsIgnoreCase("Y") || v4ServingSiteStr.equalsIgnoreCase("true"));
+ boolean v6ServingSite = v6ServingSiteStr != null &&
+ (v6ServingSiteStr.equalsIgnoreCase("Y") || v6ServingSiteStr.equalsIgnoreCase("true"));
+ if (!v4ServingSite && !v6ServingSite)
+ return null;
- VpnParam vpnp = VrfUtil.parseVrfInstanceName(vrfName);
+ VpnParam vpnp = VrfUtil.parseVrfInstanceName(vrfName);
- LimitAllocationRequest ar = new LimitAllocationRequest();
- ar.resourceSetId = resourceSetId;
- ar.resourceUnionId = resourceUnionId;
- ar.resourceName = "ServingSite";
- ar.assetId = equipmentData.equipmentId + "-" + vpnp.vpnId;
- ar.missingResourceAction = AllocationAction.Succeed_Allocate;
- ar.expiredResourceAction = AllocationAction.Succeed_Allocate;
- ar.replace = true;
- ar.strict = false;
- ar.checkLimit = 1;
- ar.checkCount = 1;
- ar.allocateCount = 1;
+ LimitAllocationRequest ar = new LimitAllocationRequest();
+ ar.resourceSetId = resourceSetId;
+ ar.resourceUnionId = resourceUnionId;
+ ar.resourceName = "ServingSite";
+ ar.assetId = equipmentData.equipmentId + "-" + vpnp.vpnId;
+ ar.missingResourceAction = AllocationAction.Succeed_Allocate;
+ ar.expiredResourceAction = AllocationAction.Succeed_Allocate;
+ ar.replace = true;
+ ar.strict = false;
+ ar.checkLimit = 1;
+ ar.checkCount = 1;
+ ar.allocateCount = 1;
- return ar;
- }
+ return ar;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/alloc/VrfAllocationRule.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/alloc/VrfAllocationRule.java
index f23f1e985..cc4adfb3e 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/alloc/VrfAllocationRule.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/alloc/VrfAllocationRule.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,75 +37,75 @@ import org.slf4j.LoggerFactory;
public class VrfAllocationRule implements AllocationRule {
- private static final Logger log = LoggerFactory.getLogger(VrfAllocationRule.class);
+ private static final Logger log = LoggerFactory.getLogger(VrfAllocationRule.class);
- @Override
- public AllocationRequest buildAllocationRequest(
- String resourceUnionId,
- String resourceSetId,
- String endPointPosition,
- ServiceData serviceData,
- EquipmentData equipmentData,
- boolean checkOnly,
- boolean change) {
- String vrfName = (String) serviceData.data.get("vrf-name");
- if (vrfName == null)
- return null;
+ @Override
+ public AllocationRequest buildAllocationRequest(
+ String resourceUnionId,
+ String resourceSetId,
+ String endPointPosition,
+ ServiceData serviceData,
+ EquipmentData equipmentData,
+ boolean checkOnly,
+ boolean change) {
+ String vrfName = (String) serviceData.data.get("vrf-name");
+ if (vrfName == null)
+ return null;
- log.info("vrfName: " + vrfName);
+ log.info("vrfName: " + vrfName);
- Set<String> resourceShareGroupList = new HashSet<>();
- resourceShareGroupList.add(vrfName);
+ Set<String> resourceShareGroupList = new HashSet<>();
+ resourceShareGroupList.add(vrfName);
- LimitAllocationRequest ar = new LimitAllocationRequest();
- ar.resourceSetId = resourceSetId;
- ar.resourceUnionId = resourceUnionId;
- ar.resourceShareGroupList = resourceShareGroupList;
- ar.resourceName = "VRF";
- ar.assetId = equipmentData.equipmentId;
- ar.missingResourceAction = AllocationAction.Succeed_Allocate;
- ar.expiredResourceAction = AllocationAction.Succeed_Allocate;
- ar.replace = true;
- ar.strict = false;
- ar.checkLimit = 999999999;
- ar.checkCount = 1;
- ar.allocateCount = 1;
+ LimitAllocationRequest ar = new LimitAllocationRequest();
+ ar.resourceSetId = resourceSetId;
+ ar.resourceUnionId = resourceUnionId;
+ ar.resourceShareGroupList = resourceShareGroupList;
+ ar.resourceName = "VRF";
+ ar.assetId = equipmentData.equipmentId;
+ ar.missingResourceAction = AllocationAction.Succeed_Allocate;
+ ar.expiredResourceAction = AllocationAction.Succeed_Allocate;
+ ar.replace = true;
+ ar.strict = false;
+ ar.checkLimit = 999999999;
+ ar.checkCount = 1;
+ ar.allocateCount = 1;
- String v4MulticastStr = (String) serviceData.data.get("v4-multicast");
- String v6MulticastStr = (String) serviceData.data.get("v6-multicast");
- boolean v4Multicast = v4MulticastStr != null &&
- (v4MulticastStr.equalsIgnoreCase("Y") || v4MulticastStr.equalsIgnoreCase("true"));
- boolean v6Multicast = v6MulticastStr != null &&
- (v6MulticastStr.equalsIgnoreCase("Y") || v6MulticastStr.equalsIgnoreCase("true"));
- if (v4Multicast || v6Multicast) {
- LimitAllocationRequest ar2 = new LimitAllocationRequest();
- ar2.resourceSetId = resourceSetId;
- ar2.resourceUnionId = resourceUnionId;
- ar2.resourceShareGroupList = resourceShareGroupList;
- ar2.resourceName = "MVRF";
- ar2.assetId = equipmentData.equipmentId;
- ar2.missingResourceAction = AllocationAction.Succeed_Allocate;
- ar2.expiredResourceAction = AllocationAction.Succeed_Allocate;
- ar2.replace = true;
- ar2.strict = false;
- ar2.checkLimit = 999999999;
- ar2.checkCount = 1;
- ar2.allocateCount = 1;
+ String v4MulticastStr = (String) serviceData.data.get("v4-multicast");
+ String v6MulticastStr = (String) serviceData.data.get("v6-multicast");
+ boolean v4Multicast = v4MulticastStr != null &&
+ (v4MulticastStr.equalsIgnoreCase("Y") || v4MulticastStr.equalsIgnoreCase("true"));
+ boolean v6Multicast = v6MulticastStr != null &&
+ (v6MulticastStr.equalsIgnoreCase("Y") || v6MulticastStr.equalsIgnoreCase("true"));
+ if (v4Multicast || v6Multicast) {
+ LimitAllocationRequest ar2 = new LimitAllocationRequest();
+ ar2.resourceSetId = resourceSetId;
+ ar2.resourceUnionId = resourceUnionId;
+ ar2.resourceShareGroupList = resourceShareGroupList;
+ ar2.resourceName = "MVRF";
+ ar2.assetId = equipmentData.equipmentId;
+ ar2.missingResourceAction = AllocationAction.Succeed_Allocate;
+ ar2.expiredResourceAction = AllocationAction.Succeed_Allocate;
+ ar2.replace = true;
+ ar2.strict = false;
+ ar2.checkLimit = 999999999;
+ ar2.checkCount = 1;
+ ar2.allocateCount = 1;
- MultiResourceAllocationRequest mar = new MultiResourceAllocationRequest();
- mar.resourceSetId = resourceSetId;
- mar.resourceUnionId = resourceUnionId;
- mar.resourceShareGroupList = resourceShareGroupList;
- mar.assetId = equipmentData.equipmentId;
- mar.missingResourceAction = AllocationAction.Succeed_Allocate;
- mar.expiredResourceAction = AllocationAction.Succeed_Allocate;
- mar.allocationRequestList = new ArrayList<>();
- mar.allocationRequestList.add(ar);
- mar.allocationRequestList.add(ar2);
+ MultiResourceAllocationRequest mar = new MultiResourceAllocationRequest();
+ mar.resourceSetId = resourceSetId;
+ mar.resourceUnionId = resourceUnionId;
+ mar.resourceShareGroupList = resourceShareGroupList;
+ mar.assetId = equipmentData.equipmentId;
+ mar.missingResourceAction = AllocationAction.Succeed_Allocate;
+ mar.expiredResourceAction = AllocationAction.Succeed_Allocate;
+ mar.allocationRequestList = new ArrayList<>();
+ mar.allocationRequestList.add(ar);
+ mar.allocationRequestList.add(ar2);
- return mar;
- }
+ return mar;
+ }
- return ar;
- }
+ return ar;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/AnyVrfPresentCheck.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/AnyVrfPresentCheck.java
index aee761c7e..fd9ca1e55 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/AnyVrfPresentCheck.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/AnyVrfPresentCheck.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,41 +34,41 @@ import org.slf4j.LoggerFactory;
public class AnyVrfPresentCheck implements EquipmentCheck {
- private static final Logger log = LoggerFactory.getLogger(AnyVrfPresentCheck.class);
+ private static final Logger log = LoggerFactory.getLogger(AnyVrfPresentCheck.class);
- private ResourceManager resourceManager;
+ private ResourceManager resourceManager;
- @Override
- public boolean checkEquipment(
- String endPointPosition,
- ServiceData serviceData,
- EquipmentData equipData,
- Map<String, Object> equipmentConstraints) {
- String vrfNameListStr = (String) serviceData.data.get("vrf-name-list");
- if (vrfNameListStr == null)
- vrfNameListStr = (String) serviceData.data.get("vrf-name");
- if (vrfNameListStr == null)
- return true;
+ @Override
+ public boolean checkEquipment(
+ String endPointPosition,
+ ServiceData serviceData,
+ EquipmentData equipData,
+ Map<String, Object> equipmentConstraints) {
+ String vrfNameListStr = (String) serviceData.data.get("vrf-name-list");
+ if (vrfNameListStr == null)
+ vrfNameListStr = (String) serviceData.data.get("vrf-name");
+ if (vrfNameListStr == null)
+ return true;
- String vrfRequiredStr = (String) equipmentConstraints.get("vrf-required");
- if (vrfRequiredStr == null || !vrfRequiredStr.equalsIgnoreCase("true"))
- return true;
+ String vrfRequiredStr = (String) equipmentConstraints.get("vrf-required");
+ if (vrfRequiredStr == null || !vrfRequiredStr.equalsIgnoreCase("true"))
+ return true;
- String[] vrfNameList = vrfNameListStr.split(",");
+ String[] vrfNameList = vrfNameListStr.split(",");
- Resource r = resourceManager.getResource("VRF", equipData.equipmentId);
- if (r != null && r.allocationItems != null)
- for (AllocationItem ai : r.allocationItems)
- for (String vrfName : vrfNameList)
- if (ai.resourceShareGroupList.contains(vrfName))
- return true;
+ Resource r = resourceManager.getResource("VRF", equipData.equipmentId);
+ if (r != null && r.allocationItems != null)
+ for (AllocationItem ai : r.allocationItems)
+ for (String vrfName : vrfNameList)
+ if (ai.resourceShareGroupList.contains(vrfName))
+ return true;
- log.info("Skipping VPE " + equipData.equipmentId +
- ": Existing VRF is required, but there is no existing VRF on the VPE for any of the requested VPNs.");
- return false;
- }
+ log.info("Skipping VPE " + equipData.equipmentId +
+ ": Existing VRF is required, but there is no existing VRF on the VPE for any of the requested VPNs.");
+ return false;
+ }
- public void setResourceManager(ResourceManager resourceManager) {
- this.resourceManager = resourceManager;
- }
+ public void setResourceManager(ResourceManager resourceManager) {
+ this.resourceManager = resourceManager;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/ExcludeVpeCheck.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/ExcludeVpeCheck.java
index 25571fb2d..7ceac9020 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/ExcludeVpeCheck.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/ExcludeVpeCheck.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,27 +31,27 @@ import org.slf4j.LoggerFactory;
public class ExcludeVpeCheck implements EquipmentCheck {
- private static final Logger log = LoggerFactory.getLogger(ExcludeVpeCheck.class);
-
- @Override
- public boolean checkEquipment(
- String endPointPosition,
- ServiceData serviceData,
- EquipmentData equipData,
- Map<String, Object> equipmentConstraints) {
- String excludeVpeListStr = (String) equipmentConstraints.get("exclude-vpe-list");
- if (excludeVpeListStr == null)
- return true;
-
- String vpeName = (String) equipData.data.get("vpe-id");
-
- String[] excludeVpeList = excludeVpeListStr.split(",");
- for (String excludeVpe : excludeVpeList)
- if (excludeVpe.equals(vpeName)) {
- log.info("Skipping VPE " + equipData.equipmentId + ": Present in the exclude VPE list.");
- return false;
- }
-
- return true;
- }
+ private static final Logger log = LoggerFactory.getLogger(ExcludeVpeCheck.class);
+
+ @Override
+ public boolean checkEquipment(
+ String endPointPosition,
+ ServiceData serviceData,
+ EquipmentData equipData,
+ Map<String, Object> equipmentConstraints) {
+ String excludeVpeListStr = (String) equipmentConstraints.get("exclude-vpe-list");
+ if (excludeVpeListStr == null)
+ return true;
+
+ String vpeName = (String) equipData.data.get("vpe-id");
+
+ String[] excludeVpeList = excludeVpeListStr.split(",");
+ for (String excludeVpe : excludeVpeList)
+ if (excludeVpe.equals(vpeName)) {
+ log.info("Skipping VPE " + equipData.equipmentId + ": Present in the exclude VPE list.");
+ return false;
+ }
+
+ return true;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/HubWithRgCheck.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/HubWithRgCheck.java
index 6c2b4c591..79428de84 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/HubWithRgCheck.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/HubWithRgCheck.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,72 +36,72 @@ import org.slf4j.LoggerFactory;
public class HubWithRgCheck implements EquipmentCheck {
- private static final Logger log = LoggerFactory.getLogger(HubWithRgCheck.class);
-
- private ResourceManager resourceManager;
-
- @Override
- public boolean checkEquipment(
- String endPointPosition,
- ServiceData serviceData,
- EquipmentData equipData,
- Map<String, Object> equipmentConstraints) {
- String vrfName = (String) serviceData.data.get("vrf-name");
- if (vrfName == null)
- return true;
-
- // Check if this is HUB. If not, this check is not applicable
- VpnParam vpnp = VrfUtil.parseVrfInstanceName(vrfName);
- if (vpnp.siteType == null || !vpnp.siteType.equals("HUB"))
- return true;
-
- boolean rgPresent = vpnp.routeGroupName != null;
-
- // First check if a new VRF would be required. If not, we are good
- Resource r = resourceManager.getResource("VRF", equipData.equipmentId);
- if (r != null && r.allocationItems != null) {
- for (AllocationItem ai : r.allocationItems)
- if (ai.resourceShareGroupList.contains(vrfName))
- return true;
-
- String resourceUnionId = serviceData.serviceInstanceId + '/' + serviceData.endPointPosition;
-
- // Check if there is already another HUB VRF with RG presence that does not match the requested
- for (AllocationItem ai : r.allocationItems) {
-
- // Skip the allocation item for the current service instance, if there, in case it is a change order
- if (ai.resourceUnionId.equals(resourceUnionId))
- continue;
-
- if (ai.resourceShareGroupList != null && ai.resourceShareGroupList.size() > 0) {
- String vrfName2 = ai.resourceShareGroupList.iterator().next();
- VpnParam vpnp2 = VrfUtil.parseVrfInstanceName(vrfName2);
-
- if (vpnp2.siteType == null || !vpnp2.siteType.equals("HUB"))
- continue;
-
- boolean rgPresent2 = vpnp2.routeGroupName != null;
-
- if (rgPresent && !rgPresent2) {
- log.info("Skipping VPE " + equipData.equipmentId +
- ": This request requires new HUB with RG VRF, " +
- "but there is already another HUB VRF with no RG: " + vrfName2 + ".");
- return false;
- }
- if (!rgPresent && rgPresent2) {
- log.info("Skipping VPE " + equipData.equipmentId +
- ": This request requires new HUB VRF with no RG, " +
- "but there is already another HUB with RG VRF: " + vrfName2 + ".");
- return false;
- }
- }
- }
- }
-
- return true;
- }
-
- public void setResourceManager(ResourceManager resourceManager) {
- this.resourceManager = resourceManager;
- }
+ private static final Logger log = LoggerFactory.getLogger(HubWithRgCheck.class);
+
+ private ResourceManager resourceManager;
+
+ @Override
+ public boolean checkEquipment(
+ String endPointPosition,
+ ServiceData serviceData,
+ EquipmentData equipData,
+ Map<String, Object> equipmentConstraints) {
+ String vrfName = (String) serviceData.data.get("vrf-name");
+ if (vrfName == null)
+ return true;
+
+ // Check if this is HUB. If not, this check is not applicable
+ VpnParam vpnp = VrfUtil.parseVrfInstanceName(vrfName);
+ if (vpnp.siteType == null || !vpnp.siteType.equals("HUB"))
+ return true;
+
+ boolean rgPresent = vpnp.routeGroupName != null;
+
+ // First check if a new VRF would be required. If not, we are good
+ Resource r = resourceManager.getResource("VRF", equipData.equipmentId);
+ if (r != null && r.allocationItems != null) {
+ for (AllocationItem ai : r.allocationItems)
+ if (ai.resourceShareGroupList.contains(vrfName))
+ return true;
+
+ String resourceUnionId = serviceData.serviceInstanceId + '/' + serviceData.endPointPosition;
+
+ // Check if there is already another HUB VRF with RG presence that does not match the requested
+ for (AllocationItem ai : r.allocationItems) {
+
+ // Skip the allocation item for the current service instance, if there, in case it is a change order
+ if (ai.resourceUnionId.equals(resourceUnionId))
+ continue;
+
+ if (ai.resourceShareGroupList != null && ai.resourceShareGroupList.size() > 0) {
+ String vrfName2 = ai.resourceShareGroupList.iterator().next();
+ VpnParam vpnp2 = VrfUtil.parseVrfInstanceName(vrfName2);
+
+ if (vpnp2.siteType == null || !vpnp2.siteType.equals("HUB"))
+ continue;
+
+ boolean rgPresent2 = vpnp2.routeGroupName != null;
+
+ if (rgPresent && !rgPresent2) {
+ log.info("Skipping VPE " + equipData.equipmentId +
+ ": This request requires new HUB with RG VRF, " +
+ "but there is already another HUB VRF with no RG: " + vrfName2 + ".");
+ return false;
+ }
+ if (!rgPresent && rgPresent2) {
+ log.info("Skipping VPE " + equipData.equipmentId +
+ ": This request requires new HUB VRF with no RG, " +
+ "but there is already another HUB with RG VRF: " + vrfName2 + ".");
+ return false;
+ }
+ }
+ }
+ }
+
+ return true;
+ }
+
+ public void setResourceManager(ResourceManager resourceManager) {
+ this.resourceManager = resourceManager;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/OneMVrfCheck.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/OneMVrfCheck.java
index 56fd535e7..82e7e01a0 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/OneMVrfCheck.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/OneMVrfCheck.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,65 +36,65 @@ import org.slf4j.LoggerFactory;
public class OneMVrfCheck implements EquipmentCheck {
- private static final Logger log = LoggerFactory.getLogger(OneMVrfCheck.class);
+ private static final Logger log = LoggerFactory.getLogger(OneMVrfCheck.class);
- private ResourceManager resourceManager;
+ private ResourceManager resourceManager;
- @Override
- public boolean checkEquipment(
- String endPointPosition,
- ServiceData serviceData,
- EquipmentData equipData,
- Map<String, Object> equipmentConstraints) {
- String vrfName = (String) serviceData.data.get("vrf-name");
- if (vrfName == null)
- return true;
+ @Override
+ public boolean checkEquipment(
+ String endPointPosition,
+ ServiceData serviceData,
+ EquipmentData equipData,
+ Map<String, Object> equipmentConstraints) {
+ String vrfName = (String) serviceData.data.get("vrf-name");
+ if (vrfName == null)
+ return true;
- String v4MulticastStr = (String) serviceData.data.get("v4-multicast");
- String v6MulticastStr = (String) serviceData.data.get("v6-multicast");
- boolean v4Multicast = v4MulticastStr != null &&
- (v4MulticastStr.equalsIgnoreCase("Y") || v4MulticastStr.equalsIgnoreCase("true"));
- boolean v6Multicast = v6MulticastStr != null &&
- (v6MulticastStr.equalsIgnoreCase("Y") || v6MulticastStr.equalsIgnoreCase("true"));
- if (!v4Multicast && !v6Multicast)
- return true;
+ String v4MulticastStr = (String) serviceData.data.get("v4-multicast");
+ String v6MulticastStr = (String) serviceData.data.get("v6-multicast");
+ boolean v4Multicast = v4MulticastStr != null &&
+ (v4MulticastStr.equalsIgnoreCase("Y") || v4MulticastStr.equalsIgnoreCase("true"));
+ boolean v6Multicast = v6MulticastStr != null &&
+ (v6MulticastStr.equalsIgnoreCase("Y") || v6MulticastStr.equalsIgnoreCase("true"));
+ if (!v4Multicast && !v6Multicast)
+ return true;
- // First check if a new VRF would be required. If not, we are good
- Resource r = resourceManager.getResource("VRF", equipData.equipmentId);
- if (r != null && r.allocationItems != null)
- for (AllocationItem ai : r.allocationItems)
- if (ai.resourceShareGroupList.contains(vrfName))
- return true;
+ // First check if a new VRF would be required. If not, we are good
+ Resource r = resourceManager.getResource("VRF", equipData.equipmentId);
+ if (r != null && r.allocationItems != null)
+ for (AllocationItem ai : r.allocationItems)
+ if (ai.resourceShareGroupList.contains(vrfName))
+ return true;
- String resourceUnionId = serviceData.serviceInstanceId + '/' + serviceData.endPointPosition;
+ String resourceUnionId = serviceData.serviceInstanceId + '/' + serviceData.endPointPosition;
- // Check if there is already another multicast VRF for the same VPN
- VpnParam vpnp = VrfUtil.parseVrfInstanceName(vrfName);
- r = resourceManager.getResource("MVRF", equipData.equipmentId);
- if (r != null && r.allocationItems != null) {
- for (AllocationItem ai : r.allocationItems) {
+ // Check if there is already another multicast VRF for the same VPN
+ VpnParam vpnp = VrfUtil.parseVrfInstanceName(vrfName);
+ r = resourceManager.getResource("MVRF", equipData.equipmentId);
+ if (r != null && r.allocationItems != null) {
+ for (AllocationItem ai : r.allocationItems) {
- // Skip the allocation item for the current service instance, if there, in case it is a change order
- if (ai.resourceUnionId.equals(resourceUnionId))
- continue;
+ // Skip the allocation item for the current service instance, if there, in case it is a change order
+ if (ai.resourceUnionId.equals(resourceUnionId))
+ continue;
- if (ai.resourceShareGroupList != null && ai.resourceShareGroupList.size() > 0) {
- String vrfName2 = ai.resourceShareGroupList.iterator().next();
- VpnParam vpnp2 = VrfUtil.parseVrfInstanceName(vrfName2);
- if (vpnp.vpnId.equals(vpnp2.vpnId)) {
- log.info("Skipping VPE " + equipData.equipmentId +
- ": This request requires new multicast VRF, " +
- "but there is already another multicast VRF for the same VPN: " + vrfName2 + ".");
- return false;
- }
- }
- }
- }
+ if (ai.resourceShareGroupList != null && ai.resourceShareGroupList.size() > 0) {
+ String vrfName2 = ai.resourceShareGroupList.iterator().next();
+ VpnParam vpnp2 = VrfUtil.parseVrfInstanceName(vrfName2);
+ if (vpnp.vpnId.equals(vpnp2.vpnId)) {
+ log.info("Skipping VPE " + equipData.equipmentId +
+ ": This request requires new multicast VRF, " +
+ "but there is already another multicast VRF for the same VPN: " + vrfName2 + ".");
+ return false;
+ }
+ }
+ }
+ }
- return true;
- }
+ return true;
+ }
- public void setResourceManager(ResourceManager resourceManager) {
- this.resourceManager = resourceManager;
- }
+ public void setResourceManager(ResourceManager resourceManager) {
+ this.resourceManager = resourceManager;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/ProvStatusCheck.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/ProvStatusCheck.java
index baed60eb5..1ec079f9b 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/ProvStatusCheck.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/ProvStatusCheck.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,19 +31,19 @@ import org.slf4j.LoggerFactory;
public class ProvStatusCheck implements EquipmentCheck {
- private static final Logger log = LoggerFactory.getLogger(ProvStatusCheck.class);
+ private static final Logger log = LoggerFactory.getLogger(ProvStatusCheck.class);
- @Override
- public boolean checkEquipment(
- String endPointPosition,
- ServiceData serviceData,
- EquipmentData equipData,
- Map<String, Object> equipmentConstraints) {
- String provStatus = (String) equipData.data.get("provisioning-status");
- if (provStatus == null || !provStatus.equals("PROV")) {
- log.info("Skipping VPE " + equipData.equipmentId + ": Not in PROV status.");
- return false;
- }
- return true;
- }
+ @Override
+ public boolean checkEquipment(
+ String endPointPosition,
+ ServiceData serviceData,
+ EquipmentData equipData,
+ Map<String, Object> equipmentConstraints) {
+ String provStatus = (String) equipData.data.get("provisioning-status");
+ if (provStatus == null || !provStatus.equals("PROV")) {
+ log.info("Skipping VPE " + equipData.equipmentId + ": Not in PROV status.");
+ return false;
+ }
+ return true;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/VlanSpeedCheck.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/VlanSpeedCheck.java
index 4644a14a7..57b8f0377 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/VlanSpeedCheck.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/VlanSpeedCheck.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,20 +31,20 @@ import org.slf4j.LoggerFactory;
public class VlanSpeedCheck implements EquipmentCheck {
- private static final Logger log = LoggerFactory.getLogger(VlanSpeedCheck.class);
+ private static final Logger log = LoggerFactory.getLogger(VlanSpeedCheck.class);
- @Override
- public boolean checkEquipment(
- String endPointPosition,
- ServiceData serviceData,
- EquipmentData equipData,
- Map<String, Object> equipmentConstraints) {
- String vpeName = (String) equipData.data.get("vpe-id");
- Long serviceSpeed = (Long) serviceData.data.get("service-speed-kbps");
- if (serviceSpeed != null && serviceSpeed > 0 && serviceSpeed < 1000) {
- log.info("Skipping VPE " + vpeName + ": Service speed < 1Mbps is not supported.");
- return false;
- }
- return true;
- }
+ @Override
+ public boolean checkEquipment(
+ String endPointPosition,
+ ServiceData serviceData,
+ EquipmentData equipData,
+ Map<String, Object> equipmentConstraints) {
+ String vpeName = (String) equipData.data.get("vpe-id");
+ Long serviceSpeed = (Long) serviceData.data.get("service-speed-kbps");
+ if (serviceSpeed != null && serviceSpeed > 0 && serviceSpeed < 1000) {
+ log.info("Skipping VPE " + vpeName + ": Service speed < 1Mbps is not supported.");
+ return false;
+ }
+ return true;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/VpeLockCheck.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/VpeLockCheck.java
index 3b350b419..fe7bd30db 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/VpeLockCheck.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/check/VpeLockCheck.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,77 +35,77 @@ import org.slf4j.LoggerFactory;
public class VpeLockCheck implements EquipmentCheck {
- private static final Logger log = LoggerFactory.getLogger(VpeLockCheck.class);
-
- private VpeLockDao vpeLockDao;
- private ResourceManager resourceManager;
-
- @Override
- public boolean checkEquipment(
- String endPointPosition,
- ServiceData serviceData,
- EquipmentData equipData,
- Map<String, Object> equipmentConstraints) {
- String vrfName = (String) serviceData.data.get("vrf-name");
- if (vrfName == null)
- return true;
-
- String vpeName = (String) equipData.data.get("vpe-id");
- String vpeLock = vpeLockDao.getVpeLock(vpeName);
- if (vpeLock == null)
- return true;
-
- if (vpeLock.equals("vpe-total-lock")) {
- log.info("Skipping VPE " + vpeName + ": There is a " + vpeLock + " on it.");
- return false;
- }
-
- if (vpeLock.equals("vpe-vrf-lock") && requiresNewVrf(equipData.equipmentId, vrfName)) {
- log.info("Skipping VPE " + vpeName + ": There is a " + vpeLock +
- " on it and it requires a new VRF for VPN: " + vrfName + ".");
- return false;
- }
-
- if (vpeLock.equals("vpe-mvrf-lock") && requiresNewMVrf(equipData.equipmentId, vrfName)) {
- log.info("Skipping VPE " + vpeName + ": There is a " + vpeLock +
- " on it and it requires a new multicast VRF for VPN: " + vrfName + ".");
- return false;
- }
-
- return true;
- }
-
- boolean requiresNewVrf(String equipmentId, String vrfName) {
- Resource r = resourceManager.getResource("VRF", equipmentId);
- if (r == null || r.allocationItems == null)
- return true;
-
- for (AllocationItem ai : r.allocationItems) {
- if (ai.resourceShareGroupList.contains(vrfName))
- return false;
- }
-
- return true;
- }
-
- boolean requiresNewMVrf(String equipmentId, String vrfName) {
- Resource r = resourceManager.getResource("MVRF", equipmentId);
- if (r == null || r.allocationItems == null)
- return true;
-
- for (AllocationItem ai : r.allocationItems) {
- if (ai.resourceShareGroupList.contains(vrfName))
- return false;
- }
-
- return true;
- }
-
- public void setVpeLockDao(VpeLockDao vpeLockDao) {
- this.vpeLockDao = vpeLockDao;
- }
-
- public void setResourceManager(ResourceManager resourceManager) {
- this.resourceManager = resourceManager;
- }
+ private static final Logger log = LoggerFactory.getLogger(VpeLockCheck.class);
+
+ private VpeLockDao vpeLockDao;
+ private ResourceManager resourceManager;
+
+ @Override
+ public boolean checkEquipment(
+ String endPointPosition,
+ ServiceData serviceData,
+ EquipmentData equipData,
+ Map<String, Object> equipmentConstraints) {
+ String vrfName = (String) serviceData.data.get("vrf-name");
+ if (vrfName == null)
+ return true;
+
+ String vpeName = (String) equipData.data.get("vpe-id");
+ String vpeLock = vpeLockDao.getVpeLock(vpeName);
+ if (vpeLock == null)
+ return true;
+
+ if (vpeLock.equals("vpe-total-lock")) {
+ log.info("Skipping VPE " + vpeName + ": There is a " + vpeLock + " on it.");
+ return false;
+ }
+
+ if (vpeLock.equals("vpe-vrf-lock") && requiresNewVrf(equipData.equipmentId, vrfName)) {
+ log.info("Skipping VPE " + vpeName + ": There is a " + vpeLock +
+ " on it and it requires a new VRF for VPN: " + vrfName + ".");
+ return false;
+ }
+
+ if (vpeLock.equals("vpe-mvrf-lock") && requiresNewMVrf(equipData.equipmentId, vrfName)) {
+ log.info("Skipping VPE " + vpeName + ": There is a " + vpeLock +
+ " on it and it requires a new multicast VRF for VPN: " + vrfName + ".");
+ return false;
+ }
+
+ return true;
+ }
+
+ boolean requiresNewVrf(String equipmentId, String vrfName) {
+ Resource r = resourceManager.getResource("VRF", equipmentId);
+ if (r == null || r.allocationItems == null)
+ return true;
+
+ for (AllocationItem ai : r.allocationItems) {
+ if (ai.resourceShareGroupList.contains(vrfName))
+ return false;
+ }
+
+ return true;
+ }
+
+ boolean requiresNewMVrf(String equipmentId, String vrfName) {
+ Resource r = resourceManager.getResource("MVRF", equipmentId);
+ if (r == null || r.allocationItems == null)
+ return true;
+
+ for (AllocationItem ai : r.allocationItems) {
+ if (ai.resourceShareGroupList.contains(vrfName))
+ return false;
+ }
+
+ return true;
+ }
+
+ public void setVpeLockDao(VpeLockDao vpeLockDao) {
+ this.vpeLockDao = vpeLockDao;
+ }
+
+ public void setResourceManager(ResourceManager resourceManager) {
+ this.resourceManager = resourceManager;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/AllocationRule.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/AllocationRule.java
index 0877933b6..260d9d016 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/AllocationRule.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/AllocationRule.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,12 +26,12 @@ import org.openecomp.sdnc.rm.data.AllocationRequest;
public interface AllocationRule {
- AllocationRequest buildAllocationRequest(
- String resourceUnionId,
- String resourceSetId,
- String endPointPosition,
- ServiceData serviceData,
- EquipmentData equipmentData,
- boolean checkOnly,
- boolean change);
+ AllocationRequest buildAllocationRequest(
+ String resourceUnionId,
+ String resourceSetId,
+ String endPointPosition,
+ ServiceData serviceData,
+ EquipmentData equipmentData,
+ boolean checkOnly,
+ boolean change);
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointAllocationDefinition.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointAllocationDefinition.java
index 21e49c3a1..5a5623c12 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointAllocationDefinition.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointAllocationDefinition.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,34 +27,34 @@ import org.openecomp.sdnc.ra.equip.comp.EquipmentReader;
public class EndPointAllocationDefinition {
- public String serviceModel;
- public String endPointPosition;
- public EquipmentReader equipmentReader;
- public List<EquipmentCheck> equipmentCheckList;
- public List<PreferenceRule> preferenceRuleList;
- public List<AllocationRule> allocationRuleList;
+ public String serviceModel;
+ public String endPointPosition;
+ public EquipmentReader equipmentReader;
+ public List<EquipmentCheck> equipmentCheckList;
+ public List<PreferenceRule> preferenceRuleList;
+ public List<AllocationRule> allocationRuleList;
- public void setServiceModel(String serviceModel) {
- this.serviceModel = serviceModel;
- }
+ public void setServiceModel(String serviceModel) {
+ this.serviceModel = serviceModel;
+ }
- public void setEndPointPosition(String endPointPosition) {
- this.endPointPosition = endPointPosition;
- }
+ public void setEndPointPosition(String endPointPosition) {
+ this.endPointPosition = endPointPosition;
+ }
- public void setEquipmentReader(EquipmentReader equipmentReader) {
- this.equipmentReader = equipmentReader;
- }
+ public void setEquipmentReader(EquipmentReader equipmentReader) {
+ this.equipmentReader = equipmentReader;
+ }
- public void setEquipmentCheckList(List<EquipmentCheck> equipmentCheckList) {
- this.equipmentCheckList = equipmentCheckList;
- }
+ public void setEquipmentCheckList(List<EquipmentCheck> equipmentCheckList) {
+ this.equipmentCheckList = equipmentCheckList;
+ }
- public void setPreferenceRuleList(List<PreferenceRule> preferenceRuleList) {
- this.preferenceRuleList = preferenceRuleList;
- }
+ public void setPreferenceRuleList(List<PreferenceRule> preferenceRuleList) {
+ this.preferenceRuleList = preferenceRuleList;
+ }
- public void setAllocationRuleList(List<AllocationRule> allocationRuleList) {
- this.allocationRuleList = allocationRuleList;
- }
+ public void setAllocationRuleList(List<AllocationRule> allocationRuleList) {
+ this.allocationRuleList = allocationRuleList;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointAllocator.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointAllocator.java
index 645c953c0..e817d587e 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointAllocator.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointAllocator.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,10 +26,10 @@ import java.util.Map;
public interface EndPointAllocator {
- List<EndPointData> allocateEndPoints(
- ServiceData serviceData,
- Map<String, Object> equipmentConstraints,
- boolean checkOnly,
- boolean change,
- int changeNumber);
+ List<EndPointData> allocateEndPoints(
+ ServiceData serviceData,
+ Map<String, Object> equipmentConstraints,
+ boolean checkOnly,
+ boolean change,
+ int changeNumber);
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointAllocatorImpl.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointAllocatorImpl.java
index 1af81434d..3d11f8e02 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointAllocatorImpl.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointAllocatorImpl.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,171 +44,171 @@ import org.slf4j.LoggerFactory;
public class EndPointAllocatorImpl implements EndPointAllocator {
- private static final Logger log = LoggerFactory.getLogger(EndPointAllocatorImpl.class);
-
- private Map<String, List<EndPointAllocationDefinition>> endPointAllocationDefinitionMap;
-
- private ResourceManager resourceManager;
-
- @Override
- public List<EndPointData> allocateEndPoints(
- ServiceData serviceData,
- Map<String, Object> equipmentConstraints,
- boolean checkOnly,
- boolean change,
- int changeNumber) {
- List<EndPointAllocationDefinition> defList = endPointAllocationDefinitionMap.get(serviceData.serviceModel);
- if (defList == null)
- throw new NotImplementedException("Service model: " + serviceData.serviceModel + " not supported");
-
- List<EndPointData> epList = new ArrayList<>();
- for (EndPointAllocationDefinition def : defList) {
- if (serviceData.endPointPosition != null && !serviceData.endPointPosition.equals(def.endPointPosition))
- continue;
-
- log.info(
- "Starting allocation of end point: " + def.endPointPosition + ": " + serviceData.serviceInstanceId);
-
- String resourceUnionId = serviceData.serviceInstanceId + '/' + def.endPointPosition;
- String resourceSetId = resourceUnionId + '/' + changeNumber;
-
- String equipmentId = (String) equipmentConstraints.get("equipment-id");
- if (equipmentId == null) {
- EndPointData epExisting = readEndPoint(resourceUnionId, resourceSetId);
- if (epExisting != null && epExisting.equipmentId != null) {
- equipmentConstraints.put("equipment-id", epExisting.equipmentId);
-
- log.info("Trying assignment on the current equipment: " + epExisting.equipmentId);
- }
- }
-
- List<EquipmentData> equipList = def.equipmentReader.readEquipment(equipmentConstraints);
- if (equipList == null || equipList.isEmpty()) {
- log.info("Equipment not found for " + def.endPointPosition);
- break;
- }
-
- if (def.equipmentCheckList != null) {
- for (EquipmentCheck filter : def.equipmentCheckList) {
- List<EquipmentData> newEquipList = new ArrayList<>();
- for (EquipmentData equipData : equipList)
- if (filter.checkEquipment(def.endPointPosition, serviceData, equipData, equipmentConstraints))
- newEquipList.add(equipData);
- equipList = newEquipList;
- }
- if (equipList.isEmpty()) {
- log.info("No equipment meets the requiremets for the service for: " + def.endPointPosition);
- break;
- }
- }
-
- if (equipList.size() > 1 && def.preferenceRuleList != null && !def.preferenceRuleList.isEmpty()) {
-
- List<PrefEquipment> prefEquipList = new ArrayList<>();
- for (EquipmentData equipData : equipList) {
- PrefEquipment prefEquip = new PrefEquipment();
- prefEquip.equipData = equipData;
- prefEquip.prefNumbers = new long[def.preferenceRuleList.size()];
- prefEquipList.add(prefEquip);
-
- int i = 0;
- for (PreferenceRule prefRule : def.preferenceRuleList)
- prefEquip.prefNumbers[i++] =
- prefRule.assignOrderNumber(def.endPointPosition, serviceData, equipData);
- }
-
- Collections.sort(prefEquipList);
-
- equipList = new ArrayList<>();
- for (PrefEquipment prefEquip : prefEquipList)
- equipList.add(prefEquip.equipData);
- }
-
- for (EquipmentData equipData : equipList) {
- boolean allgood = true;
- if (def.allocationRuleList != null)
- for (AllocationRule allocationRule : def.allocationRuleList) {
- AllocationRequest ar = allocationRule.buildAllocationRequest(resourceUnionId, resourceSetId,
- def.endPointPosition, serviceData, equipData, checkOnly, change);
- if (ar != null) {
- AllocationOutcome ao = resourceManager.allocateResources(ar);
- if (ao.status != AllocationStatus.Success) {
- allgood = false;
- break;
- }
- }
- }
- if (allgood) {
- EndPointData ep = readEndPoint(resourceUnionId, resourceSetId);
- epList.add(ep);
- break;
- }
- }
- }
-
- return epList;
- }
-
- private EndPointData readEndPoint(String resourceUnionId, String resourceSetId) {
- EndPointData ep = new EndPointData();
- ep.resourceUnionId = resourceUnionId;
- ep.resourceSetId = resourceSetId;
-
- int i1 = resourceUnionId.indexOf('/');
- if (i1 > 0)
- ep.endPointPosition = resourceUnionId.substring(i1 + 1);
-
- ep.data = new HashMap<>();
-
- List<Resource> rlist = resourceManager.getResourceUnion(resourceUnionId);
- for (Resource r : rlist) {
- if (r instanceof RangeResource) {
- RangeResource rr = (RangeResource) r;
- for (AllocationItem ai : r.allocationItems)
- if (ai.resourceUnionId.equals(resourceUnionId)) {
- RangeAllocationItem rai = (RangeAllocationItem) ai;
- ep.data.put(ep.endPointPosition + '.' + rr.resourceKey.resourceName, rai.used.first());
- }
- }
- if (r instanceof LimitResource) {
- LimitResource rr = (LimitResource) r;
- for (AllocationItem ai : r.allocationItems)
- if (ai.resourceUnionId.equals(resourceUnionId)) {
- LimitAllocationItem rai = (LimitAllocationItem) ai;
- ep.data.put(ep.endPointPosition + '.' + rr.resourceKey.resourceName + ".allocated", rai.used);
- ep.data.put(ep.endPointPosition + '.' + rr.resourceKey.resourceName + ".used", rr.used);
- ep.data.put(ep.endPointPosition + '.' + rr.resourceKey.resourceName + ".assetId",
- r.resourceKey.assetId);
- }
- }
- }
-
- return ep;
- }
-
- private static class PrefEquipment implements Comparable<PrefEquipment> {
-
- public long[] prefNumbers;
- public EquipmentData equipData;
-
- @Override
- public int compareTo(PrefEquipment o) {
- for (int i = 0; i < prefNumbers.length; i++) {
- if (prefNumbers[i] < o.prefNumbers[i])
- return -1;
- if (prefNumbers[i] > o.prefNumbers[i])
- return 1;
- }
- return 0;
- }
- }
-
- public void setEndPointAllocationDefinitionMap(
- Map<String, List<EndPointAllocationDefinition>> endPointAllocationDefinitionMap) {
- this.endPointAllocationDefinitionMap = endPointAllocationDefinitionMap;
- }
-
- public void setResourceManager(ResourceManager resourceManager) {
- this.resourceManager = resourceManager;
- }
+ private static final Logger log = LoggerFactory.getLogger(EndPointAllocatorImpl.class);
+
+ private Map<String, List<EndPointAllocationDefinition>> endPointAllocationDefinitionMap;
+
+ private ResourceManager resourceManager;
+
+ @Override
+ public List<EndPointData> allocateEndPoints(
+ ServiceData serviceData,
+ Map<String, Object> equipmentConstraints,
+ boolean checkOnly,
+ boolean change,
+ int changeNumber) {
+ List<EndPointAllocationDefinition> defList = endPointAllocationDefinitionMap.get(serviceData.serviceModel);
+ if (defList == null)
+ throw new NotImplementedException("Service model: " + serviceData.serviceModel + " not supported");
+
+ List<EndPointData> epList = new ArrayList<>();
+ for (EndPointAllocationDefinition def : defList) {
+ if (serviceData.endPointPosition != null && !serviceData.endPointPosition.equals(def.endPointPosition))
+ continue;
+
+ log.info(
+ "Starting allocation of end point: " + def.endPointPosition + ": " + serviceData.serviceInstanceId);
+
+ String resourceUnionId = serviceData.serviceInstanceId + '/' + def.endPointPosition;
+ String resourceSetId = resourceUnionId + '/' + changeNumber;
+
+ String equipmentId = (String) equipmentConstraints.get("equipment-id");
+ if (equipmentId == null) {
+ EndPointData epExisting = readEndPoint(resourceUnionId, resourceSetId);
+ if (epExisting != null && epExisting.equipmentId != null) {
+ equipmentConstraints.put("equipment-id", epExisting.equipmentId);
+
+ log.info("Trying assignment on the current equipment: " + epExisting.equipmentId);
+ }
+ }
+
+ List<EquipmentData> equipList = def.equipmentReader.readEquipment(equipmentConstraints);
+ if (equipList == null || equipList.isEmpty()) {
+ log.info("Equipment not found for " + def.endPointPosition);
+ break;
+ }
+
+ if (def.equipmentCheckList != null) {
+ for (EquipmentCheck filter : def.equipmentCheckList) {
+ List<EquipmentData> newEquipList = new ArrayList<>();
+ for (EquipmentData equipData : equipList)
+ if (filter.checkEquipment(def.endPointPosition, serviceData, equipData, equipmentConstraints))
+ newEquipList.add(equipData);
+ equipList = newEquipList;
+ }
+ if (equipList.isEmpty()) {
+ log.info("No equipment meets the requiremets for the service for: " + def.endPointPosition);
+ break;
+ }
+ }
+
+ if (equipList.size() > 1 && def.preferenceRuleList != null && !def.preferenceRuleList.isEmpty()) {
+
+ List<PrefEquipment> prefEquipList = new ArrayList<>();
+ for (EquipmentData equipData : equipList) {
+ PrefEquipment prefEquip = new PrefEquipment();
+ prefEquip.equipData = equipData;
+ prefEquip.prefNumbers = new long[def.preferenceRuleList.size()];
+ prefEquipList.add(prefEquip);
+
+ int i = 0;
+ for (PreferenceRule prefRule : def.preferenceRuleList)
+ prefEquip.prefNumbers[i++] =
+ prefRule.assignOrderNumber(def.endPointPosition, serviceData, equipData);
+ }
+
+ Collections.sort(prefEquipList);
+
+ equipList = new ArrayList<>();
+ for (PrefEquipment prefEquip : prefEquipList)
+ equipList.add(prefEquip.equipData);
+ }
+
+ for (EquipmentData equipData : equipList) {
+ boolean allgood = true;
+ if (def.allocationRuleList != null)
+ for (AllocationRule allocationRule : def.allocationRuleList) {
+ AllocationRequest ar = allocationRule.buildAllocationRequest(resourceUnionId, resourceSetId,
+ def.endPointPosition, serviceData, equipData, checkOnly, change);
+ if (ar != null) {
+ AllocationOutcome ao = resourceManager.allocateResources(ar);
+ if (ao.status != AllocationStatus.Success) {
+ allgood = false;
+ break;
+ }
+ }
+ }
+ if (allgood) {
+ EndPointData ep = readEndPoint(resourceUnionId, resourceSetId);
+ epList.add(ep);
+ break;
+ }
+ }
+ }
+
+ return epList;
+ }
+
+ private EndPointData readEndPoint(String resourceUnionId, String resourceSetId) {
+ EndPointData ep = new EndPointData();
+ ep.resourceUnionId = resourceUnionId;
+ ep.resourceSetId = resourceSetId;
+
+ int i1 = resourceUnionId.indexOf('/');
+ if (i1 > 0)
+ ep.endPointPosition = resourceUnionId.substring(i1 + 1);
+
+ ep.data = new HashMap<>();
+
+ List<Resource> rlist = resourceManager.getResourceUnion(resourceUnionId);
+ for (Resource r : rlist) {
+ if (r instanceof RangeResource) {
+ RangeResource rr = (RangeResource) r;
+ for (AllocationItem ai : r.allocationItems)
+ if (ai.resourceUnionId.equals(resourceUnionId)) {
+ RangeAllocationItem rai = (RangeAllocationItem) ai;
+ ep.data.put(ep.endPointPosition + '.' + rr.resourceKey.resourceName, rai.used.first());
+ }
+ }
+ if (r instanceof LimitResource) {
+ LimitResource rr = (LimitResource) r;
+ for (AllocationItem ai : r.allocationItems)
+ if (ai.resourceUnionId.equals(resourceUnionId)) {
+ LimitAllocationItem rai = (LimitAllocationItem) ai;
+ ep.data.put(ep.endPointPosition + '.' + rr.resourceKey.resourceName + ".allocated", rai.used);
+ ep.data.put(ep.endPointPosition + '.' + rr.resourceKey.resourceName + ".used", rr.used);
+ ep.data.put(ep.endPointPosition + '.' + rr.resourceKey.resourceName + ".assetId",
+ r.resourceKey.assetId);
+ }
+ }
+ }
+
+ return ep;
+ }
+
+ private static class PrefEquipment implements Comparable<PrefEquipment> {
+
+ public long[] prefNumbers;
+ public EquipmentData equipData;
+
+ @Override
+ public int compareTo(PrefEquipment o) {
+ for (int i = 0; i < prefNumbers.length; i++) {
+ if (prefNumbers[i] < o.prefNumbers[i])
+ return -1;
+ if (prefNumbers[i] > o.prefNumbers[i])
+ return 1;
+ }
+ return 0;
+ }
+ }
+
+ public void setEndPointAllocationDefinitionMap(
+ Map<String, List<EndPointAllocationDefinition>> endPointAllocationDefinitionMap) {
+ this.endPointAllocationDefinitionMap = endPointAllocationDefinitionMap;
+ }
+
+ public void setResourceManager(ResourceManager resourceManager) {
+ this.resourceManager = resourceManager;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointData.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointData.java
index e425e373f..eb030f3e6 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointData.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EndPointData.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,9 +25,9 @@ import java.util.Map;
public class EndPointData {
- public String resourceSetId;
- public String resourceUnionId;
- public String endPointPosition;
- public String equipmentId;
- public Map<String, Object> data;
+ public String resourceSetId;
+ public String resourceUnionId;
+ public String endPointPosition;
+ public String equipmentId;
+ public Map<String, Object> data;
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EquipmentCheck.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EquipmentCheck.java
index fcca4f7c2..ab65b31e4 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EquipmentCheck.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/EquipmentCheck.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,9 +27,9 @@ import org.openecomp.sdnc.ra.equip.data.EquipmentData;
public interface EquipmentCheck {
- boolean checkEquipment(
- String endPointPosition,
- ServiceData serviceData,
- EquipmentData equipData,
- Map<String, Object> equipmentConstraints);
+ boolean checkEquipment(
+ String endPointPosition,
+ ServiceData serviceData,
+ EquipmentData equipData,
+ Map<String, Object> equipmentConstraints);
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/PreferenceRule.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/PreferenceRule.java
index acaf10d9e..d1287633f 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/PreferenceRule.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/PreferenceRule.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,6 +25,6 @@ import org.openecomp.sdnc.ra.equip.data.EquipmentData;
public interface PreferenceRule {
- // Smaller order number is preferred
- int assignOrderNumber(String endPointPosition, ServiceData serviceData, EquipmentData equipData);
+ // Smaller order number is preferred
+ int assignOrderNumber(String endPointPosition, ServiceData serviceData, EquipmentData equipData);
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/ServiceData.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/ServiceData.java
index 0d29e54f7..685f0988d 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/ServiceData.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/comp/ServiceData.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,12 +25,12 @@ import java.util.Map;
public class ServiceData {
- public String serviceModel;
- public String serviceInstanceId;
- public String resourceSetId;
- public String resourceUnionId;
- public String resourceShareGroup;
- public String endPointPosition;
- public String resourceName;
- public Map<String, Object> data;
+ public String serviceModel;
+ public String serviceInstanceId;
+ public String resourceSetId;
+ public String resourceUnionId;
+ public String resourceShareGroup;
+ public String endPointPosition;
+ public String resourceName;
+ public Map<String, Object> data;
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/comp/EquipmentReader.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/comp/EquipmentReader.java
index a380594ba..8e3247d11 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/comp/EquipmentReader.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/comp/EquipmentReader.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,5 +28,5 @@ import org.openecomp.sdnc.ra.equip.data.EquipmentData;
public interface EquipmentReader {
- List<EquipmentData> readEquipment(Map<String, Object> equipmentConstraints);
+ List<EquipmentData> readEquipment(Map<String, Object> equipmentConstraints);
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/ServerDao.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/ServerDao.java
index 44873873b..b90a0856f 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/ServerDao.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/ServerDao.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,5 +26,5 @@ import java.util.Map;
public interface ServerDao {
- List<Map<String, Object>> getServerData(String aicSiteId);
+ List<Map<String, Object>> getServerData(String aicSiteId);
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/ServerDaoImpl.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/ServerDaoImpl.java
index e1bc2a5a8..b0c62e5c5 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/ServerDaoImpl.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/ServerDaoImpl.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,33 +32,33 @@ import org.springframework.jdbc.core.JdbcTemplate;
public class ServerDaoImpl implements ServerDao {
- private static final Logger log = LoggerFactory.getLogger(ServerDaoImpl.class);
+ private static final Logger log = LoggerFactory.getLogger(ServerDaoImpl.class);
- private static final String GET_SERVER_COUNT_SQL = "SELECT count(*) FROM PSERVER WHERE aic_site_id = ?";
+ private static final String GET_SERVER_COUNT_SQL = "SELECT count(*) FROM PSERVER WHERE aic_site_id = ?";
- private JdbcTemplate jdbcTemplate;
+ private JdbcTemplate jdbcTemplate;
- @Override
- public List<Map<String, Object>> getServerData(String aicSiteId) {
- List<Map<String, Object>> ll = new ArrayList<Map<String, Object>>();
- Map<String, Object> sd = new HashMap<String, Object>();
- sd.put("aic-site-id", aicSiteId);
- sd.put("server-id", aicSiteId + "/Server1");
- sd.put("server-model", "Unknown");
- sd.put("server-count", getServerCount(aicSiteId));
- ll.add(sd);
- return ll;
- }
+ @Override
+ public List<Map<String, Object>> getServerData(String aicSiteId) {
+ List<Map<String, Object>> ll = new ArrayList<Map<String, Object>>();
+ Map<String, Object> sd = new HashMap<String, Object>();
+ sd.put("aic-site-id", aicSiteId);
+ sd.put("server-id", aicSiteId + "/Server1");
+ sd.put("server-model", "Unknown");
+ sd.put("server-count", getServerCount(aicSiteId));
+ ll.add(sd);
+ return ll;
+ }
- private int getServerCount(String aicSiteId) {
- int n = jdbcTemplate.queryForInt(GET_SERVER_COUNT_SQL, aicSiteId);
+ private int getServerCount(String aicSiteId) {
+ int n = jdbcTemplate.queryForInt(GET_SERVER_COUNT_SQL, aicSiteId);
- log.info("Number of servers in " + aicSiteId + ": " + n);
+ log.info("Number of servers in " + aicSiteId + ": " + n);
- return n;
- }
+ return n;
+ }
- public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
- this.jdbcTemplate = jdbcTemplate;
- }
+ public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
+ this.jdbcTemplate = jdbcTemplate;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/VpePortDao.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/VpePortDao.java
index 4a0f6b8c0..052bf9edd 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/VpePortDao.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/VpePortDao.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,7 +26,7 @@ import java.util.Map;
public interface VpePortDao {
- List<Map<String, Object>> getVpePortData(String aicSiteId);
+ List<Map<String, Object>> getVpePortData(String aicSiteId);
- List<Map<String, Object>> getVpePortData(String aicSiteId, String vpeName);
+ List<Map<String, Object>> getVpePortData(String aicSiteId, String vpeName);
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/VpePortDaoImpl.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/VpePortDaoImpl.java
index d25fe9c4c..d81e391cb 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/VpePortDaoImpl.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/VpePortDaoImpl.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,48 +34,48 @@ import org.springframework.jdbc.core.RowMapper;
public class VpePortDaoImpl implements VpePortDao {
- @SuppressWarnings("unused")
- private static final Logger log = LoggerFactory.getLogger(VpePortDaoImpl.class);
+ @SuppressWarnings("unused")
+ private static final Logger log = LoggerFactory.getLogger(VpePortDaoImpl.class);
- private static final String GET_SQL = "SELECT * FROM VPE_POOL WHERE aic_site_id = ?";
- private static final String GET2_SQL = "SELECT * FROM VPE_POOL WHERE vpe_name = ?";
- private static final String GET3_SQL =
- "SELECT * FROM VPE_POOL WHERE substring(aic_site_id, 1, 8) = substring(?, 1, 8)";
+ private static final String GET_SQL = "SELECT * FROM VPE_POOL WHERE aic_site_id = ?";
+ private static final String GET2_SQL = "SELECT * FROM VPE_POOL WHERE vpe_name = ?";
+ private static final String GET3_SQL =
+ "SELECT * FROM VPE_POOL WHERE substring(aic_site_id, 1, 8) = substring(?, 1, 8)";
- private JdbcTemplate jdbcTemplate;
+ private JdbcTemplate jdbcTemplate;
- @Override
- public List<Map<String, Object>> getVpePortData(String aicSiteId) {
- return jdbcTemplate.query(GET_SQL, new Object[] { aicSiteId }, new VpePortRowMapper());
- }
+ @Override
+ public List<Map<String, Object>> getVpePortData(String aicSiteId) {
+ return jdbcTemplate.query(GET_SQL, new Object[] { aicSiteId }, new VpePortRowMapper());
+ }
- @Override
- public List<Map<String, Object>> getVpePortData(String aicSiteId, String vpeName) {
- String sql = vpeName != null ? GET2_SQL : GET3_SQL;
- Object[] param = new Object[] { vpeName != null ? vpeName : aicSiteId };
+ @Override
+ public List<Map<String, Object>> getVpePortData(String aicSiteId, String vpeName) {
+ String sql = vpeName != null ? GET2_SQL : GET3_SQL;
+ Object[] param = new Object[] { vpeName != null ? vpeName : aicSiteId };
- return jdbcTemplate.query(sql, param, new VpePortRowMapper());
- }
+ return jdbcTemplate.query(sql, param, new VpePortRowMapper());
+ }
- private static class VpePortRowMapper implements RowMapper<Map<String, Object>> {
+ private static class VpePortRowMapper implements RowMapper<Map<String, Object>> {
- @Override
- public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
- Map<String, Object> mm = new HashMap<String, Object>();
- mm.put("vpe-id", rs.getString("vpe_name"));
- mm.put("aic-site-id", rs.getString("aic_site_id"));
- mm.put("availability-zone", rs.getString("availability_zone"));
- mm.put("image-file-name", rs.getString("image_filename"));
- mm.put("vendor", rs.getString("vendor"));
- mm.put("provisioning-status", rs.getString("provisioning_status"));
- mm.put("physical-interface-name", rs.getString("physical_intf_name"));
- mm.put("physical-interface-speed", rs.getLong("physical_intf_speed"));
- mm.put("physical-interface-speed-unit", rs.getString("physical_intf_units"));
- return mm;
- }
- }
+ @Override
+ public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
+ Map<String, Object> mm = new HashMap<String, Object>();
+ mm.put("vpe-id", rs.getString("vpe_name"));
+ mm.put("aic-site-id", rs.getString("aic_site_id"));
+ mm.put("availability-zone", rs.getString("availability_zone"));
+ mm.put("image-file-name", rs.getString("image_filename"));
+ mm.put("vendor", rs.getString("vendor"));
+ mm.put("provisioning-status", rs.getString("provisioning_status"));
+ mm.put("physical-interface-name", rs.getString("physical_intf_name"));
+ mm.put("physical-interface-speed", rs.getLong("physical_intf_speed"));
+ mm.put("physical-interface-speed-unit", rs.getString("physical_intf_units"));
+ return mm;
+ }
+ }
- public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
- this.jdbcTemplate = jdbcTemplate;
- }
+ public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
+ this.jdbcTemplate = jdbcTemplate;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/VplspePortDao.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/VplspePortDao.java
index 879a233d7..dc32280f7 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/VplspePortDao.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/VplspePortDao.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,5 +26,5 @@ import java.util.Map;
public interface VplspePortDao {
- List<Map<String, Object>> getVplspePortData(String aicSiteId);
+ List<Map<String, Object>> getVplspePortData(String aicSiteId);
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/VplspePortDaoImpl.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/VplspePortDaoImpl.java
index bad646414..1f3aa8ef3 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/VplspePortDaoImpl.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/dao/VplspePortDaoImpl.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,37 +34,37 @@ import org.springframework.jdbc.core.RowMapper;
public class VplspePortDaoImpl implements VplspePortDao {
- @SuppressWarnings("unused")
- private static final Logger log = LoggerFactory.getLogger(VplspePortDaoImpl.class);
+ @SuppressWarnings("unused")
+ private static final Logger log = LoggerFactory.getLogger(VplspePortDaoImpl.class);
- private static final String GET_SQL = "SELECT * FROM VPLSPE_POOL WHERE aic_site_id = ?";
+ private static final String GET_SQL = "SELECT * FROM VPLSPE_POOL WHERE aic_site_id = ?";
- private JdbcTemplate jdbcTemplate;
+ private JdbcTemplate jdbcTemplate;
- @Override
- public List<Map<String, Object>> getVplspePortData(String aicSiteId) {
- List<Map<String, Object>> ll =
- jdbcTemplate.query(GET_SQL, new Object[] { aicSiteId }, new RowMapper<Map<String, Object>>() {
+ @Override
+ public List<Map<String, Object>> getVplspePortData(String aicSiteId) {
+ List<Map<String, Object>> ll =
+ jdbcTemplate.query(GET_SQL, new Object[] { aicSiteId }, new RowMapper<Map<String, Object>>() {
- @Override
- public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
- Map<String, Object> mm = new HashMap<String, Object>();
- mm.put("vplspe-id", rs.getString("vplspe_name"));
- mm.put("aic-site-id", rs.getString("aic_site_id"));
- mm.put("availability-zone", rs.getString("availability_zone"));
- mm.put("image-file-name", rs.getString("image_filename"));
- mm.put("vendor", rs.getString("vendor"));
- mm.put("provisioning-status", rs.getString("provisioning_status"));
- mm.put("physical-interface-name", rs.getString("physical_intf_name"));
- mm.put("physical-interface-speed", rs.getLong("physical_intf_speed"));
- mm.put("physical-interface-speed-unit", rs.getString("physical_intf_units"));
- return mm;
- }
- });
- return ll;
- }
+ @Override
+ public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
+ Map<String, Object> mm = new HashMap<String, Object>();
+ mm.put("vplspe-id", rs.getString("vplspe_name"));
+ mm.put("aic-site-id", rs.getString("aic_site_id"));
+ mm.put("availability-zone", rs.getString("availability_zone"));
+ mm.put("image-file-name", rs.getString("image_filename"));
+ mm.put("vendor", rs.getString("vendor"));
+ mm.put("provisioning-status", rs.getString("provisioning_status"));
+ mm.put("physical-interface-name", rs.getString("physical_intf_name"));
+ mm.put("physical-interface-speed", rs.getLong("physical_intf_speed"));
+ mm.put("physical-interface-speed-unit", rs.getString("physical_intf_units"));
+ return mm;
+ }
+ });
+ return ll;
+ }
- public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
- this.jdbcTemplate = jdbcTemplate;
- }
+ public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
+ this.jdbcTemplate = jdbcTemplate;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/data/EquipmentData.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/data/EquipmentData.java
index d485224b0..ae2a4e7ce 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/data/EquipmentData.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/data/EquipmentData.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,7 +25,7 @@ import java.util.Map;
public class EquipmentData {
- public String equipmentId;
- public EquipmentLevel equipmentLevel;
- public Map<String, Object> data;
+ public String equipmentId;
+ public EquipmentLevel equipmentLevel;
+ public Map<String, Object> data;
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/data/EquipmentLevel.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/data/EquipmentLevel.java
index 44ae593a0..fbf13fb5d 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/data/EquipmentLevel.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/equip/data/EquipmentLevel.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,5 +22,5 @@
package org.openecomp.sdnc.ra.equip.data;
public enum EquipmentLevel {
- Port, Device, Server, Site
+ Port, Device, Server, Site
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/pref/AffinityLinkPref.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/pref/AffinityLinkPref.java
index 09af2081d..cb3f78ec3 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/pref/AffinityLinkPref.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/pref/AffinityLinkPref.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,51 +35,51 @@ import org.slf4j.LoggerFactory;
public class AffinityLinkPref implements PreferenceRule {
- private static final Logger log = LoggerFactory.getLogger(AffinityLinkPref.class);
+ private static final Logger log = LoggerFactory.getLogger(AffinityLinkPref.class);
- private ResourceManager resourceManager;
- private List<String> affinityLinkIdList;
+ private ResourceManager resourceManager;
+ private List<String> affinityLinkIdList;
- public AffinityLinkPref() {
- // Set default values for affinity link ids (can be overridden by the spring config)
- affinityLinkIdList = new ArrayList<>();
- affinityLinkIdList.add("1");
- affinityLinkIdList.add("2");
- }
+ public AffinityLinkPref() {
+ // Set default values for affinity link ids (can be overridden by the spring config)
+ affinityLinkIdList = new ArrayList<>();
+ affinityLinkIdList.add("1");
+ affinityLinkIdList.add("2");
+ }
- @Override
- public int assignOrderNumber(String endPointPosition, ServiceData serviceData, EquipmentData equipData) {
+ @Override
+ public int assignOrderNumber(String endPointPosition, ServiceData serviceData, EquipmentData equipData) {
- // This class does not really assign order number, but instead sets the affinity link with the lowest
- // assigned bandwidth in the equipment data
+ // This class does not really assign order number, but instead sets the affinity link with the lowest
+ // assigned bandwidth in the equipment data
- String preferedAffinityLinkId = "1";
- long lowestAssignedBw = Long.MAX_VALUE;
- for (String affinityLinkId : affinityLinkIdList) {
- String assetId = equipData.equipmentId + "-" + affinityLinkId;
- Resource r = resourceManager.getResource("Bandwidth", assetId);
- if (r != null) {
- LimitResource ll = (LimitResource) r;
- if (ll.used < lowestAssignedBw) {
- lowestAssignedBw = ll.used;
- preferedAffinityLinkId = affinityLinkId;
- }
- log.info("Assigned bandwidth on affinity link: " + assetId + ": " + ll.used);
- }
- }
+ String preferedAffinityLinkId = "1";
+ long lowestAssignedBw = Long.MAX_VALUE;
+ for (String affinityLinkId : affinityLinkIdList) {
+ String assetId = equipData.equipmentId + "-" + affinityLinkId;
+ Resource r = resourceManager.getResource("Bandwidth", assetId);
+ if (r != null) {
+ LimitResource ll = (LimitResource) r;
+ if (ll.used < lowestAssignedBw) {
+ lowestAssignedBw = ll.used;
+ preferedAffinityLinkId = affinityLinkId;
+ }
+ log.info("Assigned bandwidth on affinity link: " + assetId + ": " + ll.used);
+ }
+ }
- equipData.data.put("affinity-link", preferedAffinityLinkId);
+ equipData.data.put("affinity-link", preferedAffinityLinkId);
- log.info("Prefered affinity link for " + equipData.equipmentId + ": " + preferedAffinityLinkId);
+ log.info("Prefered affinity link for " + equipData.equipmentId + ": " + preferedAffinityLinkId);
- return 0;
- }
+ return 0;
+ }
- public void setResourceManager(ResourceManager resourceManager) {
- this.resourceManager = resourceManager;
- }
+ public void setResourceManager(ResourceManager resourceManager) {
+ this.resourceManager = resourceManager;
+ }
- public void setAffinityLinkIdList(List<String> affinityLinkIdList) {
- this.affinityLinkIdList = affinityLinkIdList;
- }
+ public void setAffinityLinkIdList(List<String> affinityLinkIdList) {
+ this.affinityLinkIdList = affinityLinkIdList;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/pref/EvcExistingVrfPref.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/pref/EvcExistingVrfPref.java
index abef0a24e..93c041ebf 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/pref/EvcExistingVrfPref.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/pref/EvcExistingVrfPref.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,29 +32,29 @@ import org.slf4j.LoggerFactory;
public class EvcExistingVrfPref implements PreferenceRule {
- private static final Logger log = LoggerFactory.getLogger(EvcExistingVrfPref.class);
+ private static final Logger log = LoggerFactory.getLogger(EvcExistingVrfPref.class);
- private ResourceManager resourceManager;
+ private ResourceManager resourceManager;
- @Override
- public int assignOrderNumber(String endPointPosition, ServiceData serviceData, EquipmentData equipData) {
- String vrfName = (String) serviceData.data.get("vrf-name");
- if (vrfName == null)
- return 0;
+ @Override
+ public int assignOrderNumber(String endPointPosition, ServiceData serviceData, EquipmentData equipData) {
+ String vrfName = (String) serviceData.data.get("vrf-name");
+ if (vrfName == null)
+ return 0;
- Resource r = resourceManager.getResource("VRF", equipData.equipmentId);
- if (r != null && r.allocationItems != null)
- for (AllocationItem ai : r.allocationItems)
- if (ai.resourceShareGroupList.contains(vrfName)) {
- log.info("VRF for VPN: " + vrfName + " found on VPE: " + equipData.equipmentId);
- return 1;
- }
+ Resource r = resourceManager.getResource("VRF", equipData.equipmentId);
+ if (r != null && r.allocationItems != null)
+ for (AllocationItem ai : r.allocationItems)
+ if (ai.resourceShareGroupList.contains(vrfName)) {
+ log.info("VRF for VPN: " + vrfName + " found on VPE: " + equipData.equipmentId);
+ return 1;
+ }
- log.info("VRF for VPN: " + vrfName + " NOT found on VPE: " + equipData.equipmentId);
- return 2;
- }
+ log.info("VRF for VPN: " + vrfName + " NOT found on VPE: " + equipData.equipmentId);
+ return 2;
+ }
- public void setResourceManager(ResourceManager resourceManager) {
- this.resourceManager = resourceManager;
- }
+ public void setResourceManager(ResourceManager resourceManager) {
+ this.resourceManager = resourceManager;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/reader/AicSiteReader.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/reader/AicSiteReader.java
index 4040b0b44..1bf2ead02 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/reader/AicSiteReader.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/reader/AicSiteReader.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,18 +32,18 @@ import org.openecomp.sdnc.ra.equip.data.EquipmentLevel;
public class AicSiteReader implements EquipmentReader {
- @Override
- public List<EquipmentData> readEquipment(Map<String, Object> equipmentConstraints) {
- String aicSiteId = (String) equipmentConstraints.get("aic-site-id");
+ @Override
+ public List<EquipmentData> readEquipment(Map<String, Object> equipmentConstraints) {
+ String aicSiteId = (String) equipmentConstraints.get("aic-site-id");
- EquipmentData equipData = new EquipmentData();
- equipData.equipmentLevel = EquipmentLevel.Site;
- equipData.equipmentId = aicSiteId;
- equipData.data = new HashMap<String, Object>();
+ EquipmentData equipData = new EquipmentData();
+ equipData.equipmentLevel = EquipmentLevel.Site;
+ equipData.equipmentId = aicSiteId;
+ equipData.data = new HashMap<String, Object>();
- List<EquipmentData> equipList = new ArrayList<>();
- equipList.add(equipData);
+ List<EquipmentData> equipList = new ArrayList<>();
+ equipList.add(equipData);
- return equipList;
- }
+ return equipList;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/reader/UplinkCircuitReader.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/reader/UplinkCircuitReader.java
index 0adf6d122..ad65c379a 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/reader/UplinkCircuitReader.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/reader/UplinkCircuitReader.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,24 +31,24 @@ import org.openecomp.sdnc.ra.equip.data.EquipmentLevel;
public class UplinkCircuitReader implements EquipmentReader {
- @SuppressWarnings("unchecked")
- @Override
- public List<EquipmentData> readEquipment(Map<String, Object> equipmentConstraints) {
- List<EquipmentData> equipList = new ArrayList<>();
-
- List<Map<String, Object>> uplinkCircuitList =
- (List<Map<String, Object>>) equipmentConstraints.get("uplink-circuit-list");
- if (uplinkCircuitList == null || uplinkCircuitList.isEmpty())
- return equipList;
-
- for (Map<String, Object> uplinkCircuit : uplinkCircuitList) {
- EquipmentData equipData = new EquipmentData();
- equipData.equipmentLevel = EquipmentLevel.Device;
- equipData.equipmentId = (String) uplinkCircuit.get("uplink-circuit-id");
- equipData.data = uplinkCircuit;
- equipList.add(equipData);
- }
-
- return equipList;
- }
+ @SuppressWarnings("unchecked")
+ @Override
+ public List<EquipmentData> readEquipment(Map<String, Object> equipmentConstraints) {
+ List<EquipmentData> equipList = new ArrayList<>();
+
+ List<Map<String, Object>> uplinkCircuitList =
+ (List<Map<String, Object>>) equipmentConstraints.get("uplink-circuit-list");
+ if (uplinkCircuitList == null || uplinkCircuitList.isEmpty())
+ return equipList;
+
+ for (Map<String, Object> uplinkCircuit : uplinkCircuitList) {
+ EquipmentData equipData = new EquipmentData();
+ equipData.equipmentLevel = EquipmentLevel.Device;
+ equipData.equipmentId = (String) uplinkCircuit.get("uplink-circuit-id");
+ equipData.data = uplinkCircuit;
+ equipList.add(equipData);
+ }
+
+ return equipList;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/reader/VnfReader.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/reader/VnfReader.java
index 7039370a0..ac53afe52 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/reader/VnfReader.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/reader/VnfReader.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,18 +32,18 @@ import org.openecomp.sdnc.ra.equip.data.EquipmentLevel;
public class VnfReader implements EquipmentReader {
- @Override
- public List<EquipmentData> readEquipment(Map<String, Object> equipmentConstraints) {
- String vnfName = (String) equipmentConstraints.get("vnf-name");
+ @Override
+ public List<EquipmentData> readEquipment(Map<String, Object> equipmentConstraints) {
+ String vnfName = (String) equipmentConstraints.get("vnf-name");
- EquipmentData equipData = new EquipmentData();
- equipData.equipmentLevel = EquipmentLevel.Device;
- equipData.equipmentId = vnfName;
- equipData.data = new HashMap<String, Object>();
+ EquipmentData equipData = new EquipmentData();
+ equipData.equipmentLevel = EquipmentLevel.Device;
+ equipData.equipmentId = vnfName;
+ equipData.data = new HashMap<String, Object>();
- List<EquipmentData> equipList = new ArrayList<>();
- equipList.add(equipData);
+ List<EquipmentData> equipList = new ArrayList<>();
+ equipList.add(equipData);
- return equipList;
- }
+ return equipList;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/reader/VpePortReader.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/reader/VpePortReader.java
index 360f7806f..ba497c015 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/reader/VpePortReader.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/reader/VpePortReader.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,39 +32,39 @@ import org.openecomp.sdnc.ra.equip.data.EquipmentLevel;
public class VpePortReader implements EquipmentReader {
- private VpePortDao vpePortDao;
+ private VpePortDao vpePortDao;
- @Override
- public List<EquipmentData> readEquipment(Map<String, Object> equipmentConstraints) {
- String clli = (String) equipmentConstraints.get("clli");
- String vpeName = (String) equipmentConstraints.get("vpe-name");
- if (vpeName == null) {
- String equipmentId = (String) equipmentConstraints.get("equipment-id");
- if (equipmentId != null) {
- int i1 = equipmentId.indexOf('/');
- if (i1 > 0)
- equipmentId = equipmentId.substring(0, i1);
- vpeName = equipmentId;
- }
- }
+ @Override
+ public List<EquipmentData> readEquipment(Map<String, Object> equipmentConstraints) {
+ String clli = (String) equipmentConstraints.get("clli");
+ String vpeName = (String) equipmentConstraints.get("vpe-name");
+ if (vpeName == null) {
+ String equipmentId = (String) equipmentConstraints.get("equipment-id");
+ if (equipmentId != null) {
+ int i1 = equipmentId.indexOf('/');
+ if (i1 > 0)
+ equipmentId = equipmentId.substring(0, i1);
+ vpeName = equipmentId;
+ }
+ }
- List<Map<String, Object>> vpeDataList = vpePortDao.getVpePortData(clli, vpeName);
+ List<Map<String, Object>> vpeDataList = vpePortDao.getVpePortData(clli, vpeName);
- List<EquipmentData> equipList = new ArrayList<>();
- for (Map<String, Object> vpeData : vpeDataList) {
- EquipmentData equipData = new EquipmentData();
- equipData.equipmentLevel = EquipmentLevel.Port;
- equipData.equipmentId =
- (String) vpeData.get("vpe-id") + '/' + (String) vpeData.get("physical-interface-name");
- equipData.data = vpeData;
+ List<EquipmentData> equipList = new ArrayList<>();
+ for (Map<String, Object> vpeData : vpeDataList) {
+ EquipmentData equipData = new EquipmentData();
+ equipData.equipmentLevel = EquipmentLevel.Port;
+ equipData.equipmentId =
+ (String) vpeData.get("vpe-id") + '/' + (String) vpeData.get("physical-interface-name");
+ equipData.data = vpeData;
- equipList.add(equipData);
- }
+ equipList.add(equipData);
+ }
- return equipList;
- }
+ return equipList;
+ }
- public void setVpePortDao(VpePortDao vpePortDao) {
- this.vpePortDao = vpePortDao;
- }
+ public void setVpePortDao(VpePortDao vpePortDao) {
+ this.vpePortDao = vpePortDao;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/comp/AllocationRequestBuilder.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/comp/AllocationRequestBuilder.java
index 44e4c53a6..c2d614161 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/comp/AllocationRequestBuilder.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/comp/AllocationRequestBuilder.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,14 +29,14 @@ import org.openecomp.sdnc.rm.data.LimitAllocationOutcome;
public interface AllocationRequestBuilder {
- AllocationRequest buildAllocationRequest(
- ServiceData serviceData,
- EquipmentData equipmentData,
- boolean checkOnly,
- boolean change);
+ AllocationRequest buildAllocationRequest(
+ ServiceData serviceData,
+ EquipmentData equipmentData,
+ boolean checkOnly,
+ boolean change);
- ThresholdStatus getThresholdStatus(
- ServiceData serviceData,
- EquipmentData equipmentData,
- LimitAllocationOutcome limitAllocationOutcome);
+ ThresholdStatus getThresholdStatus(
+ ServiceData serviceData,
+ EquipmentData equipmentData,
+ LimitAllocationOutcome limitAllocationOutcome);
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/comp/AllocationRequestBuilderImpl.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/comp/AllocationRequestBuilderImpl.java
index dbc0d8be9..37f9cb81a 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/comp/AllocationRequestBuilderImpl.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/comp/AllocationRequestBuilderImpl.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -45,128 +45,128 @@ import org.slf4j.LoggerFactory;
public class AllocationRequestBuilderImpl implements AllocationRequestBuilder {
- private static final Logger log = LoggerFactory.getLogger(AllocationRequestBuilderImpl.class);
-
- private ResourceRuleDao resourceRuleDao;
- private RangeRuleDao rangeRuleDao;
-
- @Override
- public AllocationRequest buildAllocationRequest(
- ServiceData serviceData,
- EquipmentData equipmentData,
- boolean checkOnly,
- boolean change) {
- List<ResourceRule> resourceRuleList = resourceRuleDao.getResourceRules(serviceData.serviceModel,
- serviceData.endPointPosition, equipmentData.equipmentLevel);
- List<RangeRule> rangeRuleList = rangeRuleDao.getRangeRules(serviceData.serviceModel,
- serviceData.endPointPosition, equipmentData.equipmentLevel);
- if (resourceRuleList.isEmpty() && rangeRuleList.isEmpty())
- return null;
- if (resourceRuleList.size() == 1 && rangeRuleList.isEmpty())
- return buildAllocationRequest(resourceRuleList.get(0), serviceData, equipmentData, checkOnly, change);
-
- if (resourceRuleList.isEmpty() && rangeRuleList.size() == 1)
- return buildAllocationRequest(rangeRuleList.get(0), serviceData, equipmentData, checkOnly, change);
-
- MultiResourceAllocationRequest ar = new MultiResourceAllocationRequest();
- ar.stopOnFirstFailure = false;
- ar.allocationRequestList = new ArrayList<AllocationRequest>();
- for (ResourceRule rr : resourceRuleList) {
- AllocationRequest ar1 = buildAllocationRequest(rr, serviceData, equipmentData, checkOnly, change);
- ar.allocationRequestList.add(ar1);
- }
- for (RangeRule rr : rangeRuleList) {
- AllocationRequest ar1 = buildAllocationRequest(rr, serviceData, equipmentData, checkOnly, change);
- ar.allocationRequestList.add(ar1);
- }
- return ar;
- }
-
- private AllocationRequest buildAllocationRequest(
- ResourceRule resourceRule,
- ServiceData serviceData,
- EquipmentData equipmentData,
- boolean checkOnly,
- boolean change) {
- StrUtil.info(log, resourceRule);
-
- LimitAllocationRequest ar = new LimitAllocationRequest();
- ar.resourceSetId = serviceData.resourceSetId;
- ar.resourceUnionId = serviceData.resourceUnionId;
- ar.resourceName = resourceRule.resourceName;
- ar.assetId = equipmentData.equipmentId;
- ar.missingResourceAction = AllocationAction.Succeed_Allocate;
- ar.expiredResourceAction = AllocationAction.Succeed_Allocate;
- ar.replace = true;
- ar.strict = false;
- ar.checkLimit = ExpressionEvaluator.evalLong(
- change ? resourceRule.hardLimitExpression : resourceRule.softLimitExpression, equipmentData.data);
- ar.checkCount = ExpressionEvaluator.evalLong(resourceRule.allocationExpression, serviceData.data);
- ar.allocateCount = checkOnly ? 0 : ar.checkCount;
- return ar;
- }
-
- private AllocationRequest buildAllocationRequest(
- RangeRule rangeRule,
- ServiceData serviceData,
- EquipmentData equipmentData,
- boolean checkOnly,
- boolean change) {
- StrUtil.info(log, rangeRule);
-
- RangeAllocationRequest ar = new RangeAllocationRequest();
- ar.resourceSetId = serviceData.resourceSetId;
- ar.resourceUnionId = serviceData.resourceUnionId;
- ar.resourceName = rangeRule.rangeName;
- ar.assetId = equipmentData.equipmentId;
- ar.missingResourceAction = AllocationAction.Succeed_Allocate;
- ar.expiredResourceAction = AllocationAction.Succeed_Allocate;
- ar.replace = true;
- ar.check = true;
- ar.allocate = !checkOnly;
- ar.checkMin = rangeRule.minValue;
- ar.checkMax = rangeRule.maxValue;
- return ar;
- }
-
- @Override
- public ThresholdStatus getThresholdStatus(
- ServiceData serviceData,
- EquipmentData equipmentData,
- LimitAllocationOutcome limitAllocationOutcome) {
- ResourceRule rr = resourceRuleDao.getResourceRule(serviceData.serviceModel, serviceData.endPointPosition,
- equipmentData.equipmentLevel, limitAllocationOutcome.request.resourceName);
- if (rr == null || rr.thresholdList == null || rr.thresholdList.isEmpty())
- return null;
-
- ThresholdStatus thresholdStatus = null;
- long maxThresholdValue = 0;
- for (ResourceThreshold th : rr.thresholdList) {
- long thresholdValue = ExpressionEvaluator.evalLong(th.expression, equipmentData.data);
-
- if (thresholdValue > maxThresholdValue) {
- maxThresholdValue = thresholdValue;
-
- if (limitAllocationOutcome.used >= thresholdValue) {
- thresholdStatus = new ThresholdStatus();
- thresholdStatus.resourceRule = rr;
- thresholdStatus.resourceThreshold = th;
- thresholdStatus.limitValue = limitAllocationOutcome.limit;
- thresholdStatus.thresholdValue = thresholdValue;
- thresholdStatus.used = limitAllocationOutcome.used;
- thresholdStatus.lastAdded = limitAllocationOutcome.allocatedCount;
- }
- }
- }
-
- return thresholdStatus;
- }
-
- public void setResourceRuleDao(ResourceRuleDao resourceRuleDao) {
- this.resourceRuleDao = resourceRuleDao;
- }
-
- public void setRangeRuleDao(RangeRuleDao rangeRuleDao) {
- this.rangeRuleDao = rangeRuleDao;
- }
+ private static final Logger log = LoggerFactory.getLogger(AllocationRequestBuilderImpl.class);
+
+ private ResourceRuleDao resourceRuleDao;
+ private RangeRuleDao rangeRuleDao;
+
+ @Override
+ public AllocationRequest buildAllocationRequest(
+ ServiceData serviceData,
+ EquipmentData equipmentData,
+ boolean checkOnly,
+ boolean change) {
+ List<ResourceRule> resourceRuleList = resourceRuleDao.getResourceRules(serviceData.serviceModel,
+ serviceData.endPointPosition, equipmentData.equipmentLevel);
+ List<RangeRule> rangeRuleList = rangeRuleDao.getRangeRules(serviceData.serviceModel,
+ serviceData.endPointPosition, equipmentData.equipmentLevel);
+ if (resourceRuleList.isEmpty() && rangeRuleList.isEmpty())
+ return null;
+ if (resourceRuleList.size() == 1 && rangeRuleList.isEmpty())
+ return buildAllocationRequest(resourceRuleList.get(0), serviceData, equipmentData, checkOnly, change);
+
+ if (resourceRuleList.isEmpty() && rangeRuleList.size() == 1)
+ return buildAllocationRequest(rangeRuleList.get(0), serviceData, equipmentData, checkOnly, change);
+
+ MultiResourceAllocationRequest ar = new MultiResourceAllocationRequest();
+ ar.stopOnFirstFailure = false;
+ ar.allocationRequestList = new ArrayList<AllocationRequest>();
+ for (ResourceRule rr : resourceRuleList) {
+ AllocationRequest ar1 = buildAllocationRequest(rr, serviceData, equipmentData, checkOnly, change);
+ ar.allocationRequestList.add(ar1);
+ }
+ for (RangeRule rr : rangeRuleList) {
+ AllocationRequest ar1 = buildAllocationRequest(rr, serviceData, equipmentData, checkOnly, change);
+ ar.allocationRequestList.add(ar1);
+ }
+ return ar;
+ }
+
+ private AllocationRequest buildAllocationRequest(
+ ResourceRule resourceRule,
+ ServiceData serviceData,
+ EquipmentData equipmentData,
+ boolean checkOnly,
+ boolean change) {
+ StrUtil.info(log, resourceRule);
+
+ LimitAllocationRequest ar = new LimitAllocationRequest();
+ ar.resourceSetId = serviceData.resourceSetId;
+ ar.resourceUnionId = serviceData.resourceUnionId;
+ ar.resourceName = resourceRule.resourceName;
+ ar.assetId = equipmentData.equipmentId;
+ ar.missingResourceAction = AllocationAction.Succeed_Allocate;
+ ar.expiredResourceAction = AllocationAction.Succeed_Allocate;
+ ar.replace = true;
+ ar.strict = false;
+ ar.checkLimit = ExpressionEvaluator.evalLong(
+ change ? resourceRule.hardLimitExpression : resourceRule.softLimitExpression, equipmentData.data);
+ ar.checkCount = ExpressionEvaluator.evalLong(resourceRule.allocationExpression, serviceData.data);
+ ar.allocateCount = checkOnly ? 0 : ar.checkCount;
+ return ar;
+ }
+
+ private AllocationRequest buildAllocationRequest(
+ RangeRule rangeRule,
+ ServiceData serviceData,
+ EquipmentData equipmentData,
+ boolean checkOnly,
+ boolean change) {
+ StrUtil.info(log, rangeRule);
+
+ RangeAllocationRequest ar = new RangeAllocationRequest();
+ ar.resourceSetId = serviceData.resourceSetId;
+ ar.resourceUnionId = serviceData.resourceUnionId;
+ ar.resourceName = rangeRule.rangeName;
+ ar.assetId = equipmentData.equipmentId;
+ ar.missingResourceAction = AllocationAction.Succeed_Allocate;
+ ar.expiredResourceAction = AllocationAction.Succeed_Allocate;
+ ar.replace = true;
+ ar.check = true;
+ ar.allocate = !checkOnly;
+ ar.checkMin = rangeRule.minValue;
+ ar.checkMax = rangeRule.maxValue;
+ return ar;
+ }
+
+ @Override
+ public ThresholdStatus getThresholdStatus(
+ ServiceData serviceData,
+ EquipmentData equipmentData,
+ LimitAllocationOutcome limitAllocationOutcome) {
+ ResourceRule rr = resourceRuleDao.getResourceRule(serviceData.serviceModel, serviceData.endPointPosition,
+ equipmentData.equipmentLevel, limitAllocationOutcome.request.resourceName);
+ if (rr == null || rr.thresholdList == null || rr.thresholdList.isEmpty())
+ return null;
+
+ ThresholdStatus thresholdStatus = null;
+ long maxThresholdValue = 0;
+ for (ResourceThreshold th : rr.thresholdList) {
+ long thresholdValue = ExpressionEvaluator.evalLong(th.expression, equipmentData.data);
+
+ if (thresholdValue > maxThresholdValue) {
+ maxThresholdValue = thresholdValue;
+
+ if (limitAllocationOutcome.used >= thresholdValue) {
+ thresholdStatus = new ThresholdStatus();
+ thresholdStatus.resourceRule = rr;
+ thresholdStatus.resourceThreshold = th;
+ thresholdStatus.limitValue = limitAllocationOutcome.limit;
+ thresholdStatus.thresholdValue = thresholdValue;
+ thresholdStatus.used = limitAllocationOutcome.used;
+ thresholdStatus.lastAdded = limitAllocationOutcome.allocatedCount;
+ }
+ }
+ }
+
+ return thresholdStatus;
+ }
+
+ 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/openecomp/sdnc/ra/rule/dao/MaxPortSpeedDao.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/MaxPortSpeedDao.java
index a56b78809..af6eca7e9 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/MaxPortSpeedDao.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/MaxPortSpeedDao.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,6 +23,6 @@ package org.openecomp.sdnc.ra.rule.dao;
public interface MaxPortSpeedDao {
- // Returns max speed in kbps
- long getMaxPortSpeed(String imageFile, String endPointPosition, String interfaceName);
+ // Returns max speed in kbps
+ long getMaxPortSpeed(String imageFile, String endPointPosition, String interfaceName);
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/MaxPortSpeedDaoImpl.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/MaxPortSpeedDaoImpl.java
index ea0bd7715..b0cc7d2cc 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/MaxPortSpeedDaoImpl.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/MaxPortSpeedDaoImpl.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,53 +33,53 @@ import org.springframework.jdbc.core.RowMapper;
public class MaxPortSpeedDaoImpl implements MaxPortSpeedDao {
- @SuppressWarnings("unused")
- private static final Logger log = LoggerFactory.getLogger(MaxPortSpeedDaoImpl.class);
+ @SuppressWarnings("unused")
+ private static final Logger log = LoggerFactory.getLogger(MaxPortSpeedDaoImpl.class);
- private final static String GET_SQL =
- "SELECT * FROM MAX_PORT_SPEED WHERE image_file_name = ? AND end_point_position = ? AND interface_name = ?";
+ private final static String GET_SQL =
+ "SELECT * FROM MAX_PORT_SPEED WHERE image_file_name = ? AND end_point_position = ? AND interface_name = ?";
- private JdbcTemplate jdbcTemplate;
- private long defaultMaxPortSpeed = 5000000;
- private SpeedUtil speedUtil;
+ private JdbcTemplate jdbcTemplate;
+ private long defaultMaxPortSpeed = 5000000;
+ private SpeedUtil speedUtil;
- @Override
- public long getMaxPortSpeed(String imageFile, String endPointPosition, String interfaceName) {
- List<MaxPortSpeed> maxPortSpeedList =
- jdbcTemplate.query(GET_SQL, new Object[] { imageFile, endPointPosition, interfaceName },
- new RowMapper<MaxPortSpeed>() {
+ @Override
+ public long getMaxPortSpeed(String imageFile, String endPointPosition, String interfaceName) {
+ List<MaxPortSpeed> maxPortSpeedList =
+ jdbcTemplate.query(GET_SQL, new Object[] { imageFile, endPointPosition, interfaceName },
+ new RowMapper<MaxPortSpeed>() {
- @Override
- public MaxPortSpeed mapRow(ResultSet rs, int rowNum) throws SQLException {
- MaxPortSpeed mps = new MaxPortSpeed();
- mps.maxSpeed = rs.getLong("max_speed");
- mps.unit = rs.getString("unit");
- return mps;
- }
- });
+ @Override
+ public MaxPortSpeed mapRow(ResultSet rs, int rowNum) throws SQLException {
+ MaxPortSpeed mps = new MaxPortSpeed();
+ mps.maxSpeed = rs.getLong("max_speed");
+ mps.unit = rs.getString("unit");
+ return mps;
+ }
+ });
- if (maxPortSpeedList.isEmpty())
- return defaultMaxPortSpeed;
+ if (maxPortSpeedList.isEmpty())
+ return defaultMaxPortSpeed;
- MaxPortSpeed mps = maxPortSpeedList.get(0);
- return speedUtil.convertToKbps(mps.maxSpeed, mps.unit);
- }
+ MaxPortSpeed mps = maxPortSpeedList.get(0);
+ return speedUtil.convertToKbps(mps.maxSpeed, mps.unit);
+ }
- private static class MaxPortSpeed {
+ private static class MaxPortSpeed {
- public long maxSpeed;
- public String unit;
- }
+ public long maxSpeed;
+ public String unit;
+ }
- public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
- this.jdbcTemplate = jdbcTemplate;
- }
+ public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
+ this.jdbcTemplate = jdbcTemplate;
+ }
- public void setDefaultMaxPortSpeed(long defaultMaxPortSpeed) {
- this.defaultMaxPortSpeed = defaultMaxPortSpeed;
- }
+ public void setDefaultMaxPortSpeed(long defaultMaxPortSpeed) {
+ this.defaultMaxPortSpeed = defaultMaxPortSpeed;
+ }
- public void setSpeedUtil(SpeedUtil speedUtil) {
- this.speedUtil = speedUtil;
- }
+ public void setSpeedUtil(SpeedUtil speedUtil) {
+ this.speedUtil = speedUtil;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/MaxServerSpeedDao.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/MaxServerSpeedDao.java
index 4bd17f1dd..dd6ae9c8c 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/MaxServerSpeedDao.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/MaxServerSpeedDao.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,6 +23,6 @@ package org.openecomp.sdnc.ra.rule.dao;
public interface MaxServerSpeedDao {
- // Returns max speed in kbps
- long getMaxServerSpeed(String serverModel, int evcCount);
+ // Returns max speed in kbps
+ long getMaxServerSpeed(String serverModel, int evcCount);
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/MaxServerSpeedDaoImpl.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/MaxServerSpeedDaoImpl.java
index c34281797..c0be2e6b5 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/MaxServerSpeedDaoImpl.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/MaxServerSpeedDaoImpl.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,54 +33,54 @@ import org.springframework.jdbc.core.RowMapper;
public class MaxServerSpeedDaoImpl implements MaxServerSpeedDao {
- @SuppressWarnings("unused")
- private static final Logger log = LoggerFactory.getLogger(MaxServerSpeedDaoImpl.class);
+ @SuppressWarnings("unused")
+ private static final Logger log = LoggerFactory.getLogger(MaxServerSpeedDaoImpl.class);
- private final static String GET_SQL =
- "SELECT * FROM MAX_SERVER_SPEED\n" +
- "WHERE (server_model = ? OR server_model = 'ALL') AND evc_count >= ?\n" +
- "ORDER BY evc_count";
+ private final static String GET_SQL =
+ "SELECT * FROM MAX_SERVER_SPEED\n" +
+ "WHERE (server_model = ? OR server_model = 'ALL') AND evc_count >= ?\n" +
+ "ORDER BY evc_count";
- private JdbcTemplate jdbcTemplate;
- private long defaultMaxServerSpeed = 1600000;
- private SpeedUtil speedUtil;
+ private JdbcTemplate jdbcTemplate;
+ private long defaultMaxServerSpeed = 1600000;
+ private SpeedUtil speedUtil;
- @Override
- public long getMaxServerSpeed(String serverModel, int evcCount) {
- List<MaxServerSpeed> maxServerSpeedList =
- jdbcTemplate.query(GET_SQL, new Object[] { serverModel, evcCount }, new RowMapper<MaxServerSpeed>() {
+ @Override
+ public long getMaxServerSpeed(String serverModel, int evcCount) {
+ List<MaxServerSpeed> maxServerSpeedList =
+ jdbcTemplate.query(GET_SQL, new Object[] { serverModel, evcCount }, new RowMapper<MaxServerSpeed>() {
- @Override
- public MaxServerSpeed mapRow(ResultSet rs, int rowNum) throws SQLException {
- MaxServerSpeed mps = new MaxServerSpeed();
- mps.maxSpeed = rs.getLong("max_speed");
- mps.unit = rs.getString("unit");
- return mps;
- }
- });
+ @Override
+ public MaxServerSpeed mapRow(ResultSet rs, int rowNum) throws SQLException {
+ MaxServerSpeed mps = new MaxServerSpeed();
+ mps.maxSpeed = rs.getLong("max_speed");
+ mps.unit = rs.getString("unit");
+ return mps;
+ }
+ });
- if (maxServerSpeedList.isEmpty())
- return defaultMaxServerSpeed;
+ if (maxServerSpeedList.isEmpty())
+ return defaultMaxServerSpeed;
- MaxServerSpeed mps = maxServerSpeedList.get(0);
- return speedUtil.convertToKbps(mps.maxSpeed, mps.unit);
- }
+ MaxServerSpeed mps = maxServerSpeedList.get(0);
+ return speedUtil.convertToKbps(mps.maxSpeed, mps.unit);
+ }
- private static class MaxServerSpeed {
+ private static class MaxServerSpeed {
- public long maxSpeed;
- public String unit;
- }
+ public long maxSpeed;
+ public String unit;
+ }
- public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
- this.jdbcTemplate = jdbcTemplate;
- }
+ public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
+ this.jdbcTemplate = jdbcTemplate;
+ }
- public void setDefaultMaxServerSpeed(long defaultMaxServerSpeed) {
- this.defaultMaxServerSpeed = defaultMaxServerSpeed;
- }
+ public void setDefaultMaxServerSpeed(long defaultMaxServerSpeed) {
+ this.defaultMaxServerSpeed = defaultMaxServerSpeed;
+ }
- public void setSpeedUtil(SpeedUtil speedUtil) {
- this.speedUtil = speedUtil;
- }
+ public void setSpeedUtil(SpeedUtil speedUtil) {
+ this.speedUtil = speedUtil;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/ParameterDao.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/ParameterDao.java
index 509a034ae..2042ba9cd 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/ParameterDao.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/ParameterDao.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,5 +23,5 @@ package org.openecomp.sdnc.ra.rule.dao;
public interface ParameterDao {
- String getParameter(String name);
+ String getParameter(String name);
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/ParameterDaoImpl.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/ParameterDaoImpl.java
index 2cafb2806..c2ca99ce8 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/ParameterDaoImpl.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/ParameterDaoImpl.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,28 +30,28 @@ import org.springframework.jdbc.core.JdbcTemplate;
public class ParameterDaoImpl implements ParameterDao {
- private static final Logger log = LoggerFactory.getLogger(ParameterDaoImpl.class);
+ private static final Logger log = LoggerFactory.getLogger(ParameterDaoImpl.class);
- private final static String GET_SQL = "SELECT * FROM PARAMETERS WHERE name = ?";
+ private final static String GET_SQL = "SELECT * FROM PARAMETERS WHERE name = ?";
- private JdbcTemplate jdbcTemplate;
+ private JdbcTemplate jdbcTemplate;
- @Override
- public String getParameter(String name) {
- List<Map<String, Object>> ll = jdbcTemplate.queryForList(GET_SQL, name);
+ @Override
+ public String getParameter(String name) {
+ List<Map<String, Object>> ll = jdbcTemplate.queryForList(GET_SQL, name);
- if (ll == null || ll.isEmpty()) {
- log.info("Parameter: " + name + " not found in DB");
- return null;
- }
+ if (ll == null || ll.isEmpty()) {
+ log.info("Parameter: " + name + " not found in DB");
+ return null;
+ }
- String v = (String) ll.get(0).get("value");
- log.info("Parameter from DB: " + name + "='" + v + "'");
+ String v = (String) ll.get(0).get("value");
+ log.info("Parameter from DB: " + name + "='" + v + "'");
- return v;
- }
+ return v;
+ }
- public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
- this.jdbcTemplate = jdbcTemplate;
- }
+ public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
+ this.jdbcTemplate = jdbcTemplate;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/RangeRuleDao.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/RangeRuleDao.java
index 798a23037..670039f41 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/RangeRuleDao.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/RangeRuleDao.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,5 +28,5 @@ import org.openecomp.sdnc.ra.rule.data.RangeRule;
public interface RangeRuleDao {
- List<RangeRule> getRangeRules(String serviceModel, String endPointPosition, EquipmentLevel equipLevel);
+ List<RangeRule> getRangeRules(String serviceModel, String endPointPosition, EquipmentLevel equipLevel);
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/RangeRuleDaoImpl.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/RangeRuleDaoImpl.java
index dec05ece4..0880929bd 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/RangeRuleDaoImpl.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/RangeRuleDaoImpl.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,37 +34,37 @@ import org.springframework.jdbc.core.RowMapper;
public class RangeRuleDaoImpl implements RangeRuleDao {
- @SuppressWarnings("unused")
- private static final Logger log = LoggerFactory.getLogger(RangeRuleDaoImpl.class);
+ @SuppressWarnings("unused")
+ private static final Logger log = LoggerFactory.getLogger(RangeRuleDaoImpl.class);
- private static final String GET_SQL =
- "SELECT * FROM RANGE_RULE WHERE service_model = ? AND end_point_position = ? AND equipment_level = ?";
+ private static final String GET_SQL =
+ "SELECT * FROM RANGE_RULE WHERE service_model = ? AND end_point_position = ? AND equipment_level = ?";
- private JdbcTemplate jdbcTemplate;
+ private JdbcTemplate jdbcTemplate;
- @Override
- public List<RangeRule> getRangeRules(String serviceModel, String endPointPosition, EquipmentLevel equipLevel) {
- List<RangeRule> rangeRuleList =
- jdbcTemplate.query(GET_SQL, new Object[] { serviceModel, endPointPosition, equipLevel.toString() },
- new RowMapper<RangeRule>() {
+ @Override
+ public List<RangeRule> getRangeRules(String serviceModel, String endPointPosition, EquipmentLevel equipLevel) {
+ List<RangeRule> rangeRuleList =
+ jdbcTemplate.query(GET_SQL, new Object[] { serviceModel, endPointPosition, equipLevel.toString() },
+ new RowMapper<RangeRule>() {
- @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;
- }
- });
- return rangeRuleList;
- }
+ @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;
+ }
+ });
+ return rangeRuleList;
+ }
- public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
- this.jdbcTemplate = jdbcTemplate;
- }
+ public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
+ this.jdbcTemplate = jdbcTemplate;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/ResourceRuleDao.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/ResourceRuleDao.java
index 31ce9e6ab..55b24b61f 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/ResourceRuleDao.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/ResourceRuleDao.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,11 +28,11 @@ import org.openecomp.sdnc.ra.rule.data.ResourceRule;
public interface ResourceRuleDao {
- List<ResourceRule> getResourceRules(String serviceModel, String endPointPosition, EquipmentLevel equipLevel);
+ List<ResourceRule> getResourceRules(String serviceModel, String endPointPosition, EquipmentLevel equipLevel);
- ResourceRule getResourceRule(
- String serviceModel,
- String endPointPosition,
- EquipmentLevel equipLevel,
- String resourceName);
+ ResourceRule getResourceRule(
+ String serviceModel,
+ String endPointPosition,
+ EquipmentLevel equipLevel,
+ String resourceName);
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/ResourceRuleDaoImpl.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/ResourceRuleDaoImpl.java
index 819a01cd8..72793a40f 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/ResourceRuleDaoImpl.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/ResourceRuleDaoImpl.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,83 +35,83 @@ import org.springframework.jdbc.core.RowMapper;
public class ResourceRuleDaoImpl implements ResourceRuleDao {
- @SuppressWarnings("unused")
- private static final Logger log = LoggerFactory.getLogger(ResourceRuleDaoImpl.class);
-
- private static final String GET1_SQL =
- "SELECT * FROM RESOURCE_RULE WHERE service_model = ? AND end_point_position = ? AND equipment_level = ?";
- private static final String GET2_SQL =
- "SELECT * FROM RESOURCE_RULE WHERE service_model = ? AND end_point_position = ? AND equipment_level = ? AND resource_name = ?";
- private static final String THRESHOLD_SQL = "SELECT * FROM RESOURCE_THRESHOLD WHERE resource_rule_id = ?";
-
- private JdbcTemplate jdbcTemplate;
- ResourceRuleRowMapper resourceRuleRowMapper = new ResourceRuleRowMapper();
- ResourceThresholdRowMapper resourceThresholdRowMapper = new ResourceThresholdRowMapper();
-
- @Override
- public List<ResourceRule> getResourceRules(
- String serviceModel,
- String endPointPosition,
- EquipmentLevel equipLevel) {
- List<ResourceRule> resourceRuleList = jdbcTemplate.query(GET1_SQL,
- new Object[] { serviceModel, endPointPosition, equipLevel.toString() }, resourceRuleRowMapper);
-
- for (ResourceRule rr : resourceRuleList)
- rr.thresholdList = jdbcTemplate.query(THRESHOLD_SQL, new Object[] { rr.id }, resourceThresholdRowMapper);
-
- return resourceRuleList;
- }
-
- @Override
- public ResourceRule getResourceRule(
- String serviceModel,
- String endPointPosition,
- EquipmentLevel equipLevel,
- String resourceName) {
- List<ResourceRule> resourceRuleList = jdbcTemplate.query(GET2_SQL,
- new Object[] { serviceModel, endPointPosition, equipLevel.toString(), resourceName },
- resourceRuleRowMapper);
-
- if (resourceRuleList == null || resourceRuleList.isEmpty())
- return null;
-
- ResourceRule rr = resourceRuleList.get(0);
- rr.thresholdList = jdbcTemplate.query(THRESHOLD_SQL, new Object[] { rr.id }, resourceThresholdRowMapper);
-
- return rr;
- }
-
- private static class ResourceRuleRowMapper implements RowMapper<ResourceRule> {
-
- @Override
- public ResourceRule mapRow(ResultSet rs, int rowNum) throws SQLException {
- ResourceRule rl = new ResourceRule();
- rl.id = rs.getLong("resource_rule_id");
- rl.resourceName = rs.getString("resource_name");
- rl.serviceModel = rs.getString("service_model");
- rl.endPointPosition = rs.getString("end_point_position");
- rl.serviceExpression = rs.getString("service_expression");
- rl.equipmentLevel = rs.getString("equipment_level");
- rl.equipmentExpression = rs.getString("equipment_expression");
- rl.allocationExpression = rs.getString("allocation_expression");
- rl.softLimitExpression = rs.getString("soft_limit_expression");
- rl.hardLimitExpression = rs.getString("hard_limit_expression");
- return rl;
- }
- }
-
- private static class ResourceThresholdRowMapper implements RowMapper<ResourceThreshold> {
-
- @Override
- public ResourceThreshold mapRow(ResultSet rs, int rowNum) throws SQLException {
- ResourceThreshold th = new ResourceThreshold();
- th.expression = rs.getString("threshold_expression");
- th.message = rs.getString("threshold_message");
- return th;
- }
- }
-
- public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
- this.jdbcTemplate = jdbcTemplate;
- }
+ @SuppressWarnings("unused")
+ private static final Logger log = LoggerFactory.getLogger(ResourceRuleDaoImpl.class);
+
+ private static final String GET1_SQL =
+ "SELECT * FROM RESOURCE_RULE WHERE service_model = ? AND end_point_position = ? AND equipment_level = ?";
+ private static final String GET2_SQL =
+ "SELECT * FROM RESOURCE_RULE WHERE service_model = ? AND end_point_position = ? AND equipment_level = ? AND resource_name = ?";
+ private static final String THRESHOLD_SQL = "SELECT * FROM RESOURCE_THRESHOLD WHERE resource_rule_id = ?";
+
+ private JdbcTemplate jdbcTemplate;
+ ResourceRuleRowMapper resourceRuleRowMapper = new ResourceRuleRowMapper();
+ ResourceThresholdRowMapper resourceThresholdRowMapper = new ResourceThresholdRowMapper();
+
+ @Override
+ public List<ResourceRule> getResourceRules(
+ String serviceModel,
+ String endPointPosition,
+ EquipmentLevel equipLevel) {
+ List<ResourceRule> resourceRuleList = jdbcTemplate.query(GET1_SQL,
+ new Object[] { serviceModel, endPointPosition, equipLevel.toString() }, resourceRuleRowMapper);
+
+ for (ResourceRule rr : resourceRuleList)
+ rr.thresholdList = jdbcTemplate.query(THRESHOLD_SQL, new Object[] { rr.id }, resourceThresholdRowMapper);
+
+ return resourceRuleList;
+ }
+
+ @Override
+ public ResourceRule getResourceRule(
+ String serviceModel,
+ String endPointPosition,
+ EquipmentLevel equipLevel,
+ String resourceName) {
+ List<ResourceRule> resourceRuleList = jdbcTemplate.query(GET2_SQL,
+ new Object[] { serviceModel, endPointPosition, equipLevel.toString(), resourceName },
+ resourceRuleRowMapper);
+
+ if (resourceRuleList == null || resourceRuleList.isEmpty())
+ return null;
+
+ ResourceRule rr = resourceRuleList.get(0);
+ rr.thresholdList = jdbcTemplate.query(THRESHOLD_SQL, new Object[] { rr.id }, resourceThresholdRowMapper);
+
+ return rr;
+ }
+
+ private static class ResourceRuleRowMapper implements RowMapper<ResourceRule> {
+
+ @Override
+ public ResourceRule mapRow(ResultSet rs, int rowNum) throws SQLException {
+ ResourceRule rl = new ResourceRule();
+ rl.id = rs.getLong("resource_rule_id");
+ rl.resourceName = rs.getString("resource_name");
+ rl.serviceModel = rs.getString("service_model");
+ rl.endPointPosition = rs.getString("end_point_position");
+ rl.serviceExpression = rs.getString("service_expression");
+ rl.equipmentLevel = rs.getString("equipment_level");
+ rl.equipmentExpression = rs.getString("equipment_expression");
+ rl.allocationExpression = rs.getString("allocation_expression");
+ rl.softLimitExpression = rs.getString("soft_limit_expression");
+ rl.hardLimitExpression = rs.getString("hard_limit_expression");
+ return rl;
+ }
+ }
+
+ private static class ResourceThresholdRowMapper implements RowMapper<ResourceThreshold> {
+
+ @Override
+ public ResourceThreshold mapRow(ResultSet rs, int rowNum) throws SQLException {
+ ResourceThreshold th = new ResourceThreshold();
+ th.expression = rs.getString("threshold_expression");
+ th.message = rs.getString("threshold_message");
+ return th;
+ }
+ }
+
+ public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
+ this.jdbcTemplate = jdbcTemplate;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/VpeLockDao.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/VpeLockDao.java
index eb41792d9..6734fb54e 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/VpeLockDao.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/VpeLockDao.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,5 +23,5 @@ package org.openecomp.sdnc.ra.rule.dao;
public interface VpeLockDao {
- String getVpeLock(String vpeName);
+ String getVpeLock(String vpeName);
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/VpeLockDaoImpl.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/VpeLockDaoImpl.java
index eb6cef3bd..d712b8d0f 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/VpeLockDaoImpl.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/dao/VpeLockDaoImpl.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,20 +29,20 @@ import org.springframework.jdbc.core.JdbcTemplate;
public class VpeLockDaoImpl implements VpeLockDao {
- @SuppressWarnings("unused")
- private static final Logger log = LoggerFactory.getLogger(VpeLockDaoImpl.class);
+ @SuppressWarnings("unused")
+ private static final Logger log = LoggerFactory.getLogger(VpeLockDaoImpl.class);
- private final static String GET_SQL = "SELECT vpn_lock FROM VPE_LOCK WHERE vpe_name = ?";
+ private final static String GET_SQL = "SELECT vpn_lock FROM VPE_LOCK WHERE vpe_name = ?";
- private JdbcTemplate jdbcTemplate;
+ private JdbcTemplate jdbcTemplate;
- @Override
- public String getVpeLock(String vpeName) {
- List<String> ll = jdbcTemplate.queryForList(GET_SQL, String.class, vpeName);
- return ll != null && !ll.isEmpty() ? ll.get(0) : null;
- }
+ @Override
+ public String getVpeLock(String vpeName) {
+ List<String> ll = jdbcTemplate.queryForList(GET_SQL, String.class, vpeName);
+ return ll != null && !ll.isEmpty() ? ll.get(0) : null;
+ }
- public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
- this.jdbcTemplate = jdbcTemplate;
- }
+ public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
+ this.jdbcTemplate = jdbcTemplate;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/data/RangeRule.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/data/RangeRule.java
index ed76f6b16..e657e8b47 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/data/RangeRule.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/data/RangeRule.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,11 +23,11 @@ package org.openecomp.sdnc.ra.rule.data;
public class RangeRule {
- public long id;
- public String rangeName;
- public String serviceModel;
- public String endPointPosition;
- public String equipmentLevel;
- public int minValue;
- public int maxValue;
+ public long id;
+ public String rangeName;
+ public String serviceModel;
+ public String endPointPosition;
+ public String equipmentLevel;
+ public int minValue;
+ public int maxValue;
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/data/ResourceRule.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/data/ResourceRule.java
index c4d55f921..ca8ab5407 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/data/ResourceRule.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/data/ResourceRule.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,15 +25,15 @@ import java.util.List;
public class ResourceRule {
- public long id;
- public String resourceName;
- public String serviceModel;
- public String endPointPosition;
- public String serviceExpression;
- public String equipmentLevel;
- public String equipmentExpression;
- public String allocationExpression;
- public String softLimitExpression;
- public String hardLimitExpression;
- public List<ResourceThreshold> thresholdList;
+ public long id;
+ public String resourceName;
+ public String serviceModel;
+ public String endPointPosition;
+ public String serviceExpression;
+ public String equipmentLevel;
+ public String equipmentExpression;
+ public String allocationExpression;
+ public String softLimitExpression;
+ public String hardLimitExpression;
+ public List<ResourceThreshold> thresholdList;
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/data/ResourceThreshold.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/data/ResourceThreshold.java
index 7be4067e0..b733a356b 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/data/ResourceThreshold.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/data/ResourceThreshold.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,6 +23,6 @@ package org.openecomp.sdnc.ra.rule.data;
public class ResourceThreshold {
- public String expression;
- public String message;
+ public String expression;
+ public String message;
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/data/ThresholdStatus.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/data/ThresholdStatus.java
index 5f772ef18..d9ea21769 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/data/ThresholdStatus.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/rule/data/ThresholdStatus.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,10 +23,10 @@ package org.openecomp.sdnc.ra.rule.data;
public class ThresholdStatus {
- public ResourceRule resourceRule;
- public ResourceThreshold resourceThreshold;
- public long limitValue;
- public long thresholdValue;
- public long used;
- public long lastAdded;
+ public ResourceRule resourceRule;
+ public ResourceThreshold resourceThreshold;
+ public long limitValue;
+ public long thresholdValue;
+ public long used;
+ public long lastAdded;
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/service/dao/ServiceResourceDao.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/service/dao/ServiceResourceDao.java
index 811118cb4..c057d91f7 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/service/dao/ServiceResourceDao.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/service/dao/ServiceResourceDao.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,13 +26,13 @@ import org.openecomp.sdnc.ra.service.data.ServiceStatus;
public interface ServiceResourceDao {
- ServiceResource getServiceResource(String serviceInstanceId, ServiceStatus serviceStatus);
+ ServiceResource getServiceResource(String serviceInstanceId, ServiceStatus serviceStatus);
- void addServiceResource(ServiceResource serviceResource);
+ void addServiceResource(ServiceResource serviceResource);
- void updateServiceResource(ServiceResource serviceResource);
+ void updateServiceResource(ServiceResource serviceResource);
- void deleteServiceResource(String serviceInstanceId, ServiceStatus serviceStatus);
+ void deleteServiceResource(String serviceInstanceId, ServiceStatus serviceStatus);
- void updateServiceStatus(String serviceInstanceId, ServiceStatus serviceStatus, ServiceStatus newServiceStatus);
+ void updateServiceStatus(String serviceInstanceId, ServiceStatus serviceStatus, ServiceStatus newServiceStatus);
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/service/dao/ServiceResourceDaoImpl.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/service/dao/ServiceResourceDaoImpl.java
index 6432e80d7..2b5cc0acb 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/service/dao/ServiceResourceDaoImpl.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/service/dao/ServiceResourceDaoImpl.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,77 +34,77 @@ import org.springframework.jdbc.core.RowMapper;
public class ServiceResourceDaoImpl implements ServiceResourceDao {
- @SuppressWarnings("unused")
- private static final Logger log = LoggerFactory.getLogger(ServiceResourceDaoImpl.class);
-
- private static final String GET_SQL =
- "SELECT * FROM SERVICE_RESOURCE WHERE service_instance_id = ? AND service_status = ?";
-
- private static final String ADD_SQL = "INSERT INTO SERVICE_RESOURCE (\n"
- + " service_instance_id, service_status, service_change_number, resource_set_id, resource_union_id)\n"
- + "VALUES (?, ?, ?, ?, ?)";
-
- private static final String UPDATE_SQL =
- "UPDATE SERVICE_RESOURCE SET service_change_number = ?, resource_set_id = ?\n"
- + "WHERE service_instance_id = ? AND service_status = ?";
-
- private static final String DELETE_SQL =
- "DELETE FROM SERVICE_RESOURCE WHERE service_instance_id = ? AND service_status = ?";
-
- private static final String UPDATE_STATUS_SQL =
- "UPDATE SERVICE_RESOURCE SET service_status = ? WHERE service_instance_id = ? AND service_status = ?";
-
- private JdbcTemplate jdbcTemplate;
-
- @Override
- public ServiceResource getServiceResource(final String serviceInstanceId, final ServiceStatus serviceStatus) {
- List<ServiceResource> serviceResourceList =
- jdbcTemplate.query(GET_SQL, new Object[] { serviceInstanceId, serviceStatus.toString() },
- new RowMapper<ServiceResource>() {
-
- @Override
- public ServiceResource mapRow(ResultSet rs, int rowNum) throws SQLException {
- ServiceResource sr = new ServiceResource();
- sr.id = rs.getLong("service_resource_id");
- sr.serviceInstanceId = serviceInstanceId;
- sr.serviceStatus = serviceStatus;
- sr.serviceChangeNumber = rs.getInt("service_change_number");
- sr.resourceSetId = rs.getString("resource_set_id");
- sr.resourceUnionId = rs.getString("resource_union_id");
- return sr;
- }
- });
- if (serviceResourceList.isEmpty())
- return null;
- return serviceResourceList.get(0);
- }
-
- @Override
- public void addServiceResource(ServiceResource serviceResource) {
- jdbcTemplate.update(ADD_SQL, serviceResource.serviceInstanceId, serviceResource.serviceStatus.toString(),
- serviceResource.serviceChangeNumber, serviceResource.resourceSetId, serviceResource.resourceUnionId);
- }
-
- @Override
- public void updateServiceResource(ServiceResource serviceResource) {
- jdbcTemplate.update(UPDATE_SQL, serviceResource.serviceChangeNumber, serviceResource.resourceSetId,
- serviceResource.serviceInstanceId, serviceResource.serviceStatus.toString());
- }
-
- @Override
- public void deleteServiceResource(String serviceInstanceId, ServiceStatus serviceStatus) {
- jdbcTemplate.update(DELETE_SQL, serviceInstanceId, serviceStatus.toString());
- }
-
- @Override
- public void updateServiceStatus(
- String serviceInstanceId,
- ServiceStatus serviceStatus,
- ServiceStatus newServiceStatus) {
- jdbcTemplate.update(UPDATE_STATUS_SQL, newServiceStatus.toString(), serviceInstanceId, serviceStatus.toString());
- }
-
- public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
- this.jdbcTemplate = jdbcTemplate;
- }
+ @SuppressWarnings("unused")
+ private static final Logger log = LoggerFactory.getLogger(ServiceResourceDaoImpl.class);
+
+ private static final String GET_SQL =
+ "SELECT * FROM SERVICE_RESOURCE WHERE service_instance_id = ? AND service_status = ?";
+
+ private static final String ADD_SQL = "INSERT INTO SERVICE_RESOURCE (\n"
+ + " service_instance_id, service_status, service_change_number, resource_set_id, resource_union_id)\n"
+ + "VALUES (?, ?, ?, ?, ?)";
+
+ private static final String UPDATE_SQL =
+ "UPDATE SERVICE_RESOURCE SET service_change_number = ?, resource_set_id = ?\n"
+ + "WHERE service_instance_id = ? AND service_status = ?";
+
+ private static final String DELETE_SQL =
+ "DELETE FROM SERVICE_RESOURCE WHERE service_instance_id = ? AND service_status = ?";
+
+ private static final String UPDATE_STATUS_SQL =
+ "UPDATE SERVICE_RESOURCE SET service_status = ? WHERE service_instance_id = ? AND service_status = ?";
+
+ private JdbcTemplate jdbcTemplate;
+
+ @Override
+ public ServiceResource getServiceResource(final String serviceInstanceId, final ServiceStatus serviceStatus) {
+ List<ServiceResource> serviceResourceList =
+ jdbcTemplate.query(GET_SQL, new Object[] { serviceInstanceId, serviceStatus.toString() },
+ new RowMapper<ServiceResource>() {
+
+ @Override
+ public ServiceResource mapRow(ResultSet rs, int rowNum) throws SQLException {
+ ServiceResource sr = new ServiceResource();
+ sr.id = rs.getLong("service_resource_id");
+ sr.serviceInstanceId = serviceInstanceId;
+ sr.serviceStatus = serviceStatus;
+ sr.serviceChangeNumber = rs.getInt("service_change_number");
+ sr.resourceSetId = rs.getString("resource_set_id");
+ sr.resourceUnionId = rs.getString("resource_union_id");
+ return sr;
+ }
+ });
+ if (serviceResourceList.isEmpty())
+ return null;
+ return serviceResourceList.get(0);
+ }
+
+ @Override
+ public void addServiceResource(ServiceResource serviceResource) {
+ jdbcTemplate.update(ADD_SQL, serviceResource.serviceInstanceId, serviceResource.serviceStatus.toString(),
+ serviceResource.serviceChangeNumber, serviceResource.resourceSetId, serviceResource.resourceUnionId);
+ }
+
+ @Override
+ public void updateServiceResource(ServiceResource serviceResource) {
+ jdbcTemplate.update(UPDATE_SQL, serviceResource.serviceChangeNumber, serviceResource.resourceSetId,
+ serviceResource.serviceInstanceId, serviceResource.serviceStatus.toString());
+ }
+
+ @Override
+ public void deleteServiceResource(String serviceInstanceId, ServiceStatus serviceStatus) {
+ jdbcTemplate.update(DELETE_SQL, serviceInstanceId, serviceStatus.toString());
+ }
+
+ @Override
+ public void updateServiceStatus(
+ String serviceInstanceId,
+ ServiceStatus serviceStatus,
+ ServiceStatus newServiceStatus) {
+ jdbcTemplate.update(UPDATE_STATUS_SQL, newServiceStatus.toString(), serviceInstanceId, serviceStatus.toString());
+ }
+
+ public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
+ this.jdbcTemplate = jdbcTemplate;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/service/data/ServiceResource.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/service/data/ServiceResource.java
index 65d4488ee..e17145e5b 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/service/data/ServiceResource.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/service/data/ServiceResource.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,10 +23,10 @@ package org.openecomp.sdnc.ra.service.data;
public class ServiceResource {
- public long id;
- public String serviceInstanceId;
- public ServiceStatus serviceStatus;
- public int serviceChangeNumber;
- public String resourceSetId;
- public String resourceUnionId;
+ public long id;
+ public String serviceInstanceId;
+ public ServiceStatus serviceStatus;
+ public int serviceChangeNumber;
+ public String resourceSetId;
+ public String resourceUnionId;
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/service/data/ServiceStatus.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/service/data/ServiceStatus.java
index 32f473d3d..862c3e443 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/service/data/ServiceStatus.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/ra/service/data/ServiceStatus.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,5 +23,5 @@ package org.openecomp.sdnc.ra.service.data;
public enum ServiceStatus {
- Active, Pending
+ Active, Pending
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/comp/AllocationFunction.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/comp/AllocationFunction.java
index 3a9340916..00cfb1fc4 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/comp/AllocationFunction.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/comp/AllocationFunction.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -61,270 +61,270 @@ import org.slf4j.LoggerFactory;
class AllocationFunction extends SynchronizedFunction {
- @SuppressWarnings("unused")
- private static final Logger log = LoggerFactory.getLogger(AllocationFunction.class);
-
- private ResourceDao resourceDao;
-
- private String applicationId;
- private AllocationRequest request;
- private AllocationOutcome outcome;
-
- private List<Resource> updateList = new ArrayList<Resource>();
-
- public AllocationFunction(LockHelper lockHelper, ResourceDao resourceDao, String applicationId,
- AllocationRequest request, int lockTimeout) {
- super(lockHelper, getLockNames(request), lockTimeout);
- this.applicationId = applicationId;
- this.resourceDao = resourceDao;
- this.request = request;
- }
-
- private static Collection<String> getLockNames(AllocationRequest request) {
- Set<String> lockResourceNames = new HashSet<String>();
- addLockNames(lockResourceNames, request);
- return lockResourceNames;
- }
-
- private static void addLockNames(Set<String> lockResourceNames, AllocationRequest request) {
- if (request instanceof MultiAssetAllocationRequest) {
- MultiAssetAllocationRequest req = (MultiAssetAllocationRequest) request;
- if (req.assetIdList != null)
- lockResourceNames.addAll(req.assetIdList);
- } else if (request instanceof MultiResourceAllocationRequest) {
- MultiResourceAllocationRequest req = (MultiResourceAllocationRequest) request;
- if (req.allocationRequestList != null)
- for (AllocationRequest request1 : req.allocationRequestList)
- addLockNames(lockResourceNames, request1);
- } else if (request.assetId != null)
- lockResourceNames.add(request.assetId);
- }
-
- @Override
- public void _exec() throws ResourceLockedException {
- outcome = allocate(request);
- if (outcome.status == AllocationStatus.Success)
- for (Resource r : updateList)
- resourceDao.saveResource(r);
- }
-
- private AllocationOutcome allocate(AllocationRequest allocationRequest) throws ResourceLockedException {
- if (allocationRequest instanceof MultiAssetAllocationRequest)
- return allocateMultiAsset((MultiAssetAllocationRequest) allocationRequest);
- if (allocationRequest instanceof MultiResourceAllocationRequest)
- return allocateMultiResource((MultiResourceAllocationRequest) allocationRequest);
- if (allocationRequest instanceof LimitAllocationRequest)
- return allocateLimit((LimitAllocationRequest) allocationRequest);
- if (allocationRequest instanceof LabelAllocationRequest)
- return allocateLabel((LabelAllocationRequest) allocationRequest);
- if (allocationRequest instanceof RangeAllocationRequest)
- return allocateRange((RangeAllocationRequest) allocationRequest);
- return null;
- }
-
- private MultiAssetAllocationOutcome allocateMultiAsset(MultiAssetAllocationRequest req) {
- // TODO Auto-generated method stub
- return null;
- }
-
- private MultiResourceAllocationOutcome allocateMultiResource(MultiResourceAllocationRequest req) {
- MultiResourceAllocationOutcome out = new MultiResourceAllocationOutcome();
- out.request = req;
- out.allocationOutcomeList = new ArrayList<AllocationOutcome>();
- out.status = AllocationStatus.Success;
-
- if (req.allocationRequestList != null)
- for (AllocationRequest req1 : req.allocationRequestList) {
- AllocationOutcome out1 = allocate(req1);
- out.allocationOutcomeList.add(out1);
- if (out1.status != AllocationStatus.Success)
- out.status = AllocationStatus.Failure;
- }
-
- return out;
- }
-
- private LimitAllocationOutcome allocateLimit(LimitAllocationRequest req) {
- LimitAllocationOutcome out = new LimitAllocationOutcome();
- out.request = req;
-
- Resource r = resourceDao.getResource(req.assetId, req.resourceName);
- if (r == null) {
- r = new LimitResource();
- r.resourceKey = new ResourceKey();
- r.resourceKey.assetId = req.assetId;
- r.resourceKey.resourceName = req.resourceName;
- r.resourceType = ResourceType.Limit;
- } else {
- if (r.resourceType != ResourceType.Limit) {
- out.status = AllocationStatus.ResourceNotFound;
- return out;
- }
- LimitUtil.recalculate((LimitResource) r);
- }
-
- LimitResource l = (LimitResource) r;
- if (LimitUtil.checkLimit(l, req)) {
- out.status = AllocationStatus.Success;
- if (req.allocateCount > 0) {
- out.allocatedCount = LimitUtil.allocateLimit(l, req, applicationId);
- updateList.add(l);
- }
- } else
- out.status = AllocationStatus.Failure;
-
- out.used = l.used;
- out.limit = req.checkLimit;
-
- return out;
- }
-
- private LabelAllocationOutcome allocateLabel(LabelAllocationRequest req) {
- LabelAllocationOutcome out = new LabelAllocationOutcome();
-
- out.request = req;
-
- Resource r = resourceDao.getResource(req.assetId, req.resourceName);
- if (r == null) {
- r = new LabelResource();
- r.resourceKey = new ResourceKey();
- r.resourceKey.assetId = req.assetId;
- r.resourceKey.resourceName = req.resourceName;
- r.resourceType = ResourceType.Label;
- } else {
- if (r.resourceType != ResourceType.Label) {
- out.status = AllocationStatus.ResourceNotFound;
- return out;
- }
- LabelUtil.recalculate((LabelResource) r);
- }
-
- LabelResource l = (LabelResource) r;
- if (LabelUtil.checkLabel(l, req)) {
- out.status = AllocationStatus.Success;
- out.currentLabel = l.label;
- if (req.allocate) {
- out.allocatedLabel = LabelUtil.allocateLabel(l, req, applicationId);
- updateList.add(l);
- }
- } else
- out.status = AllocationStatus.Failure;
-
- return out;
- }
-
- private RangeAllocationOutcome allocateRange(RangeAllocationRequest req) {
- RangeAllocationOutcome out = new RangeAllocationOutcome();
-
- out.request = req;
-
- Resource r = resourceDao.getResource(req.assetId, req.resourceName);
- if (r == null) {
- r = new RangeResource();
- r.resourceKey = new ResourceKey();
- r.resourceKey.assetId = req.assetId;
- r.resourceKey.resourceName = req.resourceName;
- r.resourceType = ResourceType.Range;
- } else {
- if (r.resourceType != ResourceType.Range) {
- out.status = AllocationStatus.ResourceNotFound;
- return out;
- }
- RangeUtil.recalculate((RangeResource) r);
- }
-
- RangeResource rr = (RangeResource) r;
- SortedSet<Integer> foundNumbers = null;
- if (!req.check) {
- out.status = AllocationStatus.Success;
- foundNumbers = req.requestedNumbers;
- } else {
- if (req.requestedNumbers != null && req.requestedNumbers.size() > 0) {
- foundNumbers = req.requestedNumbers;
- out.status = AllocationStatus.Success;
- for (int n : foundNumbers)
- if (!RangeUtil.checkRange(rr, req, n)) {
- out.status = AllocationStatus.Failure;
- break;
- }
- } else {
- foundNumbers = new TreeSet<Integer>();
- int foundCount = 0;
-
- // First try to reuse the numbers already taken by the same resource union
- SortedSet<Integer> uu = RangeUtil.getUsed(rr, req.resourceUnionId);
- if (uu != null && !uu.isEmpty()) {
- if (uu.size() >= req.requestedCount) {
- // Just take the first req.requestedCount numbers from uu
- Iterator<Integer> i = uu.iterator();
- while (foundCount < req.requestedCount) {
- foundNumbers.add(i.next());
- foundCount++;
- }
- } else {
- // Additional numbers are requested. Try to find them starting from
- // the minimum we have in uu (the first element) towards the min
- // parameter, and then starting from the maximum in uu (the last
- // element) towards the max parameter.
- // NOTE: In case of request for sequential numbers, the parameters
- // 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;
- }
- 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 we could not find enough numbers trying to reuse currently
- // allocated, reset foundNumbers and foundCount, continue with
- // the normal allocation of new numbers.
- if (foundCount < req.requestedCount) {
- foundNumbers = new TreeSet<Integer>();
- foundCount = 0;
- }
- }
- }
-
- 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;
-
- out.status = foundCount == req.requestedCount ? AllocationStatus.Success : AllocationStatus.Failure;
- }
- }
-
- if (out.status == AllocationStatus.Success) {
- out.allocated = foundNumbers;
- if (req.allocate) {
- RangeUtil.allocateRange(rr, out.allocated, req, applicationId);
- updateList.add(rr);
- }
- } else
- out.allocated = new TreeSet<Integer>();
-
- out.used = rr.used;
-
- return out;
- }
-
- public AllocationOutcome getAllocationOutcome() {
- return outcome;
- }
+ @SuppressWarnings("unused")
+ private static final Logger log = LoggerFactory.getLogger(AllocationFunction.class);
+
+ private ResourceDao resourceDao;
+
+ private String applicationId;
+ private AllocationRequest request;
+ private AllocationOutcome outcome;
+
+ private List<Resource> updateList = new ArrayList<Resource>();
+
+ public AllocationFunction(LockHelper lockHelper, ResourceDao resourceDao, String applicationId,
+ AllocationRequest request, int lockTimeout) {
+ super(lockHelper, getLockNames(request), lockTimeout);
+ this.applicationId = applicationId;
+ this.resourceDao = resourceDao;
+ this.request = request;
+ }
+
+ private static Collection<String> getLockNames(AllocationRequest request) {
+ Set<String> lockResourceNames = new HashSet<String>();
+ addLockNames(lockResourceNames, request);
+ return lockResourceNames;
+ }
+
+ private static void addLockNames(Set<String> lockResourceNames, AllocationRequest request) {
+ if (request instanceof MultiAssetAllocationRequest) {
+ MultiAssetAllocationRequest req = (MultiAssetAllocationRequest) request;
+ if (req.assetIdList != null)
+ lockResourceNames.addAll(req.assetIdList);
+ } else if (request instanceof MultiResourceAllocationRequest) {
+ MultiResourceAllocationRequest req = (MultiResourceAllocationRequest) request;
+ if (req.allocationRequestList != null)
+ for (AllocationRequest request1 : req.allocationRequestList)
+ addLockNames(lockResourceNames, request1);
+ } else if (request.assetId != null)
+ lockResourceNames.add(request.assetId);
+ }
+
+ @Override
+ public void _exec() throws ResourceLockedException {
+ outcome = allocate(request);
+ if (outcome.status == AllocationStatus.Success)
+ for (Resource r : updateList)
+ resourceDao.saveResource(r);
+ }
+
+ private AllocationOutcome allocate(AllocationRequest allocationRequest) throws ResourceLockedException {
+ if (allocationRequest instanceof MultiAssetAllocationRequest)
+ return allocateMultiAsset((MultiAssetAllocationRequest) allocationRequest);
+ if (allocationRequest instanceof MultiResourceAllocationRequest)
+ return allocateMultiResource((MultiResourceAllocationRequest) allocationRequest);
+ if (allocationRequest instanceof LimitAllocationRequest)
+ return allocateLimit((LimitAllocationRequest) allocationRequest);
+ if (allocationRequest instanceof LabelAllocationRequest)
+ return allocateLabel((LabelAllocationRequest) allocationRequest);
+ if (allocationRequest instanceof RangeAllocationRequest)
+ return allocateRange((RangeAllocationRequest) allocationRequest);
+ return null;
+ }
+
+ private MultiAssetAllocationOutcome allocateMultiAsset(MultiAssetAllocationRequest req) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ private MultiResourceAllocationOutcome allocateMultiResource(MultiResourceAllocationRequest req) {
+ MultiResourceAllocationOutcome out = new MultiResourceAllocationOutcome();
+ out.request = req;
+ out.allocationOutcomeList = new ArrayList<AllocationOutcome>();
+ out.status = AllocationStatus.Success;
+
+ if (req.allocationRequestList != null)
+ for (AllocationRequest req1 : req.allocationRequestList) {
+ AllocationOutcome out1 = allocate(req1);
+ out.allocationOutcomeList.add(out1);
+ if (out1.status != AllocationStatus.Success)
+ out.status = AllocationStatus.Failure;
+ }
+
+ return out;
+ }
+
+ private LimitAllocationOutcome allocateLimit(LimitAllocationRequest req) {
+ LimitAllocationOutcome out = new LimitAllocationOutcome();
+ out.request = req;
+
+ Resource r = resourceDao.getResource(req.assetId, req.resourceName);
+ if (r == null) {
+ r = new LimitResource();
+ r.resourceKey = new ResourceKey();
+ r.resourceKey.assetId = req.assetId;
+ r.resourceKey.resourceName = req.resourceName;
+ r.resourceType = ResourceType.Limit;
+ } else {
+ if (r.resourceType != ResourceType.Limit) {
+ out.status = AllocationStatus.ResourceNotFound;
+ return out;
+ }
+ LimitUtil.recalculate((LimitResource) r);
+ }
+
+ LimitResource l = (LimitResource) r;
+ if (LimitUtil.checkLimit(l, req)) {
+ out.status = AllocationStatus.Success;
+ if (req.allocateCount > 0) {
+ out.allocatedCount = LimitUtil.allocateLimit(l, req, applicationId);
+ updateList.add(l);
+ }
+ } else
+ out.status = AllocationStatus.Failure;
+
+ out.used = l.used;
+ out.limit = req.checkLimit;
+
+ return out;
+ }
+
+ private LabelAllocationOutcome allocateLabel(LabelAllocationRequest req) {
+ LabelAllocationOutcome out = new LabelAllocationOutcome();
+
+ out.request = req;
+
+ Resource r = resourceDao.getResource(req.assetId, req.resourceName);
+ if (r == null) {
+ r = new LabelResource();
+ r.resourceKey = new ResourceKey();
+ r.resourceKey.assetId = req.assetId;
+ r.resourceKey.resourceName = req.resourceName;
+ r.resourceType = ResourceType.Label;
+ } else {
+ if (r.resourceType != ResourceType.Label) {
+ out.status = AllocationStatus.ResourceNotFound;
+ return out;
+ }
+ LabelUtil.recalculate((LabelResource) r);
+ }
+
+ LabelResource l = (LabelResource) r;
+ if (LabelUtil.checkLabel(l, req)) {
+ out.status = AllocationStatus.Success;
+ out.currentLabel = l.label;
+ if (req.allocate) {
+ out.allocatedLabel = LabelUtil.allocateLabel(l, req, applicationId);
+ updateList.add(l);
+ }
+ } else
+ out.status = AllocationStatus.Failure;
+
+ return out;
+ }
+
+ private RangeAllocationOutcome allocateRange(RangeAllocationRequest req) {
+ RangeAllocationOutcome out = new RangeAllocationOutcome();
+
+ out.request = req;
+
+ Resource r = resourceDao.getResource(req.assetId, req.resourceName);
+ if (r == null) {
+ r = new RangeResource();
+ r.resourceKey = new ResourceKey();
+ r.resourceKey.assetId = req.assetId;
+ r.resourceKey.resourceName = req.resourceName;
+ r.resourceType = ResourceType.Range;
+ } else {
+ if (r.resourceType != ResourceType.Range) {
+ out.status = AllocationStatus.ResourceNotFound;
+ return out;
+ }
+ RangeUtil.recalculate((RangeResource) r);
+ }
+
+ RangeResource rr = (RangeResource) r;
+ SortedSet<Integer> foundNumbers = null;
+ if (!req.check) {
+ out.status = AllocationStatus.Success;
+ foundNumbers = req.requestedNumbers;
+ } else {
+ if (req.requestedNumbers != null && req.requestedNumbers.size() > 0) {
+ foundNumbers = req.requestedNumbers;
+ out.status = AllocationStatus.Success;
+ for (int n : foundNumbers)
+ if (!RangeUtil.checkRange(rr, req, n)) {
+ out.status = AllocationStatus.Failure;
+ break;
+ }
+ } else {
+ foundNumbers = new TreeSet<Integer>();
+ int foundCount = 0;
+
+ // First try to reuse the numbers already taken by the same resource union
+ SortedSet<Integer> uu = RangeUtil.getUsed(rr, req.resourceUnionId);
+ if (uu != null && !uu.isEmpty()) {
+ if (uu.size() >= req.requestedCount) {
+ // Just take the first req.requestedCount numbers from uu
+ Iterator<Integer> i = uu.iterator();
+ while (foundCount < req.requestedCount) {
+ foundNumbers.add(i.next());
+ foundCount++;
+ }
+ } else {
+ // Additional numbers are requested. Try to find them starting from
+ // the minimum we have in uu (the first element) towards the min
+ // parameter, and then starting from the maximum in uu (the last
+ // element) towards the max parameter.
+ // NOTE: In case of request for sequential numbers, the parameters
+ // 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;
+ }
+ 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 we could not find enough numbers trying to reuse currently
+ // allocated, reset foundNumbers and foundCount, continue with
+ // the normal allocation of new numbers.
+ if (foundCount < req.requestedCount) {
+ foundNumbers = new TreeSet<Integer>();
+ foundCount = 0;
+ }
+ }
+ }
+
+ 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;
+
+ out.status = foundCount == req.requestedCount ? AllocationStatus.Success : AllocationStatus.Failure;
+ }
+ }
+
+ if (out.status == AllocationStatus.Success) {
+ out.allocated = foundNumbers;
+ if (req.allocate) {
+ RangeUtil.allocateRange(rr, out.allocated, req, applicationId);
+ updateList.add(rr);
+ }
+ } else
+ out.allocated = new TreeSet<Integer>();
+
+ out.used = rr.used;
+
+ return out;
+ }
+
+ public AllocationOutcome getAllocationOutcome() {
+ return outcome;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/comp/ReleaseFunction.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/comp/ReleaseFunction.java
index f546954ff..c8dab080b 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/comp/ReleaseFunction.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/comp/ReleaseFunction.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,52 +37,52 @@ import org.slf4j.LoggerFactory;
class ReleaseFunction extends SynchronizedFunction {
- @SuppressWarnings("unused")
- private static final Logger log = LoggerFactory.getLogger(ReleaseFunction.class);
+ @SuppressWarnings("unused")
+ private static final Logger log = LoggerFactory.getLogger(ReleaseFunction.class);
- private ResourceDao resourceDao;
+ private ResourceDao resourceDao;
- private String resourceSetId, resourceUnionId;
+ private String resourceSetId, resourceUnionId;
- public ReleaseFunction(LockHelper lockHelper, ResourceDao resourceDao, String resourceSetId,
- String resourceUnionId, Collection<String> lockNames, int lockTimeout) {
- super(lockHelper, lockNames, lockTimeout);
- this.resourceDao = resourceDao;
- this.resourceSetId = resourceSetId;
- this.resourceUnionId = resourceUnionId;
- }
+ public ReleaseFunction(LockHelper lockHelper, ResourceDao resourceDao, String resourceSetId,
+ String resourceUnionId, Collection<String> lockNames, int lockTimeout) {
+ super(lockHelper, lockNames, lockTimeout);
+ this.resourceDao = resourceDao;
+ this.resourceSetId = resourceSetId;
+ this.resourceUnionId = resourceUnionId;
+ }
- @Override
- public void _exec() throws ResourceLockedException {
- List<Resource> resourceList =
- resourceSetId != null
- ? resourceDao.getResourceSet(resourceSetId) : resourceDao.getResourceUnion(resourceUnionId);
- for (Resource r : resourceList) {
- boolean updated = false;
- if (r.allocationItems != null) {
- Iterator<AllocationItem> i = r.allocationItems.iterator();
- while (i.hasNext()) {
- AllocationItem ai = i.next();
- if (resourceSetId != null) {
- if (resourceSetId.equals(ai.resourceSetId)) {
- i.remove();
- updated = true;
- }
+ @Override
+ public void _exec() throws ResourceLockedException {
+ List<Resource> resourceList =
+ resourceSetId != null
+ ? resourceDao.getResourceSet(resourceSetId) : resourceDao.getResourceUnion(resourceUnionId);
+ for (Resource r : resourceList) {
+ boolean updated = false;
+ if (r.allocationItems != null) {
+ Iterator<AllocationItem> i = r.allocationItems.iterator();
+ while (i.hasNext()) {
+ AllocationItem ai = i.next();
+ if (resourceSetId != null) {
+ if (resourceSetId.equals(ai.resourceSetId)) {
+ i.remove();
+ updated = true;
+ }
- } else if (resourceUnionId != null) {
+ } else if (resourceUnionId != null) {
- if (resourceUnionId.equals(ai.resourceUnionId)) {
- i.remove();
- updated = true;
- }
+ if (resourceUnionId.equals(ai.resourceUnionId)) {
+ i.remove();
+ updated = true;
+ }
- }
- }
- }
- if (updated) {
- ResourceUtil.recalculate(r);
- resourceDao.saveResource(r);
- }
- }
- }
+ }
+ }
+ }
+ if (updated) {
+ ResourceUtil.recalculate(r);
+ resourceDao.saveResource(r);
+ }
+ }
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/comp/ResourceLoader.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/comp/ResourceLoader.java
index aea0b0a3c..d5bb9e471 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/comp/ResourceLoader.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/comp/ResourceLoader.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,13 +27,13 @@ import org.openecomp.sdnc.rm.data.Resource;
public interface ResourceLoader {
- void loadResource(String applicationId, Resource resource, boolean force);
+ void loadResource(String applicationId, Resource resource, boolean force);
- void loadResources(String applicationId, Collection<Resource> resourceList, boolean force);
+ void loadResources(String applicationId, Collection<Resource> resourceList, boolean force);
- void loadResourcesForAsset(String applicationId, String assetId, Collection<Resource> resourceList, boolean force);
+ void loadResourcesForAsset(String applicationId, String assetId, Collection<Resource> resourceList, boolean force);
- void deleteResource(String applicationId, String assetId, String resourceName);
+ void deleteResource(String applicationId, String assetId, String resourceName);
- void deleteResourcesForAsset(String applicationId, String assetId);
+ void deleteResourcesForAsset(String applicationId, String assetId);
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/comp/ResourceManager.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/comp/ResourceManager.java
index 7a3ce0343..737deb1cc 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/comp/ResourceManager.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/comp/ResourceManager.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,13 +29,13 @@ import org.openecomp.sdnc.rm.data.Resource;
public interface ResourceManager {
- Resource getResource(String resourceName, String assetId);
+ Resource getResource(String resourceName, String assetId);
- List<Resource> getResourceUnion(String resourceUnionId);
+ List<Resource> getResourceUnion(String resourceUnionId);
- AllocationOutcome allocateResources(AllocationRequest allocationRequest);
+ AllocationOutcome allocateResources(AllocationRequest allocationRequest);
- void releaseResourceSet(String resourceSetId);
+ void releaseResourceSet(String resourceSetId);
- void releaseResourceUnion(String resourceUnionId);
+ void releaseResourceUnion(String resourceUnionId);
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/comp/ResourceManagerImpl.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/comp/ResourceManagerImpl.java
index b9d5a0995..e70e06c23 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/comp/ResourceManagerImpl.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/comp/ResourceManagerImpl.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,92 +37,92 @@ import org.slf4j.LoggerFactory;
public class ResourceManagerImpl implements ResourceManager {
- private static final Logger log = LoggerFactory.getLogger(ResourceManagerImpl.class);
-
- private LockHelper lockHelper;
- private ResourceDao resourceDao;
-
- private String applicationId;
- private int lockTimeout = 10 * 60; // Default 10 min
-
- public ResourceManagerImpl() {
- log.info("ResourceManager created.");
- }
-
- @Override
- public Resource getResource(String resourceName, String assetId) {
- Resource r = resourceDao.getResource(assetId, resourceName);
- ResourceUtil.recalculate(r);
- return r;
- }
-
- @Override
- public List<Resource> getResourceUnion(String resourceUnionId) {
- List<Resource> rlist = resourceDao.getResourceUnion(resourceUnionId);
- for (Resource r : rlist)
- ResourceUtil.recalculate(r);
- return rlist;
- }
-
- @Override
- public AllocationOutcome allocateResources(AllocationRequest allocationRequest) {
- if (allocationRequest == null)
- throw new IllegalArgumentException("allocateResources called with null argument");
-
- AllocationFunction allocationFunction =
- new AllocationFunction(lockHelper, resourceDao, applicationId, allocationRequest, lockTimeout);
- allocationFunction.exec();
- AllocationOutcome allocationOutcome = allocationFunction.getAllocationOutcome();
-
- StrUtil.info(log, allocationOutcome);
-
- return allocationOutcome;
- }
-
- @Override
- public void releaseResourceSet(String resourceSetId) {
- List<Resource> resourceList = resourceDao.getResourceSet(resourceSetId);
- if (resourceList == null || resourceList.isEmpty())
- return;
-
- Set<String> lockNames = getLockNames(resourceList);
- ReleaseFunction releaseFunction =
- new ReleaseFunction(lockHelper, resourceDao, resourceSetId, null, lockNames, lockTimeout);
- releaseFunction.exec();
- }
-
- @Override
- public void releaseResourceUnion(String resourceUnionId) {
- List<Resource> resourceList = resourceDao.getResourceUnion(resourceUnionId);
- if (resourceList == null || resourceList.isEmpty())
- return;
-
- Set<String> lockNames = getLockNames(resourceList);
- ReleaseFunction releaseFunction =
- new ReleaseFunction(lockHelper, resourceDao, null, resourceUnionId, lockNames, lockTimeout);
- releaseFunction.exec();
- }
-
- private Set<String> getLockNames(List<Resource> resourceList) {
- Set<String> lockNames = new HashSet<String>();
- for (Resource r : resourceList)
- lockNames.add(r.resourceKey.assetId);
- return lockNames;
- }
-
- public void setResourceDao(ResourceDao resourceDao) {
- this.resourceDao = resourceDao;
- }
-
- public void setLockTimeout(int lockTimeout) {
- this.lockTimeout = lockTimeout;
- }
-
- public void setApplicationId(String applicationId) {
- this.applicationId = applicationId;
- }
-
- public void setLockHelper(LockHelper lockHelper) {
- this.lockHelper = lockHelper;
- }
+ private static final Logger log = LoggerFactory.getLogger(ResourceManagerImpl.class);
+
+ private LockHelper lockHelper;
+ private ResourceDao resourceDao;
+
+ private String applicationId;
+ private int lockTimeout = 10 * 60; // Default 10 min
+
+ public ResourceManagerImpl() {
+ log.info("ResourceManager created.");
+ }
+
+ @Override
+ public Resource getResource(String resourceName, String assetId) {
+ Resource r = resourceDao.getResource(assetId, resourceName);
+ ResourceUtil.recalculate(r);
+ return r;
+ }
+
+ @Override
+ public List<Resource> getResourceUnion(String resourceUnionId) {
+ List<Resource> rlist = resourceDao.getResourceUnion(resourceUnionId);
+ for (Resource r : rlist)
+ ResourceUtil.recalculate(r);
+ return rlist;
+ }
+
+ @Override
+ public AllocationOutcome allocateResources(AllocationRequest allocationRequest) {
+ if (allocationRequest == null)
+ throw new IllegalArgumentException("allocateResources called with null argument");
+
+ AllocationFunction allocationFunction =
+ new AllocationFunction(lockHelper, resourceDao, applicationId, allocationRequest, lockTimeout);
+ allocationFunction.exec();
+ AllocationOutcome allocationOutcome = allocationFunction.getAllocationOutcome();
+
+ StrUtil.info(log, allocationOutcome);
+
+ return allocationOutcome;
+ }
+
+ @Override
+ public void releaseResourceSet(String resourceSetId) {
+ List<Resource> resourceList = resourceDao.getResourceSet(resourceSetId);
+ if (resourceList == null || resourceList.isEmpty())
+ return;
+
+ Set<String> lockNames = getLockNames(resourceList);
+ ReleaseFunction releaseFunction =
+ new ReleaseFunction(lockHelper, resourceDao, resourceSetId, null, lockNames, lockTimeout);
+ releaseFunction.exec();
+ }
+
+ @Override
+ public void releaseResourceUnion(String resourceUnionId) {
+ List<Resource> resourceList = resourceDao.getResourceUnion(resourceUnionId);
+ if (resourceList == null || resourceList.isEmpty())
+ return;
+
+ Set<String> lockNames = getLockNames(resourceList);
+ ReleaseFunction releaseFunction =
+ new ReleaseFunction(lockHelper, resourceDao, null, resourceUnionId, lockNames, lockTimeout);
+ releaseFunction.exec();
+ }
+
+ private Set<String> getLockNames(List<Resource> resourceList) {
+ Set<String> lockNames = new HashSet<String>();
+ for (Resource r : resourceList)
+ lockNames.add(r.resourceKey.assetId);
+ return lockNames;
+ }
+
+ public void setResourceDao(ResourceDao resourceDao) {
+ this.resourceDao = resourceDao;
+ }
+
+ public void setLockTimeout(int lockTimeout) {
+ this.lockTimeout = lockTimeout;
+ }
+
+ public void setApplicationId(String applicationId) {
+ this.applicationId = applicationId;
+ }
+
+ public void setLockHelper(LockHelper lockHelper) {
+ this.lockHelper = lockHelper;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/ResourceDao.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/ResourceDao.java
index f499801c6..a116ef507 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/ResourceDao.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/ResourceDao.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,13 +27,13 @@ import org.openecomp.sdnc.rm.data.Resource;
public interface ResourceDao {
- Resource getResource(String assetId, String resourceName);
+ Resource getResource(String assetId, String resourceName);
- void saveResource(Resource resource);
+ void saveResource(Resource resource);
- void deleteResource(String assetId, String resourceName);
+ void deleteResource(String assetId, String resourceName);
- List<Resource> getResourceSet(String resourceSetId);
+ List<Resource> getResourceSet(String resourceSetId);
- List<Resource> getResourceUnion(String resourceUnionId);
+ List<Resource> getResourceUnion(String resourceUnionId);
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/AllocationItem.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/AllocationItem.java
index eb5f39885..7087c18fb 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/AllocationItem.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/AllocationItem.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,13 +25,13 @@ import java.util.Date;
public class AllocationItem {
- public long id;
- public long resourceId;
- public String applicationId;
- public String resourceSetId, resourceUnionId;
- public String resourceShareGroupList;
- public long ltUsed;
- public String llLabel;
- public String rrUsed;
- public Date allocationTime;
+ public long id;
+ public long resourceId;
+ public String applicationId;
+ public String resourceSetId, resourceUnionId;
+ public String resourceShareGroupList;
+ public long ltUsed;
+ public String llLabel;
+ public String rrUsed;
+ public Date allocationTime;
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/AllocationItemJdbcDao.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/AllocationItemJdbcDao.java
index 30f9d26a4..fe6199ea0 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/AllocationItemJdbcDao.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/AllocationItemJdbcDao.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,11 +25,11 @@ import java.util.List;
public interface AllocationItemJdbcDao {
- void add(AllocationItem ai);
+ void add(AllocationItem ai);
- List<AllocationItem> getAllocationItems(long resourceId);
+ List<AllocationItem> getAllocationItems(long resourceId);
- void update(AllocationItem ai);
+ void update(AllocationItem ai);
- void delete(long id);
+ void delete(long id);
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/AllocationItemJdbcDaoImpl.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/AllocationItemJdbcDaoImpl.java
index 1d88261c2..2710f358f 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/AllocationItemJdbcDaoImpl.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/AllocationItemJdbcDaoImpl.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,88 +39,88 @@ import org.springframework.jdbc.support.KeyHolder;
public class AllocationItemJdbcDaoImpl implements AllocationItemJdbcDao {
- @SuppressWarnings("unused")
- private static final Logger log = LoggerFactory.getLogger(ResourceJdbcDaoImpl.class);
-
- private static final String INSERT_SQL = "INSERT INTO ALLOCATION_ITEM (\n"
- + " resource_id, application_id, resource_set_id, resource_union_id, resource_share_group_list,\n"
- + " lt_used, ll_label, rr_used, allocation_time)\nVALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
-
- private static final String UPDATE_SQL = "UPDATE ALLOCATION_ITEM SET\n"
- + " resource_share_group_list = ?, lt_used = ?, ll_label = ?, rr_used = ?, allocation_time = ?\n"
- + "WHERE allocation_item_id = ?";
-
- private static final String DELETE_SQL = "DELETE FROM ALLOCATION_ITEM WHERE allocation_item_id = ?";
-
- private static final String GET_SQL = "SELECT * FROM ALLOCATION_ITEM WHERE resource_id = ?";
-
- private JdbcTemplate jdbcTemplate;
- private AllocationItemRowMapper allocationItemRowMapper = new AllocationItemRowMapper();
-
- @Override
- public void add(final AllocationItem ai) {
- PreparedStatementCreator psc = new PreparedStatementCreator() {
-
- @Override
- public PreparedStatement createPreparedStatement(Connection dbc) throws SQLException {
- PreparedStatement ps = dbc.prepareStatement(INSERT_SQL, new String[] { "allocation_item_id" });
- ps.setLong(1, ai.resourceId);
- ps.setString(2, ai.applicationId);
- ps.setString(3, ai.resourceSetId);
- ps.setString(4, ai.resourceUnionId);
- ps.setString(5, ai.resourceShareGroupList);
- ps.setLong(6, ai.ltUsed);
- ps.setString(7, ai.llLabel);
- ps.setString(8, ai.rrUsed);
- ps.setTimestamp(9, new Timestamp(ai.allocationTime.getTime()));
- return ps;
- }
- };
- KeyHolder keyHolder = new GeneratedKeyHolder();
- jdbcTemplate.update(psc, keyHolder);
- ai.id = keyHolder.getKey().longValue();
- }
-
- @Override
- public void update(AllocationItem ai) {
- Long ltUsed = ai.ltUsed <= 0 ? null : ai.ltUsed;
- jdbcTemplate.update(UPDATE_SQL, ai.resourceShareGroupList, ltUsed, ai.llLabel, ai.rrUsed, ai.allocationTime,
- ai.id);
- }
-
- @Override
- public void delete(long id) {
- jdbcTemplate.update(DELETE_SQL, id);
- }
-
- @Override
- public List<AllocationItem> getAllocationItems(long resourceId) {
- if (resourceId <= 0)
- return Collections.emptyList();
-
- return jdbcTemplate.query(GET_SQL, new Object[] { resourceId }, allocationItemRowMapper);
- }
-
- private static class AllocationItemRowMapper implements RowMapper<AllocationItem> {
-
- @Override
- public AllocationItem mapRow(ResultSet rs, int n) throws SQLException {
- AllocationItem ai = new AllocationItem();
- ai.id = rs.getLong("allocation_item_id");
- ai.resourceId = rs.getLong("resource_id");
- ai.applicationId = rs.getString("application_id");
- ai.resourceSetId = rs.getString("resource_set_id");
- ai.resourceUnionId = rs.getString("resource_union_id");
- ai.resourceShareGroupList = rs.getString("resource_share_group_list");
- ai.ltUsed = rs.getLong("lt_used");
- ai.llLabel = rs.getString("ll_label");
- ai.rrUsed = rs.getString("rr_used");
- ai.allocationTime = rs.getTimestamp("allocation_time");
- return ai;
- }
- }
-
- public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
- this.jdbcTemplate = jdbcTemplate;
- }
+ @SuppressWarnings("unused")
+ private static final Logger log = LoggerFactory.getLogger(ResourceJdbcDaoImpl.class);
+
+ private static final String INSERT_SQL = "INSERT INTO ALLOCATION_ITEM (\n"
+ + " resource_id, application_id, resource_set_id, resource_union_id, resource_share_group_list,\n"
+ + " lt_used, ll_label, rr_used, allocation_time)\nVALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
+
+ private static final String UPDATE_SQL = "UPDATE ALLOCATION_ITEM SET\n"
+ + " resource_share_group_list = ?, lt_used = ?, ll_label = ?, rr_used = ?, allocation_time = ?\n"
+ + "WHERE allocation_item_id = ?";
+
+ private static final String DELETE_SQL = "DELETE FROM ALLOCATION_ITEM WHERE allocation_item_id = ?";
+
+ private static final String GET_SQL = "SELECT * FROM ALLOCATION_ITEM WHERE resource_id = ?";
+
+ private JdbcTemplate jdbcTemplate;
+ private AllocationItemRowMapper allocationItemRowMapper = new AllocationItemRowMapper();
+
+ @Override
+ public void add(final AllocationItem ai) {
+ PreparedStatementCreator psc = new PreparedStatementCreator() {
+
+ @Override
+ public PreparedStatement createPreparedStatement(Connection dbc) throws SQLException {
+ PreparedStatement ps = dbc.prepareStatement(INSERT_SQL, new String[] { "allocation_item_id" });
+ ps.setLong(1, ai.resourceId);
+ ps.setString(2, ai.applicationId);
+ ps.setString(3, ai.resourceSetId);
+ ps.setString(4, ai.resourceUnionId);
+ ps.setString(5, ai.resourceShareGroupList);
+ ps.setLong(6, ai.ltUsed);
+ ps.setString(7, ai.llLabel);
+ ps.setString(8, ai.rrUsed);
+ ps.setTimestamp(9, new Timestamp(ai.allocationTime.getTime()));
+ return ps;
+ }
+ };
+ KeyHolder keyHolder = new GeneratedKeyHolder();
+ jdbcTemplate.update(psc, keyHolder);
+ ai.id = keyHolder.getKey().longValue();
+ }
+
+ @Override
+ public void update(AllocationItem ai) {
+ Long ltUsed = ai.ltUsed <= 0 ? null : ai.ltUsed;
+ jdbcTemplate.update(UPDATE_SQL, ai.resourceShareGroupList, ltUsed, ai.llLabel, ai.rrUsed, ai.allocationTime,
+ ai.id);
+ }
+
+ @Override
+ public void delete(long id) {
+ jdbcTemplate.update(DELETE_SQL, id);
+ }
+
+ @Override
+ public List<AllocationItem> getAllocationItems(long resourceId) {
+ if (resourceId <= 0)
+ return Collections.emptyList();
+
+ return jdbcTemplate.query(GET_SQL, new Object[] { resourceId }, allocationItemRowMapper);
+ }
+
+ private static class AllocationItemRowMapper implements RowMapper<AllocationItem> {
+
+ @Override
+ public AllocationItem mapRow(ResultSet rs, int n) throws SQLException {
+ AllocationItem ai = new AllocationItem();
+ ai.id = rs.getLong("allocation_item_id");
+ ai.resourceId = rs.getLong("resource_id");
+ ai.applicationId = rs.getString("application_id");
+ ai.resourceSetId = rs.getString("resource_set_id");
+ ai.resourceUnionId = rs.getString("resource_union_id");
+ ai.resourceShareGroupList = rs.getString("resource_share_group_list");
+ ai.ltUsed = rs.getLong("lt_used");
+ ai.llLabel = rs.getString("ll_label");
+ ai.rrUsed = rs.getString("rr_used");
+ ai.allocationTime = rs.getTimestamp("allocation_time");
+ return ai;
+ }
+ }
+
+ public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
+ this.jdbcTemplate = jdbcTemplate;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/Resource.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/Resource.java
index ca66964ce..4bbe2ebd6 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/Resource.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/Resource.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,10 +23,10 @@ package org.openecomp.sdnc.rm.dao.jdbc;
public class Resource {
- public long id;
- public String assetId, name, type;
- public long ltUsed;
- public String llLabel;
- public int llReferenceCount;
- public String rrUsed;
+ public long id;
+ public String assetId, name, type;
+ public long ltUsed;
+ public String llLabel;
+ public int llReferenceCount;
+ public String rrUsed;
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/ResourceDaoImpl.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/ResourceDaoImpl.java
index 32c8f4d7f..cbae3d20e 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/ResourceDaoImpl.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/ResourceDaoImpl.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,333 +38,333 @@ import org.openecomp.sdnc.util.str.StrUtil;
public class ResourceDaoImpl implements ResourceDao {
- private ResourceJdbcDao resourceJdbcDao;
- private ResourceLoadJdbcDao resourceLoadJdbcDao;
- private AllocationItemJdbcDao allocationItemJdbcDao;
-
- @Override
- public org.openecomp.sdnc.rm.data.Resource getResource(String assetId, String resourceName) {
- Resource rEntity = resourceJdbcDao.getResource(assetId, resourceName);
- org.openecomp.sdnc.rm.data.Resource r = createResource(rEntity);
-
- if (r != null) {
- List<AllocationItem> aiEntityList = allocationItemJdbcDao.getAllocationItems(rEntity.id);
- r.allocationItems = new ArrayList<org.openecomp.sdnc.rm.data.AllocationItem>();
- for (AllocationItem aiEntity : aiEntityList) {
- org.openecomp.sdnc.rm.data.AllocationItem ai = createAllocationItem(r, aiEntity);
- r.allocationItems.add(ai);
- }
-
- List<ResourceLoad> rlEntityList = resourceLoadJdbcDao.getResourceLoads(rEntity.id);
- r.resourceLoadList = new ArrayList<org.openecomp.sdnc.rm.data.ResourceLoad>();
- for (ResourceLoad rlEntity : rlEntityList) {
- org.openecomp.sdnc.rm.data.ResourceLoad rl = createResourceLoad(r, rlEntity);
- r.resourceLoadList.add(rl);
- }
- }
-
- return r;
- }
-
- @Override
- public void saveResource(org.openecomp.sdnc.rm.data.Resource resource) {
- if (resource == null)
- return;
-
- org.openecomp.sdnc.rm.dao.jdbc.Resource resourceEntity =
- resourceJdbcDao.getResource(resource.resourceKey.assetId, resource.resourceKey.resourceName);
- if (resourceEntity == null) {
- resourceEntity = createResourceEntity(resource);
- resourceJdbcDao.add(resourceEntity);
- if (resource.allocationItems != null)
- for (org.openecomp.sdnc.rm.data.AllocationItem ai : resource.allocationItems) {
- AllocationItem aiEntity = createAllocationItemEntity(resourceEntity.id, ai);
- allocationItemJdbcDao.add(aiEntity);
- }
- if (resource.resourceLoadList != null)
- for (org.openecomp.sdnc.rm.data.ResourceLoad rl : resource.resourceLoadList) {
- ResourceLoad rlEntity = createResourceLoadEntity(resourceEntity.id, rl);
- resourceLoadJdbcDao.add(rlEntity);
- }
- } else {
- updateResourceEntity(resourceEntity, resource);
- resourceJdbcDao.update(resourceEntity);
-
- List<AllocationItem> oldAiEntityList = allocationItemJdbcDao.getAllocationItems(resourceEntity.id);
- if (resource.allocationItems != null)
- for (org.openecomp.sdnc.rm.data.AllocationItem newai : resource.allocationItems) {
- AllocationItem foundAiEntity = null;
- for (AllocationItem oldAiEntity : oldAiEntityList)
- if (oldAiEntity.resourceSetId.equals(newai.resourceSetId)) {
- foundAiEntity = oldAiEntity;
- break;
- }
- if (foundAiEntity != null) {
- updateAllocationItemEntity(foundAiEntity, newai);
- allocationItemJdbcDao.update(foundAiEntity);
- } else {
- AllocationItem newAiEntity = createAllocationItemEntity(resourceEntity.id, newai);
- allocationItemJdbcDao.add(newAiEntity);
- }
- }
- for (AllocationItem oldAiEntity : oldAiEntityList) {
- boolean found = false;
- if (resource.allocationItems != null)
- for (org.openecomp.sdnc.rm.data.AllocationItem newai : resource.allocationItems)
- if (oldAiEntity.resourceSetId.equals(newai.resourceSetId)) {
- found = true;
- break;
- }
- if (!found)
- allocationItemJdbcDao.delete(oldAiEntity.id);
- }
-
- List<ResourceLoad> oldRlEntityList = resourceLoadJdbcDao.getResourceLoads(resourceEntity.id);
- if (resource.resourceLoadList != null)
- for (org.openecomp.sdnc.rm.data.ResourceLoad newrl : resource.resourceLoadList) {
- ResourceLoad foundRlEntity = null;
- for (ResourceLoad oldRlEntity : oldRlEntityList)
- if (oldRlEntity.applicationId.equals(newrl.applicationId)) {
- foundRlEntity = oldRlEntity;
- break;
- }
- if (foundRlEntity != null) {
- updateResourceLoadEntity(foundRlEntity, newrl);
- resourceLoadJdbcDao.update(foundRlEntity);
- } else {
- ResourceLoad newRlEntity = createResourceLoadEntity(resourceEntity.id, newrl);
- resourceLoadJdbcDao.add(newRlEntity);
- }
- }
- for (ResourceLoad oldRlEntity : oldRlEntityList) {
- boolean found = false;
- if (resource.resourceLoadList != null)
- for (org.openecomp.sdnc.rm.data.ResourceLoad newrl : resource.resourceLoadList)
- if (oldRlEntity.applicationId.equals(newrl.applicationId)) {
- found = true;
- break;
- }
- if (!found)
- resourceLoadJdbcDao.delete(oldRlEntity.id);
- }
- }
- }
-
- @Override
- public void deleteResource(String assetId, String resourceName) {
- org.openecomp.sdnc.rm.dao.jdbc.Resource resourceEntity = resourceJdbcDao.getResource(assetId, resourceName);
- if (resourceEntity != null)
- resourceJdbcDao.delete(resourceEntity.id);
- }
-
- @Override
- public List<org.openecomp.sdnc.rm.data.Resource> getResourceSet(String resourceSetId) {
- List<Resource> rEntityList = resourceJdbcDao.getResourceSet(resourceSetId);
- List<org.openecomp.sdnc.rm.data.Resource> rlist = new ArrayList<org.openecomp.sdnc.rm.data.Resource>();
- for (Resource rEntity : rEntityList) {
- org.openecomp.sdnc.rm.data.Resource r = createResource(rEntity);
- rlist.add(r);
-
- List<AllocationItem> aiEntityList = allocationItemJdbcDao.getAllocationItems(rEntity.id);
- r.allocationItems = new ArrayList<org.openecomp.sdnc.rm.data.AllocationItem>();
- for (AllocationItem aiEntity : aiEntityList) {
- org.openecomp.sdnc.rm.data.AllocationItem ai = createAllocationItem(r, aiEntity);
- r.allocationItems.add(ai);
- }
-
- List<ResourceLoad> rlEntityList = resourceLoadJdbcDao.getResourceLoads(rEntity.id);
- r.resourceLoadList = new ArrayList<org.openecomp.sdnc.rm.data.ResourceLoad>();
- for (ResourceLoad rlEntity : rlEntityList) {
- org.openecomp.sdnc.rm.data.ResourceLoad rl = createResourceLoad(r, rlEntity);
- r.resourceLoadList.add(rl);
- }
- }
- return rlist;
- }
-
- @Override
- public List<org.openecomp.sdnc.rm.data.Resource> getResourceUnion(String resourceUnionId) {
- List<Resource> rEntityList = resourceJdbcDao.getResourceUnion(resourceUnionId);
- List<org.openecomp.sdnc.rm.data.Resource> rlist = new ArrayList<org.openecomp.sdnc.rm.data.Resource>();
- for (Resource rEntity : rEntityList) {
- org.openecomp.sdnc.rm.data.Resource r = createResource(rEntity);
- rlist.add(r);
-
- List<AllocationItem> aiEntityList = allocationItemJdbcDao.getAllocationItems(rEntity.id);
- r.allocationItems = new ArrayList<org.openecomp.sdnc.rm.data.AllocationItem>();
- for (AllocationItem aiEntity : aiEntityList) {
- org.openecomp.sdnc.rm.data.AllocationItem ai = createAllocationItem(r, aiEntity);
- r.allocationItems.add(ai);
- }
-
- List<ResourceLoad> rlEntityList = resourceLoadJdbcDao.getResourceLoads(rEntity.id);
- r.resourceLoadList = new ArrayList<org.openecomp.sdnc.rm.data.ResourceLoad>();
- for (ResourceLoad rlEntity : rlEntityList) {
- org.openecomp.sdnc.rm.data.ResourceLoad rl = createResourceLoad(r, rlEntity);
- r.resourceLoadList.add(rl);
- }
- }
- return rlist;
- }
-
- private Resource createResourceEntity(org.openecomp.sdnc.rm.data.Resource resource) {
- Resource resourceEntity = new Resource();
- resourceEntity.assetId = resource.resourceKey.assetId;
- resourceEntity.name = resource.resourceKey.resourceName;
- resourceEntity.type = resource.resourceType.toString();
- if (resource.resourceType == ResourceType.Limit)
- resourceEntity.ltUsed = ((LimitResource) resource).used;
- else if (resource.resourceType == ResourceType.Label) {
- resourceEntity.llLabel = ((LabelResource) resource).label;
- resourceEntity.llReferenceCount = ((LabelResource) resource).referenceCount;
- } else if (resource.resourceType == ResourceType.Range)
- resourceEntity.rrUsed = StrUtil.listInt(((RangeResource) resource).used);
-
- return resourceEntity;
- }
-
- private ResourceLoad createResourceLoadEntity(long resourceId, org.openecomp.sdnc.rm.data.ResourceLoad rl) {
- ResourceLoad rlEntity = new ResourceLoad();
- rlEntity.resourceId = resourceId;
- rlEntity.applicationId = rl.applicationId;
- rlEntity.loadTime = rl.resourceLoadTime;
- rlEntity.expirationTime = rl.resourceExpirationTime;
- return rlEntity;
- }
-
- private void updateResourceLoadEntity(ResourceLoad rlEntity, org.openecomp.sdnc.rm.data.ResourceLoad rl) {
- rlEntity.loadTime = rl.resourceLoadTime;
- rlEntity.expirationTime = rl.resourceExpirationTime;
- }
-
- private AllocationItem createAllocationItemEntity(long resourceId, org.openecomp.sdnc.rm.data.AllocationItem ai) {
- AllocationItem aiEntity = new AllocationItem();
- aiEntity.resourceId = resourceId;
- aiEntity.resourceSetId = ai.resourceSetId;
- aiEntity.resourceUnionId = ai.resourceUnionId;
- aiEntity.resourceShareGroupList = StrUtil.listStr(ai.resourceShareGroupList);
- aiEntity.applicationId = ai.applicationId;
- aiEntity.allocationTime = ai.allocationTime;
- if (ai.resourceType == ResourceType.Limit)
- aiEntity.ltUsed = ((LimitAllocationItem) ai).used;
- else if (ai.resourceType == ResourceType.Label)
- aiEntity.llLabel = ((LabelAllocationItem) ai).label;
- else if (ai.resourceType == ResourceType.Range)
- aiEntity.rrUsed = StrUtil.listInt(((RangeAllocationItem) ai).used);
- return aiEntity;
- }
-
- private void updateAllocationItemEntity(AllocationItem aiEntity, org.openecomp.sdnc.rm.data.AllocationItem ai) {
- aiEntity.resourceShareGroupList = StrUtil.listStr(ai.resourceShareGroupList);
- aiEntity.allocationTime = ai.allocationTime;
- if (ai.resourceType == ResourceType.Limit)
- aiEntity.ltUsed = ((LimitAllocationItem) ai).used;
- else if (ai.resourceType == ResourceType.Label)
- aiEntity.llLabel = ((LabelAllocationItem) ai).label;
- else if (ai.resourceType == ResourceType.Range)
- aiEntity.rrUsed = StrUtil.listInt(((RangeAllocationItem) ai).used);
- }
-
- private void updateResourceEntity(Resource resourceEntity, org.openecomp.sdnc.rm.data.Resource resource) {
- if (resource.resourceType == ResourceType.Limit)
- resourceEntity.ltUsed = ((LimitResource) resource).used;
- else if (resource.resourceType == ResourceType.Label) {
- resourceEntity.llLabel = ((LabelResource) resource).label;
- resourceEntity.llReferenceCount = ((LabelResource) resource).referenceCount;
- } else if (resource.resourceType == ResourceType.Range)
- resourceEntity.rrUsed = StrUtil.listInt(((RangeResource) resource).used);
- }
-
- private org.openecomp.sdnc.rm.data.Resource createResource(Resource resourceEntity) {
- if (resourceEntity == null)
- return null;
-
- org.openecomp.sdnc.rm.data.Resource r = null;
- ResourceType type = ResourceType.valueOf(resourceEntity.type);
- if (type == ResourceType.Limit) {
- LimitResource l = new LimitResource();
- l.used = resourceEntity.ltUsed;
- r = l;
- } else if (type == ResourceType.Label) {
- LabelResource l = new LabelResource();
- l.label = resourceEntity.llLabel;
- l.referenceCount = resourceEntity.llReferenceCount;
- r = l;
- } else if (type == ResourceType.Range) {
- RangeResource rr = new RangeResource();
- rr.used =
- StrUtil.listInt(resourceEntity.rrUsed, "Invalid data found in DB in for Resource Id: " +
- resourceEntity.id + ": RESOURCE.RR_USED: " + resourceEntity.rrUsed);
- r = rr;
- }
-
- r.resourceType = type;
- r.resourceKey = new ResourceKey();
- r.resourceKey.assetId = resourceEntity.assetId;
- r.resourceKey.resourceName = resourceEntity.name;
-
- return r;
- }
-
- private org.openecomp.sdnc.rm.data.AllocationItem createAllocationItem(
- org.openecomp.sdnc.rm.data.Resource r,
- AllocationItem aiEntity) {
- if (r == null || aiEntity == null)
- return null;
-
- org.openecomp.sdnc.rm.data.AllocationItem ai = null;
- if (r.resourceType == ResourceType.Limit) {
- LimitAllocationItem lai = new LimitAllocationItem();
- lai.used = aiEntity.ltUsed;
- ai = lai;
- } else if (r.resourceType == ResourceType.Label) {
- LabelAllocationItem lai = new LabelAllocationItem();
- lai.label = aiEntity.llLabel;
- ai = lai;
- } else if (r.resourceType == ResourceType.Range) {
- RangeAllocationItem rai = new RangeAllocationItem();
- rai.used =
- StrUtil.listInt(aiEntity.rrUsed, "Invalid data found in DB in for Allocation Item Id: " +
- aiEntity.id + ": ALLOCATION_ITEM.RR_USED: " + aiEntity.rrUsed);
- ai = rai;
- }
-
- ai.resourceType = r.resourceType;
- ai.resourceKey = r.resourceKey;
- ai.resourceSetId = aiEntity.resourceSetId;
- ai.resourceUnionId = aiEntity.resourceUnionId;
- if (aiEntity.resourceShareGroupList != null)
- ai.resourceShareGroupList = new HashSet<String>(StrUtil.listStr(aiEntity.resourceShareGroupList));
- ai.applicationId = aiEntity.applicationId;
- ai.allocationTime = aiEntity.allocationTime;
-
- return ai;
- }
-
- private org.openecomp.sdnc.rm.data.ResourceLoad createResourceLoad(
- org.openecomp.sdnc.rm.data.Resource r,
- ResourceLoad rlEntity) {
- if (rlEntity == null)
- return null;
-
- org.openecomp.sdnc.rm.data.ResourceLoad rl = new org.openecomp.sdnc.rm.data.ResourceLoad();
- rl.resourceKey = r.resourceKey;
- rl.applicationId = rlEntity.applicationId;
- rl.resourceLoadTime = rlEntity.loadTime;
- rl.resourceExpirationTime = rlEntity.expirationTime;
-
- return rl;
- }
-
- public void setResourceJdbcDao(ResourceJdbcDao resourceJdbcDao) {
- this.resourceJdbcDao = resourceJdbcDao;
- }
-
- public void setResourceLoadJdbcDao(ResourceLoadJdbcDao resourceLoadJdbcDao) {
- this.resourceLoadJdbcDao = resourceLoadJdbcDao;
- }
-
- public void setAllocationItemJdbcDao(AllocationItemJdbcDao allocationItemJdbcDao) {
- this.allocationItemJdbcDao = allocationItemJdbcDao;
- }
+ private ResourceJdbcDao resourceJdbcDao;
+ private ResourceLoadJdbcDao resourceLoadJdbcDao;
+ private AllocationItemJdbcDao allocationItemJdbcDao;
+
+ @Override
+ public org.openecomp.sdnc.rm.data.Resource getResource(String assetId, String resourceName) {
+ Resource rEntity = resourceJdbcDao.getResource(assetId, resourceName);
+ org.openecomp.sdnc.rm.data.Resource r = createResource(rEntity);
+
+ if (r != null) {
+ List<AllocationItem> aiEntityList = allocationItemJdbcDao.getAllocationItems(rEntity.id);
+ r.allocationItems = new ArrayList<org.openecomp.sdnc.rm.data.AllocationItem>();
+ for (AllocationItem aiEntity : aiEntityList) {
+ org.openecomp.sdnc.rm.data.AllocationItem ai = createAllocationItem(r, aiEntity);
+ r.allocationItems.add(ai);
+ }
+
+ List<ResourceLoad> rlEntityList = resourceLoadJdbcDao.getResourceLoads(rEntity.id);
+ r.resourceLoadList = new ArrayList<org.openecomp.sdnc.rm.data.ResourceLoad>();
+ for (ResourceLoad rlEntity : rlEntityList) {
+ org.openecomp.sdnc.rm.data.ResourceLoad rl = createResourceLoad(r, rlEntity);
+ r.resourceLoadList.add(rl);
+ }
+ }
+
+ return r;
+ }
+
+ @Override
+ public void saveResource(org.openecomp.sdnc.rm.data.Resource resource) {
+ if (resource == null)
+ return;
+
+ org.openecomp.sdnc.rm.dao.jdbc.Resource resourceEntity =
+ resourceJdbcDao.getResource(resource.resourceKey.assetId, resource.resourceKey.resourceName);
+ if (resourceEntity == null) {
+ resourceEntity = createResourceEntity(resource);
+ resourceJdbcDao.add(resourceEntity);
+ if (resource.allocationItems != null)
+ for (org.openecomp.sdnc.rm.data.AllocationItem ai : resource.allocationItems) {
+ AllocationItem aiEntity = createAllocationItemEntity(resourceEntity.id, ai);
+ allocationItemJdbcDao.add(aiEntity);
+ }
+ if (resource.resourceLoadList != null)
+ for (org.openecomp.sdnc.rm.data.ResourceLoad rl : resource.resourceLoadList) {
+ ResourceLoad rlEntity = createResourceLoadEntity(resourceEntity.id, rl);
+ resourceLoadJdbcDao.add(rlEntity);
+ }
+ } else {
+ updateResourceEntity(resourceEntity, resource);
+ resourceJdbcDao.update(resourceEntity);
+
+ List<AllocationItem> oldAiEntityList = allocationItemJdbcDao.getAllocationItems(resourceEntity.id);
+ if (resource.allocationItems != null)
+ for (org.openecomp.sdnc.rm.data.AllocationItem newai : resource.allocationItems) {
+ AllocationItem foundAiEntity = null;
+ for (AllocationItem oldAiEntity : oldAiEntityList)
+ if (oldAiEntity.resourceSetId.equals(newai.resourceSetId)) {
+ foundAiEntity = oldAiEntity;
+ break;
+ }
+ if (foundAiEntity != null) {
+ updateAllocationItemEntity(foundAiEntity, newai);
+ allocationItemJdbcDao.update(foundAiEntity);
+ } else {
+ AllocationItem newAiEntity = createAllocationItemEntity(resourceEntity.id, newai);
+ allocationItemJdbcDao.add(newAiEntity);
+ }
+ }
+ for (AllocationItem oldAiEntity : oldAiEntityList) {
+ boolean found = false;
+ if (resource.allocationItems != null)
+ for (org.openecomp.sdnc.rm.data.AllocationItem newai : resource.allocationItems)
+ if (oldAiEntity.resourceSetId.equals(newai.resourceSetId)) {
+ found = true;
+ break;
+ }
+ if (!found)
+ allocationItemJdbcDao.delete(oldAiEntity.id);
+ }
+
+ List<ResourceLoad> oldRlEntityList = resourceLoadJdbcDao.getResourceLoads(resourceEntity.id);
+ if (resource.resourceLoadList != null)
+ for (org.openecomp.sdnc.rm.data.ResourceLoad newrl : resource.resourceLoadList) {
+ ResourceLoad foundRlEntity = null;
+ for (ResourceLoad oldRlEntity : oldRlEntityList)
+ if (oldRlEntity.applicationId.equals(newrl.applicationId)) {
+ foundRlEntity = oldRlEntity;
+ break;
+ }
+ if (foundRlEntity != null) {
+ updateResourceLoadEntity(foundRlEntity, newrl);
+ resourceLoadJdbcDao.update(foundRlEntity);
+ } else {
+ ResourceLoad newRlEntity = createResourceLoadEntity(resourceEntity.id, newrl);
+ resourceLoadJdbcDao.add(newRlEntity);
+ }
+ }
+ for (ResourceLoad oldRlEntity : oldRlEntityList) {
+ boolean found = false;
+ if (resource.resourceLoadList != null)
+ for (org.openecomp.sdnc.rm.data.ResourceLoad newrl : resource.resourceLoadList)
+ if (oldRlEntity.applicationId.equals(newrl.applicationId)) {
+ found = true;
+ break;
+ }
+ if (!found)
+ resourceLoadJdbcDao.delete(oldRlEntity.id);
+ }
+ }
+ }
+
+ @Override
+ public void deleteResource(String assetId, String resourceName) {
+ org.openecomp.sdnc.rm.dao.jdbc.Resource resourceEntity = resourceJdbcDao.getResource(assetId, resourceName);
+ if (resourceEntity != null)
+ resourceJdbcDao.delete(resourceEntity.id);
+ }
+
+ @Override
+ public List<org.openecomp.sdnc.rm.data.Resource> getResourceSet(String resourceSetId) {
+ List<Resource> rEntityList = resourceJdbcDao.getResourceSet(resourceSetId);
+ List<org.openecomp.sdnc.rm.data.Resource> rlist = new ArrayList<org.openecomp.sdnc.rm.data.Resource>();
+ for (Resource rEntity : rEntityList) {
+ org.openecomp.sdnc.rm.data.Resource r = createResource(rEntity);
+ rlist.add(r);
+
+ List<AllocationItem> aiEntityList = allocationItemJdbcDao.getAllocationItems(rEntity.id);
+ r.allocationItems = new ArrayList<org.openecomp.sdnc.rm.data.AllocationItem>();
+ for (AllocationItem aiEntity : aiEntityList) {
+ org.openecomp.sdnc.rm.data.AllocationItem ai = createAllocationItem(r, aiEntity);
+ r.allocationItems.add(ai);
+ }
+
+ List<ResourceLoad> rlEntityList = resourceLoadJdbcDao.getResourceLoads(rEntity.id);
+ r.resourceLoadList = new ArrayList<org.openecomp.sdnc.rm.data.ResourceLoad>();
+ for (ResourceLoad rlEntity : rlEntityList) {
+ org.openecomp.sdnc.rm.data.ResourceLoad rl = createResourceLoad(r, rlEntity);
+ r.resourceLoadList.add(rl);
+ }
+ }
+ return rlist;
+ }
+
+ @Override
+ public List<org.openecomp.sdnc.rm.data.Resource> getResourceUnion(String resourceUnionId) {
+ List<Resource> rEntityList = resourceJdbcDao.getResourceUnion(resourceUnionId);
+ List<org.openecomp.sdnc.rm.data.Resource> rlist = new ArrayList<org.openecomp.sdnc.rm.data.Resource>();
+ for (Resource rEntity : rEntityList) {
+ org.openecomp.sdnc.rm.data.Resource r = createResource(rEntity);
+ rlist.add(r);
+
+ List<AllocationItem> aiEntityList = allocationItemJdbcDao.getAllocationItems(rEntity.id);
+ r.allocationItems = new ArrayList<org.openecomp.sdnc.rm.data.AllocationItem>();
+ for (AllocationItem aiEntity : aiEntityList) {
+ org.openecomp.sdnc.rm.data.AllocationItem ai = createAllocationItem(r, aiEntity);
+ r.allocationItems.add(ai);
+ }
+
+ List<ResourceLoad> rlEntityList = resourceLoadJdbcDao.getResourceLoads(rEntity.id);
+ r.resourceLoadList = new ArrayList<org.openecomp.sdnc.rm.data.ResourceLoad>();
+ for (ResourceLoad rlEntity : rlEntityList) {
+ org.openecomp.sdnc.rm.data.ResourceLoad rl = createResourceLoad(r, rlEntity);
+ r.resourceLoadList.add(rl);
+ }
+ }
+ return rlist;
+ }
+
+ private Resource createResourceEntity(org.openecomp.sdnc.rm.data.Resource resource) {
+ Resource resourceEntity = new Resource();
+ resourceEntity.assetId = resource.resourceKey.assetId;
+ resourceEntity.name = resource.resourceKey.resourceName;
+ resourceEntity.type = resource.resourceType.toString();
+ if (resource.resourceType == ResourceType.Limit)
+ resourceEntity.ltUsed = ((LimitResource) resource).used;
+ else if (resource.resourceType == ResourceType.Label) {
+ resourceEntity.llLabel = ((LabelResource) resource).label;
+ resourceEntity.llReferenceCount = ((LabelResource) resource).referenceCount;
+ } else if (resource.resourceType == ResourceType.Range)
+ resourceEntity.rrUsed = StrUtil.listInt(((RangeResource) resource).used);
+
+ return resourceEntity;
+ }
+
+ private ResourceLoad createResourceLoadEntity(long resourceId, org.openecomp.sdnc.rm.data.ResourceLoad rl) {
+ ResourceLoad rlEntity = new ResourceLoad();
+ rlEntity.resourceId = resourceId;
+ rlEntity.applicationId = rl.applicationId;
+ rlEntity.loadTime = rl.resourceLoadTime;
+ rlEntity.expirationTime = rl.resourceExpirationTime;
+ return rlEntity;
+ }
+
+ private void updateResourceLoadEntity(ResourceLoad rlEntity, org.openecomp.sdnc.rm.data.ResourceLoad rl) {
+ rlEntity.loadTime = rl.resourceLoadTime;
+ rlEntity.expirationTime = rl.resourceExpirationTime;
+ }
+
+ private AllocationItem createAllocationItemEntity(long resourceId, org.openecomp.sdnc.rm.data.AllocationItem ai) {
+ AllocationItem aiEntity = new AllocationItem();
+ aiEntity.resourceId = resourceId;
+ aiEntity.resourceSetId = ai.resourceSetId;
+ aiEntity.resourceUnionId = ai.resourceUnionId;
+ aiEntity.resourceShareGroupList = StrUtil.listStr(ai.resourceShareGroupList);
+ aiEntity.applicationId = ai.applicationId;
+ aiEntity.allocationTime = ai.allocationTime;
+ if (ai.resourceType == ResourceType.Limit)
+ aiEntity.ltUsed = ((LimitAllocationItem) ai).used;
+ else if (ai.resourceType == ResourceType.Label)
+ aiEntity.llLabel = ((LabelAllocationItem) ai).label;
+ else if (ai.resourceType == ResourceType.Range)
+ aiEntity.rrUsed = StrUtil.listInt(((RangeAllocationItem) ai).used);
+ return aiEntity;
+ }
+
+ private void updateAllocationItemEntity(AllocationItem aiEntity, org.openecomp.sdnc.rm.data.AllocationItem ai) {
+ aiEntity.resourceShareGroupList = StrUtil.listStr(ai.resourceShareGroupList);
+ aiEntity.allocationTime = ai.allocationTime;
+ if (ai.resourceType == ResourceType.Limit)
+ aiEntity.ltUsed = ((LimitAllocationItem) ai).used;
+ else if (ai.resourceType == ResourceType.Label)
+ aiEntity.llLabel = ((LabelAllocationItem) ai).label;
+ else if (ai.resourceType == ResourceType.Range)
+ aiEntity.rrUsed = StrUtil.listInt(((RangeAllocationItem) ai).used);
+ }
+
+ private void updateResourceEntity(Resource resourceEntity, org.openecomp.sdnc.rm.data.Resource resource) {
+ if (resource.resourceType == ResourceType.Limit)
+ resourceEntity.ltUsed = ((LimitResource) resource).used;
+ else if (resource.resourceType == ResourceType.Label) {
+ resourceEntity.llLabel = ((LabelResource) resource).label;
+ resourceEntity.llReferenceCount = ((LabelResource) resource).referenceCount;
+ } else if (resource.resourceType == ResourceType.Range)
+ resourceEntity.rrUsed = StrUtil.listInt(((RangeResource) resource).used);
+ }
+
+ private org.openecomp.sdnc.rm.data.Resource createResource(Resource resourceEntity) {
+ if (resourceEntity == null)
+ return null;
+
+ org.openecomp.sdnc.rm.data.Resource r = null;
+ ResourceType type = ResourceType.valueOf(resourceEntity.type);
+ if (type == ResourceType.Limit) {
+ LimitResource l = new LimitResource();
+ l.used = resourceEntity.ltUsed;
+ r = l;
+ } else if (type == ResourceType.Label) {
+ LabelResource l = new LabelResource();
+ l.label = resourceEntity.llLabel;
+ l.referenceCount = resourceEntity.llReferenceCount;
+ r = l;
+ } else if (type == ResourceType.Range) {
+ RangeResource rr = new RangeResource();
+ rr.used =
+ StrUtil.listInt(resourceEntity.rrUsed, "Invalid data found in DB in for Resource Id: " +
+ resourceEntity.id + ": RESOURCE.RR_USED: " + resourceEntity.rrUsed);
+ r = rr;
+ }
+
+ r.resourceType = type;
+ r.resourceKey = new ResourceKey();
+ r.resourceKey.assetId = resourceEntity.assetId;
+ r.resourceKey.resourceName = resourceEntity.name;
+
+ return r;
+ }
+
+ private org.openecomp.sdnc.rm.data.AllocationItem createAllocationItem(
+ org.openecomp.sdnc.rm.data.Resource r,
+ AllocationItem aiEntity) {
+ if (r == null || aiEntity == null)
+ return null;
+
+ org.openecomp.sdnc.rm.data.AllocationItem ai = null;
+ if (r.resourceType == ResourceType.Limit) {
+ LimitAllocationItem lai = new LimitAllocationItem();
+ lai.used = aiEntity.ltUsed;
+ ai = lai;
+ } else if (r.resourceType == ResourceType.Label) {
+ LabelAllocationItem lai = new LabelAllocationItem();
+ lai.label = aiEntity.llLabel;
+ ai = lai;
+ } else if (r.resourceType == ResourceType.Range) {
+ RangeAllocationItem rai = new RangeAllocationItem();
+ rai.used =
+ StrUtil.listInt(aiEntity.rrUsed, "Invalid data found in DB in for Allocation Item Id: " +
+ aiEntity.id + ": ALLOCATION_ITEM.RR_USED: " + aiEntity.rrUsed);
+ ai = rai;
+ }
+
+ ai.resourceType = r.resourceType;
+ ai.resourceKey = r.resourceKey;
+ ai.resourceSetId = aiEntity.resourceSetId;
+ ai.resourceUnionId = aiEntity.resourceUnionId;
+ if (aiEntity.resourceShareGroupList != null)
+ ai.resourceShareGroupList = new HashSet<String>(StrUtil.listStr(aiEntity.resourceShareGroupList));
+ ai.applicationId = aiEntity.applicationId;
+ ai.allocationTime = aiEntity.allocationTime;
+
+ return ai;
+ }
+
+ private org.openecomp.sdnc.rm.data.ResourceLoad createResourceLoad(
+ org.openecomp.sdnc.rm.data.Resource r,
+ ResourceLoad rlEntity) {
+ if (rlEntity == null)
+ return null;
+
+ org.openecomp.sdnc.rm.data.ResourceLoad rl = new org.openecomp.sdnc.rm.data.ResourceLoad();
+ rl.resourceKey = r.resourceKey;
+ rl.applicationId = rlEntity.applicationId;
+ rl.resourceLoadTime = rlEntity.loadTime;
+ rl.resourceExpirationTime = rlEntity.expirationTime;
+
+ return rl;
+ }
+
+ public void setResourceJdbcDao(ResourceJdbcDao resourceJdbcDao) {
+ this.resourceJdbcDao = resourceJdbcDao;
+ }
+
+ public void setResourceLoadJdbcDao(ResourceLoadJdbcDao resourceLoadJdbcDao) {
+ this.resourceLoadJdbcDao = resourceLoadJdbcDao;
+ }
+
+ public void setAllocationItemJdbcDao(AllocationItemJdbcDao allocationItemJdbcDao) {
+ this.allocationItemJdbcDao = allocationItemJdbcDao;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/ResourceJdbcDao.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/ResourceJdbcDao.java
index 645c377e7..5ed07b256 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/ResourceJdbcDao.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/ResourceJdbcDao.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,15 +25,15 @@ import java.util.List;
public interface ResourceJdbcDao {
- Resource getResource(String assetId, String resourceName);
+ Resource getResource(String assetId, String resourceName);
- List<Resource> getResourceSet(String resourceSetId);
+ List<Resource> getResourceSet(String resourceSetId);
- List<Resource> getResourceUnion(String resourceUnionId);
+ List<Resource> getResourceUnion(String resourceUnionId);
- void add(Resource r);
+ void add(Resource r);
- void delete(long id);
+ void delete(long id);
- void update(Resource r);
+ void update(Resource r);
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/ResourceJdbcDaoImpl.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/ResourceJdbcDaoImpl.java
index 5e529f70e..08592819c 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/ResourceJdbcDaoImpl.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/ResourceJdbcDaoImpl.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,107 +38,107 @@ import org.springframework.jdbc.support.KeyHolder;
public class ResourceJdbcDaoImpl implements ResourceJdbcDao {
- @SuppressWarnings("unused")
- private static final Logger log = LoggerFactory.getLogger(ResourceJdbcDaoImpl.class);
-
- private static final String RESOURCE_SQL = "SELECT * FROM RESOURCE WHERE asset_id = ? AND resource_name = ?";
-
- private static final String RESOURCE_SET_SQL = "SELECT * FROM RESOURCE WHERE resource_id IN (\n"
- + "SELECT DISTINCT resource_id FROM ALLOCATION_ITEM WHERE resource_set_id = ?)";
-
- private static final String RESOURCE_UNION_SQL = "SELECT * FROM RESOURCE WHERE resource_id IN (\n"
- + "SELECT DISTINCT resource_id FROM ALLOCATION_ITEM WHERE resource_union_id = ?)";
-
- private static final String INSERT_SQL = "INSERT INTO RESOURCE (\n"
- + " asset_id, resource_name, resource_type, lt_used, ll_label, ll_reference_count, rr_used)\n"
- + "VALUES (?, ?, ?, ?, ?, ?, ?)";
-
- private static final String UPDATE_SQL = "UPDATE RESOURCE SET\n"
- + " lt_used = ?, ll_label = ?, ll_reference_count = ?, rr_used = ?\nWHERE resource_id = ?";
-
- private static final String DELETE_SQL = "DELETE FROM RESOURCE WHERE resource_id = ?";
-
- private JdbcTemplate jdbcTemplate;
- private ResourceRowMapper resourceRowMapper = new ResourceRowMapper();
-
- @Override
- public Resource getResource(String assetId, String resourceName) {
- if (assetId == null || assetId.trim().length() == 0 || resourceName == null ||
- resourceName.trim().length() == 0)
- return null;
-
- List<Resource> ll = jdbcTemplate.query(RESOURCE_SQL, new Object[] { assetId, resourceName }, resourceRowMapper);
- return ll.isEmpty() ? null : ll.get(0);
- }
-
- @Override
- public List<Resource> getResourceSet(String resourceSetId) {
- if (resourceSetId == null)
- return Collections.emptyList();
-
- return jdbcTemplate.query(RESOURCE_SET_SQL, new Object[] { resourceSetId }, resourceRowMapper);
- }
-
- @Override
- public List<Resource> getResourceUnion(String resourceUnionId) {
- if (resourceUnionId == null)
- return Collections.emptyList();
-
- return jdbcTemplate.query(RESOURCE_UNION_SQL, new Object[] { resourceUnionId }, resourceRowMapper);
- }
-
- @Override
- public void add(final Resource r) {
- PreparedStatementCreator psc = new PreparedStatementCreator() {
-
- @Override
- public PreparedStatement createPreparedStatement(Connection dbc) throws SQLException {
- PreparedStatement ps = dbc.prepareStatement(INSERT_SQL, new String[] { "resource_id" });
- ps.setString(1, r.assetId);
- ps.setString(2, r.name);
- ps.setString(3, r.type);
- ps.setLong(4, r.ltUsed);
- ps.setString(5, r.llLabel);
- ps.setInt(6, r.llReferenceCount);
- ps.setString(7, r.rrUsed);
- return ps;
- }
- };
- KeyHolder keyHolder = new GeneratedKeyHolder();
- jdbcTemplate.update(psc, keyHolder);
- r.id = keyHolder.getKey().longValue();
- }
-
- @Override
+ @SuppressWarnings("unused")
+ private static final Logger log = LoggerFactory.getLogger(ResourceJdbcDaoImpl.class);
+
+ private static final String RESOURCE_SQL = "SELECT * FROM RESOURCE WHERE asset_id = ? AND resource_name = ?";
+
+ private static final String RESOURCE_SET_SQL = "SELECT * FROM RESOURCE WHERE resource_id IN (\n"
+ + "SELECT DISTINCT resource_id FROM ALLOCATION_ITEM WHERE resource_set_id = ?)";
+
+ private static final String RESOURCE_UNION_SQL = "SELECT * FROM RESOURCE WHERE resource_id IN (\n"
+ + "SELECT DISTINCT resource_id FROM ALLOCATION_ITEM WHERE resource_union_id = ?)";
+
+ private static final String INSERT_SQL = "INSERT INTO RESOURCE (\n"
+ + " asset_id, resource_name, resource_type, lt_used, ll_label, ll_reference_count, rr_used)\n"
+ + "VALUES (?, ?, ?, ?, ?, ?, ?)";
+
+ private static final String UPDATE_SQL = "UPDATE RESOURCE SET\n"
+ + " lt_used = ?, ll_label = ?, ll_reference_count = ?, rr_used = ?\nWHERE resource_id = ?";
+
+ private static final String DELETE_SQL = "DELETE FROM RESOURCE WHERE resource_id = ?";
+
+ private JdbcTemplate jdbcTemplate;
+ private ResourceRowMapper resourceRowMapper = new ResourceRowMapper();
+
+ @Override
+ public Resource getResource(String assetId, String resourceName) {
+ if (assetId == null || assetId.trim().length() == 0 || resourceName == null ||
+ resourceName.trim().length() == 0)
+ return null;
+
+ List<Resource> ll = jdbcTemplate.query(RESOURCE_SQL, new Object[] { assetId, resourceName }, resourceRowMapper);
+ return ll.isEmpty() ? null : ll.get(0);
+ }
+
+ @Override
+ public List<Resource> getResourceSet(String resourceSetId) {
+ if (resourceSetId == null)
+ return Collections.emptyList();
+
+ return jdbcTemplate.query(RESOURCE_SET_SQL, new Object[] { resourceSetId }, resourceRowMapper);
+ }
+
+ @Override
+ public List<Resource> getResourceUnion(String resourceUnionId) {
+ if (resourceUnionId == null)
+ return Collections.emptyList();
+
+ return jdbcTemplate.query(RESOURCE_UNION_SQL, new Object[] { resourceUnionId }, resourceRowMapper);
+ }
+
+ @Override
+ public void add(final Resource r) {
+ PreparedStatementCreator psc = new PreparedStatementCreator() {
+
+ @Override
+ public PreparedStatement createPreparedStatement(Connection dbc) throws SQLException {
+ PreparedStatement ps = dbc.prepareStatement(INSERT_SQL, new String[] { "resource_id" });
+ ps.setString(1, r.assetId);
+ ps.setString(2, r.name);
+ ps.setString(3, r.type);
+ ps.setLong(4, r.ltUsed);
+ ps.setString(5, r.llLabel);
+ ps.setInt(6, r.llReferenceCount);
+ ps.setString(7, r.rrUsed);
+ return ps;
+ }
+ };
+ KeyHolder keyHolder = new GeneratedKeyHolder();
+ jdbcTemplate.update(psc, keyHolder);
+ r.id = keyHolder.getKey().longValue();
+ }
+
+ @Override
public void update(Resource r) {
- Long ltUsed = r.ltUsed <= 0 ? null : r.ltUsed;
- Integer llRefCount = r.llReferenceCount <= 0 ? null : r.llReferenceCount;
- jdbcTemplate.update(UPDATE_SQL, ltUsed, r.llLabel, llRefCount, r.rrUsed, r.id);
- }
-
- @Override
- public void delete(long id) {
- jdbcTemplate.update(DELETE_SQL, id);
- }
-
- private static class ResourceRowMapper implements RowMapper<Resource> {
-
- @Override
- public Resource mapRow(ResultSet rs, int arg1) throws SQLException {
- Resource r = new Resource();
- r.id = rs.getLong("resource_id");
- r.assetId = rs.getString("asset_id");
- r.name = rs.getString("resource_name");
- r.type = rs.getString("resource_type");
- r.ltUsed = rs.getLong("lt_used");
- r.llLabel = rs.getString("ll_label");
- r.llReferenceCount = rs.getInt("ll_reference_count");
- r.rrUsed = rs.getString("rr_used");
- return r;
- }
- }
-
- public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
- this.jdbcTemplate = jdbcTemplate;
- }
+ Long ltUsed = r.ltUsed <= 0 ? null : r.ltUsed;
+ Integer llRefCount = r.llReferenceCount <= 0 ? null : r.llReferenceCount;
+ jdbcTemplate.update(UPDATE_SQL, ltUsed, r.llLabel, llRefCount, r.rrUsed, r.id);
+ }
+
+ @Override
+ public void delete(long id) {
+ jdbcTemplate.update(DELETE_SQL, id);
+ }
+
+ private static class ResourceRowMapper implements RowMapper<Resource> {
+
+ @Override
+ public Resource mapRow(ResultSet rs, int arg1) throws SQLException {
+ Resource r = new Resource();
+ r.id = rs.getLong("resource_id");
+ r.assetId = rs.getString("asset_id");
+ r.name = rs.getString("resource_name");
+ r.type = rs.getString("resource_type");
+ r.ltUsed = rs.getLong("lt_used");
+ r.llLabel = rs.getString("ll_label");
+ r.llReferenceCount = rs.getInt("ll_reference_count");
+ r.rrUsed = rs.getString("rr_used");
+ return r;
+ }
+ }
+
+ public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
+ this.jdbcTemplate = jdbcTemplate;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/ResourceLoad.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/ResourceLoad.java
index 5c810b1d0..5b5669248 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/ResourceLoad.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/ResourceLoad.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,9 +25,9 @@ import java.util.Date;
public class ResourceLoad {
- public long id;
- public long resourceId;
- public String applicationId;
- public Date loadTime;
- public Date expirationTime;
+ public long id;
+ public long resourceId;
+ public String applicationId;
+ public Date loadTime;
+ public Date expirationTime;
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/ResourceLoadJdbcDao.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/ResourceLoadJdbcDao.java
index 9a337a83d..ad38372f2 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/ResourceLoadJdbcDao.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/ResourceLoadJdbcDao.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,12 +25,12 @@ import java.util.List;
public interface ResourceLoadJdbcDao {
- void add(ResourceLoad rl);
+ void add(ResourceLoad rl);
- List<ResourceLoad> getResourceLoads(long resourceId);
+ List<ResourceLoad> getResourceLoads(long resourceId);
- void update(ResourceLoad rl);
+ void update(ResourceLoad rl);
- void delete(long id);
+ void delete(long id);
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/ResourceLoadJdbcDaoImpl.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/ResourceLoadJdbcDaoImpl.java
index 854b66965..aa44afae3 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/ResourceLoadJdbcDaoImpl.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/dao/jdbc/ResourceLoadJdbcDaoImpl.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,74 +39,74 @@ import org.springframework.jdbc.support.KeyHolder;
public class ResourceLoadJdbcDaoImpl implements ResourceLoadJdbcDao {
- @SuppressWarnings("unused")
- private static final Logger log = LoggerFactory.getLogger(ResourceJdbcDaoImpl.class);
-
- private static final String INSERT_SQL = "INSERT INTO RESOURCE_LOAD (\n"
- + " resource_id, application_id, resource_load_time, resource_expiration_time)\nVALUES (?, ?, ?, ?)";
-
- private static final String UPDATE_SQL = "UPDATE RESOURCE_LOAD SET\n"
- + " resource_load_time = ?, resource_expiration_time = ?\nWHERE resource_id = ?";
-
- private static final String DELETE_SQL = "DELETE FROM RESOURCE_LOAD WHERE resource_load_id = ?";
-
- private static final String GET_SQL = "SELECT * FROM RESOURCE_LOAD WHERE resource_id = ?";
-
- private JdbcTemplate jdbcTemplate;
- private ResourceLoadRowMapper resourceLoadRowMapper = new ResourceLoadRowMapper();
-
- @Override
- public void add(final ResourceLoad rl) {
- PreparedStatementCreator psc = new PreparedStatementCreator() {
-
- @Override
- public PreparedStatement createPreparedStatement(Connection dbc) throws SQLException {
- PreparedStatement ps = dbc.prepareStatement(INSERT_SQL, new String[] { "resource_load_id" });
- ps.setLong(1, rl.resourceId);
- ps.setString(2, rl.applicationId);
- ps.setTimestamp(3, new Timestamp(rl.loadTime.getTime()));
- ps.setTimestamp(4, new Timestamp(rl.expirationTime.getTime()));
- return ps;
- }
- };
- KeyHolder keyHolder = new GeneratedKeyHolder();
- jdbcTemplate.update(psc, keyHolder);
- rl.id = keyHolder.getKey().longValue();
- }
-
- @Override
- public void update(ResourceLoad rl) {
- jdbcTemplate.update(UPDATE_SQL, rl.loadTime, rl.expirationTime, rl.id);
- }
-
- @Override
- public void delete(long id) {
- jdbcTemplate.update(DELETE_SQL, id);
- }
-
- @Override
- public List<ResourceLoad> getResourceLoads(long resourceId) {
- if (resourceId <= 0)
- return Collections.emptyList();
-
- return jdbcTemplate.query(GET_SQL, new Object[] { resourceId }, resourceLoadRowMapper);
- }
-
- private static class ResourceLoadRowMapper implements RowMapper<ResourceLoad> {
-
- @Override
- public ResourceLoad mapRow(ResultSet rs, int n) throws SQLException {
- ResourceLoad rl = new ResourceLoad();
- rl.id = rs.getLong("allocation_item_id");
- rl.resourceId = rs.getLong("resource_id");
- rl.applicationId = rs.getString("application_id");
- rl.loadTime = rs.getTimestamp("resource_load_time");
- rl.expirationTime = rs.getTimestamp("resource_expiration_time");
- return rl;
- }
- }
-
- public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
- this.jdbcTemplate = jdbcTemplate;
- }
+ @SuppressWarnings("unused")
+ private static final Logger log = LoggerFactory.getLogger(ResourceJdbcDaoImpl.class);
+
+ private static final String INSERT_SQL = "INSERT INTO RESOURCE_LOAD (\n"
+ + " resource_id, application_id, resource_load_time, resource_expiration_time)\nVALUES (?, ?, ?, ?)";
+
+ private static final String UPDATE_SQL = "UPDATE RESOURCE_LOAD SET\n"
+ + " resource_load_time = ?, resource_expiration_time = ?\nWHERE resource_id = ?";
+
+ private static final String DELETE_SQL = "DELETE FROM RESOURCE_LOAD WHERE resource_load_id = ?";
+
+ private static final String GET_SQL = "SELECT * FROM RESOURCE_LOAD WHERE resource_id = ?";
+
+ private JdbcTemplate jdbcTemplate;
+ private ResourceLoadRowMapper resourceLoadRowMapper = new ResourceLoadRowMapper();
+
+ @Override
+ public void add(final ResourceLoad rl) {
+ PreparedStatementCreator psc = new PreparedStatementCreator() {
+
+ @Override
+ public PreparedStatement createPreparedStatement(Connection dbc) throws SQLException {
+ PreparedStatement ps = dbc.prepareStatement(INSERT_SQL, new String[] { "resource_load_id" });
+ ps.setLong(1, rl.resourceId);
+ ps.setString(2, rl.applicationId);
+ ps.setTimestamp(3, new Timestamp(rl.loadTime.getTime()));
+ ps.setTimestamp(4, new Timestamp(rl.expirationTime.getTime()));
+ return ps;
+ }
+ };
+ KeyHolder keyHolder = new GeneratedKeyHolder();
+ jdbcTemplate.update(psc, keyHolder);
+ rl.id = keyHolder.getKey().longValue();
+ }
+
+ @Override
+ public void update(ResourceLoad rl) {
+ jdbcTemplate.update(UPDATE_SQL, rl.loadTime, rl.expirationTime, rl.id);
+ }
+
+ @Override
+ public void delete(long id) {
+ jdbcTemplate.update(DELETE_SQL, id);
+ }
+
+ @Override
+ public List<ResourceLoad> getResourceLoads(long resourceId) {
+ if (resourceId <= 0)
+ return Collections.emptyList();
+
+ return jdbcTemplate.query(GET_SQL, new Object[] { resourceId }, resourceLoadRowMapper);
+ }
+
+ private static class ResourceLoadRowMapper implements RowMapper<ResourceLoad> {
+
+ @Override
+ public ResourceLoad mapRow(ResultSet rs, int n) throws SQLException {
+ ResourceLoad rl = new ResourceLoad();
+ rl.id = rs.getLong("allocation_item_id");
+ rl.resourceId = rs.getLong("resource_id");
+ rl.applicationId = rs.getString("application_id");
+ rl.loadTime = rs.getTimestamp("resource_load_time");
+ rl.expirationTime = rs.getTimestamp("resource_expiration_time");
+ return rl;
+ }
+ }
+
+ public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
+ this.jdbcTemplate = jdbcTemplate;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/AllocationAction.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/AllocationAction.java
index c791d4272..4eab7d9d8 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/AllocationAction.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/AllocationAction.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,5 +22,5 @@
package org.openecomp.sdnc.rm.data;
public enum AllocationAction {
- Fail, Succeed_DoNothing, Succeed_Allocate
+ Fail, Succeed_DoNothing, Succeed_Allocate
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/AllocationItem.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/AllocationItem.java
index f4cabf96e..4a7ee6a7d 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/AllocationItem.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/AllocationItem.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,11 +26,11 @@ import java.util.Set;
public abstract class AllocationItem {
- public ResourceKey resourceKey;
- public ResourceType resourceType;
- public String resourceSetId;
- public String resourceUnionId;
- public Set<String> resourceShareGroupList;
- public String applicationId;
- public Date allocationTime;
+ public ResourceKey resourceKey;
+ public ResourceType resourceType;
+ public String resourceSetId;
+ public String resourceUnionId;
+ public Set<String> resourceShareGroupList;
+ public String applicationId;
+ public Date allocationTime;
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/AllocationOutcome.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/AllocationOutcome.java
index 20ecf051e..7283e11c6 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/AllocationOutcome.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/AllocationOutcome.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,6 +23,6 @@ package org.openecomp.sdnc.rm.data;
public class AllocationOutcome {
- public AllocationStatus status = null;
- public AllocationRequest request = null;
+ public AllocationStatus status = null;
+ public AllocationRequest request = null;
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/AllocationRequest.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/AllocationRequest.java
index d54475ff6..d4291167e 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/AllocationRequest.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/AllocationRequest.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,11 +25,11 @@ import java.util.Set;
public class AllocationRequest {
- public String resourceUnionId = null;
- public String resourceSetId = null;
- public Set<String> resourceShareGroupList = null;
- public String resourceName = null;
- public String assetId = null;
- public AllocationAction missingResourceAction = AllocationAction.Succeed_Allocate;
- public AllocationAction expiredResourceAction = AllocationAction.Succeed_Allocate;
+ public String resourceUnionId = null;
+ public String resourceSetId = null;
+ public Set<String> resourceShareGroupList = null;
+ public String resourceName = null;
+ public String assetId = null;
+ public AllocationAction missingResourceAction = AllocationAction.Succeed_Allocate;
+ public AllocationAction expiredResourceAction = AllocationAction.Succeed_Allocate;
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/AllocationStatus.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/AllocationStatus.java
index a18077a13..aa8d1df12 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/AllocationStatus.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/AllocationStatus.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,5 +23,5 @@ package org.openecomp.sdnc.rm.data;
public enum AllocationStatus {
- Success, Failure, NotTried, ResourceNotFound, ResourceExpired
+ Success, Failure, NotTried, ResourceNotFound, ResourceExpired
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/InitAction.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/InitAction.java
index 8b9dfaa32..d0075bdbd 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/InitAction.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/InitAction.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,15 +22,15 @@
package org.openecomp.sdnc.rm.data;
public enum InitAction {
- CheckInit("Initialize if needed"), ForceInit("Always Initialize"), NoInit("No initialization");
+ CheckInit("Initialize if needed"), ForceInit("Always Initialize"), NoInit("No initialization");
- private String str;
+ private String str;
- private InitAction(String str) {
- this.str = str;
- }
+ private InitAction(String str) {
+ this.str = str;
+ }
- public String getInitActionStr() {
- return str;
- }
+ public String getInitActionStr() {
+ return str;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LabelAllocationItem.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LabelAllocationItem.java
index e456542cf..97ee3ba89 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LabelAllocationItem.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LabelAllocationItem.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,5 +23,5 @@ package org.openecomp.sdnc.rm.data;
public class LabelAllocationItem extends AllocationItem {
- public String label;
+ public String label;
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LabelAllocationOutcome.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LabelAllocationOutcome.java
index d0cb2c527..c1763ff21 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LabelAllocationOutcome.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LabelAllocationOutcome.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,6 +23,6 @@ package org.openecomp.sdnc.rm.data;
public class LabelAllocationOutcome extends AllocationOutcome {
- public String allocatedLabel = null;
- public String currentLabel = null;
+ public String allocatedLabel = null;
+ public String currentLabel = null;
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LabelAllocationRequest.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LabelAllocationRequest.java
index 2b6ce0338..8e509f66d 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LabelAllocationRequest.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LabelAllocationRequest.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,7 +23,7 @@ package org.openecomp.sdnc.rm.data;
public class LabelAllocationRequest extends AllocationRequest {
- public String label = null;
- public boolean check = false;
- public boolean allocate = false;
+ public String label = null;
+ public boolean check = false;
+ public boolean allocate = false;
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LabelResource.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LabelResource.java
index 54bfb852e..d82701928 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LabelResource.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LabelResource.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,8 +23,8 @@ package org.openecomp.sdnc.rm.data;
public class LabelResource extends Resource {
- public static final String BLOCKED = "__BLOCKED__";
+ public static final String BLOCKED = "__BLOCKED__";
- public String label;
- public int referenceCount;
+ public String label;
+ public int referenceCount;
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LimitAllocationItem.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LimitAllocationItem.java
index 270220a8a..181172f2f 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LimitAllocationItem.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LimitAllocationItem.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,5 +23,5 @@ package org.openecomp.sdnc.rm.data;
public class LimitAllocationItem extends AllocationItem {
- public long used;
+ public long used;
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LimitAllocationOutcome.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LimitAllocationOutcome.java
index f1c13c083..ffc119414 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LimitAllocationOutcome.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LimitAllocationOutcome.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,7 +23,7 @@ package org.openecomp.sdnc.rm.data;
public class LimitAllocationOutcome extends AllocationOutcome {
- public long allocatedCount = 0;
- public long used = 0;
- public long limit = 0;
+ public long allocatedCount = 0;
+ public long used = 0;
+ public long limit = 0;
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LimitAllocationRequest.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LimitAllocationRequest.java
index 787715bb0..31c0d1155 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LimitAllocationRequest.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LimitAllocationRequest.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,9 +23,9 @@ package org.openecomp.sdnc.rm.data;
public class LimitAllocationRequest extends AllocationRequest {
- public long checkCount = 0;
- public long allocateCount = 0;
- public long checkLimit = -1;
- public boolean replace = false;
- public boolean strict = false;
+ public long checkCount = 0;
+ public long allocateCount = 0;
+ public long checkLimit = -1;
+ public boolean replace = false;
+ public boolean strict = false;
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LimitResource.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LimitResource.java
index cad0ba232..ad706ee81 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LimitResource.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/LimitResource.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,5 +23,5 @@ package org.openecomp.sdnc.rm.data;
public class LimitResource extends Resource {
- public long used = 0;
+ public long used = 0;
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/MultiAssetAllocationOutcome.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/MultiAssetAllocationOutcome.java
index bf9bbbfaa..dcbac3675 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/MultiAssetAllocationOutcome.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/MultiAssetAllocationOutcome.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,6 +25,6 @@ import java.util.List;
public class MultiAssetAllocationOutcome extends AllocationOutcome {
- public List<String> goodAssetIdList;
- public List<AllocationOutcome> allocationOutcomeList;
+ public List<String> goodAssetIdList;
+ public List<AllocationOutcome> allocationOutcomeList;
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/MultiAssetAllocationRequest.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/MultiAssetAllocationRequest.java
index da1a96d73..d4dd65ed4 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/MultiAssetAllocationRequest.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/MultiAssetAllocationRequest.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,8 +25,8 @@ import java.util.List;
public class MultiAssetAllocationRequest extends AllocationRequest {
- public List<String> assetIdList = null;
- public AllocationRequest allocationRequest = null;
- public int requestedCount = 0;
- public boolean sequential = false;
+ public List<String> assetIdList = null;
+ public AllocationRequest allocationRequest = null;
+ public int requestedCount = 0;
+ public boolean sequential = false;
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/MultiResourceAllocationOutcome.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/MultiResourceAllocationOutcome.java
index 9deca6c2b..355d50814 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/MultiResourceAllocationOutcome.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/MultiResourceAllocationOutcome.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,5 +25,5 @@ import java.util.List;
public class MultiResourceAllocationOutcome extends AllocationOutcome {
- public List<AllocationOutcome> allocationOutcomeList;
+ public List<AllocationOutcome> allocationOutcomeList;
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/MultiResourceAllocationRequest.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/MultiResourceAllocationRequest.java
index 9e48a31e5..4de9868b3 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/MultiResourceAllocationRequest.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/MultiResourceAllocationRequest.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ *reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,6 +25,6 @@ import java.util.List;
public class MultiResourceAllocationRequest extends AllocationRequest {
- public List<AllocationRequest> allocationRequestList = null;
- public boolean stopOnFirstFailure = true;
+ public List<AllocationRequest> allocationRequestList = null;
+ public boolean stopOnFirstFailure = true;
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/RangeAllocationItem.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/RangeAllocationItem.java
index 229c8e449..4260b4dc3 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/RangeAllocationItem.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/RangeAllocationItem.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,5 +25,5 @@ import java.util.SortedSet;
public class RangeAllocationItem extends AllocationItem {
- public SortedSet<Integer> used;
+ public SortedSet<Integer> used;
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/RangeAllocationOutcome.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/RangeAllocationOutcome.java
index 8b35d9f04..ad14f510a 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/RangeAllocationOutcome.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/RangeAllocationOutcome.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,6 +25,6 @@ import java.util.SortedSet;
public class RangeAllocationOutcome extends AllocationOutcome {
- public SortedSet<Integer> allocated = null;
- public SortedSet<Integer> used = null;
+ public SortedSet<Integer> allocated = null;
+ public SortedSet<Integer> used = null;
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/RangeAllocationRequest.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/RangeAllocationRequest.java
index 0732613d3..9315535f4 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/RangeAllocationRequest.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/RangeAllocationRequest.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,12 +25,12 @@ import java.util.SortedSet;
public class RangeAllocationRequest extends AllocationRequest {
- public int checkMin = 0;
- public int checkMax = 0;
- public boolean check = false;
- public boolean allocate = false;
- public boolean replace = false;
- public SortedSet<Integer> requestedNumbers = null;
- public int requestedCount = 1;
- public boolean sequential = false;
+ public int checkMin = 0;
+ public int checkMax = 0;
+ public boolean check = false;
+ public boolean allocate = false;
+ public boolean replace = false;
+ public SortedSet<Integer> requestedNumbers = null;
+ public int requestedCount = 1;
+ public boolean sequential = false;
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/RangeResource.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/RangeResource.java
index 99a2b207a..4bec30440 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/RangeResource.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/RangeResource.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,5 +25,5 @@ import java.util.SortedSet;
public class RangeResource extends Resource {
- public SortedSet<Integer> used;
+ public SortedSet<Integer> used;
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/Resource.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/Resource.java
index b04f71050..c462bde37 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/Resource.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/Resource.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,8 +25,8 @@ import java.util.Collection;
public abstract class Resource {
- public ResourceKey resourceKey;
- public ResourceType resourceType;
- public Collection<AllocationItem> allocationItems;
- public Collection<ResourceLoad> resourceLoadList;
+ public ResourceKey resourceKey;
+ public ResourceType resourceType;
+ public Collection<AllocationItem> allocationItems;
+ public Collection<ResourceLoad> resourceLoadList;
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/ResourceKey.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/ResourceKey.java
index b303b07fd..765c9251c 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/ResourceKey.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/ResourceKey.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,28 +23,28 @@ package org.openecomp.sdnc.rm.data;
public class ResourceKey {
- public String assetId;
- public String resourceName;
+ public String assetId;
+ public String resourceName;
- @Override
- public boolean equals(Object o) {
- if (this == o)
- return true;
- if (o == null || !(o instanceof ResourceKey))
- return false;
- ResourceKey rk = (ResourceKey) o;
- if (assetId == null || resourceName == null)
- return false;
- return assetId.equals(rk.assetId) && resourceName.equals(rk.resourceName);
- }
+ @Override
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (o == null || !(o instanceof ResourceKey))
+ return false;
+ ResourceKey rk = (ResourceKey) o;
+ if (assetId == null || resourceName == null)
+ return false;
+ return assetId.equals(rk.assetId) && resourceName.equals(rk.resourceName);
+ }
- @Override
- public int hashCode() {
- return (int) ((long) System.identityHashCode(assetId) + (long) System.identityHashCode(resourceName));
- }
+ @Override
+ public int hashCode() {
+ return (int) ((long) System.identityHashCode(assetId) + (long) System.identityHashCode(resourceName));
+ }
- @Override
- public String toString() {
- return "(" + assetId + ", " + resourceName + ")";
- }
+ @Override
+ public String toString() {
+ return "(" + assetId + ", " + resourceName + ")";
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/ResourceLoad.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/ResourceLoad.java
index 06970cbcc..f1e96a8bf 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/ResourceLoad.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/ResourceLoad.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,8 +25,8 @@ import java.util.Date;
public class ResourceLoad {
- public ResourceKey resourceKey;
- public String applicationId;
- public Date resourceLoadTime;
- public Date resourceExpirationTime;
+ public ResourceKey resourceKey;
+ public String applicationId;
+ public Date resourceLoadTime;
+ public Date resourceExpirationTime;
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/ResourceType.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/ResourceType.java
index 1d8b9c4c8..d97cb7d71 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/ResourceType.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/data/ResourceType.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,5 +22,5 @@
package org.openecomp.sdnc.rm.data;
public enum ResourceType {
- Limit, Label, Range
+ Limit, Label, Range
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/util/LabelUtil.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/util/LabelUtil.java
index bbaa3a378..d15a149f2 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/util/LabelUtil.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/util/LabelUtil.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,63 +33,63 @@ import org.openecomp.sdnc.rm.data.ResourceType;
public class LabelUtil {
- public static boolean checkLabel(LabelResource l, LabelAllocationRequest req) {
- if (req.check && req.label != null && l.allocationItems != null && !l.allocationItems.isEmpty()) {
- for (AllocationItem ai : l.allocationItems) {
- LabelAllocationItem lai = (LabelAllocationItem) ai;
- if (!eq(req.resourceUnionId, lai.resourceUnionId) && !eq(req.label, lai.label))
- return false;
- }
- }
- return true;
- }
+ public static boolean checkLabel(LabelResource l, LabelAllocationRequest req) {
+ if (req.check && req.label != null && l.allocationItems != null && !l.allocationItems.isEmpty()) {
+ for (AllocationItem ai : l.allocationItems) {
+ LabelAllocationItem lai = (LabelAllocationItem) ai;
+ if (!eq(req.resourceUnionId, lai.resourceUnionId) && !eq(req.label, lai.label))
+ return false;
+ }
+ }
+ return true;
+ }
- public static String allocateLabel(LabelResource l, LabelAllocationRequest req, String applicationId) {
- if (!req.allocate)
- return null;
+ public static String allocateLabel(LabelResource l, LabelAllocationRequest req, String applicationId) {
+ if (!req.allocate)
+ return null;
- LabelAllocationItem lai = (LabelAllocationItem) ResourceUtil.getAllocationItem(l, req.resourceSetId);
- if (lai == null) {
- lai = new LabelAllocationItem();
- lai.resourceType = ResourceType.Label;
- lai.resourceKey = new ResourceKey();
- lai.resourceKey.assetId = req.assetId;
- lai.resourceKey.resourceName = req.resourceName;
- lai.applicationId = applicationId;
- lai.resourceSetId = req.resourceSetId;
- lai.resourceUnionId = req.resourceUnionId;
- lai.resourceShareGroupList = req.resourceShareGroupList;
+ LabelAllocationItem lai = (LabelAllocationItem) ResourceUtil.getAllocationItem(l, req.resourceSetId);
+ if (lai == null) {
+ lai = new LabelAllocationItem();
+ lai.resourceType = ResourceType.Label;
+ lai.resourceKey = new ResourceKey();
+ lai.resourceKey.assetId = req.assetId;
+ lai.resourceKey.resourceName = req.resourceName;
+ lai.applicationId = applicationId;
+ lai.resourceSetId = req.resourceSetId;
+ lai.resourceUnionId = req.resourceUnionId;
+ lai.resourceShareGroupList = req.resourceShareGroupList;
- if (l.allocationItems == null)
- l.allocationItems = new ArrayList<AllocationItem>();
- l.allocationItems.add(lai);
- }
+ if (l.allocationItems == null)
+ l.allocationItems = new ArrayList<AllocationItem>();
+ l.allocationItems.add(lai);
+ }
- lai.label = req.label;
- lai.allocationTime = new Date();
+ lai.label = req.label;
+ lai.allocationTime = new Date();
- recalculate(l);
+ recalculate(l);
- return lai.label;
- }
+ return lai.label;
+ }
- public static void recalculate(LabelResource l) {
- l.label = null;
- l.referenceCount = 0;
- if (l.allocationItems != null)
- for (AllocationItem ai : l.allocationItems) {
- LabelAllocationItem lai = (LabelAllocationItem) ai;
- if (lai.label != null) {
- l.referenceCount++;
- if (l.label == null)
- l.label = lai.label;
- else if (!l.label.equals(lai.label))
- l.label = "__BLOCKED__";
- }
- }
- }
+ public static void recalculate(LabelResource l) {
+ l.label = null;
+ l.referenceCount = 0;
+ if (l.allocationItems != null)
+ for (AllocationItem ai : l.allocationItems) {
+ LabelAllocationItem lai = (LabelAllocationItem) ai;
+ if (lai.label != null) {
+ l.referenceCount++;
+ if (l.label == null)
+ l.label = lai.label;
+ else if (!l.label.equals(lai.label))
+ l.label = "__BLOCKED__";
+ }
+ }
+ }
- private static boolean eq(Object o1, Object o2) {
- return o1 == null ? o2 == null : o1.equals(o2);
- }
+ private static boolean eq(Object o1, Object o2) {
+ return o1 == null ? o2 == null : o1.equals(o2);
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/util/LimitUtil.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/util/LimitUtil.java
index 457995604..76c3ef76e 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/util/LimitUtil.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/util/LimitUtil.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,296 +39,296 @@ import org.slf4j.LoggerFactory;
public class LimitUtil {
- private static final Logger log = LoggerFactory.getLogger(LimitUtil.class);
-
- public static boolean checkLimit(LimitResource l, LimitAllocationRequest req) {
- if (req.checkCount <= 0)
- return true;
-
- long checkCount = req.checkCount;
- long currentUsage = 0;
- if (req.resourceSetId != null) {
- LimitAllocationItem lai = (LimitAllocationItem) ResourceUtil.getAllocationItem(l, req.resourceSetId);
- if (lai != null)
- currentUsage = lai.used;
- }
- if (!req.replace)
- checkCount += currentUsage;
-
- long used = calculateLimitUsage(l, 0, null, null);
- long wouldUse = calculateLimitUsage(l, checkCount, req.resourceUnionId, req.resourceShareGroupList);
-
- // If usage is not increasing by this request, only check the limit if
- // strictCheck is true.
- if (wouldUse <= used && !req.strict)
- return true;
-
- return wouldUse <= req.checkLimit;
- }
-
- private static long calculateLimitUsage(
- LimitResource l,
- long checkCount,
- String resourceUnionId,
- Set<String> resourceShareGroupList) {
- if ((l.allocationItems == null || l.allocationItems.isEmpty()) &&
- (resourceUnionId == null || resourceUnionId.length() == 0))
- return 0;
-
- long t1 = System.currentTimeMillis();
- boolean logit = false;
- String rn = "Resource: " + l.resourceKey.resourceName + " - " + l.resourceKey.assetId;
-
- // In order to best utilize the resource, we need to take not the sum of all allocation items, but
- // instead the maximum usage that could happen at any moment of time (given not all allocation items are active
- // at the same time), also taking into account possible resource sharing.
- // Thus we need to find all combinations of allocation items that can be active at the same time (allocation
- // items with the same first union cannot be active at the same time), compute the usage for each (again,
- // taking into account resource sharing), and take the maximum.
- //
- // Example:
- // Let's have the following allocation items:
- // ai1: sdid1, vrf1 - usage 5
- // ai2: sdid2, vrf1 - usage 10
- // ai3: sdid3, vrf2 - usage 15
- // ai4: sdid1, vrf3 - usage 20
- // ai5: sdid3, vrf1 - usage 25
- // The following combinations of active allocation items are possible:
- // 1) ai1, ai2, ai3
- // 2) ai1, ai2, ai5
- // 3) ai2, ai3, ai4
- // 4) ai2, ai3, ai5
- // Here is how we calculate the usage for combination 1:
- // ai1 and ai2 contain the same resource union vrf1, so they share the resource - we take the max of usage,
- // so we have:
- // max(5, 10) + 15 = 25
- // Similarly, we calculate the usage of the other combinations:
- // 2) max(5, 10, 25) = 25
- // 3) 10 + 15 + 20 = 45
- // 4) max(10, 25) + 15 = 40
- // So, the result in this case is:
- // max(25, 25, 45, 40) = 45
- //
- // We might have a problem with this approach, if we have a lot of combinations. Assuming we have at most 2
- // allocation items with the same resource union (sdid), the number of combinations would be
- // 2 ^ n
- // where n is the number of allocation items that have the same resource union (sdid). That would be
- // the number of change orders currently in progress.
- //
- // Here is one optimization that we can do:
- // If we have allocation items that have all resource unions the same, we don't need to generate combinations
- // with each of them, we can just take the one of them with the maximum usage, as it is clear that the others
- // will not lead to a bigger usage.
- // For example, if we had the following allocation items:
- // ai1: sdid1, vrf1 - usage 10
- // ai2: sdid1, vrf1 - usage 20
- // We only need to take the combinations with ai2, as they will always lead to bigger usage than the remaining
- // combinations with ai1.
-
- // First, group the allocation items by the first resource union, using the LimitUsage structure
- int regularChangeCount = 0;
- Map<String/* resourceUnionId */, List<LimitUsage>> limitUsageMap = new HashMap<String, List<LimitUsage>>();
- if (l.allocationItems != null)
- for (AllocationItem ai : l.allocationItems) {
- LimitAllocationItem lai = (LimitAllocationItem) ai;
- boolean regularChange =
- addLimitUsage(limitUsageMap, lai.resourceUnionId, lai.resourceShareGroupList, lai.used);
- if (regularChange)
- regularChangeCount++;
- }
- if (checkCount > 0 && resourceUnionId != null) {
- boolean regularChange = addLimitUsage(limitUsageMap, resourceUnionId, resourceShareGroupList, checkCount);
- if (regularChange)
- regularChangeCount++;
- }
-
- // Generate all the combinations, containing one LimitUsage object for each firstResourceUnion
- int significantChangeCount = 0;
- List<List<LimitUsage>> allCombinations = new ArrayList<List<LimitUsage>>();
- for (String firstResourceUnion : limitUsageMap.keySet()) {
- List<LimitUsage> limitUsageList = limitUsageMap.get(firstResourceUnion);
- if (limitUsageList.size() > 1)
- significantChangeCount++;
- if (allCombinations.isEmpty()) {
- for (LimitUsage limitUsage : limitUsageList) {
- List<LimitUsage> newCombination = new ArrayList<LimitUsage>();
- newCombination.add(limitUsage);
- allCombinations.add(newCombination);
- }
- } else {
- if (limitUsageList.size() == 1) {
- // No new combinations are generated - just add this one to all combinations we have until now
- for (List<LimitUsage> combination : allCombinations)
- combination.add(limitUsageList.get(0));
- } else {
- // We have to duplicate each of the current combinations for each element of limitUsageList
- List<List<LimitUsage>> newAllCombinations = new ArrayList<List<LimitUsage>>();
- for (List<LimitUsage> combination : allCombinations)
- for (LimitUsage limitUsage : limitUsageList) {
- List<LimitUsage> newCombination = new ArrayList<LimitUsage>(combination);
- newCombination.add(limitUsage);
- newAllCombinations.add(newCombination);
- }
- allCombinations = newAllCombinations;
- }
- }
- }
-
- // Now, go through all combinations and calculate its usage, get the maximum
- long maxUsage = 0;
- for (List<LimitUsage> combination : allCombinations) {
- long usage = calculateUsage(combination);
- if (usage > maxUsage)
- maxUsage = usage;
- }
-
- long t2 = System.currentTimeMillis();
- if (logit) {
- log.debug(rn + ": Calculating usage completed:");
- log.debug(rn + ": Regular changes: " + regularChangeCount);
- log.debug(rn + ": Significant changes: " + significantChangeCount);
- log.debug(rn + ": Combinations: " + allCombinations.size());
- log.debug(rn + ": Usage: " + maxUsage);
- log.debug(rn + ": Time: " + (t2 - t1));
- }
-
- return maxUsage;
- }
-
- private static boolean addLimitUsage(
- Map<String/* resourceUnionId */, List<LimitUsage>> limitUsageMap,
- String resourceUnionId,
- Set<String> resourceShareGroupList,
- long used) {
- List<LimitUsage> limitUsageList = limitUsageMap.get(resourceUnionId);
- if (limitUsageList == null) {
- limitUsageList = new ArrayList<LimitUsage>();
- limitUsageMap.put(resourceUnionId, limitUsageList);
- }
- // See if we already have the same shareResourceUnionSet in the list. In such case just update the usage
- // to the bigger value.
- LimitUsage limitUsage = null;
- for (LimitUsage limitUsage1 : limitUsageList) {
- if ((limitUsage1.resourceShareGroupList == null || limitUsage1.resourceShareGroupList.isEmpty()) &&
- (resourceShareGroupList == null || resourceShareGroupList.isEmpty())) {
- limitUsage = limitUsage1;
- break;
- }
- if (limitUsage1.resourceShareGroupList != null &&
- limitUsage1.resourceShareGroupList.equals(resourceShareGroupList)) {
- limitUsage = limitUsage1;
- break;
- }
- }
- if (limitUsage != null) {
- if (limitUsage.usage < used)
- limitUsage.usage = used;
- return true;
- }
-
- limitUsage = new LimitUsage();
- limitUsage.resourceUnion = resourceUnionId;
- limitUsage.resourceShareGroupList = resourceShareGroupList;
- limitUsage.usage = used;
- limitUsageList.add(limitUsage);
- return false;
- }
-
- private static class LimitUsage {
-
- @SuppressWarnings("unused")
- public String resourceUnion;
- public Set<String> resourceShareGroupList;
- public long usage;
- }
-
- private static boolean hasCommonSharedResource(LimitUsage limitUsage1, LimitUsage limitUsage2) {
- if (limitUsage1.resourceShareGroupList == null || limitUsage1.resourceShareGroupList.isEmpty())
- return false;
- if (limitUsage2.resourceShareGroupList == null || limitUsage2.resourceShareGroupList.isEmpty())
- return false;
-
- for (String resourceUnion : limitUsage1.resourceShareGroupList)
- if (limitUsage2.resourceShareGroupList.contains(resourceUnion))
- return true;
-
- return false;
- }
-
- private static long calculateUsage(List<LimitUsage> combination) {
- // All LimitUsage objects that have a common value in their sharedResourceUnionSet reuse the resource, so
- // split the combination in sets that have common value. Then the usage of each set will be the maximum of
- // the usages of the LimitUsage objects in the set. The usage of the combination will be the sum of the usages
- // of all sets.
- List<List<LimitUsage>> sharedSets = new ArrayList<List<LimitUsage>>();
- for (LimitUsage limitUsage : combination) {
- // See if we can put limitUsage in any of the existing sets - is it has a common resource union with
- // any of the LimitUsage objects in a set.
- boolean found = false;
- for (List<LimitUsage> sharedSet : sharedSets) {
- for (LimitUsage limitUsage1 : sharedSet) {
- if (hasCommonSharedResource(limitUsage, limitUsage1)) {
- found = true;
- break;
- }
- }
- if (found) {
- sharedSet.add(limitUsage);
- break;
- }
- }
- if (!found) {
- // Start a new set
- List<LimitUsage> newSharedSet = new ArrayList<LimitUsage>();
- newSharedSet.add(limitUsage);
- sharedSets.add(newSharedSet);
- }
- }
-
- long sum = 0;
- for (List<LimitUsage> sharedSet : sharedSets) {
- float max = 0;
- for (LimitUsage limitUsage : sharedSet)
- if (max < limitUsage.usage)
- max = limitUsage.usage;
- sum += max;
- }
-
- return sum;
- }
-
- public static long allocateLimit(LimitResource l, LimitAllocationRequest req, String applicationId) {
- if (req.allocateCount <= 0)
- return 0;
- long uu = l.used;
-
- LimitAllocationItem lai = (LimitAllocationItem) ResourceUtil.getAllocationItem(l, req.resourceSetId);
- if (lai == null) {
- lai = new LimitAllocationItem();
- lai.resourceType = ResourceType.Limit;
- lai.resourceKey = new ResourceKey();
- lai.resourceKey.assetId = req.assetId;
- lai.resourceKey.resourceName = req.resourceName;
- lai.applicationId = applicationId;
- lai.resourceSetId = req.resourceSetId;
- lai.resourceUnionId = req.resourceUnionId;
- lai.resourceShareGroupList = req.resourceShareGroupList;
- lai.used = req.allocateCount;
-
- if (l.allocationItems == null)
- l.allocationItems = new ArrayList<AllocationItem>();
- l.allocationItems.add(lai);
- } else
- lai.used = req.replace ? req.allocateCount : lai.used + req.allocateCount;
-
- lai.allocationTime = new Date();
-
- recalculate(l);
-
- return l.used - uu;
- }
-
- public static void recalculate(LimitResource l) {
- l.used = calculateLimitUsage(l, 0, null, null);
- }
+ private static final Logger log = LoggerFactory.getLogger(LimitUtil.class);
+
+ public static boolean checkLimit(LimitResource l, LimitAllocationRequest req) {
+ if (req.checkCount <= 0)
+ return true;
+
+ long checkCount = req.checkCount;
+ long currentUsage = 0;
+ if (req.resourceSetId != null) {
+ LimitAllocationItem lai = (LimitAllocationItem) ResourceUtil.getAllocationItem(l, req.resourceSetId);
+ if (lai != null)
+ currentUsage = lai.used;
+ }
+ if (!req.replace)
+ checkCount += currentUsage;
+
+ long used = calculateLimitUsage(l, 0, null, null);
+ long wouldUse = calculateLimitUsage(l, checkCount, req.resourceUnionId, req.resourceShareGroupList);
+
+ // If usage is not increasing by this request, only check the limit if
+ // strictCheck is true.
+ if (wouldUse <= used && !req.strict)
+ return true;
+
+ return wouldUse <= req.checkLimit;
+ }
+
+ private static long calculateLimitUsage(
+ LimitResource l,
+ long checkCount,
+ String resourceUnionId,
+ Set<String> resourceShareGroupList) {
+ if ((l.allocationItems == null || l.allocationItems.isEmpty()) &&
+ (resourceUnionId == null || resourceUnionId.length() == 0))
+ return 0;
+
+ long t1 = System.currentTimeMillis();
+ boolean logit = false;
+ String rn = "Resource: " + l.resourceKey.resourceName + " - " + l.resourceKey.assetId;
+
+ // In order to best utilize the resource, we need to take not the sum of all allocation items, but
+ // instead the maximum usage that could happen at any moment of time (given not all allocation items are active
+ // at the same time), also taking into account possible resource sharing.
+ // Thus we need to find all combinations of allocation items that can be active at the same time (allocation
+ // items with the same first union cannot be active at the same time), compute the usage for each (again,
+ // taking into account resource sharing), and take the maximum.
+ //
+ // Example:
+ // Let's have the following allocation items:
+ // ai1: sdid1, vrf1 - usage 5
+ // ai2: sdid2, vrf1 - usage 10
+ // ai3: sdid3, vrf2 - usage 15
+ // ai4: sdid1, vrf3 - usage 20
+ // ai5: sdid3, vrf1 - usage 25
+ // The following combinations of active allocation items are possible:
+ // 1) ai1, ai2, ai3
+ // 2) ai1, ai2, ai5
+ // 3) ai2, ai3, ai4
+ // 4) ai2, ai3, ai5
+ // Here is how we calculate the usage for combination 1:
+ // ai1 and ai2 contain the same resource union vrf1, so they share the resource - we take the max of usage,
+ // so we have:
+ // max(5, 10) + 15 = 25
+ // Similarly, we calculate the usage of the other combinations:
+ // 2) max(5, 10, 25) = 25
+ // 3) 10 + 15 + 20 = 45
+ // 4) max(10, 25) + 15 = 40
+ // So, the result in this case is:
+ // max(25, 25, 45, 40) = 45
+ //
+ // We might have a problem with this approach, if we have a lot of combinations. Assuming we have at most 2
+ // allocation items with the same resource union (sdid), the number of combinations would be
+ // 2 ^ n
+ // where n is the number of allocation items that have the same resource union (sdid). That would be
+ // the number of change orders currently in progress.
+ //
+ // Here is one optimization that we can do:
+ // If we have allocation items that have all resource unions the same, we don't need to generate combinations
+ // with each of them, we can just take the one of them with the maximum usage, as it is clear that the others
+ // will not lead to a bigger usage.
+ // For example, if we had the following allocation items:
+ // ai1: sdid1, vrf1 - usage 10
+ // ai2: sdid1, vrf1 - usage 20
+ // We only need to take the combinations with ai2, as they will always lead to bigger usage than the remaining
+ // combinations with ai1.
+
+ // First, group the allocation items by the first resource union, using the LimitUsage structure
+ int regularChangeCount = 0;
+ Map<String/* resourceUnionId */, List<LimitUsage>> limitUsageMap = new HashMap<String, List<LimitUsage>>();
+ if (l.allocationItems != null)
+ for (AllocationItem ai : l.allocationItems) {
+ LimitAllocationItem lai = (LimitAllocationItem) ai;
+ boolean regularChange =
+ addLimitUsage(limitUsageMap, lai.resourceUnionId, lai.resourceShareGroupList, lai.used);
+ if (regularChange)
+ regularChangeCount++;
+ }
+ if (checkCount > 0 && resourceUnionId != null) {
+ boolean regularChange = addLimitUsage(limitUsageMap, resourceUnionId, resourceShareGroupList, checkCount);
+ if (regularChange)
+ regularChangeCount++;
+ }
+
+ // Generate all the combinations, containing one LimitUsage object for each firstResourceUnion
+ int significantChangeCount = 0;
+ List<List<LimitUsage>> allCombinations = new ArrayList<List<LimitUsage>>();
+ for (String firstResourceUnion : limitUsageMap.keySet()) {
+ List<LimitUsage> limitUsageList = limitUsageMap.get(firstResourceUnion);
+ if (limitUsageList.size() > 1)
+ significantChangeCount++;
+ if (allCombinations.isEmpty()) {
+ for (LimitUsage limitUsage : limitUsageList) {
+ List<LimitUsage> newCombination = new ArrayList<LimitUsage>();
+ newCombination.add(limitUsage);
+ allCombinations.add(newCombination);
+ }
+ } else {
+ if (limitUsageList.size() == 1) {
+ // No new combinations are generated - just add this one to all combinations we have until now
+ for (List<LimitUsage> combination : allCombinations)
+ combination.add(limitUsageList.get(0));
+ } else {
+ // We have to duplicate each of the current combinations for each element of limitUsageList
+ List<List<LimitUsage>> newAllCombinations = new ArrayList<List<LimitUsage>>();
+ for (List<LimitUsage> combination : allCombinations)
+ for (LimitUsage limitUsage : limitUsageList) {
+ List<LimitUsage> newCombination = new ArrayList<LimitUsage>(combination);
+ newCombination.add(limitUsage);
+ newAllCombinations.add(newCombination);
+ }
+ allCombinations = newAllCombinations;
+ }
+ }
+ }
+
+ // Now, go through all combinations and calculate its usage, get the maximum
+ long maxUsage = 0;
+ for (List<LimitUsage> combination : allCombinations) {
+ long usage = calculateUsage(combination);
+ if (usage > maxUsage)
+ maxUsage = usage;
+ }
+
+ long t2 = System.currentTimeMillis();
+ if (logit) {
+ log.debug(rn + ": Calculating usage completed:");
+ log.debug(rn + ": Regular changes: " + regularChangeCount);
+ log.debug(rn + ": Significant changes: " + significantChangeCount);
+ log.debug(rn + ": Combinations: " + allCombinations.size());
+ log.debug(rn + ": Usage: " + maxUsage);
+ log.debug(rn + ": Time: " + (t2 - t1));
+ }
+
+ return maxUsage;
+ }
+
+ private static boolean addLimitUsage(
+ Map<String/* resourceUnionId */, List<LimitUsage>> limitUsageMap,
+ String resourceUnionId,
+ Set<String> resourceShareGroupList,
+ long used) {
+ List<LimitUsage> limitUsageList = limitUsageMap.get(resourceUnionId);
+ if (limitUsageList == null) {
+ limitUsageList = new ArrayList<LimitUsage>();
+ limitUsageMap.put(resourceUnionId, limitUsageList);
+ }
+ // See if we already have the same shareResourceUnionSet in the list. In such case just update the usage
+ // to the bigger value.
+ LimitUsage limitUsage = null;
+ for (LimitUsage limitUsage1 : limitUsageList) {
+ if ((limitUsage1.resourceShareGroupList == null || limitUsage1.resourceShareGroupList.isEmpty()) &&
+ (resourceShareGroupList == null || resourceShareGroupList.isEmpty())) {
+ limitUsage = limitUsage1;
+ break;
+ }
+ if (limitUsage1.resourceShareGroupList != null &&
+ limitUsage1.resourceShareGroupList.equals(resourceShareGroupList)) {
+ limitUsage = limitUsage1;
+ break;
+ }
+ }
+ if (limitUsage != null) {
+ if (limitUsage.usage < used)
+ limitUsage.usage = used;
+ return true;
+ }
+
+ limitUsage = new LimitUsage();
+ limitUsage.resourceUnion = resourceUnionId;
+ limitUsage.resourceShareGroupList = resourceShareGroupList;
+ limitUsage.usage = used;
+ limitUsageList.add(limitUsage);
+ return false;
+ }
+
+ private static class LimitUsage {
+
+ @SuppressWarnings("unused")
+ public String resourceUnion;
+ public Set<String> resourceShareGroupList;
+ public long usage;
+ }
+
+ private static boolean hasCommonSharedResource(LimitUsage limitUsage1, LimitUsage limitUsage2) {
+ if (limitUsage1.resourceShareGroupList == null || limitUsage1.resourceShareGroupList.isEmpty())
+ return false;
+ if (limitUsage2.resourceShareGroupList == null || limitUsage2.resourceShareGroupList.isEmpty())
+ return false;
+
+ for (String resourceUnion : limitUsage1.resourceShareGroupList)
+ if (limitUsage2.resourceShareGroupList.contains(resourceUnion))
+ return true;
+
+ return false;
+ }
+
+ private static long calculateUsage(List<LimitUsage> combination) {
+ // All LimitUsage objects that have a common value in their sharedResourceUnionSet reuse the resource, so
+ // split the combination in sets that have common value. Then the usage of each set will be the maximum of
+ // the usages of the LimitUsage objects in the set. The usage of the combination will be the sum of the usages
+ // of all sets.
+ List<List<LimitUsage>> sharedSets = new ArrayList<List<LimitUsage>>();
+ for (LimitUsage limitUsage : combination) {
+ // See if we can put limitUsage in any of the existing sets - is it has a common resource union with
+ // any of the LimitUsage objects in a set.
+ boolean found = false;
+ for (List<LimitUsage> sharedSet : sharedSets) {
+ for (LimitUsage limitUsage1 : sharedSet) {
+ if (hasCommonSharedResource(limitUsage, limitUsage1)) {
+ found = true;
+ break;
+ }
+ }
+ if (found) {
+ sharedSet.add(limitUsage);
+ break;
+ }
+ }
+ if (!found) {
+ // Start a new set
+ List<LimitUsage> newSharedSet = new ArrayList<LimitUsage>();
+ newSharedSet.add(limitUsage);
+ sharedSets.add(newSharedSet);
+ }
+ }
+
+ long sum = 0;
+ for (List<LimitUsage> sharedSet : sharedSets) {
+ float max = 0;
+ for (LimitUsage limitUsage : sharedSet)
+ if (max < limitUsage.usage)
+ max = limitUsage.usage;
+ sum += max;
+ }
+
+ return sum;
+ }
+
+ public static long allocateLimit(LimitResource l, LimitAllocationRequest req, String applicationId) {
+ if (req.allocateCount <= 0)
+ return 0;
+ long uu = l.used;
+
+ LimitAllocationItem lai = (LimitAllocationItem) ResourceUtil.getAllocationItem(l, req.resourceSetId);
+ if (lai == null) {
+ lai = new LimitAllocationItem();
+ lai.resourceType = ResourceType.Limit;
+ lai.resourceKey = new ResourceKey();
+ lai.resourceKey.assetId = req.assetId;
+ lai.resourceKey.resourceName = req.resourceName;
+ lai.applicationId = applicationId;
+ lai.resourceSetId = req.resourceSetId;
+ lai.resourceUnionId = req.resourceUnionId;
+ lai.resourceShareGroupList = req.resourceShareGroupList;
+ lai.used = req.allocateCount;
+
+ if (l.allocationItems == null)
+ l.allocationItems = new ArrayList<AllocationItem>();
+ l.allocationItems.add(lai);
+ } else
+ lai.used = req.replace ? req.allocateCount : lai.used + req.allocateCount;
+
+ lai.allocationTime = new Date();
+
+ recalculate(l);
+
+ return l.used - uu;
+ }
+
+ public static void recalculate(LimitResource l) {
+ l.used = calculateLimitUsage(l, 0, null, null);
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/util/RangeUtil.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/util/RangeUtil.java
index af828314e..27d0e55b3 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/util/RangeUtil.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/util/RangeUtil.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,76 +35,76 @@ import org.openecomp.sdnc.rm.data.ResourceType;
public class RangeUtil {
- public static void recalculate(RangeResource r) {
- r.used = new TreeSet<Integer>();
- if (r.allocationItems != null)
- for (AllocationItem ai : r.allocationItems) {
- RangeAllocationItem rai = (RangeAllocationItem) ai;
- if (rai.used != null)
- r.used.addAll(rai.used);
- }
- }
+ public static void recalculate(RangeResource r) {
+ r.used = new TreeSet<Integer>();
+ if (r.allocationItems != null)
+ for (AllocationItem ai : r.allocationItems) {
+ RangeAllocationItem rai = (RangeAllocationItem) ai;
+ if (rai.used != null)
+ r.used.addAll(rai.used);
+ }
+ }
- public static boolean checkRange(RangeResource r, RangeAllocationRequest req, int num) {
- if (num < req.checkMin || num > req.checkMax)
- return false;
+ public static boolean checkRange(RangeResource r, RangeAllocationRequest req, int num) {
+ if (num < req.checkMin || num > req.checkMax)
+ 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))
- 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))
+ return false;
+ }
- return true;
- }
+ return true;
+ }
- private static boolean eq(Object o1, Object o2) {
- return o1 == null ? o2 == null : o1.equals(o2);
- }
+ private static boolean eq(Object o1, Object o2) {
+ return o1 == null ? o2 == null : o1.equals(o2);
+ }
- public static SortedSet<Integer> getUsed(RangeResource r, String resourceUnionId) {
- SortedSet<Integer> used = new TreeSet<Integer>();
- if (r.allocationItems != null)
- for (AllocationItem ai : r.allocationItems) {
- RangeAllocationItem rai = (RangeAllocationItem) ai;
- if (eq(resourceUnionId, rai.resourceUnionId) && rai.used != null)
- used.addAll(rai.used);
- }
- return used;
- }
+ public static SortedSet<Integer> getUsed(RangeResource r, String resourceUnionId) {
+ SortedSet<Integer> used = new TreeSet<Integer>();
+ if (r.allocationItems != null)
+ for (AllocationItem ai : r.allocationItems) {
+ RangeAllocationItem rai = (RangeAllocationItem) ai;
+ if (eq(resourceUnionId, rai.resourceUnionId) && rai.used != null)
+ used.addAll(rai.used);
+ }
+ return used;
+ }
- public static void allocateRange(
- RangeResource rr,
- SortedSet<Integer> requestedNumbers,
- RangeAllocationRequest req,
- String applicationId) {
- if (!req.allocate)
- return;
+ public static void allocateRange(
+ RangeResource rr,
+ SortedSet<Integer> requestedNumbers,
+ RangeAllocationRequest req,
+ String applicationId) {
+ if (!req.allocate)
+ return;
- RangeAllocationItem rai = (RangeAllocationItem) ResourceUtil.getAllocationItem(rr, req.resourceSetId);
- if (rai == null) {
- rai = new RangeAllocationItem();
- rai.resourceType = ResourceType.Range;
- rai.resourceKey = new ResourceKey();
- rai.resourceKey.assetId = req.assetId;
- rai.resourceKey.resourceName = req.resourceName;
- rai.applicationId = applicationId;
- rai.resourceSetId = req.resourceSetId;
- rai.resourceUnionId = req.resourceUnionId;
- rai.resourceShareGroupList = req.resourceShareGroupList;
- rai.used = requestedNumbers;
+ RangeAllocationItem rai = (RangeAllocationItem) ResourceUtil.getAllocationItem(rr, req.resourceSetId);
+ if (rai == null) {
+ rai = new RangeAllocationItem();
+ rai.resourceType = ResourceType.Range;
+ rai.resourceKey = new ResourceKey();
+ rai.resourceKey.assetId = req.assetId;
+ rai.resourceKey.resourceName = req.resourceName;
+ rai.applicationId = applicationId;
+ rai.resourceSetId = req.resourceSetId;
+ rai.resourceUnionId = req.resourceUnionId;
+ rai.resourceShareGroupList = req.resourceShareGroupList;
+ rai.used = requestedNumbers;
- if (rr.allocationItems == null)
- rr.allocationItems = new ArrayList<AllocationItem>();
- rr.allocationItems.add(rai);
- } else if (req.replace)
- rai.used = requestedNumbers;
- else
- rai.used.addAll(requestedNumbers);
+ if (rr.allocationItems == null)
+ rr.allocationItems = new ArrayList<AllocationItem>();
+ rr.allocationItems.add(rai);
+ } else if (req.replace)
+ rai.used = requestedNumbers;
+ else
+ rai.used.addAll(requestedNumbers);
- rai.allocationTime = new Date();
+ rai.allocationTime = new Date();
- recalculate(rr);
- }
+ recalculate(rr);
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/util/ResourceUtil.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/util/ResourceUtil.java
index 7afe7b5db..0253204c7 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/util/ResourceUtil.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/util/ResourceUtil.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,21 +29,21 @@ import org.openecomp.sdnc.rm.data.ResourceType;
public class ResourceUtil {
- public static AllocationItem getAllocationItem(Resource r, String resourceSetId) {
- if (r.allocationItems != null)
- for (AllocationItem ai : r.allocationItems)
- if (ai.resourceSetId != null && ai.resourceSetId.equals(resourceSetId))
- return ai;
- return null;
- }
+ public static AllocationItem getAllocationItem(Resource r, String resourceSetId) {
+ if (r.allocationItems != null)
+ for (AllocationItem ai : r.allocationItems)
+ if (ai.resourceSetId != null && ai.resourceSetId.equals(resourceSetId))
+ return ai;
+ return null;
+ }
- public static void recalculate(Resource r) {
- if (r == null)
- return;
+ public static void recalculate(Resource r) {
+ if (r == null)
+ return;
- if (r.resourceType == ResourceType.Limit)
- LimitUtil.recalculate((LimitResource) r);
- else if (r.resourceType == ResourceType.Label)
- LabelUtil.recalculate((LabelResource) r);
- }
+ if (r.resourceType == ResourceType.Limit)
+ LimitUtil.recalculate((LimitResource) r);
+ else if (r.resourceType == ResourceType.Label)
+ LabelUtil.recalculate((LabelResource) r);
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/db/CachedDataSourceWrap.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/db/CachedDataSourceWrap.java
index 8918ce0cb..12ba15867 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/db/CachedDataSourceWrap.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/db/CachedDataSourceWrap.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,90 +33,90 @@ import org.slf4j.LoggerFactory;
public class CachedDataSourceWrap implements DataSource {
- private static final Logger log = LoggerFactory.getLogger(CachedDataSourceWrap.class);
-
- private ThreadLocal<ConnectionWrap> con = new ThreadLocal<>();
-
- private DataSource dataSource;
-
- @Override
- public PrintWriter getLogWriter() throws SQLException {
- return dataSource.getLogWriter();
- }
-
- @Override
- public void setLogWriter(PrintWriter out) throws SQLException {
- dataSource.setLogWriter(out);
- }
-
- @Override
- public void setLoginTimeout(int seconds) throws SQLException {
- dataSource.setLoginTimeout(seconds);
- }
-
- @Override
- public int getLoginTimeout() throws SQLException {
- return dataSource.getLoginTimeout();
- }
-
- @Override
- public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException {
- return dataSource.getParentLogger();
- }
-
- @Override
- public <T> T unwrap(Class<T> iface) throws SQLException {
- return dataSource.unwrap(iface);
- }
-
- @Override
- public boolean isWrapperFor(Class<?> iface) throws SQLException {
- return dataSource.isWrapperFor(iface);
- }
-
- @Override
- public Connection getConnection() throws SQLException {
- if (con.get() == null) {
- Connection c = dataSource.getConnection();
- ConnectionWrap cc = new ConnectionWrap(c);
- con.set(cc);
-
- log.info("Got new DB connection: " + c);
- } else
- log.info("Using thread DB connection: " + con.get().getCon());
-
- return con.get();
- }
-
- @Override
- public Connection getConnection(String username, String password) throws SQLException {
- if (con.get() == null) {
- Connection c = dataSource.getConnection(username, password);
- ConnectionWrap cc = new ConnectionWrap(c);
- con.set(cc);
-
- log.info("Got new DB connection: " + c);
- } else
- log.info("Using thread DB connection: " + con.get().getCon());
-
- return con.get();
- }
-
- public void releaseConnection() {
- if (con.get() != null) {
- try {
- con.get().realClose();
-
- log.info("DB Connection released: " + con.get().getCon());
- } catch (SQLException e) {
- log.warn("Failed to release DB connection", e);
- } finally {
- con.remove();
- }
- }
- }
-
- public void setDataSource(DataSource dataSource) {
- this.dataSource = dataSource;
- }
+ private static final Logger log = LoggerFactory.getLogger(CachedDataSourceWrap.class);
+
+ private ThreadLocal<ConnectionWrap> con = new ThreadLocal<>();
+
+ private DataSource dataSource;
+
+ @Override
+ public PrintWriter getLogWriter() throws SQLException {
+ return dataSource.getLogWriter();
+ }
+
+ @Override
+ public void setLogWriter(PrintWriter out) throws SQLException {
+ dataSource.setLogWriter(out);
+ }
+
+ @Override
+ public void setLoginTimeout(int seconds) throws SQLException {
+ dataSource.setLoginTimeout(seconds);
+ }
+
+ @Override
+ public int getLoginTimeout() throws SQLException {
+ return dataSource.getLoginTimeout();
+ }
+
+ @Override
+ public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException {
+ return dataSource.getParentLogger();
+ }
+
+ @Override
+ public <T> T unwrap(Class<T> iface) throws SQLException {
+ return dataSource.unwrap(iface);
+ }
+
+ @Override
+ public boolean isWrapperFor(Class<?> iface) throws SQLException {
+ return dataSource.isWrapperFor(iface);
+ }
+
+ @Override
+ public Connection getConnection() throws SQLException {
+ if (con.get() == null) {
+ Connection c = dataSource.getConnection();
+ ConnectionWrap cc = new ConnectionWrap(c);
+ con.set(cc);
+
+ log.info("Got new DB connection: " + c);
+ } else
+ log.info("Using thread DB connection: " + con.get().getCon());
+
+ return con.get();
+ }
+
+ @Override
+ public Connection getConnection(String username, String password) throws SQLException {
+ if (con.get() == null) {
+ Connection c = dataSource.getConnection(username, password);
+ ConnectionWrap cc = new ConnectionWrap(c);
+ con.set(cc);
+
+ log.info("Got new DB connection: " + c);
+ } else
+ log.info("Using thread DB connection: " + con.get().getCon());
+
+ return con.get();
+ }
+
+ public void releaseConnection() {
+ if (con.get() != null) {
+ try {
+ con.get().realClose();
+
+ log.info("DB Connection released: " + con.get().getCon());
+ } catch (SQLException e) {
+ log.warn("Failed to release DB connection", e);
+ } finally {
+ con.remove();
+ }
+ }
+ }
+
+ public void setDataSource(DataSource dataSource) {
+ this.dataSource = dataSource;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/db/ConnectionWrap.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/db/ConnectionWrap.java
index 1927fdb9c..11560498b 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/db/ConnectionWrap.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/db/ConnectionWrap.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -42,297 +42,297 @@ import java.util.concurrent.Executor;
public class ConnectionWrap implements Connection {
- private Connection cc;
-
- public ConnectionWrap(Connection cc) {
- super();
- this.cc = cc;
- }
-
- public Connection getCon() {
- return cc;
- }
-
- public void realClose() throws SQLException {
- cc.close();
- }
-
- @Override
- public <T> T unwrap(Class<T> iface) throws SQLException {
- return cc.unwrap(iface);
- }
-
- @Override
- public boolean isWrapperFor(Class<?> iface) throws SQLException {
- return cc.isWrapperFor(iface);
- }
-
- @Override
- public Statement createStatement() throws SQLException {
- return cc.createStatement();
- }
-
- @Override
- public PreparedStatement prepareStatement(String sql) throws SQLException {
- return cc.prepareStatement(sql);
- }
-
- @Override
- public CallableStatement prepareCall(String sql) throws SQLException {
- return cc.prepareCall(sql);
- }
-
- @Override
- public String nativeSQL(String sql) throws SQLException {
- return cc.nativeSQL(sql);
- }
-
- @Override
- public void setAutoCommit(boolean autoCommit) throws SQLException {
- cc.setAutoCommit(autoCommit);
- }
-
- @Override
- public boolean getAutoCommit() throws SQLException {
- return cc.getAutoCommit();
- }
-
- @Override
- public void commit() throws SQLException {
- cc.commit();
- }
-
- @Override
- public void rollback() throws SQLException {
- cc.rollback();
- }
-
- @Override
- public void close() throws SQLException {
- }
-
- @Override
- public boolean isClosed() throws SQLException {
- return cc.isClosed();
- }
-
- @Override
- public DatabaseMetaData getMetaData() throws SQLException {
- return cc.getMetaData();
- }
-
- @Override
- public void setReadOnly(boolean readOnly) throws SQLException {
- cc.setReadOnly(readOnly);
- }
-
- @Override
- public boolean isReadOnly() throws SQLException {
- return cc.isReadOnly();
- }
-
- @Override
- public void setCatalog(String catalog) throws SQLException {
- cc.setCatalog(catalog);
- }
-
- @Override
- public String getCatalog() throws SQLException {
- return cc.getCatalog();
- }
-
- @Override
- public void setTransactionIsolation(int level) throws SQLException {
- cc.setTransactionIsolation(level);
- }
-
- @Override
- public int getTransactionIsolation() throws SQLException {
- return cc.getTransactionIsolation();
- }
-
- @Override
- public SQLWarning getWarnings() throws SQLException {
- return cc.getWarnings();
- }
-
- @Override
- public void clearWarnings() throws SQLException {
- cc.clearWarnings();
- }
-
- @Override
- public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
- return cc.createStatement(resultSetType, resultSetConcurrency);
- }
-
- @Override
- public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
- throws SQLException {
- return cc.prepareStatement(sql, resultSetType, resultSetConcurrency);
- }
-
- @Override
- public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
- return cc.prepareCall(sql, resultSetType, resultSetConcurrency);
- }
-
- @Override
- public Map<String, Class<?>> getTypeMap() throws SQLException {
- return cc.getTypeMap();
- }
-
- @Override
- public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
- cc.setTypeMap(map);
- }
-
- @Override
- public void setHoldability(int holdability) throws SQLException {
- cc.setHoldability(holdability);
- }
-
- @Override
- public int getHoldability() throws SQLException {
- return cc.getHoldability();
- }
-
- @Override
- public Savepoint setSavepoint() throws SQLException {
- return cc.setSavepoint();
- }
-
- @Override
- public Savepoint setSavepoint(String name) throws SQLException {
- return cc.setSavepoint(name);
- }
-
- @Override
- public void rollback(Savepoint savepoint) throws SQLException {
- cc.rollback(savepoint);
- }
-
- @Override
- public void releaseSavepoint(Savepoint savepoint) throws SQLException {
- cc.releaseSavepoint(savepoint);
- }
-
- @Override
- public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
- throws SQLException {
- return cc.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
- }
-
- @Override
- public PreparedStatement prepareStatement(
- String sql,
- int resultSetType,
- int resultSetConcurrency,
- int resultSetHoldability) throws SQLException {
- return cc.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
- }
-
- @Override
- public CallableStatement prepareCall(
- String sql,
- int resultSetType,
- int resultSetConcurrency,
- int resultSetHoldability) throws SQLException {
- return cc.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
- }
-
- @Override
- public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
- return cc.prepareStatement(sql, autoGeneratedKeys);
- }
-
- @Override
- public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
- return cc.prepareStatement(sql, columnIndexes);
- }
-
- @Override
- public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
- return cc.prepareStatement(sql, columnNames);
- }
-
- @Override
- public Clob createClob() throws SQLException {
- return cc.createClob();
- }
-
- @Override
- public Blob createBlob() throws SQLException {
- return cc.createBlob();
- }
-
- @Override
- public NClob createNClob() throws SQLException {
- return cc.createNClob();
- }
-
- @Override
- public SQLXML createSQLXML() throws SQLException {
- return cc.createSQLXML();
- }
-
- @Override
- public boolean isValid(int timeout) throws SQLException {
- return cc.isValid(timeout);
- }
-
- @Override
- public void setClientInfo(String name, String value) throws SQLClientInfoException {
- cc.setClientInfo(name, value);
- }
-
- @Override
- public void setClientInfo(Properties properties) throws SQLClientInfoException {
- cc.setClientInfo(properties);
- }
-
- @Override
- public String getClientInfo(String name) throws SQLException {
- return cc.getClientInfo(name);
- }
-
- @Override
- public Properties getClientInfo() throws SQLException {
- return cc.getClientInfo();
- }
-
- @Override
- public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
- return cc.createArrayOf(typeName, elements);
- }
-
- @Override
- public Struct createStruct(String typeName, Object[] attributes) throws SQLException {
- return cc.createStruct(typeName, attributes);
- }
-
- @Override
- public void setSchema(String schema) throws SQLException {
- cc.setSchema(schema);
- }
-
- @Override
- public String getSchema() throws SQLException {
- return cc.getSchema();
- }
-
- @Override
- public void abort(Executor executor) throws SQLException {
- cc.abort(executor);
- }
-
- @Override
- public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException {
- cc.setNetworkTimeout(executor, milliseconds);
- }
-
- @Override
- public int getNetworkTimeout() throws SQLException {
- return cc.getNetworkTimeout();
- }
+ private Connection cc;
+
+ public ConnectionWrap(Connection cc) {
+ super();
+ this.cc = cc;
+ }
+
+ public Connection getCon() {
+ return cc;
+ }
+
+ public void realClose() throws SQLException {
+ cc.close();
+ }
+
+ @Override
+ public <T> T unwrap(Class<T> iface) throws SQLException {
+ return cc.unwrap(iface);
+ }
+
+ @Override
+ public boolean isWrapperFor(Class<?> iface) throws SQLException {
+ return cc.isWrapperFor(iface);
+ }
+
+ @Override
+ public Statement createStatement() throws SQLException {
+ return cc.createStatement();
+ }
+
+ @Override
+ public PreparedStatement prepareStatement(String sql) throws SQLException {
+ return cc.prepareStatement(sql);
+ }
+
+ @Override
+ public CallableStatement prepareCall(String sql) throws SQLException {
+ return cc.prepareCall(sql);
+ }
+
+ @Override
+ public String nativeSQL(String sql) throws SQLException {
+ return cc.nativeSQL(sql);
+ }
+
+ @Override
+ public void setAutoCommit(boolean autoCommit) throws SQLException {
+ cc.setAutoCommit(autoCommit);
+ }
+
+ @Override
+ public boolean getAutoCommit() throws SQLException {
+ return cc.getAutoCommit();
+ }
+
+ @Override
+ public void commit() throws SQLException {
+ cc.commit();
+ }
+
+ @Override
+ public void rollback() throws SQLException {
+ cc.rollback();
+ }
+
+ @Override
+ public void close() throws SQLException {
+ }
+
+ @Override
+ public boolean isClosed() throws SQLException {
+ return cc.isClosed();
+ }
+
+ @Override
+ public DatabaseMetaData getMetaData() throws SQLException {
+ return cc.getMetaData();
+ }
+
+ @Override
+ public void setReadOnly(boolean readOnly) throws SQLException {
+ cc.setReadOnly(readOnly);
+ }
+
+ @Override
+ public boolean isReadOnly() throws SQLException {
+ return cc.isReadOnly();
+ }
+
+ @Override
+ public void setCatalog(String catalog) throws SQLException {
+ cc.setCatalog(catalog);
+ }
+
+ @Override
+ public String getCatalog() throws SQLException {
+ return cc.getCatalog();
+ }
+
+ @Override
+ public void setTransactionIsolation(int level) throws SQLException {
+ cc.setTransactionIsolation(level);
+ }
+
+ @Override
+ public int getTransactionIsolation() throws SQLException {
+ return cc.getTransactionIsolation();
+ }
+
+ @Override
+ public SQLWarning getWarnings() throws SQLException {
+ return cc.getWarnings();
+ }
+
+ @Override
+ public void clearWarnings() throws SQLException {
+ cc.clearWarnings();
+ }
+
+ @Override
+ public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
+ return cc.createStatement(resultSetType, resultSetConcurrency);
+ }
+
+ @Override
+ public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
+ throws SQLException {
+ return cc.prepareStatement(sql, resultSetType, resultSetConcurrency);
+ }
+
+ @Override
+ public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
+ return cc.prepareCall(sql, resultSetType, resultSetConcurrency);
+ }
+
+ @Override
+ public Map<String, Class<?>> getTypeMap() throws SQLException {
+ return cc.getTypeMap();
+ }
+
+ @Override
+ public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
+ cc.setTypeMap(map);
+ }
+
+ @Override
+ public void setHoldability(int holdability) throws SQLException {
+ cc.setHoldability(holdability);
+ }
+
+ @Override
+ public int getHoldability() throws SQLException {
+ return cc.getHoldability();
+ }
+
+ @Override
+ public Savepoint setSavepoint() throws SQLException {
+ return cc.setSavepoint();
+ }
+
+ @Override
+ public Savepoint setSavepoint(String name) throws SQLException {
+ return cc.setSavepoint(name);
+ }
+
+ @Override
+ public void rollback(Savepoint savepoint) throws SQLException {
+ cc.rollback(savepoint);
+ }
+
+ @Override
+ public void releaseSavepoint(Savepoint savepoint) throws SQLException {
+ cc.releaseSavepoint(savepoint);
+ }
+
+ @Override
+ public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
+ throws SQLException {
+ return cc.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability);
+ }
+
+ @Override
+ public PreparedStatement prepareStatement(
+ String sql,
+ int resultSetType,
+ int resultSetConcurrency,
+ int resultSetHoldability) throws SQLException {
+ return cc.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
+ }
+
+ @Override
+ public CallableStatement prepareCall(
+ String sql,
+ int resultSetType,
+ int resultSetConcurrency,
+ int resultSetHoldability) throws SQLException {
+ return cc.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
+ }
+
+ @Override
+ public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
+ return cc.prepareStatement(sql, autoGeneratedKeys);
+ }
+
+ @Override
+ public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
+ return cc.prepareStatement(sql, columnIndexes);
+ }
+
+ @Override
+ public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
+ return cc.prepareStatement(sql, columnNames);
+ }
+
+ @Override
+ public Clob createClob() throws SQLException {
+ return cc.createClob();
+ }
+
+ @Override
+ public Blob createBlob() throws SQLException {
+ return cc.createBlob();
+ }
+
+ @Override
+ public NClob createNClob() throws SQLException {
+ return cc.createNClob();
+ }
+
+ @Override
+ public SQLXML createSQLXML() throws SQLException {
+ return cc.createSQLXML();
+ }
+
+ @Override
+ public boolean isValid(int timeout) throws SQLException {
+ return cc.isValid(timeout);
+ }
+
+ @Override
+ public void setClientInfo(String name, String value) throws SQLClientInfoException {
+ cc.setClientInfo(name, value);
+ }
+
+ @Override
+ public void setClientInfo(Properties properties) throws SQLClientInfoException {
+ cc.setClientInfo(properties);
+ }
+
+ @Override
+ public String getClientInfo(String name) throws SQLException {
+ return cc.getClientInfo(name);
+ }
+
+ @Override
+ public Properties getClientInfo() throws SQLException {
+ return cc.getClientInfo();
+ }
+
+ @Override
+ public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
+ return cc.createArrayOf(typeName, elements);
+ }
+
+ @Override
+ public Struct createStruct(String typeName, Object[] attributes) throws SQLException {
+ return cc.createStruct(typeName, attributes);
+ }
+
+ @Override
+ public void setSchema(String schema) throws SQLException {
+ cc.setSchema(schema);
+ }
+
+ @Override
+ public String getSchema() throws SQLException {
+ return cc.getSchema();
+ }
+
+ @Override
+ public void abort(Executor executor) throws SQLException {
+ cc.abort(executor);
+ }
+
+ @Override
+ public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException {
+ cc.setNetworkTimeout(executor, milliseconds);
+ }
+
+ @Override
+ public int getNetworkTimeout() throws SQLException {
+ return cc.getNetworkTimeout();
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/db/DataSourceWrap.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/db/DataSourceWrap.java
index d729e127d..b01b31f9f 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/db/DataSourceWrap.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/db/DataSourceWrap.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,66 +33,66 @@ import org.slf4j.LoggerFactory;
public class DataSourceWrap implements DataSource {
- private static final Logger log = LoggerFactory.getLogger(DataSourceWrap.class);
+ private static final Logger log = LoggerFactory.getLogger(DataSourceWrap.class);
- private DataSource dataSource;
+ private DataSource dataSource;
- @Override
- public PrintWriter getLogWriter() throws SQLException {
- return dataSource.getLogWriter();
- }
+ @Override
+ public PrintWriter getLogWriter() throws SQLException {
+ return dataSource.getLogWriter();
+ }
- @Override
- public void setLogWriter(PrintWriter out) throws SQLException {
- dataSource.setLogWriter(out);
- }
+ @Override
+ public void setLogWriter(PrintWriter out) throws SQLException {
+ dataSource.setLogWriter(out);
+ }
- @Override
- public void setLoginTimeout(int seconds) throws SQLException {
- dataSource.setLoginTimeout(seconds);
- }
+ @Override
+ public void setLoginTimeout(int seconds) throws SQLException {
+ dataSource.setLoginTimeout(seconds);
+ }
- @Override
- public int getLoginTimeout() throws SQLException {
- return dataSource.getLoginTimeout();
- }
+ @Override
+ public int getLoginTimeout() throws SQLException {
+ return dataSource.getLoginTimeout();
+ }
- @Override
- public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException {
- return dataSource.getParentLogger();
- }
+ @Override
+ public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedException {
+ return dataSource.getParentLogger();
+ }
- @Override
- public <T> T unwrap(Class<T> iface) throws SQLException {
- return dataSource.unwrap(iface);
- }
+ @Override
+ public <T> T unwrap(Class<T> iface) throws SQLException {
+ return dataSource.unwrap(iface);
+ }
- @Override
- public boolean isWrapperFor(Class<?> iface) throws SQLException {
- return dataSource.isWrapperFor(iface);
- }
+ @Override
+ public boolean isWrapperFor(Class<?> iface) throws SQLException {
+ return dataSource.isWrapperFor(iface);
+ }
- @Override
- public Connection getConnection() throws SQLException {
- Connection c = dataSource.getConnection();
+ @Override
+ public Connection getConnection() throws SQLException {
+ Connection c = dataSource.getConnection();
- log.debug("getConnection: " + c.getClass().getName());
+ log.debug("getConnection: " + c.getClass().getName());
- c.setAutoCommit(true);
- return c;
- }
+ c.setAutoCommit(true);
+ return c;
+ }
- @Override
- public Connection getConnection(String username, String password) throws SQLException {
- Connection c = dataSource.getConnection(username, password);
+ @Override
+ public Connection getConnection(String username, String password) throws SQLException {
+ Connection c = dataSource.getConnection(username, password);
- log.debug("getConnection: " + c.getClass().getName());
+ log.debug("getConnection: " + c.getClass().getName());
- c.setAutoCommit(true);
- return c;
- }
+ c.setAutoCommit(true);
+ return c;
+ }
- public void setDataSource(DataSource dataSource) {
- this.dataSource = dataSource;
- }
+ public void setDataSource(DataSource dataSource) {
+ this.dataSource = dataSource;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/expr/ExpressionEvaluator.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/expr/ExpressionEvaluator.java
index ff15d770b..345a6263c 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/expr/ExpressionEvaluator.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/expr/ExpressionEvaluator.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,183 +25,183 @@ import java.util.Map;
public class ExpressionEvaluator {
- public static long evalLong(String expr, Map<String, Object> vars) {
- return (long) evalFloat(expr, vars);
- }
-
- public static float evalFloat(String expr, Map<String, Object> vars) {
- expr = expr.trim();
- int sl = expr.length();
- if (sl == 0)
- throw new IllegalArgumentException("Cannot interpret empty string.");
-
- // Remove parentheses if any
- if (expr.charAt(0) == '(' && expr.charAt(sl - 1) == ')')
- return evalFloat(expr.substring(1, sl - 1), vars);
-
- // Look for operators in the order of least priority
- String[] sss = findOperator(expr, "-", true);
- if (sss != null)
- return evalFloat(sss[0], vars) - evalFloat(sss[1], vars);
-
- sss = findOperator(expr, "+", true);
- if (sss != null)
- return evalFloat(sss[0], vars) + evalFloat(sss[1], vars);
-
- sss = findOperator(expr, "/", true);
- if (sss != null)
- return evalFloat(sss[0], vars) / evalFloat(sss[1], vars);
-
- sss = findOperator(expr, "*", true);
- if (sss != null)
- return evalFloat(sss[0], vars) * evalFloat(sss[1], vars);
-
- // Check if expr is a number
- try {
- return Float.valueOf(expr);
- } catch (Exception e) {
- }
-
- // Must be a variable
- Object v = vars.get(expr);
- if (v != null) {
- if (v instanceof Float)
- return (Float) v;
- if (v instanceof Long)
- return (Long) v;
- if (v instanceof Integer)
- return (Integer) v;
- }
- return 0;
- }
-
- public static boolean evalBoolean(String expr, Map<String, Object> vars) {
- expr = expr.trim();
- int sl = expr.length();
- if (sl == 0)
- throw new IllegalArgumentException("Cannot interpret empty string.");
-
- if (expr.equalsIgnoreCase("true"))
- return true;
-
- if (expr.equalsIgnoreCase("false"))
- return false;
-
- // Remove parentheses if any
- if (expr.charAt(0) == '(' && expr.charAt(sl - 1) == ')')
- return evalBoolean(expr.substring(1, sl - 1), vars);
-
- // Look for operators in the order of least priority
- String[] sss = findOperator(expr, "or", true);
- if (sss != null)
- return evalBoolean(sss[0], vars) || evalBoolean(sss[1], vars);
-
- sss = findOperator(expr, "and", true);
- if (sss != null)
- return evalBoolean(sss[0], vars) && evalBoolean(sss[1], vars);
-
- sss = findOperator(expr, "not", true);
- if (sss != null)
- return !evalBoolean(sss[1], vars);
-
- sss = findOperator(expr, "!=", false);
- if (sss == null)
- sss = findOperator(expr, "<>", false);
- if (sss != null)
- return evalLong(sss[0], vars) != evalLong(sss[1], vars);
-
- sss = findOperator(expr, "==", false);
- if (sss == null)
- sss = findOperator(expr, "=", false);
- if (sss != null)
- return evalLong(sss[0], vars) == evalLong(sss[1], vars);
-
- sss = findOperator(expr, ">=", false);
- if (sss != null)
- return evalLong(sss[0], vars) >= evalLong(sss[1], vars);
-
- sss = findOperator(expr, ">", false);
- if (sss != null)
- return evalLong(sss[0], vars) > evalLong(sss[1], vars);
-
- sss = findOperator(expr, "<=", false);
- if (sss != null)
- return evalLong(sss[0], vars) <= evalLong(sss[1], vars);
-
- sss = findOperator(expr, "<", false);
- if (sss != null)
- return evalLong(sss[0], vars) < evalLong(sss[1], vars);
-
- throw new IllegalArgumentException("Cannot interpret '" + expr + "': Invalid expression.");
- }
-
- private static String[] findOperator(String s, String op, boolean delimiterRequired) {
- int opl = op.length();
- int sl = s.length();
- String delimiters = " \0\t\r\n()";
- int pcount = 0, qcount = 0;
- for (int i = 0; i < sl; i++) {
- char c = s.charAt(i);
- if (c == '(' && qcount == 0)
- pcount++;
- else if (c == ')' && qcount == 0) {
- pcount--;
- if (pcount < 0)
- throw new IllegalArgumentException("Cannot interpret '" + s + "': Parentheses do not match.");
- } else if (c == '\'')
- qcount = (qcount + 1) % 2;
- else if (i <= sl - opl && pcount == 0 && qcount == 0) {
- String ss = s.substring(i, i + opl);
- if (ss.equalsIgnoreCase(op)) {
- boolean found = true;
- if (delimiterRequired) {
- // Check for delimiter before and after to make sure it is not part of another word
- char chbefore = '\0';
- if (i > 0)
- chbefore = s.charAt(i - 1);
- char chafter = '\0';
- if (i < sl - opl)
- chafter = s.charAt(i + opl);
- found = delimiters.indexOf(chbefore) >= 0 && delimiters.indexOf(chafter) >= 0;
- }
- if (found) {
- // We've found the operator, split the string
- String[] sss = new String[2];
- sss[0] = s.substring(0, i);
- sss[1] = s.substring(i + opl);
- return sss;
- }
- }
- }
- }
- if (pcount > 0)
- throw new IllegalArgumentException("Cannot interpret '" + s + "': Parentheses do not match.");
- if (qcount > 0)
- throw new IllegalArgumentException("Cannot interpret '" + s + "': No closing '.");
- return null;
- }
-
- private static Object parseObject(String s) {
- s = s.trim();
- int sl = s.length();
- if (sl == 0)
- throw new IllegalArgumentException("Cannot interpret empty string.");
- if (s.equalsIgnoreCase("null"))
- return null;
- if (s.charAt(0) == '\'') {
- if (sl < 2 || s.charAt(sl - 1) != '\'')
- throw new IllegalArgumentException("Cannot interpret '" + s + "': No closing '.");
- return s.substring(1, sl - 1);
- }
- // Not in quotes - must be a number
- try {
- return Long.valueOf(s);
- } catch (Exception e) {
- }
- try {
- return Double.valueOf(s);
- } catch (Exception e) {
- throw new IllegalArgumentException("Cannot interpret '" + s + "': Invalid number.");
- }
- }
+ public static long evalLong(String expr, Map<String, Object> vars) {
+ return (long) evalFloat(expr, vars);
+ }
+
+ public static float evalFloat(String expr, Map<String, Object> vars) {
+ expr = expr.trim();
+ int sl = expr.length();
+ if (sl == 0)
+ throw new IllegalArgumentException("Cannot interpret empty string.");
+
+ // Remove parentheses if any
+ if (expr.charAt(0) == '(' && expr.charAt(sl - 1) == ')')
+ return evalFloat(expr.substring(1, sl - 1), vars);
+
+ // Look for operators in the order of least priority
+ String[] sss = findOperator(expr, "-", true);
+ if (sss != null)
+ return evalFloat(sss[0], vars) - evalFloat(sss[1], vars);
+
+ sss = findOperator(expr, "+", true);
+ if (sss != null)
+ return evalFloat(sss[0], vars) + evalFloat(sss[1], vars);
+
+ sss = findOperator(expr, "/", true);
+ if (sss != null)
+ return evalFloat(sss[0], vars) / evalFloat(sss[1], vars);
+
+ sss = findOperator(expr, "*", true);
+ if (sss != null)
+ return evalFloat(sss[0], vars) * evalFloat(sss[1], vars);
+
+ // Check if expr is a number
+ try {
+ return Float.valueOf(expr);
+ } catch (Exception e) {
+ }
+
+ // Must be a variable
+ Object v = vars.get(expr);
+ if (v != null) {
+ if (v instanceof Float)
+ return (Float) v;
+ if (v instanceof Long)
+ return (Long) v;
+ if (v instanceof Integer)
+ return (Integer) v;
+ }
+ return 0;
+ }
+
+ public static boolean evalBoolean(String expr, Map<String, Object> vars) {
+ expr = expr.trim();
+ int sl = expr.length();
+ if (sl == 0)
+ throw new IllegalArgumentException("Cannot interpret empty string.");
+
+ if (expr.equalsIgnoreCase("true"))
+ return true;
+
+ if (expr.equalsIgnoreCase("false"))
+ return false;
+
+ // Remove parentheses if any
+ if (expr.charAt(0) == '(' && expr.charAt(sl - 1) == ')')
+ return evalBoolean(expr.substring(1, sl - 1), vars);
+
+ // Look for operators in the order of least priority
+ String[] sss = findOperator(expr, "or", true);
+ if (sss != null)
+ return evalBoolean(sss[0], vars) || evalBoolean(sss[1], vars);
+
+ sss = findOperator(expr, "and", true);
+ if (sss != null)
+ return evalBoolean(sss[0], vars) && evalBoolean(sss[1], vars);
+
+ sss = findOperator(expr, "not", true);
+ if (sss != null)
+ return !evalBoolean(sss[1], vars);
+
+ sss = findOperator(expr, "!=", false);
+ if (sss == null)
+ sss = findOperator(expr, "<>", false);
+ if (sss != null)
+ return evalLong(sss[0], vars) != evalLong(sss[1], vars);
+
+ sss = findOperator(expr, "==", false);
+ if (sss == null)
+ sss = findOperator(expr, "=", false);
+ if (sss != null)
+ return evalLong(sss[0], vars) == evalLong(sss[1], vars);
+
+ sss = findOperator(expr, ">=", false);
+ if (sss != null)
+ return evalLong(sss[0], vars) >= evalLong(sss[1], vars);
+
+ sss = findOperator(expr, ">", false);
+ if (sss != null)
+ return evalLong(sss[0], vars) > evalLong(sss[1], vars);
+
+ sss = findOperator(expr, "<=", false);
+ if (sss != null)
+ return evalLong(sss[0], vars) <= evalLong(sss[1], vars);
+
+ sss = findOperator(expr, "<", false);
+ if (sss != null)
+ return evalLong(sss[0], vars) < evalLong(sss[1], vars);
+
+ throw new IllegalArgumentException("Cannot interpret '" + expr + "': Invalid expression.");
+ }
+
+ private static String[] findOperator(String s, String op, boolean delimiterRequired) {
+ int opl = op.length();
+ int sl = s.length();
+ String delimiters = " \0\t\r\n()";
+ int pcount = 0, qcount = 0;
+ for (int i = 0; i < sl; i++) {
+ char c = s.charAt(i);
+ if (c == '(' && qcount == 0)
+ pcount++;
+ else if (c == ')' && qcount == 0) {
+ pcount--;
+ if (pcount < 0)
+ throw new IllegalArgumentException("Cannot interpret '" + s + "': Parentheses do not match.");
+ } else if (c == '\'')
+ qcount = (qcount + 1) % 2;
+ else if (i <= sl - opl && pcount == 0 && qcount == 0) {
+ String ss = s.substring(i, i + opl);
+ if (ss.equalsIgnoreCase(op)) {
+ boolean found = true;
+ if (delimiterRequired) {
+ // Check for delimiter before and after to make sure it is not part of another word
+ char chbefore = '\0';
+ if (i > 0)
+ chbefore = s.charAt(i - 1);
+ char chafter = '\0';
+ if (i < sl - opl)
+ chafter = s.charAt(i + opl);
+ found = delimiters.indexOf(chbefore) >= 0 && delimiters.indexOf(chafter) >= 0;
+ }
+ if (found) {
+ // We've found the operator, split the string
+ String[] sss = new String[2];
+ sss[0] = s.substring(0, i);
+ sss[1] = s.substring(i + opl);
+ return sss;
+ }
+ }
+ }
+ }
+ if (pcount > 0)
+ throw new IllegalArgumentException("Cannot interpret '" + s + "': Parentheses do not match.");
+ if (qcount > 0)
+ throw new IllegalArgumentException("Cannot interpret '" + s + "': No closing '.");
+ return null;
+ }
+
+ private static Object parseObject(String s) {
+ s = s.trim();
+ int sl = s.length();
+ if (sl == 0)
+ throw new IllegalArgumentException("Cannot interpret empty string.");
+ if (s.equalsIgnoreCase("null"))
+ return null;
+ if (s.charAt(0) == '\'') {
+ if (sl < 2 || s.charAt(sl - 1) != '\'')
+ throw new IllegalArgumentException("Cannot interpret '" + s + "': No closing '.");
+ return s.substring(1, sl - 1);
+ }
+ // Not in quotes - must be a number
+ try {
+ return Long.valueOf(s);
+ } catch (Exception e) {
+ }
+ try {
+ return Double.valueOf(s);
+ } catch (Exception e) {
+ throw new IllegalArgumentException("Cannot interpret '" + s + "': Invalid number.");
+ }
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/speed/SpeedUtil.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/speed/SpeedUtil.java
index 8a0b006bf..f382a6393 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/speed/SpeedUtil.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/speed/SpeedUtil.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,19 +23,19 @@ package org.openecomp.sdnc.util.speed;
public class SpeedUtil {
- private long unitFactor = 1000;
+ private long unitFactor = 1000;
- public long convertToKbps(long maxSpeed, String unit) {
- if (unit.equalsIgnoreCase("kbps"))
- return maxSpeed;
- if (unit.equalsIgnoreCase("Mbps"))
- return maxSpeed * unitFactor;
- if (unit.equalsIgnoreCase("Gbps"))
- return maxSpeed * unitFactor * unitFactor;
- return 0;
- }
+ public long convertToKbps(long maxSpeed, String unit) {
+ if (unit.equalsIgnoreCase("kbps"))
+ return maxSpeed;
+ if (unit.equalsIgnoreCase("Mbps"))
+ return maxSpeed * unitFactor;
+ if (unit.equalsIgnoreCase("Gbps"))
+ return maxSpeed * unitFactor * unitFactor;
+ return 0;
+ }
- public void setUnitFactor(long unitFactor) {
- this.unitFactor = unitFactor;
- }
+ public void setUnitFactor(long unitFactor) {
+ this.unitFactor = unitFactor;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/str/StrUtil.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/str/StrUtil.java
index 02857e105..f7fa81d18 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/str/StrUtil.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/str/StrUtil.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,269 +37,269 @@ import org.slf4j.LoggerFactory;
public class StrUtil {
- private static final Logger log = LoggerFactory.getLogger(StrUtil.class);
-
- public static final String INDENT_STR = " ";
-
- public static void indent(StringBuilder ss, int ind) {
- for (int i = 0; i < ind; i++)
- ss.append(INDENT_STR);
- }
-
- public static void info(Logger log, Object o) {
- if (log.isInfoEnabled()) {
- StringBuilder ss = new StringBuilder();
- struct(ss, o);
- log.info(ss.toString());
- }
- }
-
- public static void debug(Logger log, Object o) {
- if (log.isDebugEnabled()) {
- StringBuilder ss = new StringBuilder();
- struct(ss, o);
- log.debug(ss.toString());
- }
- }
-
- public static void struct(StringBuilder ss, Object o) {
- struct(ss, o, 0);
- }
-
- public static void struct(StringBuilder ss, Object o, int ind) {
- if (o == null) {
- ss.append("null");
- return;
- }
-
- if (isSimple(o)) {
- ss.append(o);
- return;
- }
-
- Class<? extends Object> cls = o.getClass();
-
- if (cls.isEnum()) {
- ss.append(o);
- return;
- }
-
- if (cls.isArray()) {
- int n = Array.getLength(o);
- if (n == 0) {
- ss.append("[]");
- return;
- }
-
- Object o1 = Array.get(o, 0);
- if (isSimple(o1)) {
- ss.append('[').append(o1);
- for (int i = 1; i < n; i++) {
- o1 = Array.get(o, i);
- ss.append(", ").append(o1);
- }
- ss.append(']');
- return;
- }
-
- ss.append('\n');
- indent(ss, ind + 1);
- ss.append('[');
- struct(ss, o1, ind + 1);
- for (int i = 1; i < n; i++) {
- o1 = Array.get(o, i);
- struct(ss, o1, ind + 1);
- }
- ss.append('\n');
- indent(ss, ind + 1);
- ss.append(']');
- return;
- }
-
- if (o instanceof Collection<?>) {
- Collection<?> ll = (Collection<?>) o;
-
- int n = ll.size();
- if (n == 0) {
- ss.append("[]");
- return;
- }
-
- Iterator<?> ii = ll.iterator();
- Object o1 = ii.next();
- if (isSimple(o1)) {
- ss.append('[').append(o1);
- while (ii.hasNext()) {
- o1 = ii.next();
- ss.append(", ").append(o1);
- }
- ss.append(']');
- return;
- }
-
- ss.append('\n');
- indent(ss, ind + 1);
- ss.append('[');
- struct(ss, o1, ind + 1);
- while (ii.hasNext()) {
- o1 = ii.next();
- struct(ss, o1, ind + 1);
- }
- ss.append('\n');
- indent(ss, ind + 1);
- ss.append(']');
- return;
-
- }
-
- if (o instanceof Map<?, ?>) {
- Map<?, ?> mm = (Map<?, ?>) o;
-
- int n = mm.size();
- if (n == 0) {
- ss.append("{}");
- return;
- }
-
- ss.append('{');
-
- for (Object k : mm.keySet()) {
- ss.append('\n');
- indent(ss, ind + 1);
- ss.append(k).append(": ");
-
- Object o1 = mm.get(k);
- struct(ss, o1, ind + 2);
- }
-
- ss.append('\n');
- indent(ss, ind);
- ss.append('}');
-
- return;
- }
-
- Field[] fields = cls.getFields();
-
- if (fields.length == 0) {
- ss.append(o);
- return;
- }
-
- ss.append('\n');
- indent(ss, ind + 1);
- ss.append('<').append(cls.getSimpleName()).append("> {");
- for (Field f : fields) {
- ss.append('\n');
- indent(ss, ind + 2);
- ss.append(f.getName()).append(": ");
- Object v = null;
- try {
- v = f.get(o);
- } catch (IllegalAccessException e) {
- v = "*** Cannot obtain value *** : " + e.getMessage();
- }
- struct(ss, v, ind + 2);
- }
- ss.append('\n');
- indent(ss, ind + 1);
- ss.append('}');
- }
-
- public static SortedSet<Integer> listInt(String ss, String warning) {
- if (ss == null || ss.length() == 0)
- return null;
-
- SortedSet<Integer> ll = new TreeSet<Integer>();
- String[] str = ss.split(",");
- for (String s : str) {
- try {
- int i1 = s.indexOf('-');
- int start, end;
- if (i1 > 0) {
- String s1 = s.substring(0, i1);
- String s2 = s.substring(i1 + 1);
- start = Integer.parseInt(s1);
- end = Integer.parseInt(s2);
- } else
- start = end = Integer.parseInt(s);
- for (int i = start; i <= end; i++)
- ll.add(i);
- } catch (NumberFormatException e) {
- // Skip this - bad data in DB
- log.warn(warning + " [" + s + "].", e);
- }
- }
- return ll;
- }
-
- public static String listInt(SortedSet<Integer> ll) {
- if (ll == null || ll.size() == 0)
- return null;
-
- StringBuilder sb = new StringBuilder(2000);
- Iterator<Integer> i = ll.iterator();
- int n = i.next();
- int start = n;
- int end = n;
- boolean first = true;
- while (i.hasNext()) {
- n = i.next();
- if (n != end + 1) {
- if (!first)
- sb.append(',');
- first = false;
-
- if (start == end)
- sb.append(start);
- else if (start == end - 1)
- sb.append(start).append(',').append(end);
- else
- sb.append(start).append('-').append(end);
-
- start = n;
- }
- end = n;
- }
-
- if (!first)
- sb.append(',');
-
- if (start == end)
- sb.append(start);
- else if (start == end - 1)
- sb.append(start).append(',').append(end);
- else
- sb.append(start).append('-').append(end);
-
- return sb.toString();
- }
-
- public static List<String> listStr(String s) {
- if (s == null || s.length() == 0)
- return null;
- String[] ss = s.split(",");
- return Arrays.asList(ss);
- }
-
- public static String listStr(Collection<String> ll) {
- if (ll == null || ll.isEmpty())
- return null;
- StringBuilder ss = new StringBuilder(1000);
- Iterator<String> i = ll.iterator();
- ss.append(i.next());
- while (i.hasNext())
- ss.append(',').append(i.next());
- return ss.toString();
- }
-
- private static boolean isSimple(Object o) {
- if (o == null)
- return true;
-
- if (o instanceof Number || o instanceof String || o instanceof Boolean || o instanceof Date)
- return true;
-
- return false;
- }
+ private static final Logger log = LoggerFactory.getLogger(StrUtil.class);
+
+ public static final String INDENT_STR = " ";
+
+ public static void indent(StringBuilder ss, int ind) {
+ for (int i = 0; i < ind; i++)
+ ss.append(INDENT_STR);
+ }
+
+ public static void info(Logger log, Object o) {
+ if (log.isInfoEnabled()) {
+ StringBuilder ss = new StringBuilder();
+ struct(ss, o);
+ log.info(ss.toString());
+ }
+ }
+
+ public static void debug(Logger log, Object o) {
+ if (log.isDebugEnabled()) {
+ StringBuilder ss = new StringBuilder();
+ struct(ss, o);
+ log.debug(ss.toString());
+ }
+ }
+
+ public static void struct(StringBuilder ss, Object o) {
+ struct(ss, o, 0);
+ }
+
+ public static void struct(StringBuilder ss, Object o, int ind) {
+ if (o == null) {
+ ss.append("null");
+ return;
+ }
+
+ if (isSimple(o)) {
+ ss.append(o);
+ return;
+ }
+
+ Class<? extends Object> cls = o.getClass();
+
+ if (cls.isEnum()) {
+ ss.append(o);
+ return;
+ }
+
+ if (cls.isArray()) {
+ int n = Array.getLength(o);
+ if (n == 0) {
+ ss.append("[]");
+ return;
+ }
+
+ Object o1 = Array.get(o, 0);
+ if (isSimple(o1)) {
+ ss.append('[').append(o1);
+ for (int i = 1; i < n; i++) {
+ o1 = Array.get(o, i);
+ ss.append(", ").append(o1);
+ }
+ ss.append(']');
+ return;
+ }
+
+ ss.append('\n');
+ indent(ss, ind + 1);
+ ss.append('[');
+ struct(ss, o1, ind + 1);
+ for (int i = 1; i < n; i++) {
+ o1 = Array.get(o, i);
+ struct(ss, o1, ind + 1);
+ }
+ ss.append('\n');
+ indent(ss, ind + 1);
+ ss.append(']');
+ return;
+ }
+
+ if (o instanceof Collection<?>) {
+ Collection<?> ll = (Collection<?>) o;
+
+ int n = ll.size();
+ if (n == 0) {
+ ss.append("[]");
+ return;
+ }
+
+ Iterator<?> ii = ll.iterator();
+ Object o1 = ii.next();
+ if (isSimple(o1)) {
+ ss.append('[').append(o1);
+ while (ii.hasNext()) {
+ o1 = ii.next();
+ ss.append(", ").append(o1);
+ }
+ ss.append(']');
+ return;
+ }
+
+ ss.append('\n');
+ indent(ss, ind + 1);
+ ss.append('[');
+ struct(ss, o1, ind + 1);
+ while (ii.hasNext()) {
+ o1 = ii.next();
+ struct(ss, o1, ind + 1);
+ }
+ ss.append('\n');
+ indent(ss, ind + 1);
+ ss.append(']');
+ return;
+
+ }
+
+ if (o instanceof Map<?, ?>) {
+ Map<?, ?> mm = (Map<?, ?>) o;
+
+ int n = mm.size();
+ if (n == 0) {
+ ss.append("{}");
+ return;
+ }
+
+ ss.append('{');
+
+ for (Object k : mm.keySet()) {
+ ss.append('\n');
+ indent(ss, ind + 1);
+ ss.append(k).append(": ");
+
+ Object o1 = mm.get(k);
+ struct(ss, o1, ind + 2);
+ }
+
+ ss.append('\n');
+ indent(ss, ind);
+ ss.append('}');
+
+ return;
+ }
+
+ Field[] fields = cls.getFields();
+
+ if (fields.length == 0) {
+ ss.append(o);
+ return;
+ }
+
+ ss.append('\n');
+ indent(ss, ind + 1);
+ ss.append('<').append(cls.getSimpleName()).append("> {");
+ for (Field f : fields) {
+ ss.append('\n');
+ indent(ss, ind + 2);
+ ss.append(f.getName()).append(": ");
+ Object v = null;
+ try {
+ v = f.get(o);
+ } catch (IllegalAccessException e) {
+ v = "*** Cannot obtain value *** : " + e.getMessage();
+ }
+ struct(ss, v, ind + 2);
+ }
+ ss.append('\n');
+ indent(ss, ind + 1);
+ ss.append('}');
+ }
+
+ public static SortedSet<Integer> listInt(String ss, String warning) {
+ if (ss == null || ss.length() == 0)
+ return null;
+
+ SortedSet<Integer> ll = new TreeSet<Integer>();
+ String[] str = ss.split(",");
+ for (String s : str) {
+ try {
+ int i1 = s.indexOf('-');
+ int start, end;
+ if (i1 > 0) {
+ String s1 = s.substring(0, i1);
+ String s2 = s.substring(i1 + 1);
+ start = Integer.parseInt(s1);
+ end = Integer.parseInt(s2);
+ } else
+ start = end = Integer.parseInt(s);
+ for (int i = start; i <= end; i++)
+ ll.add(i);
+ } catch (NumberFormatException e) {
+ // Skip this - bad data in DB
+ log.warn(warning + " [" + s + "].", e);
+ }
+ }
+ return ll;
+ }
+
+ public static String listInt(SortedSet<Integer> ll) {
+ if (ll == null || ll.size() == 0)
+ return null;
+
+ StringBuilder sb = new StringBuilder(2000);
+ Iterator<Integer> i = ll.iterator();
+ int n = i.next();
+ int start = n;
+ int end = n;
+ boolean first = true;
+ while (i.hasNext()) {
+ n = i.next();
+ if (n != end + 1) {
+ if (!first)
+ sb.append(',');
+ first = false;
+
+ if (start == end)
+ sb.append(start);
+ else if (start == end - 1)
+ sb.append(start).append(',').append(end);
+ else
+ sb.append(start).append('-').append(end);
+
+ start = n;
+ }
+ end = n;
+ }
+
+ if (!first)
+ sb.append(',');
+
+ if (start == end)
+ sb.append(start);
+ else if (start == end - 1)
+ sb.append(start).append(',').append(end);
+ else
+ sb.append(start).append('-').append(end);
+
+ return sb.toString();
+ }
+
+ public static List<String> listStr(String s) {
+ if (s == null || s.length() == 0)
+ return null;
+ String[] ss = s.split(",");
+ return Arrays.asList(ss);
+ }
+
+ public static String listStr(Collection<String> ll) {
+ if (ll == null || ll.isEmpty())
+ return null;
+ StringBuilder ss = new StringBuilder(1000);
+ Iterator<String> i = ll.iterator();
+ ss.append(i.next());
+ while (i.hasNext())
+ ss.append(',').append(i.next());
+ return ss.toString();
+ }
+
+ private static boolean isSimple(Object o) {
+ if (o == null)
+ return true;
+
+ if (o instanceof Number || o instanceof String || o instanceof Boolean || o instanceof Date)
+ return true;
+
+ return false;
+ }
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/vrf/VpnParam.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/vrf/VpnParam.java
index a9d69507a..a28b0affa 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/vrf/VpnParam.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/vrf/VpnParam.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,8 +23,8 @@ package org.openecomp.sdnc.util.vrf;
public class VpnParam {
- public String vpnId;
- public String siteType;
- public String spokeServiceInstanceId;
- public String routeGroupName;
+ public String vpnId;
+ public String siteType;
+ public String spokeServiceInstanceId;
+ public String routeGroupName;
}
diff --git a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/vrf/VrfUtil.java b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/vrf/VrfUtil.java
index d5a691bb8..2b90027c6 100644
--- a/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/vrf/VrfUtil.java
+++ b/resource-assignment/provider/src/main/java/org/openecomp/sdnc/util/vrf/VrfUtil.java
@@ -3,7 +3,7 @@
* openECOMP : SDN-C
* ================================================================================
* Copyright (C) 2017 ONAP Intellectual Property. All rights
- * reserved.
+ * reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,54 +23,54 @@ package org.openecomp.sdnc.util.vrf;
public class VrfUtil {
- public static String createVrfInstanceName(
- String serviceInstanceId,
- String vpnId,
- String siteType,
- String routeGroup) {
- if (vpnId == null || vpnId.trim().length() == 0)
- return null;
+ public static String createVrfInstanceName(
+ String serviceInstanceId,
+ String vpnId,
+ String siteType,
+ String routeGroup) {
+ if (vpnId == null || vpnId.trim().length() == 0)
+ return null;
- String ss = "VPN-" + vpnId;
- if (siteType != null && siteType.equalsIgnoreCase("hub"))
- ss += "-HUB";
- if (siteType != null && siteType.equalsIgnoreCase("spoke"))
- ss += "-SP-" + serviceInstanceId;
- if (routeGroup != null && routeGroup.trim().length() > 0)
- ss += "-RG-" + routeGroup;
+ String ss = "VPN-" + vpnId;
+ if (siteType != null && siteType.equalsIgnoreCase("hub"))
+ ss += "-HUB";
+ if (siteType != null && siteType.equalsIgnoreCase("spoke"))
+ ss += "-SP-" + serviceInstanceId;
+ if (routeGroup != null && routeGroup.trim().length() > 0)
+ ss += "-RG-" + routeGroup;
- return ss;
- }
+ return ss;
+ }
- public static VpnParam parseVrfInstanceName(String vrfInstanceName) {
- VpnParam vpnParam = new VpnParam();
+ public static VpnParam parseVrfInstanceName(String vrfInstanceName) {
+ VpnParam vpnParam = new VpnParam();
- int i1 = vrfInstanceName.indexOf("-HUB");
- if (i1 > 0)
- vpnParam.siteType = "HUB";
+ int i1 = vrfInstanceName.indexOf("-HUB");
+ if (i1 > 0)
+ vpnParam.siteType = "HUB";
- int i2 = vrfInstanceName.indexOf("-SP-");
- if (i2 > 0)
- vpnParam.siteType = "SPOKE";
+ int i2 = vrfInstanceName.indexOf("-SP-");
+ if (i2 > 0)
+ vpnParam.siteType = "SPOKE";
- int i3 = vrfInstanceName.indexOf("-RG-");
- if (i3 > 0)
- vpnParam.routeGroupName = vrfInstanceName.substring(i3 + 4);
+ int i3 = vrfInstanceName.indexOf("-RG-");
+ if (i3 > 0)
+ vpnParam.routeGroupName = vrfInstanceName.substring(i3 + 4);
- int i4 = vrfInstanceName.length();
- if (i1 > 0)
- i4 = i1;
- else if (i2 > 0)
- i4 = i2;
- else if (i3 > 0)
- i4 = i3;
- vpnParam.vpnId = vrfInstanceName.substring(4, i4);
+ int i4 = vrfInstanceName.length();
+ if (i1 > 0)
+ i4 = i1;
+ else if (i2 > 0)
+ i4 = i2;
+ else if (i3 > 0)
+ i4 = i3;
+ vpnParam.vpnId = vrfInstanceName.substring(4, i4);
- if (i2 > 0 && i3 < 0)
- vpnParam.spokeServiceInstanceId = vrfInstanceName.substring(i2 + 4);
- if (i2 > 0 && i3 > 0)
- vpnParam.spokeServiceInstanceId = vrfInstanceName.substring(i2 + 4, i3);
+ if (i2 > 0 && i3 < 0)
+ vpnParam.spokeServiceInstanceId = vrfInstanceName.substring(i2 + 4);
+ if (i2 > 0 && i3 > 0)
+ vpnParam.spokeServiceInstanceId = vrfInstanceName.substring(i2 + 4, i3);
- return vpnParam;
- }
+ return vpnParam;
+ }
}