forked from JointCloud/pcm-coordinator
117 lines
3.1 KiB
Go
117 lines
3.1 KiB
Go
package tianhe
|
|
|
|
/*
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <stdint.h>
|
|
#include<slurm/slurm.h>
|
|
#include<slurm/slurm_errno.h>
|
|
#include <signal.h>
|
|
|
|
struct job_info_msg *get_job_info(){
|
|
|
|
struct job_info_msg* job_buffer;
|
|
if(slurm_load_jobs ((time_t) NULL,
|
|
&job_buffer, SHOW_ALL)) {
|
|
return NULL;
|
|
}
|
|
|
|
return job_buffer;
|
|
}
|
|
|
|
struct job_info* job_from_list(struct job_info_msg *list, int i){
|
|
return &list->job_array[i];
|
|
}
|
|
|
|
struct job_info_msg *get_single_job_info(uint32_t id){
|
|
struct job_info_msg* job_buffer;
|
|
if( slurm_load_job (&job_buffer, id, SHOW_DETAIL)) {
|
|
return NULL;
|
|
}
|
|
return job_buffer;
|
|
}
|
|
|
|
int delete_job(uint32_t id) {
|
|
int error_code = 0;
|
|
error_code = slurm_kill_job (id, SIGKILL, 0);
|
|
if (error_code) {
|
|
char msg[64];
|
|
sprintf(msg, "slurm_kill_job(%.12s)",id);
|
|
slurm_perror (msg);
|
|
return error_code;
|
|
}
|
|
return (error_code);
|
|
}
|
|
|
|
//static time_t last_update_time = (time_t) NULL;
|
|
//int error_code;
|
|
//job_info_msg_t * job_info_msg_ptr = NULL;
|
|
//
|
|
//error_code = slurm_load_jobs (last_update_time, &job_info_msg_ptr, 1);
|
|
//if (error_code) {
|
|
// slurm_perror ("slurm_load_jobs");
|
|
// return (error_code);
|
|
//}
|
|
//
|
|
//slurm_print_job_info_msg ( stdout, job_info_msg_ptr, 1 ) ;
|
|
//
|
|
//slurm_free_job_info_msg ( job_info_msg_ptr ) ;
|
|
|
|
*/
|
|
import "C"
|
|
import (
|
|
pbslurm "code.gitlink.org.cn/JCCE/PCM.git/adaptor/pcm_slurm/gen/idl"
|
|
)
|
|
|
|
func Get_all_jobs() pbslurm.JobInfoMsg {
|
|
var go_job_buffer pbslurm.JobInfoMsg
|
|
c_job_buffer := C.get_job_info()
|
|
if c_job_buffer == nil {
|
|
go_job_buffer.LastUpdate = int64(0)
|
|
go_job_buffer.RecordCount = uint32(0)
|
|
go_job_buffer.JobList = nil
|
|
return go_job_buffer
|
|
}
|
|
|
|
go_job_buffer.LastUpdate = int64(c_job_buffer.last_update)
|
|
go_job_buffer.RecordCount = uint32(c_job_buffer.record_count)
|
|
for i := uint32(0); i < go_job_buffer.RecordCount; i++ {
|
|
job := C.job_from_list(c_job_buffer, C.int(i))
|
|
go_job := Job_info_convert_c_to_go(job)
|
|
go_job_buffer.JobList = append(go_job_buffer.JobList, &go_job)
|
|
//fmt.Println(Reason_to_string(go_job.Job_state))
|
|
//fmt.Println(state_to_string(uint32(go_job.Job_state)))
|
|
}
|
|
C.slurm_free_job_info_msg(c_job_buffer)
|
|
|
|
return go_job_buffer
|
|
}
|
|
|
|
func Delete_job(id uint32) int32 {
|
|
error_code := C.slurm_kill_job(C.uint32_t(id), C.SIGKILL, C.uint16_t(0))
|
|
return int32(error_code)
|
|
}
|
|
|
|
func Get_job(id uint32) pbslurm.JobInfoMsg {
|
|
var go_job_buffer pbslurm.JobInfoMsg
|
|
c_job_buffer := C.get_single_job_info(C.uint32_t(id))
|
|
if c_job_buffer == nil {
|
|
go_job_buffer.LastUpdate = int64(0)
|
|
go_job_buffer.RecordCount = uint32(0)
|
|
go_job_buffer.JobList = nil
|
|
return go_job_buffer
|
|
}
|
|
go_job_buffer.LastUpdate = int64(c_job_buffer.last_update)
|
|
go_job_buffer.RecordCount = uint32(c_job_buffer.record_count)
|
|
for i := uint32(0); i < go_job_buffer.RecordCount; i++ {
|
|
job := C.job_from_list(c_job_buffer, C.int(i))
|
|
go_job := Job_info_convert_c_to_go(job)
|
|
go_job_buffer.JobList = append(go_job_buffer.JobList, &go_job)
|
|
//fmt.Println(Reason_to_string(go_job.Job_state))
|
|
//fmt.Println(state_to_string(uint32(go_job.Job_state)))
|
|
}
|
|
C.slurm_free_job_info_msg(c_job_buffer)
|
|
|
|
return go_job_buffer
|
|
}
|