Search in sources :

Example 1 with SlaveMatchState

use of com.hubspot.singularity.SlaveMatchState in project Singularity by HubSpot.

the class SingularityMesosOfferScheduler method score.

private double score(SingularityOfferHolder offerHolder, Map<String, Integer> tasksPerOffer, SingularityTaskRequestHolder taskRequestHolder, Optional<SingularitySlaveUsageWithCalculatedScores> maybeSlaveUsage, List<SingularityTaskId> activeTaskIdsForRequest) {
    final SingularityTaskRequest taskRequest = taskRequestHolder.getTaskRequest();
    final SingularityPendingTaskId pendingTaskId = taskRequest.getPendingTask().getPendingTaskId();
    if (tooManyTasksPerOfferHostForRequest(tasksPerOffer, offerHolder.getHostname(), taskRequestHolder.getTaskRequest())) {
        LOG.debug("Skipping task request for request id {}, too many tasks already scheduled using offer {}", taskRequest.getRequest().getId(), offerHolder.getHostname());
        return 0;
    }
    if (isTooManyInstancesForRequest(taskRequest, activeTaskIdsForRequest)) {
        LOG.debug("Skipping pending task {}, too many instances already running", pendingTaskId);
        return 0;
    }
    if (LOG.isTraceEnabled()) {
        LOG.trace("Attempting to match task {} resources {} with required role '{}' ({} for task + {} for executor) with remaining offer resources {}", pendingTaskId, taskRequestHolder.getTotalResources(), taskRequest.getRequest().getRequiredRole().or("*"), taskRequestHolder.getTaskResources(), taskRequestHolder.getExecutorResources(), MesosUtils.formatForLogging(offerHolder.getCurrentResources()));
    }
    final boolean matchesResources = MesosUtils.doesOfferMatchResources(taskRequest.getRequest().getRequiredRole(), taskRequestHolder.getTotalResources(), offerHolder.getCurrentResources(), taskRequestHolder.getRequestedPorts());
    if (!matchesResources) {
        return 0;
    }
    final SlaveMatchState slaveMatchState = slaveAndRackManager.doesOfferMatch(offerHolder, taskRequest, activeTaskIdsForRequest);
    if (slaveMatchState.isMatchAllowed()) {
        return score(offerHolder.getHostname(), taskRequest, maybeSlaveUsage);
    } else if (LOG.isTraceEnabled()) {
        LOG.trace("Ignoring offer on host {} with roles {} on {} for task {}; matched resources: {}, slave match state: {}", offerHolder.getHostname(), offerHolder.getRoles(), offerHolder.getHostname(), pendingTaskId, matchesResources, slaveMatchState);
    }
    return 0;
}
Also used : SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId) SingularityTaskRequest(com.hubspot.singularity.SingularityTaskRequest) SlaveMatchState(com.hubspot.singularity.SlaveMatchState)

Aggregations

SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)1 SingularityTaskRequest (com.hubspot.singularity.SingularityTaskRequest)1 SlaveMatchState (com.hubspot.singularity.SlaveMatchState)1