protected void checkResourceRequestLimit ( List < ResourceRequest > requestList , String handle ) throws InvalidSessionHandle { ConfigManager configManager = getScheduler ( ) . getConfigManager ( ) ; Session session = sessionManager . getSession ( handle ) ; PoolInfo poolInfo = session . getPoolInfo ( ) ; // Only check the resource requests if this pool is configured to not // accept more than a fixed number of requests at the same time if ( ! configManager . useRequestMax ( poolInfo ) ) { return ; } // Count the resources by type ResourceTypeCounter resourceTypeCounter = new ResourceTypeCounter ( ) ; for ( ResourceRequest req : requestList ) { resourceTypeCounter . incr ( req . type ) ; } // No resource type request should exceed the maximum for ( ResourceType resourceType : ResourceType . values ( ) ) { if ( configManager . getPoolMaximum ( poolInfo , resourceType ) < resourceTypeCounter . getCount ( resourceType ) ) { String failureMessage = "Session " + handle + " requested " + resourceTypeCounter . getCount ( resourceType ) + " resources for resource type " + resourceType + " but was only allowed " + configManager . getPoolMaximum ( poolInfo , resourceType ) + ", " + "so failing the job" ; LOG . error ( failureMessage ) ; throw new InvalidSessionHandle ( failureMessage ) ; } } }
Count the resources requested and fail the job if they are above the limit