aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org
diff options
context:
space:
mode:
authoradam <adam.krysiak@nokia.com>2018-09-14 14:36:51 +0200
committeradam <adam.krysiak@nokia.com>2018-10-01 08:15:35 +0200
commitebcb4654ec66465fd63b35d5df2f6a3e5876fd22 (patch)
treef742333dbf9379a72b2dfb33fa35c1d8e63d461f /src/main/java/org
parentb3579ac9a9c8040c4cefe94dba37f1c9e60d4096 (diff)
Added tests for dcae dispacher services
Issue-ID: CLAMP-221 Change-Id: Ifb1091f47aec38c04bbb98b8f4b1621c0c7b67a3 Signed-off-by: adam <adam.krysiak@nokia.com>
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/onap/clamp/clds/client/DcaeDispatcherServices.java40
-rw-r--r--src/main/java/org/onap/clamp/clds/client/DcaeHttpConnectionManager.java11
-rw-r--r--src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java26
-rw-r--r--src/main/java/org/onap/clamp/clds/exception/CldsDelegateException.java59
4 files changed, 33 insertions, 103 deletions
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 0aca8fb1d..16c18ae0e 100644
--- a/src/main/java/org/onap/clamp/clds/client/DcaeDispatcherServices.java
+++ b/src/main/java/org/onap/clamp/clds/client/DcaeDispatcherServices.java
@@ -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 DcaeHttpConnectionManager 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,13 @@ 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, DcaeHttpConnectionManager dcaeHttpConnectionManager) {
+ this.refProp = refProp;
+ this.dcaeHttpConnectionManager = dcaeHttpConnectionManager;
}
+
public String getOperationStatusWithRetry(String operationStatusUrl) throws InterruptedException {
String operationStatus = "";
for (int i = 0; i < Integer.valueOf(refProp.getStringValue("dcae.dispatcher.retry.limit")); i++) {
@@ -114,7 +94,7 @@ public class DcaeDispatcherServices {
Date startTime = new Date();
LoggingUtils.setTargetContext("DCAE", "getOperationStatus");
try {
- String responseStr = DcaeHttpConnectionManager.doDcaeHttpQuery(statusUrl, "GET", null, null);
+ String responseStr = dcaeHttpConnectionManager.doDcaeHttpQuery(statusUrl, "GET", null, null);
JSONObject jsonObj = parseResponse(responseStr);
String operationType = (String) jsonObj.get("operationType");
String status = (String) jsonObj.get(DCAE_STATUS_FIELD);
@@ -140,7 +120,7 @@ public class DcaeDispatcherServices {
LoggingUtils.setTargetContext("DCAE", "getDeployments");
try {
String url = refProp.getStringValue(DCAE_URL_PROPERTY_NAME) + DCAE_URL_PREFIX;
- DcaeHttpConnectionManager.doDcaeHttpQuery(url, "GET", null, null);
+ 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());
@@ -228,7 +208,7 @@ public class DcaeDispatcherServices {
String nodeAttr) throws IOException, ParseException {
Date startTime = new Date();
try {
- String responseStr = DcaeHttpConnectionManager.doDcaeHttpQuery(url, requestMethod, payload, contentType);
+ String responseStr = dcaeHttpConnectionManager.doDcaeHttpQuery(url, requestMethod, payload, contentType);
JSONObject jsonObj = parseResponse(responseStr);
JSONObject linksObj = (JSONObject) jsonObj.get(node);
String statusUrl = (String) linksObj.get(nodeAttr);
diff --git a/src/main/java/org/onap/clamp/clds/client/DcaeHttpConnectionManager.java b/src/main/java/org/onap/clamp/clds/client/DcaeHttpConnectionManager.java
index bebb6703d..059cc2b20 100644
--- a/src/main/java/org/onap/clamp/clds/client/DcaeHttpConnectionManager.java
+++ b/src/main/java/org/onap/clamp/clds/client/DcaeHttpConnectionManager.java
@@ -17,6 +17,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END============================================
+ * Modifications copyright (c) 2018 Nokia
* ===================================================================
*
*/
@@ -38,22 +39,22 @@ import javax.ws.rs.BadRequestException;
import org.apache.commons.io.IOUtils;
import org.onap.clamp.clds.util.LoggingUtils;
+import org.springframework.stereotype.Component;
/**
*
* This class manages the HTTP and HTTPS connections to DCAE.
*
*/
+@Component
public class DcaeHttpConnectionManager {
protected static final EELFLogger logger = EELFManager.getInstance()
.getLogger(DcaeHttpConnectionManager.class);
protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
private static final String DCAE_REQUEST_FAILED_LOG = "Request Failed - response payload=";
- private DcaeHttpConnectionManager() {
- }
- private static String doHttpsQuery(URL url, String requestMethod, String payload, String contentType)
+ private String doHttpsQuery(URL url, String requestMethod, String payload, String contentType)
throws IOException {
logger.info("Using HTTPS URL to contact DCAE:" + url.toString());
HttpsURLConnection secureConnection = (HttpsURLConnection) url.openConnection();
@@ -86,7 +87,7 @@ public class DcaeHttpConnectionManager {
}
}
- private static String doHttpQuery(URL url, String requestMethod, String payload, String contentType)
+ private String doHttpQuery(URL url, String requestMethod, String payload, String contentType)
throws IOException {
LoggingUtils utils = new LoggingUtils (logger);
logger.info("Using HTTP URL to contact DCAE:" + url);
@@ -138,7 +139,7 @@ public class DcaeHttpConnectionManager {
* @throws IOException
* In case of issue with the streams
*/
- public static String doDcaeHttpQuery(String url, String requestMethod, String payload, String contentType)
+ public String doDcaeHttpQuery(String url, String requestMethod, String payload, String contentType)
throws IOException {
URL urlObj = new URL(url);
if (url.contains("https://")) { // Support for HTTPS
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 5f2159681..b63bb646d 100644
--- a/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java
+++ b/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java
@@ -17,6 +17,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END============================================
+ * Modifications copyright (c) 2018 Nokia
* ===================================================================
*
*/
@@ -60,15 +61,22 @@ public class DcaeInventoryServices {
protected static final EELFLogger logger = EELFManager.getInstance().getLogger(DcaeInventoryServices.class);
protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
- public static final String DCAE_INVENTORY_URL = "dcae.inventory.url";
- 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 static final String DCAE_INVENTORY_URL = "dcae.inventory.url";
+ private static final String DCAE_INVENTORY_RETRY_INTERVAL = "dcae.intentory.retry.interval";
+ private static final String DCAE_INVENTORY_RETRY_LIMIT = "dcae.intentory.retry.limit";
public static final String DCAE_TYPE_NAME = "typeName";
public static final String DCAE_TYPE_ID = "typeId";
+ private final ClampProperties refProp;
+ private final CldsDao cldsDao;
+ private final DcaeHttpConnectionManager dcaeHttpConnectionManager;
+
@Autowired
- private ClampProperties refProp;
- @Autowired
- private CldsDao cldsDao;
+ public DcaeInventoryServices(ClampProperties refProp, CldsDao cldsDao, DcaeHttpConnectionManager dcaeHttpConnectionManager) {
+ this.refProp = refProp;
+ this.cldsDao = cldsDao;
+ this.dcaeHttpConnectionManager = dcaeHttpConnectionManager;
+ }
+
/**
* Set the event inventory.
@@ -203,7 +211,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 = dcaeHttpConnectionManager.doDcaeHttpQuery(fullUrl, "GET", null, null);
int totalCount = getTotalCountFromDcaeInventoryResponse(response);
metricsLogger.info("getDcaeInformation complete: totalCount returned=" + totalCount);
if (totalCount > 0) {
@@ -254,7 +262,7 @@ public class DcaeInventoryServices {
String apiBodyString = dcaeServiceTypeRequest.toString();
logger.info("Dcae api Body String - " + apiBodyString);
String url = refProp.getStringValue(DCAE_INVENTORY_URL) + "/dcae-service-types";
- String responseStr = DcaeHttpConnectionManager.doDcaeHttpQuery(url, "POST", apiBodyString,
+ String responseStr = dcaeHttpConnectionManager.doDcaeHttpQuery(url, "POST", apiBodyString,
"application/json");
// If the DCAEServiceTypeRequest is created successfully it will
// return a json object responce containing a node for newly created
@@ -305,7 +313,7 @@ public class DcaeInventoryServices {
if (inventoryResponse != null && inventoryResponse.getTypeId() != null) {
String fullUrl = refProp.getStringValue(DCAE_INVENTORY_URL) + "/dcae-service-types/"
+ inventoryResponse.getTypeId();
- DcaeHttpConnectionManager.doDcaeHttpQuery(fullUrl, "DELETE", null, null);
+ dcaeHttpConnectionManager.doDcaeHttpQuery(fullUrl, "DELETE", null, null);
}
result = true;
} catch (IOException | ParseException e) {
diff --git a/src/main/java/org/onap/clamp/clds/exception/CldsDelegateException.java b/src/main/java/org/onap/clamp/clds/exception/CldsDelegateException.java
deleted file mode 100644
index 22b7e3fdb..000000000
--- a/src/main/java/org/onap/clamp/clds/exception/CldsDelegateException.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP CLAMP
- * ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights
- * reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END============================================
- * ===================================================================
- *
- */
-
-package org.onap.clamp.clds.exception;
-
-/**
- * New exception to CldsDelegate errors.
- */
-public class CldsDelegateException extends RuntimeException {
-
- /**
- *
- */
- private static final long serialVersionUID = -2705212640916671093L;
-
- /**
- * This constructor can be used to create a new CldsDelegateException.
- *
- * @param message
- * A string message detailing the problem
- * @param e
- * The exception sent by the code
- */
- public CldsDelegateException(String message, Throwable e) {
- super(message, e);
- }
-
- /**
- * This constructor can be used to create a new CldsDelegateException. Use
- * this constructor only if you are creating a new exception stack, not if
- * an exception was already raised by another code.
- *
- * @param message
- * A string message detailing the problem
- */
- public CldsDelegateException(String message) {
- super(message);
- }
-}