Merge "Reduce complexity of HealthCheckUtils"
diff --git a/adapters/mso-network-adapter/src/main/java/org/openecomp/mso/adapters/network/HealthCheckHandler.java b/adapters/mso-network-adapter/src/main/java/org/openecomp/mso/adapters/network/HealthCheckHandler.java
index 85bca6f..5314de0 100644
--- a/adapters/mso-network-adapter/src/main/java/org/openecomp/mso/adapters/network/HealthCheckHandler.java
+++ b/adapters/mso-network-adapter/src/main/java/org/openecomp/mso/adapters/network/HealthCheckHandler.java
@@ -48,7 +48,7 @@
MsoLogger.setServiceName ("Healthcheck");
UUIDChecker.verifyOldUUID(requestId, msoLogger);
HealthCheckUtils healthCheck = new HealthCheckUtils ();
- if (!healthCheck.siteStatusCheck(msoLogger, startTime)) {
+ if (!healthCheck.siteStatusCheck(msoLogger)) {
return HealthCheckUtils.HEALTH_CHECK_NOK_RESPONSE;
}
diff --git a/adapters/mso-requests-db-adapter/src/main/java/org/openecomp/mso/adapters/requestsdb/HealthCheckHandler.java b/adapters/mso-requests-db-adapter/src/main/java/org/openecomp/mso/adapters/requestsdb/HealthCheckHandler.java
index 0c4c1c4..2a74d79 100644
--- a/adapters/mso-requests-db-adapter/src/main/java/org/openecomp/mso/adapters/requestsdb/HealthCheckHandler.java
+++ b/adapters/mso-requests-db-adapter/src/main/java/org/openecomp/mso/adapters/requestsdb/HealthCheckHandler.java
@@ -46,7 +46,7 @@
MsoLogger.setServiceName ("Healthcheck");
UUIDChecker.verifyOldUUID(requestId, msoLogger);
HealthCheckUtils healthCheck = new HealthCheckUtils ();
- if (!healthCheck.siteStatusCheck(msoLogger, startTime)) {
+ if (!healthCheck.siteStatusCheck(msoLogger)) {
return HealthCheckUtils.HEALTH_CHECK_NOK_RESPONSE;
}
diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/openecomp/mso/adapters/sdnc/impl/SDNCAdapterRestImpl.java b/adapters/mso-sdnc-adapter/src/main/java/org/openecomp/mso/adapters/sdnc/impl/SDNCAdapterRestImpl.java
index c69aee5..f6a3e36 100644
--- a/adapters/mso-sdnc-adapter/src/main/java/org/openecomp/mso/adapters/sdnc/impl/SDNCAdapterRestImpl.java
+++ b/adapters/mso-sdnc-adapter/src/main/java/org/openecomp/mso/adapters/sdnc/impl/SDNCAdapterRestImpl.java
@@ -131,7 +131,7 @@
MsoLogger.setServiceName ("Healthcheck");
UUIDChecker.verifyOldUUID(requestId, msoLogger);
HealthCheckUtils healthCheck = new HealthCheckUtils ();
- if (!healthCheck.siteStatusCheck(msoLogger, startTime)) {
+ if (!healthCheck.siteStatusCheck(msoLogger)) {
return HealthCheckUtils.HEALTH_CHECK_NOK_RESPONSE;
}
@@ -152,7 +152,7 @@
// Generate a Request Id
String requestId = UUIDChecker.generateUUID(msoLogger);
HealthCheckUtils healthCheck = new HealthCheckUtils ();
- if (!healthCheck.siteStatusCheck (msoLogger, startTime)) {
+ if (!healthCheck.siteStatusCheck (msoLogger)) {
return HealthCheckUtils.HEALTH_CHECK_NOK_RESPONSE;
}
@@ -175,7 +175,7 @@
// Generate a Request Id
String requestId = UUIDChecker.generateUUID(msoLogger);
HealthCheckUtils healthCheck = new HealthCheckUtils ();
- if (!healthCheck.siteStatusCheck (msoLogger, startTime)) {
+ if (!healthCheck.siteStatusCheck (msoLogger)) {
return HealthCheckUtils.HEALTH_CHECK_NOK_RESPONSE;
}
diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/openecomp/mso/adapters/sdnc/sdncrest/SDNCAdapterRest.java b/adapters/mso-sdnc-adapter/src/main/java/org/openecomp/mso/adapters/sdnc/sdncrest/SDNCAdapterRest.java
index 0c787ca..f7a37fc 100644
--- a/adapters/mso-sdnc-adapter/src/main/java/org/openecomp/mso/adapters/sdnc/sdncrest/SDNCAdapterRest.java
+++ b/adapters/mso-sdnc-adapter/src/main/java/org/openecomp/mso/adapters/sdnc/sdncrest/SDNCAdapterRest.java
@@ -58,7 +58,7 @@
UUIDChecker.verifyOldUUID(requestId, LOGGER);
HealthCheckUtils healthCheck = new HealthCheckUtils();
- if (!healthCheck.siteStatusCheck(LOGGER, startTime)) {
+ if (!healthCheck.siteStatusCheck(LOGGER)) {
return HealthCheckUtils.HEALTH_CHECK_NOK_RESPONSE;
}
diff --git a/adapters/mso-tenant-adapter/src/main/java/org/openecomp/mso/adapters/tenant/HealthCheckHandler.java b/adapters/mso-tenant-adapter/src/main/java/org/openecomp/mso/adapters/tenant/HealthCheckHandler.java
index ce2113e..1a4bec4 100644
--- a/adapters/mso-tenant-adapter/src/main/java/org/openecomp/mso/adapters/tenant/HealthCheckHandler.java
+++ b/adapters/mso-tenant-adapter/src/main/java/org/openecomp/mso/adapters/tenant/HealthCheckHandler.java
@@ -45,7 +45,7 @@
MsoLogger.setServiceName ("Healthcheck");
UUIDChecker.verifyOldUUID(requestId, msoLogger);
HealthCheckUtils healthCheck = new HealthCheckUtils ();
- if (!healthCheck.siteStatusCheck(msoLogger, startTime)) {
+ if (!healthCheck.siteStatusCheck(msoLogger)) {
return HealthCheckUtils.HEALTH_CHECK_NOK_RESPONSE;
}
diff --git a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/HealthCheckHandler.java b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/HealthCheckHandler.java
index 13e963f..8e163d4 100644
--- a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/HealthCheckHandler.java
+++ b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/HealthCheckHandler.java
@@ -56,7 +56,7 @@
MsoLogger.setServiceName("Healthcheck");
UUIDChecker.verifyOldUUID(requestId, msoLogger);
HealthCheckUtils healthCheck = new HealthCheckUtils();
- if(!healthCheck.siteStatusCheck(msoLogger, startTime)) {
+ if(!healthCheck.siteStatusCheck(msoLogger)) {
return HealthCheckUtils.HEALTH_CHECK_NOK_RESPONSE;
}
diff --git a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/HealthCheckHandler.java b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/HealthCheckHandler.java
index 3b619d9..840bd02 100644
--- a/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/HealthCheckHandler.java
+++ b/adapters/mso-vnf-adapter/src/main/java/org/openecomp/mso/adapters/vnf/HealthCheckHandler.java
@@ -49,7 +49,7 @@
MsoLogger.setServiceName ("Healthcheck");
UUIDChecker.verifyOldUUID(requestId, msoLogger);
HealthCheckUtils healthCheck = new HealthCheckUtils ();
- if (!healthCheck.siteStatusCheck(msoLogger, startTime)) {
+ if (!healthCheck.siteStatusCheck(msoLogger)) {
return HealthCheckUtils.HEALTH_CHECK_NOK_RESPONSE;
}
diff --git a/adapters/mso-workflow-message-adapter/src/main/java/org/openecomp/mso/adapters/workflowmessage/WMAdapterRest.java b/adapters/mso-workflow-message-adapter/src/main/java/org/openecomp/mso/adapters/workflowmessage/WMAdapterRest.java
index dc94a78..4be6b93 100644
--- a/adapters/mso-workflow-message-adapter/src/main/java/org/openecomp/mso/adapters/workflowmessage/WMAdapterRest.java
+++ b/adapters/mso-workflow-message-adapter/src/main/java/org/openecomp/mso/adapters/workflowmessage/WMAdapterRest.java
@@ -30,8 +30,6 @@
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@@ -62,7 +60,7 @@
UUIDChecker.verifyOldUUID(requestId, LOGGER);
HealthCheckUtils healthCheck = new HealthCheckUtils();
- if (!healthCheck.siteStatusCheck(LOGGER, startTime)) {
+ if (!healthCheck.siteStatusCheck(LOGGER)) {
return HealthCheckUtils.HEALTH_CHECK_NOK_RESPONSE;
}
diff --git a/asdc-controller/src/main/java/org/openecomp/mso/asdc/healthcheck/HealthCheckHandler.java b/asdc-controller/src/main/java/org/openecomp/mso/asdc/healthcheck/HealthCheckHandler.java
index 24e1153..2162607 100644
--- a/asdc-controller/src/main/java/org/openecomp/mso/asdc/healthcheck/HealthCheckHandler.java
+++ b/asdc-controller/src/main/java/org/openecomp/mso/asdc/healthcheck/HealthCheckHandler.java
@@ -59,7 +59,7 @@
MsoLogger.setServiceName ("Healthcheck");
UUIDChecker.verifyOldUUID(requestId, msoLogger);
HealthCheckUtils healthCheck = new HealthCheckUtils ();
- if (!healthCheck.siteStatusCheck(msoLogger, startTime)) {
+ if (!healthCheck.siteStatusCheck(msoLogger)) {
return HealthCheckUtils.HEALTH_CHECK_NOK_RESPONSE;
}
diff --git a/common/src/main/java/org/openecomp/mso/properties/MsoJavaProperties.java b/common/src/main/java/org/openecomp/mso/properties/MsoJavaProperties.java
index 3675dd6..f0ca191 100644
--- a/common/src/main/java/org/openecomp/mso/properties/MsoJavaProperties.java
+++ b/common/src/main/java/org/openecomp/mso/properties/MsoJavaProperties.java
@@ -115,7 +115,6 @@
} finally {
this.automaticRefreshInMinutes = this.getIntProperty(RELOAD_TIME_PROPERTY, DEFAULT_RELOAD_TIME_MIN);
- // Always close the file
try {
if (reader != null) {
reader.close();
@@ -155,27 +154,31 @@
return false;
}
MsoJavaProperties other = (MsoJavaProperties) obj;
- if (!msoProperties.equals(other.msoProperties)) {
- return false;
- }
- return true;
+
+ return msoProperties.equals(other.msoProperties);
}
@Override
public String toString() {
- StringBuffer response = new StringBuffer();
- response.append("Config file " + propertiesFileName + "(Timer:" + automaticRefreshInMinutes + "mins):"
- + System.getProperty("line.separator"));
+ StringBuilder response = new StringBuilder();
+ response.append("Config file ")
+ .append(propertiesFileName)
+ .append("(Timer:")
+ .append(automaticRefreshInMinutes)
+ .append("mins):")
+ .append(System.lineSeparator());
+
for (Object key : this.msoProperties.keySet()) {
String propertyName = (String) key;
response.append(propertyName);
response.append("=");
response.append(this.msoProperties.getProperty(propertyName));
- response.append(System.getProperty("line.separator"));
+ response.append(System.lineSeparator());
}
- response.append(System.getProperty("line.separator"));
- response.append(System.getProperty("line.separator"));
+ response.append(System.lineSeparator());
+ response.append(System.lineSeparator());
+
return response.toString();
}
}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/GlobalHealthcheckHandler.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/GlobalHealthcheckHandler.java
index af0fabc..52256d9 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/GlobalHealthcheckHandler.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/GlobalHealthcheckHandler.java
@@ -53,7 +53,7 @@
// Generate a Request Id
String requestId = UUIDChecker.generateUUID(msoLogger);
HealthCheckUtils healthCheck = new HealthCheckUtils ();
- if (!healthCheck.siteStatusCheck (msoLogger, startTime)) {
+ if (!healthCheck.siteStatusCheck (msoLogger)) {
return HealthCheckUtils.HEALTH_CHECK_NOK_RESPONSE;
}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/HealthcheckHandler.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/HealthcheckHandler.java
index 291414b..55f44a7 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/HealthcheckHandler.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/HealthcheckHandler.java
@@ -51,7 +51,7 @@
MsoLogger.setServiceName ("Healthcheck");
UUIDChecker.verifyOldUUID(requestId, msoLogger);
HealthCheckUtils healthCheck = new HealthCheckUtils ();
- if (!healthCheck.siteStatusCheck(msoLogger, startTime)) {
+ if (!healthCheck.siteStatusCheck(msoLogger)) {
return HealthCheckUtils.HEALTH_CHECK_NOK_RESPONSE;
}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/NodeHealthcheckHandler.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/NodeHealthcheckHandler.java
index beb26af..0191b54 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/NodeHealthcheckHandler.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/openecomp/mso/apihandlerinfra/NodeHealthcheckHandler.java
@@ -51,7 +51,7 @@
// Generate a Request Id
String requestId = UUIDChecker.generateUUID(msoLogger);
HealthCheckUtils healthCheck = new HealthCheckUtils ();
- if (!healthCheck.siteStatusCheck (msoLogger, startTime)) {
+ if (!healthCheck.siteStatusCheck (msoLogger)) {
return HealthCheckUtils.HEALTH_CHECK_NOK_RESPONSE;
}
diff --git a/status-control/src/main/java/org/openecomp/mso/HealthCheckUtils.java b/status-control/src/main/java/org/openecomp/mso/HealthCheckUtils.java
index e7c4e0d..b64f5bf 100644
--- a/status-control/src/main/java/org/openecomp/mso/HealthCheckUtils.java
+++ b/status-control/src/main/java/org/openecomp/mso/HealthCheckUtils.java
@@ -55,7 +55,7 @@
.entity (NOT_FOUND)
.build ();
- public enum NodeType {APIH, RA, BPMN};
+ public enum NodeType {APIH, RA, BPMN}
public boolean catalogDBCheck (MsoLogger subMsoLogger, long startTime) {
try(CatalogDatabase catalogDB = CatalogDatabase.getInstance()) {
@@ -79,7 +79,7 @@
return true;
}
- public boolean siteStatusCheck (MsoLogger subMsoLogger, long startTime) {
+ public boolean siteStatusCheck(MsoLogger subMsoLogger) {
// Check the Site Status value in DB first, if set to false, return NOK
String site = getProperty("site-name");
@@ -180,57 +180,26 @@
if (null == topologyProp) {
return false;
}
- String port = topologyProp.getProperty("server-port", null);
- String ip = System.getProperty("jboss.qualified.host.name");
- String sslEnabled = topologyProp.getProperty("ssl-enable", null);
- if (null == port || null == ip || ip.isEmpty() || port.isEmpty()) {
- msoLogger.error (MessageEnum.GENERAL_EXCEPTION_ARG, "Not able to get the IP or the Port value. IP:" + ip + "; Port:" + port, "", HEALTH_CHECK, MsoLogger.ErrorCode.DataError, "Not able to get the IP or the Port value. IP:" + ip + "; Port:" + port);
- return false;
+ checkHealthForProperty(topologyProp, "", requestId);
+
+ boolean healthCheck = false;
+ switch (type) {
+ case APIH:
+ healthCheck = checkHealthForProperty(topologyProp, "apih-healthcheck-urn", requestId);
+ break;
+ case RA:
+ healthCheck = checkHealthForProperty(topologyProp, "jra-healthcheck-urn", requestId);
+ break;
+ case BPMN:
+ healthCheck = checkHealthForProperty(topologyProp, "camunda-healthcheck-urn", requestId);
+ break;
+ default:
+ msoLogger.error(MessageEnum.GENERAL_EXCEPTION_ARG, "Unknown NodeType:" + type, "", HEALTH_CHECK, MsoLogger.ErrorCode.DataError, "Unknown NodeType:" + type);
+ break;
}
- String[] apis;
- if (NodeType.APIH.equals (type)) {
- String apiList = topologyProp.getProperty("apih-healthcheck-urn", null);
- if (null == apiList) {
- String errorDescription = "Not able to get apih-healthcheck-urn parameter";
- msoLogger.error (MessageEnum.GENERAL_EXCEPTION_ARG, errorDescription, "", HEALTH_CHECK, MsoLogger.ErrorCode.DataError, errorDescription);
- return false;
- }
- apis = apiList.split(",");
- } else if (NodeType.RA.equals (type)){
- String apiList = topologyProp.getProperty("jra-healthcheck-urn", null);
- if (null == apiList) {
- String errorDescription = "Not able to get jra-healthcheck-urn parameter";
- msoLogger.error (MessageEnum.GENERAL_EXCEPTION_ARG, errorDescription, "", HEALTH_CHECK, MsoLogger.ErrorCode.DataError, errorDescription);
- return false;
- }
- apis = apiList.split(",");
- } else if (NodeType.BPMN.equals (type)){
- String apiList = topologyProp.getProperty("camunda-healthcheck-urn", null);
- if (null == apiList) {
- String errorDescription = "Not able to get camunda-healthcheck-urn parameter";
- msoLogger.error (MessageEnum.GENERAL_EXCEPTION_ARG, errorDescription, "", HEALTH_CHECK, MsoLogger.ErrorCode.DataError, errorDescription);
- return false;
- }
- apis = apiList.split(",");
- } else {
- msoLogger.error (MessageEnum.GENERAL_EXCEPTION_ARG, "Unknown NodeType:" + type, "", HEALTH_CHECK, MsoLogger.ErrorCode.DataError, "Unknown NodeType:" + type);
- return false;
- }
-
- // Verify health check on APIH servers
- for (String url : apis) {
- // if any of the parameters is null or empty, no need to establish the health check request, just go to the next iteration
- if ((url == null) || url.isEmpty()) {
- continue;
- }
- // Exit the loop if local health check returns false from any of the sub component
- if (!this.verifyLocalHealth(ip, port, url, sslEnabled, requestId)) {
- return false;
- }
- }
- return true;
+ return healthCheck;
}
public boolean verifyGlobalHealthCheck(boolean verifyBpmn, String requestId) {
@@ -241,37 +210,9 @@
return false;
}
- String apihLB = topologyProp.getProperty("apih-load-balancer", null);
- String apihApi = topologyProp.getProperty("apih-nodehealthcheck-urn", null);
- String bpmnLB= topologyProp.getProperty("camunda-load-balancer", null);
- String bpmnApi = topologyProp.getProperty("camunda-nodehealthcheck-urn", null);
- String jraLB = topologyProp.getProperty("jra-load-balancer", null);
- String jraApi = topologyProp.getProperty("jra-nodehealthcheck-urn", null);
-
- if (null == apihLB || null == apihApi || null == bpmnLB || null == bpmnApi || null == jraLB || null == jraApi
- || apihLB.isEmpty () || apihApi.isEmpty () || bpmnLB.isEmpty () || bpmnApi.isEmpty () || jraLB.isEmpty () || jraApi.isEmpty () ) {
- msoLogger.error (MessageEnum.GENERAL_EXCEPTION_ARG, "Key parameters are missing from the topology file", "", HEALTH_CHECK, MsoLogger.ErrorCode.DataError, "Key parameters are missing from the topology file");
- return false;
- }
-
- // Verify health check on APIH servers
- if (!this.verifyLocalHealth (apihLB, null, apihApi, null, requestId)) {
- return false;
- }
-
- // Verify health check on Camunda servers
- if (verifyBpmn) {
- if (!this.verifyLocalHealth (bpmnLB, null, bpmnApi, null, requestId)) {
- return false;
- }
- }
-
- // Verify health check on RA servers
- if (!verifyLocalHealth (jraLB, null, jraApi, null, requestId)) {
- return false;
- }
-
- return true;
+ return verifyApihServersHealthCheck(topologyProp, requestId) &&
+ verifyCamundaServersHealthCheck(topologyProp, requestId, verifyBpmn) &&
+ verifyRaServersHealthCheck(topologyProp, requestId);
}
public String getProperty (String name) {
@@ -283,8 +224,8 @@
protected String getFinalUrl (String ip, String port, String url, String sslEnabled) {
if (null == port && null == sslEnabled) {
int length = ip.length();
- if (ip.substring(length - 1).equals ("/")) {
- ip = ip.substring (0, length - 1);
+ if ("/".equals(ip.substring(length - 1))) {
+ ip = ip.substring(0, length - 1);
}
return ip + url;
} else if ("true".equalsIgnoreCase(sslEnabled)) {
@@ -293,4 +234,75 @@
return "http://" + ip + ":" + port + url;
}
}
+
+ private boolean verifyRaServersHealthCheck(MsoJavaProperties topologyProp, String requestId) {
+ String jraLB = topologyProp.getProperty("jra-load-balancer", null);
+ String jraApi = topologyProp.getProperty("jra-nodehealthcheck-urn", null);
+
+ if (null == jraLB || null == jraApi || jraLB.isEmpty() || jraApi.isEmpty()) {
+ msoLogger.error(MessageEnum.GENERAL_EXCEPTION_ARG, "Key parameters are missing from the topology file", "", HEALTH_CHECK, MsoLogger.ErrorCode.DataError, "Key parameters are missing from the topology file");
+ return false;
+ }
+
+ return verifyLocalHealth(jraLB, null, jraApi, null, requestId);
+ }
+
+ private boolean verifyCamundaServersHealthCheck(MsoJavaProperties topologyProp, String requestId, boolean verifyBpmn) {
+ String bpmnLB = topologyProp.getProperty("camunda-load-balancer", null);
+ String bpmnApi = topologyProp.getProperty("camunda-nodehealthcheck-urn", null);
+
+ if (null == bpmnLB || null == bpmnApi || bpmnLB.isEmpty() || bpmnApi.isEmpty()) {
+ msoLogger.error(MessageEnum.GENERAL_EXCEPTION_ARG, "Key parameters are missing from the topology file", "", HEALTH_CHECK, MsoLogger.ErrorCode.DataError, "Key parameters are missing from the topology file");
+ return false;
+ }
+
+ return !verifyBpmn || verifyLocalHealth(bpmnLB, null, bpmnApi, null, requestId);
+ }
+
+ private boolean verifyApihServersHealthCheck(MsoJavaProperties topologyProp, String requestId) {
+ String apihLB = topologyProp.getProperty("apih-load-balancer", null);
+ String apihApi = topologyProp.getProperty("apih-nodehealthcheck-urn", null);
+
+ if (null == apihLB || null == apihApi || apihLB.isEmpty() || apihApi.isEmpty()) {
+ msoLogger.error(MessageEnum.GENERAL_EXCEPTION_ARG, "Key parameters are missing from the topology file", "", HEALTH_CHECK, MsoLogger.ErrorCode.DataError, "Key parameters are missing from the topology file");
+ return false;
+ }
+
+ return verifyLocalHealth(apihLB, null, apihApi, null, requestId);
+ }
+
+ private boolean checkHealthForProperty(MsoJavaProperties topologyProp, String property, String requestId) {
+ String apiList = topologyProp.getProperty(property, null);
+ if (apiList == null) {
+ String errorDescription = "Not able to get " + property + " parameter";
+ msoLogger.error(MessageEnum.GENERAL_EXCEPTION_ARG, errorDescription, "", HEALTH_CHECK, MsoLogger.ErrorCode.DataError, errorDescription);
+ return false;
+ }
+ String[] apis = apiList.split(",");
+ return checkHealthForEachApi(topologyProp, apis, requestId);
+ }
+
+ private boolean checkHealthForEachApi(MsoJavaProperties topologyProp, String[] apis, String requestId) {
+
+ String port = topologyProp.getProperty("server-port", null);
+ String ip = System.getProperty("jboss.qualified.host.name");
+ String sslEnabled = topologyProp.getProperty("ssl-enable", null);
+
+ if (null == port || null == ip || ip.isEmpty() || port.isEmpty()) {
+ msoLogger.error(MessageEnum.GENERAL_EXCEPTION_ARG, "Not able to get the IP or the Port value. IP:" + ip + "; Port:" + port, "", HEALTH_CHECK, MsoLogger.ErrorCode.DataError, "Not able to get the IP or the Port value. IP:" + ip + "; Port:" + port);
+ return false;
+ }
+
+ for (String url : apis) {
+ // if any of the parameters is null or empty, no need to establish the health check request, just go to the next iteration
+ if ((url == null) || url.isEmpty()) {
+ continue;
+ }
+ // Exit the loop if local health check returns false from any of the sub component
+ if (!this.verifyLocalHealth(ip, port, url, sslEnabled, requestId)) {
+ return false;
+ }
+ }
+ return true;
+ }
}
diff --git a/status-control/src/test/java/org/openecomp/mso/HealthCheckUtilsTest.java b/status-control/src/test/java/org/openecomp/mso/HealthCheckUtilsTest.java
index cdb5695..91016d2 100644
--- a/status-control/src/test/java/org/openecomp/mso/HealthCheckUtilsTest.java
+++ b/status-control/src/test/java/org/openecomp/mso/HealthCheckUtilsTest.java
@@ -21,22 +21,16 @@
package org.openecomp.mso;
-import org.openecomp.mso.logger.MsoLogger;
-import org.openecomp.mso.properties.MsoJavaProperties;
-import org.openecomp.mso.requestsdb.RequestsDatabase;
import org.apache.http.HttpStatus;
import org.apache.http.HttpVersion;
import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.message.BasicStatusLine;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Mockito;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
+import org.openecomp.mso.properties.MsoJavaProperties;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -63,7 +57,7 @@
private static CloseableHttpResponse nokRes, okRes;
@BeforeClass
- public static final void prepareMockvalues() {
+ public static void prepareMockvalues() {
utils = Mockito.mock(HealthCheckUtils.class);
client = Mockito.mock(CloseableHttpClient.class);
nokRes = Mockito.mock(CloseableHttpResponse.class);
@@ -207,11 +201,11 @@
try {
Mockito.when (client.execute (any(HttpUriRequest.class))).thenReturn (okRes);
- Boolean res1 = (Boolean)invokeProtectedMethod(tempUtil, "verifyLocalHealth", ip1, port, apihUrl1, sslEnable, null);
+ boolean res1 = tempUtil.verifyLocalHealth(ip1, port, apihUrl1, sslEnable, null);
assertTrue(res1);
Mockito.when (client.execute (any(HttpUriRequest.class))).thenReturn (nokRes);
- Boolean res2 = (Boolean)invokeProtectedMethod(tempUtil, "verifyLocalHealth", ip1, port, apihUrl1, sslEnable, null);
+ boolean res2 = tempUtil.verifyLocalHealth(ip1, port, apihUrl1, sslEnable, null);
assertFalse(res2);
} catch (Exception e) {
@@ -270,29 +264,4 @@
Mockito.when(utils.loadTopologyProperties()).thenReturn(properties);
}
- // User reflection to invoke to avoid change the publicity of the method
- private static Object invokeProtectedMethod (HealthCheckUtils tempUtil, String methodName, String arg1, String arg2, String arg3, String arg4, String arg5) {
- Method method;
- try {
- method = HealthCheckUtils.class.getDeclaredMethod(methodName, String.class, String.class, String.class, String.class, String.class);
- method.setAccessible(true);
- return method.invoke(tempUtil, arg1, arg2, arg3, arg4, arg5);
- } catch (NoSuchMethodException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (SecurityException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalArgumentException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return null;
- }
}
\ No newline at end of file