diff --git a/pkg/scheduler/objects/application.go b/pkg/scheduler/objects/application.go index f8ac022e1..088501e12 100644 --- a/pkg/scheduler/objects/application.go +++ b/pkg/scheduler/objects/application.go @@ -1541,10 +1541,12 @@ func (sa *Application) SetPlaceholderData(taskGroupName string, allocatedResourc if sa.PlaceholderDatas == nil { sa.PlaceholderDatas = make(map[string]*PlaceholderData) } - sa.PlaceholderDatas[taskGroupName] = &PlaceholderData{ - TaskGroupName: taskGroupName, - RequiredNode: requiredNode, - AllocatedResource: allocatedResource, + if _, ok := sa.PlaceholderDatas[taskGroupName]; !ok { + sa.PlaceholderDatas[taskGroupName] = &PlaceholderData{ + TaskGroupName: taskGroupName, + RequiredNode: requiredNode, + AllocatedResource: allocatedResource, + } } sa.PlaceholderDatas[taskGroupName].Count++ } diff --git a/pkg/webservice/handlers.go b/pkg/webservice/handlers.go index 66efcb4cb..04f20d11e 100644 --- a/pkg/webservice/handlers.go +++ b/pkg/webservice/handlers.go @@ -278,6 +278,8 @@ func getApplicationJSON(app *objects.Application) *dao.ApplicationDAOInfo { allocations := app.GetAllAllocations() allocationInfos := make([]dao.AllocationDAOInfo, 0, len(allocations)) placeHolderInfos := make([]dao.PlaceholderDAOInfo, 0, len(app.PlaceholderDatas)) + // Used to confirm whether the taskGroupName is duplicated + taskGroupNames := map[string]bool{} for _, alloc := range allocations { allocInfo := dao.AllocationDAOInfo{ @@ -295,14 +297,17 @@ func getApplicationJSON(app *objects.Application) *dao.ApplicationDAOInfo { if alloc.IsPlaceholder() { taskGroupName := alloc.GetTaskGroup() - placeHolderInfo := dao.PlaceholderDAOInfo{ - TaskGroupName: taskGroupName, - RequiredNode: app.PlaceholderDatas[taskGroupName].RequiredNode, - AllocatedResource: app.PlaceholderDatas[taskGroupName].AllocatedResource, - Count: app.PlaceholderDatas[taskGroupName].Count, - Replaced: app.PlaceholderDatas[taskGroupName].Replaced, + if _, ok := taskGroupNames[taskGroupName]; !ok { + taskGroupNames[taskGroupName] = true + placeHolderInfo := dao.PlaceholderDAOInfo{ + TaskGroupName: taskGroupName, + RequiredNode: app.PlaceholderDatas[taskGroupName].RequiredNode, + AllocatedResource: app.PlaceholderDatas[taskGroupName].AllocatedResource, + Count: app.PlaceholderDatas[taskGroupName].Count, + Replaced: app.PlaceholderDatas[taskGroupName].Replaced, + } + placeHolderInfos = append(placeHolderInfos, placeHolderInfo) } - placeHolderInfos = append(placeHolderInfos, placeHolderInfo) } }