diff options
author | sourabh_sourabh <sourabh.sourabh@est.tech> | 2022-06-20 15:57:24 +0100 |
---|---|---|
committer | sourabh_sourabh <sourabh.sourabh@est.tech> | 2022-06-22 12:20:19 +0100 |
commit | 40a8211b8f8f4b244b43620776a71371bc5371d6 (patch) | |
tree | ebdb1b504ef57a6192c80184031f2f36c75c36cb /cps-service | |
parent | 31cf29d21096ab7200658f586ecb9e40ee72249e (diff) |
Data Sync Watchdog Process
- Get all the Cm Handles state in READY and Operational datastores sync state in UNSYNCHRONIZED
- Get a random Cm Handle
- Get the first resource data from the node
- Save the data in Cps Db
- Update the Operational datastores sync state to SYNCHRONIZED
Issue-ID: CPS-1052
Issue-ID: CPS-1053
Issue-ID: CPS-1054
Change-Id: I9a20391ef30e6d56c4d789a92b8bf42cd3756c62
Signed-off-by: Lathish <lathishbabu.ganesan@est.tech>
Signed-off-by: sourabh_sourabh <sourabh.sourabh@est.tech>
Diffstat (limited to 'cps-service')
-rw-r--r-- | cps-service/src/main/java/org/onap/cps/utils/JsonObjectMapper.java | 17 | ||||
-rw-r--r-- | cps-service/src/test/groovy/org/onap/cps/utils/JsonObjectMapperSpec.groovy | 18 |
2 files changed, 35 insertions, 0 deletions
diff --git a/cps-service/src/main/java/org/onap/cps/utils/JsonObjectMapper.java b/cps-service/src/main/java/org/onap/cps/utils/JsonObjectMapper.java index 2459b51af4..338a841a7a 100644 --- a/cps-service/src/main/java/org/onap/cps/utils/JsonObjectMapper.java +++ b/cps-service/src/main/java/org/onap/cps/utils/JsonObjectMapper.java @@ -21,6 +21,7 @@ package org.onap.cps.utils; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -87,4 +88,20 @@ public class JsonObjectMapper { + "JSON content to specific class type.", e.getMessage()); } } + + /** + * Deserialize JSON content from given JSON content String to JsonNode. + * + * @param jsonContent JSON content + * @return a json node + */ + public JsonNode convertToJsonNode(final String jsonContent) { + try { + return objectMapper.readTree(jsonContent); + } catch (final JsonProcessingException e) { + log.error("Parsing error occurred while converting JSON content to Json Node."); + throw new DataValidationException("Parsing error occurred while converting " + + "JSON content to Json Node.", e.getMessage()); + } + } } diff --git a/cps-service/src/test/groovy/org/onap/cps/utils/JsonObjectMapperSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/utils/JsonObjectMapperSpec.groovy index f9b8febd43..acb52413f8 100644 --- a/cps-service/src/test/groovy/org/onap/cps/utils/JsonObjectMapperSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/utils/JsonObjectMapperSpec.groovy @@ -84,4 +84,22 @@ class JsonObjectMapperSpec extends Specification { then: 'an exception is thrown' thrown(DataValidationException) } + + def 'Map a structurally compatible json String to JsonNode.'() { + given: 'Unstructured object' + def content = '{ "nest": { "birds": "bird" } }' + when: 'the object is mapped to string' + def result = jsonObjectMapper.convertToJsonNode(content); + then: 'the result is a valid JsonNode' + result.fieldNames().next() == "nest" + } + + def 'Map a unstructured json String to JsonNode.'() { + given: 'Unstructured object' + def content = '{ "nest": { "birds": "bird" }] }' + when: 'the object is mapped to string' + jsonObjectMapper.convertToJsonNode(content); + then: 'a data validation exception is thrown' + thrown(DataValidationException) + } } |