From a1b6bef1eea5144fb9a6f33b89f2daf914415e08 Mon Sep 17 00:00:00 2001 From: FrancescoFioraEst Date: Tue, 12 Jul 2022 14:50:18 +0100 Subject: Remove usage of jackson libraries from clamp runtime acm Issue-ID: POLICY-4105 Change-Id: I04488a8a246e4c161e9a9eca86634844aba27872 Signed-off-by: FrancescoFioraEst --- pom.xml | 18 +++++-- runtime-acm/pom.xml | 22 ++++---- .../commissioning/CommissioningProvider.java | 61 +++------------------- .../runtime/main/rest/CommissioningController.java | 56 -------------------- .../commissioning/CommissioningProviderTest.java | 56 -------------------- .../rest/CommissioningControllerTest.java | 12 ----- .../resources/clds/camel/rest/clamp-api-v2.xml | 35 ------------- .../main/resources/clds/camel/routes/acm-flows.xml | 28 ---------- .../RuntimeCommissioningResponseItTestCase.java | 14 ----- 9 files changed, 32 insertions(+), 270 deletions(-) diff --git a/pom.xml b/pom.xml index f7ccea3bf..bb7181abc 100644 --- a/pom.xml +++ b/pom.xml @@ -125,6 +125,20 @@ org.springframework.boot spring-boot-starter-web + + + com.fasterxml.jackson.core + jackson-core + + + com.fasterxml.jackson.core + jackson-databind + + + com.fasterxml.jackson.core + jackson-annotations + + org.springframework.boot @@ -143,10 +157,6 @@ io.swagger swagger-models - - com.fasterxml.jackson.core - jackson-annotations - io.springfox springfox-boot-starter diff --git a/runtime-acm/pom.xml b/runtime-acm/pom.xml index 5ed1d676c..5e8f5e61f 100644 --- a/runtime-acm/pom.xml +++ b/runtime-acm/pom.xml @@ -49,16 +49,6 @@ policy-clamp-examples ${project.version} - - com.fasterxml.jackson.module - jackson-module-jsonSchema - - - javax.validation - validation-api - - - org.springframework.boot spring-boot-starter-web @@ -67,6 +57,18 @@ org.springframework.boot spring-boot-starter-json + + com.fasterxml.jackson.core + jackson-core + + + com.fasterxml.jackson.core + jackson-databind + + + com.fasterxml.jackson.core + jackson-annotations + diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java index 7d2d4f39c..0a78c54de 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java @@ -21,11 +21,6 @@ package org.onap.policy.clamp.acm.runtime.commissioning; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JavaType; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.PropertyNamingStrategies; -import com.fasterxml.jackson.module.jsonSchema.factories.SchemaFactoryWrapper; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -42,20 +37,15 @@ import org.onap.policy.clamp.models.acm.messages.rest.commissioning.Commissionin import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider; import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider; import org.onap.policy.clamp.models.acm.persistence.provider.ServiceTemplateProvider; +import org.onap.policy.common.utils.coder.Coder; +import org.onap.policy.common.utils.coder.CoderException; +import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.models.base.PfModelException; -import org.onap.policy.models.tosca.authorative.concepts.ToscaCapabilityType; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType; import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; -import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeType; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType; -import org.onap.policy.models.tosca.authorative.concepts.ToscaRelationshipType; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplates; -import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate; import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter; -import org.springframework.boot.context.event.ApplicationReadyEvent; -import org.springframework.context.event.EventListener; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -71,12 +61,10 @@ public class CommissioningProvider { private final ServiceTemplateProvider serviceTemplateProvider; private final AutomationCompositionProvider acProvider; - private final ObjectMapper mapper = new ObjectMapper(); + private static final Coder CODER = new StandardCoder(); private final ParticipantProvider participantProvider; private final SupervisionHandler supervisionHandler; - private static final Map sections = new HashMap<>(); - /** * Create a commissioning provider. * @@ -92,24 +80,6 @@ public class CommissioningProvider { this.acProvider = acProvider; this.supervisionHandler = supervisionHandler; this.participantProvider = participantProvider; - mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE); - } - - /** - * Event listener initiilize function called at ApplicationReadyEvent. - * - */ - @EventListener(ApplicationReadyEvent.class) - public void initialize() { - sections.put("data_types", mapper.constructType(ToscaDataType.class)); - sections.put("capability_types", mapper.constructType(ToscaCapabilityType.class)); - sections.put("node_types", mapper.constructType(ToscaNodeType.class)); - sections.put("relationship_types", mapper.constructType(ToscaRelationshipType.class)); - sections.put("policy_types", mapper.constructType(ToscaPolicyType.class)); - sections.put("topology_template", mapper.constructType(ToscaTopologyTemplate.class)); - sections.put("node_templates", - mapper.getTypeFactory().constructCollectionType(List.class, ToscaNodeTemplate.class)); - sections.put("all", mapper.constructType(ToscaServiceTemplate.class)); } /** @@ -330,28 +300,9 @@ public class CommissioningProvider { template.put("topology_template", fullTemplate.getToscaTopologyTemplate()); try { - return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(template); - - } catch (JsonProcessingException e) { - throw new PfModelException(Status.BAD_REQUEST, "Converion to Json Schema failed", e); - } - } + return CODER.encode(template); - /** - * Get the requested json schema. - * - * @param section section of the tosca service template to get schema for - * @return the specified tosca service template or section Json Schema - * @throws PfModelException on errors with retrieving the classes - */ - public String getToscaServiceTemplateSchema(String section) throws PfModelException { - var visitor = new SchemaFactoryWrapper(); - var sectionMapper = sections.getOrDefault(section, sections.get("all")); - try { - mapper.acceptJsonFormatVisitor(sectionMapper, visitor); - var jsonSchema = visitor.finalSchema(); - return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonSchema); - } catch (JsonProcessingException e) { + } catch (CoderException e) { throw new PfModelException(Status.BAD_REQUEST, "Converion to Json Schema failed", e); } } diff --git a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/CommissioningController.java b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/CommissioningController.java index 0458b074a..4cd384ede 100644 --- a/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/CommissioningController.java +++ b/runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/CommissioningController.java @@ -313,62 +313,6 @@ public class CommissioningController extends AbstractRestController { return ResponseEntity.ok().body(provider.getToscaServiceTemplateReduced(name, version, instanceName)); } - /** - * Retrieves the Json Schema for the specified Tosca Service Template. - * - * @param requestId request ID used in ONAP logging - * @param section section of the tosca service template to get schema for - * @return the specified tosca service template or section Json Schema - * @throws PfModelException on errros getting the Json Schema for the specified Tosca Service Template - */ - // @formatter:off - @GetMapping(value = "/commission/toscaServiceTemplateSchema", - produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML}) - @ApiOperation(value = "Query details of the requested tosca service template json schema", - notes = "Queries details of the requested commissioned tosca service template json schema, " - + "returning all tosca service template json schema details", - response = ToscaServiceTemplate.class, - tags = {TAGS}, - authorizations = @Authorization(value = AUTHORIZATION_TYPE), - responseHeaders = { - @ResponseHeader( - name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION, - response = String.class), - @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION, - response = String.class), - @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION, - response = UUID.class)}, - extensions = { - @Extension - ( - name = EXTENSION_NAME, - properties = { - @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION), - @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE) - } - ) - } - ) - @ApiResponses( - value = { - @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE), - @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE), - @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) - } - ) - // @formatter:on - public ResponseEntity queryToscaServiceTemplateJsonSchema( - @RequestHeader(name = REQUEST_ID_NAME, required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId, - @ApiParam( - value = "Section of Template schema is desired for", - required = false) @RequestParam(value = "section", required = false, defaultValue = "all") String section) - throws PfModelException { - - return ResponseEntity.ok().body(provider.getToscaServiceTemplateSchema(section)); - } - /** * Retrieves the Common or Instance Properties for the specified Tosca Service Template. * diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java index 698439d35..4058c68b6 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java @@ -29,9 +29,6 @@ import static org.mockito.Mockito.when; import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_SERVICE_TEMPLATE_YAML; import static org.onap.policy.clamp.acm.runtime.util.CommonTestData.TOSCA_ST_TEMPLATE_YAML; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.PropertyNamingStrategies; -import com.fasterxml.jackson.module.jsonSchema.factories.SchemaFactoryWrapper; import java.util.List; import java.util.Map; import java.util.Objects; @@ -42,20 +39,13 @@ import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider import org.onap.policy.clamp.models.acm.persistence.provider.ServiceTemplateProvider; import org.onap.policy.common.utils.coder.Coder; import org.onap.policy.common.utils.coder.StandardCoder; -import org.onap.policy.models.tosca.authorative.concepts.ToscaCapabilityType; import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier; -import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType; import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate; -import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeType; -import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType; -import org.onap.policy.models.tosca.authorative.concepts.ToscaRelationshipType; import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; -import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate; class CommissioningProviderTest { private static final Coder CODER = new StandardCoder(); - private final ObjectMapper mapper = new ObjectMapper(); /** * Test the fetching of automation composition definitions (ToscaServiceTemplates). @@ -170,50 +160,4 @@ class CommissioningProviderTest { assertThat(parsedServiceTemplate.getToscaTopologyTemplate().getNodeTemplates()).hasSize(7); } - - /** - * Tests the different schemas being returned from the schema endpoint. As schemas of the different - * sections of the Tosca Service Templates can be returned by the API, this test must cover all of the - * different sections. - * - */ - @Test - void testGetToscaServiceTemplateSchema() throws Exception { - var serviceTemplateProvider = mock(ServiceTemplateProvider.class); - var acProvider = mock(AutomationCompositionProvider.class); - var participantProvider = mock(ParticipantProvider.class); - - CommissioningProvider provider = - new CommissioningProvider(serviceTemplateProvider, acProvider, null, participantProvider); - ToscaServiceTemplate serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_ST_TEMPLATE_YAML); - when(serviceTemplateProvider.createServiceTemplate(serviceTemplate)).thenReturn(serviceTemplate); - - provider.createAutomationCompositionDefinitions(serviceTemplate); - provider.initialize(); - - mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE); - - Map> sections = Map.of("all", ToscaServiceTemplate.class, "data_types", ToscaDataType.class, - "capability_types", ToscaCapabilityType.class, "node_types", ToscaNodeType.class, "relationship_types", - ToscaRelationshipType.class, "policy_types", ToscaPolicyType.class, "topology_template", - ToscaTopologyTemplate.class, "node_templates", List.class); - - for (Map.Entry> entry : sections.entrySet()) { - String returnedServiceTemplateSchema = provider.getToscaServiceTemplateSchema(entry.getKey()); - assertThat(returnedServiceTemplateSchema).isNotNull(); - - var visitor = new SchemaFactoryWrapper(); - - if (entry.getKey().equals("node_templates")) { - mapper.acceptJsonFormatVisitor( - mapper.getTypeFactory().constructCollectionType(List.class, ToscaNodeTemplate.class), visitor); - } else { - mapper.acceptJsonFormatVisitor(mapper.constructType(entry.getValue()), visitor); - } - - var jsonSchema = visitor.finalSchema(); - String localServiceTemplateSchema = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonSchema); - assertThat(localServiceTemplateSchema).isEqualTo(returnedServiceTemplateSchema); - } - } } diff --git a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java index 5aa2f5a53..0cc2036e7 100644 --- a/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java +++ b/runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java @@ -141,18 +141,6 @@ class CommissioningControllerTest extends CommonRestController { assertThat(template.getNodeTypes()).hasSize(7); } - @Test - void testQueryToscaServiceTemplateSchema() throws Exception { - createFullEntryInDbWithCommonProps(); - - Invocation.Builder invocationBuilder = - super.sendRequest(COMMISSIONING_ENDPOINT + "/toscaServiceTemplateSchema"); - Response rawresp = invocationBuilder.buildGet().invoke(); - assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus()); - String schema = rawresp.readEntity(String.class); - assertNotNull(schema); - } - @Test void testQueryCommonOrInstanceProperties() throws Exception { createFullEntryInDbWithCommonProps(); 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 7db468024..23eb6b37d 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 @@ -1713,41 +1713,6 @@ - - - - - - - - application/json - - - true - - - - - java.lang.Exception - - true - - - - - 500 - - - GET JSON Schema FAILED - - - - - - - - - - - - - GET - - - application/json - - - ${header.section} - - - - - - - - - - diff --git a/runtime/src/test/java/org/onap/policy/clamp/runtime/RuntimeCommissioningResponseItTestCase.java b/runtime/src/test/java/org/onap/policy/clamp/runtime/RuntimeCommissioningResponseItTestCase.java index 8c9c5b3e4..2d82dde86 100644 --- a/runtime/src/test/java/org/onap/policy/clamp/runtime/RuntimeCommissioningResponseItTestCase.java +++ b/runtime/src/test/java/org/onap/policy/clamp/runtime/RuntimeCommissioningResponseItTestCase.java @@ -48,20 +48,6 @@ public class RuntimeCommissioningResponseItTestCase { + " \"topology_template\": {}," + " \"name\": \"ToscaServiceTemplateSimple\", \"version\": \"1.0.0\", \"metadata\": {}}"; - @Test - public void testToscaServiceTemplateSchemaStatus() { - ProducerTemplate prodTemplate = camelContext.createProducerTemplate(); - - Exchange exchangeResponse = - prodTemplate.send("direct:get-json-schema", ExchangeBuilder.anExchange(camelContext) - .withProperty("section", "data_types") - .withProperty("raiseHttpExceptionFlag", "true") - .build()); - - assertThat(HttpStatus.valueOf((Integer) exchangeResponse.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE)) - .is2xxSuccessful()).isTrue(); - } - @Test public void testToscaServiceTemplateStatus() { ProducerTemplate prodTemplate = camelContext.createProducerTemplate(); -- cgit 1.2.3-korg