summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsebdet <sebastien.determe@intl.att.com>2019-04-26 13:04:08 +0200
committersebdet <sebastien.determe@intl.att.com>2019-04-26 13:04:08 +0200
commit5415b26467f198856b3149c11827a93e2ed8a72a (patch)
tree71546e21f21b3a0fe1b373bf291d69e0d9caa101
parent373b07b5c7f7e74cffb3a7250a691cb649856b94 (diff)
Change Yaml to Json payload
Change the operational policy payload from Yaml to a JSon, yaml being embedded as URLEncoded Issue-ID: CLAMP-359 Change-Id: I8c97bb155e6136ce37c29a65a7d9d85e21fedd61 Signed-off-by: sebdet <sebastien.determe@intl.att.com>
-rw-r--r--src/main/java/org/onap/clamp/policy/Policy.java4
-rw-r--r--src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java16
-rw-r--r--src/main/resources/clds/camel/routes/flexible-flow.xml2
-rw-r--r--src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java4
-rw-r--r--src/test/resources/tosca/operational-policy-payload.json4
5 files changed, 25 insertions, 5 deletions
diff --git a/src/main/java/org/onap/clamp/policy/Policy.java b/src/main/java/org/onap/clamp/policy/Policy.java
index f4efab0d7..fc097bd60 100644
--- a/src/main/java/org/onap/clamp/policy/Policy.java
+++ b/src/main/java/org/onap/clamp/policy/Policy.java
@@ -25,13 +25,15 @@ package org.onap.clamp.policy;
import com.google.gson.JsonObject;
+import java.io.UnsupportedEncodingException;
+
public interface Policy {
String getName();
JsonObject getJsonRepresentation();
- String createPolicyPayload();
+ String createPolicyPayload() throws UnsupportedEncodingException;
/**
* Generate the policy name.
diff --git a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java
index 1e35ad6c4..b2f6109f7 100644
--- a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java
+++ b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java
@@ -31,6 +31,9 @@ import com.google.gson.JsonObject;
import com.google.gson.annotations.Expose;
import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
@@ -150,8 +153,7 @@ public class OperationalPolicy implements Serializable, Policy {
return true;
}
- @Override
- public String createPolicyPayload() {
+ public String createPolicyPayloadYaml() {
JsonObject policyPayloadResult = new JsonObject();
policyPayloadResult.addProperty("tosca_definitions_version", "tosca_simple_yaml_1_0_0");
@@ -181,6 +183,16 @@ public class OperationalPolicy implements Serializable, Policy {
return (new Yaml()).dump(jsonMap);
}
+ @Override
+ public String createPolicyPayload() throws UnsupportedEncodingException {
+
+ // Now the Yaml payload must be injected in a json ...
+ JsonObject payload = new JsonObject();
+ payload.addProperty("policy-id", this.getName());
+ payload.addProperty("content", URLEncoder.encode(createPolicyPayloadYaml(), StandardCharsets.UTF_8.toString()));
+ return new GsonBuilder().setPrettyPrinting().create().toJson(payload);
+ }
+
/**
* Return a map containing all Guard policies indexed by Guard policy Name.
*
diff --git a/src/main/resources/clds/camel/routes/flexible-flow.xml b/src/main/resources/clds/camel/routes/flexible-flow.xml
index 9ba030786..9874d05cd 100644
--- a/src/main/resources/clds/camel/routes/flexible-flow.xml
+++ b/src/main/resources/clds/camel/routes/flexible-flow.xml
@@ -210,7 +210,7 @@
<constant>POST</constant>
</setHeader>
<setHeader headerName="Content-Type">
- <constant>application/yaml; vnd.onap.operational</constant>
+ <constant>application/json</constant>
</setHeader>
<setHeader headerName="X-ONAP-RequestID">
<simple>${exchangeProperty[X-ONAP-RequestID]}
diff --git a/src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java b/src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java
index 76e29c31f..b12ca89f5 100644
--- a/src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java
+++ b/src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java
@@ -43,8 +43,10 @@ public class OperationalPolicyPayloadTest {
JsonObject jsonConfig = new GsonBuilder().create().fromJson(
ResourceFileUtil.getResourceAsString("tosca/operational-policy-properties.json"), JsonObject.class);
OperationalPolicy policy = new OperationalPolicy("testPolicy", null, jsonConfig);
- assertThat(policy.createPolicyPayload())
+ assertThat(policy.createPolicyPayloadYaml())
.isEqualTo(ResourceFileUtil.getResourceAsString("tosca/operational-policy-payload.yaml"));
+ assertThat(policy.createPolicyPayload())
+ .isEqualTo(ResourceFileUtil.getResourceAsString("tosca/operational-policy-payload.json"));
}
@Test
diff --git a/src/test/resources/tosca/operational-policy-payload.json b/src/test/resources/tosca/operational-policy-payload.json
new file mode 100644
index 000000000..1017d0a2c
--- /dev/null
+++ b/src/test/resources/tosca/operational-policy-payload.json
@@ -0,0 +1,4 @@
+{
+ "policy-id": "testPolicy",
+ "content": "tosca_definitions_version%3A+tosca_simple_yaml_1_0_0%0Atopology_template%3A%0A++policies%3A%0A++-+testPolicy%3A%0A++++++type%3A+onap.policies.controlloop.Operational%0A++++++version%3A+1.0.0%0A++++++metadata%3A+%7Bpolicy-id%3A+testPolicy%7D%0A++++++properties%3A%0A++++++++controlLoop%3A+%7BcontrolLoopName%3A+control+loop%2C+version%3A+2.0.0%2C+trigger_policy%3A+new1%2C%0A++++++++++timeout%3A+%2730%27%2C+abatement%3A+%27true%27%7D%0A++++++++policies%3A%0A++++++++-+id%3A+new1%0A++++++++++recipe%3A+Rebuild%0A++++++++++retry%3A+%2710%27%0A++++++++++timeout%3A+%2720%27%0A++++++++++actor%3A+SO%0A++++++++++payload%3A+test%0A++++++++++success%3A+new2%0A++++++++++failure%3A+new2%0A++++++++++failure_timeout%3A+new2%0A++++++++++failure_retries%3A+new2%0A++++++++++failure_exception%3A+new2%0A++++++++++failure_guard%3A+new2%0A++++++++++target%3A+%7Btype%3A+VFC%2C+resourceTargetId%3A+test%7D%0A++++++++-+id%3A+new2%0A++++++++++recipe%3A+Migrate%0A++++++++++retry%3A+%2730%27%0A++++++++++timeout%3A+%2740%27%0A++++++++++actor%3A+SDNC%0A++++++++++payload%3A+test%0A++++++++++target%3A+%7Btype%3A+VFC%2C+resourceTargetId%3A+test%7D%0A"
+} \ No newline at end of file