* limitations under the License.\r
* ============LICENSE_END============================================\r
* ===================================================================\r
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * \r
*/\r
\r
package org.onap.clamp.clds.client;\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
protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();\r
protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();\r
public static final String DCAE_INVENTORY_URL = "dcae.inventory.url";\r
+ public static final String DCAE_INVENTORY_RETRY_INTERVAL = "dcae.intentory.retry.interval";\r
+ public static final String DCAE_INVENTORY_RETRY_LIMIT = "dcae.intentory.retry.limit";\r
public static final String DCAE_TYPE_NAME = "typeName";\r
public static final String DCAE_TYPE_ID = "typeId";\r
@Autowired\r
* @throws ParseException\r
* In case of DCAE Json parse exception\r
*/\r
- public void setEventInventory(CldsModel cldsModel, String userId) throws ParseException {\r
+ public void setEventInventory(CldsModel cldsModel, String userId) throws ParseException, InterruptedException {\r
String artifactName = cldsModel.getControlName();\r
DcaeEvent dcaeEvent = new DcaeEvent();\r
DcaeInventoryResponse dcaeResponse = null;\r
* In case of issues with the Json parsing\r
*/\r
public DcaeInventoryResponse getDcaeInformation(String artifactName, String serviceUuid, String resourceUuid)\r
- throws IOException, ParseException {\r
+ throws IOException, ParseException, InterruptedException {\r
Date startTime = new Date();\r
LoggingUtils.setTargetContext("DCAE", "getDcaeInformation");\r
String queryString = "?asdcResourceId=" + resourceUuid + "&asdcServiceId=" + serviceUuid + "&typeName="\r
String fullUrl = refProp.getStringValue(DCAE_INVENTORY_URL) + "/dcae-service-types" + queryString;\r
logger.info("Dcae Inventory Service full url - " + fullUrl);\r
String dcaeInventoryResponse = null;\r
- String responseStr = DcaeHttpConnectionManager.doDcaeHttpQuery(fullUrl, "GET", null, null);\r
+\r
+ String responseStr = queryDCAEInventory (fullUrl);\r
JSONParser parser = new JSONParser();\r
Object obj0 = parser.parse(responseStr);\r
JSONObject jsonObj = (JSONObject) obj0;\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
+ private String queryDCAEInventory (String fullUrl) throws IOException, InterruptedException {\r
+ int retryInterval = 0;\r
+ int retryLimit = 1;\r
+ if (refProp.getStringValue(DCAE_INVENTORY_RETRY_LIMIT) != null) {\r
+ retryLimit = Integer.valueOf(refProp.getStringValue(DCAE_INVENTORY_RETRY_LIMIT));\r
+ }\r
+ if (refProp.getStringValue(DCAE_INVENTORY_RETRY_INTERVAL) != null) {\r
+ retryInterval = Integer.valueOf(refProp.getStringValue(DCAE_INVENTORY_RETRY_INTERVAL));\r
+ }\r
+\r
+ int i = 0;\r
+ while (i < retryLimit) {\r
+ i++;\r
+ try {\r
+ return DcaeHttpConnectionManager.doDcaeHttpQuery(fullUrl, "GET", null, null);\r
+ } catch (BadRequestException e) {\r
+ if (i == retryLimit) {\r
+ // reach the retry limit, but still failed to connect to DCAE\r
+ throw e;\r
+ } else {\r
+ // wait for a while and try to connect to DCAE again\r
+ Thread.sleep(retryInterval);\r
+ }\r
+ }\r
+ }\r
+ // normally it should not go to this branch. It should either return the DCAE query result, or throw exception\r
+ return null;\r
+ }\r
/**\r
* Inserts a new DCAEServiceType or updates an existing instance. If the\r
* typeName is same second time(already exists) then the\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