Skip to content

Commit

Permalink
huge refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
lcrownover committed Oct 20, 2024
1 parent 4ffdf8d commit 8811d63
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
21 changes: 13 additions & 8 deletions internal/api/extractors_2405.go → internal/api/extractors.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build 2405

package api

import "log/slog"
Expand All @@ -12,7 +10,7 @@ func ExtractDiagData(diagRespBytes []byte) (*DiagData, error) {
}

d := &DiagData{
ApiVersion: "24.05",
ApiVersion: apiVersion,
}

d.SetServerThreadCount(resp.Statistics.ServerThreadCount)
Expand All @@ -39,7 +37,7 @@ func ExtractNodesData(nodesRespBytes []byte) (*NodesData, error) {
}

d := &NodesData{
ApiVersion: "24.05",
ApiVersion: apiVersion,
Nodes: []NodeData{},
}

Expand Down Expand Up @@ -75,7 +73,7 @@ func ExtractJobsData(jobsRespBytes []byte) (*JobsData, error) {
}

d := &JobsData{
ApiVersion: "24.05",
ApiVersion: apiVersion,
Jobs: []JobData{},
}

Expand All @@ -85,9 +83,16 @@ func ExtractJobsData(jobsRespBytes []byte) (*JobsData, error) {
jd.SetJobUserName(j.UserName)
jd.SetJobPartitionName(j.Partition)
jd.SetJobState(j.JobState)
jd.SetJobCPUs(j.JobResources.Cpus)
jd.SetJobDependency(j.Dependency)

// 2311 handles cpus differently
switch apiVersion {
case "23.11":
jd.SetJobCPUs(j.Cpus.Number)
case "24.05":
jd.SetJobCPUs(&j.JobResources.Cpus)
}

d.Jobs = append(d.Jobs, jd)
}

Expand All @@ -102,7 +107,7 @@ func ExtractPartitionsData(partitionsRespBytes []byte) (*PartitionsData, error)
}

d := &PartitionsData{
ApiVersion: "24.05",
ApiVersion: apiVersion,
Partitions: []PartitionData{},
}

Expand All @@ -127,7 +132,7 @@ func ExtractSharesData(sharesRespBytes []byte) (*SharesData, error) {
}

d := &SharesData{
ApiVersion: "24.05",
ApiVersion: apiVersion,
Shares: []ShareData{},
}

Expand Down
File renamed without changes.
8 changes: 6 additions & 2 deletions internal/api/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,12 @@ func (j *JobData) SetJobState(states []string) error {
return nil
}

func (j *JobData) SetJobCPUs(jobcpus int32) error {
j.Cpus = jobcpus
func (j *JobData) SetJobCPUs(jobcpus *int32) error {
if jobcpus == nil {
j.Cpus = 0
return nil
}
j.Cpus = *jobcpus
return nil
}

Expand Down
2 changes: 2 additions & 0 deletions internal/api/unmarshalers_2311.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/lcrownover/prometheus-slurm-exporter/internal/util"
)

var apiVersion = "23.11"

// UnmarshalDiagResponse converts the response bytes into a slurm type
func UnmarshalDiagResponse(b []byte) (*openapi.V0040OpenapiDiagResp, error) {
var diagResp openapi.V0040OpenapiDiagResp
Expand Down
2 changes: 2 additions & 0 deletions internal/api/unmarshalers_2405.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
openapi "github.com/lcrownover/openapi-slurm-24-05"
)

var apiVersion = "24.05"

// UnmarshalDiagResponse converts the response bytes into a slurm type
func UnmarshalDiagResponse(b []byte) (*openapi.SlurmV0041GetDiag200Response, error) {
var diagResp openapi.SlurmV0041GetDiag200Response
Expand Down

0 comments on commit 8811d63

Please sign in to comment.