X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=internal%2Fsdlgoredis%2Fdbstate.go;h=61b6fdc02711d234b907e3834dae1d4a320e094e;hb=7c256b622c8fd065e91a7e289937d6e692a7eb1d;hp=543f22e9b8eb19f9475dc23a15d31ebea8457ba6;hpb=977a55ca96d5dba1c7f9273671747eaf9cd6f894;p=ric-plt%2Fsdlgo.git diff --git a/internal/sdlgoredis/dbstate.go b/internal/sdlgoredis/dbstate.go index 543f22e..61b6fdc 100644 --- a/internal/sdlgoredis/dbstate.go +++ b/internal/sdlgoredis/dbstate.go @@ -29,8 +29,9 @@ import ( //DbState struct is a holder for DB state information, which is received from //sdlgoredis sentinel 'Master' and 'Slaves' calls output. type DbState struct { - MasterDbState MasterDbState - ReplicasDbState *ReplicasDbState + MasterDbState MasterDbState + ReplicasDbState *ReplicasDbState + SentinelsDbState *SentinelsDbState } //MasterDbState struct is a holder for master Redis state information. @@ -50,6 +51,17 @@ type ReplicaDbState struct { Fields ReplicaDbStateFields } +//SentinelsDbState struct is a holder for Redis sentinels state information. +type SentinelsDbState struct { + Err error + States []*SentinelDbState +} + +//SentinelDbState struct is a holder for one Redis sentinel state information. +type SentinelDbState struct { + Fields SentinelDbStateFields +} + //MasterDbStateFields struct is a holder for master Redis state information //fields which are read from sdlgoredis sentinel 'Master' call output. type MasterDbStateFields struct { @@ -69,6 +81,14 @@ type ReplicaDbStateFields struct { Flags string } +//SentinelDbStateFields struct is a holder for sentinel Redis state information +//fields which are read from sdlgoredis sentinel 'Sentinels' call output. +type SentinelDbStateFields struct { + Ip string + Port string + Flags string +} + func (dbst *DbState) IsOnline() error { if err := dbst.MasterDbState.IsOnline(); err != nil { return err @@ -78,6 +98,11 @@ func (dbst *DbState) IsOnline() error { return err } } + if dbst.SentinelsDbState != nil { + if err := dbst.SentinelsDbState.IsOnline(); err != nil { + return err + } + } return nil } @@ -136,3 +161,30 @@ func (rdbst *ReplicaDbState) GetAddress() string { return "" } } + +func (sdbst *SentinelsDbState) IsOnline() error { + if sdbst.Err != nil { + return sdbst.Err + } + for _, state := range sdbst.States { + if err := state.IsOnline(); err != nil { + return err + } + } + return nil +} + +func (sdbst *SentinelDbState) IsOnline() error { + if sdbst.Fields.Flags != "sentinel" { + return fmt.Errorf("Sentinel flags are '%s', expected 'sentinel'", sdbst.Fields.Flags) + } + return nil +} + +func (sdbst *SentinelDbState) GetAddress() string { + if sdbst.Fields.Ip != "" || sdbst.Fields.Port != "" { + return sdbst.Fields.Ip + ":" + sdbst.Fields.Port + } else { + return "" + } +}