Add determine nodestate routine

This commit is contained in:
Jan Eitzinger 2025-06-05 16:15:40 +02:00
parent 3b5d3d671e
commit 1d9aa75960

View File

@ -23,6 +23,40 @@ type UpdateNodeStatesRequest struct {
Cluster string `json:"cluster" example:"fritz"`
}
// this routine assumes that only one of them applies per node
func determineState(states []string) schema.NodeState {
for _, state := range states {
switch state {
case "allocated":
return schema.NodeStateAllocated
case "reserved":
return schema.NodeStateReserved
case "idle":
return schema.NodeStateIdle
case "down":
return schema.NodeStateDown
case "mixed":
return schema.NodeStateMixed
}
}
return schema.NodeStateUnknown
}
// updateNodeStates godoc
// @summary Deliver updated Slurm node states
// @tags node
// @description Returns a JSON-encoded list of users.
// @description Required query-parameter defines if all users or only users with additional special roles are returned.
// @produce json
// @param request body UpdateNodeStatesRequest true "Request body containing nodes and their states"
// @success 200 {array} api.SuccessResponse "Success"
// @failure 400 {string} string "Bad Request"
// @failure 401 {string} string "Unauthorized"
// @failure 403 {string} string "Forbidden"
// @failure 500 {string} string "Internal Server Error"
// @security ApiKeyAuth
// @router /api/nodestats/ [post]
func (api *RestApi) updateNodeStates(rw http.ResponseWriter, r *http.Request) {
// Parse request body
req := UpdateNodeStatesRequest{}
@ -33,9 +67,7 @@ func (api *RestApi) updateNodeStates(rw http.ResponseWriter, r *http.Request) {
repo := repository.GetNodeRepository()
for _, node := range req.Nodes {
state := schema.NodeStateUnknown
// TODO: Determine valid node state
state := determineState(node.States)
repo.UpdateNodeState(node.Name, req.Cluster, &state)
}
}