Skip to content

Commit 39dd0ee

Browse files
committed
update
1 parent 0b9400e commit 39dd0ee

File tree

3 files changed

+63
-35
lines changed

3 files changed

+63
-35
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.spark;
19+
20+
import java.io.Serializable;
21+
22+
/**
23+
* Exposes information about Spark Executors.
24+
*
25+
* This interface is not designed to be implemented outside of Spark. We may add additional methods
26+
* which may break binary compatibility with outside implementations.
27+
*/
28+
public interface SparkExecutorInfo extends Serializable {
29+
String host();
30+
int port();
31+
long cacheSize();
32+
int numRunningTasks();
33+
}

core/src/main/scala/org/apache/spark/SparkStatusTracker.scala

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -108,32 +108,20 @@ class SparkStatusTracker private[spark] (sc: SparkContext) {
108108
}
109109

110110
/**
111-
* Returns a list of all known executors, represented by string with format: "host:port"
111+
* Returns information of all known executors, including host, port, cacheSize, numRunningTasks.
112112
*/
113-
def getExecutorList(): Array[String] = {
114-
sc.getExecutorStorageStatus.map { status =>
115-
status.blockManagerId.hostPort
116-
}
117-
}
118-
119-
/**
120-
* Returns a map contains executor id(host+port) and its cache size(memory used by caching RDDs).
121-
*/
122-
def getCacheSizeByExecutors(): Map[String, Long] = {
123-
sc.getExecutorStorageStatus.map { status =>
124-
status.blockManagerId.hostPort -> status.cacheSize
125-
}.toMap
126-
}
127-
128-
/**
129-
* Returns a map contains executor id(host+port) and its number of running tasks.
130-
*/
131-
def getRunningTasksByExecutors(): Map[String, Int] = {
113+
def getExecutorInfos: Array[SparkExecutorInfo] = {
132114
val executorIdToRunningTasks: Map[String, Int] =
133115
sc.taskScheduler.asInstanceOf[TaskSchedulerImpl].runningTasksByExecutors()
116+
134117
sc.getExecutorStorageStatus.map { status =>
135118
val bmId = status.blockManagerId
136-
bmId.hostPort -> executorIdToRunningTasks.getOrElse(bmId.executorId, 0)
137-
}.toMap
119+
new SparkExecutorInfoImpl(
120+
bmId.host,
121+
bmId.port,
122+
status.cacheSize,
123+
executorIdToRunningTasks.getOrElse(bmId.executorId, 0)
124+
)
125+
}
138126
}
139127
}

core/src/main/scala/org/apache/spark/StatusAPIImpl.scala

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,25 @@
1818
package org.apache.spark
1919

2020
private class SparkJobInfoImpl (
21-
val jobId: Int,
22-
val stageIds: Array[Int],
23-
val status: JobExecutionStatus)
24-
extends SparkJobInfo
21+
val jobId: Int,
22+
val stageIds: Array[Int],
23+
val status: JobExecutionStatus)
24+
extends SparkJobInfo
2525

2626
private class SparkStageInfoImpl(
27-
val stageId: Int,
28-
val currentAttemptId: Int,
29-
val submissionTime: Long,
30-
val name: String,
31-
val numTasks: Int,
32-
val numActiveTasks: Int,
33-
val numCompletedTasks: Int,
34-
val numFailedTasks: Int)
35-
extends SparkStageInfo
27+
val stageId: Int,
28+
val currentAttemptId: Int,
29+
val submissionTime: Long,
30+
val name: String,
31+
val numTasks: Int,
32+
val numActiveTasks: Int,
33+
val numCompletedTasks: Int,
34+
val numFailedTasks: Int)
35+
extends SparkStageInfo
36+
37+
private class SparkExecutorInfoImpl(
38+
val host: String,
39+
val port: Int,
40+
val cacheSize: Long,
41+
val numRunningTasks: Int)
42+
extends SparkExecutorInfo

0 commit comments

Comments
 (0)