You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@linkis.apache.org by "jackxu2011 (via GitHub)" <gi...@apache.org> on 2023/03/16 15:18:39 UTC

[GitHub] [linkis] jackxu2011 commented on a diff in pull request #4368: [feat] remove json4s from linkis

jackxu2011 commented on code in PR #4368:
URL: https://github.com/apache/linkis/pull/4368#discussion_r1138827684


##########
linkis-computation-governance/linkis-manager/linkis-application-manager/src/main/scala/org/apache/linkis/manager/rm/external/yarn/YarnResourceRequester.scala:
##########
@@ -77,31 +73,37 @@ class YarnResourceRequester extends ExternalResourceRequester with Logging {
     logger.info(s"rmWebAddress: $rmWebAddress")
     val queueName = identifier.asInstanceOf[YarnResourceIdentifier].getQueueName
 
-    def getYarnResource(jValue: Option[JValue]) = jValue.map(r =>
-      new YarnResource(
-        (r \ "memory").asInstanceOf[JInt].values.toLong * 1024L * 1024L,
-        (r \ "vCores").asInstanceOf[JInt].values.toInt,
-        0,
-        queueName
-      )
-    )
+    def getYarnResource(resource: Option[Any]) = resource.map(r => {
+      val value =
+        JsonUtils.jackson.readValue(r.asInstanceOf[YarnResource].toJson, classOf[Map[String, Any]])

Review Comment:
   is the json is useless,  just cast the resource to YarnResource?



##########
linkis-computation-governance/linkis-manager/linkis-application-manager/src/main/scala/org/apache/linkis/manager/rm/external/yarn/YarnResourceRequester.scala:
##########
@@ -77,31 +73,37 @@ class YarnResourceRequester extends ExternalResourceRequester with Logging {
     logger.info(s"rmWebAddress: $rmWebAddress")
     val queueName = identifier.asInstanceOf[YarnResourceIdentifier].getQueueName
 
-    def getYarnResource(jValue: Option[JValue]) = jValue.map(r =>
-      new YarnResource(
-        (r \ "memory").asInstanceOf[JInt].values.toLong * 1024L * 1024L,
-        (r \ "vCores").asInstanceOf[JInt].values.toInt,
-        0,
-        queueName
-      )
-    )
+    def getYarnResource(resource: Option[Any]) = resource.map(r => {
+      val value =
+        JsonUtils.jackson.readValue(r.asInstanceOf[YarnResource].toJson, classOf[Map[String, Any]])
+      val memory = getMapValue[Int](value, "memory")
+      val vCores = getMapValue[Int](value, "vCores")
+      new YarnResource(memory.toLong * 1024L * 1024L, vCores, 0, queueName)
+    })
 
-    def maxEffectiveHandle(queueValue: Option[JValue]): Option[YarnResource] = {
+    def maxEffectiveHandle(queueValue: Option[Any]): Option[YarnResource] = {
       val metrics = getResponseByUrl("metrics", rmWebAddress)
-      val totalResouceInfoResponse = (
-        (metrics \ "clusterMetrics" \ "totalMB").asInstanceOf[JInt].values.toLong,
-        (metrics \ "clusterMetrics" \ "totalVirtualCores").asInstanceOf[JInt].values.toLong
-      )
+      val metricsJson = JsonUtils.jackson.readValue(metrics.toString(), classOf[Map[String, Any]])
+      val clusterMetricsJson = getMapValue[String](metricsJson, "clusterMetrics")
+
+      val clusterMetrics =
+        JsonUtils.jackson.readValue(clusterMetricsJson, classOf[Map[String, Any]])
+      val totalMB = getMapValue[Int](clusterMetrics, "totalMB")

Review Comment:
   and all other locations of get a spec path json value



##########
linkis-computation-governance/linkis-manager/linkis-application-manager/src/main/scala/org/apache/linkis/manager/rm/external/yarn/YarnResourceRequester.scala:
##########
@@ -77,31 +73,37 @@ class YarnResourceRequester extends ExternalResourceRequester with Logging {
     logger.info(s"rmWebAddress: $rmWebAddress")
     val queueName = identifier.asInstanceOf[YarnResourceIdentifier].getQueueName
 
-    def getYarnResource(jValue: Option[JValue]) = jValue.map(r =>
-      new YarnResource(
-        (r \ "memory").asInstanceOf[JInt].values.toLong * 1024L * 1024L,
-        (r \ "vCores").asInstanceOf[JInt].values.toInt,
-        0,
-        queueName
-      )
-    )
+    def getYarnResource(resource: Option[Any]) = resource.map(r => {
+      val value =
+        JsonUtils.jackson.readValue(r.asInstanceOf[YarnResource].toJson, classOf[Map[String, Any]])
+      val memory = getMapValue[Int](value, "memory")
+      val vCores = getMapValue[Int](value, "vCores")
+      new YarnResource(memory.toLong * 1024L * 1024L, vCores, 0, queueName)
+    })
 
-    def maxEffectiveHandle(queueValue: Option[JValue]): Option[YarnResource] = {
+    def maxEffectiveHandle(queueValue: Option[Any]): Option[YarnResource] = {
       val metrics = getResponseByUrl("metrics", rmWebAddress)
-      val totalResouceInfoResponse = (
-        (metrics \ "clusterMetrics" \ "totalMB").asInstanceOf[JInt].values.toLong,
-        (metrics \ "clusterMetrics" \ "totalVirtualCores").asInstanceOf[JInt].values.toLong
-      )
+      val metricsJson = JsonUtils.jackson.readValue(metrics.toString(), classOf[Map[String, Any]])
+      val clusterMetricsJson = getMapValue[String](metricsJson, "clusterMetrics")
+
+      val clusterMetrics =
+        JsonUtils.jackson.readValue(clusterMetricsJson, classOf[Map[String, Any]])
+      val totalMB = getMapValue[Int](clusterMetrics, "totalMB")

Review Comment:
   this can use jsonPath to replace?



##########
linkis-computation-governance/linkis-client/linkis-computation-client/src/main/scala/org/apache/linkis/ujes/client/response/JobProgressResult.scala:
##########
@@ -17,32 +17,34 @@
 
 package org.apache.linkis.ujes.client.response
 
+import org.apache.linkis.common.utils.JsonUtils
 import org.apache.linkis.httpclient.dws.annotation.DWSHttpMessageResult
 import org.apache.linkis.protocol.engine.JobProgressInfo
 
 import java.util
 
 import scala.collection.JavaConverters._
 
-import org.json4s._
-import org.json4s.jackson.Serialization._
-
 @DWSHttpMessageResult("/api/rest_j/v\\d+/entrance/(\\S+)/progress")
 class JobProgressResult extends UJESJobResult {
 
   private var progress: Float = _
   private var progressInfo: util.List[util.Map[String, AnyRef]] = _
   private var progressInfos: Array[JobProgressInfo] = _
 
-  private implicit val formats = DefaultFormats
-
   def setProgress(progress: Float): Unit = this.progress = progress
   def getProgress: Float = progress
 
   def setProgressInfo(progressInfo: util.List[util.Map[String, AnyRef]]): Unit = {
     this.progressInfo = progressInfo
-    progressInfos =
-      progressInfo.asScala.map(map => read[JobProgressInfo](write(map.asScala.toMap))).toArray
+    progressInfos = progressInfo.asScala
+      .map(map =>
+        JsonUtils.jackson.readValue(
+          JsonUtils.jackson.writeValueAsString(map.asScala.toMap),

Review Comment:
   can change the map.asScala.toMap to map 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@linkis.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


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