package schedulerclient import "strings" // ── JobStatus mapping ─────────────────────────────────────────────────────── // JobStatusFromString maps the apiserver's job status string to a URM JobStatus. // // The input is the output of apiserver models.JobStateStr() — one of: // // PEND, PSUSP, RUN, USUSP, SSUSP, RUNKWN, EXIT, DONE, UNKWN, ERR, TRANSIENT func JobStatusFromString(s string) JobStatus { switch s { case "PEND", "PSUSP": return JobStatusPending case "RUN", "RUNKWN": return JobStatusRunning case "USUSP", "SSUSP": return JobStatusSuspended case "EXIT": return JobStatusFailed case "DONE": return JobStatusSucceeded default: // UNKWN, ERR, TRANSIENT, empty, or unknown values → unknown return JobStatusUnknown } } // ── QueueStatus mapping ───────────────────────────────────────────────────── // QueueStatusFromString maps the apiserver's composite queue status string // (e.g. "open:active", "closed:inactive_adm") to a URM status: // // active — queue is open and accepting jobs // inactive — queue is administratively or window-closed // draining — open but has an inactive-time window active (will close) // unknown — unrecognised format func QueueStatusFromString(s string) string { if s == "" { return "unknown" } // Format is ":" parts := strings.SplitN(s, ":", 2) if len(parts) < 1 { return "unknown" } openClosed := parts[0] var inactiveKind string if len(parts) > 1 { inactiveKind = parts[1] } switch openClosed { case "open": if inactiveKind == "inactive_adm" || inactiveKind == "inactive_win" { return "draining" } return "active" case "closed": return "inactive" default: return "unknown" } } // ── NodeStatus mapping ───────────────────────────────────────────────────── // NodeStatusFromString maps the apiserver's host status string (output of // models.HostStateStr()) to a URM node status: // // idle — OK, accepting work // busy — running jobs // down — CLOSED, CLOSED_BY_ADMIN // drain — LOCKU, LOCKW (not accepting new work, existing jobs finish) // unknown — UNAVAIL or unrecognised func NodeStatusFromString(s string) string { switch s { case "OK": return "idle" case "BUSY": return "busy" case "CLOSED", "CLOSED_BY_ADMIN": return "down" case "LOCKU", "LOCKW": return "drain" default: // UNAVAIL, empty, or unknown → unknown return "unknown" } }