aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java14
-rw-r--r--src/main/resources/clds/camel/rest/clamp-api-v2.xml2
-rw-r--r--src/main/resources/clds/camel/routes/flexible-flow.xml25
-rw-r--r--src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java17
-rwxr-xr-xsrc/test/resources/example/sdc/service-Vloadbalancerms-csar.csarbin112273 -> 110668 bytes
-rw-r--r--src/test/resources/tosca/operational-policy-no-guard-properties.json35
6 files changed, 77 insertions, 16 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 1859a4d6e..1e35ad6c4 100644
--- a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java
+++ b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java
@@ -183,18 +183,20 @@ public class OperationalPolicy implements Serializable, Policy {
/**
* Return a map containing all Guard policies indexed by Guard policy Name.
- *
+ *
* @return The Guards map
*/
public Map<String, String> createGuardPolicyPayloads() {
Map<String, String> result = new HashMap<>();
- JsonObject guard = new JsonObject();
JsonElement guardsList = this.getConfigurationsJson().get("guard_policies");
- for (Entry<String, JsonElement> guardElem : guardsList.getAsJsonObject().entrySet()) {
- guard.addProperty("policy-id", guardElem.getKey());
- guard.add("contents", guardElem.getValue());
- result.put(guardElem.getKey(), new GsonBuilder().create().toJson(guard));
+ if (guardsList != null) {
+ for (Entry<String, JsonElement> guardElem : guardsList.getAsJsonObject().entrySet()) {
+ JsonObject guard = new JsonObject();
+ guard.addProperty("policy-id", guardElem.getKey());
+ guard.add("contents", guardElem.getValue());
+ result.put(guardElem.getKey(), new GsonBuilder().create().toJson(guard));
+ }
}
return result;
}
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 76f45881a..810c9d205 100644
--- a/src/main/resources/clds/camel/rest/clamp-api-v2.xml
+++ b/src/main/resources/clds/camel/rest/clamp-api-v2.xml
@@ -106,6 +106,8 @@
<to
uri="bean:org.onap.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','update')" />
<to uri="direct:load-loop" />
+ <to
+ uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('Receive SUBMIT request','INFO',${header.LoopObject})" />
<log
loggingLevel="INFO"
message="Processing all MICRO-SERVICES policies defined in loop ${header.LoopObject.getName()}" />
diff --git a/src/main/resources/clds/camel/routes/flexible-flow.xml b/src/main/resources/clds/camel/routes/flexible-flow.xml
index 15a247b5d..33419c219 100644
--- a/src/main/resources/clds/camel/routes/flexible-flow.xml
+++ b/src/main/resources/clds/camel/routes/flexible-flow.xml
@@ -118,9 +118,11 @@
</setHeader>
<log
loggingLevel="INFO"
- message="Policy Endpoint for microservice: ${header.CamelHttpMethod} ${header.CamelHttpUri}"></log>
+ message="Endpoint to create microservice policy: ${header.CamelHttpMethod} ${header.CamelHttpUri}"></log>
<toD
uri="http4://policyhost:8085?throwExceptionOnFailure=${header.HttpQueryExceptionFlag}" />
+ <to
+ uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('MicroService policy created successfully','INFO',${header.LoopObject})" />
</route>
<route id="delete-micro-service-policy">
<from uri="direct:delete-micro-service-policy" />
@@ -139,9 +141,11 @@
</setHeader>
<log
loggingLevel="INFO"
- message="Policy Endpoint for microservice: ${header.CamelHttpMethod} ${header.CamelHttpUri}"></log>
+ message="Endpoint to delete microservice policy: ${header.CamelHttpMethod} ${header.CamelHttpUri}"></log>
<toD
uri="http4://policyhost:8085?throwExceptionOnFailure=${header.HttpQueryExceptionFlag}&amp;deleteWithBody=false&amp;mapHttpMessageBody=false&amp;mapHttpMessageFormUrlEncodedBody=false" />
+ <to
+ uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('MicroService policy deleted successfully','INFO',${header.LoopObject})" />
</route>
<route id="create-operational-policy">
@@ -165,9 +169,11 @@
</setHeader>
<log
loggingLevel="INFO"
- message="Policy Endpoint for operational ${header.CamelHttpMethod} ${header.CamelHttpUri}"></log>
+ message="Endpoint to create operational policy: ${header.CamelHttpMethod} ${header.CamelHttpUri}"></log>
<toD
uri="http4://policyhost:8085?throwExceptionOnFailure=${header.HttpQueryExceptionFlag}" />
+ <to
+ uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('Operational policy created successfully','INFO',${header.LoopObject})" />
</route>
<route id="delete-operational-policy">
<from uri="direct:delete-operational-policy" />
@@ -186,10 +192,11 @@
</setHeader>
<log
loggingLevel="INFO"
- message="Policy Endpoint for operational: ${header.CamelHttpMethod} ${header.CamelHttpUri}"></log>
+ message="Endpoint to delete operational policy: ${header.CamelHttpMethod} ${header.CamelHttpUri}"></log>
<toD
uri="http4://policyhost:8085?throwExceptionOnFailure=${header.HttpQueryExceptionFlag}&amp;deleteWithBody=false&amp;mapHttpMessageBody=false&amp;mapHttpMessageFormUrlEncodedBody=false" />
-
+ <to
+ uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('Operational policy deleted successfully','INFO',${header.LoopObject})" />
</route>
<route id="create-guard-policy">
@@ -213,9 +220,11 @@
</setHeader>
<log
loggingLevel="INFO"
- message="Policy Endpoint for operational ${header.CamelHttpMethod} ${header.CamelHttpUri}"></log>
+ message="Endpoint to create guard policy: ${header.CamelHttpMethod} ${header.CamelHttpUri}"></log>
<toD
uri="http4://policyhost:8085?throwExceptionOnFailure=${header.HttpQueryExceptionFlag}" />
+ <to
+ uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('Guard policy created successfully','INFO',${header.LoopObject})" />
</route>
<route id="delete-guard-policy">
<from uri="direct:delete-guard-policy" />
@@ -234,9 +243,11 @@
</setHeader>
<log
loggingLevel="INFO"
- message="Policy Endpoint for operational: ${header.CamelHttpMethod} ${header.CamelHttpUri}"></log>
+ message="Endpoint to delete guard policy: ${header.CamelHttpMethod} ${header.CamelHttpUri}"></log>
<toD
uri="http4://policyhost:8085?throwExceptionOnFailure=${header.HttpQueryExceptionFlag}&amp;deleteWithBody=false&amp;mapHttpMessageBody=false&amp;mapHttpMessageFormUrlEncodedBody=false" />
+ <to
+ uri="bean:org.onap.clamp.loop.log.LoopLogService?method=addLog('Guard policy deleted successfully','INFO',${header.LoopObject})" />
</route>
</routes> \ No newline at end of file
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 739708ca7..76e29c31f 100644
--- a/src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java
+++ b/src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java
@@ -48,17 +48,28 @@ public class OperationalPolicyPayloadTest {
}
@Test
+ public void testGuardPolicyEmptyPayloadConstruction() throws IOException {
+ JsonObject jsonConfig = new GsonBuilder().create().fromJson(
+ ResourceFileUtil.getResourceAsString("tosca/operational-policy-no-guard-properties.json"),
+ JsonObject.class);
+ OperationalPolicy policy = new OperationalPolicy("testPolicy", null, jsonConfig);
+ Map<String, String> guardsMap = policy.createGuardPolicyPayloads();
+ assertThat(guardsMap).isEmpty();
+ assertThat(guardsMap.entrySet()).isEmpty();
+ }
+
+ @Test
public void testGuardPolicyPayloadConstruction() throws IOException {
JsonObject jsonConfig = new GsonBuilder().create().fromJson(
ResourceFileUtil.getResourceAsString("tosca/operational-policy-properties.json"), JsonObject.class);
OperationalPolicy policy = new OperationalPolicy("testPolicy", null, jsonConfig);
- Map<String, String> guardsList = policy.createGuardPolicyPayloads();
+ Map<String, String> guardsMap = policy.createGuardPolicyPayloads();
JSONAssert.assertEquals(ResourceFileUtil.getResourceAsString("tosca/guard1-policy-payload.json"),
- guardsList.get("guard1"), false);
+ guardsMap.get("guard1"), false);
JSONAssert.assertEquals(ResourceFileUtil.getResourceAsString("tosca/guard2-policy-payload.json"),
- guardsList.get("guard2"), false);
+ guardsMap.get("guard2"), false);
}
}
diff --git a/src/test/resources/example/sdc/service-Vloadbalancerms-csar.csar b/src/test/resources/example/sdc/service-Vloadbalancerms-csar.csar
index b3479ba96..b5fe39d31 100755
--- a/src/test/resources/example/sdc/service-Vloadbalancerms-csar.csar
+++ b/src/test/resources/example/sdc/service-Vloadbalancerms-csar.csar
Binary files differ
diff --git a/src/test/resources/tosca/operational-policy-no-guard-properties.json b/src/test/resources/tosca/operational-policy-no-guard-properties.json
new file mode 100644
index 000000000..30c044044
--- /dev/null
+++ b/src/test/resources/tosca/operational-policy-no-guard-properties.json
@@ -0,0 +1,35 @@
+{
+ "operational_policy": {
+ "controlLoop": {
+ "trigger_policy": "new",
+ "timeout": "0",
+ "abatement": "on",
+ "controlLoopName": "LOOP_iYTIP_v1_0_ResourceInstanceName1_tca"
+ },
+ "policies": [
+ {
+ "id": "new",
+ "recipe": "Restart",
+ "retry": "10",
+ "timeout": "10",
+ "actor": "SO",
+ "payload": "",
+ "success": "",
+ "failure": "",
+ "failure_timeout": "",
+ "failure_retries": "",
+ "failure_exception": "",
+ "failure_guard": "",
+ "target": {
+ "type": "VM",
+ "resourceId": "",
+ "modelInvariantId": "",
+ "modelVersionId": "",
+ "modelName": "",
+ "modelVersion": "",
+ "modelCustomizationId": ""
+ }
+ }
+ ]
+ }
+} \ No newline at end of file