This is an automated email from the ASF dual-hosted git repository.

pbacsko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/yunikorn-core.git


The following commit(s) were added to refs/heads/master by this push:
     new d8200b26 [YUNIKORN-1807] Remove error check from createEventRecord() 
(#564)
d8200b26 is described below

commit d8200b26474b042dad99239c707e488be31ee6e9
Author: Peter Bacsko <[email protected]>
AuthorDate: Tue Jun 13 10:57:12 2023 +0200

    [YUNIKORN-1807] Remove error check from createEventRecord() (#564)
    
    Closes: #564
    
    Signed-off-by: Peter Bacsko <[email protected]>
---
 pkg/events/events.go                 | 20 ++++++--------------
 pkg/events/events_test.go            | 27 +++++----------------------
 pkg/scheduler/objects/events.go      | 21 ++++-----------------
 pkg/scheduler/objects/events_test.go | 20 --------------------
 4 files changed, 15 insertions(+), 73 deletions(-)

diff --git a/pkg/events/events.go b/pkg/events/events.go
index 272479f4..59fce611 100644
--- a/pkg/events/events.go
+++ b/pkg/events/events.go
@@ -19,20 +19,12 @@
 package events
 
 import (
-       "fmt"
        "time"
 
        "github.com/apache/yunikorn-scheduler-interface/lib/go/si"
 )
 
-func createEventRecord(recordType si.EventRecord_Type, objectID, groupID, 
reason, message string) (*si.EventRecord, error) {
-       if objectID == "" {
-               return nil, fmt.Errorf("objectID should not be nil")
-       }
-       if reason == "" {
-               return nil, fmt.Errorf("reason should not be nil")
-       }
-
+func createEventRecord(recordType si.EventRecord_Type, objectID, groupID, 
reason, message string) *si.EventRecord {
        return &si.EventRecord{
                Type:          recordType,
                ObjectID:      objectID,
@@ -40,21 +32,21 @@ func createEventRecord(recordType si.EventRecord_Type, 
objectID, groupID, reason
                Reason:        reason,
                Message:       message,
                TimestampNano: time.Now().UnixNano(),
-       }, nil
+       }
 }
 
-func CreateRequestEventRecord(objectID, groupID, reason, message string) 
(*si.EventRecord, error) {
+func CreateRequestEventRecord(objectID, groupID, reason, message string) 
*si.EventRecord {
        return createEventRecord(si.EventRecord_REQUEST, objectID, groupID, 
reason, message)
 }
 
-func CreateAppEventRecord(objectID, reason, message string) (*si.EventRecord, 
error) {
+func CreateAppEventRecord(objectID, reason, message string) *si.EventRecord {
        return createEventRecord(si.EventRecord_APP, objectID, "", reason, 
message)
 }
 
-func CreateNodeEventRecord(objectID, reason, message string) (*si.EventRecord, 
error) {
+func CreateNodeEventRecord(objectID, reason, message string) *si.EventRecord {
        return createEventRecord(si.EventRecord_NODE, objectID, "", reason, 
message)
 }
 
-func CreateQueueEventRecord(objectID, groupID, reason, message string) 
(*si.EventRecord, error) {
+func CreateQueueEventRecord(objectID, groupID, reason, message string) 
*si.EventRecord {
        return createEventRecord(si.EventRecord_QUEUE, objectID, groupID, 
reason, message)
 }
diff --git a/pkg/events/events_test.go b/pkg/events/events_test.go
index c3f68c41..3475d09c 100644
--- a/pkg/events/events_test.go
+++ b/pkg/events/events_test.go
@@ -27,8 +27,7 @@ import (
 )
 
 func TestCreateEventRecord(t *testing.T) {
-       record, err := createEventRecord(si.EventRecord_NODE, "ask", "app", 
"reason", "message")
-       assert.NilError(t, err, "the error should be nil")
+       record := createEventRecord(si.EventRecord_NODE, "ask", "app", 
"reason", "message")
        assert.Equal(t, record.Type, si.EventRecord_NODE)
        assert.Equal(t, record.ObjectID, "ask")
        assert.Equal(t, record.GroupID, "app")
@@ -40,31 +39,15 @@ func TestCreateEventRecord(t *testing.T) {
 }
 
 func TestCreateEventRecordTypes(t *testing.T) {
-       record, err := CreateRequestEventRecord("ask", "app", "reason", 
"message")
-       assert.NilError(t, err, "the error should be nil")
+       record := CreateRequestEventRecord("ask", "app", "reason", "message")
        assert.Equal(t, record.Type, si.EventRecord_REQUEST)
 
-       record, err = CreateAppEventRecord("ask", "app", "message")
-       assert.NilError(t, err, "the error should be nil")
+       record = CreateAppEventRecord("ask", "app", "message")
        assert.Equal(t, record.Type, si.EventRecord_APP)
 
-       record, err = CreateNodeEventRecord("ask", "app", "message")
-       assert.NilError(t, err, "the error should be nil")
+       record = CreateNodeEventRecord("ask", "app", "message")
        assert.Equal(t, record.Type, si.EventRecord_NODE)
 
-       record, err = CreateQueueEventRecord("ask", "app", "reason", "message")
-       assert.NilError(t, err, "the error should be nil")
+       record = CreateQueueEventRecord("ask", "app", "reason", "message")
        assert.Equal(t, record.Type, si.EventRecord_QUEUE)
 }
-
-func TestEmptyFields(t *testing.T) {
-       record, err := createEventRecord(si.EventRecord_QUEUE, "obj", "group", 
"reason", "message")
-       assert.NilError(t, err)
-       assert.Assert(t, record != nil, "the EventRecord should be created with 
a non-empty objectID")
-
-       _, err = createEventRecord(si.EventRecord_QUEUE, "", "group", "reason", 
"message")
-       assert.Assert(t, err != nil, "the EventRecord should not be created 
with empty objectID")
-
-       _, err = createEventRecord(si.EventRecord_QUEUE, "obj", "group", "", 
"message")
-       assert.Assert(t, err != nil, "the EventRecord should not be created 
with empty reason")
-}
diff --git a/pkg/scheduler/objects/events.go b/pkg/scheduler/objects/events.go
index 16226d9e..12ba3d01 100644
--- a/pkg/scheduler/objects/events.go
+++ b/pkg/scheduler/objects/events.go
@@ -21,10 +21,7 @@ package objects
 import (
        "fmt"
 
-       "go.uber.org/zap"
-
        "github.com/apache/yunikorn-core/pkg/events"
-       "github.com/apache/yunikorn-core/pkg/log"
 )
 
 type applicationEvents struct {
@@ -39,13 +36,8 @@ func (evt *applicationEvents) sendAppDoesNotFitEvent(request 
*AllocationAsk) {
        }
 
        message := fmt.Sprintf("Application %s does not fit into %s queue", 
request.GetApplicationID(), evt.app.queuePath)
-       if event, err := 
events.CreateRequestEventRecord(request.GetAllocationKey(), 
request.GetApplicationID(), "InsufficientQueueResources", message); err != nil {
-               log.Logger().Warn("Event creation failed",
-                       zap.String("event message", message),
-                       zap.Error(err))
-       } else {
-               evt.eventSystem.AddEvent(event)
-       }
+       event := events.CreateRequestEventRecord(request.GetAllocationKey(), 
request.GetApplicationID(), "InsufficientQueueResources", message)
+       evt.eventSystem.AddEvent(event)
 }
 
 func (evt *applicationEvents) sendPlaceholderLargerEvent(ph *Allocation, 
request *AllocationAsk) {
@@ -54,13 +46,8 @@ func (evt *applicationEvents) sendPlaceholderLargerEvent(ph 
*Allocation, request
        }
 
        message := fmt.Sprintf("Task group '%s' in application '%s': allocation 
resources '%s' are not matching placeholder '%s' allocation with ID '%s'", 
ph.GetTaskGroup(), evt.app.ApplicationID, 
request.GetAllocatedResource().String(), ph.GetAllocatedResource().String(), 
ph.GetAllocationKey())
-       if event, err := events.CreateRequestEventRecord(ph.GetAllocationKey(), 
evt.app.ApplicationID, "releasing placeholder: real allocation is larger than 
placeholder", message); err != nil {
-               log.Logger().Warn("Event creation failed",
-                       zap.String("event message", message),
-                       zap.Error(err))
-       } else {
-               evt.eventSystem.AddEvent(event)
-       }
+       event := events.CreateRequestEventRecord(ph.GetAllocationKey(), 
evt.app.ApplicationID, "releasing placeholder: real allocation is larger than 
placeholder", message)
+       evt.eventSystem.AddEvent(event)
 }
 
 func newApplicationEvents(app *Application, evt events.EventSystem) 
*applicationEvents {
diff --git a/pkg/scheduler/objects/events_test.go 
b/pkg/scheduler/objects/events_test.go
index 688c1666..84ae5364 100644
--- a/pkg/scheduler/objects/events_test.go
+++ b/pkg/scheduler/objects/events_test.go
@@ -59,16 +59,6 @@ func TestSendAppDoesNotFitEvent(t *testing.T) {
                allocationKey: aKey,
        })
        assert.Equal(t, 1, len(mock.events), "event was not generated")
-
-       // enabled, ObjectID missing
-       mock = newEventSystemMock()
-       evt = newApplicationEvents(app, mock)
-       assert.Assert(t, evt.eventSystem != nil, "event system should not be 
nil")
-       assert.Assert(t, evt.enabled, "event system should be enabled")
-       evt.sendAppDoesNotFitEvent(&AllocationAsk{
-               applicationID: appID0,
-       })
-       assert.Equal(t, 0, len(mock.events), "event was generated")
 }
 
 func TestSendPlaceholderLargerEvent(t *testing.T) {
@@ -94,16 +84,6 @@ func TestSendPlaceholderLargerEvent(t *testing.T) {
                allocationKey: aKey,
        })
        assert.Equal(t, 1, len(mock.events), "event was not generated")
-
-       // enabled, ObjectID missing
-       mock = newEventSystemMock()
-       evt = newApplicationEvents(app, mock)
-       assert.Assert(t, evt.eventSystem != nil, "event system should not be 
nil")
-       assert.Assert(t, evt.enabled, "event system should be enabled")
-       evt.sendPlaceholderLargerEvent(&Allocation{}, &AllocationAsk{
-               applicationID: appID0,
-       })
-       assert.Equal(t, 0, len(mock.events), "event was generated")
 }
 
 func newEventSystemMock() *EventSystemMock {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to