2 Copyright (c) 2021 AT&T Intellectual Property.
3 Copyright (c) 2018-2021 Nokia.
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-2.0
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
19 * This source code is part of the near-RT RIC (RAN Intelligent Controller)
20 * platform project (RICP).
29 //DbState struct is a holder for DB state information, which is received from
30 //sdlgoredis sentinel 'Master' and 'Slaves' calls output.
32 MasterDbState MasterDbState
33 ReplicasDbState *ReplicasDbState
34 SentinelsDbState *SentinelsDbState
37 //MasterDbState struct is a holder for master Redis state information.
38 type MasterDbState struct {
40 Fields MasterDbStateFields
43 //ReplicasDbState struct is a holder for Redis slaves state information.
44 type ReplicasDbState struct {
46 States []*ReplicaDbState
49 //ReplicaDbState struct is a holder for one Redis slave state information.
50 type ReplicaDbState struct {
51 Fields ReplicaDbStateFields
54 //SentinelsDbState struct is a holder for Redis sentinels state information.
55 type SentinelsDbState struct {
57 States []*SentinelDbState
60 //SentinelDbState struct is a holder for one Redis sentinel state information.
61 type SentinelDbState struct {
62 Fields SentinelDbStateFields
65 //MasterDbStateFields struct is a holder for master Redis state information
66 //fields which are read from sdlgoredis sentinel 'Master' call output.
67 type MasterDbStateFields struct {
74 //ReplicaDbStateFields struct is a holder for slave Redis state information
75 //fields which are read from sdlgoredis sentinel 'Slaves' call output.
76 type ReplicaDbStateFields struct {
80 MasterLinkStatus string
84 //SentinelDbStateFields struct is a holder for sentinel Redis state information
85 //fields which are read from sdlgoredis sentinel 'Sentinels' call output.
86 type SentinelDbStateFields struct {
92 func (dbst *DbState) IsOnline() error {
93 if err := dbst.MasterDbState.IsOnline(); err != nil {
96 if dbst.ReplicasDbState != nil {
97 if err := dbst.ReplicasDbState.IsOnline(); err != nil {
101 if dbst.SentinelsDbState != nil {
102 if err := dbst.SentinelsDbState.IsOnline(); err != nil {
109 func (mdbst *MasterDbState) IsOnline() error {
110 if mdbst.Err != nil {
113 if mdbst.Fields.Role != "master" {
114 return fmt.Errorf("No master DB, current role '%s'", mdbst.Fields.Role)
116 if mdbst.Fields.Flags != "master" {
117 return fmt.Errorf("Master flags are '%s', expected 'master'", mdbst.Fields.Flags)
122 func (mdbst *MasterDbState) GetAddress() string {
123 if mdbst.Fields.Ip != "" || mdbst.Fields.Port != "" {
124 return mdbst.Fields.Ip + ":" + mdbst.Fields.Port
130 func (rdbst *ReplicasDbState) IsOnline() error {
131 if rdbst.Err != nil {
134 for _, state := range rdbst.States {
135 if err := state.IsOnline(); err != nil {
142 func (rdbst *ReplicaDbState) IsOnline() error {
143 if rdbst.Fields.Role != "slave" {
144 return fmt.Errorf("Replica role is '%s', expected 'slave'", rdbst.Fields.Role)
147 if rdbst.Fields.MasterLinkStatus != "ok" {
148 return fmt.Errorf("Replica link to the master is down")
151 if rdbst.Fields.Flags != "slave" {
152 return fmt.Errorf("Replica flags are '%s', expected 'slave'", rdbst.Fields.Flags)
157 func (rdbst *ReplicaDbState) GetAddress() string {
158 if rdbst.Fields.Ip != "" || rdbst.Fields.Port != "" {
159 return rdbst.Fields.Ip + ":" + rdbst.Fields.Port
165 func (sdbst *SentinelsDbState) IsOnline() error {
166 if sdbst.Err != nil {
169 for _, state := range sdbst.States {
170 if err := state.IsOnline(); err != nil {
177 func (sdbst *SentinelDbState) IsOnline() error {
178 if sdbst.Fields.Flags != "sentinel" {
179 return fmt.Errorf("Sentinel flags are '%s', expected 'sentinel'", sdbst.Fields.Flags)
184 func (sdbst *SentinelDbState) GetAddress() string {
185 if sdbst.Fields.Ip != "" || sdbst.Fields.Port != "" {
186 return sdbst.Fields.Ip + ":" + sdbst.Fields.Port