209 lines
6.9 KiB
Go
209 lines
6.9 KiB
Go
// Package api provides primitives to interact with the openapi HTTP API.
|
|
//
|
|
// Code generated by github.com/deepmap/oapi-codegen version v1.9.0 DO NOT EDIT.
|
|
package api
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/deepmap/oapi-codegen/pkg/runtime"
|
|
"github.com/labstack/echo/v4"
|
|
)
|
|
|
|
// ServerInterface represents all server handlers.
|
|
type ServerInterface interface {
|
|
// Submit a new job for Flamenco Manager to execute.
|
|
// (POST /api/jobs)
|
|
SubmitJob(ctx echo.Context) error
|
|
// Get list of job types and their parameters.
|
|
// (GET /api/jobs/types)
|
|
GetJobTypes(ctx echo.Context) error
|
|
// Fetch info about the job.
|
|
// (GET /api/jobs/{job_id})
|
|
FetchJob(ctx echo.Context, jobId string) error
|
|
// Register a new worker
|
|
// (POST /api/worker/register-worker)
|
|
RegisterWorker(ctx echo.Context) error
|
|
// Mark the worker as offline
|
|
// (POST /api/worker/sign-off)
|
|
SignOff(ctx echo.Context) error
|
|
// Authenticate & sign in the worker.
|
|
// (POST /api/worker/sign-on)
|
|
SignOn(ctx echo.Context) error
|
|
|
|
// (GET /api/worker/state)
|
|
WorkerState(ctx echo.Context) error
|
|
// Worker changed state. This could be as acknowledgement of a Manager-requested state change, or in response to worker-local signals.
|
|
// (POST /api/worker/state-changed)
|
|
WorkerStateChanged(ctx echo.Context) error
|
|
// Obtain a new task to execute
|
|
// (POST /api/worker/task)
|
|
ScheduleTask(ctx echo.Context) error
|
|
// Update the task, typically to indicate progress, completion, or failure.
|
|
// (POST /api/worker/task/{task_id})
|
|
TaskUpdate(ctx echo.Context, taskId string) error
|
|
}
|
|
|
|
// ServerInterfaceWrapper converts echo contexts to parameters.
|
|
type ServerInterfaceWrapper struct {
|
|
Handler ServerInterface
|
|
}
|
|
|
|
// SubmitJob converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) SubmitJob(ctx echo.Context) error {
|
|
var err error
|
|
|
|
// Invoke the callback with all the unmarshalled arguments
|
|
err = w.Handler.SubmitJob(ctx)
|
|
return err
|
|
}
|
|
|
|
// GetJobTypes converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) GetJobTypes(ctx echo.Context) error {
|
|
var err error
|
|
|
|
// Invoke the callback with all the unmarshalled arguments
|
|
err = w.Handler.GetJobTypes(ctx)
|
|
return err
|
|
}
|
|
|
|
// FetchJob converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) FetchJob(ctx echo.Context) error {
|
|
var err error
|
|
// ------------- Path parameter "job_id" -------------
|
|
var jobId string
|
|
|
|
err = runtime.BindStyledParameterWithLocation("simple", false, "job_id", runtime.ParamLocationPath, ctx.Param("job_id"), &jobId)
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter job_id: %s", err))
|
|
}
|
|
|
|
// Invoke the callback with all the unmarshalled arguments
|
|
err = w.Handler.FetchJob(ctx, jobId)
|
|
return err
|
|
}
|
|
|
|
// RegisterWorker converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) RegisterWorker(ctx echo.Context) error {
|
|
var err error
|
|
|
|
// Invoke the callback with all the unmarshalled arguments
|
|
err = w.Handler.RegisterWorker(ctx)
|
|
return err
|
|
}
|
|
|
|
// SignOff converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) SignOff(ctx echo.Context) error {
|
|
var err error
|
|
|
|
ctx.Set(Worker_authScopes, []string{""})
|
|
|
|
// Invoke the callback with all the unmarshalled arguments
|
|
err = w.Handler.SignOff(ctx)
|
|
return err
|
|
}
|
|
|
|
// SignOn converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) SignOn(ctx echo.Context) error {
|
|
var err error
|
|
|
|
ctx.Set(Worker_authScopes, []string{""})
|
|
|
|
// Invoke the callback with all the unmarshalled arguments
|
|
err = w.Handler.SignOn(ctx)
|
|
return err
|
|
}
|
|
|
|
// WorkerState converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) WorkerState(ctx echo.Context) error {
|
|
var err error
|
|
|
|
ctx.Set(Worker_authScopes, []string{""})
|
|
|
|
// Invoke the callback with all the unmarshalled arguments
|
|
err = w.Handler.WorkerState(ctx)
|
|
return err
|
|
}
|
|
|
|
// WorkerStateChanged converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) WorkerStateChanged(ctx echo.Context) error {
|
|
var err error
|
|
|
|
ctx.Set(Worker_authScopes, []string{""})
|
|
|
|
// Invoke the callback with all the unmarshalled arguments
|
|
err = w.Handler.WorkerStateChanged(ctx)
|
|
return err
|
|
}
|
|
|
|
// ScheduleTask converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) ScheduleTask(ctx echo.Context) error {
|
|
var err error
|
|
|
|
ctx.Set(Worker_authScopes, []string{""})
|
|
|
|
// Invoke the callback with all the unmarshalled arguments
|
|
err = w.Handler.ScheduleTask(ctx)
|
|
return err
|
|
}
|
|
|
|
// TaskUpdate converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) TaskUpdate(ctx echo.Context) error {
|
|
var err error
|
|
// ------------- Path parameter "task_id" -------------
|
|
var taskId string
|
|
|
|
err = runtime.BindStyledParameterWithLocation("simple", false, "task_id", runtime.ParamLocationPath, ctx.Param("task_id"), &taskId)
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter task_id: %s", err))
|
|
}
|
|
|
|
ctx.Set(Worker_authScopes, []string{""})
|
|
|
|
// Invoke the callback with all the unmarshalled arguments
|
|
err = w.Handler.TaskUpdate(ctx, taskId)
|
|
return err
|
|
}
|
|
|
|
// This is a simple interface which specifies echo.Route addition functions which
|
|
// are present on both echo.Echo and echo.Group, since we want to allow using
|
|
// either of them for path registration
|
|
type EchoRouter interface {
|
|
CONNECT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
|
|
DELETE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
|
|
GET(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
|
|
HEAD(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
|
|
OPTIONS(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
|
|
PATCH(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
|
|
POST(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
|
|
PUT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
|
|
TRACE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
|
|
}
|
|
|
|
// RegisterHandlers adds each server route to the EchoRouter.
|
|
func RegisterHandlers(router EchoRouter, si ServerInterface) {
|
|
RegisterHandlersWithBaseURL(router, si, "")
|
|
}
|
|
|
|
// Registers handlers, and prepends BaseURL to the paths, so that the paths
|
|
// can be served under a prefix.
|
|
func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL string) {
|
|
|
|
wrapper := ServerInterfaceWrapper{
|
|
Handler: si,
|
|
}
|
|
|
|
router.POST(baseURL+"/api/jobs", wrapper.SubmitJob)
|
|
router.GET(baseURL+"/api/jobs/types", wrapper.GetJobTypes)
|
|
router.GET(baseURL+"/api/jobs/:job_id", wrapper.FetchJob)
|
|
router.POST(baseURL+"/api/worker/register-worker", wrapper.RegisterWorker)
|
|
router.POST(baseURL+"/api/worker/sign-off", wrapper.SignOff)
|
|
router.POST(baseURL+"/api/worker/sign-on", wrapper.SignOn)
|
|
router.GET(baseURL+"/api/worker/state", wrapper.WorkerState)
|
|
router.POST(baseURL+"/api/worker/state-changed", wrapper.WorkerStateChanged)
|
|
router.POST(baseURL+"/api/worker/task", wrapper.ScheduleTask)
|
|
router.POST(baseURL+"/api/worker/task/:task_id", wrapper.TaskUpdate)
|
|
|
|
}
|