forked from JointCloud/pcm-coordinator
79 lines
2.2 KiB
Go
79 lines
2.2 KiB
Go
package tianhe
|
|
|
|
/*
|
|
#cgo LDFLAGS: -lslurmdb
|
|
|
|
#include <stdio.h>
|
|
#include <slurm/slurm.h>
|
|
#include <slurm/slurmdb.h>
|
|
#include <memory.h>
|
|
#include <malloc.h>
|
|
|
|
typedef struct cluster_info_msg {
|
|
uint32_t record_count;
|
|
slurmdb_cluster_rec_t *cluster_array;
|
|
} cluster_info_msg_t;
|
|
|
|
typedef struct slurmdb_cluster_rec{
|
|
char *name;
|
|
} slurmdb_cluster_rec_pcm;
|
|
|
|
struct cluster_info_msg get_cluster_info() {
|
|
struct cluster_info_msg clusterinfo;
|
|
List clusterList = NULL;
|
|
slurmdb_cluster_cond_t *cluster_cond = NULL;
|
|
void *db_conn;
|
|
db_conn = slurmdb_connection_get();
|
|
clusterList = slurmdb_clusters_get(db_conn, cluster_cond);
|
|
slurmdb_connection_close(&db_conn);
|
|
|
|
slurmdb_cluster_rec_t *rec = NULL;
|
|
ListIterator itr = slurm_list_iterator_create(clusterList);
|
|
int i = 0;
|
|
uint32_t length;
|
|
length = slurm_list_count(clusterList);
|
|
clusterinfo.record_count = length;
|
|
clusterinfo.cluster_array = malloc(length * sizeof(slurmdb_cluster_rec_t));
|
|
while ((rec = slurm_list_next(itr))) {
|
|
clusterinfo.cluster_array[i] = *rec;
|
|
i++;
|
|
}
|
|
return clusterinfo;
|
|
}
|
|
|
|
struct slurmdb_cluster_rec *cluster_from_list(struct cluster_info_msg *list, int i) {
|
|
return (struct slurmdb_cluster_rec *) &list->cluster_array[i];
|
|
}
|
|
|
|
*/
|
|
import "C"
|
|
import (
|
|
pbslurm "code.gitlink.org.cn/JCCE/PCM.git/adaptor/pcm_slurm/gen/idl"
|
|
)
|
|
|
|
type ClusterInfoMsg struct {
|
|
Last_update int64
|
|
Record_count uint32
|
|
ClusterInfoList []pbslurm.ClusterInfo
|
|
}
|
|
|
|
func Cluster_descriptor_convert_c_to_go(c_struct *C.struct_slurmdb_cluster_rec) pbslurm.ClusterInfo {
|
|
var go_struct pbslurm.ClusterInfo
|
|
go_struct.Name = C.GoString(c_struct.name)
|
|
return go_struct
|
|
}
|
|
|
|
func GetClusterInfo() ClusterInfoMsg {
|
|
var go_cluster_buffer ClusterInfoMsg
|
|
c_cluster_buffer := C.get_cluster_info()
|
|
go_cluster_buffer.Record_count = uint32(c_cluster_buffer.record_count)
|
|
go_cluster_buffer.ClusterInfoList = make([]pbslurm.ClusterInfo, c_cluster_buffer.record_count, c_cluster_buffer.record_count)
|
|
|
|
for i := uint32(0); i < go_cluster_buffer.Record_count; i++ {
|
|
cluster := C.cluster_from_list(&c_cluster_buffer, C.int(i))
|
|
go_cluster := Cluster_descriptor_convert_c_to_go(cluster)
|
|
go_cluster_buffer.ClusterInfoList[i] = go_cluster
|
|
}
|
|
return go_cluster_buffer
|
|
}
|