style(frontend): gofmt the apiserver and xcecli sources

Formatting only (gofmt -w on the 29 non-vendored, non-generated files
gofmt -l reported); swag-generated apiserver/docs/docs.go left as is.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Rongsong Shen 2026-10-02 09:33:16 +00:00
parent b57ce6d6a9
commit 3615c7c0fb
Signed by untrusted user: rshen
GPG key ID: 80533536B0EB651C
29 changed files with 1280 additions and 1285 deletions

View file

@ -23,10 +23,10 @@ config_file:
}
tests := []struct {
name string
user string
pass string
wantErr bool
name string
user string
pass string
wantErr bool
}{
{"valid admin", "admin", "secret", false},
{"valid viewer", "viewer", "pass", false},

View file

@ -515,4 +515,4 @@ func TestIntegration_CrossFeature_SequentialConfigPushes(t *testing.T) {
if hb := atomic.LoadInt32(&heartbeatIntervalSecs); hb != 60 {
t.Errorf("heartbeatIntervalSecs = %d, want 60", hb)
}
}
}

View file

@ -1,9 +1,9 @@
package main
import (
_ "apiserver/docs"
"apiserver/backend"
"apiserver/backend/auth"
_ "apiserver/docs"
"apiserver/middleware"
"apiserver/router"
"apiserver/store"

View file

@ -44,16 +44,16 @@ const (
)
const (
SUCCESS_CODE = 200
CREATED = 201
ACCEPTED = 202
StatusPartialContent = 206
ERROR_CODE = 500
INVALID_PARAMS_CODE = 400
ERROR_AUTH_CHECK_TOKEN_CODE = 401
ERROR_AUTH_CODE = 403
ERROR_NOT_FOUND_CODE = 404
ERROR_TOO_MANY_REQUESTS_CODE = 429
SUCCESS_CODE = 200
CREATED = 201
ACCEPTED = 202
StatusPartialContent = 206
ERROR_CODE = 500
INVALID_PARAMS_CODE = 400
ERROR_AUTH_CHECK_TOKEN_CODE = 401
ERROR_AUTH_CODE = 403
ERROR_NOT_FOUND_CODE = 404
ERROR_TOO_MANY_REQUESTS_CODE = 429
//read file error
ERROR_READ_FILE_CODE = 501

View file

@ -675,4 +675,4 @@ func TestIntegration_SpecialCharactersInHostname(t *testing.T) {
if hostnameVal != xssHostname {
t.Errorf("hostname round-trip: got %q, want %q", hostnameVal, xssHostname)
}
}
}

View file

@ -27,7 +27,7 @@ import (
const (
//TODO: Need assign clusterID globally.
clusterID = 1
clusterID = 1
apiserverID = 0
)
@ -3190,4 +3190,3 @@ func GetHostList(hosts []string) ([]string, error) {
}
return execHosts, nil
}

View file

@ -1,11 +1,11 @@
package controllers
import (
"errors"
"apiserver/backend"
"apiserver/models"
"apiserver/store"
"apiserver/utils"
"errors"
"strings"
"testing"

View file

@ -242,4 +242,3 @@ func parseJobIDParam(jobidStr string) (models.JobInfo, error) {
ArrayIdx: 0, // peek defaults to base job; array idx can be added later
}, nil
}

View file

@ -237,7 +237,7 @@ func TestGetJobOutput_DefaultPathFallback(t *testing.T) {
// Use a real-ish packed job ID: cluster=1, apiserver=0, ts=1778311965, seq=0
// FormatJobID → "1-0-1778311965-0"
// WorkerDefaultOutputPath → "/tmp/job_1-0-1778311965-0_task0.out"
const uniqueID = int64(0x0100000006A04BDD<<0) // MakeJobID(1,0,1778311965,0,0)
const uniqueID = int64(0x0100000006A04BDD << 0) // MakeJobID(1,0,1778311965,0,0)
// Use backend.MakeJobID directly for clarity; compute inline:
// clusterID=1 at bit 56, timestamp=1778311965 at bit 20
// packed = (1 << 56) | (1778311965 << 20)
@ -512,4 +512,3 @@ func TestGetJobOutput_DoneJob(t *testing.T) {
t.Errorf("job_status = %q, want DONE", resp.Data.JobStatus)
}
}

View file

@ -7,46 +7,46 @@ import (
func TestClusterInfo_NewFields(t *testing.T) {
tests := []struct {
name string
name string
cluster ClusterInfo
field string
field string
want interface{}
}{
{
name: "HeartbeatInterval field exists and serializes",
name: "HeartbeatInterval field exists and serializes",
cluster: ClusterInfo{ClusterName: "test", HeartbeatInterval: 30},
field: "heartbeat_interval",
want: float64(30),
field: "heartbeat_interval",
want: float64(30),
},
{
name: "Vcpus field exists and serializes",
name: "Vcpus field exists and serializes",
cluster: ClusterInfo{ClusterName: "test", Vcpus: 16},
field: "vcpus",
want: float64(16),
field: "vcpus",
want: float64(16),
},
{
name: "InactiveHeartbeatCount field exists and serializes",
name: "InactiveHeartbeatCount field exists and serializes",
cluster: ClusterInfo{ClusterName: "test", InactiveHeartbeatCount: 3},
field: "inactive_heartbeat_count",
want: float64(3),
field: "inactive_heartbeat_count",
want: float64(3),
},
{
name: "HeartbeatInterval zero value serializes as 0 not omitted",
name: "HeartbeatInterval zero value serializes as 0 not omitted",
cluster: ClusterInfo{ClusterName: "test", HeartbeatInterval: 0, Vcpus: 0, InactiveHeartbeatCount: 0},
field: "heartbeat_interval",
want: float64(0),
field: "heartbeat_interval",
want: float64(0),
},
{
name: "Vcpus zero value serializes as 0 not omitted",
name: "Vcpus zero value serializes as 0 not omitted",
cluster: ClusterInfo{ClusterName: "test", HeartbeatInterval: 0, Vcpus: 0, InactiveHeartbeatCount: 0},
field: "vcpus",
want: float64(0),
field: "vcpus",
want: float64(0),
},
{
name: "InactiveHeartbeatCount zero value serializes as 0 not omitted",
name: "InactiveHeartbeatCount zero value serializes as 0 not omitted",
cluster: ClusterInfo{ClusterName: "test", HeartbeatInterval: 0, Vcpus: 0, InactiveHeartbeatCount: 0},
field: "inactive_heartbeat_count",
want: float64(0),
field: "inactive_heartbeat_count",
want: float64(0),
},
}
@ -122,4 +122,4 @@ func mapKeys(m map[string]interface{}) []string {
keys = append(keys, k)
}
return keys
}
}

View file

@ -1,17 +1,17 @@
package models
const (
CONTROL_JOB = 1
CONTROL_HOST = 2
CONTROL_QUEUE = 3
CONTROL_CLUSTER = 4
CONTROL_DEBUG = 5
)
type ActionControl struct {
TargetType int `json:"target_type"`
ActionType int `json:"action_type"`
Content Jsonb `json:"content"`
SubmitTime int64 `json:"submit_time"`
Submitter string `json:"submitter"`
}
package models
const (
CONTROL_JOB = 1
CONTROL_HOST = 2
CONTROL_QUEUE = 3
CONTROL_CLUSTER = 4
CONTROL_DEBUG = 5
)
type ActionControl struct {
TargetType int `json:"target_type"`
ActionType int `json:"action_type"`
Content Jsonb `json:"content"`
SubmitTime int64 `json:"submit_time"`
Submitter string `json:"submitter"`
}

View file

@ -88,9 +88,9 @@ type HostInfo struct {
NumSSusp int `json:"num_ssusp"`
NumUSusp int `json:"num_ususp"`
//NumRsv int `json:"num_rsv"`
NumDone int `json:"num_done"`
Topology string `json:"topology"` // JSONB
SchedStop string `json:"sched_stop"` // JSONB
NumDone int `json:"num_done"`
Topology string `json:"topology"` // JSONB
SchedStop string `json:"sched_stop"` // JSONB
ResourceValues []ResourceDistributionInfo `json:"resource_values"` // per-worker resource values
//RealLoad string `json:"real_load"` // JSONB
}

View file

@ -68,4 +68,4 @@ func TestHostStateStr(t *testing.T) {
}
})
}
}
}

View file

@ -591,32 +591,32 @@ type ArrayJobInfo struct {
}
type JobAdditionalFields struct {
JobID int64 `json:"job_id"`
SubmitUser string `json:"submit_user"`
JobStatus int `json:"job_status"`
JobID int64 `json:"job_id"`
SubmitUser string `json:"submit_user"`
JobStatus int `json:"job_status"`
SubmitTime int64 `json:"submit_time"`
FromHost string `json:"from_host"`
ExecHosts string `json:"exec_hosts"`
StartTime int64 `json:"start_time"`
EndTime int64 `json:"end_time"`
JobRusage Jsonb `json:"job_rusage"`
MaxMem float64 `json:"max_mem"`
AvgMem float64 `json:"avg_mem"`
UsedMem float64 `json:"used_mem"`
CPUTime int `json:"cpu_time"`
PeakCPUTime int `json:"peak_cpu_time"`
PeakCPUDuration float64 `json:"peak_cpu_duration"`
MemEfficiency float64 `json:"mem_efficiency"` // Memory efficiency in percentage
AvgCPUEfficiency float64 `json:"avg_cpu_efficiency"` // Average CPU efficiency in percentage
PeakCPUEfficiency float64 `json:"peak_cpu_efficiency"` // Peak CPU efficiency in percentage
NumHosts int `json:"num_hosts"` // Number of hosts used by the job
FirstHost string `json:"first_host"` // First host where the job ran
AllocSlot string `json:"alloc_slots"` // Allocated slot information
PIDInfo Jsonb `json:"pid_info"`
Pids []int `json:"pids"` // List of process IDs associated with the job
Pgids []int `json:"pgids"` // List of process group IDs associated with the job
InteractiveJobURL string `json:"interactive_job_url"`
StartTime int64 `json:"start_time"`
EndTime int64 `json:"end_time"`
JobRusage Jsonb `json:"job_rusage"`
MaxMem float64 `json:"max_mem"`
AvgMem float64 `json:"avg_mem"`
UsedMem float64 `json:"used_mem"`
CPUTime int `json:"cpu_time"`
PeakCPUTime int `json:"peak_cpu_time"`
PeakCPUDuration float64 `json:"peak_cpu_duration"`
MemEfficiency float64 `json:"mem_efficiency"` // Memory efficiency in percentage
AvgCPUEfficiency float64 `json:"avg_cpu_efficiency"` // Average CPU efficiency in percentage
PeakCPUEfficiency float64 `json:"peak_cpu_efficiency"` // Peak CPU efficiency in percentage
NumHosts int `json:"num_hosts"` // Number of hosts used by the job
FirstHost string `json:"first_host"` // First host where the job ran
AllocSlot string `json:"alloc_slots"` // Allocated slot information
PIDInfo Jsonb `json:"pid_info"`
Pids []int `json:"pids"` // List of process IDs associated with the job
Pgids []int `json:"pgids"` // List of process group IDs associated with the job
InteractiveJobURL string `json:"interactive_job_url"`
// CoreLimit/MemLimit: JobInfo has no equivalent field (these are
// submission-time resource limits, not job-state fields), but xcecli's
// JobFieldsMap accepts them as valid -o/-l display fields (bug-1674) --

View file

@ -1,139 +1,139 @@
package models
type ValueType int
const (
STRING ValueType = iota // Bool value
NUMERIC // Numeric value
BOOLEAN // String value
)
// String returns the string representation of ValueType
func (v ValueType) String() string {
switch v {
case BOOLEAN:
return "Boolean"
case NUMERIC:
return "Numeric"
case STRING:
return "String"
default:
return "Unknown"
}
}
type OrderType int
const (
INCR OrderType = iota
DECR
NA
)
// String returns the string representation of OrderType
func (o OrderType) String() string {
switch o {
case INCR:
return "Incr"
case DECR:
return "Decr"
case NA:
return "NA"
default:
return "Unknown"
}
}
var RESOURCE_DEFAULT_COLUMN = []string{
"res_name",
"description",
"value_type",
"order_type",
"flag",
"interval",
}
var RESOURCE_DISTRIBUTION_DEFAULT_COLUMN = []string{
"res_name",
"numeric_value",
"location",
"is_dynamic",
}
var RESOURCE_DEFINITION_DEFAULT_COLUMN = []string{
"res_name",
"description",
"value_type",
"order_type",
"flag",
"interval",
}
var ResourceFieldMappings = map[string]string{
// API field name → struct field name
"value": "numeric_value",
}
var ResourcesAvailableTypes = []string{"static", "dynamic"}
const (
BUILTIN = 0x01
DYNAMIC = 0x02
RELEASE = 0x20
CONSUMABLE = 0x80
)
type FlagValue int
// ToJSON returns the JSON object representation of FlagValue
func (f FlagValue) ToJSON() map[string]bool {
return map[string]bool{
"builtin": f&BUILTIN != 0,
"dynamic": f&DYNAMIC != 0,
"release": f&RELEASE != 0,
"consumable": f&CONSUMABLE != 0,
}
}
type ResourceInfo struct {
ResName string
Description string
ValueType ValueType
OrderType OrderType
Flag int
Interval int
}
// queues info query supported filter
var RESOURCE_DISTRIBUTION_SUPPORT_FILTERS = []string{
"res_name",
"is_dynamic",
"location",
}
var RESOURCE_DEFINITION_SUPPORT_FILTERS = []string{
"res_name",
}
type ResourceDistributionInfo struct {
ResourceName string `json:"res_name"`
IsDynamic bool `json:"is_dynamic"`
ValueType int `json:"value_type"`
BooleanValue bool `json:"boolean_value"`
StringValue string `json:"string_value"`
NumericValue float64 `json:"numeric_value"`
Location string `json:"location"`
}
type ResourceDefinitionInfo struct {
ResourceName string `json:"res_name"`
Description string `json:"description"`
ValueType int `json:"value_type"`
OrderType int `json:"order_type"`
Flag int `json:"flag"`
Interval int `json:"interval"`
}
var RESOURCE_DISTRIBUTION_SUPPORT_SORT = []string{
"res_name",
}
package models
type ValueType int
const (
STRING ValueType = iota // Bool value
NUMERIC // Numeric value
BOOLEAN // String value
)
// String returns the string representation of ValueType
func (v ValueType) String() string {
switch v {
case BOOLEAN:
return "Boolean"
case NUMERIC:
return "Numeric"
case STRING:
return "String"
default:
return "Unknown"
}
}
type OrderType int
const (
INCR OrderType = iota
DECR
NA
)
// String returns the string representation of OrderType
func (o OrderType) String() string {
switch o {
case INCR:
return "Incr"
case DECR:
return "Decr"
case NA:
return "NA"
default:
return "Unknown"
}
}
var RESOURCE_DEFAULT_COLUMN = []string{
"res_name",
"description",
"value_type",
"order_type",
"flag",
"interval",
}
var RESOURCE_DISTRIBUTION_DEFAULT_COLUMN = []string{
"res_name",
"numeric_value",
"location",
"is_dynamic",
}
var RESOURCE_DEFINITION_DEFAULT_COLUMN = []string{
"res_name",
"description",
"value_type",
"order_type",
"flag",
"interval",
}
var ResourceFieldMappings = map[string]string{
// API field name → struct field name
"value": "numeric_value",
}
var ResourcesAvailableTypes = []string{"static", "dynamic"}
const (
BUILTIN = 0x01
DYNAMIC = 0x02
RELEASE = 0x20
CONSUMABLE = 0x80
)
type FlagValue int
// ToJSON returns the JSON object representation of FlagValue
func (f FlagValue) ToJSON() map[string]bool {
return map[string]bool{
"builtin": f&BUILTIN != 0,
"dynamic": f&DYNAMIC != 0,
"release": f&RELEASE != 0,
"consumable": f&CONSUMABLE != 0,
}
}
type ResourceInfo struct {
ResName string
Description string
ValueType ValueType
OrderType OrderType
Flag int
Interval int
}
// queues info query supported filter
var RESOURCE_DISTRIBUTION_SUPPORT_FILTERS = []string{
"res_name",
"is_dynamic",
"location",
}
var RESOURCE_DEFINITION_SUPPORT_FILTERS = []string{
"res_name",
}
type ResourceDistributionInfo struct {
ResourceName string `json:"res_name"`
IsDynamic bool `json:"is_dynamic"`
ValueType int `json:"value_type"`
BooleanValue bool `json:"boolean_value"`
StringValue string `json:"string_value"`
NumericValue float64 `json:"numeric_value"`
Location string `json:"location"`
}
type ResourceDefinitionInfo struct {
ResourceName string `json:"res_name"`
Description string `json:"description"`
ValueType int `json:"value_type"`
OrderType int `json:"order_type"`
Flag int `json:"flag"`
Interval int `json:"interval"`
}
var RESOURCE_DISTRIBUTION_SUPPORT_SORT = []string{
"res_name",
}

View file

@ -102,7 +102,7 @@ func TestIntegration_ConcurrentResourceValuePushes(t *testing.T) {
ResourceName: "mem",
Location: "node01",
NumericValue: float64(idx + 1),
ValueType: 1, // NUMERIC
ValueType: 1, // NUMERIC
IsDynamic: true,
})
count.Add(1)
@ -129,4 +129,4 @@ func TestIntegration_ConcurrentResourceValuePushes(t *testing.T) {
if ResourceLocations.Count() != 1 {
t.Errorf("ResourceLocations count = %d, want 1 (key exists exactly once)", ResourceLocations.Count())
}
}
}

View file

@ -4,16 +4,16 @@ import "apiserver/models"
// Global store instances.
var (
Jobs *DataStore[uint64, models.JobInfo]
ArrayJobs *DataStore[uint64, models.ArrayJobInfo]
Queues *DataStore[string, models.QueueInfo]
Hosts *DataStore[string, models.HostInfo]
Jobs *DataStore[uint64, models.JobInfo]
ArrayJobs *DataStore[uint64, models.ArrayJobInfo]
Queues *DataStore[string, models.QueueInfo]
Hosts *DataStore[string, models.HostInfo]
Resources *DataStore[string, models.ResourceDefinitionInfo]
ResourceLocations *DataStore[string, models.ResourceDistributionInfo]
Clusters *DataStore[string, models.ClusterInfo]
JobExecHosts *DataStore[int64, models.JobExecHosts]
Roles *DataStore[string, RoleEntry]
UserRoles *DataStore[string, []string] // user_name → role_names
JobExecHosts *DataStore[int64, models.JobExecHosts]
Roles *DataStore[string, RoleEntry]
UserRoles *DataStore[string, []string] // user_name → role_names
)
// RoleEntry holds a role's permissions.