aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-fe/src/main
diff options
context:
space:
mode:
authorIdan Amit <ia096e@intl.att.com>2017-12-29 09:40:43 +0200
committerMichael Lando <ml636r@att.com>2017-12-31 08:51:03 +0000
commit2c285722c35d8ee7fd6c9085c8e60f0fa87d5761 (patch)
treeb99164f8030c843091088a68a5638f9d9d1d80dc /catalog-fe/src/main
parent0195e726cae3f5267dd3be69e089bbbeb4ad5f09 (diff)
SDC Designers Integration - Part 1
Finished first part of designers integration Added templated configuration file Added tests Change-Id: I76e8b413063b939e1eb58da4a5502c4b526168f2 Issue-ID: SDC-687 Signed-off-by: Idan Amit <ia096e@intl.att.com>
Diffstat (limited to 'catalog-fe/src/main')
-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
-rw-r--r--catalog-fe/src/main/resources/config/designers-configuration.yaml13
4 files changed, 118 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();
+
+ }
}
diff --git a/catalog-fe/src/main/resources/config/designers-configuration.yaml b/catalog-fe/src/main/resources/config/designers-configuration.yaml
new file mode 100644
index 0000000000..c8c041b975
--- /dev/null
+++ b/catalog-fe/src/main/resources/config/designers-configuration.yaml
@@ -0,0 +1,13 @@
+designersList:
+ DCAE:
+ displayName: DCAE
+ designerHost: 192.168.50.5
+ designerPort: 8080
+ designerPath: "/dcae"
+ designerProtocol: http
+ WORKFLOW:
+ displayName: WORKFLOW
+ designerHost: 192.168.50.5
+ designerPort: 9527
+ designerPath: ""
+ designerProtocol: http \ No newline at end of file