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 --- .../runtime/commissioning/CommissioningProvider.java | 3 ++- .../runtime/main/rest/CommissioningController.java | 15 +++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) (limited to 'runtime-controlloop/src') diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProvider.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProvider.java index f291c4e89..e5dccde7b 100644 --- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProvider.java +++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProvider.java @@ -252,7 +252,8 @@ public class CommissioningProvider implements Closeable { mapper.acceptJsonFormatVisitor(mapper.constructType(ToscaTopologyTemplate.class), visitor); break; case "node_templates": - mapper.acceptJsonFormatVisitor(mapper.constructType(ToscaNodeTemplate.class), visitor); + mapper.acceptJsonFormatVisitor(mapper.getTypeFactory() + .constructCollectionType(List.class, ToscaNodeTemplate.class), visitor); break; default: mapper.acceptJsonFormatVisitor(mapper.constructType(ToscaServiceTemplate.class), visitor); diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/CommissioningController.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/CommissioningController.java index b50e7a0ed..74548e724 100644 --- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/CommissioningController.java +++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/CommissioningController.java @@ -23,8 +23,6 @@ package org.onap.policy.clamp.controlloop.runtime.main.rest; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.PropertyNamingStrategies; -import com.fasterxml.jackson.module.jsonSchema.JsonSchema; -import com.fasterxml.jackson.module.jsonSchema.factories.SchemaFactoryWrapper; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiResponse; @@ -347,15 +345,24 @@ public class CommissioningController extends AbstractRestController { required = false) String version) { try { - return ResponseEntity.ok().body(provider.getToscaServiceTemplate(name, version)); + ObjectMapper mapper = new ObjectMapper(); + mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE); + String response = mapper.writerWithDefaultPrettyPrinter() + .writeValueAsString(provider.getToscaServiceTemplate(name, version)); + + return ResponseEntity.ok().body(response); } catch (PfModelRuntimeException | PfModelException e) { LOGGER.warn("Get of tosca service template failed", e); var resp = new CommissioningResponse(); resp.setErrorDetails(e.getErrorResponse().getErrorMessage()); return ResponseEntity.status(e.getErrorResponse().getResponseCode().getStatusCode()).body(resp); + } catch (JsonProcessingException e) { + LOGGER.warn("Get of tosca service template failed", e); + var resp = new CommissioningResponse(); + resp.setErrorDetails(e.getMessage()); + return ResponseEntity.status(Status.BAD_REQUEST.getStatusCode()).body(resp); } - } /** -- cgit 1.2.3-korg