import java.io.IOException;\r
import java.util.Date;\r
\r
+import org.apache.camel.CamelContext;\r
+import org.apache.camel.Exchange;\r
+import org.apache.camel.builder.ExchangeBuilder;\r
import org.json.simple.JSONArray;\r
import org.json.simple.JSONObject;\r
import org.json.simple.parser.JSONParser;\r
import org.onap.clamp.clds.model.dcae.DcaeInventoryResponse;\r
import org.onap.clamp.clds.util.JsonUtils;\r
import org.onap.clamp.clds.util.LoggingUtils;\r
-import org.onap.clamp.util.HttpConnectionManager;\r
import org.springframework.beans.factory.annotation.Autowired;\r
import org.springframework.stereotype.Component;\r
\r
@Component\r
public class DcaeInventoryServices {\r
\r
+ @Autowired\r
+ CamelContext camelContext;\r
+\r
protected static final EELFLogger logger = EELFManager.getInstance().getLogger(DcaeInventoryServices.class);\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_RETRY_INTERVAL = "dcae.intentory.retry.interval";\r
public static final String DCAE_INVENTORY_RETRY_LIMIT = "dcae.intentory.retry.limit";\r
private final ClampProperties refProp;\r
- private final HttpConnectionManager httpConnectionManager;\r
\r
/**\r
* Constructor.\r
*/\r
@Autowired\r
- public DcaeInventoryServices(ClampProperties refProp, HttpConnectionManager httpConnectionManager) {\r
+ public DcaeInventoryServices(ClampProperties refProp) {\r
this.refProp = refProp;\r
- this.httpConnectionManager = httpConnectionManager;\r
}\r
\r
private int getTotalCountFromDcaeInventoryResponse(String responseStr) throws ParseException {\r
public DcaeInventoryResponse getDcaeInformation(String artifactName, String serviceUuid, String resourceUuid)\r
throws IOException, ParseException, InterruptedException {\r
LoggingUtils.setTargetContext("DCAE", "getDcaeInformation");\r
- String queryString = "?asdcResourceId=" + resourceUuid + "&asdcServiceId=" + serviceUuid + "&typeName="\r
- + artifactName;\r
- String fullUrl = refProp.getStringValue(DCAE_INVENTORY_URL) + "/dcae-service-types" + queryString;\r
- logger.info("Dcae Inventory Service full url - " + fullUrl);\r
- DcaeInventoryResponse response = queryDcaeInventory(fullUrl);\r
- LoggingUtils.setResponseContext("0", "Get Dcae Information success", this.getClass().getName());\r
- Date startTime = new Date();\r
- LoggingUtils.setTimeContext(startTime, new Date());\r
- return response;\r
- }\r
\r
- private DcaeInventoryResponse queryDcaeInventory(String fullUrl)\r
- throws IOException, InterruptedException, ParseException {\r
int retryInterval = 0;\r
int retryLimit = 1;\r
if (refProp.getStringValue(DCAE_INVENTORY_RETRY_LIMIT) != null) {\r
retryInterval = Integer.valueOf(refProp.getStringValue(DCAE_INVENTORY_RETRY_INTERVAL));\r
}\r
for (int i = 0; i < retryLimit; i++) {\r
+ Exchange myCamelExchange = ExchangeBuilder.anExchange(camelContext)\r
+ .withProperty("blueprintResourceId", resourceUuid).withProperty("blueprintServiceId", serviceUuid)\r
+ .withProperty("blueprintName", artifactName).build();\r
metricsLogger.info("Attempt n°" + i + " to contact DCAE inventory");\r
- String response = httpConnectionManager.doHttpRequest(fullUrl, "GET", null, null, "DCAE", null, null);\r
- int totalCount = getTotalCountFromDcaeInventoryResponse(response);\r
- metricsLogger.info("getDcaeInformation complete: totalCount returned=" + totalCount);\r
- if (totalCount > 0) {\r
- logger.info("getDcaeInformation, answer from DCAE inventory:" + response);\r
- return getItemsFromDcaeInventoryResponse(response);\r
+\r
+ Exchange exchangeResponse = camelContext.createProducerTemplate()\r
+ .send("direct:get-dcae-blueprint-inventory", myCamelExchange);\r
+\r
+ if (Integer.valueOf(200).equals(exchangeResponse.getIn().getHeader("CamelHttpResponseCode"))) {\r
+ String dcaeResponse = (String) exchangeResponse.getIn().getBody();\r
+ int totalCount = getTotalCountFromDcaeInventoryResponse(dcaeResponse);\r
+ metricsLogger.info("getDcaeInformation complete: totalCount returned=" + totalCount);\r
+ if (totalCount > 0) {\r
+ logger.info("getDcaeInformation, answer from DCAE inventory:" + dcaeResponse);\r
+ LoggingUtils.setResponseContext("0", "Get Dcae Information success", this.getClass().getName());\r
+ Date startTime = new Date();\r
+ LoggingUtils.setTimeContext(startTime, new Date());\r
+ return getItemsFromDcaeInventoryResponse(dcaeResponse);\r
+ } else {\r
+ logger.info("Dcae inventory totalCount returned is 0, so waiting " + retryInterval\r
+ + "ms before retrying ...");\r
+ // wait for a while and try to connect to DCAE again\r
+ Thread.sleep(retryInterval);\r
+ }\r
}\r
- logger.info(\r
- "Dcae inventory totalCount returned is 0, so waiting " + retryInterval + "ms before retrying ...");\r
- // wait for a while and try to connect to DCAE again\r
- Thread.sleep(retryInterval);\r
}\r
logger.warn("Dcae inventory totalCount returned is still 0, after " + retryLimit + " attempts, returning NULL");\r
return null;\r