@@ -21,74 +21,190 @@ import org.json4s.JsonAST.JObject
2121import  org .json4s .JsonDSL ._ 
2222
2323import  org .apache .spark .deploy .DeployMessages .{MasterStateResponse , WorkerStateResponse }
24- import  org .apache .spark .deploy .master .{ApplicationInfo , DriverInfo , WorkerInfo }
24+ import  org .apache .spark .deploy .master ._ 
25+ import  org .apache .spark .deploy .master .RecoveryState .MasterState 
2526import  org .apache .spark .deploy .worker .ExecutorRunner 
2627
2728private [deploy] object  JsonProtocol  {
28-  def  writeWorkerInfo (obj : WorkerInfo ):  JObject  =  {
29-    (" id" ->  obj.id) ~ 
30-    (" host" ->  obj.host) ~ 
31-    (" port" ->  obj.port) ~ 
32-    (" webuiaddress" ->  obj.webUiAddress) ~ 
33-    (" cores" ->  obj.cores) ~ 
34-    (" coresused" ->  obj.coresUsed) ~ 
35-    (" coresfree" ->  obj.coresFree) ~ 
36-    (" memory" ->  obj.memory) ~ 
37-    (" memoryused" ->  obj.memoryUsed) ~ 
38-    (" memoryfree" ->  obj.memoryFree) ~ 
39-    (" state" ->  obj.state.toString) ~ 
40-    (" lastheartbeat" ->  obj.lastHeartbeat)
41-  }
29+   /**  
30+    * Export the [[WorkerInfo ]] to a Json object. A [[WorkerInfo ]] consists of the information of a 
31+    * worker. 
32+    * 
33+    * @return  a Json object containing the following fields: 
34+    *         `id` a string identifier of the worker 
35+    *         `host` the host that the worker is running on 
36+    *         `port` the port that the worker is bound to 
37+    *         `webuiaddress` the address used in web UI 
38+    *         `cores` total cores of the worker 
39+    *         `coresused` allocated cores of the worker 
40+    *         `coresfree` free cores of the worker 
41+    *         `memory` total memory of the worker 
42+    *         `memoryused` allocated memory of the worker 
43+    *         `memoryfree` free memory of the worker 
44+    *         `state` state of the worker, see [[WorkerState ]] 
45+    *         `lastheartbeat` time in milliseconds that the latest heart beat message from the 
46+    *         worker is received 
47+    */  
48+   def  writeWorkerInfo (obj : WorkerInfo ):  JObject  =  {
49+     (" id" ->  obj.id) ~ 
50+     (" host" ->  obj.host) ~ 
51+     (" port" ->  obj.port) ~ 
52+     (" webuiaddress" ->  obj.webUiAddress) ~ 
53+     (" cores" ->  obj.cores) ~ 
54+     (" coresused" ->  obj.coresUsed) ~ 
55+     (" coresfree" ->  obj.coresFree) ~ 
56+     (" memory" ->  obj.memory) ~ 
57+     (" memoryused" ->  obj.memoryUsed) ~ 
58+     (" memoryfree" ->  obj.memoryFree) ~ 
59+     (" state" ->  obj.state.toString) ~ 
60+     (" lastheartbeat" ->  obj.lastHeartbeat)
61+   }
4262
63+   /**  
64+    * Export the [[ApplicationInfo ]] to a Json objec. An [[ApplicationInfo ]] consists of the 
65+    * information of an application. 
66+    * 
67+    * @return  a Json object containing the following fields: 
68+    *         `id` a string identifier of the application 
69+    *         `starttime` time in milliseconds that the application starts 
70+    *         `name` the description of the application 
71+    *         `cores` total cores granted to the application 
72+    *         `user` name of the user who submitted the application 
73+    *         `memoryperslave` minimal memory in MB required to each executor 
74+    *         `submitdate` time in Date that the application is submitted 
75+    *         `state` state of the application, see [[ApplicationState ]] 
76+    *         `duration` time in milliseconds that the application has been running 
77+    */  
4378  def  writeApplicationInfo (obj : ApplicationInfo ):  JObject  =  {
44-     (" starttime" ->  obj.startTime) ~ 
4579    (" id" ->  obj.id) ~ 
80+     (" starttime" ->  obj.startTime) ~ 
4681    (" name" ->  obj.desc.name) ~ 
47-     (" cores" ->  obj.desc.maxCores ) ~ 
82+     (" cores" ->  obj.coresGranted ) ~ 
4883    (" user" ->  obj.desc.user) ~ 
4984    (" memoryperslave" ->  obj.desc.memoryPerExecutorMB) ~ 
5085    (" submitdate" ->  obj.submitDate.toString) ~ 
5186    (" state" ->  obj.state.toString) ~ 
5287    (" duration" ->  obj.duration)
5388  }
5489
90+   /**  
91+    * Export the [[ApplicationDescription ]] to a Json object. An [[ApplicationDescription ]] consists 
92+    * of the description of an application. 
93+    * 
94+    * @return  a Json object containing the following fields: 
95+    *         `name` the description of the application 
96+    *         `cores` max cores that can be allocated to the application, 0 means unlimited 
97+    *         `memoryperslave` minimal memory in MB required to each executor 
98+    *         `user` name of the user who submitted the application 
99+    *         `command` the command string used to submit the application 
100+    */  
55101  def  writeApplicationDescription (obj : ApplicationDescription ):  JObject  =  {
56102    (" name" ->  obj.name) ~ 
57-     (" cores" ->  obj.maxCores) ~ 
103+     (" cores" ->  obj.maxCores.getOrElse( 0 ) ) ~ 
58104    (" memoryperslave" ->  obj.memoryPerExecutorMB) ~ 
59105    (" user" ->  obj.user) ~ 
60106    (" command" ->  obj.command.toString)
61107  }
62108
109+   /**  
110+    * Export the [[ExecutorRunner ]] to a Json object. An [[ExecutorRunner ]] consists of the 
111+    * information of an executor. 
112+    * 
113+    * @return  a Json object containing the following fields: 
114+    *         `id` an integer identifier of the executor 
115+    *         `memory` memory in MB allocated to the executor 
116+    *         `appid` a string identifier of the application that the executor is working on 
117+    *         `appdesc` a Json object of the [[ApplicationDescription ]] of the application that the 
118+    *         executor is working on 
119+    */  
63120  def  writeExecutorRunner (obj : ExecutorRunner ):  JObject  =  {
64121    (" id" ->  obj.execId) ~ 
65122    (" memory" ->  obj.memory) ~ 
66123    (" appid" ->  obj.appId) ~ 
67124    (" appdesc" ->  writeApplicationDescription(obj.appDesc))
68125  }
69126
127+   /**  
128+    * Export the [[DriverInfo ]] to a Json object. A [[DriverInfo ]] consists of the information of a 
129+    * driver. 
130+    * 
131+    * @return  a Json object containing the following fields: 
132+    *         `id` a string identifier of the driver 
133+    *         `starttime` time in milliseconds that the driver starts 
134+    *         `state` state of the driver, see [[DriverState ]] 
135+    *         `cores` cores allocated to the driver 
136+    *         `memory` memory in MB allocated to the driver 
137+    *         `submitdate` time in Date that the driver is created 
138+    *         `worker` identifier of the worker that the driver is running on 
139+    *         `mainclass` main class of the command string that started the driver 
140+    */  
70141  def  writeDriverInfo (obj : DriverInfo ):  JObject  =  {
71142    (" id" ->  obj.id) ~ 
72143    (" starttime" ->  obj.startTime.toString) ~ 
73144    (" state" ->  obj.state.toString) ~ 
74145    (" cores" ->  obj.desc.cores) ~ 
75-     (" memory" ->  obj.desc.mem)
146+     (" memory" ->  obj.desc.mem) ~ 
147+     (" submitdate" ->  obj.submitDate.toString) ~ 
148+     (" worker" ->  obj.worker.map(_.id).getOrElse(" None" ~ 
149+     (" mainclass" ->  obj.desc.command.arguments(2 ))
76150  }
77151
152+   /**  
153+    * Export the [[MasterStateResponse ]] to a Json object. A [[MasterStateResponse ]] consists the 
154+    * information of a master node. 
155+    * 
156+    * @return  a Json object containing the following fields: 
157+    *         `url` the url of the master node 
158+    *         `workers` a list of Json objects of [[WorkerInfo ]] of the workers allocated to the 
159+    *         master 
160+    *         `aliveworkers` size of alive workers allocated to the master 
161+    *         `cores` total cores available of the master 
162+    *         `coresused` cores used by the master 
163+    *         `memory` total memory available of the master 
164+    *         `memoryused` memory used by the master 
165+    *         `activeapps` a list of Json objects of [[ApplicationInfo ]] of the active applications 
166+    *         running on the master 
167+    *         `completedapps` a list of Json objects of [[ApplicationInfo ]] of the applications 
168+    *         completed in the master 
169+    *         `activedrivers` a list of Json objects of [[DriverInfo ]] of the active drivers of the 
170+    *         master 
171+    *         `completeddrivers` a list of Json objects of [[DriverInfo ]] of the completed drivers 
172+    *         of the master 
173+    *         `status` status of the master, see [[MasterState ]] 
174+    */  
78175  def  writeMasterState (obj : MasterStateResponse ):  JObject  =  {
79176    val  aliveWorkers  =  obj.workers.filter(_.isAlive())
80177    (" url" ->  obj.uri) ~ 
81178    (" workers" ->  obj.workers.toList.map(writeWorkerInfo)) ~ 
179+     (" aliveworkers" ->  aliveWorkers.length) ~ 
82180    (" cores" ->  aliveWorkers.map(_.cores).sum) ~ 
83181    (" coresused" ->  aliveWorkers.map(_.coresUsed).sum) ~ 
84182    (" memory" ->  aliveWorkers.map(_.memory).sum) ~ 
85183    (" memoryused" ->  aliveWorkers.map(_.memoryUsed).sum) ~ 
86184    (" activeapps" ->  obj.activeApps.toList.map(writeApplicationInfo)) ~ 
87185    (" completedapps" ->  obj.completedApps.toList.map(writeApplicationInfo)) ~ 
88186    (" activedrivers" ->  obj.activeDrivers.toList.map(writeDriverInfo)) ~ 
187+     (" completeddrivers" ->  obj.completedDrivers.toList.map(writeDriverInfo)) ~ 
89188    (" status" ->  obj.status.toString)
90189  }
91190
191+   /**  
192+    * Export the [[WorkerStateResponse ]] to a Json object. A [[WorkerStateResponse ]] consists the 
193+    * information of a worker node. 
194+    * 
195+    * @return  a Json object containing the following fields: 
196+    *         `id` a string identifier of the worker node 
197+    *         `masterurl` url of the master node of the worker 
198+    *         `masterwebuiurl` the address used in web UI of the master node of the worker 
199+    *         `cores` total cores of the worker 
200+    *         `coreused` used cores of the worker 
201+    *         `memory` total memory of the worker 
202+    *         `memoryused` used memory of the worker 
203+    *         `executors` a list of Json objects of [[ExecutorRunner ]] of the executors running on 
204+    *         the worker 
205+    *         `finishedexecutors` a list of Json objects of [[ExecutorRunner ]] of the finished 
206+    *         executors of the worker 
207+    */  
92208  def  writeWorkerState (obj : WorkerStateResponse ):  JObject  =  {
93209    (" id" ->  obj.workerId) ~ 
94210    (" masterurl" ->  obj.masterUrl) ~ 
@@ -97,7 +213,7 @@ private[deploy] object JsonProtocol {
97213    (" coresused" ->  obj.coresUsed) ~ 
98214    (" memory" ->  obj.memory) ~ 
99215    (" memoryused" ->  obj.memoryUsed) ~ 
100-     (" executors" ->  obj.executors.toList. map(writeExecutorRunner)) ~ 
101-     (" finishedexecutors" ->  obj.finishedExecutors.toList. map(writeExecutorRunner))
216+     (" executors" ->  obj.executors.map(writeExecutorRunner)) ~ 
217+     (" finishedexecutors" ->  obj.finishedExecutors.map(writeExecutorRunner))
102218  }
103219}
0 commit comments