Add metaData to GraphQL-API; Remove jobs limit in REST-API

This commit is contained in:
Lou Knauer 2022-02-22 09:19:59 +01:00
parent dcb3fd6a6a
commit 96f91f1a1c
4 changed files with 71 additions and 3 deletions

View File

@ -87,6 +87,7 @@ type ComplexityRoot struct {
Exclusive func(childComplexity int) int Exclusive func(childComplexity int) int
ID func(childComplexity int) int ID func(childComplexity int) int
JobID func(childComplexity int) int JobID func(childComplexity int) int
MetaData func(childComplexity int) int
MonitoringStatus func(childComplexity int) int MonitoringStatus func(childComplexity int) int
NumAcc func(childComplexity int) int NumAcc func(childComplexity int) int
NumHWThreads func(childComplexity int) int NumHWThreads func(childComplexity int) int
@ -424,6 +425,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
return e.complexity.Job.JobID(childComplexity), true return e.complexity.Job.JobID(childComplexity), true
case "Job.metaData":
if e.complexity.Job.MetaData == nil {
break
}
return e.complexity.Job.MetaData(childComplexity), true
case "Job.monitoringStatus": case "Job.monitoringStatus":
if e.complexity.Job.MonitoringStatus == nil { if e.complexity.Job.MonitoringStatus == nil {
break break
@ -1191,6 +1199,8 @@ func (ec *executionContext) introspectType(name string) (*introspection.Type, er
var sources = []*ast.Source{ var sources = []*ast.Source{
{Name: "graph/schema.graphqls", Input: `scalar Time {Name: "graph/schema.graphqls", Input: `scalar Time
scalar Any
scalar NullableFloat scalar NullableFloat
scalar MetricScope scalar MetricScope
scalar JobState scalar JobState
@ -1212,6 +1222,7 @@ type Job {
arrayJobId: Int! arrayJobId: Int!
monitoringStatus: Int! monitoringStatus: Int!
state: JobState! state: JobState!
metaData: Any
tags: [Tag!]! tags: [Tag!]!
resources: [Resource!]! resources: [Resource!]!
} }
@ -3019,6 +3030,38 @@ func (ec *executionContext) _Job_state(ctx context.Context, field graphql.Collec
return ec.marshalNJobState2githubᚗcomᚋClusterCockpitᚋccᚑbackendᚋschemaᚐJobState(ctx, field.Selections, res) return ec.marshalNJobState2githubᚗcomᚋClusterCockpitᚋccᚑbackendᚋschemaᚐJobState(ctx, field.Selections, res)
} }
func (ec *executionContext) _Job_metaData(ctx context.Context, field graphql.CollectedField, obj *schema.Job) (ret graphql.Marshaler) {
defer func() {
if r := recover(); r != nil {
ec.Error(ctx, ec.Recover(ctx, r))
ret = graphql.Null
}
}()
fc := &graphql.FieldContext{
Object: "Job",
Field: field,
Args: nil,
IsMethod: false,
IsResolver: false,
}
ctx = graphql.WithFieldContext(ctx, fc)
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
ctx = rctx // use context from middleware stack in children
return obj.MetaData, nil
})
if err != nil {
ec.Error(ctx, err)
return graphql.Null
}
if resTmp == nil {
return graphql.Null
}
res := resTmp.(interface{})
fc.Result = res
return ec.marshalOAny2interface(ctx, field.Selections, res)
}
func (ec *executionContext) _Job_tags(ctx context.Context, field graphql.CollectedField, obj *schema.Job) (ret graphql.Marshaler) { func (ec *executionContext) _Job_tags(ctx context.Context, field graphql.CollectedField, obj *schema.Job) (ret graphql.Marshaler) {
defer func() { defer func() {
if r := recover(); r != nil { if r := recover(); r != nil {
@ -7696,6 +7739,8 @@ func (ec *executionContext) _Job(ctx context.Context, sel ast.SelectionSet, obj
if out.Values[i] == graphql.Null { if out.Values[i] == graphql.Null {
atomic.AddUint32(&invalids, 1) atomic.AddUint32(&invalids, 1)
} }
case "metaData":
out.Values[i] = ec._Job_metaData(ctx, field, obj)
case "tags": case "tags":
field := field field := field
out.Concurrently(i, func() (res graphql.Marshaler) { out.Concurrently(i, func() (res graphql.Marshaler) {
@ -10121,6 +10166,21 @@ func (ec *executionContext) marshalOAggregate2ᚖgithubᚗcomᚋClusterCockpit
return v return v
} }
func (ec *executionContext) unmarshalOAny2interface(ctx context.Context, v interface{}) (interface{}, error) {
if v == nil {
return nil, nil
}
res, err := graphql.UnmarshalAny(v)
return res, graphql.ErrorOnPath(ctx, err)
}
func (ec *executionContext) marshalOAny2interface(ctx context.Context, sel ast.SelectionSet, v interface{}) graphql.Marshaler {
if v == nil {
return graphql.Null
}
return graphql.MarshalAny(v)
}
func (ec *executionContext) unmarshalOBoolean2bool(ctx context.Context, v interface{}) (bool, error) { func (ec *executionContext) unmarshalOBoolean2bool(ctx context.Context, v interface{}) (bool, error) {
res, err := graphql.UnmarshalBoolean(v) res, err := graphql.UnmarshalBoolean(v)
return res, graphql.ErrorOnPath(ctx, err) return res, graphql.ErrorOnPath(ctx, err)

View File

@ -1,4 +1,6 @@
scalar Time scalar Time
scalar Any
scalar NullableFloat scalar NullableFloat
scalar MetricScope scalar MetricScope
scalar JobState scalar JobState
@ -20,6 +22,7 @@ type Job {
arrayJobId: Int! arrayJobId: Int!
monitoringStatus: Int! monitoringStatus: Int!
state: JobState! state: JobState!
metaData: Any
tags: [Tag!]! tags: [Tag!]!
resources: [Resource!]! resources: [Resource!]!
} }

View File

@ -165,6 +165,13 @@ func (r *queryResolver) JobsFootprints(ctx context.Context, filter []*model.JobF
} }
func (r *queryResolver) Jobs(ctx context.Context, filter []*model.JobFilter, page *model.PageRequest, order *model.OrderByInput) (*model.JobResultList, error) { func (r *queryResolver) Jobs(ctx context.Context, filter []*model.JobFilter, page *model.PageRequest, order *model.OrderByInput) (*model.JobResultList, error) {
if page == nil {
page = &model.PageRequest{
ItemsPerPage: 50,
Page: 1,
}
}
jobs, err := r.Repo.QueryJobs(ctx, filter, page, order) jobs, err := r.Repo.QueryJobs(ctx, filter, page, order)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -38,8 +38,6 @@ func (r *JobRepository) QueryJobs(
if page != nil { if page != nil {
limit := uint64(page.ItemsPerPage) limit := uint64(page.ItemsPerPage)
query = query.Offset((uint64(page.Page) - 1) * limit).Limit(limit) query = query.Offset((uint64(page.Page) - 1) * limit).Limit(limit)
} else {
query = query.Limit(50)
} }
for _, f := range filters { for _, f := range filters {
@ -90,7 +88,7 @@ func (r *JobRepository) CountJobs(
func SecurityCheck(ctx context.Context, query sq.SelectBuilder) sq.SelectBuilder { func SecurityCheck(ctx context.Context, query sq.SelectBuilder) sq.SelectBuilder {
user := auth.GetUser(ctx) user := auth.GetUser(ctx)
if user == nil || user.HasRole(auth.RoleAdmin) { if user == nil || user.HasRole(auth.RoleAdmin) || user.HasRole(auth.RoleApi) {
return query return query
} }