@@ -236,22 +236,31 @@ class ClientHelper(conf: Configuration) extends Logging {
236236 * @return the active application ids.
237237 */
238238 def getActiveApplicationIds (appName : String ): List [ApplicationId ] = {
239- val getAppsRsp = yarnClient.getApplications
239+ val applicationReports = yarnClient.getApplications
240240
241- getAppsRsp
241+ applicationReports
242242 .asScala
243- .filter(appRep => ((
244- Running .equals(convertState(appRep.getYarnApplicationState, appRep.getFinalApplicationStatus).get)
245- || New .equals(convertState(appRep.getYarnApplicationState, appRep.getFinalApplicationStatus).get)
246- )
247- && appName.equals(appRep.getName)))
248- .map(appRep => appRep.getApplicationId)
243+ .filter(applicationReport => isActiveApplication(applicationReport)
244+ && appName.equals(applicationReport.getName))
245+ .map(applicationReport => applicationReport.getApplicationId)
249246 .toList
250247 }
251248
249+ def getPreviousApplicationIds (appName : String ): List [ApplicationId ] = {
250+ val applicationReports = yarnClient.getApplications
251+
252+ applicationReports
253+ .asScala
254+ .filter(applicationReport => (! (isActiveApplication(applicationReport))
255+ && appName.equals(applicationReport.getName)))
256+ .map(applicationReport => applicationReport.getApplicationId)
257+ .toList
258+ }
259+
252260 def status (appId : ApplicationId ): Option [ApplicationStatus ] = {
253261 val statusResponse = yarnClient.getApplicationReport(appId)
254- convertState(statusResponse.getYarnApplicationState, statusResponse.getFinalApplicationStatus)
262+ info(" Got state: %s, final status: %s" .format(statusResponse.getYarnApplicationState, statusResponse.getFinalApplicationStatus))
263+ toAppStatus(statusResponse.getYarnApplicationState, statusResponse.getFinalApplicationStatus)
255264 }
256265
257266 def kill (appId : ApplicationId ) {
@@ -271,15 +280,20 @@ class ClientHelper(conf: Configuration) extends Logging {
271280 status match {
272281 case Some (status) => getAppsRsp
273282 .asScala
274- .filter(appRep => status.equals(convertState (appRep.getYarnApplicationState, appRep.getFinalApplicationStatus).get))
283+ .filter(appRep => status.equals(toAppStatus (appRep.getYarnApplicationState, appRep.getFinalApplicationStatus).get))
275284 .toList
276285 case None => getAppsRsp.asScala.toList
277286 }
278287 }
279288
280- private def convertState (state : YarnApplicationState , status : FinalApplicationStatus ): Option [ApplicationStatus ] = {
289+ private def isActiveApplication (applicationReport : ApplicationReport ): Boolean = {
290+ (Running .equals(toAppStatus(applicationReport.getYarnApplicationState, applicationReport.getFinalApplicationStatus).get)
291+ || New .equals(toAppStatus(applicationReport.getYarnApplicationState, applicationReport.getFinalApplicationStatus).get))
292+ }
293+
294+ private def toAppStatus (state : YarnApplicationState , status : FinalApplicationStatus ): Option [ApplicationStatus ] = {
281295 (state, status) match {
282- case (YarnApplicationState .FINISHED , FinalApplicationStatus .SUCCEEDED ) => Some (SuccessfulFinish )
296+ case (YarnApplicationState .FINISHED , FinalApplicationStatus .SUCCEEDED ) | ( YarnApplicationState . KILLED , FinalApplicationStatus . KILLED ) => Some (SuccessfulFinish )
283297 case (YarnApplicationState .KILLED , _) | (YarnApplicationState .FAILED , _) | (YarnApplicationState .FINISHED , _) => Some (UnsuccessfulFinish )
284298 case (YarnApplicationState .NEW , _) | (YarnApplicationState .SUBMITTED , _) => Some (New )
285299 case _ => Some (Running )
0 commit comments