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

peacewong pushed a commit to branch dev-1.3.2
in repository https://gitbox.apache.org/repos/asf/incubator-linkis.git


The following commit(s) were added to refs/heads/dev-1.3.2 by this push:
     new 3bc495773 Exclude entries for offline tags (#3834)
3bc495773 is described below

commit 3bc49577342d4424ce26ba74e6e4461ad8aa77f4
Author: 成彬彬 <[email protected]>
AuthorDate: Fri Nov 18 17:50:08 2022 +0800

    Exclude entries for offline tags (#3834)
    
    * #3496
    1. linkis-entrance - refactor method 'getUserMAxRunmningJobs' to exclude 
offlining entrance isntances.
---
 .../entrance/restful/EntranceLabelRestfulApi.java  |  3 ++-
 .../entrance/scheduler/EntranceGroupFactory.scala  | 30 ++++++++++++++++++++--
 .../manager/label/constant/LabelValueConstant.java | 23 +++++++++++++++++
 .../label/client/InstanceLabelClient.scala         |  3 +++
 4 files changed, 56 insertions(+), 3 deletions(-)

diff --git 
a/linkis-computation-governance/linkis-entrance/src/main/java/org/apache/linkis/entrance/restful/EntranceLabelRestfulApi.java
 
b/linkis-computation-governance/linkis-entrance/src/main/java/org/apache/linkis/entrance/restful/EntranceLabelRestfulApi.java
index d10d44e64..c54038ed6 100644
--- 
a/linkis-computation-governance/linkis-entrance/src/main/java/org/apache/linkis/entrance/restful/EntranceLabelRestfulApi.java
+++ 
b/linkis-computation-governance/linkis-entrance/src/main/java/org/apache/linkis/entrance/restful/EntranceLabelRestfulApi.java
@@ -20,6 +20,7 @@ package org.apache.linkis.entrance.restful;
 import org.apache.linkis.common.conf.Configuration;
 import org.apache.linkis.instance.label.client.InstanceLabelClient;
 import org.apache.linkis.manager.label.constant.LabelKeyConstant;
+import org.apache.linkis.manager.label.constant.LabelValueConstant;
 import org.apache.linkis.protocol.label.InsLabelRefreshRequest;
 import org.apache.linkis.rpc.Sender;
 import org.apache.linkis.server.Message;
@@ -71,7 +72,7 @@ public class EntranceLabelRestfulApi {
     public Message updateRouteLabel(HttpServletRequest req) {
         Map<String, Object> labels = new HashMap<String, Object>();
         logger.info("Prepare to modify the routelabel of entry to offline");
-        labels.put(LabelKeyConstant.ROUTE_KEY, "offline");
+        labels.put(LabelKeyConstant.ROUTE_KEY, 
LabelValueConstant.OFFLINE_VALUE);
         InsLabelRefreshRequest insLabelRefreshRequest = new 
InsLabelRefreshRequest();
         insLabelRefreshRequest.setLabels(labels);
         
insLabelRefreshRequest.setServiceInstance(Sender.getThisServiceInstance());
diff --git 
a/linkis-computation-governance/linkis-entrance/src/main/scala/org/apache/linkis/entrance/scheduler/EntranceGroupFactory.scala
 
b/linkis-computation-governance/linkis-entrance/src/main/scala/org/apache/linkis/entrance/scheduler/EntranceGroupFactory.scala
index c6e7f632c..313275074 100644
--- 
a/linkis-computation-governance/linkis-entrance/src/main/scala/org/apache/linkis/entrance/scheduler/EntranceGroupFactory.scala
+++ 
b/linkis-computation-governance/linkis-entrance/src/main/scala/org/apache/linkis/entrance/scheduler/EntranceGroupFactory.scala
@@ -17,6 +17,7 @@
 
 package org.apache.linkis.entrance.scheduler
 
+import org.apache.linkis.common.ServiceInstance
 import org.apache.linkis.common.conf.{CommonVars, Configuration}
 import org.apache.linkis.common.utils.{Logging, Utils}
 import org.apache.linkis.entrance.conf.EntranceConfiguration
@@ -27,12 +28,16 @@ import org.apache.linkis.governance.common.protocol.conf.{
   RequestQueryEngineConfigWithGlobalConfig,
   ResponseQueryConfig
 }
+import org.apache.linkis.instance.label.client.InstanceLabelClient
+import 
org.apache.linkis.manager.label.builder.factory.LabelBuilderFactoryContext
+import org.apache.linkis.manager.label.constant.{LabelKeyConstant, 
LabelValueConstant}
 import org.apache.linkis.manager.label.entity.Label
 import org.apache.linkis.manager.label.entity.engine.{
   ConcurrentEngineConnLabel,
   EngineTypeLabel,
   UserCreatorLabel
 }
+import org.apache.linkis.manager.label.entity.route.RouteLabel
 import org.apache.linkis.manager.label.utils.LabelUtil
 import org.apache.linkis.protocol.constants.TaskConstant
 import org.apache.linkis.protocol.utils.TaskUtils
@@ -157,12 +162,33 @@ class EntranceGroupFactory extends GroupFactory with 
Logging {
   private def getUserMaxRunningJobs(keyAndValue: util.Map[String, String]): 
Int = {
     var userDefinedRunningJobs = 
EntranceConfiguration.WDS_LINKIS_INSTANCE.getValue(keyAndValue)
     var entranceNum = 
Sender.getInstances(Sender.getThisServiceInstance.getApplicationName).length
+    val labelList = new util.ArrayList[Label[_]]()
+    val offlineRouteLabel = LabelBuilderFactoryContext.getLabelBuilderFactory
+      .createLabel[RouteLabel](LabelKeyConstant.ROUTE_KEY, 
LabelValueConstant.OFFLINE_VALUE)
+    labelList.add(offlineRouteLabel)
+    var offlineIns: Array[ServiceInstance] = null
+    Utils.tryAndWarn {
+      offlineIns = InstanceLabelClient.getInstance
+        .getInstanceFromLabel(labelList)
+        .asScala
+        .filter(l =>
+          null != l && l.getApplicationName
+            .equalsIgnoreCase(Sender.getThisServiceInstance.getApplicationName)
+        )
+        .toArray
+    }
+    if (null != offlineIns) {
+      logger.info(s"There are ${offlineIns.length} offlining instance.")
+      entranceNum = entranceNum - offlineIns.length
+    }
     /*
     Sender.getInstances may get 0 instances due to cache in Sender. So this 
instance is the one instance.
      */
-    if (0 == entranceNum) {
+    if (0 >= entranceNum) {
+      logger.error(
+        s"Got ${entranceNum} 
${Sender.getThisServiceInstance.getApplicationName} instances."
+      )
       entranceNum = 1
-      logger.error(s"Got 0 ${Sender.getThisServiceInstance.getApplicationName} 
instances.")
     }
     Math.max(
       EntranceConfiguration.ENTRANCE_INSTANCE_MIN.getValue,
diff --git 
a/linkis-computation-governance/linkis-manager/linkis-label-common/src/main/java/org/apache/linkis/manager/label/constant/LabelValueConstant.java
 
b/linkis-computation-governance/linkis-manager/linkis-label-common/src/main/java/org/apache/linkis/manager/label/constant/LabelValueConstant.java
new file mode 100644
index 000000000..cc62921c8
--- /dev/null
+++ 
b/linkis-computation-governance/linkis-manager/linkis-label-common/src/main/java/org/apache/linkis/manager/label/constant/LabelValueConstant.java
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.linkis.manager.label.constant;
+
+public class LabelValueConstant {
+
+  public static final String OFFLINE_VALUE = "offline";
+}
diff --git 
a/linkis-public-enhancements/linkis-instance-label/linkis-instance-label-client/src/main/scala/org/apache/linkis/instance/label/client/InstanceLabelClient.scala
 
b/linkis-public-enhancements/linkis-instance-label/linkis-instance-label-client/src/main/scala/org/apache/linkis/instance/label/client/InstanceLabelClient.scala
index d1f17480f..efaf43818 100644
--- 
a/linkis-public-enhancements/linkis-instance-label/linkis-instance-label-client/src/main/scala/org/apache/linkis/instance/label/client/InstanceLabelClient.scala
+++ 
b/linkis-public-enhancements/linkis-instance-label/linkis-instance-label-client/src/main/scala/org/apache/linkis/instance/label/client/InstanceLabelClient.scala
@@ -85,6 +85,9 @@ class InstanceLabelClient extends Logging {
       request.setLabels(labelMap.asInstanceOf[util.HashMap[String, Object]])
       Sender.getSender(PUBLIC_SERVICE_APPLICATION_NAME.getValue).ask(request) 
match {
         case resp: LabelInsQueryResponse =>
+          if (null == resp.getInsList || resp.getInsList.isEmpty) {
+            return new util.ArrayList[ServiceInstance]()
+          }
           if (resp.getInsList.size() != 1) {
             logger.warn(
               s"Instance num ${resp.getInsList.size()} with labels 
${BDPJettyServerHelper.gson.toJson(labelMap)} is not single one."


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

Reply via email to