Unresponsive workers (>=1 hour of no status update) are cleaned up. Several things are enabled by keeping track of workers, in future the worker server could: - keep track of how many workers are active - see if a worker for a specific architecture is available
422 lines
15 KiB
Go
422 lines
15 KiB
Go
// Package api provides primitives to interact with the openapi HTTP API.
|
|
//
|
|
// Code generated by github.com/deepmap/oapi-codegen version v1.8.2 DO NOT EDIT.
|
|
package api
|
|
|
|
import (
|
|
"bytes"
|
|
"compress/gzip"
|
|
"encoding/base64"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
"path"
|
|
"strings"
|
|
|
|
"github.com/deepmap/oapi-codegen/pkg/runtime"
|
|
"github.com/getkin/kin-openapi/openapi3"
|
|
"github.com/labstack/echo/v4"
|
|
)
|
|
|
|
const (
|
|
BearerScopes = "Bearer.Scopes"
|
|
)
|
|
|
|
// Error defines model for Error.
|
|
type Error struct {
|
|
// Embedded struct due to allOf(#/components/schemas/ObjectReference)
|
|
ObjectReference `yaml:",inline"`
|
|
// Embedded fields due to inline allOf schema
|
|
Code string `json:"code"`
|
|
|
|
// Backward compatibility with workers <= v33, equals reason
|
|
Message string `json:"message"`
|
|
OperationId string `json:"operation_id"`
|
|
Reason string `json:"reason"`
|
|
}
|
|
|
|
// GetJobResponse defines model for GetJobResponse.
|
|
type GetJobResponse struct {
|
|
// Embedded struct due to allOf(#/components/schemas/ObjectReference)
|
|
ObjectReference `yaml:",inline"`
|
|
// Embedded fields due to inline allOf schema
|
|
Canceled bool `json:"canceled"`
|
|
}
|
|
|
|
// ObjectReference defines model for ObjectReference.
|
|
type ObjectReference struct {
|
|
Href string `json:"href"`
|
|
Id string `json:"id"`
|
|
Kind string `json:"kind"`
|
|
}
|
|
|
|
// PostWorkersRequest defines model for PostWorkersRequest.
|
|
type PostWorkersRequest struct {
|
|
Arch string `json:"arch"`
|
|
}
|
|
|
|
// PostWorkersResponse defines model for PostWorkersResponse.
|
|
type PostWorkersResponse struct {
|
|
// Embedded struct due to allOf(#/components/schemas/ObjectReference)
|
|
ObjectReference `yaml:",inline"`
|
|
// Embedded fields due to inline allOf schema
|
|
WorkerId string `json:"worker_id"`
|
|
}
|
|
|
|
// RequestJobRequest defines model for RequestJobRequest.
|
|
type RequestJobRequest struct {
|
|
Arch string `json:"arch"`
|
|
Types []string `json:"types"`
|
|
WorkerId *string `json:"worker_id,omitempty"`
|
|
}
|
|
|
|
// RequestJobResponse defines model for RequestJobResponse.
|
|
type RequestJobResponse struct {
|
|
// Embedded struct due to allOf(#/components/schemas/ObjectReference)
|
|
ObjectReference `yaml:",inline"`
|
|
// Embedded fields due to inline allOf schema
|
|
Args *json.RawMessage `json:"args,omitempty"`
|
|
ArtifactLocation string `json:"artifact_location"`
|
|
DynamicArgs *[]json.RawMessage `json:"dynamic_args,omitempty"`
|
|
Location string `json:"location"`
|
|
Type string `json:"type"`
|
|
}
|
|
|
|
// StatusResponse defines model for StatusResponse.
|
|
type StatusResponse struct {
|
|
// Embedded struct due to allOf(#/components/schemas/ObjectReference)
|
|
ObjectReference `yaml:",inline"`
|
|
// Embedded fields due to inline allOf schema
|
|
Status string `json:"status"`
|
|
}
|
|
|
|
// UpdateJobRequest defines model for UpdateJobRequest.
|
|
type UpdateJobRequest struct {
|
|
Result json.RawMessage `json:"result"`
|
|
}
|
|
|
|
// UpdateJobResponse defines model for UpdateJobResponse.
|
|
type UpdateJobResponse ObjectReference
|
|
|
|
// RequestJobJSONBody defines parameters for RequestJob.
|
|
type RequestJobJSONBody RequestJobRequest
|
|
|
|
// UpdateJobJSONBody defines parameters for UpdateJob.
|
|
type UpdateJobJSONBody UpdateJobRequest
|
|
|
|
// PostWorkersJSONBody defines parameters for PostWorkers.
|
|
type PostWorkersJSONBody PostWorkersRequest
|
|
|
|
// RequestJobJSONRequestBody defines body for RequestJob for application/json ContentType.
|
|
type RequestJobJSONRequestBody RequestJobJSONBody
|
|
|
|
// UpdateJobJSONRequestBody defines body for UpdateJob for application/json ContentType.
|
|
type UpdateJobJSONRequestBody UpdateJobJSONBody
|
|
|
|
// PostWorkersJSONRequestBody defines body for PostWorkers for application/json ContentType.
|
|
type PostWorkersJSONRequestBody PostWorkersJSONBody
|
|
|
|
// ServerInterface represents all server handlers.
|
|
type ServerInterface interface {
|
|
// Get error description
|
|
// (GET /errors/{id})
|
|
GetError(ctx echo.Context, id string) error
|
|
// Request a job
|
|
// (POST /jobs)
|
|
RequestJob(ctx echo.Context) error
|
|
// Get running job
|
|
// (GET /jobs/{token})
|
|
GetJob(ctx echo.Context, token string) error
|
|
// Update a running job
|
|
// (PATCH /jobs/{token})
|
|
UpdateJob(ctx echo.Context, token string) error
|
|
// Upload an artifact
|
|
// (PUT /jobs/{token}/artifacts/{name})
|
|
UploadJobArtifact(ctx echo.Context, token string, name string) error
|
|
// Get the openapi spec in json format
|
|
// (GET /openapi)
|
|
GetOpenapi(ctx echo.Context) error
|
|
// status
|
|
// (GET /status)
|
|
GetStatus(ctx echo.Context) error
|
|
// Create a new worker
|
|
// (POST /workers)
|
|
PostWorkers(ctx echo.Context) error
|
|
// Refresh worker status
|
|
// (POST /workers/{worker_id}/status)
|
|
PostWorkerStatus(ctx echo.Context, workerId string) error
|
|
}
|
|
|
|
// ServerInterfaceWrapper converts echo contexts to parameters.
|
|
type ServerInterfaceWrapper struct {
|
|
Handler ServerInterface
|
|
}
|
|
|
|
// GetError converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) GetError(ctx echo.Context) error {
|
|
var err error
|
|
// ------------- Path parameter "id" -------------
|
|
var id string
|
|
|
|
err = runtime.BindStyledParameterWithLocation("simple", false, "id", runtime.ParamLocationPath, ctx.Param("id"), &id)
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter id: %s", err))
|
|
}
|
|
|
|
ctx.Set(BearerScopes, []string{""})
|
|
|
|
// Invoke the callback with all the unmarshalled arguments
|
|
err = w.Handler.GetError(ctx, id)
|
|
return err
|
|
}
|
|
|
|
// RequestJob converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) RequestJob(ctx echo.Context) error {
|
|
var err error
|
|
|
|
// Invoke the callback with all the unmarshalled arguments
|
|
err = w.Handler.RequestJob(ctx)
|
|
return err
|
|
}
|
|
|
|
// GetJob converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) GetJob(ctx echo.Context) error {
|
|
var err error
|
|
// ------------- Path parameter "token" -------------
|
|
var token string
|
|
|
|
err = runtime.BindStyledParameterWithLocation("simple", false, "token", runtime.ParamLocationPath, ctx.Param("token"), &token)
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter token: %s", err))
|
|
}
|
|
|
|
// Invoke the callback with all the unmarshalled arguments
|
|
err = w.Handler.GetJob(ctx, token)
|
|
return err
|
|
}
|
|
|
|
// UpdateJob converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) UpdateJob(ctx echo.Context) error {
|
|
var err error
|
|
// ------------- Path parameter "token" -------------
|
|
var token string
|
|
|
|
err = runtime.BindStyledParameterWithLocation("simple", false, "token", runtime.ParamLocationPath, ctx.Param("token"), &token)
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter token: %s", err))
|
|
}
|
|
|
|
// Invoke the callback with all the unmarshalled arguments
|
|
err = w.Handler.UpdateJob(ctx, token)
|
|
return err
|
|
}
|
|
|
|
// UploadJobArtifact converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) UploadJobArtifact(ctx echo.Context) error {
|
|
var err error
|
|
// ------------- Path parameter "token" -------------
|
|
var token string
|
|
|
|
err = runtime.BindStyledParameterWithLocation("simple", false, "token", runtime.ParamLocationPath, ctx.Param("token"), &token)
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter token: %s", err))
|
|
}
|
|
|
|
// ------------- Path parameter "name" -------------
|
|
var name string
|
|
|
|
err = runtime.BindStyledParameterWithLocation("simple", false, "name", runtime.ParamLocationPath, ctx.Param("name"), &name)
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter name: %s", err))
|
|
}
|
|
|
|
// Invoke the callback with all the unmarshalled arguments
|
|
err = w.Handler.UploadJobArtifact(ctx, token, name)
|
|
return err
|
|
}
|
|
|
|
// GetOpenapi converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) GetOpenapi(ctx echo.Context) error {
|
|
var err error
|
|
|
|
// Invoke the callback with all the unmarshalled arguments
|
|
err = w.Handler.GetOpenapi(ctx)
|
|
return err
|
|
}
|
|
|
|
// GetStatus converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) GetStatus(ctx echo.Context) error {
|
|
var err error
|
|
|
|
// Invoke the callback with all the unmarshalled arguments
|
|
err = w.Handler.GetStatus(ctx)
|
|
return err
|
|
}
|
|
|
|
// PostWorkers converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) PostWorkers(ctx echo.Context) error {
|
|
var err error
|
|
|
|
// Invoke the callback with all the unmarshalled arguments
|
|
err = w.Handler.PostWorkers(ctx)
|
|
return err
|
|
}
|
|
|
|
// PostWorkerStatus converts echo context to params.
|
|
func (w *ServerInterfaceWrapper) PostWorkerStatus(ctx echo.Context) error {
|
|
var err error
|
|
// ------------- Path parameter "worker_id" -------------
|
|
var workerId string
|
|
|
|
err = runtime.BindStyledParameterWithLocation("simple", false, "worker_id", runtime.ParamLocationPath, ctx.Param("worker_id"), &workerId)
|
|
if err != nil {
|
|
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter worker_id: %s", err))
|
|
}
|
|
|
|
// Invoke the callback with all the unmarshalled arguments
|
|
err = w.Handler.PostWorkerStatus(ctx, workerId)
|
|
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.GET(baseURL+"/errors/:id", wrapper.GetError)
|
|
router.POST(baseURL+"/jobs", wrapper.RequestJob)
|
|
router.GET(baseURL+"/jobs/:token", wrapper.GetJob)
|
|
router.PATCH(baseURL+"/jobs/:token", wrapper.UpdateJob)
|
|
router.PUT(baseURL+"/jobs/:token/artifacts/:name", wrapper.UploadJobArtifact)
|
|
router.GET(baseURL+"/openapi", wrapper.GetOpenapi)
|
|
router.GET(baseURL+"/status", wrapper.GetStatus)
|
|
router.POST(baseURL+"/workers", wrapper.PostWorkers)
|
|
router.POST(baseURL+"/workers/:worker_id/status", wrapper.PostWorkerStatus)
|
|
|
|
}
|
|
|
|
// Base64 encoded, gzipped, json marshaled Swagger object
|
|
var swaggerSpec = []string{
|
|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|
|
}
|
|
|
|
// GetSwagger returns the content of the embedded swagger specification file
|
|
// or error if failed to decode
|
|
func decodeSpec() ([]byte, error) {
|
|
zipped, err := base64.StdEncoding.DecodeString(strings.Join(swaggerSpec, ""))
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error base64 decoding spec: %s", err)
|
|
}
|
|
zr, err := gzip.NewReader(bytes.NewReader(zipped))
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error decompressing spec: %s", err)
|
|
}
|
|
var buf bytes.Buffer
|
|
_, err = buf.ReadFrom(zr)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error decompressing spec: %s", err)
|
|
}
|
|
|
|
return buf.Bytes(), nil
|
|
}
|
|
|
|
var rawSpec = decodeSpecCached()
|
|
|
|
// a naive cached of a decoded swagger spec
|
|
func decodeSpecCached() func() ([]byte, error) {
|
|
data, err := decodeSpec()
|
|
return func() ([]byte, error) {
|
|
return data, err
|
|
}
|
|
}
|
|
|
|
// Constructs a synthetic filesystem for resolving external references when loading openapi specifications.
|
|
func PathToRawSpec(pathToFile string) map[string]func() ([]byte, error) {
|
|
var res = make(map[string]func() ([]byte, error))
|
|
if len(pathToFile) > 0 {
|
|
res[pathToFile] = rawSpec
|
|
}
|
|
|
|
return res
|
|
}
|
|
|
|
// GetSwagger returns the Swagger specification corresponding to the generated code
|
|
// in this file. The external references of Swagger specification are resolved.
|
|
// The logic of resolving external references is tightly connected to "import-mapping" feature.
|
|
// Externally referenced files must be embedded in the corresponding golang packages.
|
|
// Urls can be supported but this task was out of the scope.
|
|
func GetSwagger() (swagger *openapi3.T, err error) {
|
|
var resolvePath = PathToRawSpec("")
|
|
|
|
loader := openapi3.NewLoader()
|
|
loader.IsExternalRefsAllowed = true
|
|
loader.ReadFromURIFunc = func(loader *openapi3.Loader, url *url.URL) ([]byte, error) {
|
|
var pathToFile = url.String()
|
|
pathToFile = path.Clean(pathToFile)
|
|
getSpec, ok := resolvePath[pathToFile]
|
|
if !ok {
|
|
err1 := fmt.Errorf("path not found: %s", pathToFile)
|
|
return nil, err1
|
|
}
|
|
return getSpec()
|
|
}
|
|
var specData []byte
|
|
specData, err = rawSpec()
|
|
if err != nil {
|
|
return
|
|
}
|
|
swagger, err = loader.LoadFromData(specData)
|
|
if err != nil {
|
|
return
|
|
}
|
|
return
|
|
}
|