From 919ef9dc0a2f392868533e498897b12fe0faa321 Mon Sep 17 00:00:00 2001 From: sebdet Date: Mon, 8 Apr 2019 18:32:26 +0200 Subject: Create submit route Create required components for Submit route in camel + unit tests + Policy payload generation + emulator feature for new policy api Issue-ID: CLAMP-303 Change-Id: If9033cfa3f4e346e2cbd7f891baff1f2c04a40a2 Signed-off-by: sebdet --- .../onap/clamp/clds/config/CamelConfiguration.java | 6 + .../sdc/controller/installer/BlueprintParser.java | 2 +- .../policy/operational/OperationalPolicy.java | 14 +- .../resources/clds/camel/rest/clamp-api-v2.xml | 81 ++++++++--- .../resources/clds/camel/routes/flexible-flow.xml | 149 +++++++++++++++++++-- 5 files changed, 217 insertions(+), 35 deletions(-) (limited to 'src/main') diff --git a/src/main/java/org/onap/clamp/clds/config/CamelConfiguration.java b/src/main/java/org/onap/clamp/clds/config/CamelConfiguration.java index f1056504..c3b24bc8 100644 --- a/src/main/java/org/onap/clamp/clds/config/CamelConfiguration.java +++ b/src/main/java/org/onap/clamp/clds/config/CamelConfiguration.java @@ -21,14 +21,19 @@ */ package org.onap.clamp.clds.config; +import org.apache.camel.CamelContext; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.model.rest.RestBindingMode; import org.onap.clamp.clds.util.ClampVersioning; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @Component public class CamelConfiguration extends RouteBuilder { + @Autowired + CamelContext camelContext; + @Override public void configure() { restConfiguration().component("servlet").bindingMode(RestBindingMode.json).jsonDataFormat("json-gson") @@ -38,5 +43,6 @@ public class CamelConfiguration extends RouteBuilder { .apiProperty("api.version", ClampVersioning.getCldsVersionFromProps()) .apiProperty("base.path", "/restservices/clds/"); // .apiProperty("cors", "true"); + camelContext.setTracing(true); } } diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParser.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParser.java index 93374fe1..5a8ccca9 100644 --- a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParser.java +++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParser.java @@ -88,7 +88,7 @@ public class BlueprintParser { } String msName = theBiggestMicroServiceKey.toLowerCase().contains(HOLMES_PREFIX) ? HOLMES : TCA; return Collections - .singletonList(new MicroService(msName, "onap.policy.monitoring.cdap.tca.hi.lo.ap", "", "", "")); + .singletonList(new MicroService(msName, "onap.policy.monitoring.cdap.tca.hi.lo.app", "", "", "")); } String getName(Entry entry) { 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 b6b591db..1859a4d6 100644 --- a/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java +++ b/src/main/java/org/onap/clamp/policy/operational/OperationalPolicy.java @@ -31,8 +31,7 @@ import com.google.gson.JsonObject; import com.google.gson.annotations.Expose; import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; +import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; @@ -182,15 +181,20 @@ public class OperationalPolicy implements Serializable, Policy { return (new Yaml()).dump(jsonMap); } - public List createGuardPolicyPayloads() { - List result = new ArrayList<>(); + /** + * Return a map containing all Guard policies indexed by Guard policy Name. + * + * @return The Guards map + */ + public Map createGuardPolicyPayloads() { + Map result = new HashMap<>(); JsonObject guard = new JsonObject(); JsonElement guardsList = this.getConfigurationsJson().get("guard_policies"); for (Entry guardElem : guardsList.getAsJsonObject().entrySet()) { guard.addProperty("policy-id", guardElem.getKey()); guard.add("contents", guardElem.getValue()); - result.add(new GsonBuilder().create().toJson(guard)); + 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 c17595e1..76f45881 100644 --- a/src/main/resources/clds/camel/rest/clamp-api-v2.xml +++ b/src/main/resources/clds/camel/rest/clamp-api-v2.xml @@ -102,35 +102,82 @@ + message="Receive SUBMIT request for loop: ${body}" /> - - - - + + + ${header.LoopObject.getMicroServicePolicies()} - + + ${body} + + + + false + + + + + true + + + + + + + ${header.LoopObject.getOperationalPolicies()} + + + ${body} + + + false - - - + + + true - - ${body.createPolicyPayload()} - - + + + + ${header.operationalPolicy.createGuardPolicyPayloads().entrySet()} + + + ${body} + + + + + false + + + + + true + + + - + diff --git a/src/main/resources/clds/camel/routes/flexible-flow.xml b/src/main/resources/clds/camel/routes/flexible-flow.xml index b8244990..15a247b5 100644 --- a/src/main/resources/clds/camel/routes/flexible-flow.xml +++ b/src/main/resources/clds/camel/routes/flexible-flow.xml @@ -75,43 +75,168 @@ - - + + + + + + + + ${header.LoopObject} == null + + 404 + + + + + + + + + + + + ${header.microServicePolicy.createPolicyPayload()} + + - DELETE + POST + + + application/json - {{clamp.config.policy.url}}/policyTypes/${body.getModelType()}/versions/1.0.0/policies/${body.getName()} + {{clamp.config.policy.url}}/policyTypes/${header.microServicePolicy.getModelType()}/versions/1.0.0/policies + + + + + + null - + + DELETE + + + {{clamp.config.policy.url}}/policyTypes/${header.microServicePolicy.getModelType()}/versions/1.0.0/policies/${header.microServicePolicy.getName()} + + + uri="http4://policyhost:8085?throwExceptionOnFailure=${header.HttpQueryExceptionFlag}&deleteWithBody=false&mapHttpMessageBody=false&mapHttpMessageFormUrlEncodedBody=false" /> + + + + + + + ${header.operationalPolicy.createPolicyPayload()} + + + + POST + + + application/json + + + {{clamp.config.policy.url}}/policyTypes/onap.policies.controloop.operational/versions/1.0.0/policies + + + + + + + + + + null + + + DELETE + + + {{clamp.config.policy.url}}/policyTypes/onap.policies.controloop.operational/versions/1.0.0/policies/${header.operationalPolicy.getName()} + + + + - - + + + + + ${header.guardPolicy.getValue()} + + POST + + application/json + - {{clamp.config.policy.url}}/policyTypes/${body.getModelType()}/versions/1.0.0/policies + {{clamp.config.policy.url}}/policyTypes/onap.policies.controlloop.Guard/versions/1.0.0/policies - + message="Policy Endpoint for operational ${header.CamelHttpMethod} ${header.CamelHttpUri}"> + + + + + + + null + + + DELETE + + + {{clamp.config.policy.url}}/policyTypes/onap.policies.controlloop.Guard/versions/1.0.0/policies/${header.guardPolicy.getKey()} + + + + uri="http4://policyhost:8085?throwExceptionOnFailure=${header.HttpQueryExceptionFlag}&deleteWithBody=false&mapHttpMessageBody=false&mapHttpMessageFormUrlEncodedBody=false" /> \ No newline at end of file -- cgit 1.2.3-korg