Store default Nomad job in apiClient to cache it
This commit is contained in:
@ -17,9 +17,9 @@ const (
|
|||||||
TaskNameFormat = "%s-task"
|
TaskNameFormat = "%s-task"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (apiClient *ApiClient) defaultJob() *nomadApi.Job {
|
func parseJob(jobHCL string) *nomadApi.Job {
|
||||||
config := jobspec2.ParseConfig{
|
config := jobspec2.ParseConfig{
|
||||||
Body: []byte(defaultJobHCL),
|
Body: []byte(jobHCL),
|
||||||
AllowFS: false,
|
AllowFS: false,
|
||||||
Strict: true,
|
Strict: true,
|
||||||
}
|
}
|
||||||
@ -119,14 +119,14 @@ func (apiClient *ApiClient) createJob(
|
|||||||
networkAccess bool,
|
networkAccess bool,
|
||||||
exposedPorts []uint16) *nomadApi.Job {
|
exposedPorts []uint16) *nomadApi.Job {
|
||||||
|
|
||||||
job := apiClient.defaultJob()
|
job := apiClient.defaultJob
|
||||||
job.ID = &id
|
job.ID = &id
|
||||||
job.Name = &id
|
job.Name = &id
|
||||||
|
|
||||||
var taskGroup = createTaskGroup(&job, fmt.Sprintf(TaskGroupNameFormat, id), prewarmingPoolSize)
|
var taskGroup = createTaskGroup(&job, fmt.Sprintf(TaskGroupNameFormat, id), prewarmingPoolSize)
|
||||||
configureTask(taskGroup, fmt.Sprintf(TaskNameFormat, id), cpuLimit, memoryLimit, image, networkAccess, exposedPorts)
|
configureTask(taskGroup, fmt.Sprintf(TaskNameFormat, id), cpuLimit, memoryLimit, image, networkAccess, exposedPorts)
|
||||||
|
|
||||||
return job
|
return &job
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadJobList loads the list of jobs from the Nomad api.
|
// LoadJobList loads the list of jobs from the Nomad api.
|
||||||
|
@ -19,6 +19,8 @@ type ExecutorApi interface {
|
|||||||
// ApiClient implements the ExecutorApi interface and can be used to perform different operations on the real Executor API and its return values.
|
// ApiClient implements the ExecutorApi interface and can be used to perform different operations on the real Executor API and its return values.
|
||||||
type ApiClient struct {
|
type ApiClient struct {
|
||||||
apiQuerier
|
apiQuerier
|
||||||
|
client *nomadApi.Client
|
||||||
|
defaultJob nomadApi.Job
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewExecutorApi creates a new api client.
|
// NewExecutorApi creates a new api client.
|
||||||
@ -35,7 +37,11 @@ func (apiClient *ApiClient) init(nomadURL *url.URL) (err error) {
|
|||||||
Address: nomadURL.String(),
|
Address: nomadURL.String(),
|
||||||
TLSConfig: &nomadApi.TLSConfig{},
|
TLSConfig: &nomadApi.TLSConfig{},
|
||||||
})
|
})
|
||||||
return err
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
apiClient.defaultJob = *parseJob(defaultJobHCL)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadRunners loads the allocations of the specified job.
|
// LoadRunners loads the allocations of the specified job.
|
||||||
|
Reference in New Issue
Block a user