Skip to content

Commit

Permalink
[YUNIKORN-2376] Remove dummy state dump plugin (apache#783)
Browse files Browse the repository at this point in the history
Do not register a dummy state dump plugin during init. Handle the fact
that a resource manager does not have to register a state dump plugin in
the state dump creation.

Closes: apache#783

Signed-off-by: Peter Bacsko <[email protected]>
  • Loading branch information
wilfred-s authored and pbacsko committed Feb 3, 2024
1 parent ec17e0b commit f025f07
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
19 changes: 7 additions & 12 deletions pkg/plugins/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,11 @@ import (
var plugins SchedulerPlugins

func init() {
plugins = SchedulerPlugins{
StateDumpPlugin: dummyStateDumpPlugin{},
}
}

type dummyStateDumpPlugin struct{}

var _ api.StateDumpPlugin = dummyStateDumpPlugin{}

func (d dummyStateDumpPlugin) GetStateDump() (string, error) {
return "{}", nil
plugins = SchedulerPlugins{}
}

// RegisterSchedulerPlugin registers the plugin based on the interfaces(s) it implements.
// The known interfaces are defined in yunikorn-scheduler-interface/lib/go/api
func RegisterSchedulerPlugin(plugin interface{}) {
plugins.Lock()
defer plugins.Unlock()
Expand All @@ -52,20 +44,23 @@ func RegisterSchedulerPlugin(plugin interface{}) {
}
}

// visible for testing
// UnregisterSchedulerPlugins removes all earlier set plugins
// visible for testing only
func UnregisterSchedulerPlugins() {
plugins.Lock()
defer plugins.Unlock()
plugins.ResourceManagerCallbackPlugin = nil
plugins.StateDumpPlugin = nil
}

// GetResourceManagerCallbackPlugin returns the registered callback plugin or nil if none was registered.
func GetResourceManagerCallbackPlugin() api.ResourceManagerCallback {
plugins.RLock()
defer plugins.RUnlock()
return plugins.ResourceManagerCallbackPlugin
}

// GetStateDumpPlugin returns the registered state dump plugin or nil if none was registered.
func GetStateDumpPlugin() api.StateDumpPlugin {
plugins.RLock()
defer plugins.RUnlock()
Expand Down
7 changes: 6 additions & 1 deletion pkg/webservice/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -947,9 +947,14 @@ func getRMBuildInformation(lists map[string]*scheduler.RMInformation) []map[stri
}

func getResourceManagerDiagnostics() map[string]interface{} {
result := make(map[string]interface{}, 0)
result := make(map[string]interface{})

// if the RM has not registered state dump the plugin will be nil
plugin := plugins.GetStateDumpPlugin()
if plugin == nil {
result["empty"] = "Resource Manager did not register callback"
return result
}

// get state dump from RM
dumpStr, err := plugin.GetStateDump()
Expand Down

0 comments on commit f025f07

Please sign in to comment.