The SimpleScheduler is a reference implementation of the si.SchedulerServer interface. It is used to demonstrate how to handle gRPC streams for managing resource managers, allocations, applications, and nodes within the YuniKorn ecosystem.
To implement a custom scheduler, you must satisfy the methods defined in the si.SchedulerServer interface, which include:
RegisterResourceManager: Handles the registration of a resource manager.UpdateAllocation: Manages a long-lived stream for allocation updates.UpdateApplication: Manages a long-lived stream for application updates.UpdateNode: Manages a long-lived stream for node updates.
Each stream-based method (UpdateAllocation, UpdateApplication, UpdateNode) follows a pattern of receiving data from the stream via conn.Recv(), processing it, and sending a response back via conn.Send() until the context is cancelled or an io.EOF is received.
type SimpleScheduler struct {
si.UnimplementedSchedulerServer
}
// Example method implementation for handling allocation updates
func (scheduler *SimpleScheduler) UpdateAllocation(conn si.Scheduler_UpdateAllocationServer) error {
ctx := conn.Context()
for {
select {
case <-ctx.Done():
return ctx.Err()
default:
}
_, err := conn.Recv()
if err == io.EOF {
return nil
}
if err != nil {
return err
}
resp := si.AllocationResponse{}
if err := conn.Send(&resp); err != nil {
return err
}
}
}