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;
}
Aggregations