aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java9
-rw-r--r--src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java2
-rw-r--r--src/test/resources/tosca/operational-policy-payload-legacy.yaml23
-rw-r--r--src/test/resources/tosca/operational-policy-payload.json2
4 files changed, 34 insertions, 2 deletions
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 906c3cfa..2ce5afff 100644
--- a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java
+++ b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java
@@ -183,13 +183,20 @@ public class OperationalPolicy implements Serializable, Policy {
return (new Yaml()).dump(jsonMap);
}
+ public String createPolicyPayloadYamlLegacy() {
+ Gson gson = new GsonBuilder().create();
+ Map<?, ?> jsonMap = gson.fromJson(gson.toJson(this.configurationsJson.get("operational_policy")), Map.class);
+ 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()));
+ payload.addProperty("content",
+ URLEncoder.encode(createPolicyPayloadYamlLegacy(), StandardCharsets.UTF_8.toString()));
return new GsonBuilder().setPrettyPrinting().create().toJson(payload);
}
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 b12ca89f..caed3ba9 100644
--- a/src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java
+++ b/src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java
@@ -45,6 +45,8 @@ public class OperationalPolicyPayloadTest {
OperationalPolicy policy = new OperationalPolicy("testPolicy", null, jsonConfig);
assertThat(policy.createPolicyPayloadYaml())
.isEqualTo(ResourceFileUtil.getResourceAsString("tosca/operational-policy-payload.yaml"));
+ assertThat(policy.createPolicyPayloadYamlLegacy())
+ .isEqualTo(ResourceFileUtil.getResourceAsString("tosca/operational-policy-payload-legacy.yaml"));
assertThat(policy.createPolicyPayload())
.isEqualTo(ResourceFileUtil.getResourceAsString("tosca/operational-policy-payload.json"));
}
diff --git a/src/test/resources/tosca/operational-policy-payload-legacy.yaml b/src/test/resources/tosca/operational-policy-payload-legacy.yaml
new file mode 100644
index 00000000..ddaaf71f
--- /dev/null
+++ b/src/test/resources/tosca/operational-policy-payload-legacy.yaml
@@ -0,0 +1,23 @@
+controlLoop: {controlLoopName: control loop, version: 2.0.0, trigger_policy: new1,
+ timeout: '30', abatement: 'true'}
+policies:
+- id: new1
+ recipe: Rebuild
+ retry: '10'
+ timeout: '20'
+ actor: SO
+ payload: test
+ success: new2
+ failure: new2
+ failure_timeout: new2
+ failure_retries: new2
+ failure_exception: new2
+ failure_guard: new2
+ target: {type: VFC, resourceTargetId: test}
+- id: new2
+ recipe: Migrate
+ retry: '30'
+ timeout: '40'
+ actor: SDNC
+ payload: test
+ target: {type: VFC, resourceTargetId: test}
diff --git a/src/test/resources/tosca/operational-policy-payload.json b/src/test/resources/tosca/operational-policy-payload.json
index 1017d0a2..f2271cd3 100644
--- a/src/test/resources/tosca/operational-policy-payload.json
+++ b/src/test/resources/tosca/operational-policy-payload.json
@@ -1,4 +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"
+ "content": "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%0Apolicies%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