Fix bad import rebase artifacts
This commit is contained in:

committed by
Jan-Eric Hellenberg

parent
13052fa021
commit
e45cd92557
@ -3,7 +3,7 @@ package api
|
|||||||
import (
|
import (
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"gitlab.hpi.de/codeocean/codemoon/poseidon/api/auth"
|
"gitlab.hpi.de/codeocean/codemoon/poseidon/api/auth"
|
||||||
"gitlab.hpi.de/codeocean/codemoon/poseidon/environment/pool"
|
"gitlab.hpi.de/codeocean/codemoon/poseidon/environment"
|
||||||
"gitlab.hpi.de/codeocean/codemoon/poseidon/logging"
|
"gitlab.hpi.de/codeocean/codemoon/poseidon/logging"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
@ -21,7 +21,7 @@ const (
|
|||||||
// always returns a router for the newest version of our API. We
|
// always returns a router for the newest version of our API. We
|
||||||
// use gorilla/mux because it is more convenient than net/http, e.g.
|
// use gorilla/mux because it is more convenient than net/http, e.g.
|
||||||
// when extracting path parameters.
|
// when extracting path parameters.
|
||||||
func NewRouter(runnerPool pool.RunnerPool) *mux.Router {
|
func NewRouter(runnerPool environment.RunnerPool) *mux.Router {
|
||||||
router := mux.NewRouter()
|
router := mux.NewRouter()
|
||||||
// this can later be restricted to a specific host with
|
// this can later be restricted to a specific host with
|
||||||
// `router.Host(...)` and to HTTPS with `router.Schemes("https")`
|
// `router.Host(...)` and to HTTPS with `router.Schemes("https")`
|
||||||
@ -32,7 +32,7 @@ func NewRouter(runnerPool pool.RunnerPool) *mux.Router {
|
|||||||
|
|
||||||
// newRouterV1 returns a sub-router containing the routes of version
|
// newRouterV1 returns a sub-router containing the routes of version
|
||||||
// 1 of our API.
|
// 1 of our API.
|
||||||
func newRouterV1(router *mux.Router, runnerPool pool.RunnerPool) *mux.Router {
|
func newRouterV1(router *mux.Router, runnerPool environment.RunnerPool) *mux.Router {
|
||||||
v1 := router.PathPrefix(RouteBase).Subrouter()
|
v1 := router.PathPrefix(RouteBase).Subrouter()
|
||||||
v1.HandleFunc(RouteHealth, Health).Methods(http.MethodGet)
|
v1.HandleFunc(RouteHealth, Health).Methods(http.MethodGet)
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"gitlab.hpi.de/codeocean/codemoon/poseidon/config"
|
"gitlab.hpi.de/codeocean/codemoon/poseidon/config"
|
||||||
"gitlab.hpi.de/codeocean/codemoon/poseidon/environment/pool"
|
"gitlab.hpi.de/codeocean/codemoon/poseidon/environment"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
@ -17,7 +17,7 @@ func mockHTTPHandler(writer http.ResponseWriter, _ *http.Request) {
|
|||||||
func TestNewRouterV1WithAuthenticationDisabled(t *testing.T) {
|
func TestNewRouterV1WithAuthenticationDisabled(t *testing.T) {
|
||||||
config.Config.Server.Token = ""
|
config.Config.Server.Token = ""
|
||||||
router := mux.NewRouter()
|
router := mux.NewRouter()
|
||||||
v1 := newRouterV1(router, pool.NewLocalRunnerPool())
|
v1 := newRouterV1(router, environment.NewLocalRunnerPool())
|
||||||
|
|
||||||
t.Run("health route is accessible", func(t *testing.T) {
|
t.Run("health route is accessible", func(t *testing.T) {
|
||||||
request, err := http.NewRequest(http.MethodGet, "/api/v1/health", nil)
|
request, err := http.NewRequest(http.MethodGet, "/api/v1/health", nil)
|
||||||
@ -44,7 +44,7 @@ func TestNewRouterV1WithAuthenticationDisabled(t *testing.T) {
|
|||||||
func TestNewRouterV1WithAuthenticationEnabled(t *testing.T) {
|
func TestNewRouterV1WithAuthenticationEnabled(t *testing.T) {
|
||||||
config.Config.Server.Token = "TestToken"
|
config.Config.Server.Token = "TestToken"
|
||||||
router := mux.NewRouter()
|
router := mux.NewRouter()
|
||||||
v1 := newRouterV1(router, pool.NewLocalRunnerPool())
|
v1 := newRouterV1(router, environment.NewLocalRunnerPool())
|
||||||
|
|
||||||
t.Run("health route is accessible", func(t *testing.T) {
|
t.Run("health route is accessible", func(t *testing.T) {
|
||||||
request, err := http.NewRequest(http.MethodGet, "/api/v1/health", nil)
|
request, err := http.NewRequest(http.MethodGet, "/api/v1/health", nil)
|
||||||
|
@ -7,7 +7,6 @@ import (
|
|||||||
"gitlab.hpi.de/codeocean/codemoon/poseidon/api/dto"
|
"gitlab.hpi.de/codeocean/codemoon/poseidon/api/dto"
|
||||||
"gitlab.hpi.de/codeocean/codemoon/poseidon/config"
|
"gitlab.hpi.de/codeocean/codemoon/poseidon/config"
|
||||||
"gitlab.hpi.de/codeocean/codemoon/poseidon/environment"
|
"gitlab.hpi.de/codeocean/codemoon/poseidon/environment"
|
||||||
"gitlab.hpi.de/codeocean/codemoon/poseidon/environment/pool"
|
|
||||||
"gitlab.hpi.de/codeocean/codemoon/poseidon/runner"
|
"gitlab.hpi.de/codeocean/codemoon/poseidon/runner"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -95,24 +94,24 @@ func connectToRunner(writer http.ResponseWriter, request *http.Request) {
|
|||||||
|
|
||||||
// The findRunnerMiddleware looks up the runnerId for routes containing it
|
// The findRunnerMiddleware looks up the runnerId for routes containing it
|
||||||
// and adds the runner to the context of the request.
|
// and adds the runner to the context of the request.
|
||||||
func findRunnerMiddleware(runnerPool pool.RunnerPool) func(handler http.Handler) http.Handler {
|
func findRunnerMiddleware(runnerPool environment.RunnerPool) func(handler http.Handler) http.Handler {
|
||||||
return func(next http.Handler) http.Handler {
|
return func(next http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
|
return http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
|
||||||
// Find runner
|
// Find runner
|
||||||
runnerId := mux.Vars(request)[RunnerIdKey]
|
runnerId := mux.Vars(request)[RunnerIdKey]
|
||||||
r, ok := runnerPool.GetRunner(runnerId)
|
r, ok := runnerPool.Get(runnerId)
|
||||||
if !ok {
|
if !ok {
|
||||||
writer.WriteHeader(http.StatusNotFound)
|
writer.WriteHeader(http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ctx := runner.NewContext(request.Context(), r)
|
ctx := runner.NewContext(request.Context(), r.(runner.Runner))
|
||||||
requestWithRunner := request.WithContext(ctx)
|
requestWithRunner := request.WithContext(ctx)
|
||||||
next.ServeHTTP(writer, requestWithRunner)
|
next.ServeHTTP(writer, requestWithRunner)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func registerRunnerRoutes(router *mux.Router, runnerPool pool.RunnerPool) {
|
func registerRunnerRoutes(router *mux.Router, runnerPool environment.RunnerPool) {
|
||||||
router.HandleFunc("", provideRunner).Methods(http.MethodPost)
|
router.HandleFunc("", provideRunner).Methods(http.MethodPost)
|
||||||
runnerRouter := router.PathPrefix(fmt.Sprintf("/{%s}", RunnerIdKey)).Subrouter()
|
runnerRouter := router.PathPrefix(fmt.Sprintf("/{%s}", RunnerIdKey)).Subrouter()
|
||||||
runnerRouter.Use(findRunnerMiddleware(runnerPool))
|
runnerRouter.Use(findRunnerMiddleware(runnerPool))
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"gitlab.hpi.de/codeocean/codemoon/poseidon/api/dto"
|
"gitlab.hpi.de/codeocean/codemoon/poseidon/api/dto"
|
||||||
"gitlab.hpi.de/codeocean/codemoon/poseidon/environment/pool"
|
"gitlab.hpi.de/codeocean/codemoon/poseidon/environment"
|
||||||
"gitlab.hpi.de/codeocean/codemoon/poseidon/runner"
|
"gitlab.hpi.de/codeocean/codemoon/poseidon/runner"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
@ -17,10 +17,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestFindRunnerMiddleware(t *testing.T) {
|
func TestFindRunnerMiddleware(t *testing.T) {
|
||||||
runnerPool := pool.NewLocalRunnerPool()
|
runnerPool := environment.NewLocalRunnerPool()
|
||||||
var capturedRunner runner.Runner
|
var capturedRunner runner.Runner
|
||||||
testRunner := runner.NewExerciseRunner("testRunner")
|
testRunner := runner.NewExerciseRunner("testRunner")
|
||||||
runnerPool.AddRunner(testRunner)
|
runnerPool.Add(testRunner)
|
||||||
|
|
||||||
testRunnerIdRoute := func(writer http.ResponseWriter, request *http.Request) {
|
testRunnerIdRoute := func(writer http.ResponseWriter, request *http.Request) {
|
||||||
var ok bool
|
var ok bool
|
||||||
@ -66,10 +66,10 @@ func TestFindRunnerMiddleware(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestExecuteRoute(t *testing.T) {
|
func TestExecuteRoute(t *testing.T) {
|
||||||
runnerPool := pool.NewLocalRunnerPool()
|
runnerPool := environment.NewLocalRunnerPool()
|
||||||
router := NewRouter(runnerPool)
|
router := NewRouter(runnerPool)
|
||||||
testRunner := runner.NewExerciseRunner("testRunner")
|
testRunner := runner.NewExerciseRunner("testRunner")
|
||||||
runnerPool.AddRunner(testRunner)
|
runnerPool.Add(testRunner)
|
||||||
|
|
||||||
path, err := router.Get(ExecutePath).URL(RunnerIdKey, testRunner.Id())
|
path, err := router.Get(ExecutePath).URL(RunnerIdKey, testRunner.Id())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
4
main.go
4
main.go
@ -38,7 +38,7 @@ func runServer(server *http.Server) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func initServer(runnerPool pool.RunnerPool) *http.Server {
|
func initServer(runnerPool environment.RunnerPool) *http.Server {
|
||||||
return &http.Server{
|
return &http.Server{
|
||||||
Addr: config.Config.PoseidonAPIURL().Host,
|
Addr: config.Config.PoseidonAPIURL().Host,
|
||||||
WriteTimeout: time.Second * 15,
|
WriteTimeout: time.Second * 15,
|
||||||
@ -75,7 +75,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ToDo: Move to create execution environment
|
// ToDo: Move to create execution environment
|
||||||
runnerPool := pool.NewLocalRunnerPool()
|
runnerPool := environment.NewLocalRunnerPool()
|
||||||
environment.DebugInit(runnerPool, nomadAPIClient)
|
environment.DebugInit(runnerPool, nomadAPIClient)
|
||||||
|
|
||||||
server := initServer(runnerPool)
|
server := initServer(runnerPool)
|
||||||
|
Reference in New Issue
Block a user