Files
poseidon/nomad/job.go
Konrad Hanff 3afcdeaba8 Execute commands in runner via WebSocket
This enables executing commands in runners and forwarding input and
output between the runner and the websocket to the client.

Co-authored-by: Maximilian Paß <maximilian.pass@student.hpi.uni-potsdam.de>
2021-05-31 12:32:51 +02:00

35 lines
1014 B
Go

package nomad
import (
"fmt"
nomadApi "github.com/hashicorp/nomad/api"
)
const (
TaskGroupNameFormat = "%s-group"
TaskName = "default-task"
)
// LoadJobList loads the list of jobs from the Nomad api.
func (nc *nomadApiClient) LoadJobList() (list []*nomadApi.JobListStub, err error) {
list, _, err = nc.client.Jobs().List(nil)
return
}
// JobScale returns the scale of the passed job.
func (nc *nomadApiClient) JobScale(jobId string) (jobScale int, err error) {
status, _, err := nc.client.Jobs().ScaleStatus(jobId, nil)
if err != nil {
return
}
// ToDo: Consider counting also the placed and desired allocations
jobScale = status.TaskGroups[fmt.Sprintf(TaskGroupNameFormat, jobId)].Running
return
}
// SetJobScale sets the scaling count of the passed job to Nomad.
func (nc *nomadApiClient) SetJobScale(jobId string, count int, reason string) (err error) {
_, _, err = nc.client.Jobs().Scale(jobId, fmt.Sprintf(TaskGroupNameFormat, jobId), &count, reason, false, nil, nil)
return
}