aboutsummaryrefslogtreecommitdiffstats
path: root/runtime-acm
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2022-07-12 14:50:18 +0100
committerFrancesco Fiora <francesco.fiora@est.tech>2022-07-14 07:39:13 +0000
commita1b6bef1eea5144fb9a6f33b89f2daf914415e08 (patch)
tree47856037c61e76a6b890b367a0251da5d1374cf4 /runtime-acm
parentd0db79ad9ae0446bba6b5f5dbc6f51c34d7fb4d2 (diff)
Remove usage of jackson libraries from clamp runtime acm
Issue-ID: POLICY-4105 Change-Id: I04488a8a246e4c161e9a9eca86634844aba27872 Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'runtime-acm')
-rw-r--r--runtime-acm/pom.xml22
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProvider.java61
-rw-r--r--runtime-acm/src/main/java/org/onap/policy/clamp/acm/runtime/main/rest/CommissioningController.java56
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/CommissioningProviderTest.java56
-rw-r--r--runtime-acm/src/test/java/org/onap/policy/clamp/acm/runtime/commissioning/rest/CommissioningControllerTest.java12
5 files changed, 18 insertions, 189 deletions
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();