From 96cd730211aed085f1aaacde43e72552ca397aa7 Mon Sep 17 00:00:00 2001 From: Utkarsh Bhatt Date: Thu, 19 Oct 2023 16:19:02 +0530 Subject: [PATCH] Moved Set definition to common package Signed-off-by: Utkarsh Bhatt --- microceph/ceph/client_config.go | 4 ++-- microceph/ceph/config.go | 4 ++-- microceph/ceph/services.go | 41 +++++---------------------------- microceph/common/set.go | 30 ++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 39 deletions(-) create mode 100644 microceph/common/set.go diff --git a/microceph/ceph/client_config.go b/microceph/ceph/client_config.go index ccc14943..c4639209 100644 --- a/microceph/ceph/client_config.go +++ b/microceph/ceph/client_config.go @@ -51,8 +51,8 @@ func setFieldValue(ogp *ClientConfigT, field string, value string) error { } // GetClientConfigSet provides the mapping between client config key and fieldname for population through reflection. -func GetClientConfigSet() Set { - return Set{ +func GetClientConfigSet() common.Set { + return common.Set{ "rbd_cache": "IsCache", "rbd_cache_size": "CacheSize", "rbd_cache_writethrough_until_flush": "IsCacheWritethrough", diff --git a/microceph/ceph/config.go b/microceph/ceph/config.go index b64644f1..e8b03860 100644 --- a/microceph/ceph/config.go +++ b/microceph/ceph/config.go @@ -49,8 +49,8 @@ func GetConstConfigTable() ConfigTable { } } -func GetConfigTableServiceSet() Set { - return Set{ +func GetConfigTableServiceSet() common.Set { + return common.Set{ "mon": struct{}{}, "mgr": struct{}{}, "osd": struct{}{}, diff --git a/microceph/ceph/services.go b/microceph/ceph/services.go index 4cb09fc5..59c09c8f 100644 --- a/microceph/ceph/services.go +++ b/microceph/ceph/services.go @@ -20,37 +20,8 @@ import ( "github.com/tidwall/gjson" ) -type Set map[string]interface{} - -func (sub Set) Keys() []string { - keys := make([]string, len(sub)) - count := 0 - - for key := range sub { - keys[count] = key - count++ - } - - return keys -} - -func (sub Set) isIn(super Set) bool { - flag := true - - // mark flag false if any key from subset is not present in superset. - for key := range sub { - _, ok := super[key] - if !ok { - flag = false - break // Break the loop. - } - } - - return flag -} - // Table to map fetchFunc for workers (daemons) to a service. -var serviceWorkerTable = map[string](func() (Set, error)){ +var serviceWorkerTable = map[string](func() (common.Set, error)){ "osd": getUpOsds, "mon": getMons, } @@ -94,7 +65,7 @@ func RestartCephService(service string) error { } // All still not up - if !workers.isIn(iWorkers) { + if !workers.IsIn(iWorkers) { err := fmt.Errorf( "Attempt %d: Workers: %v not all present in %v", i, workers, iWorkers, ) @@ -110,8 +81,8 @@ func RestartCephService(service string) error { return nil } -func getMons() (Set, error) { - retval := Set{} +func getMons() (common.Set, error) { + retval := common.Set{} output, err := processExec.RunCommand("ceph", "mon", "dump", "-f", "json-pretty") if err != nil { logger.Errorf("Failed fetching Mon dump: %v", err) @@ -128,8 +99,8 @@ func getMons() (Set, error) { return retval, nil } -func getUpOsds() (Set, error) { - retval := Set{} +func getUpOsds() (common.Set, error) { + retval := common.Set{} output, err := processExec.RunCommand("ceph", "osd", "dump", "-f", "json-pretty") if err != nil { logger.Errorf("Failed fetching OSD dump: %v", err) diff --git a/microceph/common/set.go b/microceph/common/set.go new file mode 100644 index 00000000..c0818541 --- /dev/null +++ b/microceph/common/set.go @@ -0,0 +1,30 @@ +package common + +type Set map[string]interface{} + +func (s Set) Keys() []string { + keys := make([]string, len(s)) + count := 0 + + for key := range s { + keys[count] = key + count++ + } + + return keys +} + +func (s Set) IsIn(super Set) bool { + flag := true + + // mark flag false if any key from subset is not present in superset. + for key := range s { + _, ok := super[key] + if !ok { + flag = false + break // Break the loop. + } + } + + return flag +}