By Default "mvn clean install" command will execute also the unit tests
and the integration tests. The integration tests require a docker engine running.
- If you want to skip the intergation test you can by doing:
+ If you want to skip the integration test you can by doing:
"mvn clean install -DskipITs=true"
For Spring it's possible to specify the application.properties location
<artifactId>jboss-jaxrs-api_2.0_spec</artifactId>
<version>1.0.1.Final</version>
</dependency>
- <dependency>
- <artifactId>jackson-databind</artifactId>
- <groupId>com.fasterxml.jackson.core</groupId>
- <version>2.9.4</version>
- </dependency>
- <dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-annotations</artifactId>
- <version>2.9.4</version>
- </dependency>
- <dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-core</artifactId>
- <version>2.9.4</version>
- </dependency>
- <dependency>
- <groupId>com.fasterxml.jackson.dataformat</groupId>
- <artifactId>jackson-dataformat-yaml</artifactId>
- <version>2.9.4</version>
- </dependency>
<!-- Remove the MYSQL connector and replace it by Mariadb -->
<dependency>
<groupId>org.mariadb.jdbc</groupId>
* The deployment ID\r
* @param serviceTypeId\r
* Service type ID\r
+ * @param blueprintInput\r
+ * The value for each blueprint parameters in a flat JSON\r
* @return The status URL\r
*/\r
public String createNewDeployment(String deploymentId, String serviceTypeId) {\r
import com.att.eelf.configuration.EELFLogger;\r
import com.att.eelf.configuration.EELFManager;\r
import com.fasterxml.jackson.core.JsonProcessingException;\r
-import com.fasterxml.jackson.databind.ObjectMapper;\r
import com.fasterxml.jackson.databind.node.ObjectNode;\r
\r
import java.io.IOException;\r
import org.onap.clamp.clds.model.dcae.DcaeInventoryResponse;\r
import org.onap.clamp.clds.model.properties.Global;\r
import org.onap.clamp.clds.model.properties.ModelProperties;\r
+import org.onap.clamp.clds.util.JacksonUtils;\r
import org.onap.clamp.clds.util.LoggingUtils;\r
import org.springframework.beans.factory.annotation.Autowired;\r
import org.springframework.stereotype.Component;\r
LoggingUtils.setResponseContext("0", "Get Dcae Information success", this.getClass().getName());\r
LoggingUtils.setTimeContext(startTime, new Date());\r
metricsLogger.info("getDcaeInformation complete: number services returned=" + numServices);\r
- return new ObjectMapper().readValue(dcaeInventoryResponse, DcaeInventoryResponse.class);\r
+ return JacksonUtils.getObjectMapperInstance().readValue(dcaeInventoryResponse, DcaeInventoryResponse.class);\r
}\r
\r
/**\r
LoggingUtils.setTargetContext("DCAE", "createDCAEServiceType");\r
String typeId = null;\r
try {\r
- ObjectMapper mapper = new ObjectMapper();\r
- ObjectNode dcaeServiceTypeRequest = mapper.createObjectNode();\r
+ ObjectNode dcaeServiceTypeRequest = JacksonUtils.getObjectMapperInstance().createObjectNode();\r
dcaeServiceTypeRequest.put("blueprintTemplate", blueprintTemplate);\r
dcaeServiceTypeRequest.put("owner", owner);\r
dcaeServiceTypeRequest.put("typeName", typeName);\r
import org.onap.clamp.clds.model.sdc.SdcServiceInfo;\r
import org.onap.clamp.clds.service.CldsService;\r
import org.onap.clamp.clds.util.CryptoUtils;\r
+import org.onap.clamp.clds.util.JacksonUtils;\r
import org.onap.clamp.clds.util.LoggingUtils;\r
import org.springframework.beans.factory.annotation.Autowired;\r
import org.springframework.stereotype.Component;\r
* an empty list\r
*/\r
private List<SdcServiceInfo> getCldsSdcServicesListFromJson(String jsonStr) {\r
- ObjectMapper objectMapper = new ObjectMapper();\r
if (StringUtils.isBlank(jsonStr)) {\r
return new ArrayList<>();\r
}\r
try {\r
- return objectMapper.readValue(jsonStr,\r
- objectMapper.getTypeFactory().constructCollectionType(List.class, SdcServiceInfo.class));\r
+ return JacksonUtils.getObjectMapperInstance().readValue(jsonStr, JacksonUtils.getObjectMapperInstance()\r
+ .getTypeFactory().constructCollectionType(List.class, SdcServiceInfo.class));\r
} catch (IOException e) {\r
logger.error("Error when attempting to decode the JSON containing CldsSdcServiceInfo", e);\r
return new ArrayList<>();\r
* issues\r
*/\r
private List<SdcResourceBasicInfo> getAllSdcResourcesListFromJson(String jsonStr) {\r
- ObjectMapper objectMapper = new ObjectMapper();\r
if (StringUtils.isBlank(jsonStr)) {\r
return new ArrayList<>();\r
}\r
try {\r
- return objectMapper.readValue(jsonStr,\r
- objectMapper.getTypeFactory().constructCollectionType(List.class, SdcResourceBasicInfo.class));\r
+ return JacksonUtils.getObjectMapperInstance().readValue(jsonStr, JacksonUtils.getObjectMapperInstance()\r
+ .getTypeFactory().constructCollectionType(List.class, SdcResourceBasicInfo.class));\r
} catch (IOException e) {\r
logger.error("Exception occurred when attempting to decode the list of CldsSdcResourceBasicInfo JSON", e);\r
return new ArrayList<>();\r
* @return\r
*/\r
public SdcServiceDetail decodeCldsSdcServiceDetailFromJson(String jsonStr) {\r
- ObjectMapper objectMapper = new ObjectMapper();\r
try {\r
- return objectMapper.readValue(jsonStr, SdcServiceDetail.class);\r
+ return JacksonUtils.getObjectMapperInstance().readValue(jsonStr, SdcServiceDetail.class);\r
} catch (IOException e) {\r
logger.error("Exception when attempting to decode the CldsSdcServiceDetail JSON", e);\r
return null;\r
String serviceUuid = getServiceUuidFromServiceInvariantId(invariantServiceUuid);\r
String serviceDetailUrl = url + "/" + serviceUuid + SDC_METADATA_URL_PREFIX;\r
String responseStr = getCldsServicesOrResourcesBasedOnURL(serviceDetailUrl);\r
- ObjectMapper objectMapper = new ObjectMapper();\r
CldsServiceData cldsServiceData = new CldsServiceData();\r
if (responseStr != null) {\r
SdcServiceDetail cldsSdcServiceDetail;\r
try {\r
- cldsSdcServiceDetail = objectMapper.readValue(responseStr, SdcServiceDetail.class);\r
+ cldsSdcServiceDetail = JacksonUtils.getObjectMapperInstance().readValue(responseStr,\r
+ SdcServiceDetail.class);\r
} catch (IOException e) {\r
logger.error("Exception when decoding the CldsServiceData JSON from SDC", e);\r
throw new SdcCommunicationException("Exception when decoding the CldsServiceData JSON from SDC", e);\r
}\r
}\r
\r
- private List<CldsVfcData> getVfcDataListFromVfResponse(String vfResponse) throws GeneralSecurityException {\r
- ObjectMapper mapper = new ObjectMapper();\r
+ private List<CldsVfcData> getVfcDataListFromVfResponse(String vfResponse) {\r
ObjectNode vfResponseNode;\r
try {\r
- vfResponseNode = (ObjectNode) mapper.readTree(vfResponse);\r
+ vfResponseNode = (ObjectNode) JacksonUtils.getObjectMapperInstance().readTree(vfResponse);\r
} catch (IOException e) {\r
logger.error("Exception when decoding the JSON list of CldsVfcData", e);\r
return new ArrayList<>();\r
String vfcResourceUUIDUrl = catalogUrl + RESOURCE_URL_PREFIX + "/" + resourceUUID + SDC_METADATA_URL_PREFIX;\r
try {\r
String vfcResponse = getCldsServicesOrResourcesBasedOnURL(vfcResourceUUIDUrl);\r
- ObjectMapper mapper = new ObjectMapper();\r
- ObjectNode vfResponseNode = (ObjectNode) mapper.readTree(vfcResponse);\r
+ ObjectNode vfResponseNode = (ObjectNode) JacksonUtils.getObjectMapperInstance().readTree(vfcResponse);\r
ArrayNode vfcArrayNode = (ArrayNode) vfResponseNode.get("resources");\r
if (vfcArrayNode != null) {\r
for (JsonNode vfcjsonNode : vfcArrayNode) {\r
\r
private List<CldsAlarmCondition> getAlarmCondtionsFromVfc(String vfcResponse) throws GeneralSecurityException {\r
List<CldsAlarmCondition> cldsAlarmConditionList = new ArrayList<>();\r
- ObjectMapper mapper = new ObjectMapper();\r
ObjectNode vfcResponseNode;\r
try {\r
- vfcResponseNode = (ObjectNode) mapper.readTree(vfcResponse);\r
+ vfcResponseNode = (ObjectNode) JacksonUtils.getObjectMapperInstance().readTree(vfcResponse);\r
} catch (IOException e) {\r
logger.error("Exception when decoding the JSON list of CldsAlarmCondition", e);\r
return cldsAlarmConditionList;\r
// Method to get the artifact for any particular VF\r
private List<CldsVfKPIData> getFieldPathFromVF(String vfResponse) throws GeneralSecurityException {\r
List<CldsVfKPIData> cldsVfKPIDataList = new ArrayList<>();\r
- ObjectMapper mapper = new ObjectMapper();\r
ObjectNode vfResponseNode;\r
try {\r
- vfResponseNode = (ObjectNode) mapper.readTree(vfResponse);\r
+ vfResponseNode = (ObjectNode) JacksonUtils.getObjectMapperInstance().readTree(vfResponse);\r
} catch (IOException e) {\r
logger.error("Exception when decoding the JSON list of CldsVfKPIData", e);\r
return cldsVfKPIDataList;\r
*/\r
public String createPropertiesObjectByUUID(CldsServiceData cldsServiceData) throws IOException {\r
String totalPropsStr;\r
- ObjectMapper mapper = new ObjectMapper();\r
+ ObjectMapper mapper = JacksonUtils.getObjectMapperInstance();\r
ObjectNode globalPropsJson = (ObjectNode) refProp.getJsonTemplate(CldsService.GLOBAL_PROPERTIES_KEY);\r
if (cldsServiceData != null && cldsServiceData.getServiceUUID() != null) {\r
// Objectnode to save all byservice, byvf , byvfc and byalarm nodes\r
ObjectNode byIdObjectNode = mapper.createObjectNode();\r
// To create vf ResourceUUID node with serviceInvariantUUID\r
- ObjectNode invariantUuidObjectNodeWithVf = createVfObjectNodeByServiceInvariantUuid(mapper,\r
- cldsServiceData);\r
+ ObjectNode invariantUuidObjectNodeWithVf = createVfObjectNodeByServiceInvariantUuid(cldsServiceData);\r
byIdObjectNode.putPOJO("byService", invariantUuidObjectNodeWithVf);\r
// To create byVf and vfcResourceNode with vfResourceUUID\r
- ObjectNode vfcObjectNodeByVfUuid = createVfcObjectNodeByVfUuid(mapper, cldsServiceData.getCldsVfs());\r
+ ObjectNode vfcObjectNodeByVfUuid = createVfcObjectNodeByVfUuid(cldsServiceData.getCldsVfs());\r
byIdObjectNode.putPOJO("byVf", vfcObjectNodeByVfUuid);\r
// To create byKpi\r
ObjectNode kpiObjectNode = mapper.createObjectNode();\r
if (cldsServiceData.getCldsVfs() != null && !cldsServiceData.getCldsVfs().isEmpty()) {\r
for (CldsVfData currCldsVfData : cldsServiceData.getCldsVfs()) {\r
if (currCldsVfData != null) {\r
- createKpiObjectNodeByVfUuid(mapper, kpiObjectNode, currCldsVfData.getCldsKPIList());\r
+ createKpiObjectNodeByVfUuid(kpiObjectNode, currCldsVfData.getCldsKPIList());\r
}\r
}\r
}\r
if (cldsServiceData.getCldsVfs() != null && !cldsServiceData.getCldsVfs().isEmpty()) {\r
for (CldsVfData currCldsVfData : cldsServiceData.getCldsVfs()) {\r
if (currCldsVfData != null) {\r
- createAlarmCondObjectNodeByVfcUuid(mapper, vfcResourceUuidObjectNode,\r
- currCldsVfData.getCldsVfcs());\r
+ createAlarmCondObjectNodeByVfcUuid(vfcResourceUuidObjectNode, currCldsVfData.getCldsVfcs());\r
}\r
}\r
}\r
// To create byAlarmCondition with alarmConditionKey\r
List<CldsAlarmCondition> allAlarmConditions = getAllAlarmConditionsFromCldsServiceData(cldsServiceData,\r
"alarmCondition");\r
- ObjectNode alarmCondObjectNodeByAlarmKey = createAlarmCondObjectNodeByAlarmKey(mapper, allAlarmConditions);\r
+ ObjectNode alarmCondObjectNodeByAlarmKey = createAlarmCondObjectNodeByAlarmKey(allAlarmConditions);\r
byIdObjectNode.putPOJO("byAlarmCondition", alarmCondObjectNodeByAlarmKey);\r
// To create byAlertDescription with AlertDescription\r
List<CldsAlarmCondition> allAlertDescriptions = getAllAlarmConditionsFromCldsServiceData(cldsServiceData,\r
"alertDescription");\r
- ObjectNode alertDescObjectNodeByAlert = createAlarmCondObjectNodeByAlarmKey(mapper, allAlertDescriptions);\r
+ ObjectNode alertDescObjectNodeByAlert = createAlarmCondObjectNodeByAlarmKey(allAlertDescriptions);\r
byIdObjectNode.putPOJO("byAlertDescription", alertDescObjectNodeByAlert);\r
globalPropsJson.putPOJO("shared", byIdObjectNode);\r
logger.info("Global properties JSON created with SDC info:" + globalPropsJson);\r
return alarmCondList;\r
}\r
\r
- private ObjectNode createAlarmCondObjectNodeByAlarmKey(ObjectMapper mapper,\r
- List<CldsAlarmCondition> cldsAlarmCondList) {\r
+ private ObjectNode createAlarmCondObjectNodeByAlarmKey(List<CldsAlarmCondition> cldsAlarmCondList) {\r
+ ObjectMapper mapper = JacksonUtils.getObjectMapperInstance();\r
ObjectNode alarmCondKeyNode = mapper.createObjectNode();\r
if (cldsAlarmCondList != null && !cldsAlarmCondList.isEmpty()) {\r
for (CldsAlarmCondition currCldsAlarmCondition : cldsAlarmCondList) {\r
return alarmCondKeyNode;\r
}\r
\r
- private ObjectNode createVfObjectNodeByServiceInvariantUuid(ObjectMapper mapper, CldsServiceData cldsServiceData) {\r
+ private ObjectNode createVfObjectNodeByServiceInvariantUuid(CldsServiceData cldsServiceData) {\r
+ ObjectMapper mapper = JacksonUtils.getObjectMapperInstance();\r
ObjectNode invariantUuidObjectNode = mapper.createObjectNode();\r
ObjectNode vfObjectNode = mapper.createObjectNode();\r
ObjectNode vfUuidNode = mapper.createObjectNode();\r
return invariantUuidObjectNode;\r
}\r
\r
- private void createKpiObjectNodeByVfUuid(ObjectMapper mapper, ObjectNode vfResourceUuidObjectNode,\r
+ private void createKpiObjectNodeByVfUuid(ObjectNode vfResourceUuidObjectNode,\r
List<CldsVfKPIData> cldsVfKpiDataList) {\r
+ ObjectMapper mapper = JacksonUtils.getObjectMapperInstance();\r
if (cldsVfKpiDataList != null && !cldsVfKpiDataList.isEmpty()) {\r
for (CldsVfKPIData currCldsVfKpiData : cldsVfKpiDataList) {\r
if (currCldsVfKpiData != null) {\r
}\r
}\r
\r
- private void createAlarmCondObjectNodeByVfcUuid(ObjectMapper mapper, ObjectNode vfcResourceUuidObjectNode,\r
+ private void createAlarmCondObjectNodeByVfcUuid(ObjectNode vfcResourceUuidObjectNode,\r
List<CldsVfcData> cldsVfcDataList) {\r
+ ObjectMapper mapper = JacksonUtils.getObjectMapperInstance();\r
ObjectNode vfcObjectNode = mapper.createObjectNode();\r
ObjectNode alarmCondNode = mapper.createObjectNode();\r
ObjectNode alertDescNode = mapper.createObjectNode();\r
* @param cldsVfDataList\r
* @return\r
*/\r
- private ObjectNode createVfcObjectNodeByVfUuid(ObjectMapper mapper, List<CldsVfData> cldsVfDataList) {\r
+ private ObjectNode createVfcObjectNodeByVfUuid(List<CldsVfData> cldsVfDataList) {\r
+ ObjectMapper mapper = JacksonUtils.getObjectMapperInstance();\r
ObjectNode vfUuidObjectNode = mapper.createObjectNode();\r
if (cldsVfDataList != null && !cldsVfDataList.isEmpty()) {\r
for (CldsVfData currCldsVfData : cldsVfDataList) {\r
import org.onap.clamp.clds.model.properties.Tca;
import org.onap.clamp.clds.model.sdc.SdcResource;
import org.onap.clamp.clds.model.sdc.SdcServiceDetail;
+import org.onap.clamp.clds.util.JacksonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
* @return SDC Locations request in the JSON Format
*/
public String formatSdcLocationsReq(ModelProperties prop, String artifactName) {
- ObjectMapper objectMapper = new ObjectMapper();
+ ObjectMapper objectMapper = JacksonUtils.getObjectMapperInstance();
Global global = prop.getGlobal();
List<String> locationsList = global.getLocation();
ArrayNode locationsArrayNode = objectMapper.createArrayNode();
* In case of issues with the Json parser
*/
protected String getYamlvalue(String jsonGlobal) throws IOException {
- ObjectMapper objectMapper = new ObjectMapper();
String yamlFileValue = "";
- ObjectNode root = objectMapper.readValue(jsonGlobal, ObjectNode.class);
+ ObjectNode root = JacksonUtils.getObjectMapperInstance().readValue(jsonGlobal, ObjectNode.class);
Iterator<Entry<String, JsonNode>> entryItr = root.fields();
while (entryItr.hasNext()) {
Entry<String, JsonNode> entry = entryItr.next();
package org.onap.clamp.clds.config;
import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.IOUtils;
+import org.onap.clamp.clds.util.JacksonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.core.env.Environment;
* In case of issues with the JSON parser
*/
public JsonNode getJsonTemplate(String key) throws IOException {
- ObjectMapper objectMapper = new ObjectMapper();
String fileReference = getStringValue(key);
- return (fileReference != null) ? objectMapper.readValue(getFileContentFromPath(fileReference), JsonNode.class)
+ return (fileReference != null)
+ ? JacksonUtils.getObjectMapperInstance().readValue(getFileContentFromPath(fileReference),
+ JsonNode.class)
: null;
}
* In case of issues with the JSON parser
*/
public JsonNode getJsonTemplate(String key1, String key2) throws IOException {
- ObjectMapper objectMapper = new ObjectMapper();
String fileReference = getStringValue(key1, key2);
- return (fileReference != null) ? objectMapper.readValue(getFileContentFromPath(fileReference), JsonNode.class)
+ return (fileReference != null)
+ ? JacksonUtils.getObjectMapperInstance().readValue(getFileContentFromPath(fileReference),
+ JsonNode.class)
: null;
}
* ============LICENSE_START=======================================================
* ONAP CLAMP
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights
* reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
package org.onap.clamp.clds.config;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.IOUtils;
import org.onap.clamp.clds.exception.CldsUsersException;
import org.onap.clamp.clds.service.CldsUser;
+import org.onap.clamp.clds.util.JacksonUtils;
public class CldsUserJsonDecoder {
try {
// the ObjectMapper readValue method closes the stream no need to do
// it
- return new ObjectMapper().readValue(cldsUsersString, CldsUser[].class);
+ return JacksonUtils.getObjectMapperInstance().readValue(cldsUsersString, CldsUser[].class);
} catch (IOException e) {
throw new CldsUsersException("Exception occurred during the decoding of the clds-users.json", e);
}
package org.onap.clamp.clds.config.sdc;
import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
+import org.onap.clamp.clds.util.JacksonUtils;
+
/**
* This class is used to decode the configuration found in
* application.properties, this is related to the blueprint mapping
public static List<BlueprintParserMappingConfiguration> createFromJson(InputStream json) throws IOException {
TypeReference<List<BlueprintParserMappingConfiguration>> mapType = new TypeReference<List<BlueprintParserMappingConfiguration>>() {
};
- return new ObjectMapper().readValue(json, mapType);
+ return JacksonUtils.getObjectMapperInstance().readValue(json, mapType);
}
}
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.util.HashMap;
import javax.annotation.PostConstruct;
import org.onap.clamp.clds.exception.sdc.controller.SdcParametersException;
+import org.onap.clamp.clds.util.JacksonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
public void loadConfiguration() throws IOException {
Resource resource = appContext.getResource(sdcControllerFile);
// Try to load json tree
- jsonRootNode = new ObjectMapper().readValue(resource.getInputStream(), JsonNode.class);
+ jsonRootNode = JacksonUtils.getObjectMapperInstance().readValue(resource.getInputStream(), JsonNode.class);
}
public SdcSingleControllerConfiguration getSdcSingleControllerConfiguration(String controllerName) {
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.util.ArrayList;
import javax.ws.rs.NotFoundException;
import org.onap.clamp.clds.dao.CldsDao;
+import org.onap.clamp.clds.util.JacksonUtils;
/**
* Represent a CLDS Model.
boolean result = false;
try {
if (propText != null) {
- JsonNode modelJson = new ObjectMapper().readTree(propText);
+ JsonNode modelJson = JacksonUtils.getObjectMapperInstance().readTree(propText);
JsonNode simpleModelJson = modelJson.get("simpleModel");
if (simpleModelJson != null && simpleModelJson.asBoolean()) {
result = true;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.onap.clamp.clds.exception.ModelBpmnException;
import org.onap.clamp.clds.service.CldsService;
+import org.onap.clamp.clds.util.JacksonUtils;
/**
* Parse Model BPMN properties.
* Example json: {"policy" :[{"id":"Policy_0oxeocn", "from":"StartEvent_1"}]}
*/
public class ModelBpmn {
- protected static final EELFLogger logger = EELFManager.getInstance()
- .getLogger(CldsService.class);
- protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
+
+ protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsService.class);
+ protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
// for each type, an array of entries
private final Map<String, List<ModelBpmnEntry>> entriesByType = new HashMap<>();
// for each id, an array of entries
- private final Map<String, List<ModelBpmnEntry>> entriesById = new HashMap<>();
+ private final Map<String, List<ModelBpmnEntry>> entriesById = new HashMap<>();
// List of all elementIds
- private List<String> bpmnElementIds;
+ private List<String> bpmnElementIds;
/**
* Create ModelBpmn and populate maps from json
public static ModelBpmn create(String modelBpmnPropText) {
try {
ModelBpmn modelBpmn = new ModelBpmn();
- ObjectMapper objectMapper = new ObjectMapper();
- ObjectNode root = objectMapper.readValue(modelBpmnPropText, ObjectNode.class);
+ ObjectNode root = JacksonUtils.getObjectMapperInstance().readValue(modelBpmnPropText, ObjectNode.class);
// iterate over each entry like:
// "Policy":[{"id":"Policy","from":"StartEvent_1"}]
Iterator<Entry<String, JsonNode>> entryItr = root.fields();
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import org.onap.clamp.clds.model.CldsEvent;
import org.onap.clamp.clds.model.CldsModel;
import org.onap.clamp.clds.service.CldsService;
+import org.onap.clamp.clds.util.JacksonUtils;
/**
* Parse model properties.
this.actionCd = actionCd;
this.testOnly = isATest;
modelBpmn = ModelBpmn.create(modelBpmnText);
- modelJson = new ObjectMapper().readTree(modelPropText);
+ modelJson = JacksonUtils.getObjectMapperInstance().readTree(modelPropText);
instantiateMissingModelElements();
} catch (IOException e) {
throw new ModelBpmnException("Exception occurred when trying to decode the BPMN Properties JSON", e);
public static String getVf(CldsModel model) {
List<String> vfs = null;
try {
- ObjectMapper mapper = new ObjectMapper();
- JsonNode modelJson = mapper.readTree(model.getPropText());
+ JsonNode modelJson = JacksonUtils.getObjectMapperInstance().readTree(model.getPropText());
Global global = new Global(modelJson);
vfs = global.getResourceVf();
} catch (IOException e) {
import org.onap.clamp.clds.model.sdc.SdcServiceDetail;
import org.onap.clamp.clds.model.sdc.SdcServiceInfo;
import org.onap.clamp.clds.transform.XslTransformer;
+import org.onap.clamp.clds.util.JacksonUtils;
import org.onap.clamp.clds.util.LoggingUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
if (template != null) {
model.setTemplateId(template.getId());
model.setDocText(template.getPropText());
- // This is to provide the Bpmn XML when Template part in UI is
+ // This is to provide the Bpmn XML when Template part in UI
+ // is
// disabled
model.setBpmnText(template.getBpmnText());
}
String controlName = model.getControlName();
String bpmnJson = cldsBpmnTransformer.doXslTransformToString(bpmn);
logger.info("PUT bpmnJson={}", bpmnJson);
- // Flag indicates whether it is triggered by Validation Test button from
+ // Flag indicates whether it is triggered by Validation Test button
+ // from
// UI
boolean isTest = false;
if (test != null && test.equalsIgnoreCase("true")) {
logger.info("modelProp - " + prop);
logger.info("docText - " + docText);
try {
- String result = camelProxy.submit(actionCd, prop, bpmnJson, modelName, controlName, docText, isTest, userId,
- isInsertTestEvent);
+ String result = camelProxy.submit(actionCd, prop, bpmnJson, modelName, controlName, docText, isTest,
+ userId, isInsertTestEvent);
logger.info("Starting Camel flow on request, result is: ", result);
} catch (SdcCommunicationException | PolicyClientException | BadRequestException e) {
errorCase = true;
if (!isTest && (actionCd.equalsIgnoreCase(CldsEvent.ACTION_SUBMIT)
|| actionCd.equalsIgnoreCase(CldsEvent.ACTION_RESUBMIT)
|| actionCd.equalsIgnoreCase(CldsEvent.ACTION_SUBMITDCAE))) {
- // To verify inventory status and modify model status to distribute
+ // To verify inventory status and modify model status to
+ // distribute
dcaeInventoryServices.setEventInventory(retrievedModel, getUserId());
retrievedModel.save(cldsDao, getUserId());
}
errorCase = true;
logger.error("Exception occured during putModelAndProcessAction", e);
}
-
if (errorCase) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(retrievedModel).build();
}
if (StringUtils.isBlank(responseStr)) {
return "";
}
- ObjectMapper objectMapper = new ObjectMapper();
+ ObjectMapper objectMapper = JacksonUtils.getObjectMapperInstance();
List<SdcServiceInfo> rawList = objectMapper.readValue(responseStr,
objectMapper.getTypeFactory().constructCollectionType(List.class, SdcServiceInfo.class));
ObjectNode invariantIdServiceNode = objectMapper.createObjectNode();
}
private String createPropertiesObjectByUUID(String cldsResponseStr) throws IOException {
- ObjectMapper mapper = new ObjectMapper();
+ ObjectMapper mapper = JacksonUtils.getObjectMapperInstance();
SdcServiceDetail cldsSdcServiceDetail = mapper.readValue(cldsResponseStr, SdcServiceDetail.class);
ObjectNode globalPropsJson = (ObjectNode) refProp.getJsonTemplate(GLOBAL_PROPERTIES_KEY);
if (cldsSdcServiceDetail != null && cldsSdcServiceDetail.getUuid() != null) {
/**
* to create json with vf, alarm and locations
*/
- ObjectNode serviceObjectNode = createEmptyVfAlarmObject(mapper);
+ ObjectNode serviceObjectNode = createEmptyVfAlarmObject();
ObjectNode vfObjectNode = mapper.createObjectNode();
/**
* to create json with vf and vfresourceId
*/
- createVfObjectNode(vfObjectNode, mapper, cldsSdcServiceDetail.getResources());
+ createVfObjectNode(vfObjectNode, cldsSdcServiceDetail.getResources());
serviceObjectNode.putPOJO(cldsSdcServiceDetail.getInvariantUUID(), vfObjectNode);
ObjectNode byServiceBasicObjetNode = mapper.createObjectNode();
byServiceBasicObjetNode.putPOJO("byService", serviceObjectNode);
/**
* to create json with VFC Node
*/
- ObjectNode emptyvfcobjectNode = createByVFCObjectNode(mapper, cldsSdcServiceDetail.getResources());
+ ObjectNode emptyvfcobjectNode = createByVFCObjectNode(cldsSdcServiceDetail.getResources());
byServiceBasicObjetNode.putPOJO("byVf", emptyvfcobjectNode);
globalPropsJson.putPOJO("shared", byServiceBasicObjetNode);
logger.info("valuie of objNode: {}", globalPropsJson);
return globalPropsJson.toString();
}
- private ObjectNode createEmptyVfAlarmObject(ObjectMapper mapper) {
+ private ObjectNode createEmptyVfAlarmObject() {
+ ObjectMapper mapper = JacksonUtils.getObjectMapperInstance();
ObjectNode emptyObjectNode = mapper.createObjectNode();
emptyObjectNode.put("", "");
ObjectNode vfObjectNode = mapper.createObjectNode();
return emptyServiceObjectNode;
}
- private void createVfObjectNode(ObjectNode vfObjectNode2, ObjectMapper mapper,
- List<SdcResource> rawCldsSdcResourceList) {
+ private void createVfObjectNode(ObjectNode vfObjectNode2, List<SdcResource> rawCldsSdcResourceList) {
+ ObjectMapper mapper = JacksonUtils.getObjectMapperInstance();
ObjectNode vfNode = mapper.createObjectNode();
vfNode.put("", "");
// To remove repeated resource instance name from
vfObjectNode2.putPOJO("alarmCondition", alarmStringJsonNode);
}
- private ObjectNode createByVFCObjectNode(ObjectMapper mapper, List<SdcResource> cldsSdcResourceList) {
+ private ObjectNode createByVFCObjectNode(List<SdcResource> cldsSdcResourceList) {
+ ObjectMapper mapper = JacksonUtils.getObjectMapperInstance();
ObjectNode emptyObjectNode = mapper.createObjectNode();
ObjectNode emptyvfcobjectNode = mapper.createObjectNode();
ObjectNode vfCObjectNode = mapper.createObjectNode();
@Path("/deploy/{modelName}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
- public Response deployModel(@PathParam("modelName") String modelName,
- CldsModel model) {
+ public Response deployModel(@PathParam("modelName") String modelName, CldsModel model) {
Date startTime = new Date();
LoggingUtils.setRequestContext("CldsService: Deploy model", getPrincipalName());
Boolean errorCase = false;
errorCase = true;
logger.error("Exception occured during deployModel", e);
}
-
if (errorCase) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(model).build();
}
@Path("/undeploy/{modelName}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
- public Response unDeployModel(@PathParam("modelName") String modelName,
- CldsModel model) {
+ public Response unDeployModel(@PathParam("modelName") String modelName, CldsModel model) {
Date startTime = new Date();
LoggingUtils.setRequestContext("CldsService: Undeploy model", getPrincipalName());
-
Boolean errorCase = false;
try {
String operationStatusUndeployUrl = dcaeDispatcherServices.deleteExistingDeployment(model.getDeploymentId(),
errorCase = true;
logger.error("Exception occured during unDeployModel", e);
}
-
if (errorCase) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(model).build();
}
}
private void checkForDuplicateServiceVf(String modelName, String modelPropText) throws IOException {
- JsonNode modelJson = new ObjectMapper().readTree(modelPropText);
- JsonNode globalNode = modelJson.get("global");
+ JsonNode globalNode = JacksonUtils.getObjectMapperInstance().readTree(modelPropText).get("global");
String service = AbstractModelElement.getValueByName(globalNode, "service");
List<String> resourceVf = AbstractModelElement.getValuesByName(globalNode, "vf");
if (service != null && resourceVf != null && !resourceVf.isEmpty()) {
List<CldsModelProp> cldsModelPropList = cldsDao.getDeployedModelProperties();
for (CldsModelProp cldsModelProp : cldsModelPropList) {
- JsonNode currentJson = new ObjectMapper().readTree(cldsModelProp.getPropText());
- JsonNode currentNode = currentJson.get("global");
+ JsonNode currentNode = JacksonUtils.getObjectMapperInstance().readTree(cldsModelProp.getPropText()).get("global");
String currentService = AbstractModelElement.getValueByName(currentNode, "service");
List<String> currentVf = AbstractModelElement.getValuesByName(currentNode, "vf");
if (currentVf != null && !currentVf.isEmpty()) {
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+
+package org.onap.clamp.clds.service;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import javax.ws.rs.ext.ContextResolver;
+
+import org.onap.clamp.clds.util.JacksonUtils;
+
+/**
+ * This class is to restrcit the class type that can be de-serialized.
+ */
+public class JacksonObjectMapperProvider implements ContextResolver<ObjectMapper> {
+
+ private final ObjectMapper defaultObjectMapper;
+
+ public JacksonObjectMapperProvider() {
+ defaultObjectMapper = createDefaultMapper();
+ }
+
+ @Override
+ public ObjectMapper getContext(Class<?> type) {
+ return defaultObjectMapper;
+ }
+
+ private static ObjectMapper createDefaultMapper() {
+ return JacksonUtils.getObjectMapperInstance();
+ }
+}
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
+
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
public class JaxrsApplication extends Application {
private static final EELFLogger logger = EELFManager.getInstance().getLogger(JaxrsApplication.class);
-
private Function<BeanDefinition, Optional<Class<?>>> beanDefinitionToClass = b -> {
try {
return Optional.of(Class.forName(b.getBeanClassName()));
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> resources = new HashSet<>();
+ resources.add(JacksonObjectMapperProvider.class);
resources.add(io.swagger.v3.jaxrs2.integration.resources.OpenApiResource.class);
resources.addAll(scan());
return resources;
private List<Class<?>> scan() {
ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false);
scanner.addIncludeFilter(new AnnotationTypeFilter(javax.ws.rs.Path.class));
- return scanner.findCandidateComponents("org.onap.clamp.clds").stream()
- .map(beanDefinitionToClass)
- .filter(Optional::isPresent)
- .map(Optional::get)
- .collect(Collectors.toList());
+ return scanner.findCandidateComponents("org.onap.clamp.clds").stream().map(beanDefinitionToClass)
+ .filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
}
-
}
\ No newline at end of file
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+
+package org.onap.clamp.clds.util;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+/**
+ * This class is used to access the jackson with restricted type access.
+ */
+public class JacksonUtils {
+
+ private static ObjectMapper objectMapper;
+
+ private JacksonUtils() {
+ }
+
+ /**
+ * Call this method to retrieve a secure ObjectMapper.
+ *
+ * @return an ObjectMapper instance (same for clamp)
+ */
+ public static synchronized ObjectMapper getObjectMapperInstance() {
+ if (objectMapper == null) {
+ objectMapper = new ObjectMapper();
+ // This is to disable the security hole that could be opened for
+ // json deserialization, if needed do this
+ // objectMapper.enableDefaultTyping(DefaultTyping.NON_FINAL);
+ objectMapper.disableDefaultTyping();
+ }
+ return objectMapper;
+ }
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+
+package org.onap.clamp.clds.util;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+
+import java.io.IOException;
+
+import org.junit.Test;
+
+public class JacksonUtilsTest {
+
+ public static class TestClass extends TestObject {
+
+ String test2;
+ TestObject2 object2;
+
+ public TestClass(String value1, String value2) {
+ super(value1);
+ test2 = value2;
+ }
+
+ public TestClass() {
+ }
+
+ public String getTest2() {
+ return test2;
+ }
+
+ public void setTest2(String test2) {
+ this.test2 = test2;
+ }
+
+ public TestObject2 getObject2() {
+ return object2;
+ }
+
+ public void setObject2(TestObject2 object2) {
+ this.object2 = object2;
+ }
+ }
+
+ @Test
+ public void testGetObjectMapperInstance() {
+ assertNotNull(JacksonUtils.getObjectMapperInstance());
+ }
+
+ /**
+ * This method test that the security hole in Jackson is not enabled in the
+ * default ObjectMapper.
+ *
+ * @throws JsonParseException
+ * In case of issues
+ * @throws JsonMappingException
+ * In case of issues
+ * @throws IOException
+ * In case of issues
+ */
+ @Test
+ public void testCreateBeanDeserializer() throws JsonParseException, JsonMappingException, IOException {
+ TestClass test = new TestClass("value1", "value2");
+ test.setObject2(new TestObject2("test3"));
+ Object testObject = JacksonUtils.getObjectMapperInstance().readValue(
+ "[\"org.onap.clamp.clds.util.JacksonUtilsTest$TestClass\",{\"test\":\"value1\",\"test2\":\"value2\",\"object2\":[\"org.onap.clamp.clds.util.TestObject2\",{\"test3\":\"test3\"}]}]",
+ Object.class);
+ assertNotNull(testObject);
+ assertFalse(testObject instanceof TestObject);
+ assertFalse(testObject instanceof TestClass);
+ }
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+
+package org.onap.clamp.clds.util;
+
+public class TestObject {
+
+ private String test;
+
+ public String getTest() {
+ return test;
+ }
+
+ public void setTest(String test) {
+ this.test = test;
+ }
+
+ // @JsonProperty("test"), @JsonCreator
+ public TestObject(String theString) {
+ this.setTest(theString);
+ }
+
+ public TestObject() {
+ }
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+
+package org.onap.clamp.clds.util;
+
+public class TestObject2 {
+
+ private String test3;
+
+ public String getTest3() {
+ return test3;
+ }
+
+ public void setTest3(String test) {
+ this.test3 = test;
+ }
+
+ public TestObject2(String theString) {
+ this.setTest3(theString);
+ }
+
+ public TestObject2() {
+ }
+}