pbacsko commented on code in PR #927:
URL: https://github.com/apache/yunikorn-core/pull/927#discussion_r1713998142
##########
pkg/scheduler/objects/application.go:
##########
@@ -2157,6 +2158,23 @@ func (sa *Application) GetMaxResource()
*resources.Resource {
return sa.getResourceFromTags(siCommon.AppTagNamespaceResourceQuota)
}
+// GetMaxApps returns the max apps that is set in the application tags
+func (sa *Application) GetMaxApps() uint64 {
+ return sa.GetUint64Tag(siCommon.AppTagNamespaceResourceMaxApps)
+}
+
+func (sa *Application) GetUint64Tag(tag string) uint64 {
Review Comment:
Nit: we don't need to export this.
##########
pkg/scheduler/partition.go:
##########
@@ -342,13 +342,19 @@ func (pc *PartitionContext) AddApplication(app
*objects.Application) error {
guaranteedRes := app.GetGuaranteedResource()
maxRes := app.GetMaxResource()
- if !isRecoveryQueue && (guaranteedRes != nil || maxRes != nil) {
+ maxApps := app.GetMaxApps()
+ if !isRecoveryQueue && (guaranteedRes != nil || maxRes != nil ||
maxApps != 0) {
// set resources based on tags, but only if the queue is
dynamic (unmanaged)
if queue.IsManaged() {
log.Log(log.SchedQueue).Warn("Trying to set resources
on a queue that is not an unmanaged leaf",
zap.String("queueName", queue.QueuePath))
} else {
- queue.SetResources(guaranteedRes, maxRes)
+ if maxApps != 0 {
+ queue.SetMaxRunningApps(maxApps)
Review Comment:
Could you cover this branch?
We have two existing test cases: `TestAddTGApplication` and
`TestAddTGAppDynamic`.
##########
pkg/scheduler/objects/application_test.go:
##########
@@ -108,46 +108,121 @@ func TestNewApplication(t *testing.T) {
assert.Assert(t, app.IsNew(), "new application must be in new state")
assert.Equal(t, app.execTimeout, defaultPlaceholderTimeout, "no timeout
passed in should be modified default")
assert.Assert(t, resources.Equals(app.placeholderAsk, res),
"placeholder ask not set as expected")
+}
+func TestNewApplicationWithAnnotaionUpdate(t *testing.T) {
Review Comment:
typo: "annotaion"
##########
pkg/scheduler/objects/application_test.go:
##########
@@ -108,46 +108,121 @@ func TestNewApplication(t *testing.T) {
assert.Assert(t, app.IsNew(), "new application must be in new state")
assert.Equal(t, app.execTimeout, defaultPlaceholderTimeout, "no timeout
passed in should be modified default")
assert.Assert(t, resources.Equals(app.placeholderAsk, res),
"placeholder ask not set as expected")
+}
+func TestNewApplicationWithAnnotaionUpdate(t *testing.T) {
+ user := security.UserGroup{
+ User: "testuser",
+ Groups: []string{},
+ }
// valid tags
- siApp = &si.AddApplicationRequest{}
+ siApp := &si.AddApplicationRequest{}
siApp.Tags = map[string]string{
siCommon.AppTagNamespaceResourceQuota:
"{\"resources\":{\"validMaxRes\":{\"value\":11}}}",
siCommon.AppTagNamespaceResourceGuaranteed:
"{\"resources\":{\"validGuaranteed\":{\"value\":22}}}",
+ siCommon.AppTagNamespaceResourceMaxApps: "33",
}
- app = NewApplication(siApp, user, nil, "")
+
+ app := NewApplication(siApp, user, nil, "")
+
guaranteed := app.GetGuaranteedResource()
maxResource := app.GetMaxResource()
+ maxApps := app.GetMaxApps()
assert.Assert(t, guaranteed != nil, "guaranteed resource has not been
set")
assert.Equal(t, 1, len(guaranteed.Resources), "more than one resource
has been set")
assert.Equal(t, resources.Quantity(22),
guaranteed.Resources["validGuaranteed"])
assert.Assert(t, maxResource != nil, "maximum resource has not been
set")
assert.Equal(t, 1, len(maxResource.Resources), "more than one resource
has been set")
assert.Equal(t, resources.Quantity(11),
maxResource.Resources["validMaxRes"], "maximum resource is incorrect")
+ assert.Assert(t, maxApps != 0, "maximum apps has not been set or
incorrect")
+ assert.Equal(t, uint64(33), maxApps, "maximum apps is incorrect")
+
+ // valid tags without max apps
+ siApp = &si.AddApplicationRequest{}
+ siApp.Tags = map[string]string{
+ siCommon.AppTagNamespaceResourceQuota:
"{\"resources\":{\"validMaxRes\":{\"value\":11}}}",
+ siCommon.AppTagNamespaceResourceGuaranteed:
"{\"resources\":{\"validGuaranteed\":{\"value\":22}}}",
+ }
+ app = NewApplication(siApp, user, nil, "")
+ guaranteed = app.GetGuaranteedResource()
+ maxResource = app.GetMaxResource()
+ maxApps = app.GetMaxApps()
+ assert.Assert(t, guaranteed != nil, "guaranteed resource has not been
set")
+ assert.Equal(t, 1, len(guaranteed.Resources), "more than one resource
has been set")
+ assert.Equal(t, resources.Quantity(22),
guaranteed.Resources["validGuaranteed"])
+ assert.Assert(t, maxResource != nil, "maximum resource has not been
set")
+ assert.Equal(t, 1, len(maxResource.Resources), "more than one resource
has been set")
+ assert.Equal(t, resources.Quantity(11),
maxResource.Resources["validMaxRes"], "maximum resource is incorrect")
+ assert.Assert(t, maxApps == 0, "maximum apps should have not been set")
// invalid tags
siApp = &si.AddApplicationRequest{}
siApp.Tags = map[string]string{
siCommon.AppTagNamespaceResourceQuota: "{xxxxxx}",
siCommon.AppTagNamespaceResourceGuaranteed: "{yyyyy}",
+ siCommon.AppTagNamespaceResourceMaxApps: "zzzzz",
}
app = NewApplication(siApp, user, nil, "")
guaranteed = app.GetGuaranteedResource()
maxResource = app.GetMaxResource()
+ maxApps = app.GetMaxApps()
assert.Assert(t, guaranteed == nil, "guaranteed resource should have
not been set")
assert.Assert(t, maxResource == nil, "maximum resource should have not
been set")
+ assert.Assert(t, maxApps == 0, "maximum apps should have not been set
or incorrect")
// negative values
siApp = &si.AddApplicationRequest{}
siApp.Tags = map[string]string{
siCommon.AppTagNamespaceResourceQuota:
"{\"resources\":{\"negativeMax\":{\"value\":-11}}}",
siCommon.AppTagNamespaceResourceGuaranteed:
"{\"resources\":{\"negativeGuaranteed\":{\"value\":-22}}}",
+ siCommon.AppTagNamespaceResourceMaxApps: "-33",
}
app = NewApplication(siApp, user, nil, "")
guaranteed = app.GetGuaranteedResource()
maxResource = app.GetMaxResource()
+ maxApps = app.GetMaxApps()
assert.Assert(t, guaranteed == nil, "guaranteed resource should have
not been set")
assert.Assert(t, maxResource == nil, "maximum resource should have not
been set")
+ assert.Assert(t, maxApps == 0, "maximum apps should have not been set
or incorrect")
+
+ // test seperate max app cases to increase testing coverage
Review Comment:
nit: comment not needed
##########
pkg/scheduler/objects/queue_test.go:
##########
@@ -2594,3 +2594,19 @@ func TestQueue_allocatedResFits(t *testing.T) {
})
}
}
+
+func TestQueueSetMaxRunningApps(t *testing.T) {
+ queue := &Queue{}
+ maxApps := uint64(10)
+
+ queue.SetMaxRunningApps(maxApps)
+ assert.Equal(t, maxApps, queue.maxRunningApps)
+
+ queue = nil
+ queue.SetMaxRunningApps(maxApps)
+ defer func() {
Review Comment:
The defer section should come earlier, otherwise it will not catch the panic
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]