diff options
author | Liam Fallon <liam.fallon@est.tech> | 2022-07-18 13:39:22 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2022-07-18 13:39:22 +0000 |
commit | c1c9b09f1b7200f814110bd7dab7f45630b3e184 (patch) | |
tree | 7386d7c9af22b73240999b1a4ae613ebc0c98cd2 | |
parent | 9924517ce68534aebd18ba9112e67b79c3b706bf (diff) | |
parent | a1b6bef1eea5144fb9a6f33b89f2daf914415e08 (diff) |
Merge "Remove usage of jackson libraries from clamp runtime acm"
9 files changed, 32 insertions, 270 deletions
@@ -125,6 +125,20 @@ <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> + <exclusions> + <exclusion> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-core</artifactId> + </exclusion> + <exclusion> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-databind</artifactId> + </exclusion> + <exclusion> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-annotations</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> @@ -144,10 +158,6 @@ <artifactId>swagger-models</artifactId> </dependency> <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-annotations</artifactId> - </dependency> - <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-boot-starter</artifactId> <version>${version.springfox}</version> 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 @@ -50,16 +50,6 @@ <version>${project.version}</version> </dependency> <dependency> - <groupId>com.fasterxml.jackson.module</groupId> - <artifactId>jackson-module-jsonSchema</artifactId> - <exclusions> - <exclusion> - <groupId>javax.validation</groupId> - <artifactId>validation-api</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> @@ -67,6 +57,18 @@ <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-json</artifactId> </exclusion> + <exclusion> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-core</artifactId> + </exclusion> + <exclusion> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-databind</artifactId> + </exclusion> + <exclusion> + <groupId>com.fasterxml.jackson.core</groupId> + <artifactId>jackson-annotations</artifactId> + </exclusion> </exclusions> </dependency> <dependency> 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<String, JavaType> 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 @@ -314,62 +314,6 @@ public class CommissioningController extends AbstractRestController { } /** - * 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<String> 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. * * @param requestId request ID used in ONAP logging 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<String, Class<?>> 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<String, Class<?>> 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 @@ -142,18 +142,6 @@ class CommissioningControllerTest extends CommonRestController { } @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 @@ </doTry> </route> </get> - <get uri="/v2/acm/getJsonSchema" outType="java.lang.String" bindingMode="off" produces="application/json"> - <route> - <removeHeaders pattern="*" - excludePattern="section"/> - <doTry> - <to uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=startLog(*, 'GET Json Schema ')"/> - <to uri="bean:org.onap.policy.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','read')"/> - <setHeader name="Content-Type"> - <constant>application/json</constant> - </setHeader> - <setProperty name="raiseHttpExceptionFlag"> - <simple resultType="java.lang.Boolean">true</simple> - </setProperty> - <to uri="direct:get-json-schema"/> - <to uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=endLog()"/> - <doCatch> - <exception>java.lang.Exception</exception> - <handled> - <constant>true</constant> - </handled> - <to - uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=errorLog()"/> - <log loggingLevel="ERROR" - message="GET JSON Schema request failed: ${exception.stacktrace}"/> - <setHeader name="CamelHttpResponseCode"> - <constant>500</constant> - </setHeader> - <setBody> - <simple>GET JSON Schema FAILED</simple> - </setBody> - </doCatch> - </doTry> - </route> - </get> - <get uri="/v2/acm/getElementDefinitions" outType="java.lang.String" bindingMode="off" produces="application/json"> <route> <removeHeaders pattern="*" diff --git a/runtime/src/main/resources/clds/camel/routes/acm-flows.xml b/runtime/src/main/resources/clds/camel/routes/acm-flows.xml index 9150a2335..602fa8f4a 100644 --- a/runtime/src/main/resources/clds/camel/routes/acm-flows.xml +++ b/runtime/src/main/resources/clds/camel/routes/acm-flows.xml @@ -312,34 +312,6 @@ </doFinally> </doTry> </route> - <route id="get-json-schema"> - <from uri="direct:get-json-schema"/> - <doTry> - <log loggingLevel="INFO" - message="Getting the JSON Schema"/> - <to - uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=invokeLog('AutomationComposition', 'Getting the JSON Schema')"/> - <setHeader name="CamelHttpMethod"> - <constant>GET</constant> - </setHeader> - <setHeader name="Content-Type"> - <constant>application/json</constant> - </setHeader> - <setProperty name="section"> - <simple>${header.section}</simple> - </setProperty> - <log loggingLevel="INFO" - message="Endpoint to get Json Schema: {{clamp.config.acm.runtime.url}}/onap/policy/clamp/acm/v2/commission/toscaServiceTemplateSchema"></log> - <toD - uri="{{clamp.config.acm.runtime.url}}/onap/policy/clamp/acm/v2/commission/toscaServiceTemplateSchema?section=${exchangeProperty[section]}&bridgeEndpoint=true&useSystemProperties=true&throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&authMethod=Basic&authUsername={{clamp.config.acm.runtime.userName}}&authPassword={{clamp.config.acm.runtime.password}}&authenticationPreemptive=true&connectionClose=true"/> - <convertBodyTo type="java.lang.String"/> - <doFinally> - <to uri="direct:reset-raise-http-exception-flag"/> - <to - uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=invokeReturnLog()"/> - </doFinally> - </doTry> - </route> <route id="get-element-definitions"> <from uri="direct:get-element-definitions"/> <doTry> 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 @@ -49,20 +49,6 @@ public class RuntimeCommissioningResponseItTestCase { + " \"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(); |