diff options
author | sebdet <sebastien.determe@intl.att.com> | 2021-03-22 18:55:46 +0100 |
---|---|---|
committer | sebdet <sebastien.determe@intl.att.com> | 2021-04-01 16:53:14 +0200 |
commit | ee233569e74e4620cb35ce4e9c4320b30d108824 (patch) | |
tree | 5c0dbbbe575381d9696ae3f6cf841bea499c0254 /src | |
parent | 1da36e7c13bc7efac7bdd8425cede0e69d3f1335 (diff) |
Rework the backend to support PDP updates
Add new mem structure so that we do not need to parse the same Json for each policy/type + rework the camel flows so that we use the same code for loop and policies related calls
Issue-ID: POLICY-2930
Issue-ID: POLICY-2931
Signed-off-by: sebdet <sebastien.determe@intl.att.com>
Change-Id: I3c30c4f87cf669b40511472d518fe5ccc89f56f0
Diffstat (limited to 'src')
13 files changed, 683 insertions, 214 deletions
diff --git a/src/main/java/org/onap/policy/clamp/loop/components/external/PolicyComponent.java b/src/main/java/org/onap/policy/clamp/loop/components/external/PolicyComponent.java index 648463d78..ff4e2643c 100644 --- a/src/main/java/org/onap/policy/clamp/loop/components/external/PolicyComponent.java +++ b/src/main/java/org/onap/policy/clamp/loop/components/external/PolicyComponent.java @@ -1,8 +1,8 @@ /*- * ============LICENSE_START======================================================= - * ONAP CLAMP + * ONAP POLICY-CLAMP * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights + * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights * reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -25,20 +25,19 @@ package org.onap.policy.clamp.loop.components.external; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; import javax.persistence.Transient; import org.apache.camel.Exchange; +import org.onap.policy.clamp.clds.util.JsonUtils; import org.onap.policy.clamp.loop.Loop; import org.onap.policy.clamp.policy.microservice.MicroServicePolicy; import org.onap.policy.clamp.policy.operational.OperationalPolicy; +import org.onap.policy.clamp.policy.pdpgroup.PdpGroupPayload; +/** + * This class represents the policy state according to all policies involved in the control loop. + * It can compute it with all policy queries result. + * It contains also the method to generate the PDP payload used for the policies deployment. + */ public class PolicyComponent extends ExternalComponent { @Transient @@ -81,81 +80,22 @@ public class PolicyComponent extends ExternalComponent { * @return The json, payload to send */ public static String createPoliciesPayloadPdpGroup(Loop loop, String action) { - Map<String, Map<String, List<JsonObject>>> pdpGroupMap = new HashMap<>(); + PdpGroupPayload pdpGroupPayload = new PdpGroupPayload(); for (OperationalPolicy opPolicy : loop.getOperationalPolicies()) { - updatePdpGroupMap(opPolicy.getPdpGroup(), opPolicy.getPdpSubgroup(), - opPolicy.getName(), - "1.0.0", pdpGroupMap); + pdpGroupPayload + .updatePdpGroupMap(opPolicy.getPdpGroup(), opPolicy.getPdpSubgroup(), opPolicy.getName(), "1.0.0"); } for (MicroServicePolicy msPolicy : loop.getMicroServicePolicies()) { - updatePdpGroupMap(msPolicy.getPdpGroup(), msPolicy.getPdpSubgroup(), - msPolicy.getName(), - "1.0.0", pdpGroupMap); + pdpGroupPayload + .updatePdpGroupMap(msPolicy.getPdpGroup(), msPolicy.getPdpSubgroup(), msPolicy.getName(), "1.0.0"); } - String payload = new GsonBuilder().setPrettyPrinting().create() - .toJson(generateActivatePdpGroupPayload(pdpGroupMap, action)); + String payload = JsonUtils.GSON.toJson(pdpGroupPayload.generateActivatePdpGroupPayload(action)); logger.info("PdpGroup policy payload: " + payload); return payload; } - private static void updatePdpGroupMap(String pdpGroup, - String pdpSubGroup, - String policyName, - String policyVersion, - Map<String, Map<String, - List<JsonObject>>> pdpGroupMap) { - JsonObject policyJson = new JsonObject(); - policyJson.addProperty("name", policyName); - policyJson.addProperty("version", policyVersion); - Map<String, List<JsonObject>> pdpSubGroupMap; - List<JsonObject> policyList; - if (pdpGroupMap.get(pdpGroup) == null) { - pdpSubGroupMap = new HashMap<>(); - policyList = new LinkedList<>(); - } else { - pdpSubGroupMap = pdpGroupMap.get(pdpGroup); - if (pdpSubGroupMap.get(pdpSubGroup) == null) { - policyList = new LinkedList<>(); - } else { - policyList = (List<JsonObject>) pdpSubGroupMap.get(pdpSubGroup); - } - } - policyList.add(policyJson); - pdpSubGroupMap.put(pdpSubGroup, policyList); - pdpGroupMap.put(pdpGroup, pdpSubGroupMap); - } - - private static JsonObject generateActivatePdpGroupPayload( - Map<String, Map<String, List<JsonObject>>> pdpGroupMap, String action) { - JsonArray payloadArray = new JsonArray(); - for (Entry<String, Map<String, List<JsonObject>>> pdpGroupInfo : pdpGroupMap.entrySet()) { - JsonObject pdpGroupNode = new JsonObject(); - JsonArray subPdpArray = new JsonArray(); - pdpGroupNode.addProperty("name", pdpGroupInfo.getKey()); - pdpGroupNode.add("deploymentSubgroups", subPdpArray); - - for (Entry<String, List<JsonObject>> pdpSubGroupInfo : pdpGroupInfo.getValue().entrySet()) { - JsonObject pdpSubGroupNode = new JsonObject(); - subPdpArray.add(pdpSubGroupNode); - pdpSubGroupNode.addProperty("pdpType", pdpSubGroupInfo.getKey()); - pdpSubGroupNode.addProperty("action", action); - - JsonArray policyArray = new JsonArray(); - pdpSubGroupNode.add("policies", policyArray); - - for (JsonObject policy : pdpSubGroupInfo.getValue()) { - policyArray.add(policy); - } - } - payloadArray.add(pdpGroupNode); - } - JsonObject jsonObject = new JsonObject(); - jsonObject.add("groups", payloadArray); - return jsonObject; - } - private static ExternalComponentState findNewState(boolean found, boolean deployed) { ExternalComponentState newState = NOT_SENT; diff --git a/src/main/java/org/onap/policy/clamp/loop/deploy/DcaeDeployParameters.java b/src/main/java/org/onap/policy/clamp/loop/deploy/DcaeDeployParameters.java index 9d56f23c4..1a1414611 100644 --- a/src/main/java/org/onap/policy/clamp/loop/deploy/DcaeDeployParameters.java +++ b/src/main/java/org/onap/policy/clamp/loop/deploy/DcaeDeployParameters.java @@ -1,8 +1,8 @@ /*- * ============LICENSE_START======================================================= - * ONAP CLAMP + * ONAP POLICY-CLAMP * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights + * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights * reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -109,5 +109,4 @@ public class DcaeDeployParameters { globalProperties.add("dcaeDeployParameters", deployParamJson); return globalProperties; } - } diff --git a/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupPayload.java b/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupPayload.java new file mode 100644 index 000000000..c89395044 --- /dev/null +++ b/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupPayload.java @@ -0,0 +1,108 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP POLICY-CLAMP + * ================================================================================ + * Copyright (C) 2021 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END============================================ + * =================================================================== + * + */ + +package org.onap.policy.clamp.policy.pdpgroup; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +/** + * This is an utility class that build the PDP group policy payload. + * This is used when policies have to be deployed to PDP group/subgroups on the Policy Engine. + */ +public class PdpGroupPayload { + + private Map<String, Map<String, List<JsonObject>>> pdpGroupMap = new HashMap<>(); + + /** + * This method updates the pdpGroupMap structure for a specific policy/version/pdpdGroup/PdpSubGroup. + * + * @param pdpGroup The pdp Group in String + * @param pdpSubGroup The pdp Sub Group in String + * @param policyName The policy name + * @param policyVersion The policy Version + */ + public void updatePdpGroupMap(String pdpGroup, + String pdpSubGroup, + String policyName, + String policyVersion) { + JsonObject policyJson = new JsonObject(); + policyJson.addProperty("name", policyName); + policyJson.addProperty("version", policyVersion); + Map<String, List<JsonObject>> pdpSubGroupMap; + List<JsonObject> policyList; + if (pdpGroupMap.get(pdpGroup) == null) { + pdpSubGroupMap = new HashMap<>(); + policyList = new LinkedList<>(); + } else { + pdpSubGroupMap = pdpGroupMap.get(pdpGroup); + if (pdpSubGroupMap.get(pdpSubGroup) == null) { + policyList = new LinkedList<>(); + } else { + policyList = pdpSubGroupMap.get(pdpSubGroup); + } + } + policyList.add(policyJson); + pdpSubGroupMap.put(pdpSubGroup, policyList); + pdpGroupMap.put(pdpGroup, pdpSubGroupMap); + } + + /** + * This method generates the Payload in Json from the pdp Group structure containing the policies/versions + * that must be sent to the policy framework. + * + * @param action The action to do, either a POST or a DELETE + * @return The Json that can be sent to policy framework as JsonObject + */ + public JsonObject generateActivatePdpGroupPayload(String action) { + JsonArray payloadArray = new JsonArray(); + for (Map.Entry<String, Map<String, List<JsonObject>>> pdpGroupInfo : pdpGroupMap.entrySet()) { + JsonObject pdpGroupNode = new JsonObject(); + JsonArray subPdpArray = new JsonArray(); + pdpGroupNode.addProperty("name", pdpGroupInfo.getKey()); + pdpGroupNode.add("deploymentSubgroups", subPdpArray); + + for (Map.Entry<String, List<JsonObject>> pdpSubGroupInfo : pdpGroupInfo.getValue().entrySet()) { + JsonObject pdpSubGroupNode = new JsonObject(); + subPdpArray.add(pdpSubGroupNode); + pdpSubGroupNode.addProperty("pdpType", pdpSubGroupInfo.getKey()); + pdpSubGroupNode.addProperty("action", action); + + JsonArray policyArray = new JsonArray(); + pdpSubGroupNode.add("policies", policyArray); + + for (JsonObject policy : pdpSubGroupInfo.getValue()) { + policyArray.add(policy); + } + } + payloadArray.add(pdpGroupNode); + } + JsonObject jsonObject = new JsonObject(); + jsonObject.add("groups", payloadArray); + return jsonObject; + } +} diff --git a/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupsAnalyzer.java b/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupsAnalyzer.java index 768872750..6098d0f63 100644 --- a/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupsAnalyzer.java +++ b/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupsAnalyzer.java @@ -25,9 +25,14 @@ package org.onap.policy.clamp.policy.pdpgroup; import com.google.gson.JsonArray; import com.google.gson.JsonObject; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.Objects; -import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; +import org.apache.commons.collections4.CollectionUtils; +import org.onap.policy.clamp.clds.util.JsonUtils; import org.onap.policy.clamp.loop.template.PolicyModel; import org.onap.policy.models.pdp.concepts.PdpGroup; import org.onap.policy.models.pdp.concepts.PdpGroups; @@ -44,8 +49,77 @@ public class PdpGroupsAnalyzer { public static final String SUPPORTED_PDP_GROUPS_INFO = "supportedPdpGroups"; /** - * Get supported subGroups based on the defined policy type and version for s specific PDPgroup. - * It returns null if the Group is not ACTIVE or if the policytype/version has not been found in the PDPSubgroups. + * This structure holds the map of PdpGroups per policies, policies are identifed by ToscaConceptIdentifier. + */ + private final Map<ToscaConceptIdentifier, Map<String, PdpGroup>> pdpGroupsDeploymentPerPolicy = + new ConcurrentHashMap<>(); + + /** + * Constructor taking he PDPGroups info from the PEF. + * It then caches the groups per policies and per types. + * + * @param pdpGroups The pdpgroup info from the PEF + */ + public PdpGroupsAnalyzer(PdpGroups pdpGroups) { + this.analyzePdpGroups(pdpGroups); + } + + /** + * Getter of the GroupDeploymentPerPolicy structure. + * + * @return The map of policies. + */ + public Map<ToscaConceptIdentifier, Map<String, PdpGroup>> getPdpGroupsDeploymentPerPolicy() { + return pdpGroupsDeploymentPerPolicy; + } + + private static void addInfoToPdpGroupsStructure(ToscaConceptIdentifier toscaId, + Map<ToscaConceptIdentifier, + Map<String, + PdpGroup>> pdpGroupsDeploymentPerToscaIdentifier, + PdpGroup pdpGroupSource, + PdpSubGroup pdpSubGroupSource) { + // Copy the subgroup but empty the policies & types + pdpGroupsDeploymentPerToscaIdentifier.computeIfAbsent(toscaId, toscaKey -> new ConcurrentHashMap<>()) + .computeIfAbsent(pdpGroupSource.getName(), pdpGroupName -> { + PdpGroup pdpGroupCopy = new PdpGroup(pdpGroupSource); + pdpGroupCopy.setPdpSubgroups(new ArrayList<>()); + return pdpGroupCopy; + }).getPdpSubgroups().add(new PdpSubGroup(pdpSubGroupSource)); + } + + private void analyzePdpGroups(PdpGroups pdpGroups) { + CollectionUtils.emptyIfNull(pdpGroups.getGroups()).stream() + .forEach(group -> CollectionUtils.emptyIfNull(group.getPdpSubgroups()).stream().forEach(subGroup -> + CollectionUtils.emptyIfNull(subGroup.getPolicies()).parallelStream().forEach(policy -> + PdpGroupsAnalyzer.addInfoToPdpGroupsStructure(policy, this.pdpGroupsDeploymentPerPolicy, + group, subGroup)))); + } + + /** + * This method retrieves all pdpGroups and subgroups where a specific policy name/version is deployed. + * + * @param policyName The policy name that must be used for searching + * @param version THe policy version that must be used for searching + * @return It returns a JsonObject containing each pdpGroup and subgroups associated + */ + public JsonObject getPdpGroupsForPolicy(String policyName, String version) { + Map<String, PdpGroup> mapOfGroups = + this.pdpGroupsDeploymentPerPolicy.get(new ToscaConceptIdentifier(policyName, version)); + if (mapOfGroups != null) { + JsonObject policyPdpGroups = new JsonObject(); + JsonArray pdpGroupsArray = new JsonArray(); + policyPdpGroups.add(ASSIGNED_PDP_GROUPS_INFO, pdpGroupsArray); + pdpGroupsArray.add(JsonUtils.GSON + .toJsonTree(mapOfGroups)); + return policyPdpGroups; + } + return null; + } + + /** + * Get supported subGroups based on the defined policy type and version for specific PDPGroup. + * It returns null if the Group is TERMINATED or if the policytype/version has not been found in the PDPSubgroups. * * @param pdpGroup The pdpGroup that must be analyzed * @param policyType The policy type @@ -56,7 +130,7 @@ public class PdpGroupsAnalyzer { */ private static JsonObject getSupportedPdpSubgroupsForModelType(PdpGroup pdpGroup, String policyType, String version) { - if (!PdpState.ACTIVE.equals(pdpGroup.getPdpGroupState())) { + if (PdpState.TERMINATED.equals(pdpGroup.getPdpGroupState())) { return null; } JsonObject supportedPdpGroup = new JsonObject(); @@ -87,7 +161,7 @@ public class PdpGroupsAnalyzer { pdpGroups.getGroups().stream().map(pdpGroup -> PdpGroupsAnalyzer.getSupportedPdpSubgroupsForModelType(pdpGroup, policyType, version)).filter(Objects::nonNull) - .forEach(jsonPdpGroup -> pdpGroupsArray.add(jsonPdpGroup)); + .forEach(pdpGroupsArray::add); return pdpGroupsArray.size() != 0 ? supportedPdpGroups : null; } @@ -99,38 +173,8 @@ public class PdpGroupsAnalyzer { * @param pdpGroups The PdpGroups containing all PDP group definition */ public static void updatePdpGroupOfPolicyModels(List<PolicyModel> policyModelsList, PdpGroups pdpGroups) { - policyModelsList.parallelStream().forEach(policyModel -> { - policyModel.setPolicyPdpGroup(getSupportedPdpGroupsForModelType(pdpGroups, policyModel.getPolicyModelType(), - policyModel.getVersion())); - }); - } - - /** - * This method searches for the PdpGroup/subgroup where the policy given is currently deployed. - * - * @param pdpGroups The pdpGroups info from PEF - * @param policyName The policy Id - * @param version The policy version - * @return It returns a JsonObject containing the pdpGroup/subgroup info - */ - public static JsonObject getPdpGroupDeploymentOfOnePolicy(PdpGroups pdpGroups, String policyName, String version) { - JsonObject pdpGroupInfo = new JsonObject(); - JsonObject assignedPdpGroups = new JsonObject(); - pdpGroupInfo.add(ASSIGNED_PDP_GROUPS_INFO, assignedPdpGroups); - - ToscaConceptIdentifier toscaConceptIdentifier = new ToscaConceptIdentifier(policyName, version); - pdpGroups.getGroups().stream().anyMatch(pdpGroup -> - pdpGroup.getPdpSubgroups().stream().anyMatch( - pdpSubGroup -> { - if (pdpSubGroup.getPolicies() != null && pdpSubGroup.getPolicies() - .contains(toscaConceptIdentifier)) { - assignedPdpGroups.addProperty("pdpGroup", pdpGroup.getName()); - assignedPdpGroups.addProperty("pdpSubGroup", pdpSubGroup.getPdpType()); - return true; - } - return false; - }) - ); - return assignedPdpGroups.entrySet().isEmpty() ? null : pdpGroupInfo; + policyModelsList.parallelStream().forEach(policyModel -> policyModel + .setPolicyPdpGroup(getSupportedPdpGroupsForModelType(pdpGroups, policyModel.getPolicyModelType(), + policyModel.getVersion()))); } }
\ No newline at end of file diff --git a/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMerger.java b/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMerger.java index 44b11119b..6775eb0c6 100644 --- a/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMerger.java +++ b/src/main/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMerger.java @@ -23,11 +23,8 @@ package org.onap.policy.clamp.policy.pdpgroup; -import com.google.gson.Gson; -import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import java.util.Map; import java.util.stream.StreamSupport; import org.onap.policy.clamp.clds.util.JsonUtils; import org.onap.policy.models.pdp.concepts.PdpGroups; @@ -38,6 +35,8 @@ import org.onap.policy.models.pdp.concepts.PdpGroups; */ public class PoliciesPdpMerger { + private PoliciesPdpMerger() {} + /** * This method extract the content of a policy without knowing the key (policy Id). * This JsonElement normally contains only the policy ID then the content, @@ -91,8 +90,9 @@ public class PoliciesPdpMerger { * @param policyJsonNode The policy json node that must be enriched */ private static void enrichOnePolicy(PdpGroups pdpGroups, JsonObject policyJsonNode) { - JsonObject deploymentPdpJson = PdpGroupsAnalyzer - .getPdpGroupDeploymentOfOnePolicy(pdpGroups, policyJsonNode.get("name").getAsString(), + PdpGroupsAnalyzer pdpGroupAnalyzer = new PdpGroupsAnalyzer(pdpGroups); + JsonObject deploymentPdpJson = pdpGroupAnalyzer + .getPdpGroupsForPolicy(policyJsonNode.get("name").getAsString(), policyJsonNode.get("version").getAsString()); mergeJsonElement(policyJsonNode, deploymentPdpJson); @@ -101,18 +101,4 @@ public class PoliciesPdpMerger { policyJsonNode.get("type_version").getAsString()); mergeJsonElement(policyJsonNode, supportedPdpGroupsJson); } - - /** - * This method removes the pdp States added for one policy. - * - * @param policyJsonNode The policy node Json as String - * @return The Json with pdp group info removed - */ - public static JsonObject removePdpStatesOnePolicy(JsonObject policyJsonNode) { - //JsonObject policyJson = JsonUtils.GSON.fromJson(policyJsonNode, JsonObject.class); - // Simply remove the nodes we have added. - policyJsonNode.remove(PdpGroupsAnalyzer.ASSIGNED_PDP_GROUPS_INFO); - policyJsonNode.remove(PdpGroupsAnalyzer.SUPPORTED_PDP_GROUPS_INFO); - return policyJsonNode; - } }
\ No newline at end of file diff --git a/src/main/resources/clds/camel/rest/clamp-api-v2.xml b/src/main/resources/clds/camel/rest/clamp-api-v2.xml index 7de2de1c9..de0bb1ab0 100644 --- a/src/main/resources/clds/camel/rest/clamp-api-v2.xml +++ b/src/main/resources/clds/camel/rest/clamp-api-v2.xml @@ -437,7 +437,7 @@ <to uri="bean:org.onap.policy.clamp.loop.log.LoopLogService?method=addLog('RESTART request','INFO',${exchangeProperty[loopObject]})"/> - <to uri="direct:add-all-to-active-pdp-group"/> + <to uri="direct:add-policies-from-loop-to-pdp-group"/> <log loggingLevel="INFO" message="RESTART request successfully executed for loop: ${header.loopName}"/> <to @@ -524,7 +524,7 @@ <constant>3000</constant> </delay> - <to uri="direct:add-all-to-active-pdp-group"/> + <to uri="direct:add-policies-from-loop-to-pdp-group"/> <log loggingLevel="INFO" message="SUBMIT request successfully executed for loop: ${header.loopName}"/> diff --git a/src/main/resources/clds/camel/routes/policy-flows.xml b/src/main/resources/clds/camel/routes/policy-flows.xml index c92617856..cc51a086e 100644 --- a/src/main/resources/clds/camel/routes/policy-flows.xml +++ b/src/main/resources/clds/camel/routes/policy-flows.xml @@ -208,8 +208,8 @@ </doTry> </route> - <route id="add-all-to-active-pdp-group"> - <from uri="direct:add-all-to-active-pdp-group"/> + <route id="add-policies-from-loop-to-pdp-group"> + <from uri="direct:add-policies-from-loop-to-pdp-group"/> <doTry> <log loggingLevel="INFO" message="Adding loop policies to PDP Group: ${exchangeProperty[loopObject].getName()}"/> @@ -220,31 +220,8 @@ ${exchangeProperty[loopObject].getComponent("POLICY").createPoliciesPayloadPdpGroup(exchangeProperty[loopObject],"POST")} </simple> </setBody> - <setHeader headerName="CamelHttpMethod"> - <constant>POST</constant> - </setHeader> - <setHeader headerName="Content-Type"> - <constant>application/json</constant> - </setHeader> - <setHeader headerName="X-ONAP-RequestID"> - <simple>${exchangeProperty[X-ONAP-RequestID]} - </simple> - </setHeader> - <setHeader headerName="X-ONAP-InvocationID"> - <simple>${exchangeProperty[X-ONAP-InvocationID]} - </simple> - </setHeader> - <setHeader headerName="X-ONAP-PartnerName"> - <simple>${exchangeProperty[X-ONAP-PartnerName]} - </simple> - </setHeader> - <log loggingLevel="INFO" - message="Endpoint to add policies to PDP Group: {{clamp.config.policy.pap.url}}/policy/pap/v1/pdps/deployments/batch"></log> - <toD - uri="{{clamp.config.policy.pap.url}}/policy/pap/v1/pdps/deployments/batch?bridgeEndpoint=true&throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&useSystemProperties=true&authUsername={{clamp.config.policy.pap.userName}}&authPassword={{clamp.config.policy.pap.password}}&httpClient.connectTimeout=10000&httpClient.socketTimeout=20000&authenticationPreemptive=true&connectionClose=true"/> - + <to uri="direct:add-multiple-policies-to-pdp-group"/> <doFinally> - <to uri="direct:reset-raise-http-exception-flag"/> <to uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=invokeReturnLog()"/> <setProperty propertyName="logMessage"> @@ -486,7 +463,43 @@ </doFinally> </doTry> </route> - + <route id="add-multiple-policies-to-pdp-group"> + <from uri="direct:add-multiple-policies-to-pdp-group"/> + <!-- Body should come from outside, expect a json describing the policy --> + <doTry> + <log loggingLevel="INFO" + message="Add policies to PDP group"/> + <to + uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=invokeLog('Policy', 'Add policies to PDP group')"/> + <setHeader headerName="CamelHttpMethod"> + <constant>POST</constant> + </setHeader> + <setHeader headerName="Content-Type"> + <constant>application/json</constant> + </setHeader> + <setHeader headerName="X-ONAP-RequestID"> + <simple>${exchangeProperty[X-ONAP-RequestID]} + </simple> + </setHeader> + <setHeader headerName="X-ONAP-InvocationID"> + <simple>${exchangeProperty[X-ONAP-InvocationID]} + </simple> + </setHeader> + <setHeader headerName="X-ONAP-PartnerName"> + <simple>${exchangeProperty[X-ONAP-PartnerName]} + </simple> + </setHeader> + <log loggingLevel="INFO" + message="Endpoint to add policies to PDP Group: {{clamp.config.policy.pap.url}}/policy/pap/v1/pdps/deployments/batch"></log> + <toD + uri="{{clamp.config.policy.pap.url}}/policy/pap/v1/pdps/deployments/batch?bridgeEndpoint=true&throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&useSystemProperties=true&authUsername={{clamp.config.policy.pap.userName}}&authPassword={{clamp.config.policy.pap.password}}&httpClient.connectTimeout=10000&httpClient.socketTimeout=20000&authenticationPreemptive=true&connectionClose=true"/> + <doFinally> + <to uri="direct:reset-raise-http-exception-flag"/> + <to + uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=invokeReturnLog()"/> + </doFinally> + </doTry> + </route> <route id="undeploy-one-policy-from-pap"> <from uri="direct:undeploy-one-policy-from-pap"/> <doTry> diff --git a/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupAnalyzerTest.java b/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupAnalyzerTest.java index e6717418a..c7ada58cf 100644 --- a/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupAnalyzerTest.java +++ b/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PdpGroupAnalyzerTest.java @@ -25,9 +25,14 @@ package org.onap.policy.clamp.policy.pdpgroup; import static org.assertj.core.api.Assertions.assertThat; +import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import org.junit.BeforeClass; import org.junit.Test; +import org.onap.policy.clamp.clds.util.JsonUtils; +import org.onap.policy.clamp.clds.util.ResourceFileUtils; import org.onap.policy.clamp.loop.template.PolicyModel; import org.onap.policy.models.pdp.concepts.PdpGroup; import org.onap.policy.models.pdp.concepts.PdpGroups; @@ -41,6 +46,15 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; public class PdpGroupAnalyzerTest { private static PdpGroups pdpGroups; + private static PdpGroup pdpGroup1; + private static PdpGroup pdpGroup2; + private static PdpGroup pdpGroup3; + private static PdpGroup pdpGroup4; + + private static PdpSubGroup pdpSubgroupBad; + private static PdpSubGroup pdpSubgroup1; + private static PdpSubGroup pdpSubgroup2; + private static PdpSubGroup pdpSubgroup3; /** * This method preloads the pdpGroups for the tests. @@ -49,7 +63,7 @@ public class PdpGroupAnalyzerTest { public static void setupPdpGroup() { // Create Pdp Groups // Those that do not work first - PdpSubGroup pdpSubgroupBad = new PdpSubGroup(); + pdpSubgroupBad = new PdpSubGroup(); pdpSubgroupBad.setPdpType("subGroupBad"); pdpSubgroupBad.setSupportedPolicyTypes(Arrays.asList(new ToscaConceptIdentifier("org.onap.test", "2.0.0"), new ToscaConceptIdentifier("org.onap.test.*", "1.0.0"), @@ -58,50 +72,54 @@ public class PdpGroupAnalyzerTest { new ToscaConceptIdentifier("org.onap.tes", "1.0.0"), new ToscaConceptIdentifier("org.onap", "1.0.0") )); - pdpSubgroupBad.setPolicies(Arrays.asList(new ToscaConceptIdentifier("org.onap", "1.0.0"))); - pdpSubgroupBad.setPolicies(Arrays.asList(new ToscaConceptIdentifier("org.onap.testos", "2.0.0"))); - pdpSubgroupBad.setPolicies(Arrays.asList(new ToscaConceptIdentifier("org.onap.testos", "1.0.1"))); - pdpSubgroupBad.setPolicies(Arrays.asList(new ToscaConceptIdentifier("org.onap.testos.new", "1.0.0"))); - pdpSubgroupBad.setPolicies(Arrays.asList(new ToscaConceptIdentifier("org.onap.*", "1.0.0"))); - - PdpSubGroup pdpSubgroup1 = new PdpSubGroup(); + pdpSubgroupBad.setPolicies(Arrays.asList(new ToscaConceptIdentifier("org.onap", "1.0.0"), + new ToscaConceptIdentifier("org.onap.testos", "2.0.0"), + new ToscaConceptIdentifier("org.onap.testos", "1.0.1"), + new ToscaConceptIdentifier("org.onap.testos.new", "1.0.0"), + new ToscaConceptIdentifier("org.onap.", "1.0.0"))); + pdpSubgroupBad.setPdpInstances(Collections.emptyList()); + + pdpSubgroup1 = new PdpSubGroup(); pdpSubgroup1.setPdpType("subGroup1"); pdpSubgroup1.setSupportedPolicyTypes( Arrays.asList(new ToscaConceptIdentifier("org.onap.*", "1.0.0"))); + pdpSubgroup1.setPdpInstances(Collections.emptyList()); - PdpSubGroup pdpSubgroup2 = new PdpSubGroup(); + pdpSubgroup2 = new PdpSubGroup(); pdpSubgroup2.setPdpType("subGroup2"); pdpSubgroup2.setSupportedPolicyTypes(Arrays.asList(new ToscaConceptIdentifier("org.onap.test", "1.0.0"))); pdpSubgroup2.setPolicies(Arrays.asList(new ToscaConceptIdentifier("org.onap.testos", "1.0.0"))); + pdpSubgroup2.setPdpInstances(Collections.emptyList()); - PdpSubGroup pdpSubgroup3 = new PdpSubGroup(); + pdpSubgroup3 = new PdpSubGroup(); pdpSubgroup3.setPdpType("subGroup3"); pdpSubgroup3.setSupportedPolicyTypes(Arrays.asList(new ToscaConceptIdentifier("org.onap.test*", "1.0.0"))); pdpSubgroup3.setPolicies(Arrays.asList(new ToscaConceptIdentifier("org.onap.testos", "2.0.0"))); + pdpSubgroup3.setPdpInstances(Collections.emptyList()); // Should match pdpSubgroup1 - PdpGroup pdpGroup1 = new PdpGroup(); + pdpGroup1 = new PdpGroup(); pdpGroup1.setName("pdpGroup1"); pdpGroup1.setPdpGroupState(PdpState.ACTIVE); pdpGroup1.setPdpSubgroups(Arrays.asList(pdpSubgroup1, pdpSubgroupBad)); // Should match pdpSubgroup1, pdpSubgroup2, pdpSubgroup3 // Should match also for the policy (pdpSubgroup2) - PdpGroup pdpGroup2 = new PdpGroup(); + pdpGroup2 = new PdpGroup(); pdpGroup2.setName("pdpGroup2"); pdpGroup2.setPdpGroupState(PdpState.ACTIVE); pdpGroup2.setPdpSubgroups(Arrays.asList(pdpSubgroup1, pdpSubgroup2, pdpSubgroup3, pdpSubgroupBad)); /// Should not match - PdpGroup pdpGroup3 = new PdpGroup(); + pdpGroup3 = new PdpGroup(); pdpGroup3.setName("pdpGroup3"); pdpGroup3.setPdpGroupState(PdpState.ACTIVE); pdpGroup3.setPdpSubgroups(Arrays.asList(pdpSubgroupBad)); // Should not match - PdpGroup pdpGroup4 = new PdpGroup(); + pdpGroup4 = new PdpGroup(); pdpGroup4.setName("pdpGroup4"); - pdpGroup4.setPdpGroupState(PdpState.PASSIVE); + pdpGroup4.setPdpGroupState(PdpState.TERMINATED); pdpGroup4.setPdpSubgroups(Arrays.asList(pdpSubgroup1)); pdpGroups = new PdpGroups(); @@ -109,8 +127,67 @@ public class PdpGroupAnalyzerTest { } @Test - public void testUpdatePdpGroupOfPolicyModels() { - // Create policyModel + public void testStructuresConstruction() { + PdpGroupsAnalyzer pdpGroupsAnalyzer = new PdpGroupsAnalyzer(pdpGroups); + assertThat(pdpGroupsAnalyzer).isNotNull(); + assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy()).hasSize(6); + assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy() + .get(new ToscaConceptIdentifier("org.onap.testos", "2.0.0"))).hasSize(3); + assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy() + .get(new ToscaConceptIdentifier("org.onap.testos", "2.0.0")).get("pdpGroup1").getPdpSubgroups().size()) + .isEqualTo(1); + assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy() + .get(new ToscaConceptIdentifier("org.onap.testos", "2.0.0")).get("pdpGroup1").getPdpSubgroups()) + .contains(pdpSubgroupBad); + assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy() + .get(new ToscaConceptIdentifier("org.onap.testos", "2.0.0")).get("pdpGroup2").getPdpSubgroups().size()) + .isEqualTo(2); + assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy() + .get(new ToscaConceptIdentifier("org.onap.testos", "2.0.0")).get("pdpGroup2").getPdpSubgroups()) + .contains(pdpSubgroup3); + assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy() + .get(new ToscaConceptIdentifier("org.onap.testos", "2.0.0")).get("pdpGroup2").getPdpSubgroups()) + .contains(pdpSubgroupBad); + assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy() + .get(new ToscaConceptIdentifier("org.onap.testos", "2.0.0")).get("pdpGroup3").getPdpSubgroups().size()) + .isEqualTo(1); + assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy() + .get(new ToscaConceptIdentifier("org.onap.testos", "2.0.0")).get("pdpGroup3").getPdpSubgroups()) + .contains(pdpSubgroupBad); + + assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy() + .get(new ToscaConceptIdentifier("org.onap.testos", "1.0.0"))).hasSize(1); + assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy() + .get(new ToscaConceptIdentifier("org.onap.testos", "1.0.0")).get("pdpGroup2").getPdpSubgroups().size()) + .isEqualTo(1); + assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy() + .get(new ToscaConceptIdentifier("org.onap.testos", "1.0.0")).get("pdpGroup2").getPdpSubgroups()) + .contains(pdpSubgroup2); + + assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy() + .get(new ToscaConceptIdentifier("org.onap.testos", "1.0.1"))).hasSize(3); + assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy() + .get(new ToscaConceptIdentifier("org.onap.testos", "1.0.1")).get("pdpGroup1").getPdpSubgroups().size()) + .isEqualTo(1); + assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy() + .get(new ToscaConceptIdentifier("org.onap.testos", "1.0.1")).get("pdpGroup1").getPdpSubgroups()) + .contains(pdpSubgroupBad); + assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy() + .get(new ToscaConceptIdentifier("org.onap.testos", "1.0.1")).get("pdpGroup2").getPdpSubgroups().size()) + .isEqualTo(1); + assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy() + .get(new ToscaConceptIdentifier("org.onap.testos", "1.0.1")).get("pdpGroup2").getPdpSubgroups()) + .contains(pdpSubgroupBad); + assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy() + .get(new ToscaConceptIdentifier("org.onap.testos", "1.0.1")).get("pdpGroup3").getPdpSubgroups().size()) + .isEqualTo(1); + assertThat(pdpGroupsAnalyzer.getPdpGroupsDeploymentPerPolicy() + .get(new ToscaConceptIdentifier("org.onap.testos", "1.0.1")).get("pdpGroup3").getPdpSubgroups()) + .contains(pdpSubgroupBad); + } + + @Test + public void testGetSupportedPdpGroupsForPolicy() throws IOException { PolicyModel policyModel = new PolicyModel(); policyModel.setCreatedBy("user"); policyModel.setPolicyAcronym("TEST"); @@ -118,24 +195,37 @@ public class PdpGroupAnalyzerTest { policyModel.setPolicyModelType("org.onap.test"); policyModel.setUpdatedBy("user"); policyModel.setVersion("1.0.0"); - PdpGroupsAnalyzer.updatePdpGroupOfPolicyModels(Arrays.asList(policyModel), pdpGroups); - assertThat(policyModel.getPolicyPdpGroup().toString()).isEqualTo( - "{\"supportedPdpGroups\":[{\"pdpGroup1\":[\"subGroup1\"]}," - + "{\"pdpGroup2\":[\"subGroup1\",\"subGroup2\",\"subGroup3\"]}]}"); - } + PdpGroupsAnalyzer pdpGroupsAnalyzer = new PdpGroupsAnalyzer(pdpGroups); + assertThat(pdpGroupsAnalyzer).isNotNull(); - @Test - public void testGetPdpGroupDeploymentsOfOnePolicy() { assertThat( - PdpGroupsAnalyzer.getPdpGroupDeploymentOfOnePolicy(pdpGroups, "org.onap.testos", "1.0.0").toString()) - .isEqualTo("{\"pdpGroupInfo\":{\"pdpGroup\":\"pdpGroup2\",\"pdpSubGroup\":\"subGroup2\"}}"); - } + JsonUtils.GSON.toJson(pdpGroupsAnalyzer.getPdpGroupsForPolicy("org.onap.testos", "2.0.0"))) + .isEqualTo(ResourceFileUtils.getResourceAsString("example/policy/pdp-deployment-testos-2_0_0.json")); + + assertThat( + JsonUtils.GSON.toJson(pdpGroupsAnalyzer.getPdpGroupsForPolicy("org.onap.testos", "1.0.0"))) + .isEqualTo(ResourceFileUtils.getResourceAsString("example/policy/pdp-deployment-testos-1_0_0.json")); - @Test - public void testGetPdpGroupDeploymentsOfOnePolicyNull() { assertThat( - PdpGroupsAnalyzer.getPdpGroupDeploymentOfOnePolicy(pdpGroups, "org.onap.DoNotExist", "1.0.0")) + pdpGroupsAnalyzer.getPdpGroupsForPolicy("org.onap.donotexist", "1.0.0")) .isNull(); } + + @Test + public void testUpdatePdpGroupOfPolicyModels() { + // Create policyModel + PolicyModel policyModel = new PolicyModel(); + policyModel.setCreatedBy("user"); + policyModel.setPolicyAcronym("TEST"); + policyModel.setPolicyModelTosca("yaml"); + policyModel.setPolicyModelType("org.onap.test"); + policyModel.setUpdatedBy("user"); + policyModel.setVersion("1.0.0"); + PdpGroupsAnalyzer.updatePdpGroupOfPolicyModels(Arrays.asList(policyModel), pdpGroups); + + assertThat(policyModel.getPolicyPdpGroup()).hasToString( + "{\"supportedPdpGroups\":[{\"pdpGroup1\":[\"subGroup1\"]}," + + "{\"pdpGroup2\":[\"subGroup1\",\"subGroup2\",\"subGroup3\"]}]}"); + } } diff --git a/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMergerTest.java b/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMergerTest.java index 7b8cbd824..be7a9d674 100644 --- a/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMergerTest.java +++ b/src/test/java/org/onap/policy/clamp/policy/pdpgroup/PoliciesPdpMergerTest.java @@ -93,20 +93,10 @@ public class PoliciesPdpMergerTest { } @Test - public void testUpdatePdpGroupOfPolicyModels() throws IOException { + public void testMergePoliciesAndPdpGroupStates() throws IOException { JSONAssert.assertEquals(ResourceFileUtils.getResourceAsString("example/policy/policy-merger.json"), PoliciesPdpMerger.mergePoliciesAndPdpGroupStates( ResourceFileUtils.getResourceAsString("http-cache/example/policy/api/v1/policies/.file"), pdpGroupsJson).toString(), true); } - - @Test - public void testRemovePdpStatesOnePolicy() throws IOException { - JsonObject policiesList = PoliciesPdpMerger.removePdpStatesOnePolicy(JsonUtils.GSON.fromJson( - ResourceFileUtils.getResourceAsString("example/policy/single-policy-enriched.json"), JsonObject.class)); - - assertThat(policiesList.get(PdpGroupsAnalyzer.ASSIGNED_PDP_GROUPS_INFO)).isNull(); - assertThat(policiesList.get(PdpGroupsAnalyzer.SUPPORTED_PDP_GROUPS_INFO)).isNull(); - assertThat(policiesList.size()).isEqualTo(6); - } } diff --git a/src/test/resources/example/policy/pdp-deployment-testos-1_0_0.json b/src/test/resources/example/policy/pdp-deployment-testos-1_0_0.json new file mode 100644 index 000000000..3b4a0eafc --- /dev/null +++ b/src/test/resources/example/policy/pdp-deployment-testos-1_0_0.json @@ -0,0 +1,30 @@ +{ + "pdpGroupInfo": [ + { + "pdpGroup2": { + "name": "pdpGroup2", + "pdpGroupState": "ACTIVE", + "pdpSubgroups": [ + { + "pdpType": "subGroup2", + "supportedPolicyTypes": [ + { + "name": "org.onap.test", + "version": "1.0.0" + } + ], + "policies": [ + { + "name": "org.onap.testos", + "version": "1.0.0" + } + ], + "currentInstanceCount": 0, + "desiredInstanceCount": 0, + "pdpInstances": [] + } + ] + } + } + ] +}
\ No newline at end of file diff --git a/src/test/resources/example/policy/pdp-deployment-testos-2_0_0.json b/src/test/resources/example/policy/pdp-deployment-testos-2_0_0.json new file mode 100644 index 000000000..0040052f2 --- /dev/null +++ b/src/test/resources/example/policy/pdp-deployment-testos-2_0_0.json @@ -0,0 +1,204 @@ +{ + "pdpGroupInfo": [ + { + "pdpGroup3": { + "name": "pdpGroup3", + "pdpGroupState": "ACTIVE", + "pdpSubgroups": [ + { + "pdpType": "subGroupBad", + "supportedPolicyTypes": [ + { + "name": "org.onap.test", + "version": "2.0.0" + }, + { + "name": "org.onap.test.*", + "version": "1.0.0" + }, + { + "name": "org.onip.testos", + "version": "1.0.0" + }, + { + "name": "org.onap.testos3", + "version": "2.0.0" + }, + { + "name": "org.onap.tes", + "version": "1.0.0" + }, + { + "name": "org.onap", + "version": "1.0.0" + } + ], + "policies": [ + { + "name": "org.onap", + "version": "1.0.0" + }, + { + "name": "org.onap.testos", + "version": "2.0.0" + }, + { + "name": "org.onap.testos", + "version": "1.0.1" + }, + { + "name": "org.onap.testos.new", + "version": "1.0.0" + }, + { + "name": "org.onap.", + "version": "1.0.0" + } + ], + "currentInstanceCount": 0, + "desiredInstanceCount": 0, + "pdpInstances": [] + } + ] + }, + "pdpGroup1": { + "name": "pdpGroup1", + "pdpGroupState": "ACTIVE", + "pdpSubgroups": [ + { + "pdpType": "subGroupBad", + "supportedPolicyTypes": [ + { + "name": "org.onap.test", + "version": "2.0.0" + }, + { + "name": "org.onap.test.*", + "version": "1.0.0" + }, + { + "name": "org.onip.testos", + "version": "1.0.0" + }, + { + "name": "org.onap.testos3", + "version": "2.0.0" + }, + { + "name": "org.onap.tes", + "version": "1.0.0" + }, + { + "name": "org.onap", + "version": "1.0.0" + } + ], + "policies": [ + { + "name": "org.onap", + "version": "1.0.0" + }, + { + "name": "org.onap.testos", + "version": "2.0.0" + }, + { + "name": "org.onap.testos", + "version": "1.0.1" + }, + { + "name": "org.onap.testos.new", + "version": "1.0.0" + }, + { + "name": "org.onap.", + "version": "1.0.0" + } + ], + "currentInstanceCount": 0, + "desiredInstanceCount": 0, + "pdpInstances": [] + } + ] + }, + "pdpGroup2": { + "name": "pdpGroup2", + "pdpGroupState": "ACTIVE", + "pdpSubgroups": [ + { + "pdpType": "subGroup3", + "supportedPolicyTypes": [ + { + "name": "org.onap.test*", + "version": "1.0.0" + } + ], + "policies": [ + { + "name": "org.onap.testos", + "version": "2.0.0" + } + ], + "currentInstanceCount": 0, + "desiredInstanceCount": 0, + "pdpInstances": [] + }, + { + "pdpType": "subGroupBad", + "supportedPolicyTypes": [ + { + "name": "org.onap.test", + "version": "2.0.0" + }, + { + "name": "org.onap.test.*", + "version": "1.0.0" + }, + { + "name": "org.onip.testos", + "version": "1.0.0" + }, + { + "name": "org.onap.testos3", + "version": "2.0.0" + }, + { + "name": "org.onap.tes", + "version": "1.0.0" + }, + { + "name": "org.onap", + "version": "1.0.0" + } + ], + "policies": [ + { + "name": "org.onap", + "version": "1.0.0" + }, + { + "name": "org.onap.testos", + "version": "2.0.0" + }, + { + "name": "org.onap.testos", + "version": "1.0.1" + }, + { + "name": "org.onap.testos.new", + "version": "1.0.0" + }, + { + "name": "org.onap.", + "version": "1.0.0" + } + ], + "currentInstanceCount": 0, + "desiredInstanceCount": 0, + "pdpInstances": [] + } + ] + } + } + ] +}
\ No newline at end of file diff --git a/src/test/resources/example/policy/policy-merger.json b/src/test/resources/example/policy/policy-merger.json index e1424fffb..c3291ef71 100644 --- a/src/test/resources/example/policy/policy-merger.json +++ b/src/test/resources/example/policy/policy-merger.json @@ -34,10 +34,38 @@ "policy-id": "MICROSERVICE_vLoadBalancerMS_v1_0_tcagen2_1_0_0_AV0", "policy-version": "1.0.0" }, - "pdpGroupInfo": { - "pdpGroup": "pdpGroup2", - "pdpSubGroup": "subGroup2" - }, + "pdpGroupInfo": [ + { + "pdpGroup2": { + "name": "pdpGroup2", + "pdpGroupState": "ACTIVE", + "pdpSubgroups": [ + { + "pdpType": "subGroup2", + "supportedPolicyTypes": [ + { + "name": "onap.policies.monitoring.tcagen2", + "version": "1.0.0" + }, + { + "name": "onap.policies.controlloop.operational.common.Drools", + "version": "1.0.0" + } + ], + "policies": [ + { + "name": "MICROSERVICE_vLoadBalancerMS_v1_0_tcagen2_1_0_0_AV0", + "version": "1.0.0" + } + ], + "currentInstanceCount": 0, + "desiredInstanceCount": 0, + "pdpInstances": [] + } + ] + } + } + ], "supportedPdpGroups": [ { "pdpGroup2": [ @@ -97,10 +125,42 @@ "policy-id": "OPERATIONAL_vLoadBalancerMS_v1_0_Drools_1_0_0_7xd", "policy-version": "1.0.0" }, - "pdpGroupInfo": { - "pdpGroup": "pdpGroup2", - "pdpSubGroup": "subGroup3" - }, + "pdpGroupInfo": [ + { + "pdpGroup2": { + "name": "pdpGroup2", + "pdpGroupState": "ACTIVE", + "pdpSubgroups": [ + { + "pdpType": "subGroup3", + "supportedPolicyTypes": [ + { + "name": "onap.policies.monitoring.tcagen2", + "version": "1.0.0" + }, + { + "name": "onap.policies.controlloop.operational.common.Drools", + "version": "1.0.0" + } + ], + "policies": [ + { + "name": "org.onap.testos", + "version": "2.0.0" + }, + { + "name": "OPERATIONAL_vLoadBalancerMS_v1_0_Drools_1_0_0_7xd", + "version": "1.0.0" + } + ], + "currentInstanceCount": 0, + "desiredInstanceCount": 0, + "pdpInstances": [] + } + ] + } + } + ], "supportedPdpGroups": [ { "pdpGroup2": [ diff --git a/src/test/resources/http-cache/example/policy/pap/v1/pdps/.file b/src/test/resources/http-cache/example/policy/pap/v1/pdps/.file index b0d6819af..467409f47 100644 --- a/src/test/resources/http-cache/example/policy/pap/v1/pdps/.file +++ b/src/test/resources/http-cache/example/policy/pap/v1/pdps/.file @@ -10,7 +10,12 @@ "desiredInstanceCount": 1, "pdpInstances": [], "pdpType": "apex", - "policies": [], + "policies": [ + { + "name": "OPERATIONAL_vLoadBalancerMS_v1_0_Drools_1_0_0_7xd", + "version": "1.0.0" + } + ], "properties": {}, "supportedPolicyTypes": [ { |