From 6c0d1926625718ae65ce9eb3cefea19aaebdbca4 Mon Sep 17 00:00:00 2001 From: Jan Eitzinger Date: Tue, 21 Feb 2023 18:04:37 +0100 Subject: [PATCH 1/2] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ae4594b..5c80bb0 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ Every cc-backend version supports a specific database version. On startup the version of the sqlite database is validated and cc-backend will terminate if the version does not match. cc-backend supports to migrate the database schema up to the required version using the `--migrate-db` command line option. In case the database file does not yet exist it is created and initialized by the `--migrate-db` command line option. -In case you want to use a newer database version with an olden version of cc-backend you can downgrade a database using the external [migrate](https://github.com/golang-migrate/migrate) tool. +In case you want to use a newer database version with an older version of cc-backend you can downgrade a database using the external [migrate](https://github.com/golang-migrate/migrate) tool. In this case you have to provide the path to the migration files in a recent source tree: `./internal/repository/migrations/`. ## Development From 60437ce2644dfe00a04c433a5f1eea77132dab1b Mon Sep 17 00:00:00 2001 From: Jan Eitzinger Date: Tue, 21 Feb 2023 18:13:16 +0100 Subject: [PATCH 2/2] Rebuild GraphQL api and Swagger UI code. --- api/swagger.json | 43 +++++++++++++++-- api/swagger.yaml | 31 +++++++++++-- internal/api/docs.go | 46 ++++++++++++++++--- internal/graph/generated/generated.go | 66 --------------------------- internal/graph/schema.resolvers.go | 1 + internal/repository/job.go | 2 +- 6 files changed, 108 insertions(+), 81 deletions(-) diff --git a/api/swagger.json b/api/swagger.json index 1981247..6436484 100644 --- a/api/swagger.json +++ b/api/swagger.json @@ -708,8 +708,7 @@ "example": 123000 }, "jobState": { - "description": "Final state of job", - "type": "string", + "description": "Final job state", "enum": [ "completed", "failed", @@ -717,6 +716,11 @@ "stopped", "timeout" ], + "allOf": [ + { + "$ref": "#/definitions/schema.JobState" + } + ], "example": "completed" }, "startTime": { @@ -769,7 +773,6 @@ }, "jobState": { "description": "Final state of job", - "type": "string", "enum": [ "completed", "failed", @@ -778,6 +781,11 @@ "timeout", "out_of_memory" ], + "allOf": [ + { + "$ref": "#/definitions/schema.JobState" + } + ], "example": "completed" }, "metaData": { @@ -901,7 +909,6 @@ }, "jobState": { "description": "Final state of job", - "type": "string", "enum": [ "completed", "failed", @@ -910,6 +917,11 @@ "timeout", "out_of_memory" ], + "allOf": [ + { + "$ref": "#/definitions/schema.JobState" + } + ], "example": "completed" }, "metaData": { @@ -1004,6 +1016,29 @@ } } }, + "schema.JobState": { + "type": "string", + "enum": [ + "running", + "completed", + "failed", + "cancelled", + "stopped", + "timeout", + "preempted", + "out_of_memory" + ], + "x-enum-varnames": [ + "JobStateRunning", + "JobStateCompleted", + "JobStateFailed", + "JobStateCancelled", + "JobStateStopped", + "JobStateTimeout", + "JobStatePreempted", + "JobStateOutOfMemory" + ] + }, "schema.JobStatistics": { "description": "Specification for job metric statistics.", "type": "object", diff --git a/api/swagger.yaml b/api/swagger.yaml index b5d738d..ca04575 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -59,7 +59,9 @@ definitions: example: 123000 type: integer jobState: - description: Final state of job + allOf: + - $ref: '#/definitions/schema.JobState' + description: Final job state enum: - completed - failed @@ -67,7 +69,6 @@ definitions: - stopped - timeout example: completed - type: string startTime: description: Start Time of job as epoch example: 1649723812 @@ -112,6 +113,8 @@ definitions: example: 123000 type: integer jobState: + allOf: + - $ref: '#/definitions/schema.JobState' description: Final state of job enum: - completed @@ -121,7 +124,6 @@ definitions: - timeout - out_of_memory example: completed - type: string metaData: additionalProperties: type: string @@ -220,6 +222,8 @@ definitions: example: 123000 type: integer jobState: + allOf: + - $ref: '#/definitions/schema.JobState' description: Final state of job enum: - completed @@ -229,7 +233,6 @@ definitions: - timeout - out_of_memory example: completed - type: string metaData: additionalProperties: type: string @@ -303,6 +306,26 @@ definitions: minimum: 1 type: integer type: object + schema.JobState: + enum: + - running + - completed + - failed + - cancelled + - stopped + - timeout + - preempted + - out_of_memory + type: string + x-enum-varnames: + - JobStateRunning + - JobStateCompleted + - JobStateFailed + - JobStateCancelled + - JobStateStopped + - JobStateTimeout + - JobStatePreempted + - JobStateOutOfMemory schema.JobStatistics: description: Specification for job metric statistics. properties: diff --git a/internal/api/docs.go b/internal/api/docs.go index 3fa6787..4ac70a6 100644 --- a/internal/api/docs.go +++ b/internal/api/docs.go @@ -1,5 +1,4 @@ -// Package api GENERATED BY SWAG; DO NOT EDIT -// This file was generated by swaggo/swag +// Code generated by swaggo/swag. DO NOT EDIT package api import "github.com/swaggo/swag" @@ -715,8 +714,7 @@ const docTemplate = `{ "example": 123000 }, "jobState": { - "description": "Final state of job", - "type": "string", + "description": "Final job state", "enum": [ "completed", "failed", @@ -724,6 +722,11 @@ const docTemplate = `{ "stopped", "timeout" ], + "allOf": [ + { + "$ref": "#/definitions/schema.JobState" + } + ], "example": "completed" }, "startTime": { @@ -776,7 +779,6 @@ const docTemplate = `{ }, "jobState": { "description": "Final state of job", - "type": "string", "enum": [ "completed", "failed", @@ -785,6 +787,11 @@ const docTemplate = `{ "timeout", "out_of_memory" ], + "allOf": [ + { + "$ref": "#/definitions/schema.JobState" + } + ], "example": "completed" }, "metaData": { @@ -908,7 +915,6 @@ const docTemplate = `{ }, "jobState": { "description": "Final state of job", - "type": "string", "enum": [ "completed", "failed", @@ -917,6 +923,11 @@ const docTemplate = `{ "timeout", "out_of_memory" ], + "allOf": [ + { + "$ref": "#/definitions/schema.JobState" + } + ], "example": "completed" }, "metaData": { @@ -1011,6 +1022,29 @@ const docTemplate = `{ } } }, + "schema.JobState": { + "type": "string", + "enum": [ + "running", + "completed", + "failed", + "cancelled", + "stopped", + "timeout", + "preempted", + "out_of_memory" + ], + "x-enum-varnames": [ + "JobStateRunning", + "JobStateCompleted", + "JobStateFailed", + "JobStateCancelled", + "JobStateStopped", + "JobStateTimeout", + "JobStatePreempted", + "JobStateOutOfMemory" + ] + }, "schema.JobStatistics": { "description": "Specification for job metric statistics.", "type": "object", diff --git a/internal/graph/generated/generated.go b/internal/graph/generated/generated.go index c4a098f..5b82186 100644 --- a/internal/graph/generated/generated.go +++ b/internal/graph/generated/generated.go @@ -5484,7 +5484,6 @@ func (ec *executionContext) _Mutation_createTag(ctx context.Context, field graph }) if err != nil { ec.Error(ctx, err) - return graphql.Null } if resTmp == nil { if !graphql.HasFieldError(ctx, fc) { @@ -5547,7 +5546,6 @@ func (ec *executionContext) _Mutation_deleteTag(ctx context.Context, field graph }) if err != nil { ec.Error(ctx, err) - return graphql.Null } if resTmp == nil { if !graphql.HasFieldError(ctx, fc) { @@ -5602,7 +5600,6 @@ func (ec *executionContext) _Mutation_addTagsToJob(ctx context.Context, field gr }) if err != nil { ec.Error(ctx, err) - return graphql.Null } if resTmp == nil { if !graphql.HasFieldError(ctx, fc) { @@ -5665,7 +5662,6 @@ func (ec *executionContext) _Mutation_removeTagsFromJob(ctx context.Context, fie }) if err != nil { ec.Error(ctx, err) - return graphql.Null } if resTmp == nil { if !graphql.HasFieldError(ctx, fc) { @@ -5728,7 +5724,6 @@ func (ec *executionContext) _Mutation_updateConfiguration(ctx context.Context, f }) if err != nil { ec.Error(ctx, err) - return graphql.Null } if resTmp == nil { return graphql.Null @@ -5918,7 +5913,6 @@ func (ec *executionContext) _Query_clusters(ctx context.Context, field graphql.C }) if err != nil { ec.Error(ctx, err) - return graphql.Null } if resTmp == nil { if !graphql.HasFieldError(ctx, fc) { @@ -5972,7 +5966,6 @@ func (ec *executionContext) _Query_tags(ctx context.Context, field graphql.Colle }) if err != nil { ec.Error(ctx, err) - return graphql.Null } if resTmp == nil { if !graphql.HasFieldError(ctx, fc) { @@ -6024,7 +6017,6 @@ func (ec *executionContext) _Query_user(ctx context.Context, field graphql.Colle }) if err != nil { ec.Error(ctx, err) - return graphql.Null } if resTmp == nil { return graphql.Null @@ -6084,7 +6076,6 @@ func (ec *executionContext) _Query_allocatedNodes(ctx context.Context, field gra }) if err != nil { ec.Error(ctx, err) - return graphql.Null } if resTmp == nil { if !graphql.HasFieldError(ctx, fc) { @@ -6145,7 +6136,6 @@ func (ec *executionContext) _Query_job(ctx context.Context, field graphql.Collec }) if err != nil { ec.Error(ctx, err) - return graphql.Null } if resTmp == nil { return graphql.Null @@ -6245,7 +6235,6 @@ func (ec *executionContext) _Query_jobMetrics(ctx context.Context, field graphql }) if err != nil { ec.Error(ctx, err) - return graphql.Null } if resTmp == nil { if !graphql.HasFieldError(ctx, fc) { @@ -6306,7 +6295,6 @@ func (ec *executionContext) _Query_jobsFootprints(ctx context.Context, field gra }) if err != nil { ec.Error(ctx, err) - return graphql.Null } if resTmp == nil { return graphql.Null @@ -6364,7 +6352,6 @@ func (ec *executionContext) _Query_jobs(ctx context.Context, field graphql.Colle }) if err != nil { ec.Error(ctx, err) - return graphql.Null } if resTmp == nil { if !graphql.HasFieldError(ctx, fc) { @@ -6429,7 +6416,6 @@ func (ec *executionContext) _Query_jobsStatistics(ctx context.Context, field gra }) if err != nil { ec.Error(ctx, err) - return graphql.Null } if resTmp == nil { if !graphql.HasFieldError(ctx, fc) { @@ -6502,7 +6488,6 @@ func (ec *executionContext) _Query_jobsCount(ctx context.Context, field graphql. }) if err != nil { ec.Error(ctx, err) - return graphql.Null } if resTmp == nil { if !graphql.HasFieldError(ctx, fc) { @@ -6563,7 +6548,6 @@ func (ec *executionContext) _Query_rooflineHeatmap(ctx context.Context, field gr }) if err != nil { ec.Error(ctx, err) - return graphql.Null } if resTmp == nil { if !graphql.HasFieldError(ctx, fc) { @@ -6618,7 +6602,6 @@ func (ec *executionContext) _Query_nodeMetrics(ctx context.Context, field graphq }) if err != nil { ec.Error(ctx, err) - return graphql.Null } if resTmp == nil { if !graphql.HasFieldError(ctx, fc) { @@ -6681,7 +6664,6 @@ func (ec *executionContext) _Query___type(ctx context.Context, field graphql.Col }) if err != nil { ec.Error(ctx, err) - return graphql.Null } if resTmp == nil { return graphql.Null @@ -6755,7 +6737,6 @@ func (ec *executionContext) _Query___schema(ctx context.Context, field graphql.C }) if err != nil { ec.Error(ctx, err) - return graphql.Null } if resTmp == nil { return graphql.Null @@ -11617,7 +11598,6 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) }) out := graphql.NewFieldSet(fields) - var invalids uint32 for i, field := range fields { innerCtx := graphql.WithRootFieldContext(ctx, &graphql.RootFieldContext{ Object: field.Name, @@ -11633,36 +11613,24 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) return ec._Mutation_createTag(ctx, field) }) - if out.Values[i] == graphql.Null { - invalids++ - } case "deleteTag": out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { return ec._Mutation_deleteTag(ctx, field) }) - if out.Values[i] == graphql.Null { - invalids++ - } case "addTagsToJob": out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { return ec._Mutation_addTagsToJob(ctx, field) }) - if out.Values[i] == graphql.Null { - invalids++ - } case "removeTagsFromJob": out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { return ec._Mutation_removeTagsFromJob(ctx, field) }) - if out.Values[i] == graphql.Null { - invalids++ - } case "updateConfiguration": out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { @@ -11674,9 +11642,6 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) } } out.Dispatch() - if invalids > 0 { - return graphql.Null - } return out } @@ -11731,7 +11696,6 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr }) out := graphql.NewFieldSet(fields) - var invalids uint32 for i, field := range fields { innerCtx := graphql.WithRootFieldContext(ctx, &graphql.RootFieldContext{ Object: field.Name, @@ -11751,9 +11715,6 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } }() res = ec._Query_clusters(ctx, field) - if res == graphql.Null { - atomic.AddUint32(&invalids, 1) - } return res } @@ -11774,9 +11735,6 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } }() res = ec._Query_tags(ctx, field) - if res == graphql.Null { - atomic.AddUint32(&invalids, 1) - } return res } @@ -11817,9 +11775,6 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } }() res = ec._Query_allocatedNodes(ctx, field) - if res == graphql.Null { - atomic.AddUint32(&invalids, 1) - } return res } @@ -11860,9 +11815,6 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } }() res = ec._Query_jobMetrics(ctx, field) - if res == graphql.Null { - atomic.AddUint32(&invalids, 1) - } return res } @@ -11903,9 +11855,6 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } }() res = ec._Query_jobs(ctx, field) - if res == graphql.Null { - atomic.AddUint32(&invalids, 1) - } return res } @@ -11926,9 +11875,6 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } }() res = ec._Query_jobsStatistics(ctx, field) - if res == graphql.Null { - atomic.AddUint32(&invalids, 1) - } return res } @@ -11949,9 +11895,6 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } }() res = ec._Query_jobsCount(ctx, field) - if res == graphql.Null { - atomic.AddUint32(&invalids, 1) - } return res } @@ -11972,9 +11915,6 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } }() res = ec._Query_rooflineHeatmap(ctx, field) - if res == graphql.Null { - atomic.AddUint32(&invalids, 1) - } return res } @@ -11995,9 +11935,6 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } }() res = ec._Query_nodeMetrics(ctx, field) - if res == graphql.Null { - atomic.AddUint32(&invalids, 1) - } return res } @@ -12025,9 +11962,6 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } } out.Dispatch() - if invalids > 0 { - return graphql.Null - } return out } diff --git a/internal/graph/schema.resolvers.go b/internal/graph/schema.resolvers.go index ce27a52..8275681 100644 --- a/internal/graph/schema.resolvers.go +++ b/internal/graph/schema.resolvers.go @@ -2,6 +2,7 @@ package graph // This file will be automatically regenerated based on the schema, any resolver implementations // will be copied through when generating and any unknown code will be moved to the end. +// Code generated by github.com/99designs/gqlgen version v0.17.24 import ( "context" diff --git a/internal/repository/job.go b/internal/repository/job.go index 309bd66..aa3ff2a 100644 --- a/internal/repository/job.go +++ b/internal/repository/job.go @@ -895,7 +895,7 @@ func (r *JobRepository) JobsStatistics(ctx context.Context, } if col == "job.user" { - for id, _ := range stats { + for id := range stats { emptyDash := "-" name, _ := r.FindNameByUser(ctx, id) if name != "" {