From e7b7a0b72ccf406c98071772064a1b732e709905 Mon Sep 17 00:00:00 2001 From: steinsgateted Date: Fri, 11 Mar 2022 13:37:10 +0800 Subject: [PATCH] [YUNIKORN-998] expose gang related info in application REST info --- pkg/scheduler/context.go | 2 +- pkg/scheduler/objects/application.go | 2 +- pkg/scheduler/objects/application_test.go | 17 +++++++++-------- pkg/webservice/handlers.go | 22 +++++++++++----------- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/pkg/scheduler/context.go b/pkg/scheduler/context.go index 31d09dc35..bdccbe357 100644 --- a/pkg/scheduler/context.go +++ b/pkg/scheduler/context.go @@ -50,7 +50,7 @@ type ClusterContext struct { needPreemption bool reservationDisabled bool - rmInfo map[string]*RMInformation + rmInfo map[string]*RMInformation startTime time.Time sync.RWMutex diff --git a/pkg/scheduler/objects/application.go b/pkg/scheduler/objects/application.go index a3e46685f..4b07c60fa 100644 --- a/pkg/scheduler/objects/application.go +++ b/pkg/scheduler/objects/application.go @@ -88,7 +88,7 @@ type Application struct { gangSchedulingStyle string // gang scheduling style can be hard (after timeout we fail the application), or soft (after timeeout we schedule it as a normal application) finishedTime time.Time // the time of finishing this application. the default value is zero time rejectedMessage string // If the application is rejected, save the rejected message - placeholderData map[string]*PlaceholderData // expose gang related info in application REST info + placeholderData map[string]*PlaceholderData // expose gang related info in application REST info rmEventHandler handler.EventHandler rmID string diff --git a/pkg/scheduler/objects/application_test.go b/pkg/scheduler/objects/application_test.go index d037999d7..62324d5c4 100644 --- a/pkg/scheduler/objects/application_test.go +++ b/pkg/scheduler/objects/application_test.go @@ -662,8 +662,9 @@ func TestStateChangeOnPlaceholderAdd(t *testing.T) { res := resources.NewResourceFromMap(map[string]resources.Quantity{"first": 1}) askID := "ask-1" tgName := "TG1" + requiredNode := "node-1" ask := newAllocationAskTG(askID, appID1, tgName, res, 1) - ask.requiredNode = "node-1" + ask.requiredNode = requiredNode err = app.AddAllocationAsk(ask) assert.NilError(t, err, "ask should have been added to app") // app with ask, even for placeholder, should be accepted @@ -672,25 +673,25 @@ func TestStateChangeOnPlaceholderAdd(t *testing.T) { clonePlaceholderData := app.GetAllPlaceholderData() assert.Assert(t, len(clonePlaceholderData) == 1) assert.Assert(t, len(app.placeholderData) == 1) - assert.Equal(t,clonePlaceholderData[0],app.placeholderData[tgName]) - assert.Equal(t, app.placeholderData[tgName].TaskGroupName, "TG1") + assert.Equal(t, clonePlaceholderData[0], app.placeholderData[tgName]) + assert.Equal(t, app.placeholderData[tgName].TaskGroupName, tgName) assert.Equal(t, app.placeholderData[tgName].Count, int64(1)) assert.Assert(t, resources.Equals(app.placeholderData[tgName].MinResource, res)) - assert.Equal(t, app.placeholderData[tgName].RequiredNode, "node-1") + assert.Equal(t, app.placeholderData[tgName].RequiredNode, requiredNode) assert.Equal(t, app.placeholderData[tgName].Replaced, int64(0)) // add second placeholder ask2 := newAllocationAskTG(askID, appID1, tgName, res, 1) - ask2.requiredNode = "node-1" + ask2.requiredNode = requiredNode err = app.AddAllocationAsk(ask2) assert.NilError(t, err, "ask should have been added to app") clonePlaceholderData = app.GetAllPlaceholderData() assert.Assert(t, len(clonePlaceholderData) == 1) assert.Assert(t, len(app.placeholderData) == 1) - assert.Equal(t,clonePlaceholderData[0],app.placeholderData[tgName]) - assert.Equal(t, app.placeholderData[tgName].TaskGroupName, "TG1") + assert.Equal(t, clonePlaceholderData[0], app.placeholderData[tgName]) + assert.Equal(t, app.placeholderData[tgName].TaskGroupName, tgName) assert.Equal(t, app.placeholderData[tgName].Count, int64(2)) assert.Assert(t, resources.Equals(app.placeholderData[tgName].MinResource, res)) - assert.Equal(t, app.placeholderData[tgName].RequiredNode, "node-1") + assert.Equal(t, app.placeholderData[tgName].RequiredNode, requiredNode) assert.Equal(t, app.placeholderData[tgName].Replaced, int64(0)) // removing the ask should move it to waiting diff --git a/pkg/webservice/handlers.go b/pkg/webservice/handlers.go index c3d637a7a..128a48266 100644 --- a/pkg/webservice/handlers.go +++ b/pkg/webservice/handlers.go @@ -307,17 +307,17 @@ func getApplicationJSON(app *objects.Application) *dao.ApplicationDAOInfo { } return &dao.ApplicationDAOInfo{ - ApplicationID: app.ApplicationID, - UsedResource: app.GetAllocatedResource().DAOString(), - MaxUsedResource: app.GetMaxAllocatedResource().DAOString(), - Partition: common.GetPartitionNameWithoutClusterID(app.Partition), - QueueName: app.QueuePath, - SubmissionTime: app.SubmissionTime.UnixNano(), - FinishedTime: common.ZeroTimeInUnixNano(app.FinishedTime()), - Allocations: allocationInfo, - State: app.CurrentState(), - User: app.GetUser().User, - RejectedMessage: app.GetRejectedMessage(), + ApplicationID: app.ApplicationID, + UsedResource: app.GetAllocatedResource().DAOString(), + MaxUsedResource: app.GetMaxAllocatedResource().DAOString(), + Partition: common.GetPartitionNameWithoutClusterID(app.Partition), + QueueName: app.QueuePath, + SubmissionTime: app.SubmissionTime.UnixNano(), + FinishedTime: common.ZeroTimeInUnixNano(app.FinishedTime()), + Allocations: allocationInfo, + State: app.CurrentState(), + User: app.GetUser().User, + RejectedMessage: app.GetRejectedMessage(), PlaceholderData: placeholderInfo, } }