summaryrefslogtreecommitdiffstats
path: root/resource-assignment/provider/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'resource-assignment/provider/src/main')
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/lock/comp/LockHelperImpl.java15
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/lock/dao/ResourceLockDao.java2
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/lock/dao/ResourceLockDaoImpl.java32
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/ResourceAllocator.java69
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/EndPointAllocatorImpl.java3
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/ResourceRequest.java2
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/comp/ReleaseFunction.java98
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/comp/ResourceManager.java9
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/comp/ResourceManagerImpl.java62
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/data/ReleaseRequest.java46
10 files changed, 213 insertions, 125 deletions
diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/lock/comp/LockHelperImpl.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/lock/comp/LockHelperImpl.java
index 0efd8977a..735d240c0 100644
--- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/lock/comp/LockHelperImpl.java
+++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/lock/comp/LockHelperImpl.java
@@ -45,7 +45,8 @@ public class LockHelperImpl implements LockHelper {
}
@Override
- public void lock(String resourceName, String lockRequester, int lockTimeout /* Seconds */, int lockWait /* Seconds */, int retryCount) {
+ public void lock(String resourceName, String lockRequester, int lockTimeout /* Seconds */,
+ int lockWait /* Seconds */, int retryCount) {
lock(Collections.singleton(resourceName), lockRequester, lockTimeout, lockWait, retryCount);
}
@@ -60,7 +61,8 @@ public class LockHelperImpl implements LockHelper {
}
@Override
- public void lock(Collection<String> resourceNameList, String lockRequester, int lockTimeout /* Seconds */, int lockWait /* Seconds */, int retryCount) {
+ public void lock(Collection<String> resourceNameList, String lockRequester, int lockTimeout /* Seconds */,
+ int lockWait /* Seconds */, int retryCount) {
for (int i = 0; true; i++) {
try {
tryLock(resourceNameList, lockRequester, lockTimeout);
@@ -129,6 +131,9 @@ public class LockHelperImpl implements LockHelper {
}
if (l != null) {
+ if (now.getTime() > l.expirationTime.getTime() || l.lockCount <= 0) {
+ l.lockCount = 0;
+ }
dbLockList.add(l);
} else {
insertLockNameList.add(name);
@@ -137,7 +142,7 @@ public class LockHelperImpl implements LockHelper {
// Update the lock info in DB
for (ResourceLock l : dbLockList) {
- resourceLockDao.update(l.id, now, new Date(now.getTime() + lockTimeout * 1000), l.lockCount + 1);
+ resourceLockDao.update(l.id, lockRequester, now, new Date(now.getTime() + lockTimeout * 1000), l.lockCount + 1);
}
// Insert records for those that are not yet there
@@ -159,7 +164,9 @@ public class LockHelperImpl implements LockHelper {
resourceLockDao.commit();
- } finally {
+ }finally
+
+ {
resourceLockDao.rollback();
}
}
diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/lock/dao/ResourceLockDao.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/lock/dao/ResourceLockDao.java
index f9d41135c..dc86f70af 100644
--- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/lock/dao/ResourceLockDao.java
+++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/lock/dao/ResourceLockDao.java
@@ -28,7 +28,7 @@ public interface ResourceLockDao {
void add(ResourceLock l);
- void update(long id, Date lockTime, Date expirationTime, int lockCount);
+ void update(long id, String lockHolder, Date lockTime, Date expirationTime, int lockCount);
ResourceLock getByResourceName(String resourceName);
diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/lock/dao/ResourceLockDaoImpl.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/lock/dao/ResourceLockDaoImpl.java
index 485419224..b8b3a66d6 100644
--- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/lock/dao/ResourceLockDaoImpl.java
+++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/lock/dao/ResourceLockDaoImpl.java
@@ -21,8 +21,6 @@
package org.onap.ccsdk.sli.adaptors.lock.dao;
-import java.sql.ResultSet;
-import java.sql.SQLException;
import java.util.Date;
import java.util.List;
import org.onap.ccsdk.sli.adaptors.lock.data.ResourceLock;
@@ -44,32 +42,28 @@ public class ResourceLockDaoImpl implements ResourceLockDao {
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 });
+ new Object[] { l.resourceName, l.lockHolder, l.lockCount, l.lockTime, l.expirationTime });
}
@Override
- public void update(long id, Date lockTime, Date expirationTime, int lockCount) {
+ public void update(long id, String lockHolder, 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 });
+ "UPDATE RESOURCE_LOCK SET lock_holder = ?, lock_time = ?, expiration_time = ?, lock_count = ? WHERE resource_lock_id = ?",
+ new Object[] { lockHolder, 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;
- }
+ new Object[] { resourceName }, (RowMapper<ResourceLock>) (rs, rowNum) -> {
+ 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;
}
diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/ResourceAllocator.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/ResourceAllocator.java
index c0cf774a8..944429a3c 100644
--- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/ResourceAllocator.java
+++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/ResourceAllocator.java
@@ -36,6 +36,7 @@ import org.onap.ccsdk.sli.adaptors.ra.comp.ResourceResponse;
import org.onap.ccsdk.sli.adaptors.ra.comp.ResourceTarget;
import org.onap.ccsdk.sli.adaptors.rm.comp.ResourceManager;
import org.onap.ccsdk.sli.adaptors.rm.data.AllocationStatus;
+import org.onap.ccsdk.sli.adaptors.rm.data.ReleaseRequest;
import org.onap.ccsdk.sli.adaptors.util.speed.SpeedUtil;
import org.onap.ccsdk.sli.adaptors.util.str.StrUtil;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
@@ -49,8 +50,6 @@ public class ResourceAllocator implements SvcLogicResource {
private static final Logger log = LoggerFactory.getLogger(ResourceAllocator.class);
private static final String[] INPUT_PREFIX = {"ra-input.", "tmp.resource-allocator."};
- private static final String START_RELEASE = "Starting release for: {}";
- private static final String START_RELEASE_FOR_TARGET = "Starting release for: {} on target: {}";
private ResourceManager resourceManager;
private EndPointAllocator endPointAllocator;
@@ -101,7 +100,7 @@ public class ResourceAllocator implements SvcLogicResource {
String orderBy, SvcLogicContext ctx) throws SvcLogicException {
String resourceEntityId = getParam(ctx,
- new String[] {"service-instance-id", "reservation-entity-id", "resource-entity-id"}, false, null);
+ new String[] {"service-instance-id", "resource-entity-id", "reservation-entity-id"}, false, null);
String resourceEntityType =
getParam(ctx, new String[] {"reservation-entity-type", "resource-entity-type"}, false, null);
String resourceEntityVersion =
@@ -147,7 +146,7 @@ public class ResourceAllocator implements SvcLogicResource {
ResourceData rd = endPointAllocator.getResource(rt.resourceTargetType, rt.resourceTargetId, rr.resourceName,
rr.resourceEntityTypeFilter, rr.resourceEntityIdFilter, rr.resourceShareGroupFilter);
setResourceDataInResponse(Collections.singletonList(rd), rsList);
- } else if ((rr!=null && (rr.resourceTargetTypeFilter != null || rr.resourceTargetIdFilter != null))
+ } else if (rr != null && (rr.resourceTargetTypeFilter != null || rr.resourceTargetIdFilter != null)
&& rr.resourceName != null) {
List<ResourceData> rdlist = endPointAllocator.getResourcesForTarget(rr.resourceTargetTypeFilter,
rr.resourceTargetIdFilter, rr.resourceName);
@@ -198,7 +197,7 @@ public class ResourceAllocator implements SvcLogicResource {
@Override
public QueryStatus release(String resource, String key, SvcLogicContext ctx) throws SvcLogicException {
String resourceEntityId = getParam(ctx,
- new String[] {"service-instance-id", "reservation-entity-id", "resource-entity-id"}, true, null);
+ new String[] {"service-instance-id", "resource-entity-id", "reservation-entity-id"}, true, null);
String resourceEntityType =
getParam(ctx, new String[] {"reservation-entity-type", "resource-entity-type"}, true, null);
String resourceEntityVersion =
@@ -207,6 +206,11 @@ public class ResourceAllocator implements SvcLogicResource {
getParam(ctx, new String[] {"reservation-target-id", "resource-target-id"}, false, null);
String resourceTargetType =
getParam(ctx, new String[] {"reservation-target-type", "resource-target-type"}, false, null);
+ String resourceName = getParam(ctx, new String[] {"resource-name"}, false, null);
+ String limitReleaseAmountStr = getParam(ctx, new String[] {"limit-release-amount"}, false, "-1");
+ int limitReleaseAmount = Integer.parseInt(limitReleaseAmountStr);
+ String rangeReleaseNumbers = getParam(ctx, new String[] {"range-release-numbers"}, false, null);
+
String endPointPosition = getParam(ctx, "endpoint-position", false, null);
@@ -217,6 +221,9 @@ public class ResourceAllocator implements SvcLogicResource {
ResourceRequest rr = new ResourceRequest();
rr.endPointPosition = endPointPosition;
+ rr.resourceName = resourceName;
+ rr.rangeReleaseNumbers = rangeReleaseNumbers;
+ rr.limitReleaseAmount = limitReleaseAmount;
ResourceTarget rt = new ResourceTarget();
rt.resourceTargetType = resourceTargetType;
@@ -240,44 +247,46 @@ public class ResourceAllocator implements SvcLogicResource {
public AllocationStatus release(ResourceEntity sd, ResourceRequest rr, ResourceTarget rt) throws Exception {
+ ReleaseRequest releaseRequest = new ReleaseRequest();
+
if (sd != null && sd.resourceEntityVersion != null) {
- String resourceSet = null;
+ releaseRequest.resourceSetId = null;
if (rr != null && rr.endPointPosition != null && !rr.endPointPosition.isEmpty()) {
- resourceSet = sd.resourceEntityType + "::" + sd.resourceEntityId + "::" + rr.endPointPosition + "::"
- + sd.resourceEntityVersion;
- } else {
- resourceSet = sd.resourceEntityType + "::" + sd.resourceEntityId + "::" + sd.resourceEntityVersion;
- }
-
- if (rt != null && rt.resourceTargetId != null && rt.resourceTargetType != null) {
- String assetId = rt.resourceTargetType + "::" + rt.resourceTargetId;
- log.info(START_RELEASE_FOR_TARGET, resourceSet, assetId);
- resourceManager.releaseResourceSet(resourceSet, assetId);
+ releaseRequest.resourceSetId = sd.resourceEntityType + "::" + sd.resourceEntityId + "::"
+ + rr.endPointPosition + "::" + sd.resourceEntityVersion;
} else {
- log.info(START_RELEASE, resourceSet);
- resourceManager.releaseResourceSet(resourceSet);
+ releaseRequest.resourceSetId =
+ sd.resourceEntityType + "::" + sd.resourceEntityId + "::" + sd.resourceEntityVersion;
}
} else if (sd != null && (sd.resourceEntityVersion == null || sd.resourceEntityVersion.isEmpty())) {
- String resourceUnion = null;
+ releaseRequest.resourceUnionId = null;
if (rr != null && rr.endPointPosition != null && !rr.endPointPosition.isEmpty()) {
- resourceUnion = sd.resourceEntityType + "::" + sd.resourceEntityId + "::" + rr.endPointPosition;
+ releaseRequest.resourceUnionId =
+ sd.resourceEntityType + "::" + sd.resourceEntityId + "::" + rr.endPointPosition;
} else {
- resourceUnion = sd.resourceEntityType + "::" + sd.resourceEntityId;
+ releaseRequest.resourceUnionId = sd.resourceEntityType + "::" + sd.resourceEntityId;
}
+ }
- if (rt != null && rt.resourceTargetId != null && rt.resourceTargetType != null) {
- String assetId = rt.resourceTargetType + "::" + rt.resourceTargetId;
- log.info(START_RELEASE_FOR_TARGET, resourceUnion, assetId);
- resourceManager.releaseResourceUnion(resourceUnion, assetId);
- } else {
- log.info(START_RELEASE, resourceUnion);
- resourceManager.releaseResourceUnion(resourceUnion);
- }
+ if (rt != null && rt.resourceTargetId != null && rt.resourceTargetType != null) {
+ releaseRequest.assetId = rt.resourceTargetType + "::" + rt.resourceTargetId;
+ }
+
+ if (rr != null) {
+ releaseRequest.resourceName = rr.resourceName;
+ releaseRequest.releaseNumbers =
+ StrUtil.listInt(rr.rangeReleaseNumbers, "Invalid value for range-release-numbers");
+ releaseRequest.releaseAmount = rr.limitReleaseAmount;
}
+ log.info("Releasing resources:");
+ StrUtil.info(log, releaseRequest);
+
+ resourceManager.releaseResources(releaseRequest);
+
return AllocationStatus.Success;
}
@@ -386,7 +395,7 @@ public class ResourceAllocator implements SvcLogicResource {
private ResourceEntity getResourceEntityData(SvcLogicContext ctx) throws SvcLogicException {
ResourceEntity sd = new ResourceEntity();
sd.resourceEntityId = getParam(ctx,
- new String[] {"service-instance-id", "reservation-entity-id", "resource-entity-id"}, true, null);
+ new String[] {"service-instance-id", "resource-entity-id", "reservation-entity-id"}, true, null);
sd.resourceEntityType =
getParam(ctx, new String[] {"reservation-entity-type", "resource-entity-type"}, true, null);
sd.resourceEntityVersion =
diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/EndPointAllocatorImpl.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/EndPointAllocatorImpl.java
index f4109a1de..d188429ea 100644
--- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/EndPointAllocatorImpl.java
+++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/EndPointAllocatorImpl.java
@@ -39,6 +39,7 @@ import org.onap.ccsdk.sli.adaptors.rm.data.MultiResourceAllocationOutcome;
import org.onap.ccsdk.sli.adaptors.rm.data.RangeAllocationItem;
import org.onap.ccsdk.sli.adaptors.rm.data.RangeAllocationOutcome;
import org.onap.ccsdk.sli.adaptors.rm.data.RangeResource;
+import org.onap.ccsdk.sli.adaptors.rm.data.ReleaseRequest;
import org.onap.ccsdk.sli.adaptors.rm.data.Resource;
import org.onap.ccsdk.sli.adaptors.util.str.StrUtil;
import org.slf4j.Logger;
@@ -83,7 +84,7 @@ public class EndPointAllocatorImpl implements EndPointAllocator {
if (!allgood) {
String resourceSetId = resourceEntity.resourceEntityType + "::" + resourceEntity.resourceEntityId
+ "::" + resourceEntity.resourceEntityVersion;
- resourceManager.releaseResourceSet(resourceSetId);
+ resourceManager.releaseResources(ReleaseRequest.resourceSet(resourceSetId));
}
}
}
diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/ResourceRequest.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/ResourceRequest.java
index c870bc414..bc05af657 100644
--- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/ResourceRequest.java
+++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/ResourceRequest.java
@@ -48,4 +48,6 @@ public class ResourceRequest {
public String resourceShareGroupFilter;
public String resourceTargetTypeFilter;
public String resourceTargetIdFilter;
+ public String rangeReleaseNumbers;
+ public int limitReleaseAmount;
}
diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/comp/ReleaseFunction.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/comp/ReleaseFunction.java
index b26c54cfa..b466b164b 100644
--- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/comp/ReleaseFunction.java
+++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/comp/ReleaseFunction.java
@@ -9,9 +9,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -22,6 +22,7 @@
package org.onap.ccsdk.sli.adaptors.rm.comp;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
@@ -30,7 +31,11 @@ import org.onap.ccsdk.sli.adaptors.lock.comp.ResourceLockedException;
import org.onap.ccsdk.sli.adaptors.lock.comp.SynchronizedFunction;
import org.onap.ccsdk.sli.adaptors.rm.dao.ResourceDao;
import org.onap.ccsdk.sli.adaptors.rm.data.AllocationItem;
+import org.onap.ccsdk.sli.adaptors.rm.data.LimitAllocationItem;
+import org.onap.ccsdk.sli.adaptors.rm.data.RangeAllocationItem;
+import org.onap.ccsdk.sli.adaptors.rm.data.ReleaseRequest;
import org.onap.ccsdk.sli.adaptors.rm.data.Resource;
+import org.onap.ccsdk.sli.adaptors.rm.data.ResourceType;
import org.onap.ccsdk.sli.adaptors.rm.util.ResourceUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -42,42 +47,93 @@ class ReleaseFunction extends SynchronizedFunction {
private ResourceDao resourceDao;
- private String resourceSetId;
- private String resourceUnionId;
- private String assetId;
+ private ReleaseRequest releaseRequest;
- public ReleaseFunction(LockHelper lockHelper, ResourceDao resourceDao, String resourceSetId, String resourceUnionId,
- String assetId, Collection<String> lockNames, int lockTimeout) {
+ public ReleaseFunction(LockHelper lockHelper, ResourceDao resourceDao, ReleaseRequest releaseRequest,
+ Collection<String> lockNames, int lockTimeout) {
super(lockHelper, lockNames, lockTimeout);
this.resourceDao = resourceDao;
- this.resourceSetId = resourceSetId;
- this.resourceUnionId = resourceUnionId;
- this.assetId = assetId;
+ this.releaseRequest = releaseRequest;
}
@Override
public void _exec() throws ResourceLockedException {
- List<Resource> resourceList = assetId != null
- ? (resourceSetId != null ? resourceDao.getResourceSetForAsset(resourceSetId, assetId)
- : resourceDao.getResourceUnionForAsset(resourceUnionId, assetId))
- : (resourceSetId != null ? resourceDao.getResourceSet(resourceSetId)
- : resourceDao.getResourceUnion(resourceUnionId));
+ List<Resource> resourceList = new ArrayList<>();
+ if (releaseRequest.assetId != null && releaseRequest.resourceName != null) {
+ Resource r = resourceDao.getResource(releaseRequest.assetId, releaseRequest.resourceName);
+ if (r != null) {
+ resourceList.add(r);
+ }
+ } else if (releaseRequest.assetId != null) {
+ if (releaseRequest.resourceSetId != null) {
+ resourceList = resourceDao.getResourceSetForAsset(releaseRequest.resourceSetId, releaseRequest.assetId);
+ } else {
+ resourceList =
+ resourceDao.getResourceUnionForAsset(releaseRequest.resourceUnionId, releaseRequest.assetId);
+ }
+ } else {
+ if (releaseRequest.resourceSetId != null) {
+ resourceList = resourceDao.getResourceSet(releaseRequest.resourceSetId);
+ } else {
+ resourceList = resourceDao.getResourceUnion(releaseRequest.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();
+ if (releaseRequest.resourceSetId != null) {
+
+ if (releaseRequest.resourceSetId.equals(ai.resourceSetId)) {
+ if (r.resourceType == ResourceType.Limit) {
+ LimitAllocationItem lai = (LimitAllocationItem) ai;
+ if (releaseRequest.releaseAmount > 0 && releaseRequest.releaseAmount < lai.used) {
+ lai.used -= releaseRequest.releaseAmount;
+ } else {
+ i.remove();
+ }
+ } else if (r.resourceType == ResourceType.Range) {
+ RangeAllocationItem rai = (RangeAllocationItem) ai;
+ if (releaseRequest.releaseNumbers != null && !releaseRequest.releaseNumbers.isEmpty()) {
+ rai.used.removeAll(releaseRequest.releaseNumbers);
+ if (rai.used.isEmpty()) {
+ i.remove();
+ }
+ } else {
+ i.remove();
+ }
+ } else {
+ i.remove();
+ }
updated = true;
}
- } else if (resourceUnionId != null) {
+ } else if (releaseRequest.resourceUnionId != null) {
- if (resourceUnionId.equals(ai.resourceUnionId)) {
- i.remove();
+ if (releaseRequest.resourceUnionId.equals(ai.resourceUnionId)) {
+ if (r.resourceType == ResourceType.Limit) {
+ LimitAllocationItem lai = (LimitAllocationItem) ai;
+ if (releaseRequest.releaseAmount > 0 && releaseRequest.releaseAmount < lai.used) {
+ lai.used -= releaseRequest.releaseAmount;
+ } else {
+ i.remove();
+ }
+ } else if (r.resourceType == ResourceType.Range) {
+ RangeAllocationItem rai = (RangeAllocationItem) ai;
+ if (releaseRequest.releaseNumbers != null && !releaseRequest.releaseNumbers.isEmpty()) {
+ rai.used.removeAll(releaseRequest.releaseNumbers);
+ if (rai.used.isEmpty()) {
+ i.remove();
+ }
+ } else {
+ i.remove();
+ }
+ } else {
+ i.remove();
+ }
updated = true;
}
diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/comp/ResourceManager.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/comp/ResourceManager.java
index 68d251587..9dd54cc39 100644
--- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/comp/ResourceManager.java
+++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/comp/ResourceManager.java
@@ -24,6 +24,7 @@ package org.onap.ccsdk.sli.adaptors.rm.comp;
import java.util.List;
import org.onap.ccsdk.sli.adaptors.rm.data.AllocationOutcome;
import org.onap.ccsdk.sli.adaptors.rm.data.AllocationRequest;
+import org.onap.ccsdk.sli.adaptors.rm.data.ReleaseRequest;
import org.onap.ccsdk.sli.adaptors.rm.data.Resource;
public interface ResourceManager {
@@ -34,13 +35,7 @@ public interface ResourceManager {
AllocationOutcome allocateResources(AllocationRequest allocationRequest);
- void releaseResourceSet(String resourceSetId);
-
- void releaseResourceUnion(String resourceUnionId);
-
- void releaseResourceSet(String resourceSetId, String assetId);
-
- void releaseResourceUnion(String resourceUnionId, String assetId);
+ void releaseResources(ReleaseRequest releaseRequest);
Resource queryResource(String resourceName, String assetId, String resourceUnionFilter,
String resourceShareGroupFilter);
diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/comp/ResourceManagerImpl.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/comp/ResourceManagerImpl.java
index c4d53ce70..83da27071 100644
--- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/comp/ResourceManagerImpl.java
+++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/comp/ResourceManagerImpl.java
@@ -28,6 +28,7 @@ import org.onap.ccsdk.sli.adaptors.lock.comp.LockHelper;
import org.onap.ccsdk.sli.adaptors.rm.dao.ResourceDao;
import org.onap.ccsdk.sli.adaptors.rm.data.AllocationOutcome;
import org.onap.ccsdk.sli.adaptors.rm.data.AllocationRequest;
+import org.onap.ccsdk.sli.adaptors.rm.data.ReleaseRequest;
import org.onap.ccsdk.sli.adaptors.rm.data.Resource;
import org.onap.ccsdk.sli.adaptors.rm.util.ResourceUtil;
import org.onap.ccsdk.sli.adaptors.util.str.StrUtil;
@@ -80,54 +81,31 @@ public class ResourceManagerImpl implements ResourceManager {
}
@Override
- public void releaseResourceSet(String resourceSetId) {
- List<Resource> resourceList = resourceDao.getResourceSet(resourceSetId);
- if (resourceList == null || resourceList.isEmpty()) {
+ public void releaseResources(ReleaseRequest releaseRequest) {
+ if (releaseRequest.resourceSetId == null && releaseRequest.resourceUnionId == null) {
return;
}
- Set<String> lockNames = getLockNames(resourceList);
- ReleaseFunction releaseFunction =
- new ReleaseFunction(lockHelper, resourceDao, resourceSetId, null, 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, null, lockNames, lockTimeout);
- releaseFunction.exec();
- }
-
- @Override
- public void releaseResourceSet(String resourceSetId, String assetId) {
- List<Resource> resourceList = resourceDao.getResourceSetForAsset(resourceSetId, assetId);
- if (resourceList == null || resourceList.isEmpty()) {
- return;
- }
-
- Set<String> lockNames = getLockNames(resourceList);
- ReleaseFunction releaseFunction =
- new ReleaseFunction(lockHelper, resourceDao, resourceSetId, null, assetId, lockNames, lockTimeout);
- releaseFunction.exec();
- }
-
- @Override
- public void releaseResourceUnion(String resourceUnionId, String assetId) {
- List<Resource> resourceList = resourceDao.getResourceUnionForAsset(resourceUnionId, assetId);
- if (resourceList == null || resourceList.isEmpty()) {
- return;
+ Set<String> lockNames = new HashSet<>();
+ if (releaseRequest.assetId != null) {
+ lockNames.add(releaseRequest.assetId);
+ } else {
+ List<Resource> resourceList = null;
+ if (releaseRequest.resourceSetId != null) {
+ resourceList = resourceDao.getResourceSet(releaseRequest.resourceSetId);
+ } else {
+ resourceList = resourceDao.getResourceUnion(releaseRequest.resourceUnionId);
+ }
+
+ if (resourceList == null || resourceList.isEmpty()) {
+ return;
+ }
+
+ lockNames = getLockNames(resourceList);
}
- Set<String> lockNames = getLockNames(resourceList);
ReleaseFunction releaseFunction =
- new ReleaseFunction(lockHelper, resourceDao, null, resourceUnionId, assetId, lockNames, lockTimeout);
+ new ReleaseFunction(lockHelper, resourceDao, releaseRequest, lockNames, lockTimeout);
releaseFunction.exec();
}
diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/data/ReleaseRequest.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/data/ReleaseRequest.java
new file mode 100644
index 000000000..dba6a172f
--- /dev/null
+++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/data/ReleaseRequest.java
@@ -0,0 +1,46 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.ccsdk.sli.adaptors.rm.data;
+
+import java.util.Set;
+
+public class ReleaseRequest {
+
+ public String resourceUnionId = null;
+ public String resourceSetId = null;
+ public String assetId = null;
+ public String resourceName = null;
+ public int releaseAmount = 0;
+ public Set<Integer> releaseNumbers = null;
+
+ public static ReleaseRequest resourceSet(String resourceSetId) {
+ ReleaseRequest rr = new ReleaseRequest();
+ rr.resourceSetId = resourceSetId;
+ return rr;
+ }
+
+ public static ReleaseRequest resourceUnion(String resourceUnionId) {
+ ReleaseRequest rr = new ReleaseRequest();
+ rr.resourceUnionId = resourceUnionId;
+ return rr;
+ }
+}