From 9db4052423f34a76296ffdcda896cdeba2b4aead Mon Sep 17 00:00:00 2001 From: Michael Lando Date: Sat, 22 Jul 2017 17:10:02 +0300 Subject: [sdc] 1710 rebase code Change-Id: Icedeac71c0a9d27518969effcd5d5519de9955a6 Signed-off-by: Michael Lando --- .../sdc/fe/servlets/HealthCheckService.java | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) (limited to 'catalog-fe/src/main/java') 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 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 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 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 healthCheckInfos = new ArrayList(); 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; + } } -- cgit 1.2.3-korg