use of org.apache.pulsar.functions.proto.Function.Instance in project incubator-pulsar by apache.
the class RoundRobinScheduler method schedule.
@Override
public List<Assignment> schedule(List<Instance> unassignedFunctionInstances, List<Assignment> currentAssignments, List<String> workers) {
Map<String, List<Assignment>> workerIdToAssignment = new HashMap<>();
for (String workerId : workers) {
workerIdToAssignment.put(workerId, new LinkedList<>());
}
for (Assignment existingAssignment : currentAssignments) {
workerIdToAssignment.get(existingAssignment.getWorkerId()).add(existingAssignment);
}
for (Instance unassignedFunctionInstance : unassignedFunctionInstances) {
String workerId = findNextWorker(workerIdToAssignment);
Assignment newAssignment = Assignment.newBuilder().setInstance(unassignedFunctionInstance).setWorkerId(workerId).build();
workerIdToAssignment.get(workerId).add(newAssignment);
}
List<Assignment> assignments = workerIdToAssignment.entrySet().stream().flatMap(entry -> entry.getValue().stream()).collect(Collectors.toList());
return assignments;
}
Aggregations