summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--msb-core/apiroute/apiroute-service/src/main/java/org/openo/msb/wrapper/serviceListener/MicroServiceChangeListener.java500
-rw-r--r--msb-core/apiroute/apiroute-service/src/main/java/org/openo/msb/wrapper/util/MicroServiceDB.java2
-rw-r--r--msb-core/apiroute/apiroute-service/src/main/java/org/openo/msb/wrapper/util/RouteUtil.java2
-rw-r--r--msb-core/apiroute/apiroute-service/src/main/resources/iui-route/js/routeController.js2
4 files changed, 246 insertions, 260 deletions
diff --git a/msb-core/apiroute/apiroute-service/src/main/java/org/openo/msb/wrapper/serviceListener/MicroServiceChangeListener.java b/msb-core/apiroute/apiroute-service/src/main/java/org/openo/msb/wrapper/serviceListener/MicroServiceChangeListener.java
index 412b4e6..50960c7 100644
--- a/msb-core/apiroute/apiroute-service/src/main/java/org/openo/msb/wrapper/serviceListener/MicroServiceChangeListener.java
+++ b/msb-core/apiroute/apiroute-service/src/main/java/org/openo/msb/wrapper/serviceListener/MicroServiceChangeListener.java
@@ -34,272 +34,258 @@ import org.slf4j.LoggerFactory;
public class MicroServiceChangeListener implements IMicroServiceChangeListener {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(MicroServiceChangeListener.class);
-
- @Override
- public void onSave(Service microServiceInfo,String serverPort) {
-
- if("UI".equals(microServiceInfo.getProtocol())){
- IuiRouteInfo iuiRouteInfo = this.buildIuiRouteInfo(microServiceInfo);
- if(null != iuiRouteInfo){
- IuiRouteServiceWrapper.getInstance().saveIuiRouteInstance(iuiRouteInfo);
- }
- }
- else{
-
- if(ifApiRouteUrl(microServiceInfo.getUrl())){
- ApiRouteInfo apiRouteInfo = this.buildApiRouteInfo(microServiceInfo);
- if(null != apiRouteInfo){
- ApiRouteServiceWrapper.getInstance().saveApiRouteInstance(apiRouteInfo,serverPort);
- }
- }
- else{
- CustomRouteInfo customRouteInfo = this.buildCustomRouteInfo(microServiceInfo);
- if(null != customRouteInfo){
- CustomRouteServiceWrapper.getInstance().saveCustomRouteInstance(customRouteInfo,serverPort);
- }
- }
- }
-
-
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(MicroServiceChangeListener.class);
+
+ @Override
+ public void onSave(Service microServiceInfo, String serverPort) {
+
+ if ("UI".equals(microServiceInfo.getProtocol())) {
+ IuiRouteInfo iuiRouteInfo = this.buildIuiRouteInfo(microServiceInfo);
+ if (null != iuiRouteInfo) {
+ IuiRouteServiceWrapper.getInstance().saveIuiRouteInstance(iuiRouteInfo);
+ }
+ } else if ("REST".equals(microServiceInfo.getProtocol())) {
+ ApiRouteInfo apiRouteInfo = this.buildApiRouteInfo(microServiceInfo);
+ if (null != apiRouteInfo) {
+ ApiRouteServiceWrapper.getInstance().saveApiRouteInstance(apiRouteInfo, serverPort);
+ }
+ } else if ("HTTP".equals(microServiceInfo.getProtocol())) {
+ CustomRouteInfo customRouteInfo = this.buildCustomRouteInfo(microServiceInfo);
+ if (null != customRouteInfo) {
+ CustomRouteServiceWrapper.getInstance()
+ .saveCustomRouteInstance(customRouteInfo, serverPort);
+ }
}
-
- @Override
- public void onChange(String serviceName, String version, Service microServiceInfo,String serverPort) {
-
- if("UI".equals(microServiceInfo.getProtocol())){
- if(serviceName.startsWith("iui_")||serviceName.startsWith("IUI_")){
- serviceName=serviceName.substring(4);
- }
- IuiRouteInfo iuiRouteInfo = this.buildIuiRouteInfo(microServiceInfo);
- if(null != iuiRouteInfo){
- IuiRouteServiceWrapper.getInstance().updateIuiRouteInstance(serviceName, iuiRouteInfo);
- }
- }
- else{
-
- if(ifApiRouteUrl(microServiceInfo.getUrl())){
- ApiRouteInfo apiRouteInfo = this.buildApiRouteInfo(microServiceInfo);
- if(null != apiRouteInfo){
- ApiRouteServiceWrapper.getInstance().updateApiRouteInstance(serviceName, version, apiRouteInfo,serverPort);
- }
- }
- else{
- if(!serviceName.startsWith("/")){
- serviceName="/"+serviceName;
- }
- CustomRouteInfo customRouteInfo = this.buildCustomRouteInfo(microServiceInfo);
- if(null != customRouteInfo){
- CustomRouteServiceWrapper.getInstance().updateCustomRouteInstance(serviceName,customRouteInfo,serverPort);
- }
- }
- }
-
+
+ }
+
+ @Override
+ public void onChange(String serviceName, String version, Service microServiceInfo,
+ String serverPort) {
+
+ if ("UI".equals(microServiceInfo.getProtocol())) {
+ if (serviceName.startsWith("iui_") || serviceName.startsWith("IUI_")) {
+ serviceName = serviceName.substring(4);
+ }
+ IuiRouteInfo iuiRouteInfo = this.buildIuiRouteInfo(microServiceInfo);
+ if (null != iuiRouteInfo) {
+ IuiRouteServiceWrapper.getInstance().updateIuiRouteInstance(serviceName, iuiRouteInfo);
+ }
+ } else if ("REST".equals(microServiceInfo.getProtocol())) {
+ ApiRouteInfo apiRouteInfo = this.buildApiRouteInfo(microServiceInfo);
+ if (null != apiRouteInfo) {
+ ApiRouteServiceWrapper.getInstance().updateApiRouteInstance(serviceName, version,
+ apiRouteInfo, serverPort);
+ }
+ } else if ("HTTP".equals(microServiceInfo.getProtocol())) {
+ if (!serviceName.startsWith("/")) {
+ serviceName = "/" + serviceName;
+ }
+ CustomRouteInfo customRouteInfo = this.buildCustomRouteInfo(microServiceInfo);
+ if (null != customRouteInfo) {
+ CustomRouteServiceWrapper.getInstance().updateCustomRouteInstance(serviceName,
+ customRouteInfo, serverPort);
+ }
}
-
- @Override
- public void onStatusChange(String serviceName,String url,String version,String protocol,String status) {
- if("UI".equals(protocol)){
-
- if(serviceName.startsWith("iui_")||serviceName.startsWith("IUI_")){
- serviceName=serviceName.substring(4);
- }
- IuiRouteServiceWrapper.getInstance().updateIuiRouteStatus(serviceName, status);
-
- }
- else{
- if(ifApiRouteUrl(url)){
- ApiRouteServiceWrapper.getInstance().updateApiRouteStatus(serviceName, version, status);
- }
- else{
- if(!serviceName.startsWith("/")){
- serviceName="/"+serviceName;
- }
- CustomRouteServiceWrapper.getInstance().updateCustomRouteStatus(serviceName, status);
- }
- }
-
-
+
+
+ }
+
+ @Override
+ public void onStatusChange(String serviceName, String url, String version, String protocol,
+ String status) {
+ if ("UI".equals(protocol)) {
+
+ if (serviceName.startsWith("iui_") || serviceName.startsWith("IUI_")) {
+ serviceName = serviceName.substring(4);
+ }
+ IuiRouteServiceWrapper.getInstance().updateIuiRouteStatus(serviceName, status);
+
+ } else if ("REST".equals(protocol)) {
+ ApiRouteServiceWrapper.getInstance().updateApiRouteStatus(serviceName, version, status);
+ } else if ("HTTP".equals(protocol)) {
+ if (!serviceName.startsWith("/")) {
+ serviceName = "/" + serviceName;
+ }
+ CustomRouteServiceWrapper.getInstance().updateCustomRouteStatus(serviceName, status);
}
- @Override
- public void onDelete(String serviceName,String url, String version,String protocol,String serverPort) {
-
- if("UI".equals(protocol)){
- if(serviceName.startsWith("iui_")||serviceName.startsWith("IUI_")){
- serviceName=serviceName.substring(4);
- }
- IuiRouteServiceWrapper.getInstance().deleteIuiRoute(serviceName, "*");
-
- }
- else{
- if(ifApiRouteUrl(url)){
- ApiRouteServiceWrapper.getInstance().deleteApiRoute(serviceName, version, "*",serverPort);
- }
- else{
-
-
- if(!serviceName.startsWith("/")){
- serviceName="/"+serviceName;
- }
-
- CustomRouteServiceWrapper.getInstance().deleteCustomRoute(serviceName, "*",serverPort);
- }
- }
+ }
+
+ @Override
+ public void onDelete(String serviceName, String url, String version, String protocol,
+ String serverPort) {
+
+ if ("UI".equals(protocol)) {
+ if (serviceName.startsWith("iui_") || serviceName.startsWith("IUI_")) {
+ serviceName = serviceName.substring(4);
+ }
+ IuiRouteServiceWrapper.getInstance().deleteIuiRoute(serviceName, "*");
+
+ } else if ("REST".equals(protocol)) {
+ ApiRouteServiceWrapper.getInstance().deleteApiRoute(serviceName, version, "*", serverPort);
+ } else if ("HTTP".equals(protocol)) {
+ if (!serviceName.startsWith("/")) {
+ serviceName = "/" + serviceName;
+ }
+
+ CustomRouteServiceWrapper.getInstance().deleteCustomRoute(serviceName, "*", serverPort);
}
-
-
- /**
- * @Title ifApiRouteUrl
- * @Description TODO(According to judge whether the API registration URL format)
- * @param url
- * @return
- * @return boolean
- */
- private boolean ifApiRouteUrl(String url){
- return RegExpTestUtil.apiRouteUrlRegExpTest(url);
+
+ }
+
+
+ /**
+ * @Title ifApiRouteUrl
+ * @Description TODO(According to judge whether the API registration URL format)
+ * @param url
+ * @return
+ * @return boolean
+ */
+ private boolean ifApiRouteUrl(String url) {
+ return RegExpTestUtil.apiRouteUrlRegExpTest(url);
+ }
+
+
+ /**
+ * From MicroServiceInfo to ApiRouteInfo
+ *
+ * @param microServiceInfo
+ * @return
+ */
+ private ApiRouteInfo buildApiRouteInfo(Service microServiceInfo) {
+
+ ApiRouteInfo apiRouteInfo = new ApiRouteInfo();
+ apiRouteInfo.setUrl(microServiceInfo.getUrl());
+
+ Set<Node> nodes = microServiceInfo.getNodes();
+ RouteServer[] routeServers = new RouteServer[nodes.size()];
+
+
+ int i = 0;
+ for (Node node : nodes) {
+ RouteServer routeServer = new RouteServer(node.getIp(), node.getPort());
+ routeServers[i] = routeServer;
+ i++;
}
-
-
- /**
- * From MicroServiceInfo to ApiRouteInfo
- * @param microServiceInfo
- * @return
- */
- private ApiRouteInfo buildApiRouteInfo(Service microServiceInfo){
-
- ApiRouteInfo apiRouteInfo = new ApiRouteInfo();
- apiRouteInfo.setUrl(microServiceInfo.getUrl());
-
- Set<Node> nodes=microServiceInfo.getNodes();
- RouteServer[] routeServers=new RouteServer[nodes.size()];
-
-
- int i=0;
- for(Node node:nodes){
- RouteServer routeServer = new RouteServer(node.getIp(),node.getPort());
- routeServers[i]=routeServer;
- i++;
- }
-
-
- apiRouteInfo.setServers(routeServers);
- String[] rangs=StringUtils.split(microServiceInfo.getVisualRange(), "|");
- if(RouteUtil.contain(rangs, "0")){
- apiRouteInfo.setVisualRange("0");
- }
- else{
- apiRouteInfo.setVisualRange("1");
- }
-
-
- if("ip_hash".equals(microServiceInfo.getLb_policy())){
- apiRouteInfo.setUseOwnUpstream("1");
+
+
+ apiRouteInfo.setServers(routeServers);
+ String[] rangs = StringUtils.split(microServiceInfo.getVisualRange(), "|");
+ if (RouteUtil.contain(rangs, "0")) {
+ apiRouteInfo.setVisualRange("0");
+ } else {
+ apiRouteInfo.setVisualRange("1");
}
-
-
-
- apiRouteInfo.setServiceName(microServiceInfo.getServiceName());
- apiRouteInfo.setVersion(microServiceInfo.getVersion());
- //TODO:set json and metrics defaultValue
- String version="".equals(microServiceInfo.getVersion())?"":"/"+microServiceInfo.getVersion();
- apiRouteInfo.setApiJson(microServiceInfo.getUrl()+"/swagger.json");
- apiRouteInfo.setMetricsUrl("/admin/metrics");
- return apiRouteInfo;
+
+
+ if ("ip_hash".equals(microServiceInfo.getLb_policy())) {
+ apiRouteInfo.setUseOwnUpstream("1");
}
-
-
- /**
- * From MicroServiceInfo to CustomRouteInfo
- * @param microServiceInfo
- * @return
- */
- private CustomRouteInfo buildCustomRouteInfo(Service microServiceInfo){
-
- CustomRouteInfo customRouteInfo = new CustomRouteInfo();
- customRouteInfo.setUrl(microServiceInfo.getUrl());
-
- Set<Node> nodes=microServiceInfo.getNodes();
- RouteServer[] routeServers=new RouteServer[nodes.size()];
-
-
- int i=0;
- for(Node node:nodes){
- RouteServer routeServer = new RouteServer(node.getIp(),node.getPort());
- routeServers[i]=routeServer;
- i++;
- }
-
- customRouteInfo.setServers(routeServers);
- String[] rangs=StringUtils.split(microServiceInfo.getVisualRange(), "|");
- if(RouteUtil.contain(rangs, "0")){
- customRouteInfo.setVisualRange("0");
- }
- else{
- customRouteInfo.setVisualRange("1");
- }
-
- if("ip_hash".equals(microServiceInfo.getLb_policy())){
- customRouteInfo.setUseOwnUpstream("1");
- }
-
- String serviceName;
- if(!microServiceInfo.getServiceName().startsWith("/")){
- serviceName="/"+microServiceInfo.getServiceName();
- }
- else{
- serviceName=microServiceInfo.getServiceName();
- }
- customRouteInfo.setServiceName(serviceName);
-
- return customRouteInfo;
+
+
+
+ apiRouteInfo.setServiceName(microServiceInfo.getServiceName());
+ apiRouteInfo.setVersion(microServiceInfo.getVersion());
+ // TODO:set json and metrics defaultValue
+ String version =
+ "".equals(microServiceInfo.getVersion()) ? "" : "/" + microServiceInfo.getVersion();
+ apiRouteInfo.setApiJson(microServiceInfo.getUrl() + "/swagger.json");
+ apiRouteInfo.setMetricsUrl("/admin/metrics");
+ return apiRouteInfo;
+ }
+
+
+ /**
+ * From MicroServiceInfo to CustomRouteInfo
+ *
+ * @param microServiceInfo
+ * @return
+ */
+ private CustomRouteInfo buildCustomRouteInfo(Service microServiceInfo) {
+
+ CustomRouteInfo customRouteInfo = new CustomRouteInfo();
+ customRouteInfo.setUrl(microServiceInfo.getUrl());
+
+ Set<Node> nodes = microServiceInfo.getNodes();
+ RouteServer[] routeServers = new RouteServer[nodes.size()];
+
+
+ int i = 0;
+ for (Node node : nodes) {
+ RouteServer routeServer = new RouteServer(node.getIp(), node.getPort());
+ routeServers[i] = routeServer;
+ i++;
}
-
-
- /**
- * From MicroServiceInfo to IuiRouteInfo
- * @param microServiceInfo
- * @return
- */
- private IuiRouteInfo buildIuiRouteInfo(Service microServiceInfo){
-
- IuiRouteInfo iuiRouteInfo = new IuiRouteInfo();
- iuiRouteInfo.setUrl(microServiceInfo.getUrl());
-
- Set<Node> nodes=microServiceInfo.getNodes();
- RouteServer[] routeServers=new RouteServer[nodes.size()];
-
-
- int i=0;
- for(Node node:nodes){
- RouteServer routeServer = new RouteServer(node.getIp(),node.getPort());
- routeServers[i]=routeServer;
- i++;
- }
-
- iuiRouteInfo.setServers(routeServers);
- String[] rangs=StringUtils.split(microServiceInfo.getVisualRange(), "|");
- if(RouteUtil.contain(rangs, "0")){
- iuiRouteInfo.setVisualRange("0");
- }
- else{
- iuiRouteInfo.setVisualRange("1");
- }
-
- if("ip_hash".equals(microServiceInfo.getLb_policy())){
- iuiRouteInfo.setUseOwnUpstream("1");
- }
-
- String serviceName=microServiceInfo.getServiceName();
- if(serviceName.startsWith("iui_")||serviceName.startsWith("IUI_")){
- serviceName=serviceName.substring(4);
- }
-
-
- iuiRouteInfo.setServiceName(serviceName);
-
- return iuiRouteInfo;
+
+ customRouteInfo.setServers(routeServers);
+ String[] rangs = StringUtils.split(microServiceInfo.getVisualRange(), "|");
+ if (RouteUtil.contain(rangs, "0")) {
+ customRouteInfo.setVisualRange("0");
+ } else {
+ customRouteInfo.setVisualRange("1");
}
+
+ if ("ip_hash".equals(microServiceInfo.getLb_policy())) {
+ customRouteInfo.setUseOwnUpstream("1");
+ }
+
+ String serviceName;
+ if (!microServiceInfo.getServiceName().startsWith("/")) {
+ serviceName = "/" + microServiceInfo.getServiceName();
+ } else {
+ serviceName = microServiceInfo.getServiceName();
+ }
+ customRouteInfo.setServiceName(serviceName);
+
+ return customRouteInfo;
+ }
+
+
+ /**
+ * From MicroServiceInfo to IuiRouteInfo
+ *
+ * @param microServiceInfo
+ * @return
+ */
+ private IuiRouteInfo buildIuiRouteInfo(Service microServiceInfo) {
+
+ IuiRouteInfo iuiRouteInfo = new IuiRouteInfo();
+ iuiRouteInfo.setUrl(microServiceInfo.getUrl());
+
+ Set<Node> nodes = microServiceInfo.getNodes();
+ RouteServer[] routeServers = new RouteServer[nodes.size()];
+
+
+ int i = 0;
+ for (Node node : nodes) {
+ RouteServer routeServer = new RouteServer(node.getIp(), node.getPort());
+ routeServers[i] = routeServer;
+ i++;
+ }
+
+ iuiRouteInfo.setServers(routeServers);
+ String[] rangs = StringUtils.split(microServiceInfo.getVisualRange(), "|");
+ if (RouteUtil.contain(rangs, "0")) {
+ iuiRouteInfo.setVisualRange("0");
+ } else {
+ iuiRouteInfo.setVisualRange("1");
+ }
+
+ if ("ip_hash".equals(microServiceInfo.getLb_policy())) {
+ iuiRouteInfo.setUseOwnUpstream("1");
+ }
+
+ String serviceName = microServiceInfo.getServiceName();
+ if (serviceName.startsWith("iui_") || serviceName.startsWith("IUI_")) {
+ serviceName = serviceName.substring(4);
+ }
+
+
+ iuiRouteInfo.setServiceName(serviceName);
+
+ return iuiRouteInfo;
+ }
}
diff --git a/msb-core/apiroute/apiroute-service/src/main/java/org/openo/msb/wrapper/util/MicroServiceDB.java b/msb-core/apiroute/apiroute-service/src/main/java/org/openo/msb/wrapper/util/MicroServiceDB.java
index 56c8aff..f2e2004 100644
--- a/msb-core/apiroute/apiroute-service/src/main/java/org/openo/msb/wrapper/util/MicroServiceDB.java
+++ b/msb-core/apiroute/apiroute-service/src/main/java/org/openo/msb/wrapper/util/MicroServiceDB.java
@@ -395,7 +395,7 @@ public class MicroServiceDB {
* @return
*/
private boolean isNeedNotifyByProtocol(String protocol) {
- return "UI".equalsIgnoreCase(protocol) ||("REST".equalsIgnoreCase(protocol));
+ return "UI".equalsIgnoreCase(protocol) || "REST".equalsIgnoreCase(protocol) || "HTTP".equalsIgnoreCase(protocol);
}
/**
diff --git a/msb-core/apiroute/apiroute-service/src/main/java/org/openo/msb/wrapper/util/RouteUtil.java b/msb-core/apiroute/apiroute-service/src/main/java/org/openo/msb/wrapper/util/RouteUtil.java
index e505e16..c987142 100644
--- a/msb-core/apiroute/apiroute-service/src/main/java/org/openo/msb/wrapper/util/RouteUtil.java
+++ b/msb-core/apiroute/apiroute-service/src/main/java/org/openo/msb/wrapper/util/RouteUtil.java
@@ -47,7 +47,7 @@ public class RouteUtil {
public static final String REQUEST_FAIL = "FAIL";
- public static String PROTOCOL_LIST="REST,UI,MQ,FTP,SNMP,TCP,UDP";
+ public static String PROTOCOL_LIST="REST,UI,HTTP,MQ,FTP,SNMP,TCP,UDP";
public static DiscoverInfo discoverInfo=new DiscoverInfo();
diff --git a/msb-core/apiroute/apiroute-service/src/main/resources/iui-route/js/routeController.js b/msb-core/apiroute/apiroute-service/src/main/resources/iui-route/js/routeController.js
index 90c8bbd..193ce45 100644
--- a/msb-core/apiroute/apiroute-service/src/main/resources/iui-route/js/routeController.js
+++ b/msb-core/apiroute/apiroute-service/src/main/resources/iui-route/js/routeController.js
@@ -35,7 +35,7 @@ var vm = avalon
},
showAPIType:"0",
showAPITypeName:[$.i18n.prop("org_openo_msb_route_swagger_type_predefined"),$.i18n.prop("org_openo_msb_route_swagger_type_custominput")],
- $msbProtocol :["REST","UI","MQ","FTP","SNMP","TCP","UDP"],
+ $msbProtocol :["REST","UI","HTTP","MQ","FTP","SNMP","TCP","UDP"],
$msbType:["UI","NAF","SAF"],
apiJson:{
local:"",