summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStan Bonev <sb5356@att.com>2018-11-01 09:43:40 -0400
committerStan Bonev <sb5356@att.com>2018-11-01 09:43:40 -0400
commit10431fbfe6e8f99f04cdb7a19cd7341467e998c5 (patch)
treef552e16766c8cfb8313840f0a7c3287fa5b7e6a7
parent3474fad00e780e279976921d60376d8d86b953c0 (diff)
RA: Enhance query for allocated resources
Change-Id: I97d724910d1caac8d7b16455296a41fef1669310 Issue-ID: CCSDK-644 Signed-off-by: Stan Bonev <sb5356@att.com>
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/ResourceAllocator.java63
-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.java59
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/ResourceRequest.java2
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/comp/ResourceManager.java5
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/comp/ResourceManagerImpl.java9
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/dao/ResourceDao.java2
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/dao/jdbc/ResourceDaoImpl.java25
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/dao/jdbc/ResourceJdbcDao.java6
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/dao/jdbc/ResourceJdbcDaoImpl.java61
-rw-r--r--resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestGetResource.java37
-rw-r--r--resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestQueryResource.java115
12 files changed, 296 insertions, 91 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 5dab1738e..e0391bc14 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
@@ -47,7 +47,7 @@ public class ResourceAllocator implements SvcLogicResource {
private static final Logger log = LoggerFactory.getLogger(ResourceAllocator.class);
- private static final String[] INPUT_PREFIX = { "ra-input.", "tmp.resource-allocator." };
+ private static final String[] INPUT_PREFIX = {"ra-input.", "tmp.resource-allocator."};
private static final String START_RELEASE_LC = "Starting release for: {}";
private ResourceManager resourceManager;
@@ -99,20 +99,22 @@ public class ResourceAllocator implements SvcLogicResource {
String orderBy, SvcLogicContext ctx) throws SvcLogicException {
String resourceEntityId = getParam(ctx,
- new String[] { "service-instance-id", "reservation-entity-id", "resource-entity-id" }, false, null);
- String resourceEntityType = getParam(ctx, new String[] { "reservation-entity-type", "resource-entity-type" },
- false, null);
- String resourceEntityVersion = getParam(ctx,
- new String[] { "reservation-entity-version", "resource-entity-version" }, false, "1");
-
- String resourceTargetId = getParam(ctx, new String[] { "reservation-target-id", "resource-target-id" }, false,
- null);
- String resourceTargetType = getParam(ctx, new String[] { "reservation-target-type", "resource-target-type" },
- false, null);
+ new String[] {"service-instance-id", "reservation-entity-id", "resource-entity-id"}, false, null);
+ String resourceEntityType =
+ getParam(ctx, new String[] {"reservation-entity-type", "resource-entity-type"}, false, null);
+ String resourceEntityVersion =
+ getParam(ctx, new String[] {"reservation-entity-version", "resource-entity-version"}, false, "1");
+
+ String resourceTargetId =
+ getParam(ctx, new String[] {"reservation-target-id", "resource-target-id"}, false, null);
+ String resourceTargetType =
+ getParam(ctx, new String[] {"reservation-target-type", "resource-target-type"}, false, null);
String resourceName = getParam(ctx, "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);
+ String resourceTargetTypeFilter = getParam(ctx, "resource-target-type-filter", false, null);
+ String resourceTargetIdFilter = getParam(ctx, "resource-target-id-filter", false, null);
if (resourceEntityId != null && resourceEntityType != null) {
List<ResourceData> rdlist = endPointAllocator.getResourcesForEntity(resourceEntityType, resourceEntityId,
@@ -122,6 +124,10 @@ public class ResourceAllocator implements SvcLogicResource {
ResourceData rd = endPointAllocator.getResource(resourceTargetType, resourceTargetId, resourceName,
resourceEntityTypeFilter, resourceEntityIdFilter, resourceShareGroupFilter);
setResourceDataInContext(ctx, prefix, Collections.singletonList(rd));
+ } else if ((resourceTargetTypeFilter != null || resourceTargetIdFilter != null) && resourceName != null) {
+ List<ResourceData> rdlist = endPointAllocator.getResourcesForTarget(resourceTargetTypeFilter,
+ resourceTargetIdFilter, resourceName);
+ setResourceDataInContext(ctx, prefix, rdlist);
}
return QueryStatus.SUCCESS;
@@ -139,6 +145,11 @@ public class ResourceAllocator implements SvcLogicResource {
ResourceData rd = endPointAllocator.getResource(rt.resourceTargetType, rt.resourceTargetId, rr.resourceName,
rr.resourceEntityTypeFilter, rr.resourceEntityIdFilter, rr.resourceShareGroupFilter);
setResourceDataInResponse(Collections.singletonList(rd), rsList);
+ } else if ((rr.resourceTargetTypeFilter != null || rr.resourceTargetIdFilter != null)
+ && rr.resourceName != null) {
+ List<ResourceData> rdlist = endPointAllocator.getResourcesForTarget(rr.resourceTargetTypeFilter,
+ rr.resourceTargetIdFilter, rr.resourceName);
+ setResourceDataInResponse(rdlist, rsList);
}
return AllocationStatus.Success;
@@ -185,11 +196,11 @@ public class ResourceAllocator implements SvcLogicResource {
@Override
public QueryStatus release(String resource, String key, SvcLogicContext ctx) throws SvcLogicException {
String resourceEntityId = getParam(ctx,
- new String[] { "service-instance-id", "reservation-entity-id", "resource-entity-id" }, true, null);
- String resourceEntityType = getParam(ctx, new String[] { "reservation-entity-type", "resource-entity-type" },
- true, null);
- String resourceEntityVersion = getParam(ctx,
- new String[] { "reservation-entity-version", "resource-entity-version" }, false, null);
+ new String[] {"service-instance-id", "reservation-entity-id", "resource-entity-id"}, true, null);
+ String resourceEntityType =
+ getParam(ctx, new String[] {"reservation-entity-type", "resource-entity-type"}, true, null);
+ String resourceEntityVersion =
+ getParam(ctx, new String[] {"reservation-entity-version", "resource-entity-version"}, false, null);
String endPointPosition = getParam(ctx, "endpoint-position", false, null);
@@ -365,20 +376,20 @@ public class ResourceAllocator implements SvcLogicResource {
private ResourceEntity getResourceEntityData(SvcLogicContext ctx) throws SvcLogicException {
ResourceEntity sd = new ResourceEntity();
sd.resourceEntityId = getParam(ctx,
- new String[] { "service-instance-id", "reservation-entity-id", "resource-entity-id" }, true, null);
- sd.resourceEntityType = getParam(ctx, new String[] { "reservation-entity-type", "resource-entity-type" }, true,
- null);
- sd.resourceEntityVersion = getParam(ctx,
- new String[] { "reservation-entity-version", "resource-entity-version" }, false, "1");
+ new String[] {"service-instance-id", "reservation-entity-id", "resource-entity-id"}, true, null);
+ sd.resourceEntityType =
+ getParam(ctx, new String[] {"reservation-entity-type", "resource-entity-type"}, true, null);
+ sd.resourceEntityVersion =
+ getParam(ctx, new String[] {"reservation-entity-version", "resource-entity-version"}, false, "1");
sd.data = getDataParam(ctx, "reservation-entity-data", "resource-entity-data", "service-data");
return sd;
}
private ResourceTarget getResourceTargetData(SvcLogicContext ctx) throws SvcLogicException {
ResourceTarget sd = new ResourceTarget();
- sd.resourceTargetId = getParam(ctx, new String[] { "reservation-target-id", "resource-target-id" }, true, null);
- sd.resourceTargetType = getParam(ctx, new String[] { "reservation-target-type", "resource-target-type" }, true,
- null);
+ sd.resourceTargetId = getParam(ctx, new String[] {"reservation-target-id", "resource-target-id"}, true, null);
+ sd.resourceTargetType =
+ getParam(ctx, new String[] {"reservation-target-type", "resource-target-type"}, true, null);
sd.data = getDataParam(ctx, "reservation-target-data", "resource-target-data", "equipment-data");
return sd;
}
@@ -435,7 +446,7 @@ public class ResourceAllocator implements SvcLogicResource {
"One of the following variable is required in DG context: " + Arrays.deepToString(names));
}
- log.info("Param: " + names + " not supplied. Using default: " + def);
+ log.info("Param: " + Arrays.deepToString(names) + " not supplied. Using default: " + def);
return def;
}
@@ -487,4 +498,4 @@ public class ResourceAllocator implements SvcLogicResource {
public void setSpeedUtil(SpeedUtil speedUtil) {
this.speedUtil = speedUtil;
}
-} \ No newline at end of file
+}
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 dbc2a31dc..abfb8d44f 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
@@ -33,4 +33,7 @@ public interface EndPointAllocator {
ResourceData getResource(String resourceTargetType, String resourceTargetId, String resourceName,
String resourceEntityTypeFilter, String resourceEntityIdFilter, String resourceShareGroupFilter);
+
+ List<ResourceData> getResourcesForTarget(String resourceTargetTypeFilter, String resourceTargetIdFilter,
+ String resourceName);
}
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 36891fef1..f4109a1de 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
@@ -204,6 +204,65 @@ public class EndPointAllocatorImpl implements EndPointAllocator {
}
@Override
+ public List<ResourceData> getResourcesForTarget(String resourceTargetTypeFilter, String resourceTargetIdFilter,
+ String resourceName) {
+ List<ResourceData> rdlist = new ArrayList<>();
+
+ String assetIdFilter = null;
+ if (resourceTargetTypeFilter != null && resourceTargetIdFilter != null) {
+ assetIdFilter = resourceTargetTypeFilter + "::" + resourceTargetIdFilter;
+ } else if (resourceTargetTypeFilter != null) {
+ assetIdFilter = resourceTargetTypeFilter;
+ } else if (resourceTargetIdFilter != null) {
+ assetIdFilter = resourceTargetIdFilter;
+ }
+
+ List<Resource> rlist = resourceManager.queryResources(resourceName, assetIdFilter);
+
+ for (Resource r : rlist) {
+
+ log.info("ResourceName:" + r.resourceKey.resourceName + " assetId:" + r.resourceKey.assetId);
+
+ ResourceData rd = new ResourceData();
+ rdlist.add(rd);
+
+ rd.resourceName = r.resourceKey.resourceName;
+ int i1 = r.resourceKey.assetId.indexOf("::");
+ if (i1 > 0) {
+ rd.resourceTargetType = r.resourceKey.assetId.substring(0, i1);
+ rd.resourceTargetId = r.resourceKey.assetId.substring(i1 + 2);
+
+ int i2 = r.resourceKey.assetId.lastIndexOf("::");
+ if (i2 > i1) {
+ rd.resourceTargetValue = r.resourceKey.assetId.substring(i2 + 2);
+ }
+ } else {
+ rd.resourceTargetType = "";
+ rd.resourceTargetId = r.resourceKey.assetId;
+ }
+
+ rd.data = new HashMap<>();
+
+ if (r instanceof RangeResource) {
+ RangeResource rr = (RangeResource) r;
+
+ log.info("rr.used: " + rr.used);
+ String ss = String.valueOf(rr.used);
+ ss = ss.substring(1, ss.length() - 1);
+ rd.data.put("allocated", ss);
+
+ } else if (r instanceof LimitResource) {
+ LimitResource lr = (LimitResource) r;
+
+ log.info("lr.used: " + lr.used);
+ rd.data.put("allocated", String.valueOf(lr.used));
+ }
+ }
+
+ return rdlist;
+ }
+
+ @Override
public ResourceData getResource(String resourceTargetType, String resourceTargetId, String resourceName,
String resourceEntityTypeFilter, String resourceEntityIdFilter, String resourceShareGroupFilter) {
ResourceData rd = new ResourceData();
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 e8bc5ad9d..c870bc414 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
@@ -46,4 +46,6 @@ public class ResourceRequest {
public String resourceEntityTypeFilter;
public String resourceEntityIdFilter;
public String resourceShareGroupFilter;
+ public String resourceTargetTypeFilter;
+ public String resourceTargetIdFilter;
}
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 b40e47582..ee77dee96 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
@@ -38,5 +38,8 @@ public interface ResourceManager {
void releaseResourceUnion(String resourceUnionId);
- Resource queryResource(String resourceName, String assetId, String resourceUnionFilter, String resourceShareGroupFilter);
+ Resource queryResource(String resourceName, String assetId, String resourceUnionFilter,
+ String resourceShareGroupFilter);
+
+ List<Resource> queryResources(String resourceName, String assetIdFilter);
}
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 d5225b12f..9ba88912d 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
@@ -113,6 +113,15 @@ public class ResourceManagerImpl implements ResourceManager {
return r;
}
+ @Override
+ public List<Resource> queryResources(String resourceName, String assetIdFilter) {
+ List<Resource> rlist = resourceDao.query(assetIdFilter, resourceName);
+ for (Resource r : rlist) {
+ ResourceUtil.recalculate(r);
+ }
+ return rlist;
+ }
+
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 bb4b64528..57c3e938e 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
@@ -37,4 +37,6 @@ public interface ResourceDao {
List<Resource> getResourceUnion(String resourceUnionId);
Resource query(String assetId, String resourceName, String resourceUnionFilter, String resourceShareGroupFilter);
+
+ List<Resource> query(String assetIdFilter, String resourceName);
}
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 7deec9223..172651631 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
@@ -92,6 +92,31 @@ public class ResourceDaoImpl implements ResourceDao {
}
@Override
+ public List<org.onap.ccsdk.sli.adaptors.rm.data.Resource> query(String assetIdFilter, String resourceName) {
+ List<Resource> rEntityList = resourceJdbcDao.queryResources(assetIdFilter, resourceName);
+ 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);
+
+ List<AllocationItem> aiEntityList = allocationItemJdbcDao.getAllocationItems(rEntity.id);
+ 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 rlist;
+ }
+
+ @Override
public void saveResource(org.onap.ccsdk.sli.adaptors.rm.data.Resource resource) {
if (resource == null) {
return;
diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/dao/jdbc/ResourceJdbcDao.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/dao/jdbc/ResourceJdbcDao.java
index b32f34082..fe19fd905 100644
--- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/dao/jdbc/ResourceJdbcDao.java
+++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/dao/jdbc/ResourceJdbcDao.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.
@@ -27,6 +27,8 @@ public interface ResourceJdbcDao {
Resource getResource(String assetId, String resourceName);
+ List<Resource> queryResources(String assetIdFilter, String resourceName);
+
List<Resource> getResourceSet(String resourceSetId);
List<Resource> getResourceUnion(String resourceUnionId);
diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/dao/jdbc/ResourceJdbcDaoImpl.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/dao/jdbc/ResourceJdbcDaoImpl.java
index 6d4455e7e..9283df9ea 100644
--- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/dao/jdbc/ResourceJdbcDaoImpl.java
+++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/dao/jdbc/ResourceJdbcDaoImpl.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,13 +21,11 @@
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.util.Collections;
import java.util.List;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
@@ -43,6 +41,9 @@ public class ResourceJdbcDaoImpl implements ResourceJdbcDao {
private static final String RESOURCE_SQL = "SELECT * FROM RESOURCE WHERE asset_id = ? AND resource_name = ?";
+ private static final String RESOURCE_QUERY_1_SQL =
+ "SELECT * FROM RESOURCE WHERE asset_id LIKE ? 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 = ?)";
@@ -63,46 +64,56 @@ public class ResourceJdbcDaoImpl implements ResourceJdbcDao {
@Override
public Resource getResource(String assetId, String resourceName) {
- if (assetId == null || assetId.trim().length() == 0 || resourceName == null ||
- resourceName.trim().length() == 0)
+ if (assetId == null || assetId.trim().length() == 0 || resourceName == null
+ || resourceName.trim().length() == 0) {
return null;
+ }
- List<Resource> ll = jdbcTemplate.query(RESOURCE_SQL, new Object[] { assetId, resourceName }, resourceRowMapper);
+ List<Resource> ll = jdbcTemplate.query(RESOURCE_SQL, new Object[] {assetId, resourceName}, resourceRowMapper);
return ll.isEmpty() ? null : ll.get(0);
}
@Override
+ public List<Resource> queryResources(String assetIdFilter, String resourceName) {
+ if (assetIdFilter == null || assetIdFilter.trim().length() == 0 || resourceName == null
+ || resourceName.trim().length() == 0) {
+ return Collections.emptyList();
+ }
+
+
+ return jdbcTemplate.query(RESOURCE_QUERY_1_SQL, new Object[] {assetIdFilter, resourceName}, resourceRowMapper);
+ }
+
+ @Override
public List<Resource> getResourceSet(String resourceSetId) {
- if (resourceSetId == null)
+ if (resourceSetId == null) {
return Collections.emptyList();
+ }
- return jdbcTemplate.query(RESOURCE_SET_SQL, new Object[] { resourceSetId }, resourceRowMapper);
+ return jdbcTemplate.query(RESOURCE_SET_SQL, new Object[] {resourceSetId}, resourceRowMapper);
}
@Override
public List<Resource> getResourceUnion(String resourceUnionId) {
- if (resourceUnionId == null)
+ if (resourceUnionId == null) {
return Collections.emptyList();
+ }
- return jdbcTemplate.query(RESOURCE_UNION_SQL, new Object[] { resourceUnionId }, resourceRowMapper);
+ 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;
- }
+ PreparedStatementCreator psc = dbc -> {
+ 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);
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
index 45889137f..a968c3fb1 100644
--- 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
@@ -6,8 +6,6 @@ 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;
@@ -86,13 +84,6 @@ public class TestGetResource {
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");
@@ -120,13 +111,6 @@ public class TestGetResource {
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");
@@ -157,13 +141,6 @@ public class TestGetResource {
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");
@@ -193,13 +170,6 @@ public class TestGetResource {
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");
@@ -229,13 +199,6 @@ public class TestGetResource {
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");
diff --git a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestQueryResource.java b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestQueryResource.java
new file mode 100644
index 000000000..4be985b2a
--- /dev/null
+++ b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestQueryResource.java
@@ -0,0 +1,115 @@
+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.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 TestQueryResource {
+
+ private static final Logger log = LoggerFactory.getLogger(TestQueryResource.class);
+
+ @Autowired(required = true)
+ private ResourceAllocator resourceAllocator;
+
+ @Autowired(required = true)
+ private DataSetup dataSetup;
+
+ private void setupResourceData() {
+ dataSetup.cleanup();
+
+ for (int k = 0; k < 6; k++) {
+ String assetId = "Port::TESTPORT-" + (k / 2 + 1) + "-" + (k + 1);
+
+ for (int i = 0; i < 5; i++) {
+ String entityId = "TEST-" + i + "-" + (k / 2 + 1);
+
+ String resourceUnion = "EVC::" + entityId;
+ String resourceSet = resourceUnion + "::1";
+
+ dataSetup.setupRangeItem("test-range-1", assetId, resourceSet, resourceUnion, String.valueOf(i));
+ }
+ }
+
+ for (int k = 0; k < 6; k++) {
+ String assetId = "Port::TESTPORT-" + (k / 2 + 1) + "-" + (k + 1);
+
+ for (int i = 0; i < 5; i++) {
+ String entityId = "TEST-" + i + "-" + (k / 2 + 1);
+
+ String resourceUnion = "EVC::" + entityId;
+ String resourceSet = resourceUnion + "::1";
+
+ dataSetup.setupLimitItem("test-limit-1", assetId, resourceSet, resourceUnion, (i + 1) * 100);
+ }
+ }
+ }
+
+ @Test
+ public void test001() throws Exception {
+
+ String t = "001";
+ log.info("============== query node " + t + " ================================");
+ log.info("=== Test query for resources - with resource target condition - range");
+
+ setupResourceData();
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("ra-input.resource-target-id-filter", "TESTPORT-1-%");
+ ctx.setAttribute("ra-input.resource-target-type-filter", "Port");
+
+ ctx.setAttribute("ra-input.resource-name", "test-range-1");
+
+ 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"), "2");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-name"), "test-range-1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-type"), "Port");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-id"), "TESTPORT-1-1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocated"), "0, 1, 2, 3, 4");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].resource-name"), "test-range-1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].resource-target-type"), "Port");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].resource-target-id"), "TESTPORT-1-2");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocated"), "0, 1, 2, 3, 4");
+ }
+
+ @Test
+ public void test002() throws Exception {
+
+ String t = "002";
+ log.info("============== query node " + t + " ================================");
+ log.info("=== Test query for resources - with resource target condition - limit");
+
+ setupResourceData();
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("ra-input.resource-target-id-filter", "TESTPORT-%-1");
+ ctx.setAttribute("ra-input.resource-target-type-filter", "Port");
+
+ ctx.setAttribute("ra-input.resource-name", "test-limit-1");
+
+ 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"), "test-limit-1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-type"), "Port");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-id"), "TESTPORT-1-1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocated"), "1500");
+ }
+}