This is an automated email from the ASF dual-hosted git repository.

casion pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/linkis.git


The following commit(s) were added to refs/heads/master by this push:
     new 537f9a951 add dss gateway support parser.
537f9a951 is described below

commit 537f9a9519a3b5b24a4ebc42a1648922f454c0ad
Author: ahaoyao <[email protected]>
AuthorDate: Fri Jul 7 10:38:39 2023 +0800

    add dss gateway support parser.
---
 .../dss/parser/DSSGatewayConfiguration.scala       | 19 +++++++--
 .../gateway/dss/parser/DSSGatewayParser.scala      | 49 +++++++++++++++++-----
 .../gateway/dss/parser/DSSRouteLabelParser.scala   | 25 ++++++++++-
 3 files changed, 78 insertions(+), 15 deletions(-)

diff --git 
a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-server-support/src/main/scala/org/apache/linkis/gateway/dss/parser/DSSGatewayConfiguration.scala
 
b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-server-support/src/main/scala/org/apache/linkis/gateway/dss/parser/DSSGatewayConfiguration.scala
index 8dd859e02..937b0ddeb 100644
--- 
a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-server-support/src/main/scala/org/apache/linkis/gateway/dss/parser/DSSGatewayConfiguration.scala
+++ 
b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-server-support/src/main/scala/org/apache/linkis/gateway/dss/parser/DSSGatewayConfiguration.scala
@@ -20,12 +20,23 @@ package org.apache.linkis.gateway.dss.parser
 import org.apache.linkis.common.conf.CommonVars
 
 object DSSGatewayConfiguration {
-  val DSS_SPRING_NAME = CommonVars("wds.linkis.dss.name", "dss-server")
+  val DSS_SPRING_NAME: CommonVars[String] = CommonVars("wds.linkis.dss.name", 
"dss-server")
 
-  val DSS_URL_LABEL_PREFIX = CommonVars("wds.dss.gateway.url.prefix.name", 
"labels")
+  val DSS_URL_LABEL_PREFIX: CommonVars[String] =
+    CommonVars("wds.dss.gateway.url.prefix.name", "labels")
 
-  val DSS_URL_ROUTE_LABEL_PREFIX = 
CommonVars("wds.dss.gateway.url.prefix.name", "labelsRoute")
+  val DSS_URL_ROUTE_LABEL_PREFIX: CommonVars[String] =
+    CommonVars("wds.dss.gateway.url.prefix.name", "labelsRoute")
 
-  val DSS_URL_APPCONNS = CommonVars("wds.dss.gateway.url.appconns", "visualis")
+  val DSS_URL_APPCONNS: CommonVars[String] = 
CommonVars("wds.dss.gateway.url.appconns", "visualis")
+
+  val DSS_APPS_SERVER_OTHER_PREFIX: CommonVars[String] =
+    CommonVars("wds.dss.gateway.apps.server.other.prefix", 
"scriptis,apiservice,datapipe,guide")
+
+  val DSS_APPS_SERVER_DISTINCT_NAME: CommonVars[String] =
+    CommonVars("wds.dss.gateway.apps.server.distinct.name", "apps")
+
+  val DSS_APPS_SERVER_ISMERGE: CommonVars[Boolean] =
+    CommonVars("wds.dss.gateway.apps.server.ismerge", true)
 
 }
diff --git 
a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-server-support/src/main/scala/org/apache/linkis/gateway/dss/parser/DSSGatewayParser.scala
 
b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-server-support/src/main/scala/org/apache/linkis/gateway/dss/parser/DSSGatewayParser.scala
index 5fbe7b20d..edd3ed949 100644
--- 
a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-server-support/src/main/scala/org/apache/linkis/gateway/dss/parser/DSSGatewayParser.scala
+++ 
b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-server-support/src/main/scala/org/apache/linkis/gateway/dss/parser/DSSGatewayParser.scala
@@ -29,16 +29,15 @@ import 
org.apache.linkis.manager.label.builder.factory.LabelBuilderFactoryContex
 import org.apache.linkis.manager.label.entity.Label
 import org.apache.linkis.manager.label.entity.route.RouteLabel
 import org.apache.linkis.protocol.constants.TaskConstant
+import org.apache.linkis.protocol.utils.ZuulEntranceUtils
 import org.apache.linkis.rpc.sender.SpringCloudFeignConfigurationCache
-import org.apache.linkis.server.BDPJettyServerHelper
+import org.apache.linkis.server.{toScalaBuffer, BDPJettyServerHelper}
 
 import org.springframework.stereotype.Component
 
 import java.util
 import java.util.Locale
 
-import scala.collection.JavaConverters._
-
 @Component
 class DSSGatewayParser extends AbstractGatewayParser {
 
@@ -71,12 +70,28 @@ class DSSGatewayParser extends AbstractGatewayParser {
   override def parse(gatewayContext: GatewayContext): Unit =
     gatewayContext.getRequest.getRequestURI match {
 
+      case DSSGatewayParser.DSS_URL_FLOW_QUERY_PREFIX(version, execId, _) =>
+        // must put it before DSS_URL_REGEX(_, _, _), because this match was 
included in DSS_URL_REGEX(_, _, _)
+        if (sendResponseWhenNotMatchVersion(gatewayContext, version)) return
+        val serviceInstances = 
ZuulEntranceUtils.parseServiceInstanceByExecID(execId)
+        gatewayContext.getGatewayRoute.setServiceInstance(serviceInstances(0))
       case DSSGatewayParser.DSS_URL_REGEX(version, firstName, secondName) =>
         if (sendResponseWhenNotMatchVersion(gatewayContext, version)) return
         var tmpServerName = "dss-" + firstName + "-" + secondName + "-server"
         tmpServerName = getServiceNameFromLabel(gatewayContext, tmpServerName)
+        // 
apiservice,datapipe,scriptis和guide服务合并到dss-apps-server,其中的接口需要转发到apps服务
+        var tmpFirstName = firstName
+        if (
+            DSSGatewayConfiguration.DSS_APPS_SERVER_ISMERGE.getValue &&
+            DSSGatewayConfiguration.DSS_APPS_SERVER_OTHER_PREFIX.getValue
+              .split(",")
+              .contains(firstName)
+        ) {
+          tmpFirstName =
+            DSSGatewayConfiguration.DSS_APPS_SERVER_DISTINCT_NAME.getValue + 
"/" + firstName
+        }
         val serviceName: Option[String] =
-          findCommonService("dss/" + firstName + "/" + secondName, 
tmpServerName)
+          findCommonService("dss/" + tmpFirstName + "/" + secondName, 
tmpServerName)
         if (serviceName.isDefined) {
           
gatewayContext.getGatewayRoute.setServiceInstance(ServiceInstance(serviceName.get,
 null))
         } else {
@@ -91,7 +106,18 @@ class DSSGatewayParser extends AbstractGatewayParser {
         if (sendResponseWhenNotMatchVersion(gatewayContext, version)) return
         var tmpServerName = "dss-" + firstName + "-server"
         tmpServerName = getServiceNameFromLabel(gatewayContext, tmpServerName)
-        val serviceName: Option[String] = findCommonService("dss/" + 
firstName, tmpServerName)
+        // 
apiservice,datapipe,scriptis和guide服务合并到dss-apps-server,其中的接口需要转发到apps服务
+        var tmpFirstName = firstName
+        if (
+            DSSGatewayConfiguration.DSS_APPS_SERVER_ISMERGE.getValue &&
+            DSSGatewayConfiguration.DSS_APPS_SERVER_OTHER_PREFIX.getValue
+              .split(",")
+              .contains(firstName)
+        ) {
+          tmpFirstName =
+            DSSGatewayConfiguration.DSS_APPS_SERVER_DISTINCT_NAME.getValue + 
"/" + firstName
+        }
+        val serviceName: Option[String] = findCommonService("dss/" + 
tmpFirstName, tmpServerName)
         if (serviceName.isDefined) {
           
gatewayContext.getGatewayRoute.setServiceInstance(ServiceInstance(serviceName.get,
 null))
         } else {
@@ -134,7 +160,7 @@ class DSSGatewayParser extends AbstractGatewayParser {
     logger.info(
       "Get ServiceName From  Label and method is " + 
gatewayContext.getRequest.getMethod.toString + ",and urlLabels is " + 
requestUrlLabels
     )
-    val requestMethod = 
gatewayContext.getRequest.getMethod.toLowerCase(Locale.getDefault())
+    val requestMethod = 
gatewayContext.getRequest.getMethod.toLowerCase(Locale.ROOT)
     if (
         requestUrlLabels == null && (requestMethod
           .equals("post") || requestMethod.equals("put") || 
requestMethod.equals("delete"))
@@ -153,7 +179,7 @@ class DSSGatewayParser extends AbstractGatewayParser {
             case map: util.Map[String, Any] => 
labelBuilderFactory.getLabels(map.asInstanceOf)
             case _ => new util.ArrayList[Label[_]]()
           }
-          labels.asScala
+          labels
             .filter(label => label.isInstanceOf[RouteLabel])
             .foreach(label => {
               routeLabelList.add(label.asInstanceOf[RouteLabel])
@@ -161,7 +187,7 @@ class DSSGatewayParser extends AbstractGatewayParser {
 
         case _ => null
       }
-      val labelNameList = routeLabelList.asScala.map(routeLabel => 
routeLabel.getStringValue).toList
+      val labelNameList = routeLabelList.map(routeLabel => 
routeLabel.getStringValue).toList
       if (labelNameList != null && labelNameList.size > 0) {
         genServiceNameByDSSLabel(labelNameList, tmpServiceName)
       } else if (null != requestUrlLabels) {
@@ -213,7 +239,7 @@ class DSSGatewayParser extends AbstractGatewayParser {
   ): Option[String] = {
     val findIt: (String => Boolean) => Option[String] = op => {
       val services =
-        
SpringCloudFeignConfigurationCache.getDiscoveryClient.getServices.asScala.filter(op).toList
+        
SpringCloudFeignConfigurationCache.getDiscoveryClient.getServices.filter(op).toList
       if (services.length == 1) Some(services.head)
       else if (services.length > 1) tooManyDeal(services)
       else None
@@ -224,7 +250,7 @@ class DSSGatewayParser extends AbstractGatewayParser {
     val findMostCorrect: (String => (String, Int)) => Option[String] = { op =>
       {
         val serviceMap =
-          
SpringCloudFeignConfigurationCache.getDiscoveryClient.getServices.asScala.map(op).toMap
+          
SpringCloudFeignConfigurationCache.getDiscoveryClient.getServices.map(op).toMap
         var count = 0
         var retService: Option[String] = None
         serviceMap.foreach { case (k, v) =>
@@ -257,4 +283,7 @@ object DSSGatewayParser {
   val APPCONN_HEADER = normalPath(API_URL_PREFIX) + 
"rest_[a-zA-Z][a-zA-Z_0-9]*/(v\\d+)/([^/]+)/"
   val APPCONN_URL_DEFAULT_REGEX = (APPCONN_HEADER + "([^/]+).+").r
 
+  val DSS_URL_FLOW_QUERY_PREFIX =
+    (DSS_HEADER + "flow/entrance/" + "([^/]+)/" + "(status|execution|kill)").r
+
 }
diff --git 
a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-server-support/src/main/scala/org/apache/linkis/gateway/dss/parser/DSSRouteLabelParser.scala
 
b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-server-support/src/main/scala/org/apache/linkis/gateway/dss/parser/DSSRouteLabelParser.scala
index 48ec059ca..e8cdc3e21 100644
--- 
a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-server-support/src/main/scala/org/apache/linkis/gateway/dss/parser/DSSRouteLabelParser.scala
+++ 
b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-server-support/src/main/scala/org/apache/linkis/gateway/dss/parser/DSSRouteLabelParser.scala
@@ -29,7 +29,30 @@ import java.util
 class DSSRouteLabelParser extends RouteLabelParser {
 
   override def parse(gatewayContext: GatewayContext): util.List[RouteLabel] = {
-    new util.ArrayList[RouteLabel]()
+    val routeLabelList = new util.ArrayList[RouteLabel]()
+    var requestLabels = gatewayContext.getRequest.getQueryParams
+      .getOrDefault(DSSGatewayConfiguration.DSS_URL_LABEL_PREFIX.getValue, 
null)
+    if (requestLabels == null) {
+      requestLabels = gatewayContext.getRequest.getQueryParams
+        
.getOrDefault(DSSGatewayConfiguration.DSS_URL_ROUTE_LABEL_PREFIX.getValue, null)
+    }
+    if (null != requestLabels && requestLabels.size > 0) {
+      val labelNameList = requestLabels(0).replace(" ", "").split(",").toList
+      if (labelNameList.size > 0) labelNameList.foreach(labelName => {
+        val routeLabel = new RouteLabel
+        routeLabel.setRoutePath(labelName)
+      })
+    }
+    if (routeLabelList.isEmpty) {
+      val requestBody = Option(gatewayContext.getRequest.getRequestBody)
+      requestBody match {
+        case Some(body) =>
+          if (body.contains("form-data")) {} else {}
+        case _ => null
+      }
+    }
+
+    routeLabelList
   }
 
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to