mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2024-12-25 12:59:06 +01:00
Change allocatedNodes; Update frontend
This commit is contained in:
parent
0b83917294
commit
f3c2a6cc24
2
frontend
2
frontend
@ -1 +1 @@
|
||||
Subproject commit 03818be47032194f1f450ab242eed56a94a3c5d1
|
||||
Subproject commit 239bf19c9a018b89db655d17c4e9adb8e64fb08e
|
@ -275,7 +275,7 @@ type QueryResolver interface {
|
||||
Clusters(ctx context.Context) ([]*model.Cluster, error)
|
||||
Tags(ctx context.Context) ([]*schema.Tag, error)
|
||||
User(ctx context.Context, username string) (*model.User, error)
|
||||
AllocatedNodes(ctx context.Context, cluster string) ([]string, error)
|
||||
AllocatedNodes(ctx context.Context, cluster string) ([]*model.Count, error)
|
||||
Job(ctx context.Context, id string) (*schema.Job, error)
|
||||
JobMetrics(ctx context.Context, id string, metrics []string, scopes []schema.MetricScope) ([]*model.JobMetricWithName, error)
|
||||
JobsFootprints(ctx context.Context, filter []*model.JobFilter, metrics []string) (*model.Footprints, error)
|
||||
@ -1504,7 +1504,7 @@ type Query {
|
||||
tags: [Tag!]! # List of all tags
|
||||
|
||||
user(username: String!): User
|
||||
allocatedNodes(cluster: String!): [String!]!
|
||||
allocatedNodes(cluster: String!): [Count!]!
|
||||
|
||||
job(id: ID!): Job
|
||||
jobMetrics(id: ID!, metrics: [String!], scopes: [MetricScope!]): [JobMetricWithName!]!
|
||||
@ -5090,9 +5090,9 @@ func (ec *executionContext) _Query_allocatedNodes(ctx context.Context, field gra
|
||||
}
|
||||
return graphql.Null
|
||||
}
|
||||
res := resTmp.([]string)
|
||||
res := resTmp.([]*model.Count)
|
||||
fc.Result = res
|
||||
return ec.marshalNString2ᚕstringᚄ(ctx, field.Selections, res)
|
||||
return ec.marshalNCount2ᚕᚖgithubᚗcomᚋClusterCockpitᚋccᚑbackendᚋgraphᚋmodelᚐCountᚄ(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _Query_job(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
|
||||
|
@ -159,7 +159,7 @@ type Query {
|
||||
tags: [Tag!]! # List of all tags
|
||||
|
||||
user(username: String!): User
|
||||
allocatedNodes(cluster: String!): [String!]!
|
||||
allocatedNodes(cluster: String!): [Count!]!
|
||||
|
||||
job(id: ID!): Job
|
||||
jobMetrics(id: ID!, metrics: [String!], scopes: [MetricScope!]): [JobMetricWithName!]!
|
||||
|
@ -110,8 +110,21 @@ func (r *queryResolver) User(ctx context.Context, username string) (*model.User,
|
||||
return auth.FetchUser(ctx, r.DB, username)
|
||||
}
|
||||
|
||||
func (r *queryResolver) AllocatedNodes(ctx context.Context, cluster string) ([]string, error) {
|
||||
return r.Repo.AllocatedNodes(cluster)
|
||||
func (r *queryResolver) AllocatedNodes(ctx context.Context, cluster string) ([]*model.Count, error) {
|
||||
data, err := r.Repo.AllocatedNodes(cluster)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
counts := make([]*model.Count, 0, len(data))
|
||||
for subcluster, hosts := range data {
|
||||
counts = append(counts, &model.Count{
|
||||
Name: subcluster,
|
||||
Count: len(hosts),
|
||||
})
|
||||
}
|
||||
|
||||
return counts, nil
|
||||
}
|
||||
|
||||
func (r *queryResolver) Job(ctx context.Context, id string) (*schema.Job, error) {
|
||||
|
@ -319,9 +319,11 @@ func (r *JobRepository) Partitions(cluster string) ([]string, error) {
|
||||
return partitions.([]string), nil
|
||||
}
|
||||
|
||||
func (r *JobRepository) AllocatedNodes(cluster string) ([]string, error) {
|
||||
nodes := make(map[string]int)
|
||||
rows, err := sq.Select("resources").From("job").
|
||||
// AllocatedNodes returns a map of all subclusters to a map of hostnames to the amount of jobs running on that host.
|
||||
// Hosts with zero jobs running on them will not show up!
|
||||
func (r *JobRepository) AllocatedNodes(cluster string) (map[string]map[string]int, error) {
|
||||
subclusters := make(map[string]map[string]int)
|
||||
rows, err := sq.Select("resources", "subcluster").From("job").
|
||||
Where("job.job_state = 'running'").
|
||||
Where("job.cluster = ?", cluster).
|
||||
RunWith(r.stmtCache).Query()
|
||||
@ -334,17 +336,24 @@ func (r *JobRepository) AllocatedNodes(cluster string) ([]string, error) {
|
||||
for rows.Next() {
|
||||
raw = raw[0:0]
|
||||
var resources []*schema.Resource
|
||||
if err := rows.Scan(&raw); err != nil {
|
||||
var subcluster string
|
||||
if err := rows.Scan(&raw, &subcluster); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := json.Unmarshal(raw, &resources); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
hosts, ok := subclusters[subcluster]
|
||||
if !ok {
|
||||
hosts = make(map[string]int)
|
||||
subclusters[subcluster] = hosts
|
||||
}
|
||||
|
||||
for _, resource := range resources {
|
||||
nodes[resource.Hostname] += 1
|
||||
hosts[resource.Hostname] += 1
|
||||
}
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
return subclusters, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user