summaryrefslogtreecommitdiffstats
path: root/models-provider/src
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2020-02-19 16:54:34 +0000
committerliamfallon <liam.fallon@est.tech>2020-02-19 17:05:12 +0000
commit589e42747b6ad53680a8e51d64597c6590fa0ade (patch)
treeb847e16d224a7abc999391252db12af918f050b6 /models-provider/src
parentca409ee108f3f653d66be804e8a9f95f794e26d4 (diff)
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 <liam.fallon@est.tech>
Diffstat (limited to 'models-provider/src')
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java50
1 files changed, 49 insertions, 1 deletions
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;
@@ -108,6 +109,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");
ToscaServiceTemplate serviceTemplate =
@@ -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());