From 8950ce29d8b75d172c58a2f910a2a3af62791e1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Pa=C3=9F?= <22845248+mpass99@users.noreply.github.com> Date: Fri, 31 Mar 2023 17:26:44 +0100 Subject: [PATCH] Recover Runner Allocations on startup. --- internal/nomad/api_querier.go | 13 +- internal/nomad/api_querier_mock.go | 341 +--------------- internal/nomad/executor_api_mock.go | 602 +--------------------------- internal/nomad/nomad.go | 32 +- internal/nomad/nomad_test.go | 10 +- 5 files changed, 89 insertions(+), 909 deletions(-) diff --git a/internal/nomad/api_querier.go b/internal/nomad/api_querier.go index 3e487ab..9c98cab 100644 --- a/internal/nomad/api_querier.go +++ b/internal/nomad/api_querier.go @@ -39,11 +39,14 @@ type apiQuerier interface { stdin io.Reader, stdout, stderr io.Writer) (int, error) // listJobs loads all jobs with the specified prefix. - listJobs(prefix string) (allocationListStub []*nomadApi.JobListStub, err error) + listJobs(prefix string) (jobListStub []*nomadApi.JobListStub, err error) // job returns the job of the given jobID. job(jobID string) (job *nomadApi.Job, err error) + // listAllocations loads all allocations. + listAllocations() (allocationListStub []*nomadApi.AllocationListStub, err error) + // allocation returns the first allocation of the given job. allocation(jobID string) (*nomadApi.Allocation, error) @@ -228,6 +231,14 @@ func (nc *nomadAPIClient) job(jobID string) (job *nomadApi.Job, err error) { return } +func (nc *nomadAPIClient) listAllocations() ([]*nomadApi.AllocationListStub, error) { + allocationListStubs, _, err := nc.client.Allocations().List(nc.queryOptions()) + if err != nil { + return nil, fmt.Errorf("error listing Nomad allocations: %w", err) + } + return allocationListStubs, nil +} + func (nc *nomadAPIClient) allocation(jobID string) (alloc *nomadApi.Allocation, err error) { allocs, _, err := nc.client.Jobs().Allocations(jobID, false, nil) if err != nil { diff --git a/internal/nomad/api_querier_mock.go b/internal/nomad/api_querier_mock.go index 075226a..728e842 100644 --- a/internal/nomad/api_querier_mock.go +++ b/internal/nomad/api_querier_mock.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.21.0. DO NOT EDIT. +// Code generated by mockery v2.23.1. DO NOT EDIT. package nomad @@ -18,14 +18,6 @@ type apiQuerierMock struct { mock.Mock } -type apiQuerierMock_Expecter struct { - mock *mock.Mock -} - -func (_m *apiQuerierMock) EXPECT() *apiQuerierMock_Expecter { - return &apiQuerierMock_Expecter{mock: &_m.Mock} -} - // DeleteJob provides a mock function with given fields: jobID func (_m *apiQuerierMock) DeleteJob(jobID string) error { ret := _m.Called(jobID) @@ -40,34 +32,6 @@ func (_m *apiQuerierMock) DeleteJob(jobID string) error { return r0 } -// apiQuerierMock_DeleteJob_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteJob' -type apiQuerierMock_DeleteJob_Call struct { - *mock.Call -} - -// DeleteJob is a helper method to define mock.On call -// - jobID string -func (_e *apiQuerierMock_Expecter) DeleteJob(jobID interface{}) *apiQuerierMock_DeleteJob_Call { - return &apiQuerierMock_DeleteJob_Call{Call: _e.mock.On("DeleteJob", jobID)} -} - -func (_c *apiQuerierMock_DeleteJob_Call) Run(run func(jobID string)) *apiQuerierMock_DeleteJob_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string)) - }) - return _c -} - -func (_c *apiQuerierMock_DeleteJob_Call) Return(err error) *apiQuerierMock_DeleteJob_Call { - _c.Call.Return(err) - return _c -} - -func (_c *apiQuerierMock_DeleteJob_Call) RunAndReturn(run func(string) error) *apiQuerierMock_DeleteJob_Call { - _c.Call.Return(run) - return _c -} - // EventStream provides a mock function with given fields: ctx func (_m *apiQuerierMock) EventStream(ctx context.Context) (<-chan *api.Events, error) { ret := _m.Called(ctx) @@ -94,34 +58,6 @@ func (_m *apiQuerierMock) EventStream(ctx context.Context) (<-chan *api.Events, return r0, r1 } -// apiQuerierMock_EventStream_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'EventStream' -type apiQuerierMock_EventStream_Call struct { - *mock.Call -} - -// EventStream is a helper method to define mock.On call -// - ctx context.Context -func (_e *apiQuerierMock_Expecter) EventStream(ctx interface{}) *apiQuerierMock_EventStream_Call { - return &apiQuerierMock_EventStream_Call{Call: _e.mock.On("EventStream", ctx)} -} - -func (_c *apiQuerierMock_EventStream_Call) Run(run func(ctx context.Context)) *apiQuerierMock_EventStream_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context)) - }) - return _c -} - -func (_c *apiQuerierMock_EventStream_Call) Return(_a0 <-chan *api.Events, _a1 error) *apiQuerierMock_EventStream_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *apiQuerierMock_EventStream_Call) RunAndReturn(run func(context.Context) (<-chan *api.Events, error)) *apiQuerierMock_EventStream_Call { - _c.Call.Return(run) - return _c -} - // Execute provides a mock function with given fields: jobID, ctx, command, tty, stdin, stdout, stderr func (_m *apiQuerierMock) Execute(jobID string, ctx context.Context, command string, tty bool, stdin io.Reader, stdout io.Writer, stderr io.Writer) (int, error) { ret := _m.Called(jobID, ctx, command, tty, stdin, stdout, stderr) @@ -146,40 +82,6 @@ func (_m *apiQuerierMock) Execute(jobID string, ctx context.Context, command str return r0, r1 } -// apiQuerierMock_Execute_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Execute' -type apiQuerierMock_Execute_Call struct { - *mock.Call -} - -// Execute is a helper method to define mock.On call -// - jobID string -// - ctx context.Context -// - command string -// - tty bool -// - stdin io.Reader -// - stdout io.Writer -// - stderr io.Writer -func (_e *apiQuerierMock_Expecter) Execute(jobID interface{}, ctx interface{}, command interface{}, tty interface{}, stdin interface{}, stdout interface{}, stderr interface{}) *apiQuerierMock_Execute_Call { - return &apiQuerierMock_Execute_Call{Call: _e.mock.On("Execute", jobID, ctx, command, tty, stdin, stdout, stderr)} -} - -func (_c *apiQuerierMock_Execute_Call) Run(run func(jobID string, ctx context.Context, command string, tty bool, stdin io.Reader, stdout io.Writer, stderr io.Writer)) *apiQuerierMock_Execute_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(context.Context), args[2].(string), args[3].(bool), args[4].(io.Reader), args[5].(io.Writer), args[6].(io.Writer)) - }) - return _c -} - -func (_c *apiQuerierMock_Execute_Call) Return(_a0 int, _a1 error) *apiQuerierMock_Execute_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *apiQuerierMock_Execute_Call) RunAndReturn(run func(string, context.Context, string, bool, io.Reader, io.Writer, io.Writer) (int, error)) *apiQuerierMock_Execute_Call { - _c.Call.Return(run) - return _c -} - // JobScale provides a mock function with given fields: jobID func (_m *apiQuerierMock) JobScale(jobID string) (uint, error) { ret := _m.Called(jobID) @@ -204,34 +106,6 @@ func (_m *apiQuerierMock) JobScale(jobID string) (uint, error) { return r0, r1 } -// apiQuerierMock_JobScale_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'JobScale' -type apiQuerierMock_JobScale_Call struct { - *mock.Call -} - -// JobScale is a helper method to define mock.On call -// - jobID string -func (_e *apiQuerierMock_Expecter) JobScale(jobID interface{}) *apiQuerierMock_JobScale_Call { - return &apiQuerierMock_JobScale_Call{Call: _e.mock.On("JobScale", jobID)} -} - -func (_c *apiQuerierMock_JobScale_Call) Run(run func(jobID string)) *apiQuerierMock_JobScale_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string)) - }) - return _c -} - -func (_c *apiQuerierMock_JobScale_Call) Return(jobScale uint, err error) *apiQuerierMock_JobScale_Call { - _c.Call.Return(jobScale, err) - return _c -} - -func (_c *apiQuerierMock_JobScale_Call) RunAndReturn(run func(string) (uint, error)) *apiQuerierMock_JobScale_Call { - _c.Call.Return(run) - return _c -} - // LoadJobList provides a mock function with given fields: func (_m *apiQuerierMock) LoadJobList() ([]*api.JobListStub, error) { ret := _m.Called() @@ -258,33 +132,6 @@ func (_m *apiQuerierMock) LoadJobList() ([]*api.JobListStub, error) { return r0, r1 } -// apiQuerierMock_LoadJobList_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LoadJobList' -type apiQuerierMock_LoadJobList_Call struct { - *mock.Call -} - -// LoadJobList is a helper method to define mock.On call -func (_e *apiQuerierMock_Expecter) LoadJobList() *apiQuerierMock_LoadJobList_Call { - return &apiQuerierMock_LoadJobList_Call{Call: _e.mock.On("LoadJobList")} -} - -func (_c *apiQuerierMock_LoadJobList_Call) Run(run func()) *apiQuerierMock_LoadJobList_Call { - _c.Call.Run(func(args mock.Arguments) { - run() - }) - return _c -} - -func (_c *apiQuerierMock_LoadJobList_Call) Return(list []*api.JobListStub, err error) *apiQuerierMock_LoadJobList_Call { - _c.Call.Return(list, err) - return _c -} - -func (_c *apiQuerierMock_LoadJobList_Call) RunAndReturn(run func() ([]*api.JobListStub, error)) *apiQuerierMock_LoadJobList_Call { - _c.Call.Return(run) - return _c -} - // RegisterNomadJob provides a mock function with given fields: job func (_m *apiQuerierMock) RegisterNomadJob(job *api.Job) (string, error) { ret := _m.Called(job) @@ -309,34 +156,6 @@ func (_m *apiQuerierMock) RegisterNomadJob(job *api.Job) (string, error) { return r0, r1 } -// apiQuerierMock_RegisterNomadJob_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RegisterNomadJob' -type apiQuerierMock_RegisterNomadJob_Call struct { - *mock.Call -} - -// RegisterNomadJob is a helper method to define mock.On call -// - job *api.Job -func (_e *apiQuerierMock_Expecter) RegisterNomadJob(job interface{}) *apiQuerierMock_RegisterNomadJob_Call { - return &apiQuerierMock_RegisterNomadJob_Call{Call: _e.mock.On("RegisterNomadJob", job)} -} - -func (_c *apiQuerierMock_RegisterNomadJob_Call) Run(run func(job *api.Job)) *apiQuerierMock_RegisterNomadJob_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(*api.Job)) - }) - return _c -} - -func (_c *apiQuerierMock_RegisterNomadJob_Call) Return(_a0 string, _a1 error) *apiQuerierMock_RegisterNomadJob_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *apiQuerierMock_RegisterNomadJob_Call) RunAndReturn(run func(*api.Job) (string, error)) *apiQuerierMock_RegisterNomadJob_Call { - _c.Call.Return(run) - return _c -} - // SetJobScale provides a mock function with given fields: jobID, count, reason func (_m *apiQuerierMock) SetJobScale(jobID string, count uint, reason string) error { ret := _m.Called(jobID, count, reason) @@ -351,36 +170,6 @@ func (_m *apiQuerierMock) SetJobScale(jobID string, count uint, reason string) e return r0 } -// apiQuerierMock_SetJobScale_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetJobScale' -type apiQuerierMock_SetJobScale_Call struct { - *mock.Call -} - -// SetJobScale is a helper method to define mock.On call -// - jobID string -// - count uint -// - reason string -func (_e *apiQuerierMock_Expecter) SetJobScale(jobID interface{}, count interface{}, reason interface{}) *apiQuerierMock_SetJobScale_Call { - return &apiQuerierMock_SetJobScale_Call{Call: _e.mock.On("SetJobScale", jobID, count, reason)} -} - -func (_c *apiQuerierMock_SetJobScale_Call) Run(run func(jobID string, count uint, reason string)) *apiQuerierMock_SetJobScale_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(uint), args[2].(string)) - }) - return _c -} - -func (_c *apiQuerierMock_SetJobScale_Call) Return(err error) *apiQuerierMock_SetJobScale_Call { - _c.Call.Return(err) - return _c -} - -func (_c *apiQuerierMock_SetJobScale_Call) RunAndReturn(run func(string, uint, string) error) *apiQuerierMock_SetJobScale_Call { - _c.Call.Return(run) - return _c -} - // allocation provides a mock function with given fields: jobID func (_m *apiQuerierMock) allocation(jobID string) (*api.Allocation, error) { ret := _m.Called(jobID) @@ -407,34 +196,6 @@ func (_m *apiQuerierMock) allocation(jobID string) (*api.Allocation, error) { return r0, r1 } -// apiQuerierMock_allocation_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'allocation' -type apiQuerierMock_allocation_Call struct { - *mock.Call -} - -// allocation is a helper method to define mock.On call -// - jobID string -func (_e *apiQuerierMock_Expecter) allocation(jobID interface{}) *apiQuerierMock_allocation_Call { - return &apiQuerierMock_allocation_Call{Call: _e.mock.On("allocation", jobID)} -} - -func (_c *apiQuerierMock_allocation_Call) Run(run func(jobID string)) *apiQuerierMock_allocation_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string)) - }) - return _c -} - -func (_c *apiQuerierMock_allocation_Call) Return(_a0 *api.Allocation, _a1 error) *apiQuerierMock_allocation_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *apiQuerierMock_allocation_Call) RunAndReturn(run func(string) (*api.Allocation, error)) *apiQuerierMock_allocation_Call { - _c.Call.Return(run) - return _c -} - // init provides a mock function with given fields: nomadConfig func (_m *apiQuerierMock) init(nomadConfig *config.Nomad) error { ret := _m.Called(nomadConfig) @@ -449,34 +210,6 @@ func (_m *apiQuerierMock) init(nomadConfig *config.Nomad) error { return r0 } -// apiQuerierMock_init_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'init' -type apiQuerierMock_init_Call struct { - *mock.Call -} - -// init is a helper method to define mock.On call -// - nomadConfig *config.Nomad -func (_e *apiQuerierMock_Expecter) init(nomadConfig interface{}) *apiQuerierMock_init_Call { - return &apiQuerierMock_init_Call{Call: _e.mock.On("init", nomadConfig)} -} - -func (_c *apiQuerierMock_init_Call) Run(run func(nomadConfig *config.Nomad)) *apiQuerierMock_init_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(*config.Nomad)) - }) - return _c -} - -func (_c *apiQuerierMock_init_Call) Return(err error) *apiQuerierMock_init_Call { - _c.Call.Return(err) - return _c -} - -func (_c *apiQuerierMock_init_Call) RunAndReturn(run func(*config.Nomad) error) *apiQuerierMock_init_Call { - _c.Call.Return(run) - return _c -} - // job provides a mock function with given fields: jobID func (_m *apiQuerierMock) job(jobID string) (*api.Job, error) { ret := _m.Called(jobID) @@ -503,32 +236,30 @@ func (_m *apiQuerierMock) job(jobID string) (*api.Job, error) { return r0, r1 } -// apiQuerierMock_job_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'job' -type apiQuerierMock_job_Call struct { - *mock.Call -} +// listAllocations provides a mock function with given fields: +func (_m *apiQuerierMock) listAllocations() ([]*api.AllocationListStub, error) { + ret := _m.Called() -// job is a helper method to define mock.On call -// - jobID string -func (_e *apiQuerierMock_Expecter) job(jobID interface{}) *apiQuerierMock_job_Call { - return &apiQuerierMock_job_Call{Call: _e.mock.On("job", jobID)} -} + var r0 []*api.AllocationListStub + var r1 error + if rf, ok := ret.Get(0).(func() ([]*api.AllocationListStub, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() []*api.AllocationListStub); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*api.AllocationListStub) + } + } -func (_c *apiQuerierMock_job_Call) Run(run func(jobID string)) *apiQuerierMock_job_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string)) - }) - return _c -} + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } -func (_c *apiQuerierMock_job_Call) Return(job *api.Job, err error) *apiQuerierMock_job_Call { - _c.Call.Return(job, err) - return _c -} - -func (_c *apiQuerierMock_job_Call) RunAndReturn(run func(string) (*api.Job, error)) *apiQuerierMock_job_Call { - _c.Call.Return(run) - return _c + return r0, r1 } // listJobs provides a mock function with given fields: prefix @@ -557,34 +288,6 @@ func (_m *apiQuerierMock) listJobs(prefix string) ([]*api.JobListStub, error) { return r0, r1 } -// apiQuerierMock_listJobs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'listJobs' -type apiQuerierMock_listJobs_Call struct { - *mock.Call -} - -// listJobs is a helper method to define mock.On call -// - prefix string -func (_e *apiQuerierMock_Expecter) listJobs(prefix interface{}) *apiQuerierMock_listJobs_Call { - return &apiQuerierMock_listJobs_Call{Call: _e.mock.On("listJobs", prefix)} -} - -func (_c *apiQuerierMock_listJobs_Call) Run(run func(prefix string)) *apiQuerierMock_listJobs_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string)) - }) - return _c -} - -func (_c *apiQuerierMock_listJobs_Call) Return(allocationListStub []*api.JobListStub, err error) *apiQuerierMock_listJobs_Call { - _c.Call.Return(allocationListStub, err) - return _c -} - -func (_c *apiQuerierMock_listJobs_Call) RunAndReturn(run func(string) ([]*api.JobListStub, error)) *apiQuerierMock_listJobs_Call { - _c.Call.Return(run) - return _c -} - type mockConstructorTestingTnewApiQuerierMock interface { mock.TestingT Cleanup(func()) diff --git a/internal/nomad/executor_api_mock.go b/internal/nomad/executor_api_mock.go index cf78847..02b8bbc 100644 --- a/internal/nomad/executor_api_mock.go +++ b/internal/nomad/executor_api_mock.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.21.0. DO NOT EDIT. +// Code generated by mockery v2.23.1. DO NOT EDIT. package nomad @@ -20,14 +20,6 @@ type ExecutorAPIMock struct { mock.Mock } -type ExecutorAPIMock_Expecter struct { - mock *mock.Mock -} - -func (_m *ExecutorAPIMock) EXPECT() *ExecutorAPIMock_Expecter { - return &ExecutorAPIMock_Expecter{mock: &_m.Mock} -} - // DeleteJob provides a mock function with given fields: jobID func (_m *ExecutorAPIMock) DeleteJob(jobID string) error { ret := _m.Called(jobID) @@ -42,34 +34,6 @@ func (_m *ExecutorAPIMock) DeleteJob(jobID string) error { return r0 } -// ExecutorAPIMock_DeleteJob_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteJob' -type ExecutorAPIMock_DeleteJob_Call struct { - *mock.Call -} - -// DeleteJob is a helper method to define mock.On call -// - jobID string -func (_e *ExecutorAPIMock_Expecter) DeleteJob(jobID interface{}) *ExecutorAPIMock_DeleteJob_Call { - return &ExecutorAPIMock_DeleteJob_Call{Call: _e.mock.On("DeleteJob", jobID)} -} - -func (_c *ExecutorAPIMock_DeleteJob_Call) Run(run func(jobID string)) *ExecutorAPIMock_DeleteJob_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string)) - }) - return _c -} - -func (_c *ExecutorAPIMock_DeleteJob_Call) Return(err error) *ExecutorAPIMock_DeleteJob_Call { - _c.Call.Return(err) - return _c -} - -func (_c *ExecutorAPIMock_DeleteJob_Call) RunAndReturn(run func(string) error) *ExecutorAPIMock_DeleteJob_Call { - _c.Call.Return(run) - return _c -} - // EventStream provides a mock function with given fields: ctx func (_m *ExecutorAPIMock) EventStream(ctx context.Context) (<-chan *api.Events, error) { ret := _m.Called(ctx) @@ -96,34 +60,6 @@ func (_m *ExecutorAPIMock) EventStream(ctx context.Context) (<-chan *api.Events, return r0, r1 } -// ExecutorAPIMock_EventStream_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'EventStream' -type ExecutorAPIMock_EventStream_Call struct { - *mock.Call -} - -// EventStream is a helper method to define mock.On call -// - ctx context.Context -func (_e *ExecutorAPIMock_Expecter) EventStream(ctx interface{}) *ExecutorAPIMock_EventStream_Call { - return &ExecutorAPIMock_EventStream_Call{Call: _e.mock.On("EventStream", ctx)} -} - -func (_c *ExecutorAPIMock_EventStream_Call) Run(run func(ctx context.Context)) *ExecutorAPIMock_EventStream_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context)) - }) - return _c -} - -func (_c *ExecutorAPIMock_EventStream_Call) Return(_a0 <-chan *api.Events, _a1 error) *ExecutorAPIMock_EventStream_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *ExecutorAPIMock_EventStream_Call) RunAndReturn(run func(context.Context) (<-chan *api.Events, error)) *ExecutorAPIMock_EventStream_Call { - _c.Call.Return(run) - return _c -} - // Execute provides a mock function with given fields: jobID, ctx, command, tty, stdin, stdout, stderr func (_m *ExecutorAPIMock) Execute(jobID string, ctx context.Context, command string, tty bool, stdin io.Reader, stdout io.Writer, stderr io.Writer) (int, error) { ret := _m.Called(jobID, ctx, command, tty, stdin, stdout, stderr) @@ -148,40 +84,6 @@ func (_m *ExecutorAPIMock) Execute(jobID string, ctx context.Context, command st return r0, r1 } -// ExecutorAPIMock_Execute_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Execute' -type ExecutorAPIMock_Execute_Call struct { - *mock.Call -} - -// Execute is a helper method to define mock.On call -// - jobID string -// - ctx context.Context -// - command string -// - tty bool -// - stdin io.Reader -// - stdout io.Writer -// - stderr io.Writer -func (_e *ExecutorAPIMock_Expecter) Execute(jobID interface{}, ctx interface{}, command interface{}, tty interface{}, stdin interface{}, stdout interface{}, stderr interface{}) *ExecutorAPIMock_Execute_Call { - return &ExecutorAPIMock_Execute_Call{Call: _e.mock.On("Execute", jobID, ctx, command, tty, stdin, stdout, stderr)} -} - -func (_c *ExecutorAPIMock_Execute_Call) Run(run func(jobID string, ctx context.Context, command string, tty bool, stdin io.Reader, stdout io.Writer, stderr io.Writer)) *ExecutorAPIMock_Execute_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(context.Context), args[2].(string), args[3].(bool), args[4].(io.Reader), args[5].(io.Writer), args[6].(io.Writer)) - }) - return _c -} - -func (_c *ExecutorAPIMock_Execute_Call) Return(_a0 int, _a1 error) *ExecutorAPIMock_Execute_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *ExecutorAPIMock_Execute_Call) RunAndReturn(run func(string, context.Context, string, bool, io.Reader, io.Writer, io.Writer) (int, error)) *ExecutorAPIMock_Execute_Call { - _c.Call.Return(run) - return _c -} - // ExecuteCommand provides a mock function with given fields: jobID, ctx, command, tty, privilegedExecution, stdin, stdout, stderr func (_m *ExecutorAPIMock) ExecuteCommand(jobID string, ctx context.Context, command string, tty bool, privilegedExecution bool, stdin io.Reader, stdout io.Writer, stderr io.Writer) (int, error) { ret := _m.Called(jobID, ctx, command, tty, privilegedExecution, stdin, stdout, stderr) @@ -206,41 +108,6 @@ func (_m *ExecutorAPIMock) ExecuteCommand(jobID string, ctx context.Context, com return r0, r1 } -// ExecutorAPIMock_ExecuteCommand_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ExecuteCommand' -type ExecutorAPIMock_ExecuteCommand_Call struct { - *mock.Call -} - -// ExecuteCommand is a helper method to define mock.On call -// - jobID string -// - ctx context.Context -// - command string -// - tty bool -// - privilegedExecution bool -// - stdin io.Reader -// - stdout io.Writer -// - stderr io.Writer -func (_e *ExecutorAPIMock_Expecter) ExecuteCommand(jobID interface{}, ctx interface{}, command interface{}, tty interface{}, privilegedExecution interface{}, stdin interface{}, stdout interface{}, stderr interface{}) *ExecutorAPIMock_ExecuteCommand_Call { - return &ExecutorAPIMock_ExecuteCommand_Call{Call: _e.mock.On("ExecuteCommand", jobID, ctx, command, tty, privilegedExecution, stdin, stdout, stderr)} -} - -func (_c *ExecutorAPIMock_ExecuteCommand_Call) Run(run func(jobID string, ctx context.Context, command string, tty bool, privilegedExecution bool, stdin io.Reader, stdout io.Writer, stderr io.Writer)) *ExecutorAPIMock_ExecuteCommand_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(context.Context), args[2].(string), args[3].(bool), args[4].(bool), args[5].(io.Reader), args[6].(io.Writer), args[7].(io.Writer)) - }) - return _c -} - -func (_c *ExecutorAPIMock_ExecuteCommand_Call) Return(_a0 int, _a1 error) *ExecutorAPIMock_ExecuteCommand_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *ExecutorAPIMock_ExecuteCommand_Call) RunAndReturn(run func(string, context.Context, string, bool, bool, io.Reader, io.Writer, io.Writer) (int, error)) *ExecutorAPIMock_ExecuteCommand_Call { - _c.Call.Return(run) - return _c -} - // JobScale provides a mock function with given fields: jobID func (_m *ExecutorAPIMock) JobScale(jobID string) (uint, error) { ret := _m.Called(jobID) @@ -265,34 +132,6 @@ func (_m *ExecutorAPIMock) JobScale(jobID string) (uint, error) { return r0, r1 } -// ExecutorAPIMock_JobScale_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'JobScale' -type ExecutorAPIMock_JobScale_Call struct { - *mock.Call -} - -// JobScale is a helper method to define mock.On call -// - jobID string -func (_e *ExecutorAPIMock_Expecter) JobScale(jobID interface{}) *ExecutorAPIMock_JobScale_Call { - return &ExecutorAPIMock_JobScale_Call{Call: _e.mock.On("JobScale", jobID)} -} - -func (_c *ExecutorAPIMock_JobScale_Call) Run(run func(jobID string)) *ExecutorAPIMock_JobScale_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string)) - }) - return _c -} - -func (_c *ExecutorAPIMock_JobScale_Call) Return(jobScale uint, err error) *ExecutorAPIMock_JobScale_Call { - _c.Call.Return(jobScale, err) - return _c -} - -func (_c *ExecutorAPIMock_JobScale_Call) RunAndReturn(run func(string) (uint, error)) *ExecutorAPIMock_JobScale_Call { - _c.Call.Return(run) - return _c -} - // LoadEnvironmentJobs provides a mock function with given fields: func (_m *ExecutorAPIMock) LoadEnvironmentJobs() ([]*api.Job, error) { ret := _m.Called() @@ -319,33 +158,6 @@ func (_m *ExecutorAPIMock) LoadEnvironmentJobs() ([]*api.Job, error) { return r0, r1 } -// ExecutorAPIMock_LoadEnvironmentJobs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LoadEnvironmentJobs' -type ExecutorAPIMock_LoadEnvironmentJobs_Call struct { - *mock.Call -} - -// LoadEnvironmentJobs is a helper method to define mock.On call -func (_e *ExecutorAPIMock_Expecter) LoadEnvironmentJobs() *ExecutorAPIMock_LoadEnvironmentJobs_Call { - return &ExecutorAPIMock_LoadEnvironmentJobs_Call{Call: _e.mock.On("LoadEnvironmentJobs")} -} - -func (_c *ExecutorAPIMock_LoadEnvironmentJobs_Call) Run(run func()) *ExecutorAPIMock_LoadEnvironmentJobs_Call { - _c.Call.Run(func(args mock.Arguments) { - run() - }) - return _c -} - -func (_c *ExecutorAPIMock_LoadEnvironmentJobs_Call) Return(_a0 []*api.Job, _a1 error) *ExecutorAPIMock_LoadEnvironmentJobs_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *ExecutorAPIMock_LoadEnvironmentJobs_Call) RunAndReturn(run func() ([]*api.Job, error)) *ExecutorAPIMock_LoadEnvironmentJobs_Call { - _c.Call.Return(run) - return _c -} - // LoadJobList provides a mock function with given fields: func (_m *ExecutorAPIMock) LoadJobList() ([]*api.JobListStub, error) { ret := _m.Called() @@ -372,33 +184,6 @@ func (_m *ExecutorAPIMock) LoadJobList() ([]*api.JobListStub, error) { return r0, r1 } -// ExecutorAPIMock_LoadJobList_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LoadJobList' -type ExecutorAPIMock_LoadJobList_Call struct { - *mock.Call -} - -// LoadJobList is a helper method to define mock.On call -func (_e *ExecutorAPIMock_Expecter) LoadJobList() *ExecutorAPIMock_LoadJobList_Call { - return &ExecutorAPIMock_LoadJobList_Call{Call: _e.mock.On("LoadJobList")} -} - -func (_c *ExecutorAPIMock_LoadJobList_Call) Run(run func()) *ExecutorAPIMock_LoadJobList_Call { - _c.Call.Run(func(args mock.Arguments) { - run() - }) - return _c -} - -func (_c *ExecutorAPIMock_LoadJobList_Call) Return(list []*api.JobListStub, err error) *ExecutorAPIMock_LoadJobList_Call { - _c.Call.Return(list, err) - return _c -} - -func (_c *ExecutorAPIMock_LoadJobList_Call) RunAndReturn(run func() ([]*api.JobListStub, error)) *ExecutorAPIMock_LoadJobList_Call { - _c.Call.Return(run) - return _c -} - // LoadRunnerIDs provides a mock function with given fields: prefix func (_m *ExecutorAPIMock) LoadRunnerIDs(prefix string) ([]string, error) { ret := _m.Called(prefix) @@ -425,34 +210,6 @@ func (_m *ExecutorAPIMock) LoadRunnerIDs(prefix string) ([]string, error) { return r0, r1 } -// ExecutorAPIMock_LoadRunnerIDs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LoadRunnerIDs' -type ExecutorAPIMock_LoadRunnerIDs_Call struct { - *mock.Call -} - -// LoadRunnerIDs is a helper method to define mock.On call -// - prefix string -func (_e *ExecutorAPIMock_Expecter) LoadRunnerIDs(prefix interface{}) *ExecutorAPIMock_LoadRunnerIDs_Call { - return &ExecutorAPIMock_LoadRunnerIDs_Call{Call: _e.mock.On("LoadRunnerIDs", prefix)} -} - -func (_c *ExecutorAPIMock_LoadRunnerIDs_Call) Run(run func(prefix string)) *ExecutorAPIMock_LoadRunnerIDs_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string)) - }) - return _c -} - -func (_c *ExecutorAPIMock_LoadRunnerIDs_Call) Return(runnerIds []string, err error) *ExecutorAPIMock_LoadRunnerIDs_Call { - _c.Call.Return(runnerIds, err) - return _c -} - -func (_c *ExecutorAPIMock_LoadRunnerIDs_Call) RunAndReturn(run func(string) ([]string, error)) *ExecutorAPIMock_LoadRunnerIDs_Call { - _c.Call.Return(run) - return _c -} - // LoadRunnerJobs provides a mock function with given fields: environmentID func (_m *ExecutorAPIMock) LoadRunnerJobs(environmentID dto.EnvironmentID) ([]*api.Job, error) { ret := _m.Called(environmentID) @@ -479,34 +236,6 @@ func (_m *ExecutorAPIMock) LoadRunnerJobs(environmentID dto.EnvironmentID) ([]*a return r0, r1 } -// ExecutorAPIMock_LoadRunnerJobs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LoadRunnerJobs' -type ExecutorAPIMock_LoadRunnerJobs_Call struct { - *mock.Call -} - -// LoadRunnerJobs is a helper method to define mock.On call -// - environmentID dto.EnvironmentID -func (_e *ExecutorAPIMock_Expecter) LoadRunnerJobs(environmentID interface{}) *ExecutorAPIMock_LoadRunnerJobs_Call { - return &ExecutorAPIMock_LoadRunnerJobs_Call{Call: _e.mock.On("LoadRunnerJobs", environmentID)} -} - -func (_c *ExecutorAPIMock_LoadRunnerJobs_Call) Run(run func(environmentID dto.EnvironmentID)) *ExecutorAPIMock_LoadRunnerJobs_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(dto.EnvironmentID)) - }) - return _c -} - -func (_c *ExecutorAPIMock_LoadRunnerJobs_Call) Return(_a0 []*api.Job, _a1 error) *ExecutorAPIMock_LoadRunnerJobs_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *ExecutorAPIMock_LoadRunnerJobs_Call) RunAndReturn(run func(dto.EnvironmentID) ([]*api.Job, error)) *ExecutorAPIMock_LoadRunnerJobs_Call { - _c.Call.Return(run) - return _c -} - // LoadRunnerPortMappings provides a mock function with given fields: runnerID func (_m *ExecutorAPIMock) LoadRunnerPortMappings(runnerID string) ([]api.PortMapping, error) { ret := _m.Called(runnerID) @@ -533,34 +262,6 @@ func (_m *ExecutorAPIMock) LoadRunnerPortMappings(runnerID string) ([]api.PortMa return r0, r1 } -// ExecutorAPIMock_LoadRunnerPortMappings_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'LoadRunnerPortMappings' -type ExecutorAPIMock_LoadRunnerPortMappings_Call struct { - *mock.Call -} - -// LoadRunnerPortMappings is a helper method to define mock.On call -// - runnerID string -func (_e *ExecutorAPIMock_Expecter) LoadRunnerPortMappings(runnerID interface{}) *ExecutorAPIMock_LoadRunnerPortMappings_Call { - return &ExecutorAPIMock_LoadRunnerPortMappings_Call{Call: _e.mock.On("LoadRunnerPortMappings", runnerID)} -} - -func (_c *ExecutorAPIMock_LoadRunnerPortMappings_Call) Run(run func(runnerID string)) *ExecutorAPIMock_LoadRunnerPortMappings_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string)) - }) - return _c -} - -func (_c *ExecutorAPIMock_LoadRunnerPortMappings_Call) Return(_a0 []api.PortMapping, _a1 error) *ExecutorAPIMock_LoadRunnerPortMappings_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *ExecutorAPIMock_LoadRunnerPortMappings_Call) RunAndReturn(run func(string) ([]api.PortMapping, error)) *ExecutorAPIMock_LoadRunnerPortMappings_Call { - _c.Call.Return(run) - return _c -} - // MarkRunnerAsUsed provides a mock function with given fields: runnerID, duration func (_m *ExecutorAPIMock) MarkRunnerAsUsed(runnerID string, duration int) error { ret := _m.Called(runnerID, duration) @@ -575,35 +276,6 @@ func (_m *ExecutorAPIMock) MarkRunnerAsUsed(runnerID string, duration int) error return r0 } -// ExecutorAPIMock_MarkRunnerAsUsed_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'MarkRunnerAsUsed' -type ExecutorAPIMock_MarkRunnerAsUsed_Call struct { - *mock.Call -} - -// MarkRunnerAsUsed is a helper method to define mock.On call -// - runnerID string -// - duration int -func (_e *ExecutorAPIMock_Expecter) MarkRunnerAsUsed(runnerID interface{}, duration interface{}) *ExecutorAPIMock_MarkRunnerAsUsed_Call { - return &ExecutorAPIMock_MarkRunnerAsUsed_Call{Call: _e.mock.On("MarkRunnerAsUsed", runnerID, duration)} -} - -func (_c *ExecutorAPIMock_MarkRunnerAsUsed_Call) Run(run func(runnerID string, duration int)) *ExecutorAPIMock_MarkRunnerAsUsed_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(int)) - }) - return _c -} - -func (_c *ExecutorAPIMock_MarkRunnerAsUsed_Call) Return(_a0 error) *ExecutorAPIMock_MarkRunnerAsUsed_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *ExecutorAPIMock_MarkRunnerAsUsed_Call) RunAndReturn(run func(string, int) error) *ExecutorAPIMock_MarkRunnerAsUsed_Call { - _c.Call.Return(run) - return _c -} - // MonitorEvaluation provides a mock function with given fields: evaluationID, ctx func (_m *ExecutorAPIMock) MonitorEvaluation(evaluationID string, ctx context.Context) error { ret := _m.Called(evaluationID, ctx) @@ -618,35 +290,6 @@ func (_m *ExecutorAPIMock) MonitorEvaluation(evaluationID string, ctx context.Co return r0 } -// ExecutorAPIMock_MonitorEvaluation_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'MonitorEvaluation' -type ExecutorAPIMock_MonitorEvaluation_Call struct { - *mock.Call -} - -// MonitorEvaluation is a helper method to define mock.On call -// - evaluationID string -// - ctx context.Context -func (_e *ExecutorAPIMock_Expecter) MonitorEvaluation(evaluationID interface{}, ctx interface{}) *ExecutorAPIMock_MonitorEvaluation_Call { - return &ExecutorAPIMock_MonitorEvaluation_Call{Call: _e.mock.On("MonitorEvaluation", evaluationID, ctx)} -} - -func (_c *ExecutorAPIMock_MonitorEvaluation_Call) Run(run func(evaluationID string, ctx context.Context)) *ExecutorAPIMock_MonitorEvaluation_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(context.Context)) - }) - return _c -} - -func (_c *ExecutorAPIMock_MonitorEvaluation_Call) Return(_a0 error) *ExecutorAPIMock_MonitorEvaluation_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *ExecutorAPIMock_MonitorEvaluation_Call) RunAndReturn(run func(string, context.Context) error) *ExecutorAPIMock_MonitorEvaluation_Call { - _c.Call.Return(run) - return _c -} - // RegisterNomadJob provides a mock function with given fields: job func (_m *ExecutorAPIMock) RegisterNomadJob(job *api.Job) (string, error) { ret := _m.Called(job) @@ -671,34 +314,6 @@ func (_m *ExecutorAPIMock) RegisterNomadJob(job *api.Job) (string, error) { return r0, r1 } -// ExecutorAPIMock_RegisterNomadJob_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RegisterNomadJob' -type ExecutorAPIMock_RegisterNomadJob_Call struct { - *mock.Call -} - -// RegisterNomadJob is a helper method to define mock.On call -// - job *api.Job -func (_e *ExecutorAPIMock_Expecter) RegisterNomadJob(job interface{}) *ExecutorAPIMock_RegisterNomadJob_Call { - return &ExecutorAPIMock_RegisterNomadJob_Call{Call: _e.mock.On("RegisterNomadJob", job)} -} - -func (_c *ExecutorAPIMock_RegisterNomadJob_Call) Run(run func(job *api.Job)) *ExecutorAPIMock_RegisterNomadJob_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(*api.Job)) - }) - return _c -} - -func (_c *ExecutorAPIMock_RegisterNomadJob_Call) Return(_a0 string, _a1 error) *ExecutorAPIMock_RegisterNomadJob_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *ExecutorAPIMock_RegisterNomadJob_Call) RunAndReturn(run func(*api.Job) (string, error)) *ExecutorAPIMock_RegisterNomadJob_Call { - _c.Call.Return(run) - return _c -} - // RegisterRunnerJob provides a mock function with given fields: template func (_m *ExecutorAPIMock) RegisterRunnerJob(template *api.Job) error { ret := _m.Called(template) @@ -713,34 +328,6 @@ func (_m *ExecutorAPIMock) RegisterRunnerJob(template *api.Job) error { return r0 } -// ExecutorAPIMock_RegisterRunnerJob_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RegisterRunnerJob' -type ExecutorAPIMock_RegisterRunnerJob_Call struct { - *mock.Call -} - -// RegisterRunnerJob is a helper method to define mock.On call -// - template *api.Job -func (_e *ExecutorAPIMock_Expecter) RegisterRunnerJob(template interface{}) *ExecutorAPIMock_RegisterRunnerJob_Call { - return &ExecutorAPIMock_RegisterRunnerJob_Call{Call: _e.mock.On("RegisterRunnerJob", template)} -} - -func (_c *ExecutorAPIMock_RegisterRunnerJob_Call) Run(run func(template *api.Job)) *ExecutorAPIMock_RegisterRunnerJob_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(*api.Job)) - }) - return _c -} - -func (_c *ExecutorAPIMock_RegisterRunnerJob_Call) Return(_a0 error) *ExecutorAPIMock_RegisterRunnerJob_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *ExecutorAPIMock_RegisterRunnerJob_Call) RunAndReturn(run func(*api.Job) error) *ExecutorAPIMock_RegisterRunnerJob_Call { - _c.Call.Return(run) - return _c -} - // SetJobScale provides a mock function with given fields: jobID, count, reason func (_m *ExecutorAPIMock) SetJobScale(jobID string, count uint, reason string) error { ret := _m.Called(jobID, count, reason) @@ -755,36 +342,6 @@ func (_m *ExecutorAPIMock) SetJobScale(jobID string, count uint, reason string) return r0 } -// ExecutorAPIMock_SetJobScale_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetJobScale' -type ExecutorAPIMock_SetJobScale_Call struct { - *mock.Call -} - -// SetJobScale is a helper method to define mock.On call -// - jobID string -// - count uint -// - reason string -func (_e *ExecutorAPIMock_Expecter) SetJobScale(jobID interface{}, count interface{}, reason interface{}) *ExecutorAPIMock_SetJobScale_Call { - return &ExecutorAPIMock_SetJobScale_Call{Call: _e.mock.On("SetJobScale", jobID, count, reason)} -} - -func (_c *ExecutorAPIMock_SetJobScale_Call) Run(run func(jobID string, count uint, reason string)) *ExecutorAPIMock_SetJobScale_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string), args[1].(uint), args[2].(string)) - }) - return _c -} - -func (_c *ExecutorAPIMock_SetJobScale_Call) Return(err error) *ExecutorAPIMock_SetJobScale_Call { - _c.Call.Return(err) - return _c -} - -func (_c *ExecutorAPIMock_SetJobScale_Call) RunAndReturn(run func(string, uint, string) error) *ExecutorAPIMock_SetJobScale_Call { - _c.Call.Return(run) - return _c -} - // WatchEventStream provides a mock function with given fields: ctx, callbacks func (_m *ExecutorAPIMock) WatchEventStream(ctx context.Context, callbacks *AllocationProcessoring) error { ret := _m.Called(ctx, callbacks) @@ -799,35 +356,6 @@ func (_m *ExecutorAPIMock) WatchEventStream(ctx context.Context, callbacks *Allo return r0 } -// ExecutorAPIMock_WatchEventStream_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WatchEventStream' -type ExecutorAPIMock_WatchEventStream_Call struct { - *mock.Call -} - -// WatchEventStream is a helper method to define mock.On call -// - ctx context.Context -// - callbacks *AllocationProcessoring -func (_e *ExecutorAPIMock_Expecter) WatchEventStream(ctx interface{}, callbacks interface{}) *ExecutorAPIMock_WatchEventStream_Call { - return &ExecutorAPIMock_WatchEventStream_Call{Call: _e.mock.On("WatchEventStream", ctx, callbacks)} -} - -func (_c *ExecutorAPIMock_WatchEventStream_Call) Run(run func(ctx context.Context, callbacks *AllocationProcessoring)) *ExecutorAPIMock_WatchEventStream_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(*AllocationProcessoring)) - }) - return _c -} - -func (_c *ExecutorAPIMock_WatchEventStream_Call) Return(_a0 error) *ExecutorAPIMock_WatchEventStream_Call { - _c.Call.Return(_a0) - return _c -} - -func (_c *ExecutorAPIMock_WatchEventStream_Call) RunAndReturn(run func(context.Context, *AllocationProcessoring) error) *ExecutorAPIMock_WatchEventStream_Call { - _c.Call.Return(run) - return _c -} - // allocation provides a mock function with given fields: jobID func (_m *ExecutorAPIMock) allocation(jobID string) (*api.Allocation, error) { ret := _m.Called(jobID) @@ -854,34 +382,6 @@ func (_m *ExecutorAPIMock) allocation(jobID string) (*api.Allocation, error) { return r0, r1 } -// ExecutorAPIMock_allocation_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'allocation' -type ExecutorAPIMock_allocation_Call struct { - *mock.Call -} - -// allocation is a helper method to define mock.On call -// - jobID string -func (_e *ExecutorAPIMock_Expecter) allocation(jobID interface{}) *ExecutorAPIMock_allocation_Call { - return &ExecutorAPIMock_allocation_Call{Call: _e.mock.On("allocation", jobID)} -} - -func (_c *ExecutorAPIMock_allocation_Call) Run(run func(jobID string)) *ExecutorAPIMock_allocation_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string)) - }) - return _c -} - -func (_c *ExecutorAPIMock_allocation_Call) Return(_a0 *api.Allocation, _a1 error) *ExecutorAPIMock_allocation_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *ExecutorAPIMock_allocation_Call) RunAndReturn(run func(string) (*api.Allocation, error)) *ExecutorAPIMock_allocation_Call { - _c.Call.Return(run) - return _c -} - // init provides a mock function with given fields: nomadConfig func (_m *ExecutorAPIMock) init(nomadConfig *config.Nomad) error { ret := _m.Called(nomadConfig) @@ -896,34 +396,6 @@ func (_m *ExecutorAPIMock) init(nomadConfig *config.Nomad) error { return r0 } -// ExecutorAPIMock_init_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'init' -type ExecutorAPIMock_init_Call struct { - *mock.Call -} - -// init is a helper method to define mock.On call -// - nomadConfig *config.Nomad -func (_e *ExecutorAPIMock_Expecter) init(nomadConfig interface{}) *ExecutorAPIMock_init_Call { - return &ExecutorAPIMock_init_Call{Call: _e.mock.On("init", nomadConfig)} -} - -func (_c *ExecutorAPIMock_init_Call) Run(run func(nomadConfig *config.Nomad)) *ExecutorAPIMock_init_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(*config.Nomad)) - }) - return _c -} - -func (_c *ExecutorAPIMock_init_Call) Return(err error) *ExecutorAPIMock_init_Call { - _c.Call.Return(err) - return _c -} - -func (_c *ExecutorAPIMock_init_Call) RunAndReturn(run func(*config.Nomad) error) *ExecutorAPIMock_init_Call { - _c.Call.Return(run) - return _c -} - // job provides a mock function with given fields: jobID func (_m *ExecutorAPIMock) job(jobID string) (*api.Job, error) { ret := _m.Called(jobID) @@ -950,32 +422,30 @@ func (_m *ExecutorAPIMock) job(jobID string) (*api.Job, error) { return r0, r1 } -// ExecutorAPIMock_job_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'job' -type ExecutorAPIMock_job_Call struct { - *mock.Call -} +// listAllocations provides a mock function with given fields: +func (_m *ExecutorAPIMock) listAllocations() ([]*api.AllocationListStub, error) { + ret := _m.Called() -// job is a helper method to define mock.On call -// - jobID string -func (_e *ExecutorAPIMock_Expecter) job(jobID interface{}) *ExecutorAPIMock_job_Call { - return &ExecutorAPIMock_job_Call{Call: _e.mock.On("job", jobID)} -} + var r0 []*api.AllocationListStub + var r1 error + if rf, ok := ret.Get(0).(func() ([]*api.AllocationListStub, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() []*api.AllocationListStub); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*api.AllocationListStub) + } + } -func (_c *ExecutorAPIMock_job_Call) Run(run func(jobID string)) *ExecutorAPIMock_job_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string)) - }) - return _c -} + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } -func (_c *ExecutorAPIMock_job_Call) Return(job *api.Job, err error) *ExecutorAPIMock_job_Call { - _c.Call.Return(job, err) - return _c -} - -func (_c *ExecutorAPIMock_job_Call) RunAndReturn(run func(string) (*api.Job, error)) *ExecutorAPIMock_job_Call { - _c.Call.Return(run) - return _c + return r0, r1 } // listJobs provides a mock function with given fields: prefix @@ -1004,34 +474,6 @@ func (_m *ExecutorAPIMock) listJobs(prefix string) ([]*api.JobListStub, error) { return r0, r1 } -// ExecutorAPIMock_listJobs_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'listJobs' -type ExecutorAPIMock_listJobs_Call struct { - *mock.Call -} - -// listJobs is a helper method to define mock.On call -// - prefix string -func (_e *ExecutorAPIMock_Expecter) listJobs(prefix interface{}) *ExecutorAPIMock_listJobs_Call { - return &ExecutorAPIMock_listJobs_Call{Call: _e.mock.On("listJobs", prefix)} -} - -func (_c *ExecutorAPIMock_listJobs_Call) Run(run func(prefix string)) *ExecutorAPIMock_listJobs_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(string)) - }) - return _c -} - -func (_c *ExecutorAPIMock_listJobs_Call) Return(allocationListStub []*api.JobListStub, err error) *ExecutorAPIMock_listJobs_Call { - _c.Call.Return(allocationListStub, err) - return _c -} - -func (_c *ExecutorAPIMock_listJobs_Call) RunAndReturn(run func(string) ([]*api.JobListStub, error)) *ExecutorAPIMock_listJobs_Call { - _c.Call.Return(run) - return _c -} - type mockConstructorTestingTNewExecutorAPIMock interface { mock.TestingT Cleanup(func()) diff --git a/internal/nomad/nomad.go b/internal/nomad/nomad.go index a3e95bb..863e5c0 100644 --- a/internal/nomad/nomad.go +++ b/internal/nomad/nomad.go @@ -93,13 +93,19 @@ type ExecutorAPI interface { type APIClient struct { apiQuerier evaluations map[string]chan error + // allocations contain management data for all pending and running allocations. + allocations storage.Storage[*allocationData] isListening bool } // NewExecutorAPI creates a new api client. // One client is usually sufficient for the complete runtime of the API. func NewExecutorAPI(nomadConfig *config.Nomad) (ExecutorAPI, error) { - client := &APIClient{apiQuerier: &nomadAPIClient{}, evaluations: map[string]chan error{}} + client := &APIClient{ + apiQuerier: &nomadAPIClient{}, + evaluations: map[string]chan error{}, + allocations: storage.NewMonitoredLocalStorage[*allocationData](monitoring.MeasurementNomadAllocations, nil, 0, nil), + } err := client.init(nomadConfig) return client, err } @@ -138,6 +144,8 @@ func (a *APIClient) LoadRunnerPortMappings(runnerID string) ([]nomadApi.PortMapp } func (a *APIClient) LoadRunnerJobs(environmentID dto.EnvironmentID) ([]*nomadApi.Job, error) { + go a.initializeAllocations() + runnerIDs, err := a.LoadRunnerIDs(RunnerJobID(environmentID, "")) if err != nil { return []*nomadApi.Job{}, fmt.Errorf("couldn't load jobs: %w", err) @@ -192,15 +200,13 @@ func (a *APIClient) WatchEventStream(ctx context.Context, callbacks *AllocationP if err != nil { return fmt.Errorf("failed retrieving allocation stream: %w", err) } - // allocations contain management data for all pending and running allocations. - allocations := storage.NewMonitoredLocalStorage[*allocationData](monitoring.MeasurementNomadAllocations, nil, 0, nil) handler := func(event *nomadApi.Event) (bool, error) { switch event.Topic { case nomadApi.TopicEvaluation: return false, handleEvaluationEvent(a.evaluations, event) case nomadApi.TopicAllocation: - return false, handleAllocationEvent(startTime, allocations, event, callbacks) + return false, handleAllocationEvent(startTime, a.allocations, event, callbacks) default: return false, nil } @@ -212,6 +218,24 @@ func (a *APIClient) WatchEventStream(ctx context.Context, callbacks *AllocationP return err } +func (a *APIClient) initializeAllocations() { + allocationStubs, err := a.listAllocations() + if err != nil { + log.WithError(err).Warn("Could not initialize allocations") + } else { + for _, stub := range allocationStubs { + if IsEnvironmentTemplateID(stub.JobID) { + continue + } else if stub.ClientStatus == structs.AllocClientStatusPending || + stub.ClientStatus == structs.AllocClientStatusRunning { + log.WithField("jobID", stub.JobID).WithField("status", stub.ClientStatus).Debug("Recovered Runner") + a.allocations.Add(stub.ID, + &allocationData{allocClientStatus: stub.ClientStatus, start: time.Unix(0, stub.CreateTime)}) + } + } + } +} + // nomadAPIEventHandler is a function that receives a nomadApi.Event and processes it. // It is called by an event listening loop. For each received event, the function is called. // If done is true, the calling function knows that it should break out of the event listening diff --git a/internal/nomad/nomad_test.go b/internal/nomad/nomad_test.go index 0c288d8..a7b9c57 100644 --- a/internal/nomad/nomad_test.go +++ b/internal/nomad/nomad_test.go @@ -184,7 +184,7 @@ func asynchronouslyMonitorEvaluation(stream chan *nomadApi.Events) chan error { apiMock := &apiQuerierMock{} apiMock.On("EventStream", mock.AnythingOfType("*context.cancelCtx")). Return(readOnlyStream, nil) - apiClient := &APIClient{apiMock, map[string]chan error{}, false} + apiClient := &APIClient{apiMock, map[string]chan error{}, storage.NewLocalStorage[*allocationData](), false} errChan := make(chan error) go func() { @@ -212,7 +212,7 @@ func TestApiClient_MonitorEvaluationReturnsErrorWhenStreamReturnsError(t *testin apiMock := &apiQuerierMock{} apiMock.On("EventStream", mock.AnythingOfType("*context.cancelCtx")). Return(nil, tests.ErrDefault) - apiClient := &APIClient{apiMock, map[string]chan error{}, false} + apiClient := &APIClient{apiMock, map[string]chan error{}, storage.NewLocalStorage[*allocationData](), false} err := apiClient.MonitorEvaluation("id", context.Background()) assert.ErrorIs(t, err, tests.ErrDefault) } @@ -466,7 +466,7 @@ func TestApiClient_WatchAllocationsHandlesEvents(t *testing.T) { eventForAllocation(t, newStartedAllocation), }} - newStoppedAllocation := createRecentAllocation(structs.AllocClientStatusRunning, structs.AllocDesiredStatusStop) + newStoppedAllocation := createRecentAllocation(structs.AllocClientStatusComplete, structs.AllocDesiredStatusStop) stopAllocationEvents := nomadApi.Events{Events: []nomadApi.Event{ eventForAllocation(t, newPendingAllocation), eventForAllocation(t, newStartedAllocation), @@ -524,7 +524,7 @@ func TestHandleAllocationEventBuffersPendingAllocation(t *testing.T) { func TestAPIClient_WatchAllocationsReturnsErrorWhenAllocationStreamCannotBeRetrieved(t *testing.T) { apiMock := &apiQuerierMock{} apiMock.On("EventStream", mock.Anything).Return(nil, tests.ErrDefault) - apiClient := &APIClient{apiMock, map[string]chan error{}, false} + apiClient := &APIClient{apiMock, map[string]chan error{}, storage.NewLocalStorage[*allocationData](), false} err := apiClient.WatchEventStream(context.Background(), noopAllocationProcessoring) assert.ErrorIs(t, err, tests.ErrDefault) @@ -598,7 +598,7 @@ func asynchronouslyWatchAllocations(stream chan *nomadApi.Events, callbacks *All apiMock := &apiQuerierMock{} apiMock.On("EventStream", ctx).Return(readOnlyStream, nil) - apiClient := &APIClient{apiMock, map[string]chan error{}, false} + apiClient := &APIClient{apiMock, map[string]chan error{}, storage.NewLocalStorage[*allocationData](), false} errChan := make(chan error) go func() {