summaryrefslogtreecommitdiffstats
path: root/catalog-fe/src
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-fe/src')
-rw-r--r--catalog-fe/src/main/java/org/openecomp/sdc/fe/servlets/HealthCheckService.java67
-rw-r--r--catalog-fe/src/main/resources/config/configuration.yaml6
2 files changed, 73 insertions, 0 deletions
diff --git a/catalog-fe/src/main/java/org/openecomp/sdc/fe/servlets/HealthCheckService.java b/catalog-fe/src/main/java/org/openecomp/sdc/fe/servlets/HealthCheckService.java
index 4ef7c4974e..21a41b6a7e 100644
--- a/catalog-fe/src/main/java/org/openecomp/sdc/fe/servlets/HealthCheckService.java
+++ b/catalog-fe/src/main/java/org/openecomp/sdc/fe/servlets/HealthCheckService.java
@@ -23,6 +23,7 @@ package org.openecomp.sdc.fe.servlets;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@@ -32,6 +33,7 @@ import java.util.concurrent.TimeUnit;
import javax.servlet.ServletContext;
import javax.ws.rs.core.Response;
+import org.apache.http.HttpStatus;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
@@ -72,6 +74,7 @@ public class HealthCheckService {
private static Logger log = LoggerFactory.getLogger(HealthCheckService.class.getName());
private HealthStatus lastHealthStatus = new HealthStatus(500, "{}");
+ private final List<HealthCheckComponent> healthCheckFeComponents = Arrays.asList(HealthCheckComponent.ON_BOARDING);
private class HealthCheckScheduledTask implements Runnable {
@Override
@@ -191,9 +194,61 @@ public class HealthCheckService {
String description = "OK";
healthCheckWrapper.getComponentsInfo()
.add(new HealthCheckInfo(HealthCheckComponent.FE, HealthCheckStatus.UP, appVersion, description));
+
+ //add hosted components fe component
+ for (HealthCheckComponent component: healthCheckFeComponents) {
+ List<HealthCheckInfo> feComponentsInfo = addHostedComponentsFeHealthCheck(component);
+ HealthCheckInfo baseComponentHCInfo = healthCheckWrapper.getComponentsInfo().stream().filter(c -> c.getHealthCheckComponent() == component).findFirst().orElse(null);
+ if (baseComponentHCInfo != null) {
+ if (baseComponentHCInfo.getComponentsInfo() == null) {
+ baseComponentHCInfo.setComponentsInfo(new ArrayList<>());
+ }
+ baseComponentHCInfo.getComponentsInfo().addAll(feComponentsInfo);
+ }
+ }
return gson.toJson(healthCheckWrapper);
}
+ private List<HealthCheckInfo> addHostedComponentsFeHealthCheck(HealthCheckComponent baseComponent) {
+ Configuration config = ((ConfigurationManager) context.getAttribute(Constants.CONFIGURATION_MANAGER_ATTR))
+ .getConfiguration();
+
+ String healthCheckUrl = null;
+ switch(baseComponent) {
+ case ON_BOARDING:
+ healthCheckUrl = buildOnboardingHealthCheckUrl(config);
+ break;
+ }
+
+ String description;
+
+ if (healthCheckUrl != null) {
+ Gson gson = new Gson();
+ CloseableHttpClient httpClient = getHttpClient(config);
+ HttpGet httpGet = new HttpGet(healthCheckUrl);
+ CloseableHttpResponse beResponse;
+
+ try {
+ beResponse = httpClient.execute(httpGet);
+ int beStatus = beResponse.getStatusLine().getStatusCode();
+ if (beStatus == HttpStatus.SC_OK || beStatus == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
+ String beJsonResponse = EntityUtils.toString(beResponse.getEntity());
+ HealthCheckWrapper healthCheckWrapper = gson.fromJson(beJsonResponse, HealthCheckWrapper.class);
+ return healthCheckWrapper.getComponentsInfo();
+ } else {
+ description = "Response code: " + beStatus;
+ }
+ } catch (Exception e) {
+ log.error("Health Check error when trying to connect to " + baseComponent, e);
+ description = e.getMessage();
+ }
+ } else {
+ description = "Incorrect Health Check Url";
+ }
+
+ return Arrays.asList(new HealthCheckInfo(HealthCheckComponent.FE, HealthCheckStatus.DOWN, null, description));
+ }
+
private HealthCheckWrapper getBeDownCheckInfos() {
List<HealthCheckInfo> healthCheckInfos = new ArrayList<HealthCheckInfo>();
healthCheckInfos.add(new HealthCheckInfo(HealthCheckComponent.FE, HealthCheckStatus.UP,
@@ -217,4 +272,16 @@ public class HealthCheckService {
builder.setDefaultRequestConfig(requestBuilder.build());
return builder.build();
}
+
+ private String buildOnboardingHealthCheckUrl(Configuration config) {
+
+ Configuration.OnboardingConfig onboardingConfig = config.getOnboarding();
+
+ String protocol = onboardingConfig.getProtocol();
+ String host = onboardingConfig.getHost();
+ Integer port = onboardingConfig.getPort();
+ String uri = onboardingConfig.getHealthCheckUri();
+
+ return protocol + "://" + host + ":" + port + uri;
+ }
}
diff --git a/catalog-fe/src/main/resources/config/configuration.yaml b/catalog-fe/src/main/resources/config/configuration.yaml
index cd123ca220..1eda94b178 100644
--- a/catalog-fe/src/main/resources/config/configuration.yaml
+++ b/catalog-fe/src/main/resources/config/configuration.yaml
@@ -26,6 +26,12 @@ requestTimeout: 10
healthCheckSocketTimeoutInMs: 5000
healthCheckIntervalInSeconds: 5
+onboarding:
+ protocol: http
+ host: localhost
+ port: 8181
+ healthCheckUri: "/onboarding/v1.0/healthcheck"
+
identificationHeaderFields:
-
- &HTTP_IV_USER HTTP_IV_USER