From 41811daa6079e07d95daf3d32719afe7ec15acbd Mon Sep 17 00:00:00 2001 From: "saul.gill" Date: Thu, 15 Jul 2021 11:45:02 +0100 Subject: Added Camel Endpoints for decommissioning Added endpoint in camel for decommissioning Changed get tosca service template get endpoint to return snake case Added endpoints in camel to retrieve control loop definitions and element definitions Added integration tests Allowed error messages and status codes to come through from runtime-controlloop backend Small refactor of clamp python emulator Issue-ID: POLICY-3443 Change-Id: I2f6103ca0f2058651a43e7ae1e0974cb1d3e69a7 Signed-off-by: saul.gill --- .../resources/clds/camel/rest/clamp-api-v2.xml | 118 ++++++++++++++++++++- .../clds/camel/routes/controlloop-flows.xml | 81 ++++++++++++++ .../RuntimeCommissioningResponseTestItCase.java | 45 ++++++++ .../test/resources/http-cache/third_party_proxy.py | 45 +++++--- 4 files changed, 271 insertions(+), 18 deletions(-) (limited to 'runtime/src') diff --git a/runtime/src/main/resources/clds/camel/rest/clamp-api-v2.xml b/runtime/src/main/resources/clds/camel/rest/clamp-api-v2.xml index 8a7523c2b..3addb55f8 100644 --- a/runtime/src/main/resources/clds/camel/rest/clamp-api-v2.xml +++ b/runtime/src/main/resources/clds/camel/rest/clamp-api-v2.xml @@ -1475,7 +1475,7 @@ application/json - true + false - true + false application/json @@ -1543,6 +1543,50 @@ + + + + + true + + + application/json + + + + + + + + java.lang.Exception + + true + + + + + + 500 + + + Decommissioning Tosca Service Template FAILED + + + + + + @@ -1610,6 +1654,76 @@ + + + + + + + + application/json + + + true + + + + + java.lang.Exception + + true + + + + + 500 + + + GET JSON Schema FAILED + + + + + + + + + + + + + + application/json + + + true + + + + + java.lang.Exception + + true + + + + + 500 + + + GET Control Loop Definitions FAILED + + + + + + + + + + + + + DELETE + + + application/json + + + ${header.name} + + + ${header.version} + + + + + + + + + + @@ -132,4 +163,54 @@ + + + + + + + GET + + + application/json + + + + + + + + + + + + + + + + + GET + + + application/json + + + + + + + + + + diff --git a/runtime/src/test/java/org/onap/policy/clamp/runtime/RuntimeCommissioningResponseTestItCase.java b/runtime/src/test/java/org/onap/policy/clamp/runtime/RuntimeCommissioningResponseTestItCase.java index 7616d7a49..a1eaf27d0 100644 --- a/runtime/src/test/java/org/onap/policy/clamp/runtime/RuntimeCommissioningResponseTestItCase.java +++ b/runtime/src/test/java/org/onap/policy/clamp/runtime/RuntimeCommissioningResponseTestItCase.java @@ -102,4 +102,49 @@ public class RuntimeCommissioningResponseTestItCase { assertThat(HttpStatus.valueOf((Integer) exchangeResponse.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE)) .is2xxSuccessful()).isTrue(); } + + @Test + public void testDecommissioningOfToscaServiceTemplateStatus() { + ProducerTemplate prodTemplate = camelContext.createProducerTemplate(); + + Exchange exchangeResponse = + prodTemplate.send("direct:decommission-service-template", ExchangeBuilder.anExchange(camelContext) + .withProperty("name", "ToscaServiceTemplate") + .withProperty("version", "1.0.0") + .withProperty("raiseHttpExceptionFlag", "true") + .build()); + + assertThat(HttpStatus.valueOf((Integer) exchangeResponse.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE)) + .is2xxSuccessful()).isTrue(); + } + + @Test + public void testGetControlLoopDefinitions() { + ProducerTemplate prodTemplate = camelContext.createProducerTemplate(); + + Exchange exchangeResponse = + prodTemplate.send("direct:get-control-loop-definitions", ExchangeBuilder.anExchange(camelContext) + .withProperty("name", "ToscaServiceTemplate") + .withProperty("version", "1.0.0") + .withProperty("raiseHttpExceptionFlag", "true") + .build()); + + assertThat(HttpStatus.valueOf((Integer) exchangeResponse.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE)) + .is2xxSuccessful()).isTrue(); + } + + @Test + public void testGetControlLoopElementDefinitions() { + ProducerTemplate prodTemplate = camelContext.createProducerTemplate(); + + Exchange exchangeResponse = + prodTemplate.send("direct:get-element-definitions", ExchangeBuilder.anExchange(camelContext) + .withProperty("name", "ToscaServiceTemplate") + .withProperty("version", "1.0.0") + .withProperty("raiseHttpExceptionFlag", "true") + .build()); + + assertThat(HttpStatus.valueOf((Integer) exchangeResponse.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE)) + .is2xxSuccessful()).isTrue(); + } } diff --git a/runtime/src/test/resources/http-cache/third_party_proxy.py b/runtime/src/test/resources/http-cache/third_party_proxy.py index 1aaf4024d..2a28c65d3 100644 --- a/runtime/src/test/resources/http-cache/third_party_proxy.py +++ b/runtime/src/test/resources/http-cache/third_party_proxy.py @@ -107,6 +107,15 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler): def _get_cached_header_file_name(self,cached_file_folder): return "%s/.header" % (cached_file_folder,) + def _create_cache(self, generated_json, cached_file_folder, cached_file_header, cached_file_content): + print "jsonGenerated: " + generated_json + if not os.path.exists(cached_file_folder): + os.makedirs(cached_file_folder, 0775) + with open(cached_file_header, 'w+') as f: + f.write("{\"Content-Length\": \"" + str(len(generated_json)) + "\", \"Content-Type\": \"application/json\"}") + with open(cached_file_content, 'w+') as f: + f.write(generated_json) + def _execute_content_generated_cases(self,http_type): print("Testing special cases, cache files will be sent to :" +TMP_ROOT) cached_file_folder = self._get_cached_file_folder_name(TMP_ROOT) @@ -274,14 +283,7 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler): print ("cached file folder for onap is %s: ", cached_file_folder) print "self.path start with /onap/controlloop/v2/commission/, generating response json..." jsonGenerated = "{\"tosca_definitions_version\": \"tosca_simple_yaml_1_1_0\",\"data_types\": {},\"node_types\": {}, \"policy_types\": {}, \"topology_template\": {}, \"name\": \"ToscaServiceTemplateSimple\", \"version\": \"1.0.0\", \"metadata\": {}}" - print "jsonGenerated: " + jsonGenerated - 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(jsonGenerated)) + "\", \"Content-Type\": \"application/json\"}") - with open(cached_file_content, 'w+') as f: - f.write(jsonGenerated) + self._create_cache(jsonGenerated, cached_file_folder, cached_file_header, cached_file_content) return True elif (self.path.startswith("/onap/controlloop/v2/commission/toscaServiceTemplateSchema")) and http_type == "GET": if not _file_available: @@ -289,14 +291,19 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler): print ("cached file folder for onap is %s: ", cached_file_folder) print "self.path start with /onap/controlloop/v2/commission/, generating response json..." jsonGenerated = "{\"tosca_definitions_version\": \"tosca_simple_yaml_1_1_0\",\"data_types\": {},\"node_types\": {}, \"policy_types\": {}, \"topology_template\": {}, \"name\": \"ToscaServiceTemplateSimple\", \"version\": \"1.0.0\", \"metadata\": {}}" - print "jsonGenerated: " + jsonGenerated - 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(jsonGenerated)) + "\", \"Content-Type\": \"application/json\"}") - with open(cached_file_content, 'w+') as f: - f.write(jsonGenerated) + self._create_cache(jsonGenerated, cached_file_folder, cached_file_header, cached_file_content) + return True + elif (self.path.startswith("/onap/controlloop/v2/commission/elements")) and http_type == "GET": + print "self.path start with /commission/elements Control Loop Elements, generating response json..." + #jsondata = json.loads(self.data_string) + jsonGenerated = "[{\"name\": ,\"org.onap.domain.pmsh.PMSH_DCAEMicroservice\": [{ \"version\": \"1.2.3\", \"derived_from\": null }]}]" + self._create_cache(jsonGenerated, cached_file_folder, cached_file_header, cached_file_content) + return True + elif (self.path.startswith("/onap/controlloop/v2/commission")) and http_type == "GET": + print "self.path start with /commission control loop definition, generating response json..." + #jsondata = json.loads(self.data_string) + jsonGenerated = "[{\"name\": ,\"org.onap.domain.pmsh.PMSHControlLoopDefinition\": [{ \"version\": \"1.2.3\", \"derived_from\": null }]}]" + self._create_cache(jsonGenerated, cached_file_folder, cached_file_header, cached_file_content) return True elif (self.path.startswith("/onap/controlloop/v2/commission")) and http_type == "POST": print "self.path start with POST /onap/controlloop/v2/commission, copying body to response ..." @@ -307,6 +314,12 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler): with open(cached_file_content, 'w+') as f: f.write(self.data_string) return True + elif (self.path.startswith("/onap/controlloop/v2/commission")) and http_type == "DELETE": + print "self.path start with /commission Decommissioning, generating response json..." + jsonGenerated = "{\"errorDetails\": null,\"affectedControlLoopDefinitions\": [{ \"name\": \"ToscaServiceTemplateSimple\", \"version\": \"1.0.0\" }]}" + self._create_cache(jsonGenerated, cached_file_folder, cached_file_header, cached_file_content) + + return True else: return False -- cgit 1.2.3-korg