[CCSDK-245] RA: Refactor RA to make it generic
[ccsdk/sli/adaptors.git] / resource-assignment / provider / src / main / java / org / onap / ccsdk / sli / adaptors / rm / comp / ResourceManagerImpl.java
index 2884e98..77d8a68 100644 (file)
@@ -8,9 +8,9 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -24,7 +24,6 @@ package org.onap.ccsdk.sli.adaptors.rm.comp;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
-
 import org.onap.ccsdk.sli.adaptors.lock.comp.LockHelper;
 import org.onap.ccsdk.sli.adaptors.rm.dao.ResourceDao;
 import org.onap.ccsdk.sli.adaptors.rm.data.AllocationOutcome;
@@ -42,7 +41,6 @@ public class ResourceManagerImpl implements ResourceManager {
     private LockHelper lockHelper;
     private ResourceDao resourceDao;
 
-    private String applicationId;
     private int lockTimeout = 10 * 60; // Default 10 min
 
     public ResourceManagerImpl() {
@@ -59,18 +57,20 @@ public class ResourceManagerImpl implements ResourceManager {
     @Override
     public List<Resource> getResourceUnion(String resourceUnionId) {
         List<Resource> rlist = resourceDao.getResourceUnion(resourceUnionId);
-        for (Resource r : rlist)
+        for (Resource r : rlist) {
             ResourceUtil.recalculate(r);
+        }
         return rlist;
     }
 
     @Override
     public AllocationOutcome allocateResources(AllocationRequest allocationRequest) {
-        if (allocationRequest == null)
+        if (allocationRequest == null) {
             throw new IllegalArgumentException("allocateResources called with null argument");
+        }
 
         AllocationFunction allocationFunction =
-                new AllocationFunction(lockHelper, resourceDao, applicationId, allocationRequest, lockTimeout);
+                new AllocationFunction(lockHelper, resourceDao, allocationRequest, lockTimeout);
         allocationFunction.exec();
         AllocationOutcome allocationOutcome = allocationFunction.getAllocationOutcome();
 
@@ -82,8 +82,9 @@ public class ResourceManagerImpl implements ResourceManager {
     @Override
     public void releaseResourceSet(String resourceSetId) {
         List<Resource> resourceList = resourceDao.getResourceSet(resourceSetId);
-        if (resourceList == null || resourceList.isEmpty())
+        if (resourceList == null || resourceList.isEmpty()) {
             return;
+        }
 
         Set<String> lockNames = getLockNames(resourceList);
         ReleaseFunction releaseFunction =
@@ -94,8 +95,9 @@ public class ResourceManagerImpl implements ResourceManager {
     @Override
     public void releaseResourceUnion(String resourceUnionId) {
         List<Resource> resourceList = resourceDao.getResourceUnion(resourceUnionId);
-        if (resourceList == null || resourceList.isEmpty())
+        if (resourceList == null || resourceList.isEmpty()) {
             return;
+        }
 
         Set<String> lockNames = getLockNames(resourceList);
         ReleaseFunction releaseFunction =
@@ -104,9 +106,10 @@ public class ResourceManagerImpl implements ResourceManager {
     }
 
     private Set<String> getLockNames(List<Resource> resourceList) {
-        Set<String> lockNames = new HashSet<String>();
-        for (Resource r : resourceList)
+        Set<String> lockNames = new HashSet<>();
+        for (Resource r : resourceList) {
             lockNames.add(r.resourceKey.assetId);
+        }
         return lockNames;
     }
 
@@ -118,10 +121,6 @@ public class ResourceManagerImpl implements ResourceManager {
         this.lockTimeout = lockTimeout;
     }
 
-    public void setApplicationId(String applicationId) {
-        this.applicationId = applicationId;
-    }
-
     public void setLockHelper(LockHelper lockHelper) {
         this.lockHelper = lockHelper;
     }