Search in sources :

Example 11 with ValueRange

use of com.microsoft.frameworklauncher.common.model.ValueRange in project pai by Microsoft.

the class SelectionManager method select.

public synchronized SelectionResult select(String taskRoleName) throws NotAvailableException {
    ResourceDescriptor requestResource = requestManager.getTaskResources().get(taskRoleName);
    LOGGER.logInfo("Select: TaskRole: [%s] Resource: [%s]", taskRoleName, requestResource);
    String requestNodeLabel = requestManager.getTaskPlatParams().get(taskRoleName).getTaskNodeLabel();
    String requestNodeGpuType = requestManager.getTaskPlatParams().get(taskRoleName).getTaskNodeGpuType();
    Map<String, NodeConfiguration> configuredNodes = requestManager.getClusterConfiguration().getNodes();
    int startStatesTaskCount = statusManager.getStartStatesTaskCount(taskRoleName);
    List<ValueRange> reusePorts = null;
    // Prefer to use previous successfully associated ports. if no associated ports, try to reuse the "Requesting" ports.
    if (requestManager.getTaskRoles().get(taskRoleName).getUseTheSamePorts()) {
        reusePorts = statusManager.getLiveAssociatedContainerPorts(taskRoleName);
        if (ValueRangeUtils.getValueNumber(reusePorts) <= 0 && previousRequestedPorts.containsKey(taskRoleName)) {
            reusePorts = previousRequestedPorts.get(taskRoleName);
            // the cache only guide the next task to use previous requesting port.
            previousRequestedPorts.remove(taskRoleName);
        }
    }
    SelectionResult result = select(requestResource, requestNodeLabel, requestNodeGpuType, startStatesTaskCount, reusePorts, configuredNodes);
    if (requestManager.getTaskRoles().get(taskRoleName).getUseTheSamePorts()) {
        // reusePortsTimes time is used to avoid startStatesTaskCount not decrease in the situation of timeout tasks back to startStates.
        if (startStatesTaskCount > 1) {
            if (reusePortsTimes == 0) {
                reusePortsTimes = startStatesTaskCount;
            }
            // If there has other tasks waiting, push current ports to previousRequestedPorts.
            if (reusePortsTimes > 1) {
                previousRequestedPorts.put(taskRoleName, result.getOptimizedResource().getPortRanges());
            }
            reusePortsTimes--;
        }
    }
    return result;
}
Also used : ValueRange(com.microsoft.frameworklauncher.common.model.ValueRange) NodeConfiguration(com.microsoft.frameworklauncher.common.model.NodeConfiguration) ResourceDescriptor(com.microsoft.frameworklauncher.common.model.ResourceDescriptor)

Aggregations

ValueRange (com.microsoft.frameworklauncher.common.model.ValueRange)11 Ports (com.microsoft.frameworklauncher.common.model.Ports)2 ResourceDescriptor (com.microsoft.frameworklauncher.common.model.ResourceDescriptor)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 NotAvailableException (com.microsoft.frameworklauncher.common.exceptions.NotAvailableException)1 NodeConfiguration (com.microsoft.frameworklauncher.common.model.NodeConfiguration)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1