You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@linkis.apache.org by al...@apache.org on 2022/03/04 06:36:39 UTC
[incubator-linkis] 12/13: Optimize code
This is an automated email from the ASF dual-hosted git repository.
alexkun pushed a commit to branch dev-1.1.1
in repository https://gitbox.apache.org/repos/asf/incubator-linkis.git
commit 5ba149118a4767e3c23fcc0b2ceece665eb8befa
Author: peacewong <wp...@gmail.com>
AuthorDate: Thu Mar 3 21:12:27 2022 +0800
Optimize code
---
.../ujes/route/AbstractLabelGatewayRouter.scala | 30 ++++++++--------------
1 file changed, 10 insertions(+), 20 deletions(-)
diff --git a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-server-support/src/main/scala/org/apache/linkis/gateway/ujes/route/AbstractLabelGatewayRouter.scala b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-server-support/src/main/scala/org/apache/linkis/gateway/ujes/route/AbstractLabelGatewayRouter.scala
index b02194a..916fb02 100644
--- a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-server-support/src/main/scala/org/apache/linkis/gateway/ujes/route/AbstractLabelGatewayRouter.scala
+++ b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-server-support/src/main/scala/org/apache/linkis/gateway/ujes/route/AbstractLabelGatewayRouter.scala
@@ -17,17 +17,16 @@
package org.apache.linkis.gateway.ujes.route
-import java.util
-
+import org.apache.commons.lang.StringUtils
import org.apache.linkis.common.ServiceInstance
import org.apache.linkis.common.utils.Logging
-import org.apache.linkis.gateway.exception.GatewayErrorException
import org.apache.linkis.gateway.http.GatewayContext
import org.apache.linkis.gateway.route.AbstractGatewayRouter
import org.apache.linkis.instance.label.service.InsLabelService
import org.apache.linkis.manager.label.entity.route.RouteLabel
+
+import java.util
import javax.annotation.Resource
-import org.apache.commons.lang.StringUtils
abstract class AbstractLabelGatewayRouter extends AbstractGatewayRouter with Logging {
@@ -43,31 +42,22 @@ abstract class AbstractLabelGatewayRouter extends AbstractGatewayRouter with Log
override def route(gatewayContext: GatewayContext): ServiceInstance = {
- val routeLabels: Option[util.List[RouteLabel]] = Option(parseToRouteLabels(gatewayContext))
+ val routeLabels: util.List[RouteLabel] = parseToRouteLabels(gatewayContext)
val serviceInstance: ServiceInstance = gatewayContext.getGatewayRoute.getServiceInstance
if (StringUtils.isNotBlank(serviceInstance.getApplicationName) && StringUtils.isNotBlank(serviceInstance.getInstance)) {
- //如果前面已经确认instance则跳过
return serviceInstance
}
- val candidateServices = routeLabels match {
- case _ if routeLabels.isDefined && !routeLabels.get.isEmpty =>
- gatewayContext.getGatewayRoute.setLabels(routeLabels.get)
- Option(insLabelService.searchInstancesByLabels(routeLabels.get))
- case _ =>
- if (null != serviceInstance) {
- logger.info("Cannot find route labels, now to find the default [" + serviceInstance.getApplicationName + "] service instances")
- //Use application name to query service instances
- Option(insLabelService.searchUnRelateInstances(serviceInstance))
- } else {
- throw new GatewayErrorException(11011, s"Cannot route the service instance without application name and labels")
- }
+ if (null == routeLabels || routeLabels.isEmpty) {
+ return null
}
- val canSelectInstances = if (candidateServices.isEmpty || candidateServices.get.size <= 0) {
+
+ val candidateServices = insLabelService.searchInstancesByLabels(routeLabels)
+ val canSelectInstances = if (null == candidateServices || candidateServices.isEmpty) {
val labelRelatedInstances = Option(insLabelService.searchLabelRelatedInstances(serviceInstance))
removeAllFromRegistry(serviceInstance.getApplicationName,
labelRelatedInstances.getOrElse(new util.ArrayList[ServiceInstance]()))
} else {
- candidateServices.get
+ candidateServices
}
selectInstance(gatewayContext, canSelectInstances)
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@linkis.apache.org
For additional commands, e-mail: commits-help@linkis.apache.org