From: sebdet Date: Mon, 8 Apr 2019 16:32:26 +0000 (+0200) Subject: Create submit route X-Git-Tag: 4.0.0~37^2~1 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=919ef9dc0a2f392868533e498897b12fe0faa321;p=clamp.git 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 --- 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 diff --git a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParserTest.java b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParserTest.java index 93d71663..e86fb27d 100644 --- a/src/test/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParserTest.java +++ b/src/test/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParserTest.java @@ -163,7 +163,7 @@ public class BlueprintParserTest { @Test public void fallBackToOneMicroServiceTCATest() { - MicroService tcaMS = new MicroService(BlueprintParser.TCA, "onap.policy.monitoring.cdap.tca.hi.lo.ap", "", "", + MicroService tcaMS = new MicroService(BlueprintParser.TCA, "onap.policy.monitoring.cdap.tca.hi.lo.app", "", "", ""); List expected = Collections.singletonList(tcaMS); @@ -174,8 +174,8 @@ public class BlueprintParserTest { @Test public void fallBackToOneMicroServiceHolmesTest() { - MicroService holmesMS = new MicroService(BlueprintParser.HOLMES, "onap.policy.monitoring.cdap.tca.hi.lo.ap", "", - "", ""); + MicroService holmesMS = new MicroService(BlueprintParser.HOLMES, "onap.policy.monitoring.cdap.tca.hi.lo.app", + "", "", ""); List expected = Collections.singletonList(holmesMS); List actual = new BlueprintParser() 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 1f57422c..739708ca 100644 --- a/src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java +++ b/src/test/java/org/onap/clamp/policy/microservice/OperationalPolicyPayloadTest.java @@ -29,7 +29,7 @@ import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; import java.io.IOException; -import java.util.List; +import java.util.Map; import org.junit.Test; import org.onap.clamp.clds.util.ResourceFileUtil; @@ -53,12 +53,12 @@ public class OperationalPolicyPayloadTest { ResourceFileUtil.getResourceAsString("tosca/operational-policy-properties.json"), JsonObject.class); OperationalPolicy policy = new OperationalPolicy("testPolicy", null, jsonConfig); - List guardsList = policy.createGuardPolicyPayloads(); + Map guardsList = policy.createGuardPolicyPayloads(); JSONAssert.assertEquals(ResourceFileUtil.getResourceAsString("tosca/guard1-policy-payload.json"), - guardsList.get(0), false); + guardsList.get("guard1"), false); JSONAssert.assertEquals(ResourceFileUtil.getResourceAsString("tosca/guard2-policy-payload.json"), - guardsList.get(1), false); + guardsList.get("guard2"), false); } } diff --git a/src/test/resources/example/sdc/blueprint-dcae/tca.yaml b/src/test/resources/example/sdc/blueprint-dcae/tca.yaml index b1659073..b2bf8bb9 100644 --- a/src/test/resources/example/sdc/blueprint-dcae/tca.yaml +++ b/src/test/resources/example/sdc/blueprint-dcae/tca.yaml @@ -17,7 +17,7 @@ node_templates: properties: policy_id: get_input: policy_id - policy_type_id: onap.policy.monitoring.cdap.tca.hi.lo.ap + policy_type_id: onap.policy.monitoring.cdap.tca.hi.lo.app cdap_host_host: type: dcae.nodes.StreamingAnalytics.SelectedCDAPInfrastructure properties: diff --git a/src/test/resources/example/sdc/blueprint-dcae/tca_2.yaml b/src/test/resources/example/sdc/blueprint-dcae/tca_2.yaml index 55901368..fb042575 100644 --- a/src/test/resources/example/sdc/blueprint-dcae/tca_2.yaml +++ b/src/test/resources/example/sdc/blueprint-dcae/tca_2.yaml @@ -166,5 +166,5 @@ node_templates: properties: policy_id: get_input: policy_id - policy_type_id: onap.policy.monitoring.cdap.tca.hi.lo.ap + policy_type_id: onap.policy.monitoring.cdap.tca.hi.lo.app diff --git a/src/test/resources/example/sdc/blueprint-dcae/tca_3.yaml b/src/test/resources/example/sdc/blueprint-dcae/tca_3.yaml index b1659073..b2bf8bb9 100644 --- a/src/test/resources/example/sdc/blueprint-dcae/tca_3.yaml +++ b/src/test/resources/example/sdc/blueprint-dcae/tca_3.yaml @@ -17,7 +17,7 @@ node_templates: properties: policy_id: get_input: policy_id - policy_type_id: onap.policy.monitoring.cdap.tca.hi.lo.ap + policy_type_id: onap.policy.monitoring.cdap.tca.hi.lo.app cdap_host_host: type: dcae.nodes.StreamingAnalytics.SelectedCDAPInfrastructure properties: diff --git a/src/test/resources/http-cache/third_party_proxy.py b/src/test/resources/http-cache/third_party_proxy.py index 30f51075..f19aa0da 100755 --- a/src/test/resources/http-cache/third_party_proxy.py +++ b/src/test/resources/http-cache/third_party_proxy.py @@ -171,7 +171,7 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler): with open(cached_file_content, 'w') as f: f.write(jsonGenerated) return True - elif (self.path.startswith("/pdp/api/") and http_type == "PUT" or http_type == "DELETE") or (self.path.startswith("/pdp/api/policyEngineImport") and http_type == "POST"): + elif (self.path.startswith("/pdp/api/") and (http_type == "PUT" or http_type == "DELETE")) or (self.path.startswith("/pdp/api/policyEngineImport") and http_type == "POST"): print "self.path start with /pdp/api/, copying body to response ..." if not os.path.exists(cached_file_folder): os.makedirs(cached_file_folder, 0777) @@ -180,6 +180,25 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler): with open(cached_file_content, 'w+') as f: f.write(self.data_string) return True + elif self.path.startswith("/policy/api/v1/policyTypes/") and http_type == "POST": + print "self.path start with POST new policy API /pdp/api/, copying body to response ..." + if not os.path.exists(cached_file_folder): + os.makedirs(cached_file_folder, 0777) + with open(cached_file_header, 'w+') as f: + f.write("{\"Content-Length\": \"" + str(len(self.data_string)) + "\", \"Content-Type\": \""+str(self.headers['Content-Type'])+"\"}") + with open(cached_file_content, 'w+') as f: + f.write(self.data_string) + return True + elif self.path.startswith("/policy/api/v1/policyTypes/") and http_type == "DELETE": + print "self.path start with DELETE new policy API /policy/api/v1/policyTypes/ ..." + if not os.path.exists(cached_file_folder): + os.makedirs(cached_file_folder, 0777) + + with open(cached_file_header, 'w+') as f: + f.write("{\"Content-Length\": \"" + str(len("")) + "\", \"Content-Type\": \""+str("")+"\"}") + with open(cached_file_content, 'w+') as f: + f.write(self.data_string) + return True else: return False @@ -337,7 +356,10 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler): cached_file_header="" print("\n\n\nGot a DELETE for %s " % self.path) self.check_credentials() - self.data_string = self.rfile.read(int(self.headers['Content-Length'])) + if self.headers.get('Content-Length') is not None: + self.data_string = self.rfile.read(int(self.headers['Content-Length'])) + else: + self.data_string = "empty generated" print("self.headers:\n %s" % self.headers) is_special = self._execute_content_generated_cases("DELETE")