Add the Environment ID to the influxdb data.
Also move the interface of an execution environment into its own file, execution_environment.go.
This commit is contained in:
@ -47,8 +47,8 @@ func configureV1Router(router *mux.Router,
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
})
|
||||
v1 := router.PathPrefix(BasePath).Subrouter()
|
||||
v1.HandleFunc(HealthPath, Health).Methods(http.MethodGet)
|
||||
v1.HandleFunc(VersionPath, Version).Methods(http.MethodGet)
|
||||
v1.HandleFunc(HealthPath, Health).Methods(http.MethodGet).Name(HealthPath)
|
||||
v1.HandleFunc(VersionPath, Version).Methods(http.MethodGet).Name(VersionPath)
|
||||
|
||||
runnerController := &RunnerController{manager: runnerManager}
|
||||
environmentController := &EnvironmentController{manager: environmentManager}
|
||||
@ -59,7 +59,8 @@ func configureV1Router(router *mux.Router,
|
||||
// May add a statistics controller if another route joins
|
||||
statisticsRouter := router.PathPrefix(StatisticsPath).Subrouter()
|
||||
statisticsRouter.
|
||||
HandleFunc(EnvironmentsPath, StatisticsExecutionEnvironments(environmentManager)).Methods(http.MethodGet)
|
||||
HandleFunc(EnvironmentsPath, StatisticsExecutionEnvironments(environmentManager)).
|
||||
Methods(http.MethodGet).Name(EnvironmentsPath)
|
||||
}
|
||||
|
||||
if auth.InitializeAuthentication() {
|
||||
|
@ -51,7 +51,6 @@ func (r *RunnerController) provide(writer http.ResponseWriter, request *http.Req
|
||||
return
|
||||
}
|
||||
environmentID := dto.EnvironmentID(runnerRequest.ExecutionEnvironmentID)
|
||||
logging.AddEnvironmentID(request, environmentID)
|
||||
|
||||
nextRunner, err := r.manager.Claim(environmentID, runnerRequest.InactivityTimeout)
|
||||
if err != nil {
|
||||
@ -66,7 +65,7 @@ func (r *RunnerController) provide(writer http.ResponseWriter, request *http.Req
|
||||
}
|
||||
return
|
||||
}
|
||||
logging.AddRunnerID(request, nextRunner.ID())
|
||||
addMonitoringData(request, nextRunner)
|
||||
sendJSON(writer, &dto.RunnerResponse{ID: nextRunner.ID(), MappedPorts: nextRunner.MappedPorts()}, http.StatusOK)
|
||||
}
|
||||
|
||||
@ -80,7 +79,7 @@ func (r *RunnerController) updateFileSystem(writer http.ResponseWriter, request
|
||||
}
|
||||
|
||||
targetRunner, _ := runner.FromContext(request.Context())
|
||||
logging.AddRunnerID(request, targetRunner.ID())
|
||||
addMonitoringData(request, targetRunner)
|
||||
if err := targetRunner.UpdateFileSystem(fileCopyRequest); err != nil {
|
||||
log.WithError(err).Error("Could not perform the requested updateFileSystem.")
|
||||
writeInternalServerError(writer, err, dto.ErrorUnknown)
|
||||
@ -106,7 +105,7 @@ func (r *RunnerController) execute(writer http.ResponseWriter, request *http.Req
|
||||
scheme = "ws"
|
||||
}
|
||||
targetRunner, _ := runner.FromContext(request.Context())
|
||||
logging.AddRunnerID(request, targetRunner.ID())
|
||||
addMonitoringData(request, targetRunner)
|
||||
|
||||
path, err := r.runnerRouter.Get(WebsocketPath).URL(RunnerIDKey, targetRunner.ID())
|
||||
if err != nil {
|
||||
@ -158,7 +157,7 @@ func (r *RunnerController) findRunnerMiddleware(next http.Handler) http.Handler
|
||||
// It destroys the given runner on the executor and removes it from the used runners list.
|
||||
func (r *RunnerController) delete(writer http.ResponseWriter, request *http.Request) {
|
||||
targetRunner, _ := runner.FromContext(request.Context())
|
||||
logging.AddRunnerID(request, targetRunner.ID())
|
||||
addMonitoringData(request, targetRunner)
|
||||
|
||||
err := r.manager.Return(targetRunner)
|
||||
if err != nil {
|
||||
@ -172,3 +171,9 @@ func (r *RunnerController) delete(writer http.ResponseWriter, request *http.Requ
|
||||
|
||||
writer.WriteHeader(http.StatusNoContent)
|
||||
}
|
||||
|
||||
// addMonitoringData adds the data of the runner and environment we want to monitor.
|
||||
func addMonitoringData(request *http.Request, r runner.Runner) {
|
||||
logging.AddRunnerID(request, r.ID())
|
||||
logging.AddEnvironmentID(request, r.Environment())
|
||||
}
|
||||
|
@ -254,6 +254,7 @@ func (s *UpdateFileSystemRouteTestSuite) SetupTest() {
|
||||
s.path = routeURL.String()
|
||||
s.runnerMock = &runner.RunnerMock{}
|
||||
s.runnerMock.On("ID").Return(tests.DefaultMockID)
|
||||
s.runnerMock.On("Environment").Return(dto.EnvironmentID(tests.DefaultEnvironmentIDAsInteger))
|
||||
s.runnerManager.On("Get", tests.DefaultMockID).Return(s.runnerMock, nil)
|
||||
s.recorder = httptest.NewRecorder()
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/openHPI/poseidon/internal/runner"
|
||||
"github.com/openHPI/poseidon/pkg/dto"
|
||||
"github.com/openHPI/poseidon/pkg/logging"
|
||||
"io"
|
||||
"net/http"
|
||||
"sync"
|
||||
@ -337,7 +336,8 @@ func (wp *webSocketProxy) writeMessage(messageType int, data []byte) error {
|
||||
// connectToRunner is the endpoint for websocket connections.
|
||||
func (r *RunnerController) connectToRunner(writer http.ResponseWriter, request *http.Request) {
|
||||
targetRunner, _ := runner.FromContext(request.Context())
|
||||
logging.AddRunnerID(request, targetRunner.ID())
|
||||
addMonitoringData(request, targetRunner)
|
||||
|
||||
executionID := request.URL.Query().Get(ExecutionIDKey)
|
||||
if !targetRunner.ExecutionExists(executionID) {
|
||||
writeNotFound(writer, ErrUnknownExecutionID)
|
||||
|
49
internal/runner/execution_environment.go
Normal file
49
internal/runner/execution_environment.go
Normal file
@ -0,0 +1,49 @@
|
||||
package runner
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/openHPI/poseidon/pkg/dto"
|
||||
)
|
||||
|
||||
// ExecutionEnvironment are groups of runner that share the configuration stored in the environment.
|
||||
type ExecutionEnvironment interface {
|
||||
json.Marshaler
|
||||
|
||||
// ID returns the id of the environment.
|
||||
ID() dto.EnvironmentID
|
||||
SetID(id dto.EnvironmentID)
|
||||
// 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() error
|
||||
// CPULimit sets the share of cpu that a runner should receive at minimum.
|
||||
CPULimit() uint
|
||||
SetCPULimit(limit uint)
|
||||
// MemoryLimit sets the amount of memory that should be available for each runner.
|
||||
MemoryLimit() uint
|
||||
SetMemoryLimit(limit uint)
|
||||
// Image sets the image of the runner, e.g. Docker image.
|
||||
Image() string
|
||||
SetImage(image string)
|
||||
// NetworkAccess sets if a runner should have network access and if ports should be mapped.
|
||||
NetworkAccess() (bool, []uint16)
|
||||
SetNetworkAccess(allow bool, ports []uint16)
|
||||
// SetConfigFrom copies all above attributes from the passed environment to the object itself.
|
||||
SetConfigFrom(environment ExecutionEnvironment)
|
||||
|
||||
// Register saves this environment at the executor.
|
||||
Register() error
|
||||
// Delete removes this environment and all it's runner from the executor and Poseidon itself.
|
||||
Delete() error
|
||||
|
||||
// Sample returns and removes an arbitrary available runner.
|
||||
// ok is true iff a runner was returned.
|
||||
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.
|
||||
DeleteRunner(id string)
|
||||
// IdleRunnerCount returns the number of idle runners of the environment.
|
||||
IdleRunnerCount() int
|
||||
}
|
@ -1,52 +1,6 @@
|
||||
package runner
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/openHPI/poseidon/pkg/dto"
|
||||
)
|
||||
|
||||
// ExecutionEnvironment are groups of runner that share the configuration stored in the environment.
|
||||
type ExecutionEnvironment interface {
|
||||
json.Marshaler
|
||||
|
||||
// ID returns the id of the environment.
|
||||
ID() dto.EnvironmentID
|
||||
SetID(id dto.EnvironmentID)
|
||||
// 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() error
|
||||
// CPULimit sets the share of cpu that a runner should receive at minimum.
|
||||
CPULimit() uint
|
||||
SetCPULimit(limit uint)
|
||||
// MemoryLimit sets the amount of memory that should be available for each runner.
|
||||
MemoryLimit() uint
|
||||
SetMemoryLimit(limit uint)
|
||||
// Image sets the image of the runner, e.g. Docker image.
|
||||
Image() string
|
||||
SetImage(image string)
|
||||
// NetworkAccess sets if a runner should have network access and if ports should be mapped.
|
||||
NetworkAccess() (bool, []uint16)
|
||||
SetNetworkAccess(allow bool, ports []uint16)
|
||||
// SetConfigFrom copies all above attributes from the passed environment to the object itself.
|
||||
SetConfigFrom(environment ExecutionEnvironment)
|
||||
|
||||
// Register saves this environment at the executor.
|
||||
Register() error
|
||||
// Delete removes this environment and all it's runner from the executor and Poseidon itself.
|
||||
Delete() error
|
||||
|
||||
// Sample returns and removes an arbitrary available runner.
|
||||
// ok is true iff a runner was returned.
|
||||
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.
|
||||
DeleteRunner(id string)
|
||||
// IdleRunnerCount returns the number of idle runners of the environment.
|
||||
IdleRunnerCount() int
|
||||
}
|
||||
import "github.com/openHPI/poseidon/pkg/dto"
|
||||
|
||||
// Manager keeps track of the used and unused runners of all execution environments in order to provide unused
|
||||
// runners to new clients and ensure no runner is used twice.
|
||||
|
Reference in New Issue
Block a user