Skip to content

Commit

Permalink
Moved Set definition to common package
Browse files Browse the repository at this point in the history
Signed-off-by: Utkarsh Bhatt <[email protected]>
  • Loading branch information
UtkarshBhatthere committed Oct 19, 2023
1 parent 8990a9f commit e0329d0
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 39 deletions.
4 changes: 2 additions & 2 deletions microceph/ceph/client_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions microceph/ceph/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{},
Expand Down
41 changes: 6 additions & 35 deletions microceph/ceph/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
30 changes: 30 additions & 0 deletions microceph/common/set.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit e0329d0

Please sign in to comment.