summaryrefslogtreecommitdiffstats
path: root/catalog-fe/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-fe/src/main/java')
-rw-r--r--catalog-fe/src/main/java/org/openecomp/sdc/fe/impl/DesignerStatusBL.java78
-rw-r--r--catalog-fe/src/main/java/org/openecomp/sdc/fe/listen/FEAppContextListener.java4
-rw-r--r--catalog-fe/src/main/java/org/openecomp/sdc/fe/servlets/ConfigServlet.java28
3 files changed, 105 insertions, 5 deletions
diff --git a/catalog-fe/src/main/java/org/openecomp/sdc/fe/impl/DesignerStatusBL.java b/catalog-fe/src/main/java/org/openecomp/sdc/fe/impl/DesignerStatusBL.java
new file mode 100644
index 0000000000..cadaf19e96
--- /dev/null
+++ b/catalog-fe/src/main/java/org/openecomp/sdc/fe/impl/DesignerStatusBL.java
@@ -0,0 +1,78 @@
+package org.openecomp.sdc.fe.impl;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpHead;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.openecomp.sdc.fe.config.ConfigurationManager;
+import org.openecomp.sdc.fe.config.DesignersConfiguration;
+import org.openecomp.sdc.fe.config.DesignersConfiguration.Designer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+public class DesignerStatusBL {
+
+ private static Logger log = LoggerFactory.getLogger(DesignerStatusBL.class.getName());
+ private static Gson gson = new GsonBuilder().setPrettyPrinting().create();
+ private CloseableHttpClient client = null;
+
+ public DesignerStatusBL() {
+ this.client = HttpClients.createDefault();
+ }
+
+ public DesignerStatusBL(CloseableHttpClient client) {
+ this.client = client;
+
+ }
+
+ public String checkDesinerListAvailability() {
+ String result = null;
+
+ DesignersConfiguration designersConfiguarion = ConfigurationManager.getConfigurationManager()
+ .getDesignersConfiguration();
+
+ if (designersConfiguarion == null || designersConfiguarion.getDesignersList() == null) {
+ log.warn("Configuration of type {} was not found", DesignersConfiguration.class);
+ } else {
+ log.debug("The value returned from getConfig is {}", designersConfiguarion);
+
+ Map<String, Designer> avaiableDesignersMap = new HashMap<String, Designer>();
+
+ designersConfiguarion.getDesignersList().forEach((key, value) -> {
+ if (CheckDesignerAvailabilty(value)) {
+ avaiableDesignersMap.put(key, value);
+ }
+
+ });
+ result = gson.toJson(avaiableDesignersMap);
+ }
+ return result;
+ }
+
+ private boolean CheckDesignerAvailabilty(Designer designer) {
+
+ StringBuilder requestString = new StringBuilder();
+ boolean result = false;
+
+ requestString.append(designer.getDesignerProtocol()).append("://").append(designer.getDesignerHost()).append(":")
+ .append(designer.getDesignerPort()).append(designer.getDesignerPath());
+
+ HttpHead head = new HttpHead(requestString.toString());
+
+ try (CloseableHttpResponse response = this.client.execute(head)) {
+ result = response != null && response.getStatusLine().getStatusCode() == 200;
+ } catch (IOException e) {
+ log.debug("The designer {} is offline", designer);
+ }
+
+ return result;
+ }
+
+}
diff --git a/catalog-fe/src/main/java/org/openecomp/sdc/fe/listen/FEAppContextListener.java b/catalog-fe/src/main/java/org/openecomp/sdc/fe/listen/FEAppContextListener.java
index b132c46866..ea67efbc7e 100644
--- a/catalog-fe/src/main/java/org/openecomp/sdc/fe/listen/FEAppContextListener.java
+++ b/catalog-fe/src/main/java/org/openecomp/sdc/fe/listen/FEAppContextListener.java
@@ -30,6 +30,7 @@ import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.impl.ExternalConfiguration;
import org.openecomp.sdc.common.listener.AppContextListener;
import org.openecomp.sdc.fe.config.ConfigurationManager;
+import org.openecomp.sdc.fe.impl.DesignerStatusBL;
import org.openecomp.sdc.fe.monitoring.FeMonitoringService;
import org.openecomp.sdc.fe.servlets.HealthCheckService;
import org.slf4j.Logger;
@@ -48,6 +49,9 @@ public class FEAppContextListener extends AppContextListener implements ServletC
log.debug("loading configuration from configDir:{} appName:{}", ExternalConfiguration.getConfigDir(),
ExternalConfiguration.getAppName());
context.getServletContext().setAttribute(Constants.CONFIGURATION_MANAGER_ATTR, configurationManager);
+
+ DesignerStatusBL dsbl = new DesignerStatusBL();
+ context.getServletContext().setAttribute(Constants.DESIGNER_BL_COMPONENT, dsbl);
// Health Check service
HealthCheckService hcs = new HealthCheckService(context.getServletContext());
diff --git a/catalog-fe/src/main/java/org/openecomp/sdc/fe/servlets/ConfigServlet.java b/catalog-fe/src/main/java/org/openecomp/sdc/fe/servlets/ConfigServlet.java
index b8d623b72e..bcaf504497 100644
--- a/catalog-fe/src/main/java/org/openecomp/sdc/fe/servlets/ConfigServlet.java
+++ b/catalog-fe/src/main/java/org/openecomp/sdc/fe/servlets/ConfigServlet.java
@@ -33,11 +33,13 @@ import javax.ws.rs.container.TimeoutHandler;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
import org.openecomp.sdc.common.api.ConfigurationSource;
import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.servlets.BasicServlet;
import org.openecomp.sdc.fe.config.Configuration;
+import org.openecomp.sdc.fe.impl.DesignerStatusBL;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -47,11 +49,12 @@ import org.slf4j.LoggerFactory;
@Path("/config")
public class ConfigServlet extends BasicServlet {
+ private static final long serialVersionUID = 1L;
private static Logger log = LoggerFactory.getLogger(ConfigServlet.class.getName());
- @GET
- @Path("/get")
- @Produces(MediaType.APPLICATION_JSON)
+ //@GET
+ //@Path("/get")
+ //@Produces(MediaType.APPLICATION_JSON)
public String getConfig(@Context final HttpServletRequest request) {
String result = null;
@@ -82,8 +85,8 @@ public class ConfigServlet extends BasicServlet {
}
- @GET
- @Path("/asyncget")
+ //@GET
+ //@Path("/asyncget")
public void asyncGet(@Suspended final AsyncResponse asyncResponse) {
asyncResponse.setTimeoutHandler(new TimeoutHandler() {
@@ -111,4 +114,19 @@ public class ConfigServlet extends BasicServlet {
}).start();
}
+ @GET
+ @Path("/ui/designers")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getDesignersConfiguration(@Context final HttpServletRequest request) {
+ String result = null;
+
+ ServletContext context = request.getSession().getServletContext();
+
+ DesignerStatusBL designerStatusBL = (DesignerStatusBL) context.getAttribute(Constants.DESIGNER_BL_COMPONENT);
+
+ result = designerStatusBL.checkDesinerListAvailability();
+
+ return Response.status(Status.OK).entity(result).build();
+
+ }
}