2018-10-06 20:03:14 -07:00
// Copyright (C) 2018 spdf
//
// This file is part of Elektron.
//
// Elektron is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Elektron is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Elektron. If not, see <http://www.gnu.org/licenses/>.
//
2017-01-03 20:56:55 -05:00
package schedulers
import (
2018-01-19 21:20:43 +00:00
"bytes"
"fmt"
2018-09-30 18:23:38 -07:00
"log"
"sync"
"time"
2018-01-19 21:20:43 +00:00
"github.com/golang/protobuf/proto"
2018-01-19 17:46:35 -05:00
mesos "github.com/mesos/mesos-go/api/v0/mesosproto"
"github.com/mesos/mesos-go/api/v0/mesosutil"
sched "github.com/mesos/mesos-go/api/v0/scheduler"
2018-09-30 18:23:38 -07:00
"gitlab.com/spdf/elektron/def"
2018-10-04 13:45:31 -04:00
elekLogDef "gitlab.com/spdf/elektron/logging/def"
2018-09-30 18:23:38 -07:00
"gitlab.com/spdf/elektron/utilities"
"gitlab.com/spdf/elektron/utilities/schedUtils"
2017-01-03 20:56:55 -05:00
)
2018-01-30 14:12:37 -05:00
type BaseScheduler struct {
2017-09-26 13:17:47 -04:00
ElectronScheduler
2018-01-19 21:20:43 +00:00
SchedPolicyContext
// Current scheduling policy used for resource offer consumption.
curSchedPolicy SchedPolicyState
2018-02-05 18:21:34 -05:00
tasksCreated int
tasksRunning int
tasks [ ] def . Task
metrics map [ string ] def . Metric
Running map [ string ] map [ string ] bool
wattsAsAResource bool
classMapWatts bool
TasksRunningMutex sync . Mutex
HostNameToSlaveID map [ string ] string
totalResourceAvailabilityRecorded bool
2017-02-09 20:27:18 -05:00
// First set of PCP values are garbage values, signal to logger to start recording when we're
2018-01-19 21:20:43 +00:00
// about to schedule a new task
2017-09-26 13:17:47 -04:00
RecordPCP * bool
2017-02-09 20:27:18 -05:00
// This channel is closed when the program receives an interrupt,
// signalling that the program should shut down.
Shutdown chan struct { }
// This channel is closed after shutdown is closed, and only when all
2017-09-28 15:36:47 -04:00
// outstanding tasks have been cleaned up.
2017-02-09 20:27:18 -05:00
Done chan struct { }
2017-09-28 15:36:47 -04:00
// Controls when to shutdown pcp logging.
2017-02-09 20:27:18 -05:00
PCPLog chan struct { }
schedTrace * log . Logger
2018-01-19 21:20:43 +00:00
// Send the type of the message to be logged
2018-10-04 13:45:31 -04:00
logMsgType chan elekLogDef . LogMessageType
2018-01-19 21:20:43 +00:00
// Send the message to be logged
logMsg chan string
mutex sync . Mutex
// Whether switching of scheduling policies at runtime has been enabled
schedPolSwitchEnabled bool
2018-04-17 20:09:35 +00:00
// Name of the first scheduling policy to be deployed, if provided.
// This scheduling policy would be deployed first regardless of the distribution of tasks in the TaskQueue.
// Note: Scheduling policy switching needs to be enabled.
nameOfFstSchedPolToDeploy string
2018-04-17 23:44:36 +00:00
// Scheduling policy switching criteria.
schedPolSwitchCriteria string
2018-01-31 19:00:31 -05:00
// Size of window of tasks that can be scheduled in the next offer cycle.
// The window size can be adjusted to make the most use of every resource offer.
2018-02-16 21:49:12 +00:00
// By default, the schedWindowSize would correspond to the number of remaining tasks that haven't yet
// been scheduled.
schedWindowSize int
// Number of tasks in the window
numTasksInSchedWindow int
2018-01-31 19:00:31 -05:00
2018-04-17 20:12:33 +00:00
// Whether the scheduling window needs to be fixed.
toFixSchedWindow bool // If yes, then schedWindowSize is initialized and kept unchanged.
2018-02-02 17:06:59 -05:00
// Strategy to resize the schedulingWindow.
schedWindowResStrategy schedUtils . SchedWindowResizingStrategy
2018-02-06 16:50:16 -05:00
// Indicate whether the any resource offers from mesos have been received.
hasReceivedResourceOffers bool
2017-02-09 20:27:18 -05:00
}
2017-01-03 20:56:55 -05:00
2018-10-04 19:24:16 -04:00
func ( s * BaseScheduler ) init ( opts ... SchedulerOptions ) {
2017-09-26 13:17:47 -04:00
for _ , opt := range opts {
2018-01-19 21:20:43 +00:00
// applying options
2017-09-26 13:17:47 -04:00
if err := opt ( s ) ; err != nil {
log . Fatal ( err )
}
}
2018-02-05 02:18:33 -05:00
s . TasksRunningMutex . Lock ( )
2018-02-02 19:24:51 -05:00
s . Running = make ( map [ string ] map [ string ] bool )
2018-02-05 02:18:33 -05:00
s . TasksRunningMutex . Unlock ( )
2018-02-02 19:24:51 -05:00
s . HostNameToSlaveID = make ( map [ string ] string )
2018-01-19 21:20:43 +00:00
s . mutex = sync . Mutex { }
2018-02-02 17:06:59 -05:00
s . schedWindowResStrategy = schedUtils . SchedWindowResizingCritToStrategy [ "fillNextOfferCycle" ]
2018-02-06 16:50:16 -05:00
// Initially no resource offers would have been received.
s . hasReceivedResourceOffers = false
2017-09-26 13:17:47 -04:00
}
2018-01-30 14:12:37 -05:00
func ( s * BaseScheduler ) SwitchSchedPol ( newSchedPol SchedPolicyState ) {
2018-01-19 21:20:43 +00:00
s . curSchedPolicy = newSchedPol
2017-01-03 20:56:55 -05:00
}
2018-01-19 21:20:43 +00:00
2018-01-30 14:12:37 -05:00
func ( s * BaseScheduler ) newTask ( offer * mesos . Offer , task def . Task ) * mesos . TaskInfo {
2018-01-19 21:20:43 +00:00
taskName := fmt . Sprintf ( "%s-%d" , task . Name , * task . Instances )
s . tasksCreated ++
if ! * s . RecordPCP {
// Turn on elecLogDef
* s . RecordPCP = true
time . Sleep ( 1 * time . Second ) // Make sure we're recording by the time the first task starts
}
resources := [ ] * mesos . Resource {
mesosutil . NewScalarResource ( "cpus" , task . CPU ) ,
mesosutil . NewScalarResource ( "mem" , task . RAM ) ,
}
if s . wattsAsAResource {
if wattsToConsider , err := def . WattsToConsider ( task , s . classMapWatts , offer ) ; err == nil {
s . LogTaskWattsConsideration ( task , * offer . Hostname , wattsToConsider )
resources = append ( resources , mesosutil . NewScalarResource ( "watts" , wattsToConsider ) )
} else {
// Error in determining wattsConsideration
s . LogElectronError ( err )
}
}
return & mesos . TaskInfo {
Name : proto . String ( taskName ) ,
TaskId : & mesos . TaskID {
Value : proto . String ( "electron-" + taskName ) ,
} ,
SlaveId : offer . SlaveId ,
Resources : resources ,
Command : & mesos . CommandInfo {
Value : proto . String ( task . CMD ) ,
} ,
Container : & mesos . ContainerInfo {
Type : mesos . ContainerInfo_DOCKER . Enum ( ) ,
Docker : & mesos . ContainerInfo_DockerInfo {
Image : proto . String ( task . Image ) ,
Network : mesos . ContainerInfo_DockerInfo_BRIDGE . Enum ( ) , // Run everything isolated
} ,
} ,
}
2017-01-03 20:56:55 -05:00
}
2018-01-19 21:20:43 +00:00
2018-01-30 14:12:37 -05:00
func ( s * BaseScheduler ) OfferRescinded ( _ sched . SchedulerDriver , offerID * mesos . OfferID ) {
2018-01-19 21:20:43 +00:00
s . LogOfferRescinded ( offerID )
}
2018-01-30 14:12:37 -05:00
func ( s * BaseScheduler ) SlaveLost ( _ sched . SchedulerDriver , slaveID * mesos . SlaveID ) {
2018-01-19 21:20:43 +00:00
s . LogSlaveLost ( slaveID )
}
2018-01-30 14:12:37 -05:00
func ( s * BaseScheduler ) ExecutorLost ( _ sched . SchedulerDriver , executorID * mesos . ExecutorID ,
2017-01-03 20:56:55 -05:00
slaveID * mesos . SlaveID , status int ) {
2018-01-19 21:20:43 +00:00
s . LogExecutorLost ( executorID , slaveID )
2017-01-03 20:56:55 -05:00
}
2018-01-30 14:12:37 -05:00
func ( s * BaseScheduler ) Error ( _ sched . SchedulerDriver , err string ) {
2018-01-19 21:20:43 +00:00
s . LogMesosError ( err )
2017-01-03 20:56:55 -05:00
}
2018-01-30 14:12:37 -05:00
func ( s * BaseScheduler ) FrameworkMessage (
2017-01-03 20:56:55 -05:00
driver sched . SchedulerDriver ,
executorID * mesos . ExecutorID ,
slaveID * mesos . SlaveID ,
message string ) {
2018-01-19 21:20:43 +00:00
s . LogFrameworkMessage ( executorID , slaveID , message )
2017-01-03 20:56:55 -05:00
}
2018-01-30 14:12:37 -05:00
func ( s * BaseScheduler ) Registered (
2017-01-03 20:56:55 -05:00
_ sched . SchedulerDriver ,
frameworkID * mesos . FrameworkID ,
masterInfo * mesos . MasterInfo ) {
2018-01-19 21:20:43 +00:00
s . LogFrameworkRegistered ( frameworkID , masterInfo )
}
2018-01-30 14:12:37 -05:00
func ( s * BaseScheduler ) Reregistered ( _ sched . SchedulerDriver , masterInfo * mesos . MasterInfo ) {
2018-01-19 21:20:43 +00:00
s . LogFrameworkReregistered ( masterInfo )
}
2018-01-30 14:12:37 -05:00
func ( s * BaseScheduler ) Disconnected ( sched . SchedulerDriver ) {
2018-01-19 21:20:43 +00:00
s . LogDisconnected ( )
}
2018-01-30 14:12:37 -05:00
func ( s * BaseScheduler ) ResourceOffers ( driver sched . SchedulerDriver , offers [ ] * mesos . Offer ) {
2018-02-16 21:49:12 +00:00
// Recording the total amount of resources available across the cluster.
2018-02-09 22:32:44 +00:00
utilities . RecordTotalResourceAvailability ( offers )
2018-02-02 19:24:51 -05:00
for _ , offer := range offers {
if _ , ok := s . HostNameToSlaveID [ offer . GetHostname ( ) ] ; ! ok {
2018-03-01 21:57:50 +00:00
s . HostNameToSlaveID [ offer . GetHostname ( ) ] = * offer . SlaveId . Value
2018-02-02 19:24:51 -05:00
}
}
2018-04-17 20:09:35 +00:00
// Switch just before consuming the resource offers.
s . curSchedPolicy . SwitchIfNecessary ( s )
2018-04-17 23:44:36 +00:00
// s.Log(elecLogDef.GENERAL, fmt.Sprintf("SchedWindowSize[%d], #TasksInWindow[%d]",
// s.schedWindowSize, s.numTasksInSchedWindow))
2018-01-19 21:20:43 +00:00
s . curSchedPolicy . ConsumeOffers ( s , driver , offers )
2018-02-06 16:50:16 -05:00
s . hasReceivedResourceOffers = true
2018-01-19 21:20:43 +00:00
}
2018-01-30 14:12:37 -05:00
func ( s * BaseScheduler ) StatusUpdate ( driver sched . SchedulerDriver , status * mesos . TaskStatus ) {
2018-01-19 21:20:43 +00:00
s . LogTaskStatusUpdate ( status )
if * status . State == mesos . TaskState_TASK_RUNNING {
2018-03-01 21:57:50 +00:00
// If this is our first time running into this Agent
s . TasksRunningMutex . Lock ( )
if _ , ok := s . Running [ * status . SlaveId . Value ] ; ! ok {
s . Running [ * status . SlaveId . Value ] = make ( map [ string ] bool )
}
// Add task to list of tasks running on node
s . Running [ * status . SlaveId . Value ] [ * status . TaskId . Value ] = true
2018-01-19 21:20:43 +00:00
s . tasksRunning ++
2018-04-17 23:44:36 +00:00
s . TasksRunningMutex . Unlock ( )
2018-01-19 21:20:43 +00:00
} else if IsTerminal ( status . State ) {
2018-02-09 22:32:44 +00:00
// Update resource availability.
utilities . ResourceAvailabilityUpdate ( "ON_TASK_TERMINAL_STATE" ,
* status . TaskId , * status . SlaveId )
2018-02-02 19:24:51 -05:00
s . TasksRunningMutex . Lock ( )
2018-03-01 21:57:50 +00:00
delete ( s . Running [ * status . SlaveId . Value ] , * status . TaskId . Value )
2018-01-19 21:20:43 +00:00
s . tasksRunning --
2018-04-17 23:44:36 +00:00
s . TasksRunningMutex . Unlock ( )
2018-01-19 21:20:43 +00:00
if s . tasksRunning == 0 {
select {
case <- s . Shutdown :
close ( s . Done )
default :
}
}
}
}
2018-10-04 13:45:31 -04:00
func ( s * BaseScheduler ) Log ( lmt elekLogDef . LogMessageType , msg string ) {
2018-01-19 21:20:43 +00:00
s . mutex . Lock ( )
s . logMsgType <- lmt
s . logMsg <- msg
s . mutex . Unlock ( )
}
2018-01-30 14:12:37 -05:00
func ( s * BaseScheduler ) LogTaskStarting ( ts * def . Task , offer * mesos . Offer ) {
2018-10-04 13:45:31 -04:00
lmt := elekLogDef . GENERAL
msgColor := elekLogDef . LogMessageColors [ lmt ]
2018-01-19 21:20:43 +00:00
var msg string
if ts == nil {
msg = msgColor . Sprintf ( "TASKS STARTING... host = [%s]" , offer . GetHostname ( ) )
} else {
msg = msgColor . Sprintf ( "TASK STARTING... task = [%s], Instance = %d, host = [%s]" ,
ts . Name , * ts . Instances , offer . GetHostname ( ) )
}
s . Log ( lmt , msg )
}
2018-01-30 14:12:37 -05:00
func ( s * BaseScheduler ) LogTaskWattsConsideration ( ts def . Task , host string , wattsToConsider float64 ) {
2018-10-04 13:45:31 -04:00
lmt := elekLogDef . GENERAL
msgColor := elekLogDef . LogMessageColors [ lmt ]
2018-01-19 21:20:43 +00:00
msg := msgColor . Sprintf ( "Watts considered for task[%s] and host[%s] = %f Watts" ,
ts . Name , host , wattsToConsider )
s . Log ( lmt , msg )
}
2018-01-30 14:12:37 -05:00
func ( s * BaseScheduler ) LogOffersReceived ( offers [ ] * mesos . Offer ) {
2018-10-04 13:45:31 -04:00
lmt := elekLogDef . GENERAL
msgColor := elekLogDef . LogMessageColors [ lmt ]
2018-01-19 21:20:43 +00:00
msg := msgColor . Sprintf ( "Received %d resource offers" , len ( offers ) )
s . Log ( lmt , msg )
}
2018-01-30 14:12:37 -05:00
func ( s * BaseScheduler ) LogNoPendingTasksDeclineOffers ( offer * mesos . Offer ) {
2018-10-04 13:45:31 -04:00
lmt := elekLogDef . WARNING
msgColor := elekLogDef . LogMessageColors [ lmt ]
2018-01-19 21:20:43 +00:00
msg := msgColor . Sprintf ( "DECLINING OFFER for host[%s]... " +
"No tasks left to schedule" , offer . GetHostname ( ) )
s . Log ( lmt , msg )
}
2018-01-30 14:12:37 -05:00
func ( s * BaseScheduler ) LogNumberOfRunningTasks ( ) {
2018-10-04 13:45:31 -04:00
lmt := elekLogDef . GENERAL
msgColor := elekLogDef . LogMessageColors [ lmt ]
2018-02-02 19:24:51 -05:00
msg := msgColor . Sprintf ( "Number of tasks still Running = %d" , s . tasksRunning )
2018-01-19 21:20:43 +00:00
s . Log ( lmt , msg )
}
2018-01-30 14:12:37 -05:00
func ( s * BaseScheduler ) LogCoLocatedTasks ( slaveID string ) {
2018-10-04 13:45:31 -04:00
lmt := elekLogDef . GENERAL
msgColor := elekLogDef . LogMessageColors [ lmt ]
2018-01-19 21:20:43 +00:00
buffer := bytes . Buffer { }
buffer . WriteString ( fmt . Sprintln ( "Colocated with:" ) )
2018-02-02 19:24:51 -05:00
s . TasksRunningMutex . Lock ( )
for taskName := range s . Running [ slaveID ] {
2018-01-19 21:20:43 +00:00
buffer . WriteString ( fmt . Sprintln ( taskName ) )
}
2018-02-02 19:24:51 -05:00
s . TasksRunningMutex . Unlock ( )
2018-01-19 21:20:43 +00:00
msg := msgColor . Sprintf ( buffer . String ( ) )
s . Log ( lmt , msg )
}
2018-01-30 14:12:37 -05:00
func ( s * BaseScheduler ) LogSchedTrace ( taskToSchedule * mesos . TaskInfo , offer * mesos . Offer ) {
2018-01-19 21:20:43 +00:00
msg := fmt . Sprint ( offer . GetHostname ( ) + ":" + taskToSchedule . GetTaskId ( ) . GetValue ( ) )
2018-10-04 13:45:31 -04:00
s . Log ( elekLogDef . SCHED_TRACE , msg )
2018-01-19 21:20:43 +00:00
}
2018-01-30 14:12:37 -05:00
func ( s * BaseScheduler ) LogTerminateScheduler ( ) {
2018-10-04 13:45:31 -04:00
lmt := elekLogDef . GENERAL
msgColor := elekLogDef . LogMessageColors [ lmt ]
2018-01-19 21:20:43 +00:00
msg := msgColor . Sprint ( "Done scheduling all tasks!" )
s . Log ( lmt , msg )
}
2018-01-30 14:12:37 -05:00
func ( s * BaseScheduler ) LogInsufficientResourcesDeclineOffer ( offer * mesos . Offer ,
2018-01-19 21:20:43 +00:00
offerResources ... interface { } ) {
2018-10-04 13:45:31 -04:00
lmt := elekLogDef . WARNING
msgColor := elekLogDef . LogMessageColors [ lmt ]
2018-01-19 21:20:43 +00:00
buffer := bytes . Buffer { }
buffer . WriteString ( fmt . Sprintln ( "DECLINING OFFER... Offer has insufficient resources to launch a task" ) )
buffer . WriteString ( fmt . Sprintf ( "Offer Resources <CPU: %f, RAM: %f, Watts: %f>" , offerResources ... ) )
msg := msgColor . Sprint ( buffer . String ( ) )
s . Log ( lmt , msg )
}
2018-01-30 14:12:37 -05:00
func ( s * BaseScheduler ) LogOfferRescinded ( offerID * mesos . OfferID ) {
2018-10-04 13:45:31 -04:00
lmt := elekLogDef . ERROR
msgColor := elekLogDef . LogMessageColors [ lmt ]
2018-01-19 21:20:43 +00:00
msg := msgColor . Sprintf ( "OFFER RESCINDED: OfferID = %s" , offerID )
s . Log ( lmt , msg )
}
2018-01-30 14:12:37 -05:00
func ( s * BaseScheduler ) LogSlaveLost ( slaveID * mesos . SlaveID ) {
2018-10-04 13:45:31 -04:00
lmt := elekLogDef . ERROR
msgColor := elekLogDef . LogMessageColors [ lmt ]
2018-01-19 21:20:43 +00:00
msg := msgColor . Sprintf ( "SLAVE LOST: SlaveID = %s" , slaveID )
s . Log ( lmt , msg )
}
2018-01-30 14:12:37 -05:00
func ( s * BaseScheduler ) LogExecutorLost ( executorID * mesos . ExecutorID , slaveID * mesos . SlaveID ) {
2018-10-04 13:45:31 -04:00
lmt := elekLogDef . ERROR
msgColor := elekLogDef . LogMessageColors [ lmt ]
2018-01-19 21:20:43 +00:00
msg := msgColor . Sprintf ( "EXECUTOR LOST: ExecutorID = %s, SlaveID = %s" , executorID , slaveID )
s . Log ( lmt , msg )
}
2018-01-30 14:12:37 -05:00
func ( s * BaseScheduler ) LogFrameworkMessage ( executorID * mesos . ExecutorID ,
2018-01-19 21:20:43 +00:00
slaveID * mesos . SlaveID , message string ) {
2018-10-04 13:45:31 -04:00
lmt := elekLogDef . GENERAL
msgColor := elekLogDef . LogMessageColors [ lmt ]
2018-01-19 21:20:43 +00:00
msg := msgColor . Sprintf ( "Received Framework message from executor [%s]: %s" , executorID , message )
s . Log ( lmt , msg )
}
2018-01-30 14:12:37 -05:00
func ( s * BaseScheduler ) LogMesosError ( err string ) {
2018-10-04 13:45:31 -04:00
lmt := elekLogDef . ERROR
msgColor := elekLogDef . LogMessageColors [ lmt ]
2018-01-19 21:20:43 +00:00
msg := msgColor . Sprintf ( "MESOS ERROR: %s" , err )
s . Log ( lmt , msg )
}
2018-01-30 14:12:37 -05:00
func ( s * BaseScheduler ) LogElectronError ( err error ) {
2018-10-04 13:45:31 -04:00
lmt := elekLogDef . ERROR
msgColor := elekLogDef . LogMessageColors [ lmt ]
2018-01-19 21:20:43 +00:00
msg := msgColor . Sprintf ( "ELECTRON ERROR: %v" , err )
s . Log ( lmt , msg )
}
2018-01-30 14:12:37 -05:00
func ( s * BaseScheduler ) LogFrameworkRegistered ( frameworkID * mesos . FrameworkID ,
2018-01-19 21:20:43 +00:00
masterInfo * mesos . MasterInfo ) {
2018-10-04 13:45:31 -04:00
lmt := elekLogDef . SUCCESS
msgColor := elekLogDef . LogMessageColors [ lmt ]
2018-01-19 21:20:43 +00:00
msg := msgColor . Sprintf ( "FRAMEWORK REGISTERED! frameworkID = %s, master = %s" ,
frameworkID , masterInfo )
s . Log ( lmt , msg )
}
2018-01-30 14:12:37 -05:00
func ( s * BaseScheduler ) LogFrameworkReregistered ( masterInfo * mesos . MasterInfo ) {
2018-10-04 13:45:31 -04:00
lmt := elekLogDef . GENERAL
msgColor := elekLogDef . LogMessageColors [ lmt ]
2018-01-19 21:20:43 +00:00
msg := msgColor . Sprintf ( "Framework re-registered with master %s" , masterInfo )
s . Log ( lmt , msg )
2017-01-03 20:56:55 -05:00
}
2018-01-30 14:12:37 -05:00
func ( s * BaseScheduler ) LogDisconnected ( ) {
2018-10-04 13:45:31 -04:00
lmt := elekLogDef . WARNING
msgColor := elekLogDef . LogMessageColors [ lmt ]
2018-01-19 21:20:43 +00:00
msg := msgColor . Sprint ( "Framework disconnected with master" )
s . Log ( lmt , msg )
2017-01-03 20:56:55 -05:00
}
2018-01-30 14:12:37 -05:00
func ( s * BaseScheduler ) LogTaskStatusUpdate ( status * mesos . TaskStatus ) {
2018-10-04 13:45:31 -04:00
var lmt elekLogDef . LogMessageType
2018-01-19 21:20:43 +00:00
switch * status . State {
case mesos . TaskState_TASK_ERROR , mesos . TaskState_TASK_FAILED ,
mesos . TaskState_TASK_KILLED , mesos . TaskState_TASK_LOST :
2018-10-04 13:45:31 -04:00
lmt = elekLogDef . ERROR
2018-01-19 21:20:43 +00:00
case mesos . TaskState_TASK_FINISHED :
2018-10-04 13:45:31 -04:00
lmt = elekLogDef . SUCCESS
2018-01-19 21:20:43 +00:00
default :
2018-10-04 13:45:31 -04:00
lmt = elekLogDef . GENERAL
2018-01-19 21:20:43 +00:00
}
2018-10-04 13:45:31 -04:00
msgColor := elekLogDef . LogMessageColors [ lmt ]
msg := elekLogDef . LogMessageColors [ elekLogDef . GENERAL ] . Sprintf ( "Task Status received for task [%s] --> %s" ,
2018-01-19 21:20:43 +00:00
* status . TaskId . Value , msgColor . Sprint ( NameFor ( status . State ) ) )
s . Log ( lmt , msg )
2017-01-03 20:56:55 -05:00
}
2018-02-11 13:11:42 +00:00
2018-04-17 23:44:36 +00:00
func ( s * BaseScheduler ) LogSchedPolicySwitch ( name string , nextPolicy SchedPolicyState ) {
logSPS := func ( ) {
2018-10-04 13:45:31 -04:00
s . Log ( elekLogDef . SPS , name )
2018-04-17 20:12:33 +00:00
}
if s . hasReceivedResourceOffers && ( s . curSchedPolicy != nextPolicy ) {
2018-04-17 23:44:36 +00:00
logSPS ( )
2018-04-17 20:12:33 +00:00
} else if ! s . hasReceivedResourceOffers {
2018-04-17 23:44:36 +00:00
logSPS ( )
2018-02-11 13:11:42 +00:00
}
2018-04-17 23:44:36 +00:00
// Logging the size of the scheduling window and the scheduling policy
// that is going to schedule the tasks in the scheduling window.
2018-10-04 13:45:31 -04:00
s . Log ( elekLogDef . SCHED_WINDOW , fmt . Sprintf ( "%d %s" , s . schedWindowSize , name ) )
2018-02-11 13:11:42 +00:00
}
2018-04-17 20:10:36 +00:00
func ( s * BaseScheduler ) LogClsfnAndTaskDistOverhead ( overhead time . Duration ) {
// Logging the overhead in microseconds.
2018-10-04 13:45:31 -04:00
s . Log ( elekLogDef . CLSFN_TASKDIST_OVERHEAD , fmt . Sprintf ( "%f" , float64 ( overhead . Nanoseconds ( ) ) / 1000.0 ) )
2018-04-17 20:10:36 +00:00
}