Skip to content

Commit bc64375

Browse files
committed
use new way
1 parent c4bc9f2 commit bc64375

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

internal/ccontrol/ccontrol.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -406,10 +406,7 @@ func ShowJobs(jobIds string, queryAll bool) util.CraneCmdError {
406406
return util.ErrorGeneric
407407
}
408408

409-
allocDeviceTotal := "None"
410-
if len(taskInfo.AllocatedResView.DeviceMap) != 0 {
411-
allocDeviceTotal = taskInfo.AllocatedResView.DeviceMap
412-
}
409+
allocDeviceTotal := util.GetDeviceMapStr(taskInfo.AllocatedResView)
413410

414411
printed[taskInfo.TaskId] = true
415412

internal/util/string.go

+36
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,42 @@ func ParseGres(gres string) *protos.DeviceMap {
736736
return result
737737
}
738738

739+
func GetDeviceMapStr(resourceView *protos.ResourceView) string {
740+
if resourceView.DeviceMap == nil ||
741+
resourceView.DeviceMap.NameTypeMap == nil ||
742+
len(resourceView.DeviceMap.NameTypeMap) == 0 {
743+
return "None"
744+
}
745+
746+
var result strings.Builder
747+
isFirstDevice := true
748+
749+
for deviceName, typeCountMap := range resourceView.DeviceMap.NameTypeMap {
750+
if !isFirstDevice {
751+
result.WriteString("; ")
752+
} else {
753+
isFirstDevice = false
754+
}
755+
result.WriteString(fmt.Sprintf("%s:", deviceName))
756+
if typeCountMap.Total > 0 {
757+
result.WriteString(fmt.Sprintf("untyped:%d", typeCountMap.Total))
758+
}
759+
760+
isFirstType := typeCountMap.Total == 0
761+
for typeName, count := range typeCountMap.TypeCountMap {
762+
if !isFirstType {
763+
result.WriteString(",")
764+
} else {
765+
isFirstType = false
766+
}
767+
768+
result.WriteString(fmt.Sprintf("%s:%d", typeName, count))
769+
}
770+
}
771+
772+
return result.String()
773+
}
774+
739775
func ParseTaskStatusName(state string) (protos.TaskStatus, error) {
740776
state = strings.ToLower(state)
741777
switch state {

protos/PublicDefs.proto

+1-5
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ message ResourceV2 {
6868
map<string /*craned id*/, ResourceInNode> each_node_res = 1;
6969
}
7070

71-
message ResourceViewStr {
72-
AllocatableResource allocatable_res = 1;
73-
string device_map = 2;
74-
}
7571

7672
message ResourceView {
7773
AllocatableResource allocatable_res = 1;
@@ -295,7 +291,7 @@ message TaskInfo {
295291
google.protobuf.Duration elapsed_time = 37;
296292
repeated string execution_node = 38;
297293
bool exclusive = 39;
298-
ResourceViewStr allocated_res_view = 40;
294+
ResourceView allocated_res_view = 40;
299295
}
300296

301297
message PartitionInfo {

0 commit comments

Comments
 (0)