@ Override public Result evaluate ( TaskRequest taskRequest , VirtualMachineCurrentState targetVM , TaskTrackerState taskTrackerState ) { Set < String > coTasks = coTasksGetter . call ( taskRequest . getId ( ) ) ; String targetHostAttrVal = AttributeUtilities . getAttrValue ( targetVM . getCurrAvailableResources ( ) , hostAttributeName ) ; if ( targetHostAttrVal == null || targetHostAttrVal . isEmpty ( ) ) { return new Result ( false , hostAttributeName + " attribute unavailable on host " + targetVM . getCurrAvailableResources ( ) . hostname ( ) ) ; } for ( String coTask : coTasks ) { TaskTracker . ActiveTask activeTask = taskTrackerState . getAllRunningTasks ( ) . get ( coTask ) ; if ( activeTask == null ) activeTask = taskTrackerState . getAllCurrentlyAssignedTasks ( ) . get ( coTask ) ; if ( activeTask != null ) { String usedAttrVal = AttributeUtilities . getAttrValue ( activeTask . getTotalLease ( ) , hostAttributeName ) ; if ( usedAttrVal == null || usedAttrVal . isEmpty ( ) ) return new Result ( false , hostAttributeName + " attribute unavailable on host " + activeTask . getTotalLease ( ) . hostname ( ) + " running co-task " + coTask ) ; if ( usedAttrVal . equals ( targetHostAttrVal ) ) { return new Result ( false , hostAttributeName + " " + targetHostAttrVal + " already used for another co-task " + coTask ) ; } } } return new Result ( true , "" ) ; }
Determines whether a particular target host is appropriate for a particular task request by rejecting any host that has the same value for the unique constraint attribute as another host that is already assigned a co - task of the specified task request .