Ngone51 commented on a change in pull request #25409: [SPARK-28414][WEBUI] UI 
updates to show resource info in Standalone
URL: https://github.com/apache/spark/pull/25409#discussion_r317646956
 
 

 ##########
 File path: core/src/main/scala/org/apache/spark/deploy/master/WorkerInfo.scala
 ##########
 @@ -64,12 +61,54 @@ private[spark] class WorkerInfo(
 
   def coresFree: Int = cores - coresUsed
   def memoryFree: Int = memory - memoryUsed
-  def resourcesFree: Map[String, Int] = {
+  def resourcesAmountFree: Map[String, Int] = {
     resources.map { case (rName, rInfo) =>
       rName -> rInfo.availableAddrs.length
     }
   }
 
+  def resourcesInfo[T: ClassTag]: Map[String, T] = {
+    resources.map { case (rName, rInfo) =>
+      rName -> createResourceInfo(rName, rInfo.addresses, 
implicitly[ClassTag[T]])
+    }
+  }
+
+  def resourcesInfoFree: Map[String, ResourceInformation] = {
+    resources.map { case (rName, rInfo) =>
+      rName -> createResourceInfo(rName, rInfo.availableAddrs,
+        implicitly[ClassTag[ResourceInformation]])
+    }
+  }
+
+  def resourcesInfoUsed[T: ClassTag]: Map[String, T] = {
+    resources.map { case (rName, rInfo) =>
+      rName -> createResourceInfo(rName, rInfo.assignedAddrs, 
implicitly[ClassTag[T]])
+    }
+  }
+
+  private def createResourceInfo[T](
+      name: String,
+      addresses: Seq[String],
+      ct: ClassTag[T]): T = {
+    val clazz = ct.runtimeClass
+    val rf = {
+      clazz match {
+        case _ if clazz.equals(classOf[MutableResourceInfo]) =>
 
 Review comment:
   Thanks, and I chosen the alternative one, which seems more simply in 
WorkerInfo. While, the other one actually needs 4 functions(combinations of 
[immutable, mutable] * [total, used]), which seems noisy in WorkerInfo from my 
view.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

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

Reply via email to