manirajv06 commented on code in PR #574:
URL: https://github.com/apache/yunikorn-core/pull/574#discussion_r1257834550


##########
pkg/scheduler/objects/queue_events.go:
##########
@@ -0,0 +1,127 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package objects
+
+import (
+       "github.com/apache/yunikorn-core/pkg/common"
+       "github.com/apache/yunikorn-core/pkg/events"
+       "github.com/apache/yunikorn-scheduler-interface/lib/go/si"
+)
+
+type queueEvents struct {
+       enabled     bool
+       eventSystem events.EventSystem
+       queue       *Queue
+}
+
+func (q *queueEvents) sendNewQueueEvent() {
+       if !q.enabled {
+               return
+       }

Review Comment:
   Do we really need `q.enabled` ? Instead, Can we use `eventSystem != nil` ?



##########
pkg/scheduler/objects/queue_events.go:
##########
@@ -0,0 +1,127 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package objects
+
+import (
+       "github.com/apache/yunikorn-core/pkg/common"
+       "github.com/apache/yunikorn-core/pkg/events"
+       "github.com/apache/yunikorn-scheduler-interface/lib/go/si"
+)
+
+type queueEvents struct {
+       enabled     bool
+       eventSystem events.EventSystem
+       queue       *Queue
+}
+
+func (q *queueEvents) sendNewQueueEvent() {
+       if !q.enabled {
+               return
+       }
+
+       var detail si.EventRecord_ChangeDetail
+       if q.queue.IsManaged() {
+               detail = si.EventRecord_DETAILS_NONE
+       } else {
+               detail = si.EventRecord_QUEUE_DYNAMIC
+       }

Review Comment:
   detail could be assigned with most frequently used value by default and 
change it only when necessary.



##########
pkg/scheduler/partition.go:
##########
@@ -196,6 +196,7 @@ func (pc *PartitionContext) addQueue(conf 
[]configs.QueueConfig, parent *objects
                if err != nil {
                        return err
                }
+               thisQueue.SendNewQueueEvent()

Review Comment:
   I am not really sure about triggering new queue event from this place as 
there are some other places where this needs to be triggered. Instead of doing 
this in 'n' number of places, I think it is better to trigger this even after 
queue creation in corresponding constructors in `Queue` itself. For example, 
NewConfiguredQueue and NewDynamicQueue



##########
pkg/scheduler/objects/queue_events.go:
##########
@@ -0,0 +1,127 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+package objects
+
+import (
+       "github.com/apache/yunikorn-core/pkg/common"
+       "github.com/apache/yunikorn-core/pkg/events"
+       "github.com/apache/yunikorn-scheduler-interface/lib/go/si"
+)
+
+type queueEvents struct {
+       enabled     bool
+       eventSystem events.EventSystem
+       queue       *Queue
+}
+
+func (q *queueEvents) sendNewQueueEvent() {
+       if !q.enabled {
+               return
+       }
+
+       var detail si.EventRecord_ChangeDetail
+       if q.queue.IsManaged() {
+               detail = si.EventRecord_DETAILS_NONE
+       } else {
+               detail = si.EventRecord_QUEUE_DYNAMIC
+       }
+       event := events.CreateQueueEventRecord(q.queue.QueuePath, common.Empty, 
common.Empty, si.EventRecord_ADD,
+               detail, nil)
+       q.eventSystem.AddEvent(event)
+}
+
+func (q *queueEvents) sendNewApplicationEvent(appID string) {
+       if !q.enabled {
+               return
+       }
+
+       event := events.CreateQueueEventRecord(q.queue.QueuePath, common.Empty, 
appID, si.EventRecord_ADD,
+               si.EventRecord_QUEUE_APP, nil)
+       q.eventSystem.AddEvent(event)
+}
+
+func (q *queueEvents) sendRemoveQueueEvent() {
+       if !q.enabled {
+               return
+       }
+
+       var detail si.EventRecord_ChangeDetail
+       if q.queue.IsManaged() {
+               detail = si.EventRecord_DETAILS_NONE
+       } else {
+               detail = si.EventRecord_QUEUE_DYNAMIC
+       }
+       event := events.CreateQueueEventRecord(q.queue.QueuePath, common.Empty, 
common.Empty, si.EventRecord_REMOVE,
+               detail, nil)
+       q.eventSystem.AddEvent(event)
+}
+
+func (q *queueEvents) sendRemoveApplicationEvent(appID string) {
+       if !q.enabled {
+               return
+       }
+
+       event := events.CreateQueueEventRecord(q.queue.QueuePath, common.Empty, 
appID, si.EventRecord_REMOVE,
+               si.EventRecord_QUEUE_APP, nil)
+       q.eventSystem.AddEvent(event)
+}
+func (q *queueEvents) sendMaxResourceChangedEvent() {
+       if !q.enabled {
+               return
+       }
+
+       event := events.CreateQueueEventRecord(q.queue.QueuePath, common.Empty, 
common.Empty, si.EventRecord_SET,
+               si.EventRecord_QUEUE_MAX, q.queue.maxResource)
+       q.eventSystem.AddEvent(event)
+}
+
+func (q *queueEvents) sendGuaranteedResourceChangedEvent() {
+       if !q.enabled {
+               return
+       }
+
+       event := events.CreateQueueEventRecord(q.queue.QueuePath, common.Empty, 
common.Empty, si.EventRecord_SET,
+               si.EventRecord_QUEUE_GUARANTEED, q.queue.guaranteedResource)
+       q.eventSystem.AddEvent(event)
+}
+
+func (q *queueEvents) sendTypeChangedEvent() {
+       if !q.enabled {
+               return
+       }
+
+       var message string
+       if q.queue.isLeaf {
+               message = "leaf queue: true"
+       } else {
+               message = "leaf queue: false"
+       }

Review Comment:
   same like before



##########
pkg/scheduler/objects/queue.go:
##########
@@ -296,12 +302,18 @@ func (sq *Queue) applyConf(conf configs.QueueConfig) 
error {
                sq.isManaged = true
        }
 
+       prevLeaf := sq.isLeaf
        sq.isLeaf = !conf.Parent
        // Make sure the parent flag is set correctly: config might expect auto 
parent type creation
        if len(conf.Queues) > 0 {
                sq.isLeaf = false
        }
 
+       if prevLeaf != sq.isLeaf && sq.initialized {

Review Comment:
   Do we really need `sq.initialized`? Instead, Can we use `sq.queueEvents != 
nil` or something like that? 



-- 
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]

Reply via email to