Make Execution Environment interface Nomad independent
This commit is contained in:
@@ -5,8 +5,6 @@ package runner
|
||||
import (
|
||||
dto "github.com/openHPI/poseidon/pkg/dto"
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
|
||||
nomad "github.com/openHPI/poseidon/internal/nomad"
|
||||
)
|
||||
|
||||
// ExecutionEnvironmentMock is an autogenerated mock type for the ExecutionEnvironment type
|
||||
@@ -19,13 +17,13 @@ func (_m *ExecutionEnvironmentMock) AddRunner(r Runner) {
|
||||
_m.Called(r)
|
||||
}
|
||||
|
||||
// ApplyPrewarmingPoolSize provides a mock function with given fields: apiClient
|
||||
func (_m *ExecutionEnvironmentMock) ApplyPrewarmingPoolSize(apiClient nomad.ExecutorAPI) error {
|
||||
ret := _m.Called(apiClient)
|
||||
// ApplyPrewarmingPoolSize provides a mock function with given fields:
|
||||
func (_m *ExecutionEnvironmentMock) ApplyPrewarmingPoolSize() error {
|
||||
ret := _m.Called()
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(nomad.ExecutorAPI) error); ok {
|
||||
r0 = rf(apiClient)
|
||||
if rf, ok := ret.Get(0).(func() error); ok {
|
||||
r0 = rf()
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
@@ -47,13 +45,13 @@ func (_m *ExecutionEnvironmentMock) CPULimit() uint {
|
||||
return r0
|
||||
}
|
||||
|
||||
// Delete provides a mock function with given fields: apiClient
|
||||
func (_m *ExecutionEnvironmentMock) Delete(apiClient nomad.ExecutorAPI) error {
|
||||
ret := _m.Called(apiClient)
|
||||
// Delete provides a mock function with given fields:
|
||||
func (_m *ExecutionEnvironmentMock) Delete() error {
|
||||
ret := _m.Called()
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(nomad.ExecutorAPI) error); ok {
|
||||
r0 = rf(apiClient)
|
||||
if rf, ok := ret.Get(0).(func() error); ok {
|
||||
r0 = rf()
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
@@ -182,13 +180,13 @@ func (_m *ExecutionEnvironmentMock) PrewarmingPoolSize() uint {
|
||||
return r0
|
||||
}
|
||||
|
||||
// Register provides a mock function with given fields: apiClient
|
||||
func (_m *ExecutionEnvironmentMock) Register(apiClient nomad.ExecutorAPI) error {
|
||||
ret := _m.Called(apiClient)
|
||||
// Register provides a mock function with given fields:
|
||||
func (_m *ExecutionEnvironmentMock) Register() error {
|
||||
ret := _m.Called()
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(nomad.ExecutorAPI) error); ok {
|
||||
r0 = rf(apiClient)
|
||||
if rf, ok := ret.Get(0).(func() error); ok {
|
||||
r0 = rf()
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
@@ -196,13 +194,13 @@ func (_m *ExecutionEnvironmentMock) Register(apiClient nomad.ExecutorAPI) error
|
||||
return r0
|
||||
}
|
||||
|
||||
// Sample provides a mock function with given fields: apiClient
|
||||
func (_m *ExecutionEnvironmentMock) Sample(apiClient nomad.ExecutorAPI) (Runner, bool) {
|
||||
ret := _m.Called(apiClient)
|
||||
// Sample provides a mock function with given fields:
|
||||
func (_m *ExecutionEnvironmentMock) Sample() (Runner, bool) {
|
||||
ret := _m.Called()
|
||||
|
||||
var r0 Runner
|
||||
if rf, ok := ret.Get(0).(func(nomad.ExecutorAPI) Runner); ok {
|
||||
r0 = rf(apiClient)
|
||||
if rf, ok := ret.Get(0).(func() Runner); ok {
|
||||
r0 = rf()
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(Runner)
|
||||
@@ -210,8 +208,8 @@ func (_m *ExecutionEnvironmentMock) Sample(apiClient nomad.ExecutorAPI) (Runner,
|
||||
}
|
||||
|
||||
var r1 bool
|
||||
if rf, ok := ret.Get(1).(func(nomad.ExecutorAPI) bool); ok {
|
||||
r1 = rf(apiClient)
|
||||
if rf, ok := ret.Get(1).(func() bool); ok {
|
||||
r1 = rf()
|
||||
} else {
|
||||
r1 = ret.Get(1).(bool)
|
||||
}
|
||||
|
@@ -2,7 +2,6 @@ package runner
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/openHPI/poseidon/internal/nomad"
|
||||
"github.com/openHPI/poseidon/pkg/dto"
|
||||
)
|
||||
|
||||
@@ -17,7 +16,7 @@ type ExecutionEnvironment interface {
|
||||
PrewarmingPoolSize() uint
|
||||
SetPrewarmingPoolSize(count uint)
|
||||
// ApplyPrewarmingPoolSize creates idle runners according to the PrewarmingPoolSize.
|
||||
ApplyPrewarmingPoolSize(apiClient nomad.ExecutorAPI) error
|
||||
ApplyPrewarmingPoolSize() error
|
||||
// CPULimit sets the share of cpu that a runner should receive at minimum.
|
||||
CPULimit() uint
|
||||
SetCPULimit(limit uint)
|
||||
@@ -34,13 +33,13 @@ type ExecutionEnvironment interface {
|
||||
SetConfigFrom(environment ExecutionEnvironment)
|
||||
|
||||
// Register saves this environment at the executor.
|
||||
Register(apiClient nomad.ExecutorAPI) error
|
||||
Register() error
|
||||
// Delete removes this environment and all it's runner from the executor and Poseidon itself.
|
||||
Delete(apiClient nomad.ExecutorAPI) error
|
||||
Delete() error
|
||||
|
||||
// Sample returns and removes an arbitrary available runner.
|
||||
// ok is true iff a runner was returned.
|
||||
Sample(apiClient nomad.ExecutorAPI) (r Runner, ok bool)
|
||||
Sample() (r Runner, ok bool)
|
||||
// AddRunner adds an existing runner to the idle runners of the environment.
|
||||
AddRunner(r Runner)
|
||||
// DeleteRunner removes an idle runner from the environment.
|
||||
|
@@ -83,7 +83,7 @@ func (m *NomadRunnerManager) Claim(environmentID dto.EnvironmentID, duration int
|
||||
if !ok {
|
||||
return nil, ErrUnknownExecutionEnvironment
|
||||
}
|
||||
runner, ok := environment.Sample(m.apiClient)
|
||||
runner, ok := environment.Sample()
|
||||
if !ok {
|
||||
return nil, ErrNoRunnersAvailable
|
||||
}
|
||||
@@ -133,7 +133,7 @@ func (m *NomadRunnerManager) Load() {
|
||||
for _, job := range runnerJobs {
|
||||
m.loadSingleJob(job, environmentLogger, environment)
|
||||
}
|
||||
err = environment.ApplyPrewarmingPoolSize(m.apiClient)
|
||||
err = environment.ApplyPrewarmingPoolSize()
|
||||
if err != nil {
|
||||
environmentLogger.WithError(err).Error("Couldn't scale environment")
|
||||
}
|
||||
|
@@ -227,7 +227,7 @@ func (s *ManagerTestSuite) TestUpdateRunnersAddsIdleRunner() {
|
||||
allocation.JobID = environment.ID().ToString()
|
||||
mockIdleRunners(environment.(*ExecutionEnvironmentMock))
|
||||
|
||||
_, ok = environment.Sample(s.apiMock)
|
||||
_, ok = environment.Sample()
|
||||
s.Require().False(ok)
|
||||
|
||||
modifyMockedCall(s.apiMock, "WatchEventStream", func(call *mock.Call) {
|
||||
@@ -244,7 +244,7 @@ func (s *ManagerTestSuite) TestUpdateRunnersAddsIdleRunner() {
|
||||
go s.nomadRunnerManager.keepRunnersSynced(ctx)
|
||||
<-time.After(10 * time.Millisecond)
|
||||
|
||||
_, ok = environment.Sample(s.apiMock)
|
||||
_, ok = environment.Sample()
|
||||
s.True(ok)
|
||||
}
|
||||
|
||||
@@ -272,7 +272,7 @@ func (s *ManagerTestSuite) TestUpdateRunnersRemovesIdleAndUsedRunner() {
|
||||
go s.nomadRunnerManager.keepRunnersSynced(ctx)
|
||||
<-time.After(10 * time.Millisecond)
|
||||
|
||||
_, ok = environment.Sample(s.apiMock)
|
||||
_, ok = environment.Sample()
|
||||
s.False(ok)
|
||||
_, ok = s.nomadRunnerManager.usedRunners.Get(allocation.JobID)
|
||||
s.False(ok)
|
||||
@@ -295,7 +295,7 @@ func (s *ManagerTestSuite) TestOnAllocationAdded() {
|
||||
alloc := &nomadApi.Allocation{JobID: nomad.TemplateJobID(tests.DefaultEnvironmentIDAsInteger)}
|
||||
s.nomadRunnerManager.onAllocationAdded(alloc)
|
||||
|
||||
_, ok = environment.Sample(s.apiMock)
|
||||
_, ok = environment.Sample()
|
||||
s.False(ok)
|
||||
})
|
||||
s.Run("does not panic when environment id cannot be parsed", func() {
|
||||
@@ -326,7 +326,7 @@ func (s *ManagerTestSuite) TestOnAllocationAdded() {
|
||||
}
|
||||
s.nomadRunnerManager.onAllocationAdded(alloc)
|
||||
|
||||
runner, ok := environment.Sample(s.apiMock)
|
||||
runner, ok := environment.Sample()
|
||||
s.True(ok)
|
||||
nomadJob, ok := runner.(*NomadJob)
|
||||
s.True(ok)
|
||||
@@ -346,7 +346,7 @@ func (s *ManagerTestSuite) TestOnAllocationAdded() {
|
||||
}
|
||||
s.nomadRunnerManager.onAllocationAdded(alloc)
|
||||
|
||||
runner, ok := environment.Sample(s.apiMock)
|
||||
runner, ok := environment.Sample()
|
||||
s.True(ok)
|
||||
nomadJob, ok := runner.(*NomadJob)
|
||||
s.True(ok)
|
||||
|
Reference in New Issue
Block a user