change directory name

This commit is contained in:
zhouqunjie 2022-10-17 08:02:26 +08:00
parent 8ae093d187
commit eb2e6166c0
47 changed files with 2271 additions and 2274 deletions

View File

@ -0,0 +1,118 @@
/*These are some extra functions to work with slurm in go
** They are seperated, since they don't use the slurm-API
** but wrap arround the SLURM comand line tools */
package extra
import (
"errors"
"fmt"
"os"
"os/exec"
"path/filepath"
"slurm"
"slurm/jobinfo"
"strconv"
"strings"
)
var slurm_path string
func find_slurm_path() {
var err error
var path string
path = os.Getenv("SLURM_PATH")
if path == " " {
path, err = exec.LookPath("sinfo")
if err != nil {
fmt.Printf("could not find slurm executables\n Either add slum-bins to your PATH or define SLURM_PATH\n")
} else {
slurm_path = strings.TrimSuffix(path, "bin/sinfo")
}
} else {
test_path := filepath.Join(path, "bin/sinfo")
_, err := os.Stat(test_path)
if os.IsNotExist(err) {
fmt.Printf("Slurm executable sinfo does no exist at %s\n", test_path)
} else {
slurm_path = path
}
}
}
func Cancel_job(JobId uint32) error {
find_slurm_path()
if slurm_path == "" {
return errors.New("Cannot find slurm executable")
}
job_list := job_info.Get_job(JobId)
if job_list.Error_code != 0 {
msg := slurm.GetErrorString(job_list.Error_code)
fmt.Printf(msg)
return errors.New(msg)
}
path := filepath.Join(slurm_path, "bin", "scancel")
cmd := exec.Command(path, strconv.FormatInt(int64(JobId), 10))
fmt.Print(cmd.String())
out, err := cmd.CombinedOutput()
if err != nil {
msg := string(out) + err.Error()
return errors.New(msg)
}
return nil
}
type Acc_Job_info struct {
JobId uint32
User string
Account string
State string
JobName string
}
var sacct_format_string string
func parse_sacct_output(input string) []Acc_Job_info {
var job_list []Acc_Job_info
lines := strings.Split(string(input), "\n")
fmt.Printf("len %d\n", len(lines)-1)
for l := range lines {
var job_info Acc_Job_info
elements := strings.Split(lines[l], "|")
if len(elements) < 5 {
break //Well, this is not clean, but keep it like this for Now
}
id, ierr := strconv.Atoi(elements[0])
if ierr != nil {
break //we have no useable entry here but something like 323.batch . Ignore these for now
}
job_info.JobId = uint32(id)
job_info.User = elements[1]
job_info.Account = elements[2]
job_info.State = elements[3]
job_info.JobName = elements[4]
job_list = append(job_list, job_info)
}
return job_list
}
func Get_job_info_accounting(JobId uint32) ([]Acc_Job_info, error) {
sacct_format_string = "JobId,user,account,state,JobName"
find_slurm_path()
if slurm_path == "" {
return nil, errors.New("Cannot find slurm executable")
}
path := filepath.Join(slurm_path, "bin", "sacct")
cmd := exec.Command(path, "-j", strconv.FormatInt(int64(JobId), 10), "--format", sacct_format_string, "-p", "-n")
//fmt.Printf(cmd.String())
out, err := cmd.CombinedOutput()
if err != nil {
msg := string(out) + err.Error()
return nil, errors.New(msg)
}
list := parse_sacct_output(string(out))
return list, nil
}

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,5 @@
package node_info package node_info
/* /*
#cgo LDFLAGS: -lslurm #cgo LDFLAGS: -lslurm
#include<stdlib.h> #include<stdlib.h>
@ -74,45 +75,46 @@ import "fmt"
import "unsafe" import "unsafe"
type Node_info struct { type Node_info struct {
Arch string; Arch string
Boards uint16; Boards uint16
Boot_time int64; Boot_time int64
Cluster_name string; Cluster_name string
Cores uint16; Cores uint16
Core_spec_cnt uint16; Core_spec_cnt uint16
Cpu_bind uint32; Cpu_bind uint32
Cpu_load uint32; Cpu_load uint32
Free_mem uint64; Free_mem uint64
Cpus uint16; Cpus uint16
Cpu_spec_list string; Cpu_spec_list string
Features string; Features string
Features_act string; Features_act string
Gres string; Gres string
Gres_drain string; Gres_drain string
Gres_used string; Gres_used string
Mcs_label string; Mcs_label string
Mem_spec_limit uint64; Mem_spec_limit uint64
Name string; Name string
Next_state uint32; Next_state uint32
Node_addr string; Node_addr string
Node_hostname string; Node_hostname string
Node_state uint32; Node_state uint32
Os string; Os string
Owner uint32; Owner uint32
Partitions string; Partitions string
Port uint16; Port uint16
Real_memory uint64; Real_memory uint64
Reason string; Reason string
Reason_time int64; Reason_time int64
Reason_uid uint32; Reason_uid uint32
Slurmd_start_time int64; Slurmd_start_time int64
Sockets uint16; Sockets uint16
Threads uint16; Threads uint16
Tmp_disk uint32; Tmp_disk uint32
Weight uint32; Weight uint32
Tres_fmt_str string; Tres_fmt_str string
Version string; Version string
} }
func Node_info_convert_c_to_go(c_struct *C.struct_node_info) Node_info { func Node_info_convert_c_to_go(c_struct *C.struct_node_info) Node_info {
var go_struct Node_info var go_struct Node_info
@ -220,11 +222,12 @@ func Node_info_convert_c_to_go(c_struct *C.struct_node_info) Node_info{
fmt.Printf("%s:\t %s\n", "tres fmt str", go_struct.Tres_fmt_str) fmt.Printf("%s:\t %s\n", "tres fmt str", go_struct.Tres_fmt_str)
fmt.Printf("%s:\t %s\n", "version", go_struct.Version) fmt.Printf("%s:\t %s\n", "version", go_struct.Version)
} }
type Node_info_msg struct { type Node_info_msg struct {
Last_update int64; Last_update int64
Record_count uint32; Record_count uint32
Error_code uint32; Error_code uint32
Node_list []Node_info; Node_list []Node_info
} }
func Get_all_nodes() Node_info_msg { func Get_all_nodes() Node_info_msg {
@ -244,7 +247,7 @@ func Get_all_nodes() Node_info_msg {
go_node := Node_info_convert_c_to_go(node) go_node := Node_info_convert_c_to_go(node)
go_node_buffer.Node_list[i] = go_node go_node_buffer.Node_list[i] = go_node
} }
C.slurm_free_node_info_msg (c_node_buffer); C.slurm_free_node_info_msg(c_node_buffer)
return go_node_buffer return go_node_buffer
} }
@ -260,7 +263,7 @@ func Get_node_info (name string) Node_info_msg {
go_node_buffer.Record_count = uint32(0) go_node_buffer.Record_count = uint32(0)
go_node_buffer.Error_code = uint32(C.slurm_get_errno()) go_node_buffer.Error_code = uint32(C.slurm_get_errno())
return go_node_buffer; return go_node_buffer
} }
go_node_buffer.Last_update = int64(c_node_buffer.last_update) go_node_buffer.Last_update = int64(c_node_buffer.last_update)
go_node_buffer.Record_count = uint32(c_node_buffer.record_count) go_node_buffer.Record_count = uint32(c_node_buffer.record_count)
@ -270,9 +273,8 @@ func Get_node_info (name string) Node_info_msg {
go_node := Node_info_convert_c_to_go(node) go_node := Node_info_convert_c_to_go(node)
go_node_buffer.Node_list[i] = go_node go_node_buffer.Node_list[i] = go_node
} }
C.slurm_free_node_info_msg (c_node_buffer); C.slurm_free_node_info_msg(c_node_buffer)
return go_node_buffer return go_node_buffer
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,121 +0,0 @@
/*These are some extra functions to work with slurm in go
** They are seperated, since they don't use the slurm-API
** but wrap arround the SLURM comand line tools */
package extra
import (
"fmt"
"os"
"os/exec"
"strings"
"errors"
"path/filepath"
"slurm/jobinfo"
"slurm"
"strconv"
)
var slurm_path string
func find_slurm_path () {
var err error
var path string
path=os.Getenv("SLURM_PATH")
if path == " "{
path, err = exec.LookPath("sinfo")
if err != nil {
fmt.Printf("could not find slurm executables\n Either add slum-bins to your PATH or define SLURM_PATH\n")
} else {
slurm_path=strings.TrimSuffix(path, "bin/sinfo")
}
} else {
test_path := filepath.Join(path, "bin/sinfo")
_, err := os.Stat(test_path)
if os.IsNotExist(err) {
fmt.Printf("Slurm executable sinfo does no exist at %s\n", test_path)
} else {
slurm_path = path
}
}
}
func Cancel_job( JobId uint32) error{
find_slurm_path()
if slurm_path == "" {
return errors.New("Cannot find slurm executable")
}
job_list := job_info.Get_job(JobId)
if job_list.Error_code != 0 {
msg := slurm.GetErrorString(job_list.Error_code)
fmt.Printf(msg)
return errors.New(msg)
}
path := filepath.Join(slurm_path,"bin","scancel")
cmd := exec.Command(path, strconv.FormatInt(int64(JobId), 10))
fmt.Print(cmd.String())
out, err := cmd.CombinedOutput()
if err!= nil {
msg := string(out) + err.Error()
return errors.New(msg)
}
return nil
}
type Acc_Job_info struct {
JobId uint32;
User string;
Account string;
State string;
JobName string;
}
var sacct_format_string string
func parse_sacct_output(input string) []Acc_Job_info {
var job_list []Acc_Job_info
lines := strings.Split(string(input), "\n")
fmt.Printf("len %d\n",len(lines)-1)
for l := range lines {
var job_info Acc_Job_info
elements := strings.Split(lines[l], "|")
if len(elements) < 5 {
break //Well, this is not clean, but keep it like this for Now
}
id, ierr := strconv.Atoi(elements[0])
if ierr != nil {
break //we have no useable entry here but something like 323.batch . Ignore these for now
}
job_info.JobId =uint32(id)
job_info.User = elements[1]
job_info.Account = elements[2]
job_info.State = elements[3]
job_info.JobName =elements[4]
job_list = append(job_list, job_info)
}
return job_list
}
func Get_job_info_accounting(JobId uint32 ) ([]Acc_Job_info, error) {
sacct_format_string = "JobId,user,account,state,JobName"
find_slurm_path()
if slurm_path == "" {
return nil, errors.New("Cannot find slurm executable")
}
path := filepath.Join(slurm_path,"bin","sacct")
cmd:= exec.Command(path, "-j", strconv.FormatInt(int64(JobId), 10),"--format", sacct_format_string,"-p","-n")
//fmt.Printf(cmd.String())
out, err := cmd.CombinedOutput()
if err!= nil {
msg := string(out) + err.Error()
return nil, errors.New(msg)
}
list := parse_sacct_output(string(out))
return list, nil
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff