X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fclamp%2Fclds%2Fclient%2FDcaeInventoryServices.java;h=0ebaab555d6dc847ac020efce813e290e17f52ed;hb=f0d7a9645a2b773df5d278d3858ce36a61f23645;hp=7f209199de55264da1ebd0f6dc13f9b40325eea3;hpb=0387f232b4a56e98092519ccc2e0ee7985f6701c;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 7f209199..0ebaab55 100644 --- a/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java +++ b/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java @@ -29,20 +29,13 @@ import com.att.eelf.configuration.EELFManager; import java.io.IOException; import java.util.Date; -import java.util.List; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; import org.onap.clamp.clds.config.ClampProperties; -import org.onap.clamp.clds.dao.CldsDao; -import org.onap.clamp.clds.model.CldsEvent; -import org.onap.clamp.clds.model.CldsModel; -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.JsonUtils; import org.onap.clamp.clds.util.LoggingUtils; import org.onap.clamp.util.HttpConnectionManager; @@ -62,93 +55,17 @@ public class DcaeInventoryServices { public static final String DCAE_INVENTORY_RETRY_INTERVAL = "dcae.intentory.retry.interval"; public static final String DCAE_INVENTORY_RETRY_LIMIT = "dcae.intentory.retry.limit"; private final ClampProperties refProp; - private final CldsDao cldsDao; private final HttpConnectionManager httpConnectionManager; /** * Constructor. */ @Autowired - public DcaeInventoryServices(ClampProperties refProp, CldsDao cldsDao, - HttpConnectionManager httpConnectionManager) { + public DcaeInventoryServices(ClampProperties refProp, HttpConnectionManager httpConnectionManager) { this.refProp = refProp; - this.cldsDao = cldsDao; this.httpConnectionManager = httpConnectionManager; } - /** - * Set the event inventory. - * - * @param cldsModel - * The CldsModel - * @param userId - * The user ID - * @throws ParseException - * In case of DCAE Json parse exception - */ - public void setEventInventory(CldsModel cldsModel, String userId) throws InterruptedException { - String artifactName = cldsModel.getControlName(); - DcaeEvent dcaeEvent = new DcaeEvent(); - DcaeInventoryResponse dcaeResponse = null; - Date startTime = new Date(); - LoggingUtils.setTargetContext("DCAE", "setEventInventory"); - if (artifactName != null) { - artifactName = artifactName + ".yml"; - } - try { - // Below are the properties required for calling the dcae inventory - ModelProperties prop = new ModelProperties(cldsModel.getName(), cldsModel.getControlName(), null, - false, "{}", cldsModel.getPropText()); - Global global = prop.getGlobal(); - String invariantServiceUuid = global.getService(); - List resourceUuidList = global.getResourceVf(); - String resourceUuid = ""; - if (resourceUuidList != null && !resourceUuidList.isEmpty()) { - resourceUuid = resourceUuidList.get(0); - } - /* Inventory service url is called in this method */ - dcaeResponse = getDcaeInformation(artifactName, invariantServiceUuid, resourceUuid); - /* set dcae events */ - dcaeEvent.setArtifactName(artifactName); - dcaeEvent.setEvent(DcaeEvent.EVENT_DISTRIBUTION); - LoggingUtils.setResponseContext("0", "Set inventory success", this.getClass().getName()); - } 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); - } catch (IOException ex) { - LoggingUtils.setResponseContext("900", "Set inventory failed", this.getClass().getName()); - LoggingUtils.setErrorContext("900", "Set inventory error"); - logger.error("Error during DCAE communication", ex); - } finally { - LoggingUtils.setTimeContext(startTime, new Date()); - metricsLogger.info("setEventInventory complete"); - } - this.analyzeAndSaveDcaeResponse(dcaeResponse, cldsModel, dcaeEvent, userId); - } - - private void analyzeAndSaveDcaeResponse(DcaeInventoryResponse dcaeResponse, CldsModel cldsModel, - DcaeEvent dcaeEvent, String userId) { - if (dcaeResponse != null) { - logger.info("Dcae Response for query on inventory: " + dcaeResponse); - String oldTypeId = cldsModel.getTypeId(); - if (dcaeResponse.getTypeId() != null) { - cldsModel.setTypeId(dcaeResponse.getTypeId()); - } - if (dcaeResponse.getTypeName() != null) { - cldsModel.setTypeName(dcaeResponse.getTypeName()); - } - if (oldTypeId == null || !cldsModel.getEvent().getActionCd().equalsIgnoreCase(CldsEvent.ACTION_DISTRIBUTE) - || cldsModel.getEvent().getActionCd().equalsIgnoreCase(CldsEvent.ACTION_SUBMITDCAE)) { - CldsEvent.insEvent(cldsDao, dcaeEvent.getControlName(), userId, dcaeEvent.getCldsActionCd(), - CldsEvent.ACTION_STATE_RECEIVED, null); - } - cldsModel.save(cldsDao, userId); - } else { - logger.info(cldsModel.getName() + " Model is not present in Dcae Inventory Service."); - } - } - private int getTotalCountFromDcaeInventoryResponse(String responseStr) throws ParseException { JSONParser parser = new JSONParser(); Object obj0 = parser.parse(responseStr); @@ -169,23 +86,18 @@ public class DcaeInventoryServices { /** * DO a query to DCAE to get some Information. * - * @param artifactName - * The artifact Name - * @param serviceUuid - * The service UUID - * @param resourceUuid - * The resource UUID + * @param artifactName The artifact Name + * @param serviceUuid The service UUID + * @param resourceUuid The resource UUID * @return The DCAE inventory for the artifact in DcaeInventoryResponse - * @throws IOException - * In case of issues with the stream - * @throws ParseException - * In case of issues with the Json parsing + * @throws IOException In case of issues with the stream + * @throws ParseException In case of issues with the Json parsing */ public DcaeInventoryResponse getDcaeInformation(String artifactName, String serviceUuid, String resourceUuid) - throws IOException, ParseException, InterruptedException { + throws IOException, ParseException, InterruptedException { LoggingUtils.setTargetContext("DCAE", "getDcaeInformation"); String queryString = "?asdcResourceId=" + resourceUuid + "&asdcServiceId=" + serviceUuid + "&typeName=" - + artifactName; + + artifactName; String fullUrl = refProp.getStringValue(DCAE_INVENTORY_URL) + "/dcae-service-types" + queryString; logger.info("Dcae Inventory Service full url - " + fullUrl); DcaeInventoryResponse response = queryDcaeInventory(fullUrl); @@ -196,7 +108,7 @@ public class DcaeInventoryServices { } private DcaeInventoryResponse queryDcaeInventory(String fullUrl) - throws IOException, InterruptedException, ParseException { + throws IOException, InterruptedException, ParseException { int retryInterval = 0; int retryLimit = 1; if (refProp.getStringValue(DCAE_INVENTORY_RETRY_LIMIT) != null) { @@ -215,7 +127,7 @@ public class DcaeInventoryServices { return getItemsFromDcaeInventoryResponse(response); } logger.info( - "Dcae inventory totalCount returned is 0, so waiting " + retryInterval + "ms before retrying ..."); + "Dcae inventory totalCount returned is 0, so waiting " + retryInterval + "ms before retrying ..."); // wait for a while and try to connect to DCAE again Thread.sleep(retryInterval); }