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/>.
//
2016-10-13 17:15:09 -04:00
package schedulers
2016-09-16 19:06:53 -04:00
import (
2016-10-07 19:29:36 -04:00
"fmt"
2018-09-30 18:23:38 -07:00
2018-01-19 17:46:35 -05:00
mesos "github.com/mesos/mesos-go/api/v0/mesosproto"
2016-09-16 19:06:53 -04:00
)
// NameFor returns the string name for a TaskState.
func NameFor ( state * mesos . TaskState ) string {
switch * state {
case mesos . TaskState_TASK_STAGING :
return "TASK_STAGING"
case mesos . TaskState_TASK_STARTING :
return "TASK_STARTING"
case mesos . TaskState_TASK_RUNNING :
return "TASK_RUNNING"
case mesos . TaskState_TASK_FINISHED :
return "TASK_FINISHED" // TERMINAL
case mesos . TaskState_TASK_FAILED :
return "TASK_FAILED" // TERMINAL
case mesos . TaskState_TASK_KILLED :
return "TASK_KILLED" // TERMINAL
case mesos . TaskState_TASK_LOST :
return "TASK_LOST" // TERMINAL
2016-10-07 19:29:36 -04:00
case mesos . TaskState_TASK_ERROR :
return "TASK_ERROR"
2016-09-16 19:06:53 -04:00
default :
2016-10-07 19:29:36 -04:00
return fmt . Sprintf ( "UNKNOWN: %d" , * state )
2016-09-16 19:06:53 -04:00
}
}
// IsTerminal determines if a TaskState is a terminal state, i.e. if it singals
// that the task has stopped running.
func IsTerminal ( state * mesos . TaskState ) bool {
switch * state {
case mesos . TaskState_TASK_FINISHED ,
mesos . TaskState_TASK_FAILED ,
mesos . TaskState_TASK_KILLED ,
2016-10-07 19:29:36 -04:00
mesos . TaskState_TASK_LOST ,
mesos . TaskState_TASK_ERROR :
2016-09-16 19:06:53 -04:00
return true
default :
return false
}
}