You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@linkis.apache.org by pe...@apache.org on 2022/06/24 06:21:24 UTC

[incubator-linkis] 02/03: fix: deprecated JavaLog and Logging's method, fix InstanceResource code not reach pr

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

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

commit cebc771ae297793ccb133649ee7c520d80f97ade
Author: Jack Xu <xu...@126.com>
AuthorDate: Thu Jun 23 10:42:46 2022 +0800

    fix: deprecated JavaLog and Logging's method, fix InstanceResource code not reach pr
---
 .../org/apache/linkis/common/utils/JavaLog.scala   | 73 +++++-----------------
 .../org/apache/linkis/common/utils/Logging.scala   | 13 +++-
 .../apache/linkis/common/utils/VariableUtils.scala | 11 ++--
 .../httpclient/discovery/AbstractDiscovery.scala   | 24 +++----
 .../linkis/mybatis/conf/MybatisConfiguration.java  | 22 +++----
 .../rm/service/RequestResourceService.scala        |  4 +-
 .../manager/common/entity/resource/Resource.scala  |  2 +-
 .../manager/common/utils/ResourceUtils.scala       | 39 ++++++------
 8 files changed, 78 insertions(+), 110 deletions(-)

diff --git a/linkis-commons/linkis-common/src/main/scala/org/apache/linkis/common/utils/JavaLog.scala b/linkis-commons/linkis-common/src/main/scala/org/apache/linkis/common/utils/JavaLog.scala
index c9787b7b2..b1352ea65 100644
--- a/linkis-commons/linkis-common/src/main/scala/org/apache/linkis/common/utils/JavaLog.scala
+++ b/linkis-commons/linkis-common/src/main/scala/org/apache/linkis/common/utils/JavaLog.scala
@@ -14,76 +14,33 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
- 
+
 package org.apache.linkis.common.utils
 
 import org.slf4j.LoggerFactory
 
-
+/**
+ * every define the logger by self
+ * this class is deprecated
+ */
+@deprecated("do not use this class for log")
 class JavaLog {
-  //  if(!JavaLog.initialized) {
-  //    JavaLog.initLock synchronized {
-  //      if(!JavaLog.initialized) {
-  //        JavaLog.initializeLogging
-  //        JavaLog.initialized = true
-  //      }
-  //    }
-  //  }
+
+
   protected implicit lazy val logger = LoggerFactory.getLogger(getClass)
 
   def debug(message: Object): Unit = if (logger.isDebugEnabled && message != null) logger.debug(message.toString)
 
-  def info(message: Object): Unit = if(logger.isInfoEnabled && message != null) logger.info(message.toString)
+  def info(message: Object): Unit = if (logger.isInfoEnabled && message != null) logger.info(message.toString)
 
-  def info(message: Object, t: Throwable): Unit = if(logger.isInfoEnabled && message != null) logger.info(message.toString, t)
+  def info(message: Object, t: Throwable): Unit = if (logger.isInfoEnabled && message != null) logger.info(message.toString, t)
 
-  def warn(message: Object): Unit = if(logger.isWarnEnabled && message != null) logger.warn(message.toString)
+  def warn(message: Object): Unit = if (logger.isWarnEnabled && message != null) logger.warn(message.toString)
 
-  def warn(message: Object, t: Throwable): Unit = if(logger.isWarnEnabled && message != null) logger.warn(message.toString, t)
+  def warn(message: Object, t: Throwable): Unit = if (logger.isWarnEnabled && message != null) logger.warn(message.toString, t)
 
-  def error(message: Object): Unit = if(logger.isErrorEnabled && message != null) logger.error(message.toString)
+  def error(message: Object): Unit = if (logger.isErrorEnabled && message != null) logger.error(message.toString)
 
-  def error(message: Object, t: Throwable): Unit = if(logger.isErrorEnabled && message != null) logger.error(message.toString, t)
+  def error(message: Object, t: Throwable): Unit = if (logger.isErrorEnabled && message != null) logger.error(message.toString, t)
 
-}
-//private[utils] object JavaLog {
-//  @volatile private var initialized = false
-//  private val initLock = new Array[Byte](0)
-//  Utils.tryQuietly {
-//    val bridgeClass = Class.forName("org.slf4j.bridge.SLF4JBridgeHandler")
-//    bridgeClass.getMethod("removeHandlersForRootLogger").invoke(null)
-//    val installed = bridgeClass.getMethod("isInstalled").invoke(null).asInstanceOf[Boolean]
-//    if (!installed) {
-//      bridgeClass.getMethod("install").invoke(null)
-//    }
-//  }
-//  if(!initialized) {
-//    initLock synchronized {
-//      if(!initialized) {
-//        initializeLogging
-//        initialized = true
-//      }
-//    }
-//  }
-//  private def initializeLogging: Unit = {
-//    val binderClass = StaticLoggerBinder.getSingleton.getLoggerFactoryClassStr
-//    val usingLog4j12 = "org.slf4j.impl.Log4jLoggerFactory".equals(binderClass)
-//    if (usingLog4j12) {
-//      val log4j12Initialized = LogManager.getRootLogger.getAllAppenders.hasMoreElements
-//      if (!log4j12Initialized) {
-//        val defaultLogProps = System.getProperty("log4j.configuration", "log4j.properties")
-//        var url = Thread.currentThread.getContextClassLoader.getResource(defaultLogProps)
-//        if(url == null) {
-//          if(!new File(defaultLogProps).exists()) {
-//            System.err.println(s"BDP Server was unable to load $defaultLogProps.")
-//            return
-//          }
-//          url = if(defaultLogProps.startsWith("file:/")) new URL(defaultLogProps)
-//            else new URL("file:///" + defaultLogProps)
-//        }
-//        PropertyConfigurator.configure(url)
-//        System.err.println(s"Using BDP Server's log4j profile: $defaultLogProps.")
-//      }
-//    }
-//  }
-//}
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/linkis-commons/linkis-common/src/main/scala/org/apache/linkis/common/utils/Logging.scala b/linkis-commons/linkis-common/src/main/scala/org/apache/linkis/common/utils/Logging.scala
index a761df81b..0983d160a 100644
--- a/linkis-commons/linkis-common/src/main/scala/org/apache/linkis/common/utils/Logging.scala
+++ b/linkis-commons/linkis-common/src/main/scala/org/apache/linkis/common/utils/Logging.scala
@@ -19,45 +19,56 @@ package org.apache.linkis.common.utils
 
 import org.slf4j.LoggerFactory
 
-
+/**
+ * use the class's method will miss the real info line number, so deprecated all the method
+ * and this trait will be deprecated too
+ */
 trait Logging {
 
   protected lazy implicit val logger = LoggerFactory.getLogger(getClass)
 
+  @deprecated
   def trace(message: => String): Unit = {
     if (logger.isTraceEnabled) {
       logger.trace(message)
     }
   }
 
+  @deprecated
   def debug(message: => String): Unit = {
     if (logger.isDebugEnabled) {
       logger.debug(message)
     }
   }
 
+  @deprecated
   def info(message: => String): Unit = {
     if (logger.isInfoEnabled) {
       logger.info(message)
     }
   }
 
+  @deprecated
   def info(message: => String, t: Throwable): Unit = {
     logger.info(message, t)
   }
 
+  @deprecated
   def warn(message: => String): Unit = {
     logger.warn(message)
   }
 
+  @deprecated
   def warn(message: => String, t: Throwable): Unit = {
     logger.warn(message, t)
   }
 
+  @deprecated
   def error(message: => String, t: Throwable): Unit = {
     logger.error(message, t)
   }
 
+  @deprecated
   def error(message: => String): Unit = {
     logger.error(message)
   }
diff --git a/linkis-commons/linkis-common/src/main/scala/org/apache/linkis/common/utils/VariableUtils.scala b/linkis-commons/linkis-common/src/main/scala/org/apache/linkis/common/utils/VariableUtils.scala
index 926ecc796..4c7de924b 100644
--- a/linkis-commons/linkis-common/src/main/scala/org/apache/linkis/common/utils/VariableUtils.scala
+++ b/linkis-commons/linkis-common/src/main/scala/org/apache/linkis/common/utils/VariableUtils.scala
@@ -217,18 +217,18 @@ object VariableUtils extends Logging {
         val rightValue = ma.group(3)
 
         if (name == null || name.trim.isEmpty) {
-           throw new LinkisCommonErrorException(20041, s"[$str] replaced var is null")
+          throw new LinkisCommonErrorException(20041, s"[$str] replaced var is null")
         } else {
           var expression = name.trim
           val varType = nameAndType.get(name.trim).orNull
           if (varType == null) {
-            warn(s"Use undefined variables or use the set method: [$str](使用了未定义的变量或者使用了set方式:[$str])")
+            logger.warn(s"Use undefined variables or use the set method: [$str](使用了未定义的变量或者使用了set方式:[$str])")
             parseCode ++= codes(i - 1) ++ str
           } else {
             var res: String = varType.getValue
             if (signal != null && !signal.trim.isEmpty) {
               if (rightValue == null || rightValue.trim.isEmpty) {
-                 throw new LinkisCommonErrorException(20042, s"[$str] expression is not right, please check")
+                throw new LinkisCommonErrorException(20042, s"[$str] expression is not right, please check")
               } else {
                 expression = expression + "_" + signal.trim + "_" + rightValue.trim
                 val rightToken = rightValue.trim
@@ -241,7 +241,7 @@ object VariableUtils extends Logging {
               }
             }
             if (!expressionCache.contains(expression)) {
-              info(s"Variable expression [$str] = $res(变量表达式[$str] = $res)")
+              logger.info(s"Variable expression [$str] = $res(变量表达式[$str] = $res)")
               expressionCache += expression
             }
             parseCode ++= codes(i - 1) ++ res
@@ -257,7 +257,6 @@ object VariableUtils extends Logging {
   }
 
 
-
   /**
    * Get user-defined variables and values
    *
@@ -302,7 +301,7 @@ object VariableUtils extends Logging {
             }
           }
         case errRegex() =>
-          warn(s"The variable definition is incorrect:$str,if it is not used, it will not run the error, but it is recommended to use the correct specification to define")
+          logger.warn(s"The variable definition is incorrect:$str,if it is not used, it will not run the error, but it is recommended to use the correct specification to define")
         case _ =>
       }
     }
diff --git a/linkis-commons/linkis-httpclient/src/main/scala/org/apache/linkis/httpclient/discovery/AbstractDiscovery.scala b/linkis-commons/linkis-httpclient/src/main/scala/org/apache/linkis/httpclient/discovery/AbstractDiscovery.scala
index 414e72789..01b4be66b 100644
--- a/linkis-commons/linkis-httpclient/src/main/scala/org/apache/linkis/httpclient/discovery/AbstractDiscovery.scala
+++ b/linkis-commons/linkis-httpclient/src/main/scala/org/apache/linkis/httpclient/discovery/AbstractDiscovery.scala
@@ -17,17 +17,17 @@
 
 package org.apache.linkis.httpclient.discovery
 
-import java.io.Closeable
-import java.net.ConnectException
-import java.util
-import java.util.concurrent.ScheduledFuture
 import org.apache.commons.lang3.StringUtils
+import org.apache.http.HttpResponse
 import org.apache.linkis.common.utils.{Logging, Utils}
 import org.apache.linkis.httpclient.Client
-import org.apache.linkis.httpclient.exception.DiscoveryException
-import org.apache.http.HttpResponse
 import org.apache.linkis.httpclient.config.HttpClientConstant
+import org.apache.linkis.httpclient.exception.DiscoveryException
 
+import java.io.Closeable
+import java.net.ConnectException
+import java.util
+import java.util.concurrent.ScheduledFuture
 import scala.collection.JavaConverters._
 import scala.concurrent.duration.TimeUnit
 
@@ -70,12 +70,12 @@ abstract class AbstractDiscovery extends Discovery with Closeable with Logging {
   }
 
   def startHealthyCheck(delayTime: Long): ScheduledFuture[_] = {
-    info("start HealthyCheck thread")
+    logger.info("start HealthyCheck thread")
     Utils.defaultScheduler.scheduleAtFixedRate(new Runnable {
       override def run(): Unit = {
         serverInstances.asScala.foreach { serverUrl =>
           val action = getHeartbeatAction(serverUrl)
-          info("heartbeat to healthy gateway " + serverUrl)
+          logger.info("heartbeat to healthy gateway " + serverUrl)
           Utils.tryCatch(client.execute(action, 3000) match {
             case heartbeat: HeartbeatResult =>
               if (!heartbeat.isHealthy) {
@@ -91,7 +91,7 @@ abstract class AbstractDiscovery extends Discovery with Closeable with Logging {
   }
 
   def startDiscovery(): ScheduledFuture[_] = {
-    info("start Discovery thread")
+    logger.info("start Discovery thread")
     client.execute(getHeartbeatAction(serverUrl), 3000) match {
       case heartbeat: HeartbeatResult => if (!heartbeat.isHealthy) throw new DiscoveryException(s"connect to serverUrl $serverUrl failed! Reason: gateway server is unhealthy!")
       else discoveryListeners.asScala.foreach(_.onServerDiscovered(serverUrl))
@@ -99,7 +99,7 @@ abstract class AbstractDiscovery extends Discovery with Closeable with Logging {
 
     Utils.defaultScheduler.scheduleAtFixedRate(new Runnable {
       override def run(): Unit = Utils.tryAndWarn {
-        info("to discovery gateway" + serverUrl)
+        logger.info("to discovery gateway" + serverUrl)
         val serverUrls = discovery()
         addServerInstances(serverUrls)
       }
@@ -149,7 +149,7 @@ abstract class AbstractDiscovery extends Discovery with Closeable with Logging {
   }
 
   def addUnhealthyServerInstances(unhealthyUrl: String): Unit = {
-    info(s"add  ${unhealthyUrl} to unhealthy list ")
+    logger.info(s"add  ${unhealthyUrl} to unhealthy list ")
     val updateUnhealthyUrl = if (serverInstances.contains(unhealthyUrl)) {
       unhealthyUrl
     } else if (serverInstances.contains(unhealthyUrl + HttpClientConstant.PATH_SPLIT_TOKEN)) {
@@ -158,7 +158,7 @@ abstract class AbstractDiscovery extends Discovery with Closeable with Logging {
       ""
     }
     if (StringUtils.isBlank(updateUnhealthyUrl)) {
-      info(s"${unhealthyUrl}  unhealthy url not exists")
+      logger.info(s"${unhealthyUrl}  unhealthy url not exists")
     } else {
       unhealthyServerInstances synchronized unhealthyServerInstances.add(updateUnhealthyUrl)
       discoveryListeners.asScala.foreach(_.onServerUnhealthy(updateUnhealthyUrl))
diff --git a/linkis-commons/linkis-mybatis/src/main/java/org/apache/linkis/mybatis/conf/MybatisConfiguration.java b/linkis-commons/linkis-mybatis/src/main/java/org/apache/linkis/mybatis/conf/MybatisConfiguration.java
index 69cde69bb..d58d01c23 100644
--- a/linkis-commons/linkis-mybatis/src/main/java/org/apache/linkis/mybatis/conf/MybatisConfiguration.java
+++ b/linkis-commons/linkis-mybatis/src/main/java/org/apache/linkis/mybatis/conf/MybatisConfiguration.java
@@ -41,40 +41,40 @@ public class MybatisConfiguration {
                     "wds.linkis.server.mybatis.datasource.driver-class-name",
                     "com.mysql.jdbc.Driver");
     public static final CommonVars<Integer> BDP_SERVER_MYBATIS_DATASOURCE_INITIALSIZE =
-            CommonVars.apply("wds.linkis.server.mybatis.datasource.initialSize", new Integer(1));
+            CommonVars.apply("wds.linkis.server.mybatis.datasource.initialSize", 1);
     public static final CommonVars<Integer> BDP_SERVER_MYBATIS_DATASOURCE_MINIDLE =
-            CommonVars.apply("wds.linkis.server.mybatis.datasource.minIdle", new Integer(1));
+            CommonVars.apply("wds.linkis.server.mybatis.datasource.minIdle", 1);
     public static final CommonVars<Integer> BDP_SERVER_MYBATIS_DATASOURCE_MAXACTIVE =
-            CommonVars.apply("wds.linkis.server.mybatis.datasource.maxActive", new Integer(20));
+            CommonVars.apply("wds.linkis.server.mybatis.datasource.maxActive", 20);
     public static final CommonVars<Integer> BDP_SERVER_MYBATIS_DATASOURCE_MAXWAIT =
-            CommonVars.apply("wds.linkis.server.mybatis.datasource.maxWait", new Integer(6000));
+            CommonVars.apply("wds.linkis.server.mybatis.datasource.maxWait", 6000);
     public static final CommonVars<Integer> BDP_SERVER_MYBATIS_DATASOURCE_TBERM =
             CommonVars.apply(
                     "wds.linkis.server.mybatis.datasource.timeBetweenEvictionRunsMillis",
-                    new Integer(60000));
+                    60000);
     public static final CommonVars<Integer> BDP_SERVER_MYBATIS_DATASOURCE_MEITM =
             CommonVars.apply(
                     "wds.linkis.server.mybatis.datasource.minEvictableIdleTimeMillis",
-                    new Integer(300000));
+                    300000);
     public static final CommonVars<String> BDP_SERVER_MYBATIS_DATASOURCE_VALIDATIONQUERY =
             CommonVars.apply("wds.linkis.server.mybatis.datasource.validationQuery", "SELECT 1");
 
     public static final CommonVars<Boolean> BDP_SERVER_MYBATIS_DATASOURCE_TESTWHILEIDLE =
             CommonVars.apply(
-                    "wds.linkis.server.mybatis.datasource.testWhileIdle", new Boolean(true));
+                    "wds.linkis.server.mybatis.datasource.testWhileIdle", Boolean.TRUE);
     public static final CommonVars<Boolean> BDP_SERVER_MYBATIS_DATASOURCE_TESTONBORROW =
             CommonVars.apply(
-                    "wds.linkis.server.mybatis.datasource.testOnBorrow", new Boolean(false));
+                    "wds.linkis.server.mybatis.datasource.testOnBorrow", Boolean.FALSE);
     public static final CommonVars<Boolean> BDP_SERVER_MYBATIS_DATASOURCE_TESTONRETURN =
             CommonVars.apply(
-                    "wds.linkis.server.mybatis.datasource.testOnReturn", new Boolean(false));
+                    "wds.linkis.server.mybatis.datasource.testOnReturn", Boolean.FALSE);
     public static final CommonVars<Boolean> BDP_SERVER_MYBATIS_DATASOURCE_POOLPREPAREDSTATEMENTS =
             CommonVars.apply(
                     "wds.linkis.server.mybatis.datasource.poolPreparedStatements",
-                    new Boolean(true));
+                    Boolean.TRUE);
     public static final CommonVars<Boolean> MYBATIS_DATASOURCE_REMOVE_ABANDONED_ENABLED =
             CommonVars.apply(
-                    "wds.linkis.server.mybatis.remove.abandoned.enabled", new Boolean(true));
+                    "wds.linkis.server.mybatis.remove.abandoned.enabled", Boolean.TRUE);
     public static final CommonVars<Integer> MYBATIS_DATASOURCE_REMOVE_ABANDONED_TIMEOUT =
             CommonVars.apply("wds.linkis.server.mybatis.remove.abandoned.timeout", 300);
 }
diff --git a/linkis-computation-governance/linkis-manager/linkis-application-manager/src/main/scala/org/apache/linkis/manager/rm/service/RequestResourceService.scala b/linkis-computation-governance/linkis-manager/linkis-application-manager/src/main/scala/org/apache/linkis/manager/rm/service/RequestResourceService.scala
index 8714c3297..5b61ff789 100644
--- a/linkis-computation-governance/linkis-manager/linkis-application-manager/src/main/scala/org/apache/linkis/manager/rm/service/RequestResourceService.scala
+++ b/linkis-computation-governance/linkis-manager/linkis-application-manager/src/main/scala/org/apache/linkis/manager/rm/service/RequestResourceService.scala
@@ -122,10 +122,10 @@ abstract class RequestResourceService(labelResourceService: LabelResourceService
     requestResource match {
       case m: MemoryResource =>
         (RMErrorCode.DRIVER_MEMORY_INSUFFICIENT.getCode, RMErrorCode.DRIVER_MEMORY_INSUFFICIENT.getMessage)
-      case c: CPUResource =>
-        (RMErrorCode.DRIVER_CPU_INSUFFICIENT.getCode, RMErrorCode.DRIVER_CPU_INSUFFICIENT.getMessage)
       case i: InstanceResource =>
         (RMErrorCode.INSTANCES_INSUFFICIENT.getCode, RMErrorCode.INSTANCES_INSUFFICIENT.getMessage)
+      case c: CPUResource =>
+        (RMErrorCode.DRIVER_CPU_INSUFFICIENT.getCode, RMErrorCode.DRIVER_CPU_INSUFFICIENT.getMessage)
       case l: LoadResource =>
         val loadAvailable = availableResource.asInstanceOf[LoadResource]
         if(l.cores > loadAvailable.cores) {
diff --git a/linkis-computation-governance/linkis-manager/linkis-manager-common/src/main/scala/org/apache/linkis/manager/common/entity/resource/Resource.scala b/linkis-computation-governance/linkis-manager/linkis-manager-common/src/main/scala/org/apache/linkis/manager/common/entity/resource/Resource.scala
index 627924c82..ae899c3e7 100644
--- a/linkis-computation-governance/linkis-manager/linkis-manager-common/src/main/scala/org/apache/linkis/manager/common/entity/resource/Resource.scala
+++ b/linkis-computation-governance/linkis-manager/linkis-manager-common/src/main/scala/org/apache/linkis/manager/common/entity/resource/Resource.scala
@@ -96,8 +96,8 @@ object Resource extends Logging {
 
   def getZeroResource(resource: Resource): Resource = resource match {
     case m: MemoryResource => new MemoryResource(0)
-    case c: CPUResource => new CPUResource(0)
     case i: InstanceResource => new InstanceResource(0)
+    case c: CPUResource => new CPUResource(0)
     case l: LoadResource => new LoadResource(0, 0)
     case li: LoadInstanceResource => new LoadInstanceResource(0, 0, 0)
     case yarn: YarnResource => new YarnResource(0, 0, 0)
diff --git a/linkis-computation-governance/linkis-manager/linkis-manager-common/src/main/scala/org/apache/linkis/manager/common/utils/ResourceUtils.scala b/linkis-computation-governance/linkis-manager/linkis-manager-common/src/main/scala/org/apache/linkis/manager/common/utils/ResourceUtils.scala
index 8f8507afa..dbe561ec8 100644
--- a/linkis-computation-governance/linkis-manager/linkis-manager-common/src/main/scala/org/apache/linkis/manager/common/utils/ResourceUtils.scala
+++ b/linkis-computation-governance/linkis-manager/linkis-manager-common/src/main/scala/org/apache/linkis/manager/common/utils/ResourceUtils.scala
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
- 
+
 package org.apache.linkis.manager.common.utils
 
 import org.apache.linkis.manager.common.entity.persistence.PersistenceResource
@@ -81,27 +81,27 @@ object ResourceUtils {
   }
 
   def getResourceTypeByResource(resource: Resource): ResourceType = resource match {
-    case cpuResource: CPUResource => ResourceType.CPU
-    case loadResource: LoadResource => ResourceType.Load
-    case instanceResource: InstanceResource => ResourceType.Instance
-    case loadInstanceResource: LoadInstanceResource => ResourceType.LoadInstance
-    case yarnResource: YarnResource => ResourceType.Yarn
-    case driverAndYarnResource: DriverAndYarnResource => ResourceType.DriverAndYarn
-    case specialResource: SpecialResource => ResourceType.Special
+    case _: LoadResource => ResourceType.Load
+    case _: InstanceResource => ResourceType.Instance
+    case _: CPUResource => ResourceType.CPU
+    case _: LoadInstanceResource => ResourceType.LoadInstance
+    case _: YarnResource => ResourceType.Yarn
+    case _: DriverAndYarnResource => ResourceType.DriverAndYarn
+    case _: SpecialResource => ResourceType.Special
     case _ => ResourceType.LoadInstance
   }
 
-  def convertTo(nodeResource: NodeResource, resourceType: ResourceType) : NodeResource = {
-    if(nodeResource.getResourceType.equals(resourceType)) return nodeResource
-    if(resourceType.equals(ResourceType.LoadInstance)){
-      if(nodeResource.getResourceType.equals(ResourceType.DriverAndYarn)){
+  def convertTo(nodeResource: NodeResource, resourceType: ResourceType): NodeResource = {
+    if (nodeResource.getResourceType.equals(resourceType)) return nodeResource
+    if (resourceType.equals(ResourceType.LoadInstance)) {
+      if (nodeResource.getResourceType.equals(ResourceType.DriverAndYarn)) {
         nodeResource.setResourceType(resourceType)
-        if(nodeResource.getMaxResource != null) nodeResource.setMaxResource(nodeResource.getMaxResource.asInstanceOf[DriverAndYarnResource].loadInstanceResource)
-        if(nodeResource.getMinResource != null) nodeResource.setMinResource(nodeResource.getMinResource.asInstanceOf[DriverAndYarnResource].loadInstanceResource)
-        if(nodeResource.getUsedResource != null) nodeResource.setUsedResource(nodeResource.getUsedResource.asInstanceOf[DriverAndYarnResource].loadInstanceResource)
-        if(nodeResource.getLockedResource != null) nodeResource.setLockedResource(nodeResource.getLockedResource.asInstanceOf[DriverAndYarnResource].loadInstanceResource)
-        if(nodeResource.getExpectedResource != null) nodeResource.setExpectedResource(nodeResource.getExpectedResource.asInstanceOf[DriverAndYarnResource].loadInstanceResource)
-        if(nodeResource.getLeftResource != null && nodeResource.getLeftResource.isInstanceOf[DriverAndYarnResource]){
+        if (nodeResource.getMaxResource != null) nodeResource.setMaxResource(nodeResource.getMaxResource.asInstanceOf[DriverAndYarnResource].loadInstanceResource)
+        if (nodeResource.getMinResource != null) nodeResource.setMinResource(nodeResource.getMinResource.asInstanceOf[DriverAndYarnResource].loadInstanceResource)
+        if (nodeResource.getUsedResource != null) nodeResource.setUsedResource(nodeResource.getUsedResource.asInstanceOf[DriverAndYarnResource].loadInstanceResource)
+        if (nodeResource.getLockedResource != null) nodeResource.setLockedResource(nodeResource.getLockedResource.asInstanceOf[DriverAndYarnResource].loadInstanceResource)
+        if (nodeResource.getExpectedResource != null) nodeResource.setExpectedResource(nodeResource.getExpectedResource.asInstanceOf[DriverAndYarnResource].loadInstanceResource)
+        if (nodeResource.getLeftResource != null && nodeResource.getLeftResource.isInstanceOf[DriverAndYarnResource]) {
           nodeResource.setLeftResource(nodeResource.getLeftResource.asInstanceOf[DriverAndYarnResource].loadInstanceResource)
         }
         return nodeResource
@@ -112,6 +112,7 @@ object ResourceUtils {
 
   /**
    * Get the proportion of left resources, and return the smallest CPU, memory, and instance
+   *
    * @param leftResource
    * @param maxResource
    * @return
@@ -123,7 +124,7 @@ object ResourceUtils {
       case leftLoadInstanceResource: LoadInstanceResource =>
         maxResource match {
           case maxLoadInstanceResource: LoadInstanceResource =>
-            val cpuRate = if (maxLoadInstanceResource.cores >  0) (leftLoadInstanceResource.cores * 1.0F) / maxLoadInstanceResource.cores else 1F
+            val cpuRate = if (maxLoadInstanceResource.cores > 0) (leftLoadInstanceResource.cores * 1.0F) / maxLoadInstanceResource.cores else 1F
             val memoryRate = if (maxLoadInstanceResource.memory > 0) (leftLoadInstanceResource.memory * 1.0F) / maxLoadInstanceResource.memory else 1F
             val instanceRate = if (maxLoadInstanceResource.instances > 0) (leftLoadInstanceResource.instances * 1.0F) / maxLoadInstanceResource.instances else 1F
             Math.min(Math.min(cpuRate, memoryRate), instanceRate)


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@linkis.apache.org
For additional commands, e-mail: commits-help@linkis.apache.org