Implement review suggestions
This commit is contained in:
@@ -19,6 +19,20 @@ 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)
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(nomad.ExecutorAPI) error); ok {
|
||||
r0 = rf(apiClient)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// CPULimit provides a mock function with given fields:
|
||||
func (_m *ExecutionEnvironmentMock) CPULimit() uint {
|
||||
ret := _m.Called()
|
||||
@@ -205,20 +219,6 @@ func (_m *ExecutionEnvironmentMock) Sample(apiClient nomad.ExecutorAPI) (Runner,
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// Scale provides a mock function with given fields: apiClient
|
||||
func (_m *ExecutionEnvironmentMock) Scale(apiClient nomad.ExecutorAPI) error {
|
||||
ret := _m.Called(apiClient)
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(nomad.ExecutorAPI) error); ok {
|
||||
r0 = rf(apiClient)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
||||
// SetCPULimit provides a mock function with given fields: limit
|
||||
func (_m *ExecutionEnvironmentMock) SetCPULimit(limit uint) {
|
||||
_m.Called(limit)
|
||||
@@ -253,17 +253,3 @@ func (_m *ExecutionEnvironmentMock) SetNetworkAccess(allow bool, ports []uint16)
|
||||
func (_m *ExecutionEnvironmentMock) SetPrewarmingPoolSize(count uint) {
|
||||
_m.Called(count)
|
||||
}
|
||||
|
||||
// UpdateRunnerSpecs provides a mock function with given fields: apiClient
|
||||
func (_m *ExecutionEnvironmentMock) UpdateRunnerSpecs(apiClient nomad.ExecutorAPI) error {
|
||||
ret := _m.Called(apiClient)
|
||||
|
||||
var r0 error
|
||||
if rf, ok := ret.Get(0).(func(nomad.ExecutorAPI) error); ok {
|
||||
r0 = rf(apiClient)
|
||||
} else {
|
||||
r0 = ret.Error(0)
|
||||
}
|
||||
|
||||
return r0
|
||||
}
|
||||
|
@@ -31,6 +31,8 @@ type ExecutionEnvironment interface {
|
||||
// PrewarmingPoolSize sets the number of idle runner of this environment that should be prewarmed.
|
||||
PrewarmingPoolSize() uint
|
||||
SetPrewarmingPoolSize(count uint)
|
||||
// ApplyPrewarmingPoolSize creates idle runners according to the PrewarmingPoolSize.
|
||||
ApplyPrewarmingPoolSize(apiClient nomad.ExecutorAPI) error
|
||||
// CPULimit sets the share of cpu that a runner should receive at minimum.
|
||||
CPULimit() uint
|
||||
SetCPULimit(limit uint)
|
||||
@@ -50,8 +52,6 @@ type ExecutionEnvironment interface {
|
||||
Register(apiClient nomad.ExecutorAPI) error
|
||||
// Delete removes this environment and all it's runner from the executor and Poseidon itself.
|
||||
Delete(apiClient nomad.ExecutorAPI) error
|
||||
// Scale manages if the executor has enough idle runner according to the PrewarmingPoolSize.
|
||||
Scale(apiClient nomad.ExecutorAPI) error
|
||||
|
||||
// Sample returns and removes an arbitrary available runner.
|
||||
// ok is true iff a runner was returned.
|
||||
@@ -74,9 +74,8 @@ type Manager interface {
|
||||
// Iff the requested environment is not stored it returns false.
|
||||
GetEnvironment(id dto.EnvironmentID) (ExecutionEnvironment, bool)
|
||||
|
||||
// SetEnvironment stores the environment in Poseidons memory.
|
||||
// It returns true iff a new environment is stored and false iff an existing environment was updated.
|
||||
SetEnvironment(environment ExecutionEnvironment) bool
|
||||
// StoreEnvironment stores the environment in Poseidons memory.
|
||||
StoreEnvironment(environment ExecutionEnvironment)
|
||||
|
||||
// DeleteEnvironment removes the specified execution environment in Poseidons memory.
|
||||
// It does nothing if the specified environment can not be found.
|
||||
@@ -129,10 +128,8 @@ func (m *NomadRunnerManager) GetEnvironment(id dto.EnvironmentID) (ExecutionEnvi
|
||||
return m.environments.Get(id)
|
||||
}
|
||||
|
||||
func (m *NomadRunnerManager) SetEnvironment(environment ExecutionEnvironment) bool {
|
||||
_, ok := m.environments.Get(environment.ID())
|
||||
func (m *NomadRunnerManager) StoreEnvironment(environment ExecutionEnvironment) {
|
||||
m.environments.Add(environment)
|
||||
return !ok
|
||||
}
|
||||
|
||||
func (m *NomadRunnerManager) DeleteEnvironment(id dto.EnvironmentID) {
|
||||
@@ -215,7 +212,7 @@ func (m *NomadRunnerManager) Load() {
|
||||
for _, job := range runnerJobs {
|
||||
m.loadSingleJob(job, environmentLogger, environment)
|
||||
}
|
||||
err = environment.Scale(m.apiClient)
|
||||
err = environment.ApplyPrewarmingPoolSize(m.apiClient)
|
||||
if err != nil {
|
||||
environmentLogger.WithError(err).Error("Couldn't scale environment")
|
||||
}
|
||||
|
@@ -137,16 +137,7 @@ func (_m *ManagerMock) Return(r Runner) error {
|
||||
return r0
|
||||
}
|
||||
|
||||
// SetEnvironment provides a mock function with given fields: environment
|
||||
func (_m *ManagerMock) SetEnvironment(environment ExecutionEnvironment) bool {
|
||||
ret := _m.Called(environment)
|
||||
|
||||
var r0 bool
|
||||
if rf, ok := ret.Get(0).(func(ExecutionEnvironment) bool); ok {
|
||||
r0 = rf(environment)
|
||||
} else {
|
||||
r0 = ret.Get(0).(bool)
|
||||
}
|
||||
|
||||
return r0
|
||||
// StoreEnvironment provides a mock function with given fields: environment
|
||||
func (_m *ManagerMock) StoreEnvironment(environment ExecutionEnvironment) {
|
||||
_m.Called(environment)
|
||||
}
|
||||
|
@@ -82,8 +82,7 @@ func mockIdleRunners(environmentMock *ExecutionEnvironmentMock) {
|
||||
|
||||
func (s *ManagerTestSuite) setDefaultEnvironment() {
|
||||
s.exerciseEnvironment.On("ID").Return(defaultEnvironmentID)
|
||||
created := s.nomadRunnerManager.SetEnvironment(s.exerciseEnvironment)
|
||||
s.Require().True(created)
|
||||
s.nomadRunnerManager.StoreEnvironment(s.exerciseEnvironment)
|
||||
}
|
||||
|
||||
func (s *ManagerTestSuite) waitForRunnerRefresh() {
|
||||
@@ -93,8 +92,7 @@ func (s *ManagerTestSuite) waitForRunnerRefresh() {
|
||||
func (s *ManagerTestSuite) TestSetEnvironmentAddsNewEnvironment() {
|
||||
anotherEnvironment := &ExecutionEnvironmentMock{}
|
||||
anotherEnvironment.On("ID").Return(anotherEnvironmentID)
|
||||
created := s.nomadRunnerManager.SetEnvironment(anotherEnvironment)
|
||||
s.Require().True(created)
|
||||
s.nomadRunnerManager.StoreEnvironment(anotherEnvironment)
|
||||
|
||||
job, ok := s.nomadRunnerManager.environments.Get(anotherEnvironmentID)
|
||||
s.True(ok)
|
||||
|
@@ -21,6 +21,9 @@ type Storage interface {
|
||||
// It does nothing if no runner with the id is present in the store.
|
||||
Delete(id string)
|
||||
|
||||
// Purge removes all runners from the storage.
|
||||
Purge()
|
||||
|
||||
// Length returns the number of currently stored runners in the storage.
|
||||
Length() int
|
||||
|
||||
@@ -72,6 +75,12 @@ func (s *localRunnerStorage) Delete(id string) {
|
||||
delete(s.runners, id)
|
||||
}
|
||||
|
||||
func (s *localRunnerStorage) Purge() {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
s.runners = make(map[string]Runner)
|
||||
}
|
||||
|
||||
func (s *localRunnerStorage) Sample() (Runner, bool) {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
|
Reference in New Issue
Block a user