aboutsummaryrefslogtreecommitdiffstats
path: root/resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/comp
diff options
context:
space:
mode:
authorMarcus G K Williams <marcus.williams@intel.com>2017-08-02 15:09:24 -0700
committerMarcus G K Williams <marcus.williams@intel.com>2017-08-02 16:08:09 -0700
commit806052bf4df8bd023cfb391794bc5937f2624716 (patch)
tree166e4a28582d96eaf3a8dd69b484cf02076d634c /resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/comp
parent16508ffde287f481791ae0b9c071f60a331c680d (diff)
Convert tabs to spaces
Per Java Code Style Guide: https://wiki.onap.org/display/DW/Java+code+style Converting tabs to 4 spaces. Issue-Id: SDNC-25 Change-Id: I99ce6c244df72f805b52d0d66403d8b76d9929ae Signed-off-by: Marcus G K Williams <marcus.williams@intel.com>
Diffstat (limited to 'resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm/comp')
-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
5 files changed, 410 insertions, 410 deletions
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 3a934091..00cfb1fc 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 f546954f..c8dab080 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 aea0b0a3..d5bb9e47 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 7a3ce034..737deb1c 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 b9d5a099..e70e06c2 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;
+ }
}