Move Nomad job creation to Nomad package
Previously, low level Nomad job creation was done in the environment manager. It used many functions of the nomad package so we felt like this logic better belongs to the nomad package.
This commit is contained in:

committed by
Maximilian Paß

parent
87f823756b
commit
ff582805b4
@@ -143,3 +143,32 @@ func (nc *nomadAPIClient) writeOptions() *nomadApi.WriteOptions {
|
||||
Namespace: nc.namespace,
|
||||
}
|
||||
}
|
||||
|
||||
// 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(nc.queryOptions())
|
||||
return
|
||||
}
|
||||
|
||||
// JobScale returns the scale of the passed job.
|
||||
func (nc *nomadAPIClient) JobScale(jobID string) (jobScale uint, err error) {
|
||||
status, _, err := nc.client.Jobs().ScaleStatus(jobID, nc.queryOptions())
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
// ToDo: Consider counting also the placed and desired allocations
|
||||
jobScale = uint(status.TaskGroups[TaskGroupName].Running)
|
||||
return
|
||||
}
|
||||
|
||||
// SetJobScale sets the scaling count of the passed job to Nomad.
|
||||
func (nc *nomadAPIClient) SetJobScale(jobID string, count uint, reason string) (err error) {
|
||||
intCount := int(count)
|
||||
_, _, err = nc.client.Jobs().Scale(jobID, TaskGroupName, &intCount, reason, false, nil, nil)
|
||||
return
|
||||
}
|
||||
|
||||
func (nc *nomadAPIClient) job(jobID string) (job *nomadApi.Job, err error) {
|
||||
job, _, err = nc.client.Jobs().Info(jobID, nil)
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user