summaryrefslogtreecommitdiffstats
path: root/catalog-fe/src
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
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')
-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
-rw-r--r--catalog-fe/src/test/java/org/openecomp/sdc/fe/servlets/DesignerStatusBLTest.java110
5 files changed, 228 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
diff --git a/catalog-fe/src/test/java/org/openecomp/sdc/fe/servlets/DesignerStatusBLTest.java b/catalog-fe/src/test/java/org/openecomp/sdc/fe/servlets/DesignerStatusBLTest.java
new file mode 100644
index 0000000000..0ad233fd6d
--- /dev/null
+++ b/catalog-fe/src/test/java/org/openecomp/sdc/fe/servlets/DesignerStatusBLTest.java
@@ -0,0 +1,110 @@
+package org.openecomp.sdc.fe.servlets;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.http.StatusLine;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpHead;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.openecomp.sdc.fe.config.ConfigurationManager;
+import org.openecomp.sdc.fe.config.DesignersConfiguration;
+import org.openecomp.sdc.fe.config.DesignersConfiguration.Designer;
+import org.openecomp.sdc.fe.impl.DesignerStatusBL;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+public class DesignerStatusBLTest {
+
+ final static CloseableHttpClient httpClient = Mockito.mock(CloseableHttpClient.class);
+ DesignerStatusBL designerStatusBL = new DesignerStatusBL(httpClient);
+ private static Gson gson = new GsonBuilder().setPrettyPrinting().create();
+
+ final static ConfigurationManager configurationManager = Mockito.mock(ConfigurationManager.class);
+ final static DesignersConfiguration designersConfiguraiton = Mockito.mock(DesignersConfiguration.class);
+ final static Designer offlineDesigner = new Designer();
+ final static Designer onlineDesinger = new Designer();
+ final static CloseableHttpResponse httpResponse = Mockito.mock(CloseableHttpResponse.class);
+ final static StatusLine statusLine = Mockito.mock(StatusLine.class);
+ final static Map<String, Designer> testDesignersList = new HashMap<String, Designer>();
+
+ final static String offlineDesignerDisplayName = "offlineDesigner";
+ final static String offlineDesignerHost = "192.168.10.1";
+ final static int offlineDesignerPort = 1000;
+ final static String offlineDesignerPath = "/offline";
+ final static String offlineDesignerProtocol = "http";
+
+ final static String onlineDesignerDisplayName = "onlineDesigner";
+ final static String onlineDesignerHost = "192.168.20.2";
+ final static int onlineDesignerPort = 2000;
+ final static String onlineDesignerPath = "/online";
+ final static String onlineDesignerProtocol = "http";
+
+ StringBuilder offlineRequestString = new StringBuilder();
+ StringBuilder onlineRequestString = new StringBuilder();
+
+ @BeforeClass
+ public static void beforeClass() {
+ ConfigurationManager.setTestInstance(configurationManager);
+ when(configurationManager.getDesignersConfiguration()).thenReturn(designersConfiguraiton);
+
+ offlineDesigner.setDisplayName(offlineDesignerDisplayName);
+ offlineDesigner.setDesignerHost(offlineDesignerHost);
+ offlineDesigner.setDesignerPort(offlineDesignerPort);
+ offlineDesigner.setDesignerPath(offlineDesignerPath);
+ offlineDesigner.setDesignerProtocol(offlineDesignerProtocol);
+
+ StringBuilder offlineRequestString = new StringBuilder();
+ offlineRequestString.append(offlineDesignerProtocol).append("://").append(onlineDesignerHost).append(":")
+ .append(offlineDesignerPort).append(offlineDesignerPath);
+
+ onlineDesinger.setDisplayName(onlineDesignerDisplayName);
+ onlineDesinger.setDesignerHost(onlineDesignerHost);
+ onlineDesinger.setDesignerPort(onlineDesignerPort);
+ onlineDesinger.setDesignerPath(onlineDesignerPath);
+ onlineDesinger.setDesignerProtocol(onlineDesignerProtocol);
+
+ StringBuilder onlineRequestString = new StringBuilder();
+ onlineRequestString.append(onlineDesignerProtocol).append("://").append(onlineDesignerHost).append(":")
+ .append(offlineDesignerPort).append(offlineDesignerPath);
+
+ }
+
+ @Test
+ public void TestOfflineDesignerNotBeingReturnedWhenCallingCheckDesinerListAvailability() throws ClientProtocolException, IOException {
+ testDesignersList.put("offlineDesigner", offlineDesigner);
+ when(designersConfiguraiton.getDesignersList()).thenReturn(testDesignersList);
+
+ when(statusLine.getStatusCode()).thenReturn(404);
+ when(httpResponse.getStatusLine()).thenReturn(statusLine);
+ when(httpClient.execute(Mockito.any(HttpHead.class))).thenReturn(httpResponse);
+
+ assertTrue(designerStatusBL.checkDesinerListAvailability().equals("{}"));
+
+ }
+
+ @Test
+ public void TestOnlineDesignerNotBeingReturnedWhenCallingCheckDesinerListAvailability() throws ClientProtocolException, IOException {
+ testDesignersList.put("onlineDesigner", onlineDesinger);
+ when(designersConfiguraiton.getDesignersList()).thenReturn(testDesignersList);
+
+ when(statusLine.getStatusCode()).thenReturn(200);
+ when(httpResponse.getStatusLine()).thenReturn(statusLine);
+ when(httpClient.execute(Mockito.any())).thenReturn(httpResponse);
+
+ String result = gson.toJson(testDesignersList);
+
+ assertTrue(designerStatusBL.checkDesinerListAvailability().equals(result));
+
+ }
+
+}