summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorilanap <ilanap@amdocs.com>2019-11-28 11:13:24 +0200
committerOren Kleks <oren.kleks@amdocs.com>2019-12-05 09:19:40 +0000
commitee4c4d72ed2118ea44dd5d83e1cf1677b6ebb03c (patch)
treea1558696a8576d1e1d1e0665ebefec81398e3be5
parentcc8f8c056b99d530d48190b67846be3705a4225f (diff)
Add Option to proxy to plugins
Added option to proxy the plugins throught the catalog proxy. Remove hardcoded redirect to workflow and added to the plugin configuration. Issue-ID: SDC-2691 Signed-off-by: ilanap <ilanap@amdocs.com> Change-Id: Ica479ff00e1a8c281b9280b5495ac022172775c4 Signed-off-by: ilanap <ilanap@amdocs.com>
-rw-r--r--catalog-fe/src/main/java/org/openecomp/sdc/fe/servlets/FeProxyServlet.java116
-rw-r--r--catalog-fe/src/test/java/org/openecomp/sdc/servlets/FeProxyServletTest.java25
-rw-r--r--catalog-ui/configurations/dev.js2
-rw-r--r--catalog-ui/configurations/prod.js2
-rw-r--r--common-app-api/src/main/java/org/openecomp/sdc/fe/config/PluginsConfiguration.java108
-rw-r--r--docs/configuration.rst6
-rw-r--r--sdc-os-chef/environments/plugins-configuration.yaml2
-rw-r--r--sdc-os-chef/kubernetes/sdc/templates/configmaps/sdc-environment-configmap.yaml4
8 files changed, 128 insertions, 137 deletions
diff --git a/catalog-fe/src/main/java/org/openecomp/sdc/fe/servlets/FeProxyServlet.java b/catalog-fe/src/main/java/org/openecomp/sdc/fe/servlets/FeProxyServlet.java
index 1c7b174c57..1d7643fe40 100644
--- a/catalog-fe/src/main/java/org/openecomp/sdc/fe/servlets/FeProxyServlet.java
+++ b/catalog-fe/src/main/java/org/openecomp/sdc/fe/servlets/FeProxyServlet.java
@@ -46,9 +46,8 @@ public class FeProxyServlet extends SSLProxyServlet {
private static final String URL = "%s://%s%s%s";
private static final String ONBOARDING_CONTEXT = "/onboarding-api";
private static final String DCAED_CONTEXT = "/dcae-api";
- private static final String WORKFLOW_CONTEXT = "/wf";
private static final String SDC1_FE_PROXY = "/sdc1/feProxy";
- private static final String PLUGIN_ID_WORKFLOW = "WORKFLOW";
+ private static final String SDC1_PLUGIN_REDIRECT = SDC1_FE_PROXY + "/plugin";
private static final Logger LOGGER = Logger.getLogger(FeProxyServlet.class);
private static final int EXPIRE_DURATION = 10;
@@ -154,6 +153,24 @@ public class FeProxyServlet extends SSLProxyServlet {
}
+ /****
+ * scan all the plugins from the configuration against the URL and the redicert path
+ * @param request
+ * @return
+ */
+ private Plugin getPluginProxyForRequest(HttpServletRequest request) {
+ return getPluginConfiguration(request).getPluginsList()
+ .stream()
+ .filter(plugin -> {
+ if (plugin.getPluginProxyRedirectPath() != null && !plugin.getPluginProxyRedirectPath().isEmpty()) {
+ return request.getRequestURI().contains(SDC1_PLUGIN_REDIRECT + plugin.getPluginProxyRedirectPath());
+ } else {
+ return false;
+ }
+ })
+ .findFirst().orElse(null);
+ }
+
private String getModifiedUrl(HttpServletRequest request) throws MalformedURLException {
Configuration config = getConfiguration(request);
if (config == null) {
@@ -161,50 +178,77 @@ public class FeProxyServlet extends SSLProxyServlet {
throw new RuntimeException("failed to read FE configuration");
}
String uri = request.getRequestURI();
- String protocol;
- String host;
- String port;
+
+ // the modify logic is as follows:
+ // - proxy ONBOARDING to the onboarding context. this is not a plugin and hardcoded
+ // - proxy DCAE to the correct context. also - not a plugin but hardcoded
+ // - proxy to the plugin according to configuration if the path is found in the plugin patterns
+ // - proxy to the catalog backend if no other proxy was found
+
if (uri.contains(ONBOARDING_CONTEXT)) {
uri = uri.replace(SDC1_FE_PROXY + ONBOARDING_CONTEXT, ONBOARDING_CONTEXT);
- protocol = config.getOnboarding().getProtocolBe();
- host = config.getOnboarding().getHostBe();
- port = config.getOnboarding().getPortBe().toString();
- } else if (uri.contains(DCAED_CONTEXT)) {
+ return getModifiedUrlString(
+ request,
+ uri,
+ config.getOnboarding().getHostBe(),
+ config.getOnboarding().getPortBe().toString(),
+ config.getOnboarding().getProtocolBe());
+ }
+ if (uri.contains(DCAED_CONTEXT)) {
uri = uri.replace(SDC1_FE_PROXY + DCAED_CONTEXT, DCAED_CONTEXT);
- protocol = config.getBeProtocol();
- host = config.getBeHost();
- if (config.getBeProtocol().equals(BeProtocol.HTTP.getProtocolName())) {
- port = config.getBeHttpPort().toString();
- } else {
- port = config.getBeSslPort().toString();
+ return getModifiedUrlString(
+ request,
+ uri,
+ config.getBeHost(),
+ getCatalogBePort(config),
+ config.getBeProtocol());
+ }
+
+ if (uri.contains(SDC1_PLUGIN_REDIRECT)) {
+ Plugin proxyPlugin = getPluginProxyForRequest(request);
+ if (proxyPlugin != null) {
+ String proxyUrlStr = (proxyPlugin.getPluginFeProxyUrl() != null) ? proxyPlugin.getPluginFeProxyUrl() : proxyPlugin.getPluginSourceUrl();
+ URL proxyUrl = new URL(proxyUrlStr);
+ uri = uri.replace(SDC1_PLUGIN_REDIRECT + proxyPlugin.getPluginProxyRedirectPath(), proxyUrl.getPath());
+ return getModifiedUrlString(request, uri, proxyUrl);
}
- } else if (uri.contains(WORKFLOW_CONTEXT)) {
- String workflowPluginURL = getPluginConfiguration(request).getPluginsList()
- .stream()
- .filter(plugin -> plugin.getPluginId().equalsIgnoreCase(PLUGIN_ID_WORKFLOW))
- .map(Plugin::getPluginDiscoveryUrl)
- .findFirst().orElse(null);
-
- java.net.URL workflowURL = new URL(workflowPluginURL);
- protocol = workflowURL.getProtocol();
- host = workflowURL.getHost();
- port = String.valueOf(workflowURL.getPort());
- uri = uri.replace(SDC1_FE_PROXY + WORKFLOW_CONTEXT, workflowURL.getPath() + WORKFLOW_CONTEXT);
+ }
+
+ Plugin proxyPlugin = getPluginProxyForRequest(request);
+ if (proxyPlugin != null) {
+ String proxyUrlStr = (proxyPlugin.getPluginFeProxyUrl() != null) ? proxyPlugin.getPluginFeProxyUrl() : proxyPlugin.getPluginSourceUrl();
+ URL proxyUrl = new URL(proxyUrlStr);
+ uri = uri.replace(SDC1_FE_PROXY + proxyPlugin.getPluginProxyRedirectPath(), proxyUrl.getPath());
+ return getModifiedUrlString(request, uri, proxyUrl);
+ }
+
+ uri = uri.replace(SDC1_FE_PROXY, "/sdc2");
+ return getModifiedUrlString(
+ request,
+ uri,
+ config.getBeHost(),
+ getCatalogBePort(config),
+ config.getBeProtocol());
+ }
+
+
+ private String getCatalogBePort(Configuration config) {
+ if (config.getBeProtocol().equals(BeProtocol.HTTP.getProtocolName())) {
+ return config.getBeHttpPort().toString();
} else {
- uri = uri.replace(SDC1_FE_PROXY, "/sdc2");
- protocol = config.getBeProtocol();
- host = config.getBeHost();
- if (config.getBeProtocol().equals(BeProtocol.HTTP.getProtocolName())) {
- port = config.getBeHttpPort().toString();
- } else {
- port = config.getBeSslPort().toString();
- }
+ return config.getBeSslPort().toString();
}
+ }
+ private String getModifiedUrlString(HttpServletRequest request, String uri, URL url) {
+ String queryString = getQueryString(request);
+ return String.format(URL, url.getProtocol(), url.getAuthority(), uri, queryString);
+ }
+
+ private String getModifiedUrlString(HttpServletRequest request, String uri, String host, String port, String protocol) {
String authority = getAuthority(host, port);
String queryString = getQueryString(request);
return String.format(URL, protocol, authority, uri, queryString);
-
}
private PluginsConfiguration getPluginConfiguration(HttpServletRequest request) {
diff --git a/catalog-fe/src/test/java/org/openecomp/sdc/servlets/FeProxyServletTest.java b/catalog-fe/src/test/java/org/openecomp/sdc/servlets/FeProxyServletTest.java
index 4915936b1d..81e939b929 100644
--- a/catalog-fe/src/test/java/org/openecomp/sdc/servlets/FeProxyServletTest.java
+++ b/catalog-fe/src/test/java/org/openecomp/sdc/servlets/FeProxyServletTest.java
@@ -113,7 +113,12 @@ public class FeProxyServletTest {
when(plugin.getPluginId()).thenReturn("WORKFLOW");
when(plugin.getPluginSourceUrl()).thenReturn(WF_PROTOCOL + "://" + WF_HOST + ":" + WF_PORT);
when(plugin.getPluginDiscoveryUrl()).thenReturn(WF_PROTOCOL + "://" + WF_HOST + ":" + WF_PORT + "/workflows");
+ when(plugin.getPluginFeProxyUrl()).thenReturn(WF_PROTOCOL + "://" + WF_HOST + ":" + WF_PORT + "/workflows/wf/");
+ when(plugin.getPluginProxyRedirectPath()).thenReturn("/wf/");
pluginList.add(plugin);
+ PluginsConfiguration.Plugin noConfigPlugin = new PluginsConfiguration.Plugin();
+ noConfigPlugin.setPluginId("NO_CONFIG");
+ pluginList.add(noConfigPlugin);
when(configurationManager.getPluginsConfiguration()).thenReturn(pluginsConfiguration);
when(pluginsConfiguration.getPluginsList()).thenReturn(pluginList);
@@ -182,17 +187,31 @@ public class FeProxyServletTest {
@Test
public void testRewriteURIWithWFAPIRequest() {
- when(servletRequest.getRequestURI()).thenReturn("/sdc1/feProxy/wf/workflows");
- String requestResourceUrl = "http://localhost:8080/sdc1/feProxy/wf/workflows";
+ when(servletRequest.getRequestURI()).thenReturn("/sdc1/feProxy/plugin/wf/workflows");
+ String requestResourceUrl = "http://localhost:8080/sdc1/feProxy/plugin/wf/workflows";
String expectedChangedUrl = WF_PROTOCOL + "://" + WF_HOST + ":" + WF_PORT + "/workflows/wf/workflows";
when(servletRequest.getRequestURL()).thenReturn(new StringBuffer(requestResourceUrl));
when(servletRequest.getContextPath()).thenReturn("/sdc1");
- when(servletRequest.getServletPath()).thenReturn("/feProxy/wf/workflows");
+ when(servletRequest.getServletPath()).thenReturn("/feProxy/plugin/wf/workflows");
String rewriteURI = feProxy.rewriteTarget(servletRequest);
assertEquals(expectedChangedUrl, rewriteURI);
+
+ // now test in case it did not go through the plugin
+ when(servletRequest.getRequestURI()).thenReturn("/sdc1/feProxy/wf/workflows");
+ requestResourceUrl = "http://localhost:8080/sdc1/feProxy/wf/workflows";
+ expectedChangedUrl = BE_PROTOCOL + "://" + BE_HOST + ":" + BE_PORT + "/sdc2/wf/workflows";
+ when(servletRequest.getRequestURL()).thenReturn(new StringBuffer(requestResourceUrl));
+
+ when(servletRequest.getContextPath()).thenReturn("/sdc1");
+ when(servletRequest.getServletPath()).thenReturn("/feProxy/wf/workflows");
+
+ rewriteURI = feProxy.rewriteTarget(servletRequest);
+
+ assertEquals(expectedChangedUrl, rewriteURI);
+
}
/**
diff --git a/catalog-ui/configurations/dev.js b/catalog-ui/configurations/dev.js
index bca591296a..be1f52a787 100644
--- a/catalog-ui/configurations/dev.js
+++ b/catalog-ui/configurations/dev.js
@@ -49,7 +49,7 @@ const SDC_CONFIG = {
"GET_lifecycle_state_UNDOCHECKOUT":"lifecycleState/UNDOCHECKOUT",
"root": "/sdc1/feProxy/rest",
"no_proxy_root": "/sdc1/rest",
- "workflow_root": "/sdc1/feProxy/wf",
+ "workflow_root": "/sdc1/feProxy/plugin/wf",
"POST_workflow_artifact": "sdc/v1/catalog",
"PUT_service": "/v1/catalog/services/:id/metadata",
"GET_download_artifact": "/v1/catalog/",
diff --git a/catalog-ui/configurations/prod.js b/catalog-ui/configurations/prod.js
index 496c5760a6..32c9ae2a2b 100644
--- a/catalog-ui/configurations/prod.js
+++ b/catalog-ui/configurations/prod.js
@@ -49,7 +49,7 @@ const SDC_CONFIG = {
"GET_lifecycle_state_UNDOCHECKOUT":"lifecycleState/UNDOCHECKOUT",
"root": "/sdc1/feProxy/rest",
"no_proxy_root": "/sdc1/rest",
- "workflow_root": "/sdc1/feProxy/wf",
+ "workflow_root": "/sdc1/feProxy/plugin/wf",
"POST_workflow_artifact": "sdc/v1/catalog",
"PUT_service": "/v1/catalog/services/:id/metadata",
"GET_download_artifact": "/v1/catalog/",
diff --git a/common-app-api/src/main/java/org/openecomp/sdc/fe/config/PluginsConfiguration.java b/common-app-api/src/main/java/org/openecomp/sdc/fe/config/PluginsConfiguration.java
index 449c9eaccc..55b0ea0db9 100644
--- a/common-app-api/src/main/java/org/openecomp/sdc/fe/config/PluginsConfiguration.java
+++ b/common-app-api/src/main/java/org/openecomp/sdc/fe/config/PluginsConfiguration.java
@@ -20,132 +20,50 @@
package org.openecomp.sdc.fe.config;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
import org.openecomp.sdc.common.api.BasicConfiguration;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+@Getter
+@Setter
+@ToString
public class PluginsConfiguration extends BasicConfiguration {
private List<Plugin> pluginsList;
private Integer connectionTimeout;
- public List<Plugin> getPluginsList() {
- return pluginsList;
- }
-
- public void setPluginsList(List<Plugin> pluginsList) {
- this.pluginsList = pluginsList;
- }
-
- public Integer getConnectionTimeout() {
- return connectionTimeout;
- }
-
- public void setConnectionTimeout(Integer connectionTimeout) {
- this.connectionTimeout = connectionTimeout;
- }
-
public PluginsConfiguration() {
this.pluginsList = new ArrayList<>();
}
+ @Getter
+ @Setter
public static class Plugin {
-
private String pluginId;
private String pluginDiscoveryUrl;
private String pluginSourceUrl;
private String pluginStateUrl;
+ private String pluginFeProxyUrl; // this is optional in case it is different from the source url.
+ private String pluginProxyRedirectPath;
private Map<String, PluginDisplayOptions> pluginDisplayOptions;
private boolean isOnline;
- public String getPluginId() {
- return pluginId;
- }
-
- public void setPluginId(String pluginId) {
- this.pluginId = pluginId;
- }
-
- public String getPluginDiscoveryUrl() {
- return pluginDiscoveryUrl;
- }
-
- public void setPluginDiscoveryUrl(String pluginDiscoveryUrl) {
- this.pluginDiscoveryUrl = pluginDiscoveryUrl;
- }
-
- public String getPluginSourceUrl() {
- return pluginSourceUrl;
- }
-
- public void setPluginSourceUrl(String pluginSourceUrl) {
- this.pluginSourceUrl = pluginSourceUrl;
- }
-
- public String getPluginStateUrl() {
- return pluginStateUrl;
- }
-
- public void setPluginStateUrl(String pluginStateUrl) {
- this.pluginStateUrl = pluginStateUrl;
- }
-
- public Map<String, PluginDisplayOptions> getPluginDisplayOptions() {
- return pluginDisplayOptions;
- }
-
- public void setPluginDisplayOptions(Map<String, PluginDisplayOptions> pluginDisplayOptions) {
- this.pluginDisplayOptions = pluginDisplayOptions;
- }
-
}
+ @Getter
+ @Setter
+ @ToString
public static class PluginDisplayOptions {
-
private String displayName;
private List<String> displayContext;
private List<String> displayRoles;
-
- public String getDisplayName() {
- return displayName;
- }
-
- public void setDisplayName(String displayName) {
- this.displayName = displayName;
- }
-
- public List<String> getDisplayContext() {
- return displayContext;
- }
-
- public void setDisplayContext(List<String> displayContext) {
- this.displayContext = displayContext;
- }
-
- public List<String> getDisplayRoles() {
- return displayRoles;
- }
-
- public void setDisplayRoles(List<String> displayRoles) {
- this.displayRoles = displayRoles;
- }
-
- @Override
- public String toString() {
- return "PluginDisplayOptions["
- + "displayName='" + displayName
- + ", displayContext=" + displayContext
- + ", displayRoles=" + displayRoles
- + ']';
- }
}
- @Override
- public String toString() {
- return "PluginsConfiguration[" + "pluginsList=" + pluginsList + ", connectionTimeout=" + connectionTimeout + ']';
- }
}
diff --git a/docs/configuration.rst b/docs/configuration.rst
index 59f571d6ca..5156f6ee95 100644
--- a/docs/configuration.rst
+++ b/docs/configuration.rst
@@ -1382,6 +1382,10 @@ FE-plugins-configuration.yaml
# definition of the plugins that exist in sdc
# we have a pre-defined list of plugins that are connected to the system.
# the plugins define where they are shown, to whom and on what elements
+ # in addition, the catalog can proxy to the plugin as well if the following 2 keys are set:
+ # pluginFeProxyUrl - the pattern of the url that should be proxied after the sdc1/feProxy/plugin prefix
+ # pluginProxyRedirectPath - the redirect path to the plugin (full url including protool/host and port)
+
pluginsList:
# the DCAE-DS is the SDC monitoring design studio this entry defines there use as part of the service level context
- pluginId: DCAED
@@ -1414,6 +1418,8 @@ FE-plugins-configuration.yaml
- pluginId: WORKFLOW
pluginDiscoveryUrl: <%= @workflow_discovery_url %>
pluginSourceUrl: <%= @workflow_source_url %>
+ pluginFeProxyUrl: <%= @workflow_fe_proxy_url %>
+ pluginProxyRedirectPath: <%= @workflow_redirect_path %>
pluginStateUrl: "workflowDesigner"
pluginDisplayOptions:
tab:
diff --git a/sdc-os-chef/environments/plugins-configuration.yaml b/sdc-os-chef/environments/plugins-configuration.yaml
index 21de74636f..1135cbb54e 100644
--- a/sdc-os-chef/environments/plugins-configuration.yaml
+++ b/sdc-os-chef/environments/plugins-configuration.yaml
@@ -19,6 +19,8 @@ pluginsList:
- pluginId: WORKFLOW
pluginDiscoveryUrl: <%= @workflow_discovery_url %>
pluginSourceUrl: <%= @workflow_source_url %>
+ pluginFeProxyUrl: <%= @workflow_fe_proxy_url %>
+ pluginProxyRedirectPath: <%= @workflow_redirect_path %>
pluginStateUrl: "workflowDesigner"
pluginDisplayOptions:
tab:
diff --git a/sdc-os-chef/kubernetes/sdc/templates/configmaps/sdc-environment-configmap.yaml b/sdc-os-chef/kubernetes/sdc/templates/configmaps/sdc-environment-configmap.yaml
index 0eb5289c64..e332729526 100644
--- a/sdc-os-chef/kubernetes/sdc/templates/configmaps/sdc-environment-configmap.yaml
+++ b/sdc-os-chef/kubernetes/sdc/templates/configmaps/sdc-environment-configmap.yaml
@@ -57,7 +57,9 @@ data:
},
"WORKFLOW": {
"workflow_discovery_url": "10.0.2.15",
- "workflow_source_url": "10.0.2.15"
+ "workflow_source_url": "10.0.2.15",
+ "workflow_fe_proxy_url": "10.0.2.15",
+ "workflow_redirect_path": "/wf"
}
},
"VnfRepo": {