From 3854d7c1008aa947e4b532bbef9d9efc738f6928 Mon Sep 17 00:00:00 2001 From: sebdet Date: Wed, 15 Apr 2020 00:43:20 +0200 Subject: Fix legacy policy submit issues Operational legacy policy does not support semantic versionin for get status and delete policies, it has to be changed to integer Issue-ID: CLAMP-820 Signed-off-by: sebdet Change-Id: I78ff69b7502900d96fcc605fe997dd564dfa3e98 --- .../loop/components/external/PolicyComponent.java | 46 ++- src/main/java/org/onap/clamp/policy/Policy.java | 2 + .../policy/microservice/MicroServicePolicy.java | 5 + .../resources/clds/camel/routes/loop-flows.xml | 23 +- .../resources/clds/camel/routes/policy-flows.xml | 322 ++++----------------- 5 files changed, 108 insertions(+), 290 deletions(-) (limited to 'src/main') diff --git a/src/main/java/org/onap/clamp/loop/components/external/PolicyComponent.java b/src/main/java/org/onap/clamp/loop/components/external/PolicyComponent.java index 8270a96e3..227f40a72 100644 --- a/src/main/java/org/onap/clamp/loop/components/external/PolicyComponent.java +++ b/src/main/java/org/onap/clamp/loop/components/external/PolicyComponent.java @@ -28,7 +28,6 @@ import com.att.eelf.configuration.EELFManager; import com.google.gson.GsonBuilder; import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedList; import java.util.List; @@ -76,25 +75,33 @@ public class PolicyComponent extends ExternalComponent { /** * Generates the Json that must be sent to policy to add all policies to Active * PDP group. - * + * @param loop the loop object + * @param action POST (to add policy to group) or DELETE (to delete policy from group) * @return The json, payload to send */ - public static String createPoliciesPayloadPdpGroup(Loop loop) { + public static String createPoliciesPayloadPdpGroup(Loop loop, String action) { Map>> pdpGroupMap = new HashMap<>(); for (OperationalPolicy opPolicy : loop.getOperationalPolicies()) { updatePdpGroupMap(opPolicy.getPdpGroup(), opPolicy.getPdpSubgroup(), opPolicy.getName(), - opPolicy.getPolicyModel().getVersion(), pdpGroupMap); + "1.0.0", pdpGroupMap); + if (opPolicy.isLegacy()) { + for (String guardName:opPolicy.createGuardPolicyPayloads().keySet()) { + updatePdpGroupMap(opPolicy.getPdpGroup(), opPolicy.getPdpSubgroup(), + guardName, + "1.0.0", pdpGroupMap); + } + } } for (MicroServicePolicy msPolicy : loop.getMicroServicePolicies()) { updatePdpGroupMap(msPolicy.getPdpGroup(), msPolicy.getPdpSubgroup(), msPolicy.getName(), - msPolicy.getPolicyModel().getVersion(), pdpGroupMap); + "1.0.0", pdpGroupMap); } String payload = new GsonBuilder().setPrettyPrinting().create() - .toJson(generateActivatePdpGroupPayload(pdpGroupMap)); + .toJson(generateActivatePdpGroupPayload(pdpGroupMap, action)); logger.info("PdpGroup policy payload: " + payload); return payload; } @@ -102,12 +109,12 @@ public class PolicyComponent extends ExternalComponent { private static void updatePdpGroupMap(String pdpGroup, String pdpSubGroup, String policyName, - String policyModelVersion, + String policyVersion, Map>> pdpGroupMap) { JsonObject policyJson = new JsonObject(); policyJson.addProperty("name", policyName); - policyJson.addProperty("version", policyModelVersion); + policyJson.addProperty("version", policyVersion); Map> pdpSubGroupMap; List policyList; if (pdpGroupMap.get(pdpGroup) == null) { @@ -129,7 +136,7 @@ public class PolicyComponent extends ExternalComponent { } private static JsonObject generateActivatePdpGroupPayload( - Map>> pdpGroupMap) { + Map>> pdpGroupMap, String action) { JsonArray payloadArray = new JsonArray(); for (Entry>> pdpGroupInfo : pdpGroupMap.entrySet()) { JsonObject pdpGroupNode = new JsonObject(); @@ -141,7 +148,7 @@ public class PolicyComponent extends ExternalComponent { JsonObject pdpSubGroupNode = new JsonObject(); subPdpArray.add(pdpSubGroupNode); pdpSubGroupNode.addProperty("pdpType", pdpSubGroupInfo.getKey()); - pdpSubGroupNode.addProperty("action", "POST"); + pdpSubGroupNode.addProperty("action", action); JsonArray policyArray = new JsonArray(); pdpSubGroupNode.add("policies", policyArray); @@ -157,25 +164,6 @@ public class PolicyComponent extends ExternalComponent { return jsonObject; } - /** - * Generates the list of policy names that must be send/remove to/from active - * PDP group. - * - * @return A list of policy names - */ - public static List listPolicyNamesPdpGroup(Loop loop) { - List policyNamesList = new ArrayList<>(); - for (OperationalPolicy opPolicy : loop.getOperationalPolicies()) { - policyNamesList.add(opPolicy.getName()); - policyNamesList.addAll(opPolicy.createGuardPolicyPayloads().keySet()); - } - for (MicroServicePolicy microServicePolicy : loop.getMicroServicePolicies()) { - policyNamesList.add(microServicePolicy.getName()); - } - logger.info("Policies that will be removed from PDP: " + policyNamesList); - return policyNamesList; - } - private static ExternalComponentState findNewState(boolean found, boolean deployed) { ExternalComponentState newState = NOT_SENT; diff --git a/src/main/java/org/onap/clamp/policy/Policy.java b/src/main/java/org/onap/clamp/policy/Policy.java index d84f2c8a0..65e88d182 100644 --- a/src/main/java/org/onap/clamp/policy/Policy.java +++ b/src/main/java/org/onap/clamp/policy/Policy.java @@ -284,4 +284,6 @@ public abstract class Policy extends AuditEntity { .append(blueprintFilename.replaceAll(".yaml", "")); return buffer.toString().replace('.', '_').replaceAll(" ", ""); } + + public abstract Boolean isLegacy(); } diff --git a/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java b/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java index 77627a31a..127f495cc 100644 --- a/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java +++ b/src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java @@ -157,6 +157,11 @@ public class MicroServicePolicy extends Policy implements Serializable { this.getPolicyModel().getPolicyModelType(), serviceModel)); } + @Override + public Boolean isLegacy() { + return false; + } + public Boolean getShared() { return shared; } diff --git a/src/main/resources/clds/camel/routes/loop-flows.xml b/src/main/resources/clds/camel/routes/loop-flows.xml index 8c22743a3..2f4d9c8cf 100644 --- a/src/main/resources/clds/camel/routes/loop-flows.xml +++ b/src/main/resources/clds/camel/routes/loop-flows.xml @@ -40,6 +40,9 @@ ${body.getPolicyModel().getPolicyModelType()} + + ${body.getPolicyModel().getVersion()} + 1.0.0 @@ -61,9 +64,22 @@ ${body.getPolicyModel().getPolicyModelType()} - - 1.0.0 + + ${body.getPolicyModel().getVersion()} + + + ${body.isLegacy()} == true + + 1 + + + + + 1.0.0 + + + ${body} @@ -84,6 +100,9 @@ onap.policies.controlloop.Guard + + 1.0.0 + 1 diff --git a/src/main/resources/clds/camel/routes/policy-flows.xml b/src/main/resources/clds/camel/routes/policy-flows.xml index 80926722f..a61bc67fb 100644 --- a/src/main/resources/clds/camel/routes/policy-flows.xml +++ b/src/main/resources/clds/camel/routes/policy-flows.xml @@ -54,9 +54,9 @@ + message="Endpoint to get policy: {{clamp.config.policy.api.url}}/policy/api/v1/policytypes/${exchangeProperty[policyType]}/versions/${exchangeProperty[policyTypeVersion]}/policies/${exchangeProperty[policyName]}/versions/${exchangeProperty[policyVersion]}"> + uri="{{clamp.config.policy.api.url}}/policy/api/v1/policytypes/${exchangeProperty[policyType]}/versions/${exchangeProperty[policyTypeVersion]}/policies/${exchangeProperty[policyName]}/versions/${exchangeProperty[policyVersion]}?bridgeEndpoint=true&useSystemProperties=true&throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&authMethod=Basic&authUsername={{clamp.config.policy.api.userName}}&authPassword={{clamp.config.policy.api.password}}&connectionTimeToLive=5000&httpClient.connectTimeout=10000&httpClient.socketTimeout=20000&authenticationPreemptive=true&connectionClose=true"/> ${exchangeProperty[X-ONAP-PartnerName]} + + + ${body.isLegacy()} == true + + 1 + + + + + 1.0.0 + + + + message="Endpoint to delete policy: {{clamp.config.policy.api.url}}/policy/api/v1/policytypes/${exchangeProperty[policy].getPolicyModel().getPolicyModelType()}/versions/${exchangeProperty[policy].getPolicyModel().getVersion()}/policies/${exchangeProperty[policy].getName()}/versions/${exchangeProperty[policyVersion]}"> + uri="{{clamp.config.policy.api.url}}/policy/api/v1/policytypes/${exchangeProperty[policy].getPolicyModel().getPolicyModelType()}/versions/${exchangeProperty[policy].getPolicyModel().getVersion()}/policies/${exchangeProperty[policy].getName()}/versions/${exchangeProperty[policyVersion]}?bridgeEndpoint=true&useSystemProperties=true&mapHttpMessageHeaders=false&throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&deleteWithBody=false&mapHttpMessageBody=false&mapHttpMessageFormUrlEncodedBody=false&authUsername={{clamp.config.policy.api.userName}}&authPassword={{clamp.config.policy.api.password}}&connectionTimeToLive=5000&httpClient.connectTimeout=10000&httpClient.socketTimeout=20000&authenticationPreemptive=true&connectionClose=true"/> @@ -279,199 +292,6 @@ - - - - - - - ${exchangeProperty[microServicePolicy].createPolicyPayload()} - - - - POST - - - application/json - - - ${exchangeProperty[X-ONAP-RequestID]} - - - - ${exchangeProperty[X-ONAP-InvocationID]} - - - - ${exchangeProperty[X-ONAP-PartnerName]} - - - - - - - - - ${exchangeProperty[microServicePolicy].getName()} creation - status - - - - POLICY - - - - - - - - - - - - - null - - - DELETE - - - ${exchangeProperty[X-ONAP-RequestID]} - - - - ${exchangeProperty[X-ONAP-InvocationID]} - - - - ${exchangeProperty[X-ONAP-PartnerName]} - - - - - - - - - - ${exchangeProperty[microServicePolicy].getName()} removal - status - - - - POLICY - - - - - - - - - - - - - ${exchangeProperty[operationalPolicy].createPolicyPayload()} - - - - POST - - - application/json - - - ${exchangeProperty[X-ONAP-RequestID]} - - - - ${exchangeProperty[X-ONAP-InvocationID]} - - - - ${exchangeProperty[X-ONAP-PartnerName]} - - - - - - - - - ${exchangeProperty[operationalPolicy].getName()} creation - status - - - - POLICY - - - - - - - - - - - - - null - - - DELETE - - - ${exchangeProperty[X-ONAP-RequestID]} - - - - ${exchangeProperty[X-ONAP-InvocationID]} - - - - ${exchangeProperty[X-ONAP-PartnerName]} - - - - - - - - - ${exchangeProperty[operationalPolicy].getName()} removal - status - - - - POLICY - - - - - - @@ -575,7 +395,7 @@ - ${exchangeProperty[loopObject].getComponent("POLICY").createPoliciesPayloadPdpGroup(exchangeProperty[loopObject])} + ${exchangeProperty[loopObject].getComponent("POLICY").createPoliciesPayloadPdpGroup(exchangeProperty[loopObject],"POST")} @@ -618,67 +438,51 @@ - - - - - ${exchangeProperty[loopObject].getComponent("POLICY").listPolicyNamesPdpGroup(exchangeProperty[loopObject])} - - - ${body} - - - null - - - DELETE - - - ${exchangeProperty[X-ONAP-RequestID]} - - - - ${exchangeProperty[X-ONAP-InvocationID]} - - - - ${exchangeProperty[X-ONAP-PartnerName]} - - - - - - ${exchangeProperty[policyName]} PDP Group removal status - - - - POLICY - - - - - java.lang.Exception - - false - - - PDP Group removal, Error reported: ${exception} - - - POLICY - - - - - - - - + + + + + ${exchangeProperty[loopObject].getComponent("POLICY").createPoliciesPayloadPdpGroup(exchangeProperty[loopObject],"DELETE")} + + + + POST + + + application/json + + + ${exchangeProperty[X-ONAP-RequestID]} + + + + ${exchangeProperty[X-ONAP-InvocationID]} + + + + ${exchangeProperty[X-ONAP-PartnerName]} + + + + + + + + + + PDP Group remove ALL status + + + POLICY + + + + -- cgit 1.2.3-korg