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
/*
#cgo LDFLAGS: -lslurm
#include<stdlib.h>
@ -73,47 +74,48 @@ import "C"
import "fmt"
import "unsafe"
type Node_info struct {
Arch string;
Boards uint16;
Boot_time int64;
Cluster_name string;
Cores uint16;
Core_spec_cnt uint16;
Cpu_bind uint32;
Cpu_load uint32;
Free_mem uint64;
Cpus uint16;
Cpu_spec_list string;
Features string;
Features_act string;
Gres string;
Gres_drain string;
Gres_used string;
Mcs_label string;
Mem_spec_limit uint64;
Name string;
Next_state uint32;
Node_addr string;
Node_hostname string;
Node_state uint32;
Os string;
Owner uint32;
Partitions string;
Port uint16;
Real_memory uint64;
Reason string;
Reason_time int64;
Reason_uid uint32;
Slurmd_start_time int64;
Sockets uint16;
Threads uint16;
Tmp_disk uint32;
Weight uint32;
Tres_fmt_str string;
Version string;
type Node_info struct {
Arch string
Boards uint16
Boot_time int64
Cluster_name string
Cores uint16
Core_spec_cnt uint16
Cpu_bind uint32
Cpu_load uint32
Free_mem uint64
Cpus uint16
Cpu_spec_list string
Features string
Features_act string
Gres string
Gres_drain string
Gres_used string
Mcs_label string
Mem_spec_limit uint64
Name string
Next_state uint32
Node_addr string
Node_hostname string
Node_state uint32
Os string
Owner uint32
Partitions string
Port uint16
Real_memory uint64
Reason string
Reason_time int64
Reason_uid uint32
Slurmd_start_time int64
Sockets uint16
Threads uint16
Tmp_disk uint32
Weight uint32
Tres_fmt_str 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
go_struct.Arch = C.GoString(c_struct.arch)
@ -155,76 +157,77 @@ func Node_info_convert_c_to_go(c_struct *C.struct_node_info) Node_info{
go_struct.Tres_fmt_str = C.GoString(c_struct.tres_fmt_str)
go_struct.Version = C.GoString(c_struct.version)
return go_struct
}
}
func State_to_string(state uint32) string{
func State_to_string(state uint32) string {
switch s := C.uint16_t(state); s {
case C.NODE_STATE_UNKNOWN:
return "node state unknown"
case C.NODE_STATE_UNKNOWN:
return "node state unknown"
case C.NODE_STATE_DOWN:
return "node state down"
return "node state down"
case C.NODE_STATE_IDLE:
return "node state idle"
return "node state idle"
case C.NODE_STATE_ALLOCATED:
return "node state allocated"
return "node state allocated"
case C.NODE_STATE_ERROR:
return "node state error"
return "node state error"
case C.NODE_STATE_MIXED:
return "node state mixed"
return "node state mixed"
case C.NODE_STATE_FUTURE:
return "node state future"
return "node state future"
case C.NODE_STATE_END:
return "node state end"
}
return "node state end"
}
return "Unkown state"
}
func Print_node_info(go_struct Node_info){
fmt.Printf("%s:\t %s\n","arch", go_struct.Arch)
fmt.Printf("%s:\t %d\n","boards", go_struct.Boards)
fmt.Printf("%s:\t %d\n","boot time", go_struct.Boot_time)
fmt.Printf("%s:\t %s\n","cluster name", go_struct.Cluster_name)
fmt.Printf("%s:\t %d\n","cores", go_struct.Cores)
fmt.Printf("%s:\t %d\n","core spec cnt", go_struct.Core_spec_cnt)
fmt.Printf("%s:\t %d\n","cpu bind", go_struct.Cpu_bind)
fmt.Printf("%s:\t %d\n","cpu load", go_struct.Cpu_load)
fmt.Printf("%s:\t %d\n","free mem", go_struct.Free_mem)
fmt.Printf("%s:\t %d\n","cpus", go_struct.Cpus)
fmt.Printf("%s:\t %s\n","cpu spec list", go_struct.Cpu_spec_list)
fmt.Printf("%s:\t %s\n","features", go_struct.Features)
fmt.Printf("%s:\t %s\n","features act", go_struct.Features_act)
fmt.Printf("%s:\t %s\n","gres", go_struct.Gres)
fmt.Printf("%s:\t %s\n","gres drain", go_struct.Gres_drain)
fmt.Printf("%s:\t %s\n","gres used", go_struct.Gres_used)
fmt.Printf("%s:\t %s\n","mcs label", go_struct.Mcs_label)
fmt.Printf("%s:\t %d\n","mem spec limit", go_struct.Mem_spec_limit)
fmt.Printf("%s:\t %s\n","name", go_struct.Name)
fmt.Printf("%s:\t %d\n","next state", go_struct.Next_state)
fmt.Printf("%s:\t %s\n","node addr", go_struct.Node_addr)
fmt.Printf("%s:\t %s\n","node hostname", go_struct.Node_hostname)
fmt.Printf("%s:\t %d\n","node state", go_struct.Node_state)
fmt.Printf("%s:\t %s\n","os", go_struct.Os)
fmt.Printf("%s:\t %d\n","owner", go_struct.Owner)
fmt.Printf("%s:\t %s\n","partitions", go_struct.Partitions)
fmt.Printf("%s:\t %d\n","port", go_struct.Port)
fmt.Printf("%s:\t %d\n","real memory", go_struct.Real_memory)
fmt.Printf("%s:\t %s\n","reason", go_struct.Reason)
fmt.Printf("%s:\t %d\n","reason time", go_struct.Reason_time)
fmt.Printf("%s:\t %d\n","reason uid", go_struct.Reason_uid)
fmt.Printf("%s:\t %d\n","slurmd start time", go_struct.Slurmd_start_time)
fmt.Printf("%s:\t %d\n","sockets", go_struct.Sockets)
fmt.Printf("%s:\t %d\n","threads", go_struct.Threads)
fmt.Printf("%s:\t %d\n","tmp disk", go_struct.Tmp_disk)
fmt.Printf("%s:\t %d\n","weight", go_struct.Weight)
fmt.Printf("%s:\t %s\n","tres fmt str", go_struct.Tres_fmt_str)
fmt.Printf("%s:\t %s\n","version", go_struct.Version)
}
func Print_node_info(go_struct Node_info) {
fmt.Printf("%s:\t %s\n", "arch", go_struct.Arch)
fmt.Printf("%s:\t %d\n", "boards", go_struct.Boards)
fmt.Printf("%s:\t %d\n", "boot time", go_struct.Boot_time)
fmt.Printf("%s:\t %s\n", "cluster name", go_struct.Cluster_name)
fmt.Printf("%s:\t %d\n", "cores", go_struct.Cores)
fmt.Printf("%s:\t %d\n", "core spec cnt", go_struct.Core_spec_cnt)
fmt.Printf("%s:\t %d\n", "cpu bind", go_struct.Cpu_bind)
fmt.Printf("%s:\t %d\n", "cpu load", go_struct.Cpu_load)
fmt.Printf("%s:\t %d\n", "free mem", go_struct.Free_mem)
fmt.Printf("%s:\t %d\n", "cpus", go_struct.Cpus)
fmt.Printf("%s:\t %s\n", "cpu spec list", go_struct.Cpu_spec_list)
fmt.Printf("%s:\t %s\n", "features", go_struct.Features)
fmt.Printf("%s:\t %s\n", "features act", go_struct.Features_act)
fmt.Printf("%s:\t %s\n", "gres", go_struct.Gres)
fmt.Printf("%s:\t %s\n", "gres drain", go_struct.Gres_drain)
fmt.Printf("%s:\t %s\n", "gres used", go_struct.Gres_used)
fmt.Printf("%s:\t %s\n", "mcs label", go_struct.Mcs_label)
fmt.Printf("%s:\t %d\n", "mem spec limit", go_struct.Mem_spec_limit)
fmt.Printf("%s:\t %s\n", "name", go_struct.Name)
fmt.Printf("%s:\t %d\n", "next state", go_struct.Next_state)
fmt.Printf("%s:\t %s\n", "node addr", go_struct.Node_addr)
fmt.Printf("%s:\t %s\n", "node hostname", go_struct.Node_hostname)
fmt.Printf("%s:\t %d\n", "node state", go_struct.Node_state)
fmt.Printf("%s:\t %s\n", "os", go_struct.Os)
fmt.Printf("%s:\t %d\n", "owner", go_struct.Owner)
fmt.Printf("%s:\t %s\n", "partitions", go_struct.Partitions)
fmt.Printf("%s:\t %d\n", "port", go_struct.Port)
fmt.Printf("%s:\t %d\n", "real memory", go_struct.Real_memory)
fmt.Printf("%s:\t %s\n", "reason", go_struct.Reason)
fmt.Printf("%s:\t %d\n", "reason time", go_struct.Reason_time)
fmt.Printf("%s:\t %d\n", "reason uid", go_struct.Reason_uid)
fmt.Printf("%s:\t %d\n", "slurmd start time", go_struct.Slurmd_start_time)
fmt.Printf("%s:\t %d\n", "sockets", go_struct.Sockets)
fmt.Printf("%s:\t %d\n", "threads", go_struct.Threads)
fmt.Printf("%s:\t %d\n", "tmp disk", go_struct.Tmp_disk)
fmt.Printf("%s:\t %d\n", "weight", go_struct.Weight)
fmt.Printf("%s:\t %s\n", "tres fmt str", go_struct.Tres_fmt_str)
fmt.Printf("%s:\t %s\n", "version", go_struct.Version)
}
type Node_info_msg struct {
Last_update int64;
Record_count uint32;
Error_code uint32;
Node_list []Node_info;
Last_update int64
Record_count uint32
Error_code uint32
Node_list []Node_info
}
func Get_all_nodes() Node_info_msg {
@ -238,18 +241,18 @@ func Get_all_nodes() Node_info_msg {
}
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.Node_list =make([]Node_info,c_node_buffer.record_count, c_node_buffer.record_count)
for i:=uint32(0); i<go_node_buffer.Record_count; i++ {
node := C.node_from_list(c_node_buffer, C.int(i))
go_node := Node_info_convert_c_to_go(node)
go_node_buffer.Node_list[i]=go_node
go_node_buffer.Node_list = make([]Node_info, c_node_buffer.record_count, c_node_buffer.record_count)
for i := uint32(0); i < go_node_buffer.Record_count; i++ {
node := C.node_from_list(c_node_buffer, C.int(i))
go_node := Node_info_convert_c_to_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
}
func Get_node_info (name string) Node_info_msg {
func Get_node_info(name string) Node_info_msg {
var go_node_buffer Node_info_msg
c_name := C.CString(name)
@ -260,19 +263,18 @@ func Get_node_info (name string) Node_info_msg {
go_node_buffer.Record_count = uint32(0)
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.Record_count = uint32(c_node_buffer.record_count)
go_node_buffer.Node_list =make([]Node_info,c_node_buffer.record_count, c_node_buffer.record_count)
for i:=uint32(0); i<go_node_buffer.Record_count; i++ {
node := C.node_from_list(c_node_buffer, C.int(i))
go_node := Node_info_convert_c_to_go(node)
go_node_buffer.Node_list[i]=go_node
go_node_buffer.Node_list = make([]Node_info, c_node_buffer.record_count, c_node_buffer.record_count)
for i := uint32(0); i < go_node_buffer.Record_count; i++ {
node := C.node_from_list(c_node_buffer, C.int(i))
go_node := Node_info_convert_c_to_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
}

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