You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

slurmdb_wckey.go 3.2 kB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package slurmer
  2. /*
  3. #cgo LDFLAGS: -lslurmdb
  4. #include <stdio.h>
  5. #include <slurm/slurm.h>
  6. #include <slurm/slurmdb.h>
  7. #include <memory.h>
  8. #include <malloc.h>
  9. typedef struct wckey_info_msg {
  10. uint32_t record_count;
  11. slurmdb_wckey_rec_t *wckey_array;
  12. } wckey_info_msg_t;
  13. typedef struct slurmdb_wckey_rec{
  14. uint16_t admin_level;
  15. List assoc_list;
  16. List coord_accts;
  17. char *default_acct;
  18. char *default_wckey;
  19. char *name;
  20. char *old_name;
  21. uint32_t uid;
  22. List wckey_list;
  23. } slurmdb_wckey_rec_pcm;
  24. struct wckey_info_msg get_wckey_info() {
  25. struct wckey_info_msg wckeyinfo;
  26. List wckeyList = NULL;
  27. slurmdb_wckey_cond_t *wckey_cond = NULL;
  28. void *db_conn;
  29. db_conn = slurmdb_connection_get();
  30. wckeyList = slurmdb_wckeys_get(db_conn, wckey_cond);
  31. slurmdb_connection_close(&db_conn);
  32. slurmdb_wckey_rec_t *rec = NULL;
  33. ListIterator itr = slurm_list_iterator_create(wckeyList);
  34. int i = 0;
  35. uint32_t length;
  36. length = slurm_list_count(wckeyList);
  37. wckeyinfo.record_count = length;
  38. wckeyinfo.wckey_array = malloc(length * sizeof(slurmdb_wckey_rec_t));
  39. while ((rec = slurm_list_next(itr))) {
  40. wckeyinfo.wckey_array[i] = *rec;
  41. i++;
  42. }
  43. return wckeyinfo;
  44. }
  45. struct slurmdb_wckey_rec *wckey_from_list(struct wckey_info_msg *list, int i) {
  46. return (struct slurmdb_wckey_rec *) &list->wckey_array[i];
  47. }
  48. */
  49. import "C"
  50. import (
  51. pbslurm "code.gitlink.org.cn/JCCE/PCM.git/adaptor/pcm_slurm/gen/idl"
  52. "context"
  53. )
  54. type WckeyInfoMsg struct {
  55. LastUpdate int64
  56. RecordCount uint32
  57. WckeyInfoList []pbslurm.WckeyInfo
  58. }
  59. func WckeyDescriptorConvertCToGo(cStruct *C.struct_slurmdb_wckey_rec) pbslurm.WckeyInfo {
  60. var goStruct pbslurm.WckeyInfo
  61. goStruct.Name = C.GoString(cStruct.name)
  62. return goStruct
  63. }
  64. func GetWckeyInfo() WckeyInfoMsg {
  65. var goWckeyBuffer WckeyInfoMsg
  66. cWckeyBuffer := C.get_wckey_info()
  67. goWckeyBuffer.RecordCount = uint32(cWckeyBuffer.record_count)
  68. goWckeyBuffer.WckeyInfoList = make([]pbslurm.WckeyInfo, cWckeyBuffer.record_count, cWckeyBuffer.record_count)
  69. for i := uint32(0); i < goWckeyBuffer.RecordCount; i++ {
  70. wckey := C.wckey_from_list(&cWckeyBuffer, C.int(i))
  71. goWckey := WckeyDescriptorConvertCToGo(wckey)
  72. goWckeyBuffer.WckeyInfoList[i] = goWckey
  73. }
  74. return goWckeyBuffer
  75. }
  76. func (slurmStruct SlurmStruct) ListWckeys(ctx context.Context, req *pbslurm.ListWckeysReq) (*pbslurm.ListWckeysResp, error) {
  77. wckeyList := GetWckeyInfo()
  78. resp := pbslurm.ListWckeysResp{}
  79. for _, wckey := range wckeyList.WckeyInfoList {
  80. wckeyInfoResult := wckey
  81. //wckeyInfoResult.Name = wckey.Name
  82. resp.WckeyInfos = append(resp.WckeyInfos, &wckeyInfoResult)
  83. }
  84. return &resp, nil
  85. }
  86. func (slurmStruct SlurmStruct) GetWckey(ctx context.Context, req *pbslurm.GetWckeyReq) (*pbslurm.GetWckeyResp, error) {
  87. wckeyList := GetWckeyInfo()
  88. resp := pbslurm.GetWckeyResp{}
  89. for _, wckey := range wckeyList.WckeyInfoList {
  90. //wckeyInfoResult := pbslurm.WckeyInfo{}
  91. //todo add filter logic
  92. wckeyInfoResult := wckey
  93. //wckeyInfoResult.Name = wckey.Name
  94. resp.WckeyInfo = append(resp.WckeyInfo, &wckeyInfoResult)
  95. }
  96. return &resp, nil
  97. }

PCM is positioned as Software stack over Cloud, aiming to build the standards and ecology of heterogeneous cloud collaboration for JCC in a non intrusive and autonomous peer-to-peer manner.