Skip to content

Instantly share code, notes, and snippets.

@ashkrit
Created February 10, 2019 11:12
Show Gist options
  • Save ashkrit/8b0faec5d7ead4134394da7f08bc9707 to your computer and use it in GitHub Desktop.
Save ashkrit/8b0faec5d7ead4134394da7f08bc9707 to your computer and use it in GitHub Desktop.
val metrics = client.clusterMetrics()
val clusterQueueInfo = client.clusterQueue()
val queueWithCapacity = client.freeQueues(metrics, clusterQueueInfo)
val selectedYarnApps = client.appsBy(user, status)
if (hasApps(selectedYarnApps)) {
val now = System.currentTimeMillis()
val appsByMaxWaitingTime = selectedYarnApps.apps.app.asScala.map(app =>
(app, TimeUnit.MILLISECONDS.toMinutes(now - app.startedTime))
).filter(v => v._2 > WaitTimeThreshHoldInMinute)
.sortBy(v => v._2)(Ordering[Long].reverse)
appsByMaxWaitingTime.foreach { case (app, waitTime) =>
println(s" Application ${app.id} is waiting for ${waitTime} minutes")
client.moveApp(app, queueWithCapacity)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment