summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorsebdet <sebastien.determe@intl.att.com>2020-04-15 00:43:20 +0200
committersebdet <sebastien.determe@intl.att.com>2020-04-15 00:43:20 +0200
commit3854d7c1008aa947e4b532bbef9d9efc738f6928 (patch)
treeb7f370f60f47d5eac4750de7a113c08d8391a2c7 /src
parent0f3c8ae745988969aca1f605635b291367ecd69d (diff)
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 <sebastien.determe@intl.att.com> Change-Id: I78ff69b7502900d96fcc605fe997dd564dfa3e98
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/onap/clamp/loop/components/external/PolicyComponent.java46
-rw-r--r--src/main/java/org/onap/clamp/policy/Policy.java2
-rw-r--r--src/main/java/org/onap/clamp/policy/microservice/MicroServicePolicy.java5
-rw-r--r--src/main/resources/clds/camel/routes/loop-flows.xml23
-rw-r--r--src/main/resources/clds/camel/routes/policy-flows.xml322
-rw-r--r--src/test/java/org/onap/clamp/loop/PolicyComponentTest.java17
-rw-r--r--src/test/resources/tosca/pdp-group-policy-payload.json8
7 files changed, 128 insertions, 295 deletions
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<String, Map<String, List<JsonObject>>> 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<String, Map<String,
List<JsonObject>>> pdpGroupMap) {
JsonObject policyJson = new JsonObject();
policyJson.addProperty("name", policyName);
- policyJson.addProperty("version", policyModelVersion);
+ policyJson.addProperty("version", policyVersion);
Map<String, List<JsonObject>> pdpSubGroupMap;
List<JsonObject> policyList;
if (pdpGroupMap.get(pdpGroup) == null) {
@@ -129,7 +136,7 @@ public class PolicyComponent extends ExternalComponent {
}
private static JsonObject generateActivatePdpGroupPayload(
- Map<String, Map<String, List<JsonObject>>> pdpGroupMap) {
+ 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();
@@ -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<String> listPolicyNamesPdpGroup(Loop loop) {
- List<String> 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 @@
<setProperty propertyName="policyType">
<simple>${body.getPolicyModel().getPolicyModelType()}</simple>
</setProperty>
+ <setProperty propertyName="policyTypeVersion">
+ <simple>${body.getPolicyModel().getVersion()}</simple>
+ </setProperty>
<setProperty propertyName="policyVersion">
<simple>1.0.0</simple>
</setProperty>
@@ -61,9 +64,22 @@
<setProperty propertyName="policyType">
<simple>${body.getPolicyModel().getPolicyModelType()}</simple>
</setProperty>
- <setProperty propertyName="policyVersion">
- <simple>1.0.0</simple>
+ <setProperty propertyName="policyTypeVersion">
+ <simple>${body.getPolicyModel().getVersion()}</simple>
</setProperty>
+ <choice>
+ <when>
+ <simple>${body.isLegacy()} == true</simple>
+ <setProperty propertyName="policyVersion">
+ <simple>1</simple>
+ </setProperty>
+ </when>
+ <otherwise>
+ <setProperty propertyName="policyVersion">
+ <simple>1.0.0</simple>
+ </setProperty>
+ </otherwise>
+ </choice>
<setProperty propertyName="operationalPolicy">
<simple>${body}</simple>
</setProperty>
@@ -84,6 +100,9 @@
<setProperty propertyName="policyType">
<simple>onap.policies.controlloop.Guard</simple>
</setProperty>
+ <setProperty propertyName="policyTypeVersion">
+ <simple>1.0.0</simple>
+ </setProperty>
<setProperty propertyName="policyVersion">
<simple>1</simple>
</setProperty>
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 @@
</simple>
</setHeader>
<log loggingLevel="INFO"
- message="Endpoint to get policy: {{clamp.config.policy.api.url}}/policy/api/v1/policytypes/${exchangeProperty[policyType]}/versions/1.0.0/policies/${exchangeProperty[policyName]}/versions/${exchangeProperty[policyVersion]}"></log>
+ 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]}"></log>
<toD
- uri="{{clamp.config.policy.api.url}}/policy/api/v1/policytypes/${exchangeProperty[policyType]}/versions/1.0.0/policies/${exchangeProperty[policyName]}/versions/${exchangeProperty[policyVersion]}?bridgeEndpoint=true&amp;useSystemProperties=true&amp;throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&amp;authMethod=Basic&amp;authUsername={{clamp.config.policy.api.userName}}&amp;authPassword={{clamp.config.policy.api.password}}&amp;connectionTimeToLive=5000&amp;httpClient.connectTimeout=10000&amp;httpClient.socketTimeout=20000&amp;authenticationPreemptive=true&amp;connectionClose=true"/>
+ uri="{{clamp.config.policy.api.url}}/policy/api/v1/policytypes/${exchangeProperty[policyType]}/versions/${exchangeProperty[policyTypeVersion]}/policies/${exchangeProperty[policyName]}/versions/${exchangeProperty[policyVersion]}?bridgeEndpoint=true&amp;useSystemProperties=true&amp;throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&amp;authMethod=Basic&amp;authUsername={{clamp.config.policy.api.userName}}&amp;authPassword={{clamp.config.policy.api.password}}&amp;connectionTimeToLive=5000&amp;httpClient.connectTimeout=10000&amp;httpClient.socketTimeout=20000&amp;authenticationPreemptive=true&amp;connectionClose=true"/>
<doFinally>
<to uri="direct:reset-raise-http-exception-flag"/>
<to
@@ -258,10 +258,23 @@
<simple>${exchangeProperty[X-ONAP-PartnerName]}
</simple>
</setHeader>
+ <choice>
+ <when>
+ <simple>${body.isLegacy()} == true</simple>
+ <setProperty propertyName="policyVersion">
+ <simple>1</simple>
+ </setProperty>
+ </when>
+ <otherwise>
+ <setProperty propertyName="policyVersion">
+ <simple>1.0.0</simple>
+ </setProperty>
+ </otherwise>
+ </choice>
<log loggingLevel="INFO"
- message="Endpoint to delete microservice policy: {{clamp.config.policy.api.url}}/policy/api/v1/policytypes/${exchangeProperty[policy].getPolicyModel().getPolicyModelType()}/versions/${exchangeProperty[policy].getPolicyModel().getVersion()}/policies/${exchangeProperty[policy].getName()}/versions/1.0.0"></log>
+ 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]}"></log>
<toD
- uri="{{clamp.config.policy.api.url}}/policy/api/v1/policytypes/${exchangeProperty[policy].getPolicyModel().getPolicyModelType()}/versions/${exchangeProperty[policy].getPolicyModel().getVersion()}/policies/${exchangeProperty[policy].getName()}/versions/1.0.0?bridgeEndpoint=true&amp;useSystemProperties=true&amp;mapHttpMessageHeaders=false&amp;throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&amp;deleteWithBody=false&amp;mapHttpMessageBody=false&amp;mapHttpMessageFormUrlEncodedBody=false&amp;authUsername={{clamp.config.policy.api.userName}}&amp;authPassword={{clamp.config.policy.api.password}}&amp;connectionTimeToLive=5000&amp;httpClient.connectTimeout=10000&amp;httpClient.socketTimeout=20000&amp;authenticationPreemptive=true&amp;connectionClose=true"/>
+ 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&amp;useSystemProperties=true&amp;mapHttpMessageHeaders=false&amp;throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&amp;deleteWithBody=false&amp;mapHttpMessageBody=false&amp;mapHttpMessageFormUrlEncodedBody=false&amp;authUsername={{clamp.config.policy.api.userName}}&amp;authPassword={{clamp.config.policy.api.password}}&amp;connectionTimeToLive=5000&amp;httpClient.connectTimeout=10000&amp;httpClient.socketTimeout=20000&amp;authenticationPreemptive=true&amp;connectionClose=true"/>
<doFinally>
<to uri="direct:reset-raise-http-exception-flag"/>
@@ -279,199 +292,6 @@
</doFinally>
</doTry>
</route>
- <route id="create-micro-service-policy">
- <from uri="direct:create-micro-service-policy"/>
- <doTry>
- <log loggingLevel="INFO"
- message="Creating Micro Service Policy: ${exchangeProperty[microServicePolicy].getName()}"/>
- <to
- uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=invokeLog('Policy', 'Create Micro Service Policy')"/>
- <setBody>
- <simple>${exchangeProperty[microServicePolicy].createPolicyPayload()}
- </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 create microservice policy: {{clamp.config.policy.api.url}}/policy/api/v1/policytypes/${exchangeProperty[microServicePolicy].getPolicyModel().getPolicyModelType()}/versions/1.0.0/policies"></log>
- <toD
- uri="{{clamp.config.policy.api.url}}/policy/api/v1/policytypes/${exchangeProperty[microServicePolicy].getPolicyModel().getPolicyModelType()}/versions/1.0.0/policies?bridgeEndpoint=true&amp;useSystemProperties=true&amp;mapHttpMessageHeaders=false&amp;throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&amp;authUsername={{clamp.config.policy.api.userName}}&amp;authPassword={{clamp.config.policy.api.password}}&amp;connectionTimeToLive=5000&amp;httpClient.connectTimeout=10000&amp;httpClient.socketTimeout=20000&amp;authenticationPreemptive=true&amp;connectionClose=true"/>
- <doFinally>
- <to uri="direct:reset-raise-http-exception-flag"/>
- <to
- uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=invokeReturnLog()"/>
- <setProperty propertyName="logMessage">
- <simple>${exchangeProperty[microServicePolicy].getName()} creation
- status
- </simple>
- </setProperty>
- <setProperty propertyName="logComponent">
- <simple>POLICY</simple>
- </setProperty>
- <to uri="direct:dump-loop-log-http-response"/>
- </doFinally>
- </doTry>
- </route>
-
- <route id="delete-micro-service-policy">
- <from uri="direct:delete-micro-service-policy"/>
- <doTry>
- <log loggingLevel="INFO"
- message="Deleting Micro Service Policy: ${exchangeProperty[microServicePolicy].getName()}"/>
- <to
- uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=invokeLog('Policy', 'Delete Micro Service Policy')"/>
- <setBody>
- <constant>null</constant>
- </setBody>
- <setHeader headerName="CamelHttpMethod">
- <constant>DELETE</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 delete microservice policy: {{clamp.config.policy.api.url}}/policy/api/v1/policytypes/${exchangeProperty[microServicePolicy].getPolicyModel().getPolicyModelType()}/versions/1.0.0/policies/${exchangeProperty[microServicePolicy].getName()}/versions/1.0.0"></log>
- <toD
- uri="{{clamp.config.policy.api.url}}/policy/api/v1/policytypes/${exchangeProperty[microServicePolicy].getPolicyModel().getPolicyModelType()}/versions/1.0.0/policies/${exchangeProperty[microServicePolicy].getName()}/versions/1.0.0?bridgeEndpoint=true&amp;useSystemProperties=true&amp;mapHttpMessageHeaders=false&amp;throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&amp;deleteWithBody=false&amp;mapHttpMessageBody=false&amp;mapHttpMessageFormUrlEncodedBody=false&amp;authUsername={{clamp.config.policy.api.userName}}&amp;authPassword={{clamp.config.policy.api.password}}&amp;connectionTimeToLive=5000&amp;httpClient.connectTimeout=10000&amp;httpClient.socketTimeout=20000&amp;authenticationPreemptive=true&amp;connectionClose=true"/>
-
- <doFinally>
- <to uri="direct:reset-raise-http-exception-flag"/>
- <to
- uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=invokeReturnLog()"/>
- <setProperty propertyName="logMessage">
- <simple>${exchangeProperty[microServicePolicy].getName()} removal
- status
- </simple>
- </setProperty>
- <setProperty propertyName="logComponent">
- <simple>POLICY</simple>
- </setProperty>
- <to uri="direct:dump-loop-log-http-response"/>
- </doFinally>
- </doTry>
- </route>
-
- <route id="create-operational-policy">
- <from uri="direct:create-operational-policy"/>
- <doTry>
- <log loggingLevel="INFO"
- message="Creating Operational Policy: ${exchangeProperty[operationalPolicy].getName()}"/>
- <to
- uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=invokeLog('Policy', 'Create Operational Policy')"/>
- <setBody>
- <simple>${exchangeProperty[operationalPolicy].createPolicyPayload()}
- </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 create operational policy: {{clamp.config.policy.api.url}}/policy/api/v1/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies"></log>
- <toD
- uri="{{clamp.config.policy.api.url}}/policy/api/v1/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies?bridgeEndpoint=true&amp;useSystemProperties=true&amp;mapHttpMessageHeaders=false&amp;throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&amp;authUsername={{clamp.config.policy.api.userName}}&amp;authPassword={{clamp.config.policy.api.password}}&amp;connectionTimeToLive=5000&amp;httpClient.connectTimeout=10000&amp;httpClient.socketTimeout=20000&amp;authenticationPreemptive=true&amp;connectionClose=true"/>
- <doFinally>
- <to uri="direct:reset-raise-http-exception-flag"/>
- <to
- uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=invokeReturnLog()"/>
- <setProperty propertyName="logMessage">
- <simple>${exchangeProperty[operationalPolicy].getName()} creation
- status
- </simple>
- </setProperty>
- <setProperty propertyName="logComponent">
- <simple>POLICY</simple>
- </setProperty>
- <to uri="direct:dump-loop-log-http-response"/>
- </doFinally>
- </doTry>
- </route>
-
- <route id="delete-operational-policy">
- <from uri="direct:delete-operational-policy"/>
- <doTry>
- <log loggingLevel="INFO"
- message="Deleting Operational Policy: ${exchangeProperty[operationalPolicy].getName()}"/>
- <to
- uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=invokeLog('Policy', 'Delete Operational Policy')"/>
- <setBody>
- <constant>null</constant>
- </setBody>
- <setHeader headerName="CamelHttpMethod">
- <constant>DELETE</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 delete operational policy: {{clamp.config.policy.api.url}}/policy/api/v1/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies/${exchangeProperty[operationalPolicy].getName()}/versions/1"></log>
- <toD
- uri="{{clamp.config.policy.api.url}}/policy/api/v1/policytypes/onap.policies.controlloop.Operational/versions/1.0.0/policies/${exchangeProperty[operationalPolicy].getName()}/versions/1?bridgeEndpoint=true&amp;useSystemProperties=true&amp;mapHttpMessageHeaders=false&amp;throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&amp;deleteWithBody=false&amp;mapHttpMessageBody=false&amp;mapHttpMessageFormUrlEncodedBody=false&amp;authUsername={{clamp.config.policy.api.userName}}&amp;authPassword={{clamp.config.policy.api.password}}&amp;connectionTimeToLive=5000&amp;httpClient.connectTimeout=10000&amp;httpClient.socketTimeout=20000&amp;authenticationPreemptive=true&amp;connectionClose=true"/>
- <doFinally>
- <to uri="direct:reset-raise-http-exception-flag"/>
- <to
- uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=invokeReturnLog()"/>
- <setProperty propertyName="logMessage">
- <simple>${exchangeProperty[operationalPolicy].getName()} removal
- status
- </simple>
- </setProperty>
- <setProperty propertyName="logComponent">
- <simple>POLICY</simple>
- </setProperty>
- <to uri="direct:dump-loop-log-http-response"/>
- </doFinally>
- </doTry>
- </route>
-
<route id="create-guard-policy">
<from uri="direct:create-guard-policy"/>
<doTry>
@@ -575,7 +395,7 @@
<to
uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=invokeLog('Policy', 'Add policies to PDP group')"/>
<setBody>
- <simple>${exchangeProperty[loopObject].getComponent("POLICY").createPoliciesPayloadPdpGroup(exchangeProperty[loopObject])}
+ <simple>${exchangeProperty[loopObject].getComponent("POLICY").createPoliciesPayloadPdpGroup(exchangeProperty[loopObject],"POST")}
</simple>
</setBody>
<setHeader headerName="CamelHttpMethod">
@@ -618,67 +438,51 @@
<route id="remove-all-policy-from-active-pdp-group">
<from uri="direct:remove-all-policy-from-active-pdp-group"/>
- <doTry>
- <log loggingLevel="INFO"
- message="Removing policies from active PDP group for loop: ${exchangeProperty[loopObject].getName()}"/>
- <to
- uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=invokeLog('Policy', 'Removing policies PDP group')"/>
- <split>
- <simple>${exchangeProperty[loopObject].getComponent("POLICY").listPolicyNamesPdpGroup(exchangeProperty[loopObject])}
- </simple>
- <setProperty propertyName="policyName">
- <simple>${body}</simple>
- </setProperty>
- <setBody>
- <constant>null</constant>
- </setBody>
- <setHeader headerName="CamelHttpMethod">
- <constant>DELETE</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 delete policy from PDP Group: {{clamp.config.policy.pap.url}}/pdps/policies/${exchangeProperty[policyName]}/versions/1.0.0"></log>
- <toD
- uri="{{clamp.config.policy.pap.url}}/policy/pap/v1/pdps/policies/${exchangeProperty[policyName]}/versions/1.0.0?bridgeEndpoint=true&amp;useSystemProperties=true&amp;mapHttpMessageHeaders=false&amp;throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&amp;authUsername={{clamp.config.policy.pap.userName}}&amp;authPassword={{clamp.config.policy.pap.password}}&amp;connectionTimeToLive=5000&amp;httpClient.connectTimeout=10000&amp;httpClient.socketTimeout=20000&amp;authenticationPreemptive=true&amp;connectionClose=true"/>
- <setProperty propertyName="logMessage">
- <simple>${exchangeProperty[policyName]} PDP Group removal status
- </simple>
- </setProperty>
- <setProperty propertyName="logComponent">
- <simple>POLICY</simple>
- </setProperty>
- <to uri="direct:dump-loop-log-http-response"/>
- </split>
- <doCatch>
- <exception>java.lang.Exception</exception>
- <handled>
- <constant>false</constant>
- </handled>
- <setProperty propertyName="logMessage">
- <simple>PDP Group removal, Error reported: ${exception}</simple>
- </setProperty>
- <setProperty propertyName="logComponent">
- <simple>POLICY</simple>
- </setProperty>
- <to uri="direct:dump-loop-log-http-response"/>
- </doCatch>
- <doFinally>
- <to uri="direct:reset-raise-http-exception-flag"/>
- <to
- uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=invokeReturnLog()"/>
- </doFinally>
- </doTry>
+ <doTry>
+ <log loggingLevel="INFO"
+ message="Removing loop policies from PDP Group: ${exchangeProperty[loopObject].getName()}"/>
+ <to
+ uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=invokeLog('Policy', 'Remove policies from PDP group')"/>
+ <setBody>
+ <simple>${exchangeProperty[loopObject].getComponent("POLICY").createPoliciesPayloadPdpGroup(exchangeProperty[loopObject],"DELETE")}
+ </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 remove policies from 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&amp;throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&amp;useSystemProperties=true&amp;authUsername={{clamp.config.policy.pap.userName}}&amp;authPassword={{clamp.config.policy.pap.password}}&amp;connectionTimeToLive=5000&amp;httpClient.connectTimeout=10000&amp;httpClient.socketTimeout=20000&amp;authenticationPreemptive=true&amp;connectionClose=true"/>
+
+ <doFinally>
+ <to uri="direct:reset-raise-http-exception-flag"/>
+ <to
+ uri="bean:org.onap.clamp.flow.log.FlowLogOperation?method=invokeReturnLog()"/>
+ <setProperty propertyName="logMessage">
+ <simple>PDP Group remove ALL status</simple>
+ </setProperty>
+ <setProperty propertyName="logComponent">
+ <simple>POLICY</simple>
+ </setProperty>
+ <to uri="direct:dump-loop-log-http-response"/>
+ </doFinally>
+ </doTry>
</route>
<route id="get-all-pdp-groups">
<from uri="direct:get-all-pdp-groups"/>
diff --git a/src/test/java/org/onap/clamp/loop/PolicyComponentTest.java b/src/test/java/org/onap/clamp/loop/PolicyComponentTest.java
index 432de6065..6449a8966 100644
--- a/src/test/java/org/onap/clamp/loop/PolicyComponentTest.java
+++ b/src/test/java/org/onap/clamp/loop/PolicyComponentTest.java
@@ -24,7 +24,6 @@
package org.onap.clamp.loop;
import static org.assertj.core.api.Assertions.assertThat;
-
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import java.io.IOException;
@@ -32,6 +31,7 @@ import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.junit.Test;
import org.mockito.Mockito;
+import org.onap.clamp.clds.config.LegacyOperationalPolicyController;
import org.onap.clamp.clds.util.ResourceFileUtil;
import org.onap.clamp.loop.components.external.ExternalComponentState;
import org.onap.clamp.loop.components.external.PolicyComponent;
@@ -267,7 +267,8 @@ public class PolicyComponentTest {
new Gson().fromJson("{\"configtype\":\"json\"}", JsonObject.class), null, "pdpGroup2", "pdpSubgroup1");
loopTest.addMicroServicePolicy(microServicePolicy2);
- PolicyModel policyModel2 = new PolicyModel("onap.policies.controlloop.Operational", null, "1.0.0");
+ PolicyModel policyModel2 = new PolicyModel(LegacyOperationalPolicyController.OPERATIONAL_POLICY_LEGACY, null,
+ "1.0.0");
OperationalPolicy opPolicy =
new OperationalPolicy("opPolicy", new Gson().fromJson("{\"configtype\":\"json\"}", JsonObject.class),
new Gson().fromJson("{\"jsonschema\":\"schema\"}", JsonObject.class), policyModel2, null,
@@ -275,16 +276,22 @@ public class PolicyComponentTest {
"pdpSubgroup2");
loopTest.addOperationalPolicy(opPolicy);
+ OperationalPolicy opLegacyPolicy =
+ new OperationalPolicy("opLegacyPolicy", new Gson().fromJson(
+ "{\"guard_policies\":[{\"policy-id\":\"guard1\"}]}", JsonObject.class),
+ new Gson().fromJson("{\"jsonschema\":\"schema\"}", JsonObject.class), policyModel2, null,
+ "pdpGroup2",
+ "pdpSubgroup2");
+
+ loopTest.addOperationalPolicy(opLegacyPolicy);
LoopTemplate loopTemplate = new LoopTemplate("test", "yaml", "svg", 1, null);
loopTemplate.setDcaeBlueprintId("UUID-blueprint");
loopTest.setLoopTemplate(loopTemplate);
- String payload = PolicyComponent.createPoliciesPayloadPdpGroup(loopTest);
+ String payload = PolicyComponent.createPoliciesPayloadPdpGroup(loopTest, "POST");
String expectedRes = ResourceFileUtil.getResourceAsString("tosca/pdp-group-policy-payload.json");
assertThat(payload).isEqualTo(expectedRes);
-
- assertThat(PolicyComponent.listPolicyNamesPdpGroup(loopTest)).containsExactlyInAnyOrder("opPolicy","configPolicyTest","configPolicyTest2");
}
}
diff --git a/src/test/resources/tosca/pdp-group-policy-payload.json b/src/test/resources/tosca/pdp-group-policy-payload.json
index c81440e73..dce740fcd 100644
--- a/src/test/resources/tosca/pdp-group-policy-payload.json
+++ b/src/test/resources/tosca/pdp-group-policy-payload.json
@@ -23,6 +23,14 @@
"action": "POST",
"policies": [
{
+ "name": "opLegacyPolicy",
+ "version": "1.0.0"
+ },
+ {
+ "name": "guard1",
+ "version": "1.0.0"
+ },
+ {
"name": "opPolicy",
"version": "1.0.0"
}