X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fclamp%2Fclds%2Fclient%2FDcaeDispatcherServices.java;h=0f4659591a357dcaf27672b1ac9bb0a447a888a8;hb=a6d09fbe1046057b72247f97ac72a521949409ce;hp=0aca8fb1dc414a932111ad1b71496df77802d6f1;hpb=7a58af870eb9934dfec4b5353672d7c428208116;p=clamp.git diff --git a/src/main/java/org/onap/clamp/clds/client/DcaeDispatcherServices.java b/src/main/java/org/onap/clamp/clds/client/DcaeDispatcherServices.java index 0aca8fb1..0f465959 100644 --- a/src/main/java/org/onap/clamp/clds/client/DcaeDispatcherServices.java +++ b/src/main/java/org/onap/clamp/clds/client/DcaeDispatcherServices.java @@ -18,16 +18,15 @@ * limitations under the License. * ============LICENSE_END============================================ * =================================================================== - * + * */ package org.onap.clamp.clds.client; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ObjectNode; +import com.google.gson.JsonObject; import java.io.IOException; import java.util.Date; @@ -37,6 +36,7 @@ import org.json.simple.parser.ParseException; import org.onap.clamp.clds.config.ClampProperties; import org.onap.clamp.clds.exception.dcae.DcaeDeploymentException; 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; @@ -49,8 +49,8 @@ public class DcaeDispatcherServices { protected static final EELFLogger logger = EELFManager.getInstance().getLogger(DcaeDispatcherServices.class); protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger(); - @Autowired - private ClampProperties refProp; + private final ClampProperties refProp; + private final HttpConnectionManager dcaeHttpConnectionManager; private static final String STATUS_URL_LOG = "Status URL extracted: "; private static final String DCAE_URL_PREFIX = "/dcae-deployments/"; private static final String DCAE_URL_PROPERTY_NAME = "dcae.dispatcher.url"; @@ -58,33 +58,19 @@ public class DcaeDispatcherServices { private static final String DCAE_LINK_FIELD = "links"; private static final String DCAE_STATUS_FIELD = "status"; - /** - * Delete the deployment on DCAE. - * - * @param deploymentId - * The deployment ID - * @return Return the URL Status - */ - public String deleteDeployment(String deploymentId) { - Date startTime = new Date(); - LoggingUtils.setTargetContext("DCAE", "deleteDeployment"); - try { - String url = refProp.getStringValue(DCAE_URL_PROPERTY_NAME) + DCAE_URL_PREFIX + deploymentId; - String statusUrl = getDcaeResponse(url, "DELETE", null, null, DCAE_LINK_FIELD, DCAE_STATUS_FIELD); - logger.info(STATUS_URL_LOG + statusUrl); - LoggingUtils.setResponseContext("0", "Delete deployments success", this.getClass().getName()); - return statusUrl; - } catch (Exception e) { - LoggingUtils.setResponseContext("900", "Delete deployments failed", this.getClass().getName()); - LoggingUtils.setErrorContext("900", "Delete deployments error"); - logger.error("Exception occurred during Delete Deployment Operation with DCAE", e); - throw new DcaeDeploymentException("Exception occurred during Delete Deployment Operation with DCAE", e); - } finally { - LoggingUtils.setTimeContext(startTime, new Date()); - metricsLogger.info("deleteDeployment complete"); - } + @Autowired + public DcaeDispatcherServices(ClampProperties refProp, HttpConnectionManager dcaeHttpConnectionManager) { + this.refProp = refProp; + this.dcaeHttpConnectionManager = dcaeHttpConnectionManager; } + /** + * Get the Operation Status from a specified URL with retry. + * @param operationStatusUrl + * The URL of the DCAE + * @return The status + * @throws InterruptedException Exception during the retry + */ public String getOperationStatusWithRetry(String operationStatusUrl) throws InterruptedException { String operationStatus = ""; for (int i = 0; i < Integer.valueOf(refProp.getStringValue("dcae.dispatcher.retry.limit")); i++) { @@ -103,9 +89,8 @@ public class DcaeDispatcherServices { /** * Get the Operation Status from a specified URL. - * * @param statusUrl - * The URL provided by a previous DCAE Query + * The URL provided by a previous DCAE Query * @return The status */ public String getOperationStatus(String statusUrl) { @@ -114,7 +99,7 @@ public class DcaeDispatcherServices { Date startTime = new Date(); LoggingUtils.setTargetContext("DCAE", "getOperationStatus"); try { - String responseStr = DcaeHttpConnectionManager.doDcaeHttpQuery(statusUrl, "GET", null, null); + String responseStr = dcaeHttpConnectionManager.doGeneralHttpQuery(statusUrl, "GET", null, null, "DCAE", null, null); JSONObject jsonObj = parseResponse(responseStr); String operationType = (String) jsonObj.get("operationType"); String status = (String) jsonObj.get(DCAE_STATUS_FIELD); @@ -132,52 +117,30 @@ public class DcaeDispatcherServices { return opStatus; } - /** - * This method send a getDeployments operation to DCAE. - */ - public void getDeployments() { - Date startTime = new Date(); - LoggingUtils.setTargetContext("DCAE", "getDeployments"); - try { - String url = refProp.getStringValue(DCAE_URL_PROPERTY_NAME) + DCAE_URL_PREFIX; - DcaeHttpConnectionManager.doDcaeHttpQuery(url, "GET", null, null); - LoggingUtils.setResponseContext("0", "Get deployments success", this.getClass().getName()); - } catch (Exception e) { - LoggingUtils.setResponseContext("900", "Get deployments failed", this.getClass().getName()); - LoggingUtils.setErrorContext("900", "Get deployments error"); - logger.error("Exception occurred during getDeployments Operation with DCAE", e); - throw new DcaeDeploymentException("Exception occurred during getDeployments Operation with DCAE", e); - } finally { - LoggingUtils.setTimeContext(startTime, new Date()); - metricsLogger.info("getDeployments complete"); - } - } - /** * Returns status URL for createNewDeployment operation. - * * @param deploymentId - * The deployment ID + * The deployment ID * @param serviceTypeId - * Service type ID + * Service type ID * @param blueprintInputJson - * The value for each blueprint parameters in a flat JSON + * The value for each blueprint parameters in a flat JSON * @return The status URL */ - public String createNewDeployment(String deploymentId, String serviceTypeId, JsonNode blueprintInputJson) { + public String createNewDeployment(String deploymentId, String serviceTypeId, JsonObject blueprintInputJson) { Date startTime = new Date(); LoggingUtils.setTargetContext("DCAE", "createNewDeployment"); try { - ObjectNode rootNode = (ObjectNode) refProp.getJsonTemplate("dcae.deployment.template"); - rootNode.put("serviceTypeId", serviceTypeId); + JsonObject rootObject = refProp.getJsonTemplate("dcae.deployment.template").getAsJsonObject(); + rootObject.addProperty("serviceTypeId", serviceTypeId); if (blueprintInputJson != null) { - rootNode.set("inputs", blueprintInputJson); + rootObject.add("inputs", blueprintInputJson); } - String apiBodyString = rootNode.toString(); + String apiBodyString = rootObject.toString(); logger.info("Dcae api Body String - " + apiBodyString); String url = refProp.getStringValue(DCAE_URL_PROPERTY_NAME) + DCAE_URL_PREFIX + deploymentId; String statusUrl = getDcaeResponse(url, "PUT", apiBodyString, "application/json", DCAE_LINK_FIELD, - DCAE_STATUS_FIELD); + DCAE_STATUS_FIELD); LoggingUtils.setResponseContext("0", "Create new deployment failed", this.getClass().getName()); return statusUrl; } catch (Exception e) { @@ -193,11 +156,10 @@ public class DcaeDispatcherServices { /*** * Returns status URL for deleteExistingDeployment operation. - * * @param deploymentId - * The deployment ID + * The deployment ID * @param serviceTypeId - * The service Type ID + * The service Type ID * @return The status URL */ public String deleteExistingDeployment(String deploymentId, String serviceTypeId) { @@ -208,7 +170,7 @@ public class DcaeDispatcherServices { logger.info("Dcae api Body String - " + apiBodyString); String url = refProp.getStringValue(DCAE_URL_PROPERTY_NAME) + DCAE_URL_PREFIX + deploymentId; String statusUrl = getDcaeResponse(url, "DELETE", apiBodyString, "application/json", DCAE_LINK_FIELD, - DCAE_STATUS_FIELD); + DCAE_STATUS_FIELD); LoggingUtils.setResponseContext("0", "Delete existing deployment success", this.getClass().getName()); return statusUrl; @@ -217,7 +179,7 @@ public class DcaeDispatcherServices { LoggingUtils.setErrorContext("900", "Delete existing deployment error"); logger.error("Exception occurred during deleteExistingDeployment Operation with DCAE", e); throw new DcaeDeploymentException("Exception occurred during deleteExistingDeployment Operation with DCAE", - e); + e); } finally { LoggingUtils.setTimeContext(startTime, new Date()); metricsLogger.info("deleteExistingDeployment complete"); @@ -225,10 +187,10 @@ public class DcaeDispatcherServices { } private String getDcaeResponse(String url, String requestMethod, String payload, String contentType, String node, - String nodeAttr) throws IOException, ParseException { + String nodeAttr) throws IOException, ParseException { Date startTime = new Date(); try { - String responseStr = DcaeHttpConnectionManager.doDcaeHttpQuery(url, requestMethod, payload, contentType); + String responseStr = dcaeHttpConnectionManager.doGeneralHttpQuery(url, requestMethod, payload, contentType, "DCAE", null, null); JSONObject jsonObj = parseResponse(responseStr); JSONObject linksObj = (JSONObject) jsonObj.get(node); String statusUrl = (String) linksObj.get(nodeAttr);