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
36 //MasterDbState struct is a holder for master Redis state information.
37 type MasterDbState struct {
39 Fields MasterDbStateFields
42 //ReplicasDbState struct is a holder for Redis slaves state information.
43 type ReplicasDbState struct {
45 States []*ReplicaDbState
48 //ReplicaDbState struct is a holder for one Redis slave state information.
49 type ReplicaDbState struct {
50 Fields ReplicaDbStateFields
53 //MasterDbStateFields struct is a holder for master Redis state information
54 //fields which are read from sdlgoredis sentinel 'Master' call output.
55 type MasterDbStateFields struct {
62 //ReplicaDbStateFields struct is a holder for slave Redis state information
63 //fields which are read from sdlgoredis sentinel 'Slaves' call output.
64 type ReplicaDbStateFields struct {
68 MasterLinkStatus string
72 func (dbst *DbState) IsOnline() error {
73 if err := dbst.MasterDbState.IsOnline(); err != nil {
76 if dbst.ReplicasDbState != nil {
77 if err := dbst.ReplicasDbState.IsOnline(); err != nil {
84 func (mdbst *MasterDbState) IsOnline() error {
88 if mdbst.Fields.Role != "master" {
89 return fmt.Errorf("No master DB, current role '%s'", mdbst.Fields.Role)
91 if mdbst.Fields.Flags != "master" {
92 return fmt.Errorf("Master flags are '%s', expected 'master'", mdbst.Fields.Flags)
97 func (mdbst *MasterDbState) GetAddress() string {
98 if mdbst.Fields.Ip != "" || mdbst.Fields.Port != "" {
99 return mdbst.Fields.Ip + ":" + mdbst.Fields.Port
105 func (rdbst *ReplicasDbState) IsOnline() error {
106 if rdbst.Err != nil {
109 for _, state := range rdbst.States {
110 if err := state.IsOnline(); err != nil {
117 func (rdbst *ReplicaDbState) IsOnline() error {
118 if rdbst.Fields.Role != "slave" {
119 return fmt.Errorf("Replica role is '%s', expected 'slave'", rdbst.Fields.Role)
122 if rdbst.Fields.MasterLinkStatus != "ok" {
123 return fmt.Errorf("Replica link to the master is down")
126 if rdbst.Fields.Flags != "slave" {
127 return fmt.Errorf("Replica flags are '%s', expected 'slave'", rdbst.Fields.Flags)
132 func (rdbst *ReplicaDbState) GetAddress() string {
133 if rdbst.Fields.Ip != "" || rdbst.Fields.Port != "" {
134 return rdbst.Fields.Ip + ":" + rdbst.Fields.Port