mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2025-06-08 08:33:49 +02:00
Implement node query
This commit is contained in:
parent
3d6dca9386
commit
87c93e90cd
@ -393,7 +393,6 @@ type TimeRangeOutput {
|
|||||||
input NodeFilter {
|
input NodeFilter {
|
||||||
hostname: StringInput
|
hostname: StringInput
|
||||||
cluster: StringInput
|
cluster: StringInput
|
||||||
subCluster: StringInput
|
|
||||||
nodeState: NodeState
|
nodeState: NodeState
|
||||||
healthState: MonitoringState
|
healthState: MonitoringState
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
package repository
|
package repository
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -12,6 +13,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/ClusterCockpit/cc-backend/internal/graph/model"
|
||||||
"github.com/ClusterCockpit/cc-backend/pkg/archive"
|
"github.com/ClusterCockpit/cc-backend/pkg/archive"
|
||||||
"github.com/ClusterCockpit/cc-backend/pkg/log"
|
"github.com/ClusterCockpit/cc-backend/pkg/log"
|
||||||
"github.com/ClusterCockpit/cc-backend/pkg/lrucache"
|
"github.com/ClusterCockpit/cc-backend/pkg/lrucache"
|
||||||
@ -212,8 +214,51 @@ func (r *NodeRepository) DeleteNode(id int64) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *NodeRepository) QueryNodes() ([]*schema.Node, error) {
|
func (r *NodeRepository) QueryNodes(
|
||||||
return nil, nil
|
ctx context.Context,
|
||||||
|
filters []*model.NodeFilter,
|
||||||
|
) ([]*schema.Node, error) {
|
||||||
|
query, qerr := SecurityCheck(ctx, sq.Select(jobColumns...).From("node"))
|
||||||
|
if qerr != nil {
|
||||||
|
return nil, qerr
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, f := range filters {
|
||||||
|
if f.Hostname != nil {
|
||||||
|
query = buildStringCondition("node.hostname", f.Hostname, query)
|
||||||
|
}
|
||||||
|
if f.Cluster != nil {
|
||||||
|
query = buildStringCondition("node.cluster", f.Cluster, query)
|
||||||
|
}
|
||||||
|
if f.NodeState != nil {
|
||||||
|
query = query.Where("node.node_state = ?", f.NodeState)
|
||||||
|
}
|
||||||
|
if f.HealthState != nil {
|
||||||
|
query = query.Where("node.health_state = ?", f.HealthState)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rows, err := query.RunWith(r.stmtCache).Query()
|
||||||
|
if err != nil {
|
||||||
|
queryString, queryVars, _ := query.ToSql()
|
||||||
|
log.Errorf("Error while running query '%s' %v: %v", queryString, queryVars, err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
nodes := make([]*schema.Node, 0, 50)
|
||||||
|
for rows.Next() {
|
||||||
|
node := schema.Node{}
|
||||||
|
|
||||||
|
if err := rows.Scan(&node.Hostname, &node.Cluster, &node.SubCluster,
|
||||||
|
&node.NodeState, &node.HealthState); err != nil {
|
||||||
|
rows.Close()
|
||||||
|
log.Warn("Error while scanning rows (Nodes)")
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
nodes = append(nodes, &node)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nodes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *NodeRepository) ListNodes(cluster string) ([]*schema.Node, error) {
|
func (r *NodeRepository) ListNodes(cluster string) ([]*schema.Node, error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user