mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2025-10-03 05:04:30 +02:00
Ongoing work on node table
Sync commit: Does not compile
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
// All rights reserved. This file is part of cc-backend.
|
// All rights reserved. This file is part of cc-backend.
|
||||||
// Use of this source code is governed by a MIT-style
|
// Use of this source code is governed by a MIT-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -25,7 +26,6 @@ type Node struct {
|
|||||||
GpusTotal int `json:"gpusTotal"`
|
GpusTotal int `json:"gpusTotal"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// updateNodeStatesRequest model
|
|
||||||
type UpdateNodeStatesRequest struct {
|
type UpdateNodeStatesRequest struct {
|
||||||
Nodes []Node `json:"nodes"`
|
Nodes []Node `json:"nodes"`
|
||||||
Cluster string `json:"cluster" example:"fritz"`
|
Cluster string `json:"cluster" example:"fritz"`
|
||||||
|
@@ -1,16 +1,24 @@
|
|||||||
|
-- sqlfluff:dialect:sqlite
|
||||||
|
--
|
||||||
CREATE TABLE "node" (
|
CREATE TABLE "node" (
|
||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY,
|
||||||
time_stamp INTEGER NOT NULL,
|
|
||||||
hostname VARCHAR(255) NOT NULL,
|
hostname VARCHAR(255) NOT NULL,
|
||||||
cluster VARCHAR(255) NOT NULL,
|
cluster VARCHAR(255) NOT NULL,
|
||||||
subcluster VARCHAR(255) NOT NULL,
|
subcluster VARCHAR(255) NOT NULL,
|
||||||
|
meta_data TEXT, -- JSON
|
||||||
|
UNIQUE (hostname, cluster)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE "node_state" (
|
||||||
|
id INTEGER PRIMARY KEY,
|
||||||
|
time_stamp INTEGER NOT NULL,
|
||||||
jobs_running INTEGER DEFAULT 0 NOT NULL,
|
jobs_running INTEGER DEFAULT 0 NOT NULL,
|
||||||
cpus_allocated INTEGER DEFAULT 0 NOT NULL,
|
|
||||||
cpus_total INTEGER DEFAULT 0 NOT NULL,
|
cpus_total INTEGER DEFAULT 0 NOT NULL,
|
||||||
memory_allocated INTEGER DEFAULT 0 NOT NULL,
|
|
||||||
memory_total INTEGER DEFAULT 0 NOT NULL,
|
memory_total INTEGER DEFAULT 0 NOT NULL,
|
||||||
gpus_allocated INTEGER DEFAULT 0 NOT NULL,
|
|
||||||
gpus_total INTEGER DEFAULT 0 NOT NULL,
|
gpus_total INTEGER DEFAULT 0 NOT NULL,
|
||||||
|
cpus_allocated INTEGER DEFAULT 0 NOT NULL,
|
||||||
|
memory_allocated INTEGER DEFAULT 0 NOT NULL,
|
||||||
|
gpus_allocated INTEGER DEFAULT 0 NOT NULL,
|
||||||
node_state VARCHAR(255) NOT NULL
|
node_state VARCHAR(255) NOT NULL
|
||||||
CHECK (node_state IN (
|
CHECK (node_state IN (
|
||||||
'allocated', 'reserved', 'idle', 'mixed',
|
'allocated', 'reserved', 'idle', 'mixed',
|
||||||
@@ -20,7 +28,8 @@ CREATE TABLE "node" (
|
|||||||
CHECK (health_state IN (
|
CHECK (health_state IN (
|
||||||
'full', 'partial', 'failed'
|
'full', 'partial', 'failed'
|
||||||
)),
|
)),
|
||||||
UNIQUE (hostname, cluster)
|
node_id INTEGER,
|
||||||
|
FOREIGN KEY (node_id) REFERENCES node (id)
|
||||||
);
|
);
|
||||||
|
|
||||||
-- Add Indices For New Node Table VARCHAR Fields
|
-- Add Indices For New Node Table VARCHAR Fields
|
||||||
|
@@ -143,12 +143,18 @@ func (r *NodeRepository) GetNode(id int64, withMeta bool) (*schema.Node, error)
|
|||||||
return node, nil
|
return node, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// const NamedNodeInsert string = `
|
||||||
|
// INSERT INTO node (time_stamp, hostname, cluster, subcluster, node_state, health_state,
|
||||||
|
//
|
||||||
|
// cpus_allocated, cpus_total, memory_allocated, memory_total, gpus_allocated, gpus_total)
|
||||||
|
// VALUES (:time_stamp, :hostname, :cluster, :subcluster, :node_state, :health_state,
|
||||||
|
// :cpus_allocated, :cpus_total, :memory_allocated, :memory_total, :gpus_allocated, :gpus_total);`
|
||||||
const NamedNodeInsert string = `
|
const NamedNodeInsert string = `
|
||||||
INSERT INTO node (time_stamp, hostname, cluster, subcluster, node_state, health_state,
|
INSERT INTO node (hostname, cluster, subcluster)
|
||||||
cpus_allocated, cpus_total, memory_allocated, memory_total, gpus_allocated, gpus_total)
|
VALUES (:hostname, :cluster, :subcluster);`
|
||||||
VALUES (:time_stamp, :hostname, :cluster, :subcluster, :node_state, :health_state,
|
|
||||||
:cpus_allocated, :cpus_total, :memory_allocated, :memory_total, :gpus_allocated, :gpus_total);`
|
|
||||||
|
|
||||||
|
// AddNode adds a Node to the node table. This can be triggered by a node collector registration or
|
||||||
|
// from a nodestate update from the job scheduler.
|
||||||
func (r *NodeRepository) AddNode(node *schema.Node) (int64, error) {
|
func (r *NodeRepository) AddNode(node *schema.Node) (int64, error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
@@ -177,7 +183,7 @@ func (r *NodeRepository) InsertNodeState(nodeState *schema.Node) error {
|
|||||||
|
|
||||||
_, err = r.DB.NamedExec(NamedNodeInsert, nodeState)
|
_, err = r.DB.NamedExec(NamedNodeInsert, nodeState)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cclog.Errorf("Error while adding node '%v' to database", nodeState.Hostname)
|
cclog.Errorf("Error while insert node '%v' to database", nodeState.Hostname)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user