X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=internal%2Fsdlgoredis%2Fdbstate.go;h=6bbe40f912cd8550a4ebc9964f7f26a3e43964df;hb=refs%2Fchanges%2F50%2F9150%2F1;hp=543f22e9b8eb19f9475dc23a15d31ebea8457ba6;hpb=977a55ca96d5dba1c7f9273671747eaf9cd6f894;p=ric-plt%2Fsdlgo.git diff --git a/internal/sdlgoredis/dbstate.go b/internal/sdlgoredis/dbstate.go index 543f22e..6bbe40f 100644 --- a/internal/sdlgoredis/dbstate.go +++ b/internal/sdlgoredis/dbstate.go @@ -29,48 +29,75 @@ 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 + Err error + ConfigNodeCnt int + + PrimaryDbState PrimaryDbState + ReplicasDbState *ReplicasDbState + SentinelsDbState *SentinelsDbState } -//MasterDbState struct is a holder for master Redis state information. -type MasterDbState struct { +//PrimaryDbState struct is a holder for primary Redis state information. +type PrimaryDbState struct { Err error - Fields MasterDbStateFields + Fields PrimaryDbStateFields } -//ReplicasDbState struct is a holder for Redis slaves state information. +//ReplicasDbState struct is a holder for Redis replicas state information. type ReplicasDbState struct { Err error States []*ReplicaDbState } -//ReplicaDbState struct is a holder for one Redis slave state information. +//ReplicaDbState struct is a holder for one Redis replica state information. type ReplicaDbState struct { Fields ReplicaDbStateFields } -//MasterDbStateFields struct is a holder for master Redis state information +//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 +} + +//PrimaryDbStateFields struct is a holder for primary Redis state information //fields which are read from sdlgoredis sentinel 'Master' call output. -type MasterDbStateFields struct { +type PrimaryDbStateFields struct { Role string Ip string Port string Flags string } -//ReplicaDbStateFields struct is a holder for slave Redis state information +//ReplicaDbStateFields struct is a holder for replica Redis state information //fields which are read from sdlgoredis sentinel 'Slaves' call output. type ReplicaDbStateFields struct { - Role string - Ip string - Port string - MasterLinkStatus string - Flags string + Role string + Ip string + Port string + PrimaryLinkStatus string + 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 { + if err := dbst.Err; err != nil { + return err + } + + if err := dbst.PrimaryDbState.IsOnline(); err != nil { return err } if dbst.ReplicasDbState != nil { @@ -78,25 +105,30 @@ func (dbst *DbState) IsOnline() error { return err } } + if dbst.SentinelsDbState != nil { + if err := dbst.SentinelsDbState.IsOnline(); err != nil { + return err + } + } return nil } -func (mdbst *MasterDbState) IsOnline() error { - if mdbst.Err != nil { - return mdbst.Err +func (pdbst *PrimaryDbState) IsOnline() error { + if pdbst.Err != nil { + return pdbst.Err } - if mdbst.Fields.Role != "master" { - return fmt.Errorf("No master DB, current role '%s'", mdbst.Fields.Role) + if pdbst.Fields.Role != "master" { + return fmt.Errorf("No primary DB, current role '%s'", pdbst.Fields.Role) } - if mdbst.Fields.Flags != "master" { - return fmt.Errorf("Master flags are '%s', expected 'master'", mdbst.Fields.Flags) + if pdbst.Fields.Flags != "master" { + return fmt.Errorf("Primary flags are '%s', expected 'master'", pdbst.Fields.Flags) } return nil } -func (mdbst *MasterDbState) GetAddress() string { - if mdbst.Fields.Ip != "" || mdbst.Fields.Port != "" { - return mdbst.Fields.Ip + ":" + mdbst.Fields.Port +func (pdbst *PrimaryDbState) GetAddress() string { + if pdbst.Fields.Ip != "" || pdbst.Fields.Port != "" { + return pdbst.Fields.Ip + ":" + pdbst.Fields.Port } else { return "" } @@ -119,8 +151,8 @@ func (rdbst *ReplicaDbState) IsOnline() error { return fmt.Errorf("Replica role is '%s', expected 'slave'", rdbst.Fields.Role) } - if rdbst.Fields.MasterLinkStatus != "ok" { - return fmt.Errorf("Replica link to the master is down") + if rdbst.Fields.PrimaryLinkStatus != "ok" { + return fmt.Errorf("Replica link to the primary is down") } if rdbst.Fields.Flags != "slave" { @@ -136,3 +168,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 "" + } +}