summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStan Bonev <sb5356@att.com>2018-10-19 10:24:06 -0400
committerDan Timoney <dtimoney@att.com>2018-10-25 13:25:55 +0000
commitf9865fbaaffa841172ca0ae8e5c05cb95d1c7d0c (patch)
tree4be77c4c3dc78af670a637c523908a988093e77c
parent74e0d6cdac309204f740e43befdab3426d4cd1ec (diff)
RA: New criteria for querying allocated resources
Change-Id: Ia3a4b162ea4eca51ba7c500ad5daaa3865e26314 Issue-ID: CCSDK-620 Signed-off-by: Stan Bonev <sb5356@att.com>
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/ResourceAllocator.java19
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/EndPointAllocator.java3
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/EndPointAllocatorImpl.java25
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/ResourceRequest.java4
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/comp/ResourceManager.java7
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/comp/ResourceManagerImpl.java8
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/dao/ResourceDao.java7
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/dao/jdbc/AllocationItemJdbcDao.java6
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/dao/jdbc/AllocationItemJdbcDaoImpl.java61
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/dao/jdbc/ResourceDaoImpl.java32
-rw-r--r--resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/DataSetup.java9
-rw-r--r--resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestGetResource.java259
12 files changed, 392 insertions, 48 deletions
diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/ResourceAllocator.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/ResourceAllocator.java
index 385dae752..5dab1738e 100644
--- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/ResourceAllocator.java
+++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/ResourceAllocator.java
@@ -110,13 +110,17 @@ public class ResourceAllocator implements SvcLogicResource {
String resourceTargetType = getParam(ctx, new String[] { "reservation-target-type", "resource-target-type" },
false, null);
String resourceName = getParam(ctx, "resource-name", false, null);
+ String resourceEntityTypeFilter = getParam(ctx, "resource-entity-type-filter", false, null);
+ String resourceEntityIdFilter = getParam(ctx, "resource-entity-id-filter", false, null);
+ String resourceShareGroupFilter = getParam(ctx, "resource-share-group-filter", false, null);
if (resourceEntityId != null && resourceEntityType != null) {
List<ResourceData> rdlist = endPointAllocator.getResourcesForEntity(resourceEntityType, resourceEntityId,
resourceEntityVersion);
setResourceDataInContext(ctx, prefix, rdlist);
} else if (resourceTargetId != null && resourceTargetType != null && resourceName != null) {
- ResourceData rd = endPointAllocator.getResource(resourceTargetType, resourceTargetId, resourceName);
+ ResourceData rd = endPointAllocator.getResource(resourceTargetType, resourceTargetId, resourceName,
+ resourceEntityTypeFilter, resourceEntityIdFilter, resourceShareGroupFilter);
setResourceDataInContext(ctx, prefix, Collections.singletonList(rd));
}
@@ -126,13 +130,14 @@ public class ResourceAllocator implements SvcLogicResource {
public AllocationStatus query(ResourceEntity sd, ResourceTarget rt, ResourceRequest rr,
List<ResourceResponse> rsList) throws Exception {
- if (sd.resourceEntityId != null && sd.resourceEntityType != null) {
+ if (sd != null && sd.resourceEntityId != null && sd.resourceEntityType != null) {
List<ResourceData> rdlist = endPointAllocator.getResourcesForEntity(sd.resourceEntityType,
sd.resourceEntityId, sd.resourceEntityVersion);
setResourceDataInResponse(rdlist, rsList);
- } else if (rt.resourceTargetId != null && rt.resourceTargetType != null && rr.resourceName != null) {
- ResourceData rd = endPointAllocator.getResource(rt.resourceTargetType, rt.resourceTargetId,
- rr.resourceName);
+ } else if (rt != null && rt.resourceTargetId != null && rt.resourceTargetType != null && rr != null
+ && rr.resourceName != null) {
+ ResourceData rd = endPointAllocator.getResource(rt.resourceTargetType, rt.resourceTargetId, rr.resourceName,
+ rr.resourceEntityTypeFilter, rr.resourceEntityIdFilter, rr.resourceShareGroupFilter);
setResourceDataInResponse(Collections.singletonList(rd), rsList);
}
@@ -232,8 +237,8 @@ public class ResourceAllocator implements SvcLogicResource {
resourceManager.releaseResourceSet(resourceSet);
} else {
- String resourceSet = sd.resourceEntityType + "::" + sd.resourceEntityId + "::"
- + sd.resourceEntityVersion;
+ String resourceSet =
+ sd.resourceEntityType + "::" + sd.resourceEntityId + "::" + sd.resourceEntityVersion;
log.info(START_RELEASE_LC, resourceSet);
resourceManager.releaseResourceSet(resourceSet);
}
diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/EndPointAllocator.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/EndPointAllocator.java
index c6461d496..dbc2a31dc 100644
--- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/EndPointAllocator.java
+++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/EndPointAllocator.java
@@ -31,5 +31,6 @@ public interface EndPointAllocator {
List<ResourceData> getResourcesForEntity(String resourceEntityType, String resourceEntityId,
String resourceEntityVersion);
- ResourceData getResource(String resourceTargetType, String resourceTargetId, String resourceName);
+ ResourceData getResource(String resourceTargetType, String resourceTargetId, String resourceName,
+ String resourceEntityTypeFilter, String resourceEntityIdFilter, String resourceShareGroupFilter);
}
diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/EndPointAllocatorImpl.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/EndPointAllocatorImpl.java
index 952ceb6bd..36891fef1 100644
--- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/EndPointAllocatorImpl.java
+++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/EndPointAllocatorImpl.java
@@ -47,7 +47,7 @@ import org.slf4j.LoggerFactory;
public class EndPointAllocatorImpl implements EndPointAllocator {
private static final Logger log = LoggerFactory.getLogger(EndPointAllocatorImpl.class);
-
+
private ResourceManager resourceManager;
private Map<String, List<AllocationRule>> allocationRuleMap;
@@ -204,10 +204,27 @@ public class EndPointAllocatorImpl implements EndPointAllocator {
}
@Override
- public ResourceData getResource(String resourceTargetType, String resourceTargetId, String resourceName) {
- ResourceData rd = new ResourceData();;
+ public ResourceData getResource(String resourceTargetType, String resourceTargetId, String resourceName,
+ String resourceEntityTypeFilter, String resourceEntityIdFilter, String resourceShareGroupFilter) {
+ ResourceData rd = new ResourceData();
String assetId = resourceTargetType + "::" + resourceTargetId;
- Resource r = resourceManager.getResource(resourceName, assetId);
+
+ String resourceUnionFilter = null;
+ if (resourceEntityTypeFilter != null && resourceEntityIdFilter != null) {
+ resourceUnionFilter = resourceEntityTypeFilter + "::" + resourceEntityIdFilter;
+ } else if (resourceEntityTypeFilter != null) {
+ resourceUnionFilter = resourceEntityTypeFilter;
+ } else if (resourceEntityIdFilter != null) {
+ resourceUnionFilter = resourceEntityIdFilter;
+ }
+
+ Resource r = null;
+ if (resourceUnionFilter != null || resourceShareGroupFilter != null) {
+ r = resourceManager.queryResource(resourceName, assetId, resourceUnionFilter, resourceShareGroupFilter);
+ } else {
+ r = resourceManager.getResource(resourceName, assetId);
+ }
+
if (r != null) {
log.info("ResourceName:" + r.resourceKey.resourceName + " assetId:" + r.resourceKey.assetId);
diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/ResourceRequest.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/ResourceRequest.java
index 36a137974..e8bc5ad9d 100644
--- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/ResourceRequest.java
+++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/ResourceRequest.java
@@ -22,7 +22,6 @@
package org.onap.ccsdk.sli.adaptors.ra.comp;
import java.util.List;
-
import org.onap.ccsdk.sli.adaptors.rm.data.Range;
import org.onap.ccsdk.sli.adaptors.rm.data.ResourceType;
@@ -44,4 +43,7 @@ public class ResourceRequest {
public String endPointPosition;
public ResourceType resourceType;
public List<Range> rangeOverrideList;
+ public String resourceEntityTypeFilter;
+ public String resourceEntityIdFilter;
+ public String resourceShareGroupFilter;
}
diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/comp/ResourceManager.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/comp/ResourceManager.java
index 8aaa28687..b40e47582 100644
--- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/comp/ResourceManager.java
+++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/comp/ResourceManager.java
@@ -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.
@@ -22,7 +22,6 @@
package org.onap.ccsdk.sli.adaptors.rm.comp;
import java.util.List;
-
import org.onap.ccsdk.sli.adaptors.rm.data.AllocationOutcome;
import org.onap.ccsdk.sli.adaptors.rm.data.AllocationRequest;
import org.onap.ccsdk.sli.adaptors.rm.data.Resource;
@@ -38,4 +37,6 @@ public interface ResourceManager {
void releaseResourceSet(String resourceSetId);
void releaseResourceUnion(String resourceUnionId);
+
+ Resource queryResource(String resourceName, String assetId, String resourceUnionFilter, String resourceShareGroupFilter);
}
diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/comp/ResourceManagerImpl.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/comp/ResourceManagerImpl.java
index 77d8a6819..d5225b12f 100644
--- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/comp/ResourceManagerImpl.java
+++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/comp/ResourceManagerImpl.java
@@ -105,6 +105,14 @@ public class ResourceManagerImpl implements ResourceManager {
releaseFunction.exec();
}
+ @Override
+ public Resource queryResource(String resourceName, String assetId, String resourceUnionFilter,
+ String resourceShareGroupFilter) {
+ Resource r = resourceDao.query(assetId, resourceName, resourceUnionFilter, resourceShareGroupFilter);
+ ResourceUtil.recalculate(r);
+ return r;
+ }
+
private Set<String> getLockNames(List<Resource> resourceList) {
Set<String> lockNames = new HashSet<>();
for (Resource r : resourceList) {
diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/dao/ResourceDao.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/dao/ResourceDao.java
index 18d6d45c7..bb4b64528 100644
--- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/dao/ResourceDao.java
+++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/dao/ResourceDao.java
@@ -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.
@@ -22,7 +22,6 @@
package org.onap.ccsdk.sli.adaptors.rm.dao;
import java.util.List;
-
import org.onap.ccsdk.sli.adaptors.rm.data.Resource;
public interface ResourceDao {
@@ -36,4 +35,6 @@ public interface ResourceDao {
List<Resource> getResourceSet(String resourceSetId);
List<Resource> getResourceUnion(String resourceUnionId);
+
+ Resource query(String assetId, String resourceName, String resourceUnionFilter, String resourceShareGroupFilter);
}
diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/dao/jdbc/AllocationItemJdbcDao.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/dao/jdbc/AllocationItemJdbcDao.java
index fab61b39a..8e3a12988 100644
--- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/dao/jdbc/AllocationItemJdbcDao.java
+++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/dao/jdbc/AllocationItemJdbcDao.java
@@ -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.
@@ -32,4 +32,6 @@ public interface AllocationItemJdbcDao {
void update(AllocationItem ai);
void delete(long id);
+
+ List<AllocationItem> queryAllocationItems(long resourceId, String resourceUnionFilter, String resourceShareGroupFilter);
}
diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/dao/jdbc/AllocationItemJdbcDaoImpl.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/dao/jdbc/AllocationItemJdbcDaoImpl.java
index 354dd4e0b..fcde0f8f1 100644
--- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/dao/jdbc/AllocationItemJdbcDaoImpl.java
+++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/dao/jdbc/AllocationItemJdbcDaoImpl.java
@@ -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.
@@ -21,14 +21,12 @@
package org.onap.ccsdk.sli.adaptors.rm.dao.jdbc;
-import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Collections;
import java.util.List;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
@@ -59,22 +57,18 @@ public class AllocationItemJdbcDaoImpl implements AllocationItemJdbcDao {
@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;
- }
+ PreparedStatementCreator psc = dbc -> {
+ 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);
@@ -95,12 +89,37 @@ public class AllocationItemJdbcDaoImpl implements AllocationItemJdbcDao {
@Override
public List<AllocationItem> getAllocationItems(long resourceId) {
- if (resourceId <= 0)
+ if (resourceId <= 0) {
return Collections.emptyList();
+ }
return jdbcTemplate.query(GET_SQL, new Object[] { resourceId }, allocationItemRowMapper);
}
+ @Override
+ public List<AllocationItem> queryAllocationItems(long resourceId, String resourceUnionFilter,
+ String resourceShareGroupFilter) {
+ if (resourceId <= 0) {
+ return Collections.emptyList();
+ }
+
+ String sql = GET_SQL;
+
+ if (resourceUnionFilter != null) {
+ sql += " AND resource_union_id LIKE '" + resourceUnionFilter + "'";
+ }
+
+ if (resourceShareGroupFilter != null) {
+ if (resourceShareGroupFilter.equalsIgnoreCase("null")) {
+ sql += " AND resource_share_group_list IS NULL";
+ } else {
+ sql += " AND resource_share_group_list LIKE '" + resourceShareGroupFilter + "'";
+ }
+ }
+
+ return jdbcTemplate.query(sql, new Object[] { resourceId }, allocationItemRowMapper);
+ }
+
private static class AllocationItemRowMapper implements RowMapper<AllocationItem> {
@Override
diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/dao/jdbc/ResourceDaoImpl.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/dao/jdbc/ResourceDaoImpl.java
index e202de778..7deec9223 100644
--- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/dao/jdbc/ResourceDaoImpl.java
+++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/dao/jdbc/ResourceDaoImpl.java
@@ -66,6 +66,32 @@ public class ResourceDaoImpl implements ResourceDao {
}
@Override
+ public org.onap.ccsdk.sli.adaptors.rm.data.Resource query(String assetId, String resourceName,
+ String resourceUnionFilter, String resourceShareGroupFilter) {
+ Resource rEntity = resourceJdbcDao.getResource(assetId, resourceName);
+ org.onap.ccsdk.sli.adaptors.rm.data.Resource r = createResource(rEntity);
+
+ if (r != null) {
+ List<AllocationItem> aiEntityList = allocationItemJdbcDao.queryAllocationItems(rEntity.id,
+ resourceUnionFilter, resourceShareGroupFilter);
+ r.allocationItems = new ArrayList<>();
+ for (AllocationItem aiEntity : aiEntityList) {
+ org.onap.ccsdk.sli.adaptors.rm.data.AllocationItem ai = createAllocationItem(r, aiEntity);
+ r.allocationItems.add(ai);
+ }
+
+ List<ResourceLoad> rlEntityList = resourceLoadJdbcDao.getResourceLoads(rEntity.id);
+ r.resourceLoadList = new ArrayList<>();
+ for (ResourceLoad rlEntity : rlEntityList) {
+ org.onap.ccsdk.sli.adaptors.rm.data.ResourceLoad rl = createResourceLoad(r, rlEntity);
+ r.resourceLoadList.add(rl);
+ }
+ }
+
+ return r;
+ }
+
+ @Override
public void saveResource(org.onap.ccsdk.sli.adaptors.rm.data.Resource resource) {
if (resource == null) {
return;
@@ -201,8 +227,7 @@ public class ResourceDaoImpl implements ResourceDao {
@Override
public List<org.onap.ccsdk.sli.adaptors.rm.data.Resource> getResourceSet(String resourceSetId) {
List<Resource> rEntityList = resourceJdbcDao.getResourceSet(resourceSetId);
- List<org.onap.ccsdk.sli.adaptors.rm.data.Resource> rlist =
- new ArrayList<>();
+ List<org.onap.ccsdk.sli.adaptors.rm.data.Resource> rlist = new ArrayList<>();
for (Resource rEntity : rEntityList) {
org.onap.ccsdk.sli.adaptors.rm.data.Resource r = createResource(rEntity);
rlist.add(r);
@@ -227,8 +252,7 @@ public class ResourceDaoImpl implements ResourceDao {
@Override
public List<org.onap.ccsdk.sli.adaptors.rm.data.Resource> getResourceUnion(String resourceUnionId) {
List<Resource> rEntityList = resourceJdbcDao.getResourceUnion(resourceUnionId);
- List<org.onap.ccsdk.sli.adaptors.rm.data.Resource> rlist =
- new ArrayList<>();
+ List<org.onap.ccsdk.sli.adaptors.rm.data.Resource> rlist = new ArrayList<>();
for (Resource rEntity : rEntityList) {
org.onap.ccsdk.sli.adaptors.rm.data.Resource r = createResource(rEntity);
rlist.add(r);
diff --git a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/DataSetup.java b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/DataSetup.java
index e7b855de7..b41c068ea 100644
--- a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/DataSetup.java
+++ b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/DataSetup.java
@@ -66,7 +66,7 @@ public class DataSetup {
}
public void setupRangeItem(String resourceName, String assetId, String resourceSetId, String resourceUnionId,
- String used) {
+ String resourceShareGroup, String used) {
initTables();
Long rid = resource.getId("asset_id = '" + assetId + "' AND resource_name = '" + resourceName + "'");
@@ -74,7 +74,12 @@ public class DataSetup {
resource.add(assetId, resourceName, "Range", null, used);
rid = resource.getLastId();
}
- allocationItem.add(rid, "SDNC", resourceSetId, resourceUnionId, null, null, used, new Date());
+ allocationItem.add(rid, "SDNC", resourceSetId, resourceUnionId, resourceShareGroup, null, used, new Date());
+ }
+
+ public void setupRangeItem(String resourceName, String assetId, String resourceSetId, String resourceUnionId,
+ String used) {
+ setupRangeItem(resourceName, assetId, resourceSetId, resourceUnionId, null, used);
}
public boolean checkRangeItem(String resourceName, String assetId, String resourceSetId, String used) {
diff --git a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestGetResource.java b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestGetResource.java
new file mode 100644
index 000000000..45889137f
--- /dev/null
+++ b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestGetResource.java
@@ -0,0 +1,259 @@
+package jtest.org.onap.ccsdk.sli.adaptors.ra;
+
+import org.junit.Assert;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.MethodSorters;
+import org.onap.ccsdk.sli.adaptors.ra.ResourceAllocator;
+import org.onap.ccsdk.sli.adaptors.ra.comp.ResourceRequest;
+import org.onap.ccsdk.sli.adaptors.ra.comp.ResourceTarget;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = {"classpath:test-context.xml"})
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestGetResource {
+
+ private static final Logger log = LoggerFactory.getLogger(TestGetResource.class);
+
+ @Autowired(required = true)
+ private ResourceAllocator resourceAllocator;
+
+ @Autowired(required = true)
+ private DataSetup dataSetup;
+
+ private void setupResourceData() {
+ dataSetup.cleanup();
+
+ String targetId = "GBLOND2025MG2";
+ String assetId = "Device::" + targetId;
+ String resourceName = "internal-vlan";
+
+ for (int i = 0; i < 5; i++) {
+ String entityId = "TEST" + i;
+
+ String resourceUnion = "EVC::" + entityId;
+ String resourceSet = resourceUnion + "::1";
+
+ dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, String.valueOf(i));
+ }
+
+ for (int i = 0; i < 5; i++) {
+ String entityId = "TEST" + (i + 10);
+
+ String resourceUnion = "EVC::SVLAN::" + entityId;
+ String resourceSet = resourceUnion + "::1";
+
+ dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, String.valueOf(10 + i));
+ }
+
+ for (int i = 0; i < 5; i++) {
+ String entityId = "TEST" + (i + 20);
+
+ String resourceUnion = "EVC::" + entityId;
+ String resourceSet = resourceUnion + "::1";
+ String resourceShareGroup = "SHARE1";
+
+ dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, resourceShareGroup,
+ String.valueOf(20 + i));
+ }
+
+ for (int i = 0; i < 5; i++) {
+ String entityId = "TEST" + (i + 30);
+
+ String resourceUnion = "EVC::SVLAN::" + entityId;
+ String resourceSet = resourceUnion + "::1";
+ String resourceShareGroup = "SHARE1";
+
+ dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, resourceShareGroup,
+ String.valueOf(30 + i));
+ }
+ }
+
+ @Test
+ public void test001() throws Exception {
+
+ String t = "001";
+ log.info("============== query node " + t + " ================================");
+ log.info("=== Test query for resource target - no additional criteria");
+
+ setupResourceData();
+
+ ResourceTarget rt = new ResourceTarget();
+ rt.resourceTargetId = "GBLOND2025MG2";
+ rt.resourceTargetType = "Device";
+
+ ResourceRequest rr = new ResourceRequest();
+ rr.resourceName = "internal-vlan";
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("ra-input.resource-target-id", "GBLOND2025MG2");
+ ctx.setAttribute("ra-input.resource-target-type", "Device");
+
+ ctx.setAttribute("ra-input.resource-name", "internal-vlan");
+
+ QueryStatus st = resourceAllocator.query("NetworkCapacity", false, null, null, "ra-output", null, ctx);
+
+ Assert.assertTrue(st == QueryStatus.SUCCESS);
+
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list_length"), "1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-name"), "internal-vlan");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-type"), "Device");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-id"), "GBLOND2025MG2");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocated"),
+ "0, 1, 2, 3, 4, 10, 11, 12, 13, 14, 20, 21, 22, 23, 24, 30, 31, 32, 33, 34");
+ }
+
+ @Test
+ public void test002() throws Exception {
+
+ String t = "002";
+ log.info("============== query node " + t + " ================================");
+ log.info("=== Test query for resource target - with resource entity condition");
+
+ setupResourceData();
+
+ ResourceTarget rt = new ResourceTarget();
+ rt.resourceTargetId = "GBLOND2025MG2";
+ rt.resourceTargetType = "Device";
+
+ ResourceRequest rr = new ResourceRequest();
+ rr.resourceName = "internal-vlan";
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("ra-input.resource-target-id", "GBLOND2025MG2");
+ ctx.setAttribute("ra-input.resource-target-type", "Device");
+
+ ctx.setAttribute("ra-input.resource-name", "internal-vlan");
+
+ ctx.setAttribute("ra-input.resource-entity-type-filter", "EVC");
+ ctx.setAttribute("ra-input.resource-entity-id-filter", "SVLAN%");
+
+ QueryStatus st = resourceAllocator.query("NetworkCapacity", false, null, null, "ra-output", null, ctx);
+
+ Assert.assertTrue(st == QueryStatus.SUCCESS);
+
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list_length"), "1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-name"), "internal-vlan");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-type"), "Device");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-id"), "GBLOND2025MG2");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocated"),
+ "10, 11, 12, 13, 14, 30, 31, 32, 33, 34");
+ }
+
+ @Test
+ public void test003() throws Exception {
+
+ String t = "003";
+ log.info("============== query node " + t + " ================================");
+ log.info("=== Test query for resource target - with resource share group condition");
+
+ setupResourceData();
+
+ ResourceTarget rt = new ResourceTarget();
+ rt.resourceTargetId = "GBLOND2025MG2";
+ rt.resourceTargetType = "Device";
+
+ ResourceRequest rr = new ResourceRequest();
+ rr.resourceName = "internal-vlan";
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("ra-input.resource-target-id", "GBLOND2025MG2");
+ ctx.setAttribute("ra-input.resource-target-type", "Device");
+
+ ctx.setAttribute("ra-input.resource-name", "internal-vlan");
+
+ ctx.setAttribute("ra-input.resource-share-group-filter", "SHARE1");
+
+ QueryStatus st = resourceAllocator.query("NetworkCapacity", false, null, null, "ra-output", null, ctx);
+
+ Assert.assertTrue(st == QueryStatus.SUCCESS);
+
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list_length"), "1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-name"), "internal-vlan");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-type"), "Device");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-id"), "GBLOND2025MG2");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocated"),
+ "20, 21, 22, 23, 24, 30, 31, 32, 33, 34");
+ }
+
+ @Test
+ public void test004() throws Exception {
+
+ String t = "004";
+ log.info("============== query node " + t + " ================================");
+ log.info("=== Test query for resource target - with resource share group condition NULL");
+
+ setupResourceData();
+
+ ResourceTarget rt = new ResourceTarget();
+ rt.resourceTargetId = "GBLOND2025MG2";
+ rt.resourceTargetType = "Device";
+
+ ResourceRequest rr = new ResourceRequest();
+ rr.resourceName = "internal-vlan";
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("ra-input.resource-target-id", "GBLOND2025MG2");
+ ctx.setAttribute("ra-input.resource-target-type", "Device");
+
+ ctx.setAttribute("ra-input.resource-name", "internal-vlan");
+
+ ctx.setAttribute("ra-input.resource-share-group-filter", "null");
+
+ QueryStatus st = resourceAllocator.query("NetworkCapacity", false, null, null, "ra-output", null, ctx);
+
+ Assert.assertTrue(st == QueryStatus.SUCCESS);
+
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list_length"), "1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-name"), "internal-vlan");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-type"), "Device");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-id"), "GBLOND2025MG2");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocated"),
+ "0, 1, 2, 3, 4, 10, 11, 12, 13, 14");
+ }
+
+ @Test
+ public void test005() throws Exception {
+
+ String t = "005";
+ log.info("============== query node " + t + " ================================");
+ log.info("=== Test query for resource target - with both resource entity and resource share group conditions");
+
+ setupResourceData();
+
+ ResourceTarget rt = new ResourceTarget();
+ rt.resourceTargetId = "GBLOND2025MG2";
+ rt.resourceTargetType = "Device";
+
+ ResourceRequest rr = new ResourceRequest();
+ rr.resourceName = "internal-vlan";
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("ra-input.resource-target-id", "GBLOND2025MG2");
+ ctx.setAttribute("ra-input.resource-target-type", "Device");
+
+ ctx.setAttribute("ra-input.resource-name", "internal-vlan");
+
+ ctx.setAttribute("ra-input.resource-entity-type-filter", "EVC");
+ ctx.setAttribute("ra-input.resource-entity-id-filter", "SVLAN%");
+ ctx.setAttribute("ra-input.resource-share-group-filter", "null");
+
+ QueryStatus st = resourceAllocator.query("NetworkCapacity", false, null, null, "ra-output", null, ctx);
+
+ Assert.assertTrue(st == QueryStatus.SUCCESS);
+
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list_length"), "1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-name"), "internal-vlan");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-type"), "Device");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-id"), "GBLOND2025MG2");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocated"), "10, 11, 12, 13, 14");
+ }
+}