Reconfigure Swagger integration. Regenerate API docs

This commit is contained in:
Jan Eitzinger
2022-09-16 06:09:55 +02:00
parent 8e90c954ff
commit f1941b5e67
8 changed files with 34 additions and 85 deletions

534
internal/api/docs.go Normal file
View File

@@ -0,0 +1,534 @@
// Package api GENERATED BY SWAG; DO NOT EDIT
// This file was generated by swaggo/swag
package api
import "github.com/swaggo/swag"
const docTemplate = `{
"schemes": {{ marshal .Schemes }},
"swagger": "2.0",
"info": {
"description": "{{escape .Description}}",
"title": "{{.Title}}",
"termsOfService": "TODO",
"contact": {
"name": "ClusterCockpit project",
"url": "TODO",
"email": "support@clustercockpit.org"
},
"license": {
"name": "MIT License",
"url": "https://opensource.org/licenses/MIT"
},
"version": "{{.Version}}"
},
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/jobs/": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "Get a list of all jobs. Filters can be applied using query parameters.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"jobs"
],
"summary": "List all jobs",
"parameters": [
{
"enum": [
"running",
"completed",
"failed",
"canceled",
"stopped",
"timeout"
],
"type": "string",
"description": "Job State",
"name": "state",
"in": "query"
},
{
"type": "string",
"description": "Job Cluster",
"name": "cluster",
"in": "query"
},
{
"type": "string",
"description": "Syntax: \u003cfrom\u003e-\u003cto\u003e, where \u003cfrom\u003e and \u003cto\u003e are unix timestamps in seconds",
"name": "start-time",
"in": "query"
},
{
"type": "integer",
"description": "Page Number",
"name": "page",
"in": "query"
},
{
"type": "integer",
"description": "Items per page",
"name": "items-per-page",
"in": "query"
},
{
"type": "boolean",
"description": "Include metadata in response",
"name": "with-metadata",
"in": "query"
}
],
"responses": {
"200": {
"description": "Array of jobs",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/schema.Job"
}
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/api.ErrorResponse"
}
}
}
}
},
"/jobs/start_job/": {
"post": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "A new job started. The body should be in the ` + "`" + `meta.json` + "`" + ` format\nbut some fields required there are optional here (e.g. ` + "`" + `jobState` + "`" + ` defaults to \"running\").",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"jobs"
],
"summary": "Add a newly started job",
"parameters": [
{
"description": "Job to add",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/schema.Job"
}
}
],
"responses": {
"201": {
"description": "Job added successfully",
"schema": {
"$ref": "#/definitions/api.StartJobApiResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/api.ErrorResponse"
}
},
"422": {
"description": "The combination of jobId, clusterId and startTime does already exist",
"schema": {
"$ref": "#/definitions/api.ErrorResponse"
}
}
}
}
},
"/jobs/stop_job/": {
"post": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "Job to stop is specified by request body.\nAll fields are required in request body.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"jobs"
],
"summary": "Mark job as stopped and trigger archiving",
"parameters": [
{
"description": "All fields required",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/api.StopJobApiRequest"
}
}
],
"responses": {
"201": {
"description": "Job resource",
"schema": {
"$ref": "#/definitions/schema.Job"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/api.ErrorResponse"
}
},
"404": {
"description": "Resource not found",
"schema": {
"$ref": "#/definitions/api.ErrorResponse"
}
}
}
}
},
"/jobs/stop_job/{id}": {
"post": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "Job to stop is specified by database ID.\nOnly stopTime and final state are required in request body.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"jobs"
],
"summary": "Mark job as stopped and trigger archiving",
"parameters": [
{
"type": "integer",
"description": "Database ID of Job",
"name": "id",
"in": "path",
"required": true
},
{
"description": "Required fields: [stopTime, state]",
"name": "request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/api.StopJobApiRequest"
}
}
],
"responses": {
"201": {
"description": "Job resource",
"schema": {
"$ref": "#/definitions/schema.Job"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/api.ErrorResponse"
}
},
"404": {
"description": "Resource not found",
"schema": {
"$ref": "#/definitions/api.ErrorResponse"
}
}
}
}
},
"/jobs/tag_job/{id}": {
"post": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "Add one or more tags as array in request body to job specified by DB ID.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"jobs"
],
"summary": "Add one or more tags to a job",
"parameters": [
{
"type": "integer",
"description": "Job Database ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "Array of tag-objects to add",
"name": "request",
"in": "body",
"required": true,
"schema": {
"description": "Array of tag-objects for request payload",
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"description": "Tag Name",
"type": "string"
},
"type": {
"description": "Tag Type",
"type": "string"
}
}
}
}
}
],
"responses": {
"200": {
"description": "Job resource",
"schema": {
"$ref": "#/definitions/schema.Job"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/api.ErrorResponse"
}
},
"404": {
"description": "Job or tag does not exist",
"schema": {
"$ref": "#/definitions/api.ErrorResponse"
}
}
}
}
}
},
"definitions": {
"api.ErrorResponse": {
"description": "Error Response when using API.",
"type": "object",
"properties": {
"error": {
"description": "Error Message",
"type": "string"
},
"status": {
"description": "Statustext of Errorcode",
"type": "string"
}
}
},
"api.StartJobApiResponse": {
"description": "Successful job start response with database id of new job.",
"type": "object",
"properties": {
"id": {
"description": "Database ID of new job",
"type": "integer"
}
}
},
"api.StopJobApiRequest": {
"description": "Request to stop running job using stop time and state. Optional fields: JobId, ClusterId and StartTime. They are only used if no database id was provided.",
"type": "object",
"properties": {
"cluster": {
"description": "Cluster of job (Optional)",
"type": "string"
},
"jobId": {
"description": "Job ID of job (Optional)",
"type": "integer"
},
"jobState": {
"description": "Final job state",
"type": "string"
},
"startTime": {
"description": "Start Time of job (Optional)",
"type": "integer"
},
"stopTime": {
"description": "Stop Time as Epoch",
"type": "integer"
}
}
},
"schema.Job": {
"type": "object",
"properties": {
"arrayJobId": {
"type": "integer"
},
"cluster": {
"type": "string"
},
"duration": {
"type": "integer"
},
"exclusive": {
"type": "integer"
},
"id": {
"type": "integer"
},
"jobId": {
"type": "integer"
},
"jobState": {
"type": "string"
},
"metaData": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"monitoringStatus": {
"type": "integer"
},
"numAcc": {
"type": "integer"
},
"numHwthreads": {
"type": "integer"
},
"numNodes": {
"type": "integer"
},
"partition": {
"type": "string"
},
"project": {
"type": "string"
},
"resources": {
"type": "array",
"items": {
"$ref": "#/definitions/schema.Resource"
}
},
"smt": {
"type": "integer"
},
"startTime": {
"type": "string"
},
"subCluster": {
"type": "string"
},
"tags": {
"type": "array",
"items": {
"$ref": "#/definitions/schema.Tag"
}
},
"user": {
"type": "string"
},
"walltime": {
"type": "integer"
}
}
},
"schema.Resource": {
"type": "object",
"properties": {
"accelerators": {
"type": "array",
"items": {
"type": "string"
}
},
"configuration": {
"type": "string"
},
"hostname": {
"type": "string"
},
"hwthreads": {
"type": "array",
"items": {
"type": "integer"
}
}
}
},
"schema.Tag": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"type": {
"type": "string"
}
}
}
},
"securityDefinitions": {
"ApiKeyAuth": {
"description": "JWT based authentification for general API endpoint use.",
"type": "apiKey",
"name": "X-Auth-Token",
"in": "header"
}
}
}`
// SwaggerInfo holds exported Swagger Info so clients can modify it
var SwaggerInfo = &swag.Spec{
Version: "0.1.0",
Host: "localhost:8080",
BasePath: "/api",
Schemes: []string{},
Title: "ClusterCockpit REST API",
Description: "Array of tag-objects for request payload",
InfoInstanceName: "swagger",
SwaggerTemplate: docTemplate,
}
func init() {
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
}

View File

@@ -35,12 +35,12 @@ import (
// @version 0.1.0
// @description API for batch job control.
// @termsOfService TODO
// @contact.name HPC-Support
// @contact.name ClusterCockpit project
// @contact.url TODO
// @contact.email hpc-support@fau.de
// @contact.email support@clustercockpit.org
// @license.name MIT License
// @license.url https://opensource.org/licenses/MIT
// @host clustercockpit.localhost:8082
// @host localhost:8080
// @BasePath /api
// @securityDefinitions.apikey ApiKeyAuth
// @in header
@@ -97,11 +97,11 @@ type StartJobApiResponse struct {
// @Description They are only used if no database id was provided.
type StopJobApiRequest struct {
// Stop Time as Epoch
StopTime int64 `json:"stopTime"`
State schema.JobState `json:"jobState"` // Final job state
JobId *int64 `json:"jobId"` // Job ID of job (Optional)
Cluster *string `json:"cluster"` // Cluster of job (Optional)
StartTime *int64 `json:"startTime"` // Start Time of job (Optional)
StopTime int64 `json:"stopTime"`
State schema.JobState `json:"jobState"` // Final job state
JobId *int64 `json:"jobId"` // Job ID of job (Optional)
Cluster *string `json:"cluster"` // Cluster of job (Optional)
StartTime *int64 `json:"startTime"` // Start Time of job (Optional)
}
// ErrorResponse model
@@ -136,8 +136,6 @@ func decode(r io.Reader, val interface{}) error {
return dec.Decode(val)
}
// getJobs godoc
// @Summary List all jobs
// @Description Get a list of all jobs. Filters can be applied using query parameters.
@@ -427,8 +425,8 @@ func (api *RestApi) stopJobById(rw http.ResponseWriter, r *http.Request) {
job, err = api.JobRepository.FindById(id)
} else {
handleError(errors.New("the parameter 'id' is required"), http.StatusBadRequest, rw)
return
handleError(errors.New("the parameter 'id' is required"), http.StatusBadRequest, rw)
return
}
if err != nil {
handleError(fmt.Errorf("finding job failed: %w", err), http.StatusUnprocessableEntity, rw)
@@ -627,7 +625,6 @@ func (api *RestApi) stopJobByRequest(rw http.ResponseWriter, r *http.Request) {
// rw.Write([]byte(`{ "status": "OK" }`))
// }
func (api *RestApi) getJobMetrics(rw http.ResponseWriter, r *http.Request) {
id := mux.Vars(r)["id"]
metrics := r.URL.Query()["metric"]
@@ -670,9 +667,6 @@ func (api *RestApi) getJobMetrics(rw http.ResponseWriter, r *http.Request) {
})
}
func (api *RestApi) getJWT(rw http.ResponseWriter, r *http.Request) {
rw.Header().Set("Content-Type", "text/plain")
username := r.FormValue("username")
@@ -787,10 +781,6 @@ func (api *RestApi) updateConfiguration(rw http.ResponseWriter, r *http.Request)
rw.Write([]byte("success"))
}
func (api *RestApi) putMachineState(rw http.ResponseWriter, r *http.Request) {
if api.MachineStateDir == "" {
http.Error(rw, "not enabled", http.StatusNotFound)