mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2025-07-23 21:01:40 +02:00
Change allocatedNodes; Update frontend
This commit is contained in:
2
frontend
2
frontend
Submodule frontend updated: 03818be470...239bf19c9a
@@ -275,7 +275,7 @@ type QueryResolver interface {
|
|||||||
Clusters(ctx context.Context) ([]*model.Cluster, error)
|
Clusters(ctx context.Context) ([]*model.Cluster, error)
|
||||||
Tags(ctx context.Context) ([]*schema.Tag, error)
|
Tags(ctx context.Context) ([]*schema.Tag, error)
|
||||||
User(ctx context.Context, username string) (*model.User, 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)
|
Job(ctx context.Context, id string) (*schema.Job, error)
|
||||||
JobMetrics(ctx context.Context, id string, metrics []string, scopes []schema.MetricScope) ([]*model.JobMetricWithName, 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)
|
JobsFootprints(ctx context.Context, filter []*model.JobFilter, metrics []string) (*model.Footprints, error)
|
||||||
@@ -1504,7 +1504,7 @@ type Query {
|
|||||||
tags: [Tag!]! # List of all tags
|
tags: [Tag!]! # List of all tags
|
||||||
|
|
||||||
user(username: String!): User
|
user(username: String!): User
|
||||||
allocatedNodes(cluster: String!): [String!]!
|
allocatedNodes(cluster: String!): [Count!]!
|
||||||
|
|
||||||
job(id: ID!): Job
|
job(id: ID!): Job
|
||||||
jobMetrics(id: ID!, metrics: [String!], scopes: [MetricScope!]): [JobMetricWithName!]!
|
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
|
return graphql.Null
|
||||||
}
|
}
|
||||||
res := resTmp.([]string)
|
res := resTmp.([]*model.Count)
|
||||||
fc.Result = res
|
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) {
|
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
|
tags: [Tag!]! # List of all tags
|
||||||
|
|
||||||
user(username: String!): User
|
user(username: String!): User
|
||||||
allocatedNodes(cluster: String!): [String!]!
|
allocatedNodes(cluster: String!): [Count!]!
|
||||||
|
|
||||||
job(id: ID!): Job
|
job(id: ID!): Job
|
||||||
jobMetrics(id: ID!, metrics: [String!], scopes: [MetricScope!]): [JobMetricWithName!]!
|
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)
|
return auth.FetchUser(ctx, r.DB, username)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *queryResolver) AllocatedNodes(ctx context.Context, cluster string) ([]string, error) {
|
func (r *queryResolver) AllocatedNodes(ctx context.Context, cluster string) ([]*model.Count, error) {
|
||||||
return r.Repo.AllocatedNodes(cluster)
|
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) {
|
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
|
return partitions.([]string), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *JobRepository) AllocatedNodes(cluster string) ([]string, error) {
|
// AllocatedNodes returns a map of all subclusters to a map of hostnames to the amount of jobs running on that host.
|
||||||
nodes := make(map[string]int)
|
// Hosts with zero jobs running on them will not show up!
|
||||||
rows, err := sq.Select("resources").From("job").
|
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.job_state = 'running'").
|
||||||
Where("job.cluster = ?", cluster).
|
Where("job.cluster = ?", cluster).
|
||||||
RunWith(r.stmtCache).Query()
|
RunWith(r.stmtCache).Query()
|
||||||
@@ -334,17 +336,24 @@ func (r *JobRepository) AllocatedNodes(cluster string) ([]string, error) {
|
|||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
raw = raw[0:0]
|
raw = raw[0:0]
|
||||||
var resources []*schema.Resource
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
if err := json.Unmarshal(raw, &resources); err != nil {
|
if err := json.Unmarshal(raw, &resources); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hosts, ok := subclusters[subcluster]
|
||||||
|
if !ok {
|
||||||
|
hosts = make(map[string]int)
|
||||||
|
subclusters[subcluster] = hosts
|
||||||
|
}
|
||||||
|
|
||||||
for _, resource := range resources {
|
for _, resource := range resources {
|
||||||
nodes[resource.Hostname] += 1
|
hosts[resource.Hostname] += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, nil
|
return subclusters, nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user