From 589e42747b6ad53680a8e51d64597c6590fa0ade Mon Sep 17 00:00:00 2001 From: liamfallon Date: Wed, 19 Feb 2020 16:54:34 +0000 Subject: Fix cascaded get filtering and speed This change adds proper cascading bahaviour to the returned service template for filtered gets on policies. It also significantly improves the performance on get operations, all get operations on the API now result in only one database query. Issue-ID: POLICY-1402 Change-Id: I7c7d0a8d9f1caf8b610461779e242c34b7f77365 Signed-off-by: liamfallon --- .../provider/impl/PolicyToscaPersistenceTest.java | 50 +++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) (limited to 'models-provider/src/test/java/org') diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java index 311686831..11ecadb53 100644 --- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java +++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java @@ -44,6 +44,7 @@ import org.onap.policy.models.provider.PolicyModelsProviderFactory; import org.onap.policy.models.provider.PolicyModelsProviderParameters; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -107,6 +108,34 @@ public class PolicyToscaPersistenceTest { } } + @Test + public void testHpaPolicyTypeGet() throws PfModelException { + long getStartTime = System.currentTimeMillis(); + ToscaServiceTemplate hpaServiceTemplate = + databaseProvider.getPolicyTypes("onap.policies.optimization.resource.HpaPolicy", "1.0.0"); + LOGGER.trace("HPA policy normal get time (ms): {}", System.currentTimeMillis() - getStartTime); + + assertEquals(3, hpaServiceTemplate.getPolicyTypesAsMap().size()); + assertEquals(5, hpaServiceTemplate.getDataTypesAsMap().size()); + + getStartTime = System.currentTimeMillis(); + ToscaPolicyTypeFilter hpaFilter = ToscaPolicyTypeFilter.builder() + .name("onap.policies.optimization.resource.HpaPolicy").version("1.0.0").build(); + hpaServiceTemplate = databaseProvider.getFilteredPolicyTypes(hpaFilter); + LOGGER.trace("HPA policy filter name version get time (ms): {}", System.currentTimeMillis() - getStartTime); + + assertEquals(3, hpaServiceTemplate.getPolicyTypesAsMap().size()); + assertEquals(5, hpaServiceTemplate.getDataTypesAsMap().size()); + + getStartTime = System.currentTimeMillis(); + hpaFilter = ToscaPolicyTypeFilter.builder().name("onap.policies.optimization.resource.HpaPolicy").build(); + hpaServiceTemplate = databaseProvider.getFilteredPolicyTypes(hpaFilter); + LOGGER.trace("HPA policy filter name only get time (ms): {}", System.currentTimeMillis() - getStartTime); + + assertEquals(3, hpaServiceTemplate.getPolicyTypesAsMap().size()); + assertEquals(5, hpaServiceTemplate.getDataTypesAsMap().size()); + } + @Test public void testNamingPolicyGet() throws PfModelException { String policyYamlString = ResourceUtils.getResourceAsString("policies/sdnc.policy.naming.input.tosca.yaml"); @@ -120,7 +149,26 @@ public class PolicyToscaPersistenceTest { long getStartTime = System.currentTimeMillis(); ToscaServiceTemplate namingServiceTemplate = databaseProvider.getPolicies("SDNC_Policy.ONAP_VNF_NAMING_TIMESTAMP", "1.0.0"); - LOGGER.trace("Naming policy get time (ms): {}", System.currentTimeMillis() - getStartTime); + LOGGER.trace("Naming policy normal get time (ms): {}", System.currentTimeMillis() - getStartTime); + + assertEquals(1, namingServiceTemplate.getToscaTopologyTemplate().getPoliciesAsMap().size()); + assertEquals(1, namingServiceTemplate.getPolicyTypesAsMap().size()); + assertEquals(3, namingServiceTemplate.getDataTypesAsMap().size()); + + getStartTime = System.currentTimeMillis(); + ToscaPolicyFilter filter = + ToscaPolicyFilter.builder().name("SDNC_Policy.ONAP_VNF_NAMING_TIMESTAMP").version("1.0.0").build(); + namingServiceTemplate = databaseProvider.getFilteredPolicies(filter); + LOGGER.trace("Naming policy filtered get time (ms): {}", System.currentTimeMillis() - getStartTime); + + assertEquals(1, namingServiceTemplate.getToscaTopologyTemplate().getPoliciesAsMap().size()); + assertEquals(1, namingServiceTemplate.getPolicyTypesAsMap().size()); + assertEquals(3, namingServiceTemplate.getDataTypesAsMap().size()); + + getStartTime = System.currentTimeMillis(); + filter = ToscaPolicyFilter.builder().name("SDNC_Policy.ONAP_VNF_NAMING_TIMESTAMP").build(); + namingServiceTemplate = databaseProvider.getFilteredPolicies(filter); + LOGGER.trace("Naming policy filtered name only get time (ms): {}", System.currentTimeMillis() - getStartTime); assertEquals(1, namingServiceTemplate.getToscaTopologyTemplate().getPoliciesAsMap().size()); assertEquals(1, namingServiceTemplate.getPolicyTypesAsMap().size()); -- cgit 1.2.3-korg