Adding totalPolicyDeployCounts updates to PapStasticsManager 32/126432/8
authorisaac <isaac.adorno@att.com>
Tue, 4 Jan 2022 22:34:20 +0000 (16:34 -0600)
committerIsaac Adorno <isaac.adorno@att.com>
Fri, 7 Jan 2022 14:51:17 +0000 (14:51 +0000)
Issue-ID: POLICY-3836
Signed-off-by: isaac <isaac.adorno@att.com>
Change-Id: Ia4ed2595984f68bf75ca9dacb6aa76f04a306224

main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupDeployProvider.java
main/src/test/java/org/onap/policy/pap/main/rest/ProviderSuper.java
main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeployProvider.java
main/src/test/resources/simpleDeploy/multiple_requests.json [new file with mode: 0644]

index 5277ca6..2963fe6 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP PAP
  * ================================================================================
- * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 2022 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2020-2021 Nordix Foundation.
  * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
  * ================================================================================
@@ -56,6 +56,7 @@ import org.onap.policy.models.pdp.concepts.PdpSubGroup;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.pap.main.PapConstants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
@@ -428,6 +429,8 @@ public class PdpGroupDeployProvider extends ProviderBase {
 
         ToscaConceptIdentifier desiredIdent = policy.getIdentifier();
         ToscaConceptIdentifier desiredType = policy.getTypeIdentifier();
+        PapStatisticsManager mgr = Registry.get(PapConstants.REG_STATISTICS_MANAGER, PapStatisticsManager.class);
+        mgr.updateTotalPolicyDeployCount();
 
         return (group, subgroup) -> {
 
index f5798fd..26e44d8 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP PAP
  * ================================================================================
- * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2022 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2021 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -81,7 +81,7 @@ public class ProviderSuper {
     protected PdpModifyRequestMap reqmap;
     protected PolicyModelsProviderFactoryWrapper daofact;
     protected ToscaPolicy policy1;
-
+    protected PapStatisticsManager statsmanager;
 
     /**
      * Configures DAO, captors, and various mocks.
@@ -98,6 +98,7 @@ public class ProviderSuper {
         lockit = new Object();
         daofact = mock(PolicyModelsProviderFactoryWrapper.class);
         policy1 = loadPolicy("policy.json");
+        statsmanager = mock(PapStatisticsManager.class);
 
         when(daofact.create()).thenReturn(dao);
 
@@ -112,6 +113,7 @@ public class ProviderSuper {
         Registry.register(PapConstants.REG_PDP_MODIFY_MAP, reqmap);
         Registry.register(PapConstants.REG_PAP_DAO_FACTORY, daofact);
         Registry.register(PapConstants.REG_POLICY_NOTIFIER, notifier);
+        Registry.register(PapConstants.REG_STATISTICS_MANAGER, statsmanager);
     }
 
     protected void assertGroup(List<PdpGroup> groups, String name) {
index 40e37e4..28e515f 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP PAP
  * ================================================================================
- * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2022 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2021 Nordix Foundation.
  * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
  * ================================================================================
@@ -54,6 +54,7 @@ import org.onap.policy.models.pdp.concepts.PdpSubGroup;
 import org.onap.policy.models.pdp.concepts.PdpUpdate;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.pap.main.PapConstants;
 
 public class TestPdpGroupDeployProvider extends ProviderSuper {
 
@@ -575,6 +576,25 @@ public class TestPdpGroupDeployProvider extends ProviderSuper {
                 .hasMessage("policy not supported by any PDP group: policyA 1.2.3");
     }
 
+    /**
+     * Tests PapStatisticsManager counts when policies are added to a subgroup.
+     *
+     * @throws Exception if an error occurs
+     */
+    @Test
+    public void testDeployedPdpGroupCountStatistics() throws Exception {
+        Registry.unregister(PapConstants.REG_STATISTICS_MANAGER);
+        PapStatisticsManager mgr = new PapStatisticsManager();
+        Registry.register(PapConstants.REG_STATISTICS_MANAGER, mgr);
+
+        when(dao.getFilteredPdpGroups(any())).thenReturn(loadGroups("deployPoliciesWildCard.json"));
+        prov.deployPolicies(loadRequest("multiple_requests.json"), DEFAULT_USER);
+        assertEquals(mgr.getTotalPolicyDeployCount(), 3);
+
+        Registry.unregister(PapConstants.REG_STATISTICS_MANAGER);
+        Registry.register(PapConstants.REG_STATISTICS_MANAGER, statsmanager);
+    }
+
     @Test
     public void testMakeUpdater() throws Exception {
         /*
diff --git a/main/src/test/resources/simpleDeploy/multiple_requests.json b/main/src/test/resources/simpleDeploy/multiple_requests.json
new file mode 100644 (file)
index 0000000..926d486
--- /dev/null
@@ -0,0 +1,25 @@
+{
+  "policies": [
+    {
+      "name": "policy_test1",
+      "policy-id": "policy_test1",
+      "version": "1.2.3",
+      "type": "typeA",
+      "type_version": "100.2.3"
+    },
+    {
+      "name": "policy_test2",
+      "policy-id": "policy_test2",
+      "version": "4.5.6",
+      "type": "typeB",
+      "type_version": "100.2.3"
+    },
+    {
+      "name": "policy_test3",
+      "policy-id": "policy_test3",
+      "version": "1.2.3",
+      "type": "typeC",
+      "type_version": "100.2.3"
+    }
+  ]
+}