From 806052bf4df8bd023cfb391794bc5937f2624716 Mon Sep 17 00:00:00 2001 From: Marcus G K Williams Date: Wed, 2 Aug 2017 15:09:24 -0700 Subject: 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 --- .../openecomp/sdnc/rm/comp/AllocationFunction.java | 534 ++++++++--------- .../openecomp/sdnc/rm/comp/ReleaseFunction.java | 84 +-- .../org/openecomp/sdnc/rm/comp/ResourceLoader.java | 12 +- .../openecomp/sdnc/rm/comp/ResourceManager.java | 12 +- .../sdnc/rm/comp/ResourceManagerImpl.java | 178 +++--- .../org/openecomp/sdnc/rm/dao/ResourceDao.java | 12 +- .../openecomp/sdnc/rm/dao/jdbc/AllocationItem.java | 20 +- .../sdnc/rm/dao/jdbc/AllocationItemJdbcDao.java | 10 +- .../rm/dao/jdbc/AllocationItemJdbcDaoImpl.java | 170 +++--- .../org/openecomp/sdnc/rm/dao/jdbc/Resource.java | 14 +- .../sdnc/rm/dao/jdbc/ResourceDaoImpl.java | 660 ++++++++++----------- .../sdnc/rm/dao/jdbc/ResourceJdbcDao.java | 14 +- .../sdnc/rm/dao/jdbc/ResourceJdbcDaoImpl.java | 206 +++---- .../openecomp/sdnc/rm/dao/jdbc/ResourceLoad.java | 12 +- .../sdnc/rm/dao/jdbc/ResourceLoadJdbcDao.java | 10 +- .../sdnc/rm/dao/jdbc/ResourceLoadJdbcDaoImpl.java | 142 ++--- .../openecomp/sdnc/rm/data/AllocationAction.java | 4 +- .../org/openecomp/sdnc/rm/data/AllocationItem.java | 16 +- .../openecomp/sdnc/rm/data/AllocationOutcome.java | 6 +- .../openecomp/sdnc/rm/data/AllocationRequest.java | 16 +- .../openecomp/sdnc/rm/data/AllocationStatus.java | 4 +- .../org/openecomp/sdnc/rm/data/InitAction.java | 18 +- .../sdnc/rm/data/LabelAllocationItem.java | 4 +- .../sdnc/rm/data/LabelAllocationOutcome.java | 6 +- .../sdnc/rm/data/LabelAllocationRequest.java | 8 +- .../org/openecomp/sdnc/rm/data/LabelResource.java | 8 +- .../sdnc/rm/data/LimitAllocationItem.java | 4 +- .../sdnc/rm/data/LimitAllocationOutcome.java | 8 +- .../sdnc/rm/data/LimitAllocationRequest.java | 12 +- .../org/openecomp/sdnc/rm/data/LimitResource.java | 4 +- .../sdnc/rm/data/MultiAssetAllocationOutcome.java | 6 +- .../sdnc/rm/data/MultiAssetAllocationRequest.java | 10 +- .../rm/data/MultiResourceAllocationOutcome.java | 4 +- .../rm/data/MultiResourceAllocationRequest.java | 6 +- .../sdnc/rm/data/RangeAllocationItem.java | 4 +- .../sdnc/rm/data/RangeAllocationOutcome.java | 6 +- .../sdnc/rm/data/RangeAllocationRequest.java | 18 +- .../org/openecomp/sdnc/rm/data/RangeResource.java | 4 +- .../java/org/openecomp/sdnc/rm/data/Resource.java | 10 +- .../org/openecomp/sdnc/rm/data/ResourceKey.java | 44 +- .../org/openecomp/sdnc/rm/data/ResourceLoad.java | 10 +- .../org/openecomp/sdnc/rm/data/ResourceType.java | 4 +- .../java/org/openecomp/sdnc/rm/util/LabelUtil.java | 104 ++-- .../java/org/openecomp/sdnc/rm/util/LimitUtil.java | 586 +++++++++--------- .../java/org/openecomp/sdnc/rm/util/RangeUtil.java | 126 ++-- .../org/openecomp/sdnc/rm/util/ResourceUtil.java | 32 +- 46 files changed, 1591 insertions(+), 1591 deletions(-) (limited to 'resource-assignment/provider/src/main/java/org/openecomp/sdnc/rm') 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 updateList = new ArrayList(); - - 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 getLockNames(AllocationRequest request) { - Set lockResourceNames = new HashSet(); - addLockNames(lockResourceNames, request); - return lockResourceNames; - } - - private static void addLockNames(Set 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(); - 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 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(); - int foundCount = 0; - - // First try to reuse the numbers already taken by the same resource union - SortedSet 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 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(); - 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(); - - 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 updateList = new ArrayList(); + + 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 getLockNames(AllocationRequest request) { + Set lockResourceNames = new HashSet(); + addLockNames(lockResourceNames, request); + return lockResourceNames; + } + + private static void addLockNames(Set 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(); + 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 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(); + int foundCount = 0; + + // First try to reuse the numbers already taken by the same resource union + SortedSet 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 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(); + 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(); + + 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 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 lockNames, int lockTimeout) { + super(lockHelper, lockNames, lockTimeout); + this.resourceDao = resourceDao; + this.resourceSetId = resourceSetId; + this.resourceUnionId = resourceUnionId; + } - @Override - public void _exec() throws ResourceLockedException { - List resourceList = - resourceSetId != null - ? resourceDao.getResourceSet(resourceSetId) : resourceDao.getResourceUnion(resourceUnionId); - for (Resource r : resourceList) { - boolean updated = false; - if (r.allocationItems != null) { - Iterator 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 resourceList = + resourceSetId != null + ? resourceDao.getResourceSet(resourceSetId) : resourceDao.getResourceUnion(resourceUnionId); + for (Resource r : resourceList) { + boolean updated = false; + if (r.allocationItems != null) { + Iterator 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 resourceList, boolean force); + void loadResources(String applicationId, Collection resourceList, boolean force); - void loadResourcesForAsset(String applicationId, String assetId, Collection resourceList, boolean force); + void loadResourcesForAsset(String applicationId, String assetId, Collection 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 getResourceUnion(String resourceUnionId); + List 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 getResourceUnion(String resourceUnionId) { - List 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 resourceList = resourceDao.getResourceSet(resourceSetId); - if (resourceList == null || resourceList.isEmpty()) - return; - - Set lockNames = getLockNames(resourceList); - ReleaseFunction releaseFunction = - new ReleaseFunction(lockHelper, resourceDao, resourceSetId, null, lockNames, lockTimeout); - releaseFunction.exec(); - } - - @Override - public void releaseResourceUnion(String resourceUnionId) { - List resourceList = resourceDao.getResourceUnion(resourceUnionId); - if (resourceList == null || resourceList.isEmpty()) - return; - - Set lockNames = getLockNames(resourceList); - ReleaseFunction releaseFunction = - new ReleaseFunction(lockHelper, resourceDao, null, resourceUnionId, lockNames, lockTimeout); - releaseFunction.exec(); - } - - private Set getLockNames(List resourceList) { - Set lockNames = new HashSet(); - 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 getResourceUnion(String resourceUnionId) { + List 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 resourceList = resourceDao.getResourceSet(resourceSetId); + if (resourceList == null || resourceList.isEmpty()) + return; + + Set lockNames = getLockNames(resourceList); + ReleaseFunction releaseFunction = + new ReleaseFunction(lockHelper, resourceDao, resourceSetId, null, lockNames, lockTimeout); + releaseFunction.exec(); + } + + @Override + public void releaseResourceUnion(String resourceUnionId) { + List resourceList = resourceDao.getResourceUnion(resourceUnionId); + if (resourceList == null || resourceList.isEmpty()) + return; + + Set lockNames = getLockNames(resourceList); + ReleaseFunction releaseFunction = + new ReleaseFunction(lockHelper, resourceDao, null, resourceUnionId, lockNames, lockTimeout); + releaseFunction.exec(); + } + + private Set getLockNames(List resourceList) { + Set lockNames = new HashSet(); + 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 f499801c..a116ef50 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 getResourceSet(String resourceSetId); + List getResourceSet(String resourceSetId); - List getResourceUnion(String resourceUnionId); + List 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 eb5f3988..7087c18f 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 30f9d26a..fe6199ea 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 getAllocationItems(long resourceId); + List 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 1d88261c..2710f358 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 getAllocationItems(long resourceId) { - if (resourceId <= 0) - return Collections.emptyList(); - - return jdbcTemplate.query(GET_SQL, new Object[] { resourceId }, allocationItemRowMapper); - } - - private static class AllocationItemRowMapper implements RowMapper { - - @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 getAllocationItems(long resourceId) { + if (resourceId <= 0) + return Collections.emptyList(); + + return jdbcTemplate.query(GET_SQL, new Object[] { resourceId }, allocationItemRowMapper); + } + + private static class AllocationItemRowMapper implements RowMapper { + + @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 ca66964c..4bbe2ebd 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 32c8f4d7..cbae3d20 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 aiEntityList = allocationItemJdbcDao.getAllocationItems(rEntity.id); - r.allocationItems = new ArrayList(); - for (AllocationItem aiEntity : aiEntityList) { - org.openecomp.sdnc.rm.data.AllocationItem ai = createAllocationItem(r, aiEntity); - r.allocationItems.add(ai); - } - - List rlEntityList = resourceLoadJdbcDao.getResourceLoads(rEntity.id); - r.resourceLoadList = new ArrayList(); - 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 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 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 getResourceSet(String resourceSetId) { - List rEntityList = resourceJdbcDao.getResourceSet(resourceSetId); - List rlist = new ArrayList(); - for (Resource rEntity : rEntityList) { - org.openecomp.sdnc.rm.data.Resource r = createResource(rEntity); - rlist.add(r); - - List aiEntityList = allocationItemJdbcDao.getAllocationItems(rEntity.id); - r.allocationItems = new ArrayList(); - for (AllocationItem aiEntity : aiEntityList) { - org.openecomp.sdnc.rm.data.AllocationItem ai = createAllocationItem(r, aiEntity); - r.allocationItems.add(ai); - } - - List rlEntityList = resourceLoadJdbcDao.getResourceLoads(rEntity.id); - r.resourceLoadList = new ArrayList(); - for (ResourceLoad rlEntity : rlEntityList) { - org.openecomp.sdnc.rm.data.ResourceLoad rl = createResourceLoad(r, rlEntity); - r.resourceLoadList.add(rl); - } - } - return rlist; - } - - @Override - public List getResourceUnion(String resourceUnionId) { - List rEntityList = resourceJdbcDao.getResourceUnion(resourceUnionId); - List rlist = new ArrayList(); - for (Resource rEntity : rEntityList) { - org.openecomp.sdnc.rm.data.Resource r = createResource(rEntity); - rlist.add(r); - - List aiEntityList = allocationItemJdbcDao.getAllocationItems(rEntity.id); - r.allocationItems = new ArrayList(); - for (AllocationItem aiEntity : aiEntityList) { - org.openecomp.sdnc.rm.data.AllocationItem ai = createAllocationItem(r, aiEntity); - r.allocationItems.add(ai); - } - - List rlEntityList = resourceLoadJdbcDao.getResourceLoads(rEntity.id); - r.resourceLoadList = new ArrayList(); - 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(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 aiEntityList = allocationItemJdbcDao.getAllocationItems(rEntity.id); + r.allocationItems = new ArrayList(); + for (AllocationItem aiEntity : aiEntityList) { + org.openecomp.sdnc.rm.data.AllocationItem ai = createAllocationItem(r, aiEntity); + r.allocationItems.add(ai); + } + + List rlEntityList = resourceLoadJdbcDao.getResourceLoads(rEntity.id); + r.resourceLoadList = new ArrayList(); + 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 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 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 getResourceSet(String resourceSetId) { + List rEntityList = resourceJdbcDao.getResourceSet(resourceSetId); + List rlist = new ArrayList(); + for (Resource rEntity : rEntityList) { + org.openecomp.sdnc.rm.data.Resource r = createResource(rEntity); + rlist.add(r); + + List aiEntityList = allocationItemJdbcDao.getAllocationItems(rEntity.id); + r.allocationItems = new ArrayList(); + for (AllocationItem aiEntity : aiEntityList) { + org.openecomp.sdnc.rm.data.AllocationItem ai = createAllocationItem(r, aiEntity); + r.allocationItems.add(ai); + } + + List rlEntityList = resourceLoadJdbcDao.getResourceLoads(rEntity.id); + r.resourceLoadList = new ArrayList(); + for (ResourceLoad rlEntity : rlEntityList) { + org.openecomp.sdnc.rm.data.ResourceLoad rl = createResourceLoad(r, rlEntity); + r.resourceLoadList.add(rl); + } + } + return rlist; + } + + @Override + public List getResourceUnion(String resourceUnionId) { + List rEntityList = resourceJdbcDao.getResourceUnion(resourceUnionId); + List rlist = new ArrayList(); + for (Resource rEntity : rEntityList) { + org.openecomp.sdnc.rm.data.Resource r = createResource(rEntity); + rlist.add(r); + + List aiEntityList = allocationItemJdbcDao.getAllocationItems(rEntity.id); + r.allocationItems = new ArrayList(); + for (AllocationItem aiEntity : aiEntityList) { + org.openecomp.sdnc.rm.data.AllocationItem ai = createAllocationItem(r, aiEntity); + r.allocationItems.add(ai); + } + + List rlEntityList = resourceLoadJdbcDao.getResourceLoads(rEntity.id); + r.resourceLoadList = new ArrayList(); + 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(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 645c377e..5ed07b25 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 getResourceSet(String resourceSetId); + List getResourceSet(String resourceSetId); - List getResourceUnion(String resourceUnionId); + List 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 5e529f70..08592819 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 ll = jdbcTemplate.query(RESOURCE_SQL, new Object[] { assetId, resourceName }, resourceRowMapper); - return ll.isEmpty() ? null : ll.get(0); - } - - @Override - public List getResourceSet(String resourceSetId) { - if (resourceSetId == null) - return Collections.emptyList(); - - return jdbcTemplate.query(RESOURCE_SET_SQL, new Object[] { resourceSetId }, resourceRowMapper); - } - - @Override - public List 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 ll = jdbcTemplate.query(RESOURCE_SQL, new Object[] { assetId, resourceName }, resourceRowMapper); + return ll.isEmpty() ? null : ll.get(0); + } + + @Override + public List getResourceSet(String resourceSetId) { + if (resourceSetId == null) + return Collections.emptyList(); + + return jdbcTemplate.query(RESOURCE_SET_SQL, new Object[] { resourceSetId }, resourceRowMapper); + } + + @Override + public List 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 { - - @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 { + + @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 5c810b1d..5b566924 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 9a337a83..ad38372f 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 getResourceLoads(long resourceId); + List 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 854b6696..aa44afae 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 getResourceLoads(long resourceId) { - if (resourceId <= 0) - return Collections.emptyList(); - - return jdbcTemplate.query(GET_SQL, new Object[] { resourceId }, resourceLoadRowMapper); - } - - private static class ResourceLoadRowMapper implements RowMapper { - - @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 getResourceLoads(long resourceId) { + if (resourceId <= 0) + return Collections.emptyList(); + + return jdbcTemplate.query(GET_SQL, new Object[] { resourceId }, resourceLoadRowMapper); + } + + private static class ResourceLoadRowMapper implements RowMapper { + + @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 c791d427..4eab7d9d 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 f4cabf96..4a7ee6a7 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 resourceShareGroupList; - public String applicationId; - public Date allocationTime; + public ResourceKey resourceKey; + public ResourceType resourceType; + public String resourceSetId; + public String resourceUnionId; + public Set 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 20ecf051..7283e11c 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 d54475ff..d4291167 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 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 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 a18077a1..aa8d1df1 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 8b9dfaa3..d0075bdb 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 e456542c..97ee3ba8 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 d0cb2c52..c1763ff2 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 2b6ce033..8e509f66 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 54bfb852..d8270192 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 270220a8..181172f2 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 f1c13c08..ffc11941 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 787715bb..31c0d115 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 cad0ba23..ad706ee8 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 bf9bbbfa..dcbac367 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 goodAssetIdList; - public List allocationOutcomeList; + public List goodAssetIdList; + public List 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 da1a96d7..d4dd65ed 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 assetIdList = null; - public AllocationRequest allocationRequest = null; - public int requestedCount = 0; - public boolean sequential = false; + public List 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 9deca6c2..355d5081 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 allocationOutcomeList; + public List 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 9e48a31e..4de9868b 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 allocationRequestList = null; - public boolean stopOnFirstFailure = true; + public List 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 229c8e44..4260b4dc 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 used; + public SortedSet 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 8b35d9f0..ad14f510 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 allocated = null; - public SortedSet used = null; + public SortedSet allocated = null; + public SortedSet 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 0732613d..9315535f 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 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 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 99a2b207..4bec3044 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 used; + public SortedSet 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 b04f7105..c462bde3 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 allocationItems; - public Collection resourceLoadList; + public ResourceKey resourceKey; + public ResourceType resourceType; + public Collection allocationItems; + public Collection 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 b303b07f..765c9251 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 06970cbc..f1e96a8b 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 1d8b9c4c..d97cb7d7 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 bbaa3a37..d15a149f 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(); - l.allocationItems.add(lai); - } + if (l.allocationItems == null) + l.allocationItems = new ArrayList(); + 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 45799560..76c3ef76 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 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> limitUsageMap = new HashMap>(); - 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> allCombinations = new ArrayList>(); - for (String firstResourceUnion : limitUsageMap.keySet()) { - List limitUsageList = limitUsageMap.get(firstResourceUnion); - if (limitUsageList.size() > 1) - significantChangeCount++; - if (allCombinations.isEmpty()) { - for (LimitUsage limitUsage : limitUsageList) { - List newCombination = new ArrayList(); - 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 combination : allCombinations) - combination.add(limitUsageList.get(0)); - } else { - // We have to duplicate each of the current combinations for each element of limitUsageList - List> newAllCombinations = new ArrayList>(); - for (List combination : allCombinations) - for (LimitUsage limitUsage : limitUsageList) { - List newCombination = new ArrayList(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 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> limitUsageMap, - String resourceUnionId, - Set resourceShareGroupList, - long used) { - List limitUsageList = limitUsageMap.get(resourceUnionId); - if (limitUsageList == null) { - limitUsageList = new ArrayList(); - 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 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 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> sharedSets = new ArrayList>(); - 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 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 newSharedSet = new ArrayList(); - newSharedSet.add(limitUsage); - sharedSets.add(newSharedSet); - } - } - - long sum = 0; - for (List 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(); - 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 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> limitUsageMap = new HashMap>(); + 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> allCombinations = new ArrayList>(); + for (String firstResourceUnion : limitUsageMap.keySet()) { + List limitUsageList = limitUsageMap.get(firstResourceUnion); + if (limitUsageList.size() > 1) + significantChangeCount++; + if (allCombinations.isEmpty()) { + for (LimitUsage limitUsage : limitUsageList) { + List newCombination = new ArrayList(); + 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 combination : allCombinations) + combination.add(limitUsageList.get(0)); + } else { + // We have to duplicate each of the current combinations for each element of limitUsageList + List> newAllCombinations = new ArrayList>(); + for (List combination : allCombinations) + for (LimitUsage limitUsage : limitUsageList) { + List newCombination = new ArrayList(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 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> limitUsageMap, + String resourceUnionId, + Set resourceShareGroupList, + long used) { + List limitUsageList = limitUsageMap.get(resourceUnionId); + if (limitUsageList == null) { + limitUsageList = new ArrayList(); + 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 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 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> sharedSets = new ArrayList>(); + 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 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 newSharedSet = new ArrayList(); + newSharedSet.add(limitUsage); + sharedSets.add(newSharedSet); + } + } + + long sum = 0; + for (List 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(); + 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 af828314..27d0e55b 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(); - 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(); + 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 getUsed(RangeResource r, String resourceUnionId) { - SortedSet used = new TreeSet(); - 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 getUsed(RangeResource r, String resourceUnionId) { + SortedSet used = new TreeSet(); + 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 requestedNumbers, - RangeAllocationRequest req, - String applicationId) { - if (!req.allocate) - return; + public static void allocateRange( + RangeResource rr, + SortedSet 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(); - rr.allocationItems.add(rai); - } else if (req.replace) - rai.used = requestedNumbers; - else - rai.used.addAll(requestedNumbers); + if (rr.allocationItems == null) + rr.allocationItems = new ArrayList(); + 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 7afe7b5d..0253204c 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); + } } -- cgit 1.2.3-korg