X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fclamp%2Fclds%2Fclient%2FDcaeInventoryServices.java;h=d8bfeeaece8627e6e457db1a4b97212a9f34bd29;hb=a6d09fbe1046057b72247f97ac72a521949409ce;hp=327aff1da594c7e8ed5127ce74874169b2c1cbba;hpb=116703e35d4426dfd644246e17a40d4cab5cf641;p=clamp.git diff --git a/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java b/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java index 327aff1d..d8bfeeae 100644 --- a/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java +++ b/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java @@ -26,7 +26,6 @@ package org.onap.clamp.clds.client; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; -import com.fasterxml.jackson.core.JsonProcessingException; import java.io.IOException; import java.util.Date; @@ -44,8 +43,9 @@ import org.onap.clamp.clds.model.DcaeEvent; import org.onap.clamp.clds.model.dcae.DcaeInventoryResponse; import org.onap.clamp.clds.model.properties.Global; import org.onap.clamp.clds.model.properties.ModelProperties; -import org.onap.clamp.clds.util.JacksonUtils; +import org.onap.clamp.clds.util.JsonUtils; import org.onap.clamp.clds.util.LoggingUtils; +import org.onap.clamp.util.HttpConnectionManager; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -63,14 +63,17 @@ public class DcaeInventoryServices { public static final String DCAE_INVENTORY_RETRY_LIMIT = "dcae.intentory.retry.limit"; private final ClampProperties refProp; private final CldsDao cldsDao; - private final DcaeHttpConnectionManager dcaeHttpConnectionManager; + private final HttpConnectionManager httpConnectionManager; + /** + * Constructor. + */ @Autowired public DcaeInventoryServices(ClampProperties refProp, CldsDao cldsDao, - DcaeHttpConnectionManager dcaeHttpConnectionManager) { + HttpConnectionManager httpConnectionManager) { this.refProp = refProp; this.cldsDao = cldsDao; - this.dcaeHttpConnectionManager = dcaeHttpConnectionManager; + this.httpConnectionManager = httpConnectionManager; } /** @@ -83,7 +86,7 @@ public class DcaeInventoryServices { * @throws ParseException * In case of DCAE Json parse exception */ - public void setEventInventory(CldsModel cldsModel, String userId) throws ParseException, InterruptedException { + public void setEventInventory(CldsModel cldsModel, String userId) throws InterruptedException { String artifactName = cldsModel.getControlName(); DcaeEvent dcaeEvent = new DcaeEvent(); DcaeInventoryResponse dcaeResponse = null; @@ -109,7 +112,7 @@ public class DcaeInventoryServices { dcaeEvent.setArtifactName(artifactName); dcaeEvent.setEvent(DcaeEvent.EVENT_DISTRIBUTION); LoggingUtils.setResponseContext("0", "Set inventory success", this.getClass().getName()); - } catch (JsonProcessingException e) { + } catch (ParseException e) { LoggingUtils.setResponseContext("900", "Set inventory failed", this.getClass().getName()); LoggingUtils.setErrorContext("900", "Set inventory error"); logger.error("Error during JSON decoding", e); @@ -154,15 +157,13 @@ public class DcaeInventoryServices { return totalCount.intValue(); } - private DcaeInventoryResponse getItemsFromDcaeInventoryResponse(String responseStr) - throws ParseException, IOException { + private DcaeInventoryResponse getItemsFromDcaeInventoryResponse(String responseStr) throws ParseException { JSONParser parser = new JSONParser(); Object obj0 = parser.parse(responseStr); JSONObject jsonObj = (JSONObject) obj0; JSONArray itemsArray = (JSONArray) jsonObj.get("items"); JSONObject dcaeServiceType0 = (JSONObject) itemsArray.get(0); - return JacksonUtils.getObjectMapperInstance().readValue(dcaeServiceType0.toString(), - DcaeInventoryResponse.class); + return JsonUtils.GSON.fromJson(dcaeServiceType0.toString(), DcaeInventoryResponse.class); } /** @@ -182,7 +183,6 @@ public class DcaeInventoryServices { */ public DcaeInventoryResponse getDcaeInformation(String artifactName, String serviceUuid, String resourceUuid) throws IOException, ParseException, InterruptedException { - Date startTime = new Date(); LoggingUtils.setTargetContext("DCAE", "getDcaeInformation"); String queryString = "?asdcResourceId=" + resourceUuid + "&asdcServiceId=" + serviceUuid + "&typeName=" + artifactName; @@ -190,6 +190,7 @@ public class DcaeInventoryServices { logger.info("Dcae Inventory Service full url - " + fullUrl); DcaeInventoryResponse response = queryDcaeInventory(fullUrl); LoggingUtils.setResponseContext("0", "Get Dcae Information success", this.getClass().getName()); + Date startTime = new Date(); LoggingUtils.setTimeContext(startTime, new Date()); return response; } @@ -206,7 +207,7 @@ public class DcaeInventoryServices { } for (int i = 0; i < retryLimit; i++) { metricsLogger.info("Attempt n°" + i + " to contact DCAE inventory"); - String response = dcaeHttpConnectionManager.doDcaeHttpQuery(fullUrl, "GET", null, null); + String response = httpConnectionManager.doGeneralHttpQuery(fullUrl, "GET", null, null, "DCAE", null, null); int totalCount = getTotalCountFromDcaeInventoryResponse(response); metricsLogger.info("getDcaeInformation complete: totalCount returned=" + totalCount); if (totalCount > 0) {