Skip to content

Commit cb35b20

Browse files
committed
apply mesos#845
1 parent 24e9f60 commit cb35b20

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/main/scala/org/apache/mesos/chronos/scheduler/api/JobManagementResource.scala

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,7 @@ class JobManagementResource @Inject()(val jobScheduler: JobScheduler,
324324
@Timed
325325
def getSummary(): Response = {
326326
try {
327-
import scala.collection.JavaConversions._
328-
val jobs = jobGraph.dag.vertexSet()
329-
.flatMap {
330-
jobGraph.getJobForName
331-
}
327+
val jobs = jobGraph.transformVertextSet(j => jobGraph.getJobForName(j))
332328
.map {
333329
job =>
334330
val state = Exporter.getLastState(job).toString
@@ -368,12 +364,7 @@ class JobManagementResource @Inject()(val jobScheduler: JobScheduler,
368364
@QueryParam("offset") offset: Integer
369365
) = {
370366
try {
371-
val jobs = ListBuffer[BaseJob]()
372-
import scala.collection.JavaConversions._
373-
jobGraph.dag.vertexSet().map({
374-
job =>
375-
jobs += jobGraph.getJobForName(job).get
376-
})
367+
val jobs = jobGraph.transformVertextSet(j => jobGraph.getJobForName(j))
377368

378369
val _limit: Integer = limit match {
379370
case x: Integer =>

src/main/scala/org/apache/mesos/chronos/scheduler/graph/JobGraph.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import org.jgrapht.graph.DefaultEdge
1212
import scala.collection.convert.decorateAsScala._
1313
import scala.collection.mutable.ListBuffer
1414
import scala.collection.{mutable, _}
15+
import scala.collection.JavaConverters._
1516

1617
/**
1718
* This class provides methods to access dependency structures of jobs.
@@ -52,6 +53,14 @@ class JobGraph {
5253
Some(parents)
5354
}
5455

56+
57+
def transformVertextSet[T](f: String => Option[T]): Set[T] = {
58+
lock.synchronized {
59+
dag.vertexSet().asScala.flatMap(vertex => f(vertex))
60+
}
61+
}
62+
63+
5564
def getJobForName(name: String): Option[BaseJob] = {
5665
jobNameMapping.get(name)
5766
}

0 commit comments

Comments
 (0)