diff options
author | Stan Bonev <sb5356@att.com> | 2018-10-19 10:24:06 -0400 |
---|---|---|
committer | Dan Timoney <dtimoney@att.com> | 2018-10-25 13:25:55 +0000 |
commit | f9865fbaaffa841172ca0ae8e5c05cb95d1c7d0c (patch) | |
tree | 4be77c4c3dc78af670a637c523908a988093e77c /resource-assignment/provider/src/main/java/org | |
parent | 74e0d6cdac309204f740e43befdab3426d4cd1ec (diff) |
RA: New criteria for querying allocated resources
Change-Id: Ia3a4b162ea4eca51ba7c500ad5daaa3865e26314
Issue-ID: CCSDK-620
Signed-off-by: Stan Bonev <sb5356@att.com>
Diffstat (limited to 'resource-assignment/provider/src/main/java/org')
10 files changed, 126 insertions, 46 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); |