diff --git a/dbm-services/common/dbha/ha-module/agent/connection.go b/dbm-services/common/dbha/ha-module/agent/connection.go index dd1722e4cb..99978e5202 100644 --- a/dbm-services/common/dbha/ha-module/agent/connection.go +++ b/dbm-services/common/dbha/ha-module/agent/connection.go @@ -38,11 +38,11 @@ func (gm *GMConnection) Init() error { } // ReportInstance agent report instance detect info to gm -func (gm *GMConnection) ReportInstance(dbType string, jsonInfo []byte) error { +func (gm *GMConnection) ReportInstance(detectType string, jsonInfo []byte) error { var writeBuf string writeBuf += HEADER writeBuf += "\r\n" - writeBuf += dbType + writeBuf += detectType writeBuf += "\r\n" writeBuf += strconv.Itoa(len(jsonInfo)) writeBuf += "\r\n" diff --git a/dbm-services/common/dbha/ha-module/agent/monitor_agent.go b/dbm-services/common/dbha/ha-module/agent/monitor_agent.go index 74d1d12874..0d9b3046ff 100644 --- a/dbm-services/common/dbha/ha-module/agent/monitor_agent.go +++ b/dbm-services/common/dbha/ha-module/agent/monitor_agent.go @@ -24,7 +24,7 @@ type MonitorAgent struct { City string Campus string //detect dbType - DBType string + DetectType string // agent ip MonIp string LastFetchInsTime time.Time @@ -41,12 +41,12 @@ type MonitorAgent struct { } // NewMonitorAgent new a new agent do detect -func NewMonitorAgent(conf *config.Config, dbType string) (*MonitorAgent, error) { +func NewMonitorAgent(conf *config.Config, detectType string) (*MonitorAgent, error) { var err error agent := &MonitorAgent{ City: conf.AgentConf.City, Campus: conf.AgentConf.Campus, - DBType: dbType, + DetectType: detectType, LastFetchInsTime: time.Now(), LastFetchGMTime: time.Now(), GMInstance: map[string]*GMConnection{}, @@ -109,7 +109,7 @@ func (a *MonitorAgent) RefreshInstanceCache() { err := a.FetchDBInstance() if err != nil { log.Logger.Errorf("fetch %s instance failed. err:%s", - a.DBType, err.Error()) + a.DetectType, err.Error()) } a.flushInsFetchTime() } @@ -190,9 +190,9 @@ func (a *MonitorAgent) FetchDBInstance() error { log.Logger.Debugf("fetch db instance info len:%d", len(rawInfo)) // get callback function by db type - cb, ok := dbmodule.DBCallbackMap[types.DBType(a.DBType)] + cb, ok := dbmodule.DBCallbackMap[a.DetectType] if !ok { - err = fmt.Errorf("can't find fetch %s instance callback", a.DBType) + err = fmt.Errorf("can't find fetch %s instance callback", a.DetectType) log.Logger.Error(err.Error()) return err } @@ -380,7 +380,7 @@ func (a *MonitorAgent) registerAgentInfoToHaDB() error { "agent", a.City, a.Campus, - a.DBType) + a.DetectType) if err != nil { return err } @@ -391,7 +391,7 @@ func (a *MonitorAgent) registerAgentInfoToHaDB() error { // only detect the minimum port instance, other instances ignore. func (a *MonitorAgent) moduloHashSharding(allDbInstance []dbutil.DataBaseDetect) (map[string]dbutil.DataBaseDetect, error) { - mod, modValue, err := a.HaDBClient.AgentGetHashValue(a.MonIp, a.DBType, a.Conf.AgentConf.FetchInterval) + mod, modValue, err := a.HaDBClient.AgentGetHashValue(a.MonIp, a.DetectType, a.Conf.AgentConf.FetchInterval) if err != nil { log.Logger.Errorf("get Modulo failed and wait next refresh time. err:%s", err.Error()) return nil, err @@ -417,7 +417,7 @@ func (a *MonitorAgent) moduloHashSharding(allDbInstance []dbutil.DataBaseDetect) // reporterHeartbeat send heartbeat to hadb func (a *MonitorAgent) reporterHeartbeat() error { interval := time.Now().Sub(a.heartbeat).Seconds() - err := a.HaDBClient.ReporterAgentHeartbeat(a.DBType, int(interval), "N/A") + err := a.HaDBClient.ReporterAgentHeartbeat(a.DetectType, int(interval), "N/A") a.heartbeat = time.Now() return err } @@ -426,7 +426,7 @@ func (a *MonitorAgent) reporterHeartbeat() error { // only agent trigger double check(report GM) should call this func (a *MonitorAgent) reporterBindGM(gmInfo string) error { interval := time.Now().Sub(a.heartbeat).Seconds() - err := a.HaDBClient.ReporterAgentHeartbeat(a.DBType, int(interval), gmInfo) + err := a.HaDBClient.ReporterAgentHeartbeat(a.DetectType, int(interval), gmInfo) a.heartbeat = time.Now() return err } diff --git a/dbm-services/common/dbha/ha-module/client/hadb.go b/dbm-services/common/dbha/ha-module/client/hadb.go index 906a6cfda3..21a05bae45 100644 --- a/dbm-services/common/dbha/ha-module/client/hadb.go +++ b/dbm-services/common/dbha/ha-module/client/hadb.go @@ -452,7 +452,7 @@ func (c *HaDBClient) GetAliveGMInfo(interval int) ([]GMInfo, error) { } // ReporterAgentHeartbeat report agent heartbeat to ha_status table -func (c *HaDBClient) ReporterAgentHeartbeat(dbType string, interval int, gmInfo string) error { +func (c *HaDBClient) ReporterAgentHeartbeat(detectType string, interval int, gmInfo string) error { var result HaStatusResponse currentTime := time.Now() @@ -462,7 +462,7 @@ func (c *HaDBClient) ReporterAgentHeartbeat(dbType string, interval int, gmInfo Name: constvar.ReporterAgentHeartbeat, QueryArgs: &HaStatus{ IP: util.LocalIp, - DbType: dbType, + DbType: detectType, }, SetArgs: &HaStatus{ ReportInterval: interval, diff --git a/dbm-services/common/dbha/ha-module/client/name_service.go b/dbm-services/common/dbha/ha-module/client/name_service.go index 3a6db5c26c..46fa7ffa7e 100644 --- a/dbm-services/common/dbha/ha-module/client/name_service.go +++ b/dbm-services/common/dbha/ha-module/client/name_service.go @@ -133,34 +133,13 @@ func (c *NameServiceClient) DeleteDomain(domainName string, app string, ip strin // PolarisClbGWResp the response format for polaris and clb type PolarisClbGWResp struct { - Message string `json:"message"` - Status int `json:"status"` - Ips []string `json:"ips,omitempty"` -} - -// PolarisClbBodyParseCB the http body process callback for polaris and clb api -func PolarisClbBodyParseCB(b []byte) (interface{}, error) { - result := &PolarisClbGWResp{} - err := json.Unmarshal(b, result) - if err != nil { - log.Logger.Errorf("unmarshall %s to %+v get an error:%s", string(b), *result, err.Error()) - return nil, fmt.Errorf("json unmarshal failed, err: %+v", err) - } - - // check response and data is nil - if result.Status != statusSuccess { - log.Logger.Errorf("result.Code is %d not equal to %d,message:%s", - result.Status, statusSuccess, result.Message) - return nil, fmt.Errorf("%v - %v", result.Status, result.Message) - } - return result, nil + Ips []string `json:"ips,omitempty"` } // ClbDeRegister un-register address to clb -func (c *NameServiceClient) ClbDeRegister(region string, lbid string, listenid string, addr string) error { +func (c *NameServiceClient) ClbDeRegister( + region string, lbid string, listenid string, addr string) error { req := map[string]interface{}{ - "db_cloud_token": c.Conf.BKConf.BkToken, - "bk_cloud_id": c.CloudId, "region": region, "loadbalancerid": lbid, "listenerid": listenid, @@ -168,18 +147,15 @@ func (c *NameServiceClient) ClbDeRegister(region string, lbid string, listenid s } log.Logger.Debugf("ClbDeRegister param:%v", req) - response, err := c.DoNewForCB(http.MethodPost, + response, err := c.DoNew(http.MethodPost, c.SpliceUrlByPrefix(c.Conf.UrlPre, constvar.CLBDeRegisterUrl, ""), - req, nil, PolarisClbBodyParseCB) + req, nil) if err != nil { + log.Logger.Errorf("ClbDeRegister failed,%s", err.Error()) return err } - gwRsp := response.(*PolarisClbGWResp) - if gwRsp.Status != 0 { - return fmt.Errorf("%s failed, return code:%d, msg:%s", - util.AtWhere(), gwRsp.Status, gwRsp.Message) - } + log.Logger.Debugf("ClbDeRegister:%v", response) return nil } @@ -188,29 +164,28 @@ func (c *NameServiceClient) ClbGetTargets( region string, lbid string, listenid string, ) ([]string, error) { req := map[string]interface{}{ - "db_cloud_token": c.Conf.BKConf.BkToken, - "bk_cloud_id": c.CloudId, "region": region, "loadbalancerid": lbid, "listenerid": listenid, } log.Logger.Debugf("ClbDeRegister param:%v", req) - response, err := c.DoNewForCB(http.MethodPost, + response, err := c.DoNew(http.MethodPost, c.SpliceUrlByPrefix(c.Conf.UrlPre, constvar.CLBGetTargetsUrl, ""), - req, nil, PolarisClbBodyParseCB) + req, nil) if err != nil { + log.Logger.Errorf("ClbGetTargets failed,%s", err.Error()) return nil, err } - gwRsp := response.(*PolarisClbGWResp) - if gwRsp.Status != 0 { - gwErr := fmt.Errorf("%s failed, return code:%d, msg:%s", - util.AtWhere(), gwRsp.Status, gwRsp.Message) - return nil, gwErr + log.Logger.Debugf("ClbGet Response:%v", response) + var gwResp PolarisClbGWResp + err = json.Unmarshal(response.Data, &gwResp) + if err != nil { + log.Logger.Errorf("ClbGetTargets failed,%s", err.Error()) + return make([]string, 0), err } - - return gwRsp.Ips, nil + return gwResp.Ips, nil } // GetPolarisTargets get target address from polaris @@ -222,25 +197,26 @@ func (c *NameServiceClient) GetPolarisTargets(servicename string) ([]string, err } log.Logger.Debugf("GetPolarisTargets param:%v", req) - response, err := c.DoNewForCB(http.MethodPost, + response, err := c.DoNew(http.MethodPost, c.SpliceUrlByPrefix(c.Conf.UrlPre, constvar.PolarisTargetsUrl, ""), - req, nil, PolarisClbBodyParseCB) + req, nil) if err != nil { return nil, err } - gwRsp := response.(*PolarisClbGWResp) - if gwRsp.Status != 0 { - gwErr := fmt.Errorf("%s failed, return code:%d, msg:%s", - util.AtWhere(), gwRsp.Status, gwRsp.Message) - return nil, gwErr + var gwResp PolarisClbGWResp + err = json.Unmarshal(response.Data, &gwResp) + if err != nil { + log.Logger.Errorf("ClbGetTargets failed,%s", err.Error()) + return make([]string, 0), err } - return gwRsp.Ips, nil + return gwResp.Ips, nil } // PolarisUnBindTarget unbind address from polaris -func (c *NameServiceClient) PolarisUnBindTarget(servicename string, servertoken string, addr string) error { +func (c *NameServiceClient) PolarisUnBindTarget( + servicename string, servertoken string, addr string) error { req := map[string]interface{}{ "db_cloud_token": c.Conf.BKConf.BkToken, "bk_cloud_id": c.CloudId, @@ -250,18 +226,13 @@ func (c *NameServiceClient) PolarisUnBindTarget(servicename string, servertoken } log.Logger.Debugf("PolarisUnBindTarget param:%v", req) - response, err := c.DoNewForCB(http.MethodPost, + response, err := c.DoNew(http.MethodPost, c.SpliceUrlByPrefix(c.Conf.UrlPre, constvar.PolarisUnBindUrl, ""), - req, nil, PolarisClbBodyParseCB) + req, nil) if err != nil { + log.Logger.Errorf("PolarisUnBindTarget failed,%s", err.Error()) return err } - - gwRsp := response.(*PolarisClbGWResp) - if gwRsp.Status != 0 { - return fmt.Errorf("%s failed, return code:%d, msg:%s", - util.AtWhere(), gwRsp.Status, gwRsp.Message) - } - + log.Logger.Debugf("PolarisUnBindTarget response:%v", response) return nil } diff --git a/dbm-services/common/dbha/ha-module/constvar/constant.go b/dbm-services/common/dbha/ha-module/constvar/constant.go index 713c9d19b6..99baf97cc5 100644 --- a/dbm-services/common/dbha/ha-module/constvar/constant.go +++ b/dbm-services/common/dbha/ha-module/constvar/constant.go @@ -76,10 +76,10 @@ const ( // DetectTenDBCluster detect TenDBCluster DetectTenDBCluster = "tendbcluster" - //TendisCache if specified, agent detect would detect RedisCluster's cache - TendisCache = "Rediscache" - //Twemproxy if specified, agent detect would detect RedisCluster's proxy - Twemproxy = "Twemproxy" + // DetectRedis detect tendiscache and twemproxy + DetectRedis = "TwemproxyRedisInstance" + // DetectTendisplus detect tendisplus and predixy + DetectTendisplus = "PredixyTendisplusCluster" //Predixy if specified, agent detect would detect TendisplusCluster's proxy layer Predixy = "Predixy" @@ -186,13 +186,13 @@ const ( // CmDBEntryDetailUrl TODO CmDBEntryDetailUrl = "dbmeta/dbha/entry_detail/" // CLBDeRegisterUrl TODO - CLBDeRegisterUrl = "clb_deregister_part_target/" + CLBDeRegisterUrl = "deregister_part_target/" // CLBGetTargetsUrl TODO - CLBGetTargetsUrl = "clb_get_target_private_ips/" + CLBGetTargetsUrl = "get_target_private_ips/" // PolarisTargetsUrl TODO - PolarisTargetsUrl = "polaris_describe_targets/" + PolarisTargetsUrl = "describe_targets/" // PolarisUnBindUrl TODO - PolarisUnBindUrl = "polaris_unbind_part_targets/" + PolarisUnBindUrl = "unbind_part_targets/" // BKConfigBatchUrl TODO BKConfigBatchUrl = "bkconfig/v1/confitem/batchget/" // BKConfigQueryUrl TODO diff --git a/dbm-services/common/dbha/ha-module/dbha.go b/dbm-services/common/dbha/ha-module/dbha.go index 85489c7b31..623a06dfdf 100644 --- a/dbm-services/common/dbha/ha-module/dbha.go +++ b/dbm-services/common/dbha/ha-module/dbha.go @@ -65,18 +65,18 @@ func main() { switch dbhaType { case constvar.Agent: // new agent for each db type - for _, dbType := range conf.AgentConf.ActiveDBType { - go func(dbType string) { - Agent, err := agent.NewMonitorAgent(conf, dbType) + for _, clusterType := range conf.AgentConf.ActiveDBType { + go func(clusterType string) { + Agent, err := agent.NewMonitorAgent(conf, clusterType) if err != nil { - log.Logger.Fatalf("agent init failed. dbtype:%s err:%s", dbType, err.Error()) + log.Logger.Fatalf("agent init failed. clustertype:%s err:%s", clusterType, err.Error()) } err = Agent.Run() if err != nil { - log.Logger.Fatalf("agent run failed. dbtype:%s err:%s", dbType, err.Error()) + log.Logger.Fatalf("agent run failed. clustertype:%s err:%s", clusterType, err.Error()) } - }(dbType) + }(clusterType) } var c chan struct{} <-c diff --git a/dbm-services/common/dbha/ha-module/dbmodule/dbmysql/MySQLBackend_switch.go b/dbm-services/common/dbha/ha-module/dbmodule/dbmysql/MySQLBackend_switch.go index 47bd71c39a..082d44e96e 100644 --- a/dbm-services/common/dbha/ha-module/dbmodule/dbmysql/MySQLBackend_switch.go +++ b/dbm-services/common/dbha/ha-module/dbmodule/dbmysql/MySQLBackend_switch.go @@ -24,7 +24,7 @@ func (ins *MySQLSwitch) ShowSwitchInstanceInfo() string { ins.Ip, ins.Port, ins.IDC, ins.Role, ins.Status, ins.App, ins.ClusterType, ins.MetaType) //TODO right way to check empty? - if ins.StandBySlave != (MySQLSlaveInfo{}) { + if ins.StandBySlave != (dbutil.SlaveInfo{}) { str = fmt.Sprintf("%s Switch from MASTER:<%s#%d> to SLAVE:<%s#%d>", str, ins.Ip, ins.Port, ins.StandBySlave.Ip, ins.StandBySlave.Port) } @@ -44,7 +44,7 @@ func (ins *MySQLSwitch) CheckSwitch() (bool, error) { log.Logger.Infof("info:{%s} is master", ins.ShowSwitchInstanceInfo()) log.Logger.Infof("check slave status. info{%s}", ins.ShowSwitchInstanceInfo()) - if ins.StandBySlave == (MySQLSlaveInfo{}) { + if ins.StandBySlave == (dbutil.SlaveInfo{}) { ins.ReportLogs(constvar.FailResult, "no standby slave info found") return false, err } diff --git a/dbm-services/common/dbha/ha-module/dbmodule/dbmysql/MySQL_callback.go b/dbm-services/common/dbha/ha-module/dbmodule/dbmysql/MySQL_callback.go index a3784b2c1e..b882a06b09 100644 --- a/dbm-services/common/dbha/ha-module/dbmodule/dbmysql/MySQL_callback.go +++ b/dbm-services/common/dbha/ha-module/dbmodule/dbmysql/MySQL_callback.go @@ -12,25 +12,6 @@ import ( "dbm-services/common/dbha/ha-module/log" ) -// DBInstanceInfoDetail instance detail info from cmdb api -type DBInstanceInfoDetail struct { - IP string `json:"ip"` - Port int `json:"port"` - AdminPort int `json:"admin_port"` - BKIdcCityID int `json:"bk_idc_city_id"` - InstanceRole string `json:"instance_role"` - //only TenDBCluster's spider node used - SpiderRole string `json:"spider_role"` - Status string `json:"status"` - Cluster string `json:"cluster"` - BKBizID int `json:"bk_biz_id"` - ClusterType string `json:"cluster_type"` - MachineType string `json:"machine_type"` - Receiver []MySQLSlaveInfo `json:"receiver"` - ProxyInstanceSet []dbutil.ProxyInfo `json:"proxyinstance_set"` - BindEntry dbutil.BindEntry `json:"bind_entry"` -} - // UnMarshalMySQLInstanceByCmdb convert cmdb instance info to MySQLDetectInstanceInfoFromCmDB func UnMarshalMySQLInstanceByCmdb(instances []interface{}, clusterType string) ([]*MySQLDetectInstanceInfoFromCmDB, error) { @@ -40,7 +21,7 @@ func UnMarshalMySQLInstanceByCmdb(instances []interface{}, cache := map[string]*MySQLDetectInstanceInfoFromCmDB{} for _, v := range instances { - ins := DBInstanceInfoDetail{} + ins := dbutil.DBInstanceInfoDetail{} rawData, err := json.Marshal(v) if err != nil { return nil, fmt.Errorf("marshal instance info failed:%s", err.Error()) @@ -120,7 +101,7 @@ func NewSpiderClusterByCmDB(instances []interface{}, conf *config.Config) ([]dbu // GQA call this and send to gcm switch func NewMySQLSwitchInstance(instances []interface{}, conf *config.Config) ([]dbutil.DataBaseSwitch, error) { var ret []dbutil.DataBaseSwitch - initFunc := func(ins DBInstanceInfoDetail) (dbutil.DataBaseSwitch, error) { + initFunc := func(ins dbutil.DBInstanceInfoDetail) (dbutil.DataBaseSwitch, error) { mysqlCommon := MySQLCommonSwitch{ BaseSwitch: dbutil.BaseSwitch{ Ip: ins.IP, @@ -181,7 +162,7 @@ func NewMySQLSwitchInstance(instances []interface{}, conf *config.Config) ([]dbu } for _, v := range instances { - ins := DBInstanceInfoDetail{} + ins := dbutil.DBInstanceInfoDetail{} rawData, err := json.Marshal(v) if err != nil { return nil, fmt.Errorf("marshal instance info failed:%s", err.Error()) diff --git a/dbm-services/common/dbha/ha-module/dbmodule/dbmysql/MySQL_common_switch.go b/dbm-services/common/dbha/ha-module/dbmodule/dbmysql/MySQL_common_switch.go index 4b1bbeed08..e284c6f8ef 100644 --- a/dbm-services/common/dbha/ha-module/dbmodule/dbmysql/MySQL_common_switch.go +++ b/dbm-services/common/dbha/ha-module/dbmodule/dbmysql/MySQL_common_switch.go @@ -50,7 +50,7 @@ type MySQLCommonSwitch struct { //instance role type Role string //standby slave which master switch to - StandBySlave MySQLSlaveInfo + StandBySlave dbutil.SlaveInfo } // MySQLCommonSwitchUtil common switch util for mysql-related instance used @@ -62,7 +62,7 @@ type MySQLCommonSwitchUtil interface { FindUsefulDatabase() (bool, error) CheckSlaveSlow() error ResetSlave() (string, uint64, error) - SetStandbySlave([]MySQLSlaveInfo) + SetStandbySlave([]dbutil.SlaveInfo) // SetInstanceRole and blow func all meta-type instance used SetInstanceRole(string) @@ -80,16 +80,6 @@ type SpiderCommonSwitch struct { RouteTable []RouteInfo } -// MySQLSlaveInfo defined slave switch info -type MySQLSlaveInfo struct { - Ip string `json:"ip"` - Port int `json:"port"` - IsStandBy bool `json:"is_stand_by"` - Status string `json:"status"` - BinlogFile string - BinlogPosition string -} - // DelayInfo defined slave delay info type DelayInfo struct { // check whether SQL_Thread hang @@ -197,7 +187,7 @@ type TdbctlInfo struct { // SetStandbySlave only master instance could call this. // Always use standbySlave.If no standby attribute slave found, use // the first index slave -func (ins *MySQLCommonSwitch) SetStandbySlave(slaves []MySQLSlaveInfo) { +func (ins *MySQLCommonSwitch) SetStandbySlave(slaves []dbutil.SlaveInfo) { if len(slaves) > 0 { //try to found standby slave for _, slave := range slaves { @@ -209,7 +199,7 @@ func (ins *MySQLCommonSwitch) SetStandbySlave(slaves []MySQLSlaveInfo) { ins.StandBySlave = slaves[0] log.Logger.Debugf("set standy slave success:%#v", ins.StandBySlave) } else { - ins.StandBySlave = MySQLSlaveInfo{} + ins.StandBySlave = dbutil.SlaveInfo{} } } @@ -630,7 +620,7 @@ func (ins *SpiderCommonSwitch) SetRoutes() error { } for _, v := range rawData { - cmdbIns := DBInstanceInfoDetail{} + cmdbIns := dbutil.DBInstanceInfoDetail{} rawIns, jsonErr := json.Marshal(v) if jsonErr != nil { return fmt.Errorf("get tdbctl primary failed:%s", jsonErr.Error()) diff --git a/dbm-services/common/dbha/ha-module/dbmodule/dbmysql/SpiderProxyLayer_switch.go b/dbm-services/common/dbha/ha-module/dbmodule/dbmysql/SpiderProxyLayer_switch.go index 28aa0d45cf..7bb156f542 100644 --- a/dbm-services/common/dbha/ha-module/dbmodule/dbmysql/SpiderProxyLayer_switch.go +++ b/dbm-services/common/dbha/ha-module/dbmodule/dbmysql/SpiderProxyLayer_switch.go @@ -53,7 +53,7 @@ func (ins *SpiderProxyLayerSwitch) ElectPrimary() (TdbctlInfo, error) { HaDBClient: client.NewHaDBClient(&dbConf.HADB, ins.Config.GetCloudId()), SwitchUid: ins.GetSwitchUid(), }, - StandBySlave: MySQLSlaveInfo{ + StandBySlave: dbutil.SlaveInfo{ Ip: node.Host, Port: node.Port, }, diff --git a/dbm-services/common/dbha/ha-module/dbmodule/dbmysql/SpiderStorageLayer_switch.go b/dbm-services/common/dbha/ha-module/dbmodule/dbmysql/SpiderStorageLayer_switch.go index f43eafbb74..d133038cdd 100644 --- a/dbm-services/common/dbha/ha-module/dbmodule/dbmysql/SpiderStorageLayer_switch.go +++ b/dbm-services/common/dbha/ha-module/dbmodule/dbmysql/SpiderStorageLayer_switch.go @@ -43,7 +43,7 @@ func (ins *SpiderStorageSwitch) CheckSwitch() (bool, error) { log.Logger.Infof("info:{%s} is master", ins.ShowSwitchInstanceInfo()) log.Logger.Infof("check slave status. info{%s}", ins.ShowSwitchInstanceInfo()) - if ins.StandBySlave == (MySQLSlaveInfo{}) { + if ins.StandBySlave == (dbutil.SlaveInfo{}) { ins.ReportLogs(constvar.FailResult, "no slave info found") return false, err } @@ -133,7 +133,7 @@ func (ins *SpiderStorageSwitch) ShowSwitchInstanceInfo() string { ins.Ip, ins.Port, ins.IDC, ins.Role, ins.Status, ins.App, ins.ClusterType, ins.MetaType) //TODO right way to check empty? - if ins.StandBySlave != (MySQLSlaveInfo{}) { + if ins.StandBySlave != (dbutil.SlaveInfo{}) { str = fmt.Sprintf("%s Switch from MASTER:<%s#%d> to SLAVE:<%s#%d>", str, ins.Ip, ins.Port, ins.StandBySlave.Ip, ins.StandBySlave.Port) } diff --git a/dbm-services/common/dbha/ha-module/dbmodule/redis/predixy_callback.go b/dbm-services/common/dbha/ha-module/dbmodule/redis/predixy_callback.go deleted file mode 100644 index 503284af49..0000000000 --- a/dbm-services/common/dbha/ha-module/dbmodule/redis/predixy_callback.go +++ /dev/null @@ -1,94 +0,0 @@ -package redis - -import ( - "encoding/json" - - "dbm-services/common/dbha/ha-module/config" - "dbm-services/common/dbha/ha-module/constvar" - "dbm-services/common/dbha/ha-module/dbutil" - "dbm-services/common/dbha/ha-module/log" -) - -// NewPredixyInstanceByCmdb Agent通过CMDB获取的信息来生成需要探测的实例 -func NewPredixyInstanceByCmdb(instances []interface{}, - conf *config.Config) ([]dbutil.DataBaseDetect, error) { - var ( - err error - unmarshalIns []*RedisDetectInfoFromCmDB - ret []dbutil.DataBaseDetect - ) - - unmarshalIns, err = UnMarshalRedisInstanceByCmdb( - instances, constvar.TendisplusCluster, - constvar.PredixyMetaType) - - if err != nil { - return nil, err - } - - for _, uIns := range unmarshalIns { - ret = append(ret, NewPredixyDetectInstance(uIns, conf)) - } - - return ret, err -} - -// DeserializePredixy 反序列化从Agent上报上来的故障实例 -func DeserializePredixy(jsonInfo []byte, conf *config.Config) (dbutil.DataBaseDetect, error) { - response := RedisDetectResponse{} - err := json.Unmarshal(jsonInfo, &response) - if err != nil { - log.Logger.Errorf("json unmarshal failed. jsoninfo:\n%s\n, err:%s", - string(jsonInfo), err.Error()) - return nil, err - } - ret := NewPredixyDetectInstanceFromRsp(&response, conf) - return ret, nil -} - -// NewPredixySwitchInstance TODO -func NewPredixySwitchInstance(instances []interface{}, - conf *config.Config) ([]dbutil.DataBaseSwitch, error) { - var err error - var ret []dbutil.DataBaseSwitch - for _, v := range instances { - swIns, err := CreateRedisProxySwitchInfo(v, conf) - if err != nil { - log.Logger.Errorf("parse predixy switch instance failed,err:%s", - err.Error()) - continue - } - - if swIns.MetaType != constvar.PredixyMetaType { - log.Logger.Errorf("Create predixy switch while the metaType[%s] != %s", - swIns.MetaType, constvar.PredixyMetaType) - continue - } - - if swIns.CheckFetchEntryDetail() { - edErr := swIns.GetEntryDetailInfo() - if edErr != nil { - log.Logger.Errorf("GetEntryDetail failed in NewPredixySwitch,err:%s", - edErr.Error()) - } - } - - pw := PredixySwitch{ - RedisProxySwitchInfo: *swIns, - } - - passwd, err := GetInstancePassByCluster( - constvar.Predixy, pw.Cluster, conf, - ) - if err != nil { - log.Logger.Errorf("get predixy switch passwd failed,err:%s,info:%s", - err.Error(), pw.ShowSwitchInstanceInfo()) - } else { - log.Logger.Infof("get predixy switch passwd[%s]", passwd) - pw.Pass = passwd - } - ret = append(ret, &pw) - } - - return ret, err -} diff --git a/dbm-services/common/dbha/ha-module/dbmodule/redis/predixy_detect.go b/dbm-services/common/dbha/ha-module/dbmodule/redis/predixy_detect.go index 359f4aedfa..e4c10c930c 100644 --- a/dbm-services/common/dbha/ha-module/dbmodule/redis/predixy_detect.go +++ b/dbm-services/common/dbha/ha-module/dbmodule/redis/predixy_detect.go @@ -12,12 +12,12 @@ import ( "dbm-services/common/dbha/ha-module/util" ) -// PredixyDetectInstance TODO +// PredixyDetectInstance predixy detect instance type PredixyDetectInstance struct { RedisDetectBase } -// Detection TODO +// Detection detect predixy instance func (ins *PredixyDetectInstance) Detection() error { err := ins.DoPredixyDetection() if err == nil && ins.Status == constvar.DBCheckSuccess { @@ -92,7 +92,7 @@ func (ins *PredixyDetectInstance) DoPredixyDetection() error { } } -// Serialization TODO +// Serialization serialize predixy detect instance func (ins *PredixyDetectInstance) Serialization() ([]byte, error) { response := RedisDetectResponse{ BaseDetectDBResponse: ins.NewDBResponse(), @@ -107,25 +107,29 @@ func (ins *PredixyDetectInstance) Serialization() ([]byte, error) { return resByte, nil } -// ShowDetectionInfo TODO +// ShowDetectionInfo show detect instance information func (ins *PredixyDetectInstance) ShowDetectionInfo() string { str := fmt.Sprintf("ip:%s, port:%d, status:%s, DBType:%s", ins.Ip, ins.Port, ins.Status, ins.DBType) return str } -// NewPredixyDetectInstance TODO +// NewPredixyDetectInstance create predixy detect ins, +// +// used by FetchDBCallback func NewPredixyDetectInstance(ins *RedisDetectInfoFromCmDB, conf *config.Config) *PredixyDetectInstance { return &PredixyDetectInstance{ - RedisDetectBase: *GetDetectBaseByInfo(ins, constvar.Predixy, conf), + RedisDetectBase: *GetDetectBaseByInfo(ins, constvar.PredixyMetaType, conf), } } -// NewPredixyDetectInstanceFromRsp TODO +// NewPredixyDetectInstanceFromRsp create predixy detect ins, +// +// used by gm/DeserializeCallback func NewPredixyDetectInstanceFromRsp(ins *RedisDetectResponse, conf *config.Config) *PredixyDetectInstance { return &PredixyDetectInstance{ - RedisDetectBase: *GetDetectBaseByRsp(ins, constvar.Predixy, conf), + RedisDetectBase: *GetDetectBaseByRsp(ins, constvar.PredixyMetaType, conf), } } diff --git a/dbm-services/common/dbha/ha-module/dbmodule/redis/predixy_switch.go b/dbm-services/common/dbha/ha-module/dbmodule/redis/predixy_switch.go index a1ef04586b..1aeccf24c2 100644 --- a/dbm-services/common/dbha/ha-module/dbmodule/redis/predixy_switch.go +++ b/dbm-services/common/dbha/ha-module/dbmodule/redis/predixy_switch.go @@ -7,17 +7,17 @@ import ( "dbm-services/common/dbha/ha-module/log" ) -// PredixySwitch TODO +// PredixySwitch predixy switch instance type PredixySwitch struct { RedisProxySwitchInfo } -// CheckSwitch TODO +// CheckSwitch no nothing to check func (ins *PredixySwitch) CheckSwitch() (bool, error) { return true, nil } -// DoSwitch TODO +// DoSwitch kick predixy from gateway func (ins *PredixySwitch) DoSwitch() error { ins.ReportLogs(constvar.InfoResult, fmt.Sprintf("handle predixy switch[%s:%d]", ins.Ip, ins.Port)) @@ -54,12 +54,12 @@ func (ins *PredixySwitch) RollBack() error { return nil } -// UpdateMetaInfo TODO +// UpdateMetaInfo nothing to update func (ins *PredixySwitch) UpdateMetaInfo() error { return nil } -// ShowSwitchInstanceInfo TODO +// ShowSwitchInstanceInfo show predixy switch information func (ins *PredixySwitch) ShowSwitchInstanceInfo() string { format := `<%s#%d IDC:%s Status:%s App:%s ClusterType:%s MachineType:%s Cluster:%s> switch` str := fmt.Sprintf( diff --git a/dbm-services/common/dbha/ha-module/dbmodule/redis/redis_base.go b/dbm-services/common/dbha/ha-module/dbmodule/redis/redis_base.go index cb486cf266..35e78a7ff6 100644 --- a/dbm-services/common/dbha/ha-module/dbmodule/redis/redis_base.go +++ b/dbm-services/common/dbha/ha-module/dbmodule/redis/redis_base.go @@ -1,6 +1,7 @@ package redis import ( + "encoding/json" "fmt" "math/rand" "strconv" @@ -15,70 +16,39 @@ import ( "dbm-services/common/dbha/ha-module/util" ) -// PolarisInfo TODO -type PolarisInfo struct { - Namespace string - Service string - Token string -} - -// CLBInfo TODO -type CLBInfo struct { - Region string - LoadBalanceId string - ListenId string -} - -// DNSInfo TODO -type DNSInfo struct { - Domain string -} - -// GWInfo TODO +// GWInfo the gateway information type GWInfo struct { - PolarisFlag bool - Polaris []PolarisInfo - CLBFlag bool - CLB []CLBInfo - DNSFlag bool - DNS []DNSInfo + PolarisFlag bool + CLBFlag bool + DNSFlag bool + DNSForword bool + ServiceEntry dbutil.BindEntry } -// RedisSwitchInfo TODO +// RedisSwitchInfo redis switch instance information type RedisSwitchInfo struct { dbutil.BaseSwitch - AdminPort int - ApiGw GWInfo - DnsClient *client.NameServiceClient - PolarisGWClient *client.NameServiceClient - MasterConf string - SlaveConf string - Proxy []dbutil.ProxyInfo - Slave []RedisSlaveInfo - Pass string - Timeout int + AdminPort int + Proxy []dbutil.ProxyInfo + Slave []dbutil.SlaveInfo + Pass string + Timeout int } -// RedisSlaveInfo TODO -type RedisSlaveInfo struct { - Ip string `json:"ip"` - Port int `json:"port"` -} - -// RedisDetectBase TODO +// RedisDetectBase redis detect information type RedisDetectBase struct { dbutil.BaseDetectDB Pass string Timeout int } -// RedisDetectResponse TODO +// RedisDetectResponse redis detect response type RedisDetectResponse struct { dbutil.BaseDetectDBResponse Pass string `json:"pass"` } -// RedisDetectInfoFromCmDB TODO +// RedisDetectInfoFromCmDB redis detect information from cmdb type RedisDetectInfoFromCmDB struct { Ip string Port int @@ -89,14 +59,12 @@ type RedisDetectInfoFromCmDB struct { Cluster string } -// RedisProxySwitchInfo TODO +// RedisProxySwitchInfo redis proxy switch information type RedisProxySwitchInfo struct { dbutil.BaseSwitch - AdminPort int - ApiGw GWInfo - DnsClient *client.NameServiceClient - PolarisGWClient *client.NameServiceClient - Pass string + AdminPort int + ApiGw GWInfo + Pass string } // CheckSSH redis do ssh check @@ -113,14 +81,80 @@ func (ins *RedisDetectBase) CheckSSH() error { return nil } -// ShowSwitchInstanceInfo TODO +// GetType return dbType +func (ins *RedisDetectBase) GetType() types.DBType { + return ins.DBType +} + +// GetDetectType return clusterType +func (ins *RedisDetectBase) GetDetectType() string { + return ins.ClusterType +} + +// GetDetectBaseByInfo get detect instance by cmdb +func GetDetectBaseByInfo(ins *RedisDetectInfoFromCmDB, + dbType string, conf *config.Config) *RedisDetectBase { + passwd := GetRedisMachinePasswd(ins.App, conf) + return &RedisDetectBase{ + BaseDetectDB: dbutil.BaseDetectDB{ + Ip: ins.Ip, + Port: ins.Port, + App: ins.App, + DBType: types.DBType(dbType), + ReporterTime: time.Unix(0, 0), + ReportInterval: conf.AgentConf.ReportInterval + rand.Intn(20), + Status: constvar.DBCheckSuccess, + Cluster: ins.Cluster, + ClusterType: ins.ClusterType, + SshInfo: dbutil.Ssh{ + Port: conf.SSH.Port, + User: conf.SSH.User, + Pass: passwd, + Dest: conf.SSH.Dest, + Timeout: conf.SSH.Timeout, + }, + }, + Pass: ins.Pass, + Timeout: conf.DBConf.Redis.Timeout, + } +} + +// GetDetectBaseByRsp get detect instance by agent response +func GetDetectBaseByRsp(ins *RedisDetectResponse, + dbType string, conf *config.Config) *RedisDetectBase { + passwd := GetRedisMachinePasswd(ins.App, conf) + return &RedisDetectBase{ + BaseDetectDB: dbutil.BaseDetectDB{ + Ip: ins.DBIp, + Port: ins.DBPort, + App: ins.App, + DBType: types.DBType(dbType), + ReporterTime: time.Unix(0, 0), + ReportInterval: conf.AgentConf.ReportInterval + rand.Intn(20), + Status: types.CheckStatus(ins.Status), + Cluster: ins.Cluster, + ClusterType: ins.ClusterType, + SshInfo: dbutil.Ssh{ + Port: conf.SSH.Port, + User: conf.SSH.User, + Pass: passwd, + Dest: conf.SSH.Dest, + Timeout: conf.SSH.Timeout, + }, + }, + Pass: ins.Pass, + Timeout: conf.DBConf.Redis.Timeout, + } +} + +// ShowSwitchInstanceInfo show instance information func (ins *RedisProxySwitchInfo) ShowSwitchInstanceInfo() string { str := fmt.Sprintf("ip:%s, port:%d, IDC:%s, status:%s, app:%s, cluster_type:%s, machine_type:%s", ins.Ip, ins.Port, ins.IDC, ins.Status, ins.App, ins.ClusterType, ins.MetaType) return str } -// KickOffDns TODO +// KickOffDns kick instance from dns func (ins *RedisProxySwitchInfo) KickOffDns() error { if !ins.ApiGw.DNSFlag { log.Logger.Infof("no need kickDNS,info:%s", @@ -128,35 +162,9 @@ func (ins *RedisProxySwitchInfo) KickOffDns() error { return nil } - for _, dnsInfo := range ins.ApiGw.DNS { - ipInfos, err := ins.DnsClient.GetDomainInfoByDomain(dnsInfo.Domain) - if err != nil { - log.Logger.Errorf("get domain info by domain name failed. err:%s, info:{%s}", - err.Error(), ins.ShowSwitchInstanceInfo()) - return err - } - - if len(ipInfos) == 0 { - log.Logger.Errorf("domain name: %s without ip. info:{%s}", - dnsInfo.Domain, ins.ShowSwitchInstanceInfo()) - return fmt.Errorf("domain name: %s without ip", dnsInfo.Domain) - } else if len(ipInfos) == 1 { - log.Logger.Warnf("domain name: %s only one ip. so we skip it. info:{%s}", - dnsInfo.Domain, ins.ShowSwitchInstanceInfo()) - } else { - err = ins.DnsClient.DeleteDomain( - dnsInfo.Domain, ins.App, ins.Ip, ins.Port, - ) - if err != nil { - log.Logger.Errorf("delete domain %s failed. err:%s, info:{%s}", - dnsInfo.Domain, err.Error(), ins.ShowSwitchInstanceInfo()) - return err - } - log.Logger.Infof("delete domain %s success. info:{%s}", - dnsInfo.Domain, ins.ShowSwitchInstanceInfo()) - } - } - return nil + return ins.DeleteNameService(dbutil.BindEntry{ + Dns: ins.ApiGw.ServiceEntry.Dns, + }) } // KickOffClb TODO @@ -167,31 +175,10 @@ func (ins *RedisProxySwitchInfo) KickOffClb() error { return nil } - for _, clbInfo := range ins.ApiGw.CLB { - ips, err := ins.PolarisGWClient.ClbGetTargets( - clbInfo.Region, clbInfo.LoadBalanceId, clbInfo.ListenId, - ) - if err != nil { - log.Logger.Errorf("call ClbGetTargets failed,info:%s", - ins.ShowSwitchInstanceInfo()) - return err - } - - addr := fmt.Sprintf("%s:%d", ins.Ip, ins.Port) - if len(ips) > 1 { - err := ins.PolarisGWClient.ClbDeRegister( - clbInfo.Region, clbInfo.LoadBalanceId, clbInfo.ListenId, addr, - ) - if err != nil { - log.Logger.Errorf("Kickoff %s from clb failed,info:%s", - addr, ins.ShowSwitchInstanceInfo()) - return err - } - } else { - log.Logger.Infof("CLB only left one ip, and no need to kickoff,info:%s", - ins.ShowSwitchInstanceInfo()) - } - } + /*return ins.DeleteNameService(dbutil.BindEntry{ + Clb: ins.ApiGw.ServiceEntry.Clb, + })*/ + // cmdb not support fetch clb information return nil } @@ -203,84 +190,24 @@ func (ins *RedisProxySwitchInfo) KickOffPolaris() error { return nil } - for _, pinfo := range ins.ApiGw.Polaris { - ips, err := ins.PolarisGWClient.GetPolarisTargets(pinfo.Service) - if err != nil { - log.Logger.Errorf("call GetPolarisTargets failed,info:%s,err:%s", - ins.ShowSwitchInstanceInfo(), err.Error()) - return err - } - - addr := fmt.Sprintf("%s:%d", ins.Ip, ins.Port) - if len(ips) > 1 { - err := ins.PolarisGWClient.PolarisUnBindTarget( - pinfo.Service, pinfo.Token, addr) - if err != nil { - log.Logger.Errorf("Kickoff %s from polaris failed,info:%s,err=%s", - addr, ins.ShowSwitchInstanceInfo(), err.Error()) - return err - } - } else { - log.Logger.Infof("Polaris only left one ip, and no need to kickoff,info:%s", - ins.ShowSwitchInstanceInfo()) - } - } + /*return ins.DeleteNameService(dbutil.BindEntry{ + Polaris: ins.ApiGw.ServiceEntry.Polaris, + })*/ + // cmdb not support fetch polaris information return nil } -// CheckFetchEntryDetail TODO -func (ins *RedisProxySwitchInfo) CheckFetchEntryDetail() bool { - if ins.ApiGw.PolarisFlag || ins.ApiGw.CLBFlag || ins.ApiGw.DNSFlag { - return true - } else { - return false - } -} - -// GetEntryDetailInfo TODO -func (ins *RedisProxySwitchInfo) GetEntryDetailInfo() error { - entry, err := ins.CmDBClient.GetEntryDetail(ins.Cluster) - if err != nil { - log.Logger.Errorf("GetEntryDetail failed, info:%s,err:%s", - ins.ShowSwitchInstanceInfo(), err.Error()) - return err - } - - clusterEntryInfo, ok := entry[ins.Cluster] - if !ok { - entryErr := fmt.Errorf("GetEntryDetail can not find [%s] in [%v]", - ins.Cluster, entry) - log.Logger.Errorf(entryErr.Error()) - return entryErr - } - - entryInfo, ok := clusterEntryInfo.(map[string]interface{}) - if !ok { - entryErr := fmt.Errorf("GetEntryDetail transfer type fail,[%v]", - clusterEntryInfo) - log.Logger.Errorf(entryErr.Error()) - return entryErr - } - err = ParseAPIGWInfo(entryInfo, &ins.ApiGw) - if err != nil { - log.Logger.Errorf("Parse APIGW failed, info:%s,err:%s", - ins.ShowSwitchInstanceInfo(), err.Error()) - return err - } - return nil -} - -// UnMarshalRedisInstanceByCmdb TODO +// UnMarshalRedisInstanceByCmdb parse the information from cmdb func UnMarshalRedisInstanceByCmdb(instances []interface{}, - uClusterType string, uMetaType string) ([]*RedisDetectInfoFromCmDB, error) { + uClusterType string) ([]*RedisDetectInfoFromCmDB, error) { var ( err error ret []*RedisDetectInfoFromCmDB ) for _, v := range instances { - ins := v.(map[string]interface{}) - inf, ok := ins["cluster_type"] + vMap := v.(map[string]interface{}) + inf, ok := vMap["cluster_type"] if !ok { err = fmt.Errorf("umarshal failed. cluster_type not exist") log.Logger.Errorf(err.Error()) @@ -290,63 +217,23 @@ func UnMarshalRedisInstanceByCmdb(instances []interface{}, if clusterType != uClusterType { continue } - inf, ok = ins["machine_type"] - if !ok { - err = fmt.Errorf("umarshal failed. machine_type not exist") - log.Logger.Errorf(err.Error()) - return nil, err - } - metaType := inf.(string) - if metaType != uMetaType { - continue - } - inf, ok = ins["status"] - if !ok { - err = fmt.Errorf("umarshal failed. status not exist") - log.Logger.Errorf(err.Error()) - return nil, err - } - status := inf.(string) - if status != constvar.RUNNING && status != constvar.AVAILABLE { - continue - } - inf, ok = ins["ip"] - if !ok { - err = fmt.Errorf("umarshal failed. ip not exist") - log.Logger.Errorf(err.Error()) - return nil, err - } - ip := inf.(string) - inf, ok = ins["port"] - if !ok { - err = fmt.Errorf("umarshal failed. port not exist") - log.Logger.Errorf(err.Error()) - return nil, err - } - port := int(inf.(float64)) - inf, ok = ins["bk_biz_id"] - if !ok { - err = fmt.Errorf("umarshal failed. app not exist") - log.Logger.Errorf(err.Error()) - return nil, err - } - app := strconv.Itoa(int(inf.(float64))) - inf, ok = ins["cluster"] - if !ok { - err = fmt.Errorf("umarshal failed. cluster not exist") - log.Logger.Errorf(err.Error()) - return nil, err + ins := dbutil.DBInstanceInfoDetail{} + rawData, err := json.Marshal(v) + if err != nil { + return nil, fmt.Errorf("marshal instance info failed:%s", err.Error()) + } + if err = json.Unmarshal(rawData, &ins); err != nil { + return nil, fmt.Errorf("unmarshal instance info failed:%s", err.Error()) } - cluster := inf.(string) detechInfo := &RedisDetectInfoFromCmDB{ - Ip: ip, - Port: port, - App: app, - ClusterType: clusterType, - MetaType: metaType, - Cluster: cluster, + Ip: ins.IP, + Port: ins.Port, + App: strconv.Itoa(ins.BKBizID), + ClusterType: ins.ClusterType, + MetaType: ins.MachineType, + Cluster: ins.Cluster, } ret = append(ret, detechInfo) @@ -354,457 +241,126 @@ func UnMarshalRedisInstanceByCmdb(instances []interface{}, return ret, nil } -// CreateRedisProxySwitchInfo TODO -func CreateRedisProxySwitchInfo( - instance interface{}, conf *config.Config, -) (*RedisProxySwitchInfo, error) { - var err error - +// GetClusterAndMetaFromIns get cluster and meta from instance +func GetClusterAndMetaFromIns(instance interface{}) (string, string, error) { ins := instance.(map[string]interface{}) - inf, ok := ins["ip"] - if !ok { - err = fmt.Errorf("umarshal failed. ip not exist") - log.Logger.Errorf(err.Error()) - return nil, err - } - ip := inf.(string) - - inf, ok = ins["port"] - if !ok { - err = fmt.Errorf("umarshal failed. port not exist") - log.Logger.Errorf(err.Error()) - return nil, err - } - port := int(inf.(float64)) - - inf, ok = ins["bk_idc_city_id"] - if !ok { - err = fmt.Errorf("umarshal failed. role not exist") - log.Logger.Errorf(err.Error()) - return nil, err - } - idc := strconv.Itoa(int(inf.(float64))) - - inf, ok = ins["status"] - if !ok { - err = fmt.Errorf("umarshal failed. ip not exist") - log.Logger.Errorf(err.Error()) - return nil, err - } - status := inf.(string) - - inf, ok = ins["bk_biz_id"] + inf, ok := ins["cluster_type"] if !ok { - err = fmt.Errorf("umarshal failed. app not exist") + err := fmt.Errorf("umarshal failed. cluster_type not exist") log.Logger.Errorf(err.Error()) - return nil, err - } - app := strconv.Itoa(int(inf.(float64))) - - inf, ok = ins["cluster_type"] - if !ok { - err = fmt.Errorf("umarshal failed. cluster_type not exist") - log.Logger.Errorf(err.Error()) - return nil, err + return "", "", err } clusterType := inf.(string) inf, ok = ins["machine_type"] if !ok { - err = fmt.Errorf("umarshal failed. machine_type not exist") + err := fmt.Errorf("umarshal failed. meta_type not exist") log.Logger.Errorf(err.Error()) - return nil, err + return "", "", err } metaType := inf.(string) + return clusterType, metaType, nil +} - inf, ok = ins["cluster"] - if !ok { - err = fmt.Errorf("umarshal failed. cluster not exist") - log.Logger.Errorf(err.Error()) - return nil, err - } - cluster := inf.(string) +// CreateRedisProxySwitchInfo +func CreateRedisProxySwitchInfo( + instance interface{}, conf *config.Config, +) (*RedisProxySwitchInfo, error) { + var err error - inf, ok = ins["admin_port"] - if !ok { - err = fmt.Errorf("umarshal failed. admin_port not exist") - log.Logger.Errorf(err.Error()) - return nil, err + ins := dbutil.DBInstanceInfoDetail{} + rawData, err := json.Marshal(instance) + if err != nil { + return nil, fmt.Errorf("marshal instance info failed:%s", err.Error()) } - adminPort := int(inf.(float64)) - - inf, ok = ins["bind_entry"] - if !ok { - err = fmt.Errorf("umarshal failed. bind_entry not exist") - log.Logger.Errorf(err.Error()) - return nil, err + if err = json.Unmarshal(rawData, &ins); err != nil { + return nil, fmt.Errorf("unmarshal instance info failed:%s", err.Error()) } - bindEntry := inf.(map[string]interface{}) cmdbClient := client.NewCmDBClient(&conf.DBConf.CMDB, conf.GetCloudId()) hadbClient := client.NewHaDBClient(&conf.DBConf.HADB, conf.GetCloudId()) swIns := RedisProxySwitchInfo{ BaseSwitch: dbutil.BaseSwitch{ - Ip: ip, - Port: port, - IDC: idc, - Status: status, - App: app, - ClusterType: clusterType, - MetaType: metaType, - Cluster: cluster, + Ip: ins.IP, + Port: ins.Port, + IDC: strconv.Itoa(ins.BKIdcCityID), + Status: ins.Status, + App: strconv.Itoa(ins.BKBizID), + ClusterType: ins.ClusterType, + MetaType: ins.MachineType, + Cluster: ins.Cluster, CmDBClient: cmdbClient, HaDBClient: hadbClient, + Config: conf, }, - AdminPort: adminPort, + AdminPort: ins.AdminPort, } - _, ok = bindEntry["dns"] - if !ok { + if ins.BindEntry.Dns == nil { log.Logger.Infof("switch info not contain dns") swIns.ApiGw.DNSFlag = false } else { swIns.ApiGw.DNSFlag = true - swIns.DnsClient = client.NewNameServiceClient(&conf.DNS.BindConf, conf.GetCloudId()) + swIns.ApiGw.ServiceEntry.Dns = ins.BindEntry.Dns + for _, dns := range ins.BindEntry.Dns { + if dns.ForwardEntryId != 0 { + swIns.ApiGw.DNSForword = true + } + } } - _, ok = bindEntry["polaris"] - if !ok { + if ins.BindEntry.Polaris != nil && len(ins.BindEntry.Polaris) > 0 { + swIns.ApiGw.PolarisFlag = true + } else { log.Logger.Infof("switch info not contain polaris") swIns.ApiGw.PolarisFlag = false - } else { - swIns.ApiGw.PolarisFlag = true + // clb not support } - _, ok = bindEntry["clb"] - if !ok { + if ins.BindEntry.Clb != nil && len(ins.BindEntry.Clb) > 0 { + swIns.ApiGw.CLBFlag = true + } else { log.Logger.Infof("switch info not contain clb") swIns.ApiGw.CLBFlag = false - } else { - swIns.ApiGw.CLBFlag = true - } - if swIns.ApiGw.CLBFlag || swIns.ApiGw.PolarisFlag { - swIns.PolarisGWClient = client.NewNameServiceClient(&conf.DNS.PolarisConf, conf.GetCloudId()) + // polaris not support } - return &swIns, nil } -// ParseAPIGWInfo TODO -func ParseAPIGWInfo(entryDetail map[string]interface{}, apiGW *GWInfo) error { - if nil == apiGW { - return fmt.Errorf("input apiGW is nil") - } - - log.Logger.Infof("input entryDetail:%v", entryDetail) - if apiGW.PolarisFlag { - pVal, ok := entryDetail["polaris"] - if !ok { - err := fmt.Errorf("have PolarisFlag ture but entryDetail lack polaris") - log.Logger.Errorf(err.Error()) - return err - } else { - pArr := pVal.([]interface{}) - if nil == pArr { - return fmt.Errorf("type trans failed while parse polaris") - } - for _, polaris := range pArr { - var pIns PolarisInfo - pInfo := polaris.(map[string]interface{}) - pname, pok := pInfo["polaris_name"] - if pok { - pIns.Service = pname.(string) - } - ptoken, pok := pInfo["polaris_token"] - if pok { - pIns.Token = ptoken.(string) - } - apiGW.Polaris = append(apiGW.Polaris, pIns) - } - } - } - - if apiGW.CLBFlag { - cVal, ok := entryDetail["clb"] - if !ok { - err := fmt.Errorf("have CLBFlag ture but entryDetail lack clb") - log.Logger.Errorf(err.Error()) - return err - } else { - cArr := cVal.([]interface{}) - if nil == cArr { - return fmt.Errorf("type trans failed while parse CLB") - } - for _, clb := range cArr { - var cins CLBInfo - cinfo := clb.(map[string]interface{}) - clbid, cok := cinfo["clb_id"] - if cok { - cins.LoadBalanceId = clbid.(string) - } - listenId, cok := cinfo["listener_id"] - if cok { - cins.ListenId = listenId.(string) - } - domain, cok := cinfo["clb_domain"] - if cok { - cins.Region = domain.(string) - } - } - } - } - - if apiGW.DNSFlag { - dVal, ok := entryDetail["dns"] - if !ok { - err := fmt.Errorf("have DNSFlag ture but entryDetail lack dns") - log.Logger.Errorf(err.Error()) - return err - } else { - dArr := dVal.([]interface{}) - if nil == dArr { - return fmt.Errorf("type trans failed while parse CLB") - } - for _, dns := range dArr { - var dnsIns DNSInfo - dinfo := dns.(map[string]interface{}) - domain, dok := dinfo["domain"] - if dok { - dnsIns.Domain = domain.(string) - } - apiGW.DNS = append(apiGW.DNS, dnsIns) - } - } - } - - return nil -} - -// CreateRedisSwitchInfo TODO +// CreateRedisSwitchInfo create redis switch instance func CreateRedisSwitchInfo(instance interface{}, conf *config.Config) (*RedisSwitchInfo, error) { var err error - ins := instance.(map[string]interface{}) - inf, ok := ins["ip"] - if !ok { - err = fmt.Errorf("umarshal failed. ip not exist") - log.Logger.Errorf(err.Error()) - return nil, err - } - ip := inf.(string) - - inf, ok = ins["port"] - if !ok { - err = fmt.Errorf("umarshal failed. port not exist") - log.Logger.Errorf(err.Error()) - return nil, err - } - port := int(inf.(float64)) - - inf, ok = ins["bk_idc_city_id"] - if !ok { - err = fmt.Errorf("umarshal failed. role not exist") - log.Logger.Errorf(err.Error()) - return nil, err - } - idc := strconv.Itoa(int(inf.(float64))) - - inf, ok = ins["status"] - if !ok { - err = fmt.Errorf("umarshal failed. ip not exist") - log.Logger.Errorf(err.Error()) - return nil, err - } - status := inf.(string) - - inf, ok = ins["bk_biz_id"] - if !ok { - err = fmt.Errorf("umarshal failed. app not exist") - log.Logger.Errorf(err.Error()) - return nil, err - } - app := strconv.Itoa(int(inf.(float64))) - - inf, ok = ins["cluster_type"] - if !ok { - err = fmt.Errorf("umarshal failed. cluster_type not exist") - log.Logger.Errorf(err.Error()) - return nil, err - } - clusterType := inf.(string) - - inf, ok = ins["machine_type"] - if !ok { - err = fmt.Errorf("umarshal failed. machine_type not exist") - log.Logger.Errorf(err.Error()) - return nil, err - } - metaType := inf.(string) - - inf, ok = ins["cluster"] - if !ok { - err = fmt.Errorf("umarshal failed. cluster not exist") - log.Logger.Errorf(err.Error()) - return nil, err + ins := dbutil.DBInstanceInfoDetail{} + rawData, err := json.Marshal(instance) + if err != nil { + return nil, fmt.Errorf("marshal instance info failed:%s", err.Error()) } - cluster := inf.(string) - - _, ok = ins["bind_entry"] - if !ok { - err = fmt.Errorf("umarshal failed. bind_entry not exist") - log.Logger.Errorf(err.Error()) - return nil, err + if err = json.Unmarshal(rawData, &ins); err != nil { + return nil, fmt.Errorf("unmarshal instance info failed:%s", err.Error()) } cmdbClient := client.NewCmDBClient(&conf.DBConf.CMDB, conf.GetCloudId()) hadbClient := client.NewHaDBClient(&conf.DBConf.HADB, conf.GetCloudId()) - inf, ok = ins["receiver"] - if !ok { - err = fmt.Errorf("umarshal failed. receiver not exist") - log.Logger.Errorf(err.Error()) - return nil, err - } - slave := inf.([]interface{}) - - inf, ok = ins["proxyinstance_set"] - if !ok { - err = fmt.Errorf("umarshal failed. proxyinstance_set not exist") - log.Logger.Errorf(err.Error()) - return nil, err - } - proxy := inf.([]interface{}) - swIns := RedisSwitchInfo{ BaseSwitch: dbutil.BaseSwitch{ - Ip: ip, - Port: port, - IDC: idc, - Status: status, - App: app, - ClusterType: clusterType, - MetaType: metaType, - Cluster: cluster, + Ip: ins.IP, + Port: ins.Port, + IDC: strconv.Itoa(ins.BKIdcCityID), + Status: ins.Status, + App: strconv.Itoa(ins.BKBizID), + ClusterType: ins.ClusterType, + MetaType: ins.MachineType, + Cluster: ins.Cluster, CmDBClient: cmdbClient, HaDBClient: hadbClient, + Config: conf, }, Timeout: conf.DBConf.Redis.Timeout, - } - - for _, rawInfo := range slave { - mapInfo := rawInfo.(map[string]interface{}) - inf, ok = mapInfo["ip"] - if !ok { - err = fmt.Errorf("umarshal failed. slave ip not exist") - log.Logger.Errorf(err.Error()) - return nil, err - } - slaveIp := inf.(string) - inf, ok = mapInfo["port"] - if !ok { - err = fmt.Errorf("umarshal failed. slave port not exist") - log.Logger.Errorf(err.Error()) - return nil, err - } - slavePort := inf.(float64) - swIns.Slave = append(swIns.Slave, RedisSlaveInfo{ - Ip: slaveIp, - Port: int(slavePort), - }) - } - - for _, rawInfo := range proxy { - mapInfo := rawInfo.(map[string]interface{}) - inf, ok = mapInfo["ip"] - if !ok { - err = fmt.Errorf("umarshal failed. proxy ip not exist") - log.Logger.Errorf(err.Error()) - return nil, err - } - proxyIp := inf.(string) - inf, ok = mapInfo["port"] - if !ok { - err = fmt.Errorf("umarshal failed. proxy port not exist") - log.Logger.Errorf(err.Error()) - return nil, err - } - proxyPort := inf.(float64) - inf, ok = mapInfo["admin_port"] - if !ok { - err = fmt.Errorf("umarshal failed. proxy port not exist") - log.Logger.Errorf(err.Error()) - return nil, err - } - proxyAdminPort := inf.(float64) - var status string - inf, ok = mapInfo["status"] - if !ok { - status = "" - } else { - status = inf.(string) - } - swIns.Proxy = append(swIns.Proxy, dbutil.ProxyInfo{ - Ip: proxyIp, - Port: int(proxyPort), - AdminPort: int(proxyAdminPort), - Status: status, - }) + Slave: ins.Receiver, + Proxy: ins.ProxyInstanceSet, } return &swIns, nil } - -// GetDetectBaseByInfo TODO -func GetDetectBaseByInfo(ins *RedisDetectInfoFromCmDB, - dbType string, conf *config.Config) *RedisDetectBase { - passwd := GetRedisMachinePasswd(ins.App, conf) - return &RedisDetectBase{ - BaseDetectDB: dbutil.BaseDetectDB{ - Ip: ins.Ip, - Port: ins.Port, - App: ins.App, - DBType: types.DBType(dbType), - ReporterTime: time.Unix(0, 0), - ReportInterval: conf.AgentConf.ReportInterval + rand.Intn(20), - Status: constvar.DBCheckSuccess, - Cluster: ins.Cluster, - ClusterType: ins.ClusterType, - SshInfo: dbutil.Ssh{ - Port: conf.SSH.Port, - User: conf.SSH.User, - Pass: passwd, - Dest: conf.SSH.Dest, - Timeout: conf.SSH.Timeout, - }, - }, - Pass: ins.Pass, - Timeout: conf.DBConf.Redis.Timeout, - } -} - -// GetDetectBaseByRsp TODO -func GetDetectBaseByRsp(ins *RedisDetectResponse, - dbType string, conf *config.Config) *RedisDetectBase { - passwd := GetRedisMachinePasswd(ins.App, conf) - return &RedisDetectBase{ - BaseDetectDB: dbutil.BaseDetectDB{ - Ip: ins.DBIp, - Port: ins.DBPort, - App: ins.App, - DBType: types.DBType(dbType), - ReporterTime: time.Unix(0, 0), - ReportInterval: conf.AgentConf.ReportInterval + rand.Intn(20), - Status: types.CheckStatus(ins.Status), - Cluster: ins.Cluster, - SshInfo: dbutil.Ssh{ - Port: conf.SSH.Port, - User: conf.SSH.User, - Pass: passwd, - Dest: conf.SSH.Dest, - Timeout: conf.SSH.Timeout, - }, - }, - Pass: ins.Pass, - Timeout: conf.DBConf.Redis.Timeout, - } -} diff --git a/dbm-services/common/dbha/ha-module/dbmodule/redis/redis_callback.go b/dbm-services/common/dbha/ha-module/dbmodule/redis/redis_callback.go deleted file mode 100644 index a7bb44648e..0000000000 --- a/dbm-services/common/dbha/ha-module/dbmodule/redis/redis_callback.go +++ /dev/null @@ -1,86 +0,0 @@ -package redis - -import ( - "encoding/json" - - "dbm-services/common/dbha/ha-module/config" - "dbm-services/common/dbha/ha-module/constvar" - "dbm-services/common/dbha/ha-module/dbutil" - "dbm-services/common/dbha/ha-module/log" -) - -// NewRedisInstanceByCmdb Agent通过CMDB获取的信息来生成需要探测的实例 -func NewRedisInstanceByCmdb(instances []interface{}, - conf *config.Config) ([]dbutil.DataBaseDetect, error) { - var ( - err error - unmarshalIns []*RedisDetectInfoFromCmDB - ret []dbutil.DataBaseDetect - ) - - unmarshalIns, err = UnMarshalRedisInstanceByCmdb(instances, - constvar.RedisCluster, constvar.RedisMetaType) - - if err != nil { - return nil, err - } - - for _, uIns := range unmarshalIns { - ret = append(ret, NewRedisDetectInstance(uIns, conf)) - } - - return ret, err -} - -// DeserializeRedis 反序列化从Agent上报上来的故障实例 -func DeserializeRedis(jsonInfo []byte, - conf *config.Config) (dbutil.DataBaseDetect, error) { - response := RedisDetectResponse{} - err := json.Unmarshal(jsonInfo, &response) - if err != nil { - log.Logger.Errorf("json unmarshal failed. jsoninfo:\n%s\n, err:%s", - string(jsonInfo), err.Error()) - return nil, err - } - ret := NewRedisDetectInstanceFromRsp(&response, conf) - return ret, nil -} - -// NewRedisSwitchInstance TODO -func NewRedisSwitchInstance(instances []interface{}, - conf *config.Config) ([]dbutil.DataBaseSwitch, error) { - var err error - var ret []dbutil.DataBaseSwitch - for _, v := range instances { - swIns, err := CreateRedisSwitchInfo(v, conf) - if err != nil { - log.Logger.Errorf("parse redis switch instance failed,err:%s", - err.Error()) - continue - } - - if swIns.MetaType != constvar.RedisMetaType { - log.Logger.Errorf("Create redis switch while the metaType[%s] != %s", - swIns.MetaType, constvar.RedisMetaType) - continue - } - - pw := RedisSwitch{ - RedisSwitchInfo: *swIns, - Config: conf, - } - - passwd, err := GetInstancePassByCluster( - constvar.TendisCache, pw.Cluster, conf, - ) - if err != nil { - log.Logger.Errorf("get redis switch passwd failed,err:%s,info:%s", - err.Error(), pw.ShowSwitchInstanceInfo()) - } else { - pw.Pass = passwd - } - ret = append(ret, &pw) - } - - return ret, err -} diff --git a/dbm-services/common/dbha/ha-module/dbmodule/redis/redis_detect.go b/dbm-services/common/dbha/ha-module/dbmodule/redis/redis_detect.go index 159caf440f..febc1cc369 100644 --- a/dbm-services/common/dbha/ha-module/dbmodule/redis/redis_detect.go +++ b/dbm-services/common/dbha/ha-module/dbmodule/redis/redis_detect.go @@ -13,12 +13,12 @@ import ( "dbm-services/common/dbha/ha-module/util" ) -// RedisDetectInstance TODO +// RedisDetectInstance redis detect instance type RedisDetectInstance struct { RedisDetectBase } -// Detection TODO +// Detection detection api func (ins *RedisDetectInstance) Detection() error { err := ins.DoRedisDetection() if err == nil && ins.Status == constvar.DBCheckSuccess { @@ -52,7 +52,7 @@ func (ins *RedisDetectInstance) Detection() error { } } -// DoRedisDetection TODO +// DoRedisDetection do detect action func (ins *RedisDetectInstance) DoRedisDetection() error { r := &client.RedisClient{} addr := fmt.Sprintf("%s:%d", ins.Ip, ins.Port) @@ -105,7 +105,7 @@ func (ins *RedisDetectInstance) DoRedisDetection() error { return nil } -// Serialization TODO +// Serialization do serialize func (ins *RedisDetectInstance) Serialization() ([]byte, error) { response := RedisDetectResponse{ BaseDetectDBResponse: ins.NewDBResponse(), @@ -120,7 +120,7 @@ func (ins *RedisDetectInstance) Serialization() ([]byte, error) { return resByte, nil } -// GetRole TODO +// GetRole get role of instance func (ins *RedisDetectInstance) GetRole(info string) (string, error) { beginPos := strings.Index(info, "role:") if beginPos < 0 { @@ -141,7 +141,7 @@ func (ins *RedisDetectInstance) GetRole(info string) (string, error) { return roleInfo, nil } -// DoSetCheck TODO +// DoSetCheck check redis set response func (ins *RedisDetectInstance) DoSetCheck(r *client.RedisClient) error { keyFormat := "dbha:agent:%s" checkKey := fmt.Sprintf(keyFormat, ins.Ip) @@ -175,25 +175,29 @@ func (ins *RedisDetectInstance) DoSetCheck(r *client.RedisClient) error { } } -// ShowDetectionInfo TODO +// ShowDetectionInfo show detect instance information func (ins *RedisDetectInstance) ShowDetectionInfo() string { str := fmt.Sprintf("ip:%s, port:%d, status:%s, DBType:%s", ins.Ip, ins.Port, ins.Status, ins.DBType) return str } -// NewRedisDetectInstance TODO +// NewRedisDetectInstance create Redis detect ins, +// +// used by FetchDBCallback func NewRedisDetectInstance(ins *RedisDetectInfoFromCmDB, conf *config.Config) *RedisDetectInstance { return &RedisDetectInstance{ - RedisDetectBase: *GetDetectBaseByInfo(ins, constvar.TendisCache, conf), + RedisDetectBase: *GetDetectBaseByInfo(ins, constvar.RedisMetaType, conf), } } -// NewRedisDetectInstanceFromRsp TODO +// NewRedisDetectInstanceFromRsp create Redis detect ins, +// +// used by gm/DeserializeCallback func NewRedisDetectInstanceFromRsp(ins *RedisDetectResponse, conf *config.Config) *RedisDetectInstance { return &RedisDetectInstance{ - RedisDetectBase: *GetDetectBaseByRsp(ins, constvar.TendisCache, conf), + RedisDetectBase: *GetDetectBaseByRsp(ins, constvar.RedisMetaType, conf), } } diff --git a/dbm-services/common/dbha/ha-module/dbmodule/redis/redis_switch.go b/dbm-services/common/dbha/ha-module/dbmodule/redis/redis_switch.go index 91830f27ea..4a6c69769d 100644 --- a/dbm-services/common/dbha/ha-module/dbmodule/redis/redis_switch.go +++ b/dbm-services/common/dbha/ha-module/dbmodule/redis/redis_switch.go @@ -14,14 +14,14 @@ import ( "dbm-services/common/dbha/ha-module/util" ) -// RedisSwitch TODO +// RedisSwitch redis switch instance type RedisSwitch struct { RedisSwitchInfo Config *config.Config FLock *util.FileLock } -// CheckSwitch TODO +// CheckSwitch check redis status before switch func (ins *RedisSwitch) CheckSwitch() (bool, error) { ins.ReportLogs( constvar.InfoResult, fmt.Sprintf("handle instance[%s:%d]", ins.Ip, ins.Port), @@ -59,7 +59,7 @@ func (ins *RedisSwitch) CheckSwitch() (bool, error) { return true, nil } -// DoSwitch TODO +// DoSwitch do switch action func (ins *RedisSwitch) DoSwitch() error { log.Logger.Infof("redis do switch.info:{%s}", ins.ShowSwitchInstanceInfo()) r := &client.RedisClient{} @@ -117,7 +117,7 @@ func (ins *RedisSwitch) DoSwitch() error { return nil } -// ShowSwitchInstanceInfo TODO +// ShowSwitchInstanceInfo show switch instance information func (ins *RedisSwitch) ShowSwitchInstanceInfo() string { format := `<%s#%d IDC:%s Status:%s App:%s ClusterType:%s MachineType:%s Cluster:%s>` str := fmt.Sprintf( @@ -136,7 +136,7 @@ func (ins *RedisSwitch) RollBack() error { return nil } -// UpdateMetaInfo TODO +// UpdateMetaInfo swap redis role information from cmdb func (ins *RedisSwitch) UpdateMetaInfo() error { defer ins.DoUnLockByFile() ins.ReportLogs(constvar.InfoResult, "handle swap_role for cmdb") @@ -209,7 +209,7 @@ func (ins *RedisSwitch) DoUnLockByFile() { } } -// CheckTwemproxyPing TODO +// CheckTwemproxyPing check twemproxy ping cmd func (ins *RedisSwitch) CheckTwemproxyPing() ([]dbutil.ProxyInfo, error) { ins.ReportLogs(constvar.InfoResult, fmt.Sprintf("twemproxy ping:start check_ping, with [%d] twemproxy", @@ -261,7 +261,7 @@ func (ins *RedisSwitch) CheckTwemproxyPing() ([]dbutil.ProxyInfo, error) { return kickProxys, nil } -// KickOffTwemproxy TODO +// KickOffTwemproxy kick twemproxy from gateway func (ins *RedisSwitch) KickOffTwemproxy(kickProxys []dbutil.ProxyInfo) { if len(kickProxys) == 0 { ins.ReportLogs(constvar.InfoResult, @@ -440,16 +440,6 @@ func (ins *RedisSwitch) DoKickTwemproxy(proxy dbutil.ProxyInfo) error { continue } - if proxyIns.CheckFetchEntryDetail() { - edErr := proxyIns.GetEntryDetailInfo() - if edErr != nil { - kickErrLog := fmt.Sprintf("GetEntryDetail failed while Kick Twemproxy:%s,err:%s", - proxyIns.ShowSwitchInstanceInfo(), edErr.Error()) - log.Logger.Errorf("RedisSwitch %s", kickErrLog) - return edErr - } - } - err = proxyIns.KickOffDns() if err != nil { kickErrLog := fmt.Sprintf("kick twemproxy failed by dns,proxy=%s,err=%s", @@ -483,7 +473,7 @@ func (ins *RedisSwitch) DoKickTwemproxy(proxy dbutil.ProxyInfo) error { return nil } -// TwemproxySwitchM2S TODO +// TwemproxySwitchM2S twemproxy switch master and slave role func (ins *RedisSwitch) TwemproxySwitchM2S(masterIp string, masterPort int, slaveIp string, slavePort int) (bool, int) { var successSwitchNum int64 = 0 diff --git a/dbm-services/common/dbha/ha-module/dbmodule/redis/rediscluster_callback.go b/dbm-services/common/dbha/ha-module/dbmodule/redis/rediscluster_callback.go new file mode 100644 index 0000000000..4946a9709c --- /dev/null +++ b/dbm-services/common/dbha/ha-module/dbmodule/redis/rediscluster_callback.go @@ -0,0 +1,209 @@ +package redis + +import ( + "encoding/json" + "fmt" + + "dbm-services/common/dbha/ha-module/config" + "dbm-services/common/dbha/ha-module/constvar" + "dbm-services/common/dbha/ha-module/dbutil" + "dbm-services/common/dbha/ha-module/log" +) + +// RedisClusterNewIns Agent通过CMDB获取的信息来生成需要探测的实例 +func RedisClusterNewIns(instances []interface{}, + conf *config.Config) ([]dbutil.DataBaseDetect, error) { + + var ( + err error + unmarshalIns []*RedisDetectInfoFromCmDB + ret []dbutil.DataBaseDetect + ) + + unmarshalIns, err = UnMarshalRedisInstanceByCmdb(instances, constvar.RedisCluster) + if err != nil { + log.Logger.Errorf("RedisCluster UnMarshal failed,%s,err:%s", + constvar.RedisCluster, err.Error()) + return nil, err + } + + var redisIns, twemIns []dbutil.DataBaseDetect + for _, uIns := range unmarshalIns { + // check the cluster_type should be TwemproxyRedisInstance + if uIns.ClusterType != constvar.RedisCluster { + continue + } + + // create detect instance by machine_type + if uIns.MetaType == constvar.RedisMetaType { + redisIns = append(redisIns, NewRedisDetectInstance(uIns, conf)) + count, _ := GetInstancePass(constvar.RedisMetaType, redisIns, conf) + if count != len(redisIns) { + log.Logger.Errorf("RedisCluster redis passwd part failed,succ:%d,total:%d", + count, len(redisIns)) + } + } else if uIns.MetaType == constvar.TwemproxyMetaType { + twemIns = append(twemIns, NewTwemproxyDetectInstance(uIns, conf)) + count, _ := GetInstancePass(constvar.TwemproxyMetaType, twemIns, conf) + if count != len(twemIns) { + log.Logger.Errorf("RedisCluster twemproxy passwd part failed,succ:%d,total:%d", + count, len(twemIns)) + } + } else { + log.Logger.Errorf("RedisCluster cluster is %s but meta type is invalid", + constvar.RedisCluster) + } + } + + ret = append(ret, redisIns...) + ret = append(ret, twemIns...) + return ret, err +} + +// RedisClusterDeserialize 反序列化从Agent上报上来的故障实例 +func RedisClusterDeserialize(jsonInfo []byte, + conf *config.Config) (dbutil.DataBaseDetect, error) { + response := RedisDetectResponse{} + err := json.Unmarshal(jsonInfo, &response) + if err != nil { + log.Logger.Errorf("json unmarshal failed. jsoninfo:\n%s\n, err:%s", + string(jsonInfo), err.Error()) + return nil, err + } + + // cluster_type should be equal to TwemproxyRedisInstance + if response.ClusterType != constvar.RedisCluster { + unmatchErr := fmt.Errorf("cluster unmatch %s:%s", + response.ClusterType, constvar.RedisCluster) + log.Logger.Errorf("RedisCluster Deserialize. %s", unmatchErr.Error()) + return nil, unmatchErr + } + + // create detect instance by machine_type + if response.DBType == constvar.RedisMetaType { + ret := NewRedisDetectInstanceFromRsp(&response, conf) + return ret, nil + } else if response.DBType == constvar.TwemproxyMetaType { + ret := NewTwemproxyDetectInstanceFromRsp(&response, conf) + return ret, nil + } else { + unmatchErr := fmt.Errorf("RedisCluster meta_type not exist,%s", + response.DBType) + log.Logger.Errorf("deserialize failed,%s", unmatchErr.Error()) + return nil, err + } +} + +// RedisClusterNewSwitchIns create redis cluster switch ins +func RedisClusterNewSwitchIns(instances []interface{}, + conf *config.Config) ([]dbutil.DataBaseSwitch, error) { + var err error + var ret []dbutil.DataBaseSwitch + for _, v := range instances { + // get cluster_type and meta type from instance information + clusterType, metaType, err := GetClusterAndMetaFromIns(v) + if err != nil { + log.Logger.Errorf("redis ins lack cluster and meta info,%v,err:%s", + v, err.Error()) + continue + } + + // check cluster_type is equal to TwemproxyRedisInstance + if clusterType != constvar.RedisCluster { + continue + } + + // create instance by machine_type + if metaType == constvar.RedisMetaType { + pw, err := NewRedisSwitchIns(v, conf) + if err != nil { + log.Logger.Errorf("new redis switch ins failed:%s", err.Error()) + continue + } + ret = append(ret, pw) + } else if metaType == constvar.TwemproxyMetaType { + pw, err := NewTwemproxySwitchIns(v, conf) + if err != nil { + log.Logger.Errorf("new twemproxy switch ins failed:%s", err.Error()) + continue + } + ret = append(ret, pw) + } else { + log.Logger.Errorf("redis cluster[%s] not fit meta[%s]", + clusterType, metaType) + continue + } + } + return ret, err +} + +// NewRedisSwitchIns create redis switch instance +func NewRedisSwitchIns(instance interface{}, + conf *config.Config) (dbutil.DataBaseSwitch, error) { + swIns, err := CreateRedisSwitchInfo(instance, conf) + if err != nil { + //stuff err + log.Logger.Errorf("parse redis switch instance failed,err:%s", + err.Error()) + return nil, err + } + + // check machine_type is equal to tendiscache + if swIns.MetaType != constvar.RedisMetaType { + log.Logger.Errorf("Create redis switch while the metaType[%s] != %s", + swIns.MetaType, constvar.RedisMetaType) + return nil, err + } + + pw := RedisSwitch{ + RedisSwitchInfo: *swIns, + Config: conf, + } + + // get the password of redis switch instance + passwd, err := GetInstancePassByCluster( + constvar.RedisMetaType, pw.Cluster, conf, + ) + if err != nil { + log.Logger.Errorf("get redis switch passwd failed,err:%s,info:%s", + err.Error(), pw.ShowSwitchInstanceInfo()) + } else { + pw.Pass = passwd + } + + return &pw, nil +} + +// NewTwemproxySwitchIns create twemproxy switch instance +func NewTwemproxySwitchIns(instance interface{}, + conf *config.Config) (dbutil.DataBaseSwitch, error) { + swIns, err := CreateRedisProxySwitchInfo(instance, conf) + if err != nil { + log.Logger.Errorf("parse twemproxy switch instance failed,err:%s", + err.Error()) + return nil, err + } + + // check machine_type is equal to twemproxy + if swIns.MetaType != constvar.TwemproxyMetaType { + log.Logger.Errorf("Create Twemproxy switch while the metaType[%s] != %s", + swIns.MetaType, constvar.TwemproxyMetaType) + return nil, err + } + + pw := TwemproxySwitch{ + RedisProxySwitchInfo: *swIns, + } + + // get the password of twemproxy switch instance + passwd, err := GetInstancePassByCluster( + constvar.TwemproxyMetaType, pw.Cluster, conf, + ) + if err != nil { + log.Logger.Errorf("get twemproxy switch passwd failed,err:%s,info:%s", + err.Error(), pw.ShowSwitchInstanceInfo()) + } else { + pw.Pass = passwd + } + return &pw, nil +} diff --git a/dbm-services/common/dbha/ha-module/dbmodule/redis/svr_password.go b/dbm-services/common/dbha/ha-module/dbmodule/redis/svr_password.go index e29877741e..1467c7d01b 100644 --- a/dbm-services/common/dbha/ha-module/dbmodule/redis/svr_password.go +++ b/dbm-services/common/dbha/ha-module/dbmodule/redis/svr_password.go @@ -200,8 +200,8 @@ func GetInstancePass(dbType types.DBType, } if succCount != len(insArr) { - passErr := fmt.Errorf("PassWDClusters not all instance get passwd,succ:%d,all:%d", - succCount, len(insArr)) + passErr := fmt.Errorf("PassWDClusters not all instance get passwd,dbtype:%s,succ:%d,all:%d", + dbType, succCount, len(insArr)) log.Logger.Errorf(passErr.Error()) return succCount, passErr } @@ -222,8 +222,6 @@ func GetInstancePassByCluster(dbType types.DBType, return "", passErr } - remoteConfigClient := client.NewRemoteConfigClient(&conf.DNS.RemoteConf, conf.GetCloudId()) - key := fmt.Sprintf("%s-%s-%s-%s-%s-%s", cFile, cType, cName, lName, namespace, cluster) cachePasswd, ok := passwdCache.Get(key) @@ -231,6 +229,7 @@ func GetInstancePassByCluster(dbType types.DBType, return cachePasswd.(string), nil } + remoteConfigClient := client.NewRemoteConfigClient(&conf.DNS.RemoteConf, conf.GetCloudId()) clusterPasswds := QueryPasswords(remoteConfigClient, cFile, cType, cName, lName, []string{cluster}, namespace) @@ -258,7 +257,6 @@ func QueryPasswords(remoteConfigClient *client.RemoteConfigClient, cFile string, log.Logger.Errorf(err.Error()) return clusterPasswd } - content, cok := configData["content"] if !cok { passErr := fmt.Errorf("PassWDQuery content not exist") @@ -301,7 +299,7 @@ func QueryPasswords(remoteConfigClient *client.RemoteConfigClient, cFile string, // SetPasswordToInstance set password to redis detection instance func SetPasswordToInstance(dbType types.DBType, passwd string, ins dbutil.DataBaseDetect) error { - if dbType == constvar.TendisCache { + if dbType == constvar.RedisMetaType { cacheP, isCache := ins.(*RedisDetectInstance) if isCache { cacheP.Pass = passwd @@ -309,7 +307,7 @@ func SetPasswordToInstance(dbType types.DBType, passErr := fmt.Errorf("the type[%s] of instance transfer type failed", dbType) return passErr } - } else if dbType == constvar.Twemproxy { + } else if dbType == constvar.TwemproxyMetaType { twemP, isTwem := ins.(*TwemproxyDetectInstance) if isTwem { twemP.Pass = passwd @@ -317,7 +315,7 @@ func SetPasswordToInstance(dbType types.DBType, passErr := fmt.Errorf("the type[%s] of instance transfer type failed", dbType) return passErr } - } else if dbType == constvar.Predixy { + } else if dbType == constvar.PredixyMetaType { predixyP, isPredixy := ins.(*PredixyDetectInstance) if isPredixy { predixyP.Pass = passwd @@ -325,7 +323,7 @@ func SetPasswordToInstance(dbType types.DBType, passErr := fmt.Errorf("the type[%s] of instance transfer type failed", dbType) return passErr } - } else if dbType == constvar.Tendisplus { + } else if dbType == constvar.TendisplusMetaType { tendisP, isTendis := ins.(*TendisplusDetectInstance) if isTendis { tendisP.Pass = passwd @@ -346,16 +344,16 @@ func SetPasswordToInstance(dbType types.DBType, // conf_type conf_file conf_name conf_name level_name namespace func GetConfigParamByDbType(dbType types.DBType, ) (string, string, string, string, string, error) { - if dbType == constvar.TendisCache { + if dbType == constvar.RedisMetaType { clusterMeta := constvar.RedisCluster return "proxyconf", "Twemproxy-latest", "redis_password", "cluster", clusterMeta, nil - } else if dbType == constvar.Twemproxy { + } else if dbType == constvar.TwemproxyMetaType { clusterMeta := constvar.RedisCluster return "proxyconf", "Twemproxy-latest", "password", "cluster", clusterMeta, nil - } else if dbType == constvar.Predixy { + } else if dbType == constvar.PredixyMetaType { clusterMeta := constvar.TendisplusCluster return "proxyconf", "Predixy-latest", "password", "cluster", clusterMeta, nil - } else if dbType == constvar.Tendisplus { + } else if dbType == constvar.TendisplusMetaType { clusterMeta := constvar.TendisplusCluster return "proxyconf", "Predixy-latest", "redis_password", "cluster", clusterMeta, nil } else { diff --git a/dbm-services/common/dbha/ha-module/dbmodule/redis/tendiscluster_callback.go b/dbm-services/common/dbha/ha-module/dbmodule/redis/tendiscluster_callback.go new file mode 100644 index 0000000000..1c49d298d7 --- /dev/null +++ b/dbm-services/common/dbha/ha-module/dbmodule/redis/tendiscluster_callback.go @@ -0,0 +1,206 @@ +package redis + +import ( + "encoding/json" + "fmt" + + "dbm-services/common/dbha/ha-module/config" + "dbm-services/common/dbha/ha-module/constvar" + "dbm-services/common/dbha/ha-module/dbutil" + "dbm-services/common/dbha/ha-module/log" +) + +// TendisClusterNewIns create tendisplus and predixy detect instance +func TendisClusterNewIns(instances []interface{}, + conf *config.Config) ([]dbutil.DataBaseDetect, error) { + var ( + err error + unmarshalIns []*RedisDetectInfoFromCmDB + ret []dbutil.DataBaseDetect + ) + + unmarshalIns, err = UnMarshalRedisInstanceByCmdb(instances, constvar.TendisplusCluster) + if err != nil { + log.Logger.Errorf("TendisCluster UnMarshal failed,%s,err:%s", + constvar.TendisplusCluster, err.Error()) + return nil, err + } + + var tendisIns, predixyIns []dbutil.DataBaseDetect + for _, uIns := range unmarshalIns { + // check the cluster_type should be PredixyTendisplusCluster + if uIns.ClusterType != constvar.TendisplusCluster { + continue + } + + // create detect instance by machine_type + if uIns.MetaType == constvar.TendisplusMetaType { + tendisIns = append(tendisIns, NewTendisplusDetectInstance(uIns, conf)) + count, _ := GetInstancePass(constvar.TendisplusMetaType, tendisIns, conf) + if count != len(tendisIns) { + log.Logger.Errorf("TendisCluster tendisplus passwd part failed,succ:%d,total:%d", + count, len(tendisIns)) + } + } else if uIns.MetaType == constvar.PredixyMetaType { + predixyIns = append(predixyIns, NewPredixyDetectInstance(uIns, conf)) + count, _ := GetInstancePass(constvar.PredixyMetaType, predixyIns, conf) + if count != len(predixyIns) { + log.Logger.Errorf("TendisCluster predixy passwd part failed,succ:%d,total:%d", + count, len(predixyIns)) + } + } else { + log.Logger.Errorf("TendisCluster cluster is %s but meta type is invalid", + constvar.TendisplusCluster) + } + } + + ret = append(ret, tendisIns...) + ret = append(ret, predixyIns...) + return ret, err +} + +// TendisClusterDeserialize deserialize tendisplus and predixy detect instance +func TendisClusterDeserialize(jsonInfo []byte, + conf *config.Config) (dbutil.DataBaseDetect, error) { + response := RedisDetectResponse{} + err := json.Unmarshal(jsonInfo, &response) + if err != nil { + log.Logger.Errorf("json unmarshal failed. jsoninfo:\n%s\n, err:%s", + string(jsonInfo), err.Error()) + return nil, err + } + + // cluster_type should be equal to PredixyTendisplusCluster + if response.ClusterType != constvar.TendisplusCluster { + unmatchErr := fmt.Errorf("cluster unmatch %s:%s", + response.ClusterType, constvar.TendisplusCluster) + log.Logger.Errorf("TendisCluster Deserialize. %s", unmatchErr.Error()) + return nil, err + } + + // create detect instance by machine_type + if response.DBType == constvar.TendisplusMetaType { + ret := NewTendisplusDetectInstanceFromRsp(&response, conf) + return ret, nil + } else if response.DBType == constvar.PredixyMetaType { + ret := NewPredixyDetectInstanceFromRsp(&response, conf) + return ret, nil + } else { + unmatchErr := fmt.Errorf("TendisCluster meta_type not exist,%s", + response.DBType) + log.Logger.Errorf("deserialize failed,%s", unmatchErr.Error()) + return nil, err + } +} + +// TendisClusterNewSwitchIns create tendisplus and predixy switch instance +func TendisClusterNewSwitchIns(instances []interface{}, + conf *config.Config) ([]dbutil.DataBaseSwitch, error) { + var err error + var ret []dbutil.DataBaseSwitch + for _, v := range instances { + // get cluster_type and meta type from instance information + clusterType, metaType, err := GetClusterAndMetaFromIns(v) + if err != nil { + log.Logger.Errorf("tendis ins lack cluster and meta info,%v,err:%s", + v, err.Error()) + continue + } + + // check cluster_type is equal to PredixyTendisplusCluster + if clusterType != constvar.TendisplusCluster { + continue + } + + // create instance by machine_type + if metaType == constvar.TendisplusMetaType { + pw, err := NewTendisplusSwitchIns(v, conf) + if err != nil { + log.Logger.Errorf("new tendis switch ins failed:%s", err.Error()) + continue + } + ret = append(ret, pw) + } else if metaType == constvar.PredixyMetaType { + pw, err := NewPredixySwitchIns(v, conf) + if err != nil { + log.Logger.Errorf("new predixy switch ins failed:%s", err.Error()) + continue + } + ret = append(ret, pw) + } else { + log.Logger.Errorf("tendis cluster[%s] not fit meta[%s]", + clusterType, metaType) + } + } + return ret, err +} + +// NewTendisplusSwitchIns new tendisplus switch instance +func NewTendisplusSwitchIns(instance interface{}, + conf *config.Config) (dbutil.DataBaseSwitch, error) { + swIns, err := CreateRedisSwitchInfo(instance, conf) + if err != nil { + log.Logger.Errorf("parse tendisplus switch instance failed,err:%s", + err.Error()) + return nil, err + } + + // check machine_type is equal to tendisplus + if swIns.MetaType != constvar.TendisplusMetaType { + log.Logger.Errorf("Create tendisplus switch while the metaType[%s] != %s", + swIns.MetaType, constvar.TendisplusMetaType) + return nil, err + } + + pw := TendisplusSwitch{ + RedisSwitchInfo: *swIns, + } + + // get the password of switch instance + passwd, err := GetInstancePassByCluster( + constvar.TendisplusMetaType, pw.Cluster, conf, + ) + if err != nil { + log.Logger.Errorf("get tendisplus switch passwd failed,err:%s,info:%s", + err.Error(), pw.ShowSwitchInstanceInfo()) + } else { + pw.Pass = passwd + } + + return &pw, nil +} + +// NewPredixySwitchInstance new predixy switch instance +func NewPredixySwitchIns(instance interface{}, + conf *config.Config) (dbutil.DataBaseSwitch, error) { + swIns, err := CreateRedisProxySwitchInfo(instance, conf) + if err != nil { + log.Logger.Errorf("parse predixy switch instance failed,err:%s", + err.Error()) + return nil, err + } + + // check machine_type is equal to Predixy + if swIns.MetaType != constvar.PredixyMetaType { + log.Logger.Errorf("Create predixy switch while the metaType[%s] != %s", + swIns.MetaType, constvar.PredixyMetaType) + return nil, err + } + + pw := PredixySwitch{ + RedisProxySwitchInfo: *swIns, + } + + // get the password of switch instance + passwd, err := GetInstancePassByCluster( + constvar.PredixyMetaType, pw.Cluster, conf, + ) + if err != nil { + log.Logger.Errorf("get predixy switch passwd failed,err:%s,info:%s", + err.Error(), pw.ShowSwitchInstanceInfo()) + } else { + log.Logger.Infof("get predixy switch passwd[%s]", passwd) + pw.Pass = passwd + } + return &pw, nil +} diff --git a/dbm-services/common/dbha/ha-module/dbmodule/redis/tendisplus_callback.go b/dbm-services/common/dbha/ha-module/dbmodule/redis/tendisplus_callback.go deleted file mode 100644 index 1a5063c412..0000000000 --- a/dbm-services/common/dbha/ha-module/dbmodule/redis/tendisplus_callback.go +++ /dev/null @@ -1,86 +0,0 @@ -package redis - -import ( - "encoding/json" - - "dbm-services/common/dbha/ha-module/config" - "dbm-services/common/dbha/ha-module/constvar" - "dbm-services/common/dbha/ha-module/dbutil" - "dbm-services/common/dbha/ha-module/log" -) - -// NewTendisplusInstanceByCmdb Agent通过CMDB获取的信息来生成需要探测的实例 -func NewTendisplusInstanceByCmdb(instances []interface{}, - conf *config.Config) ([]dbutil.DataBaseDetect, error) { - var ( - err error - unmarshalIns []*RedisDetectInfoFromCmDB - ret []dbutil.DataBaseDetect - ) - - unmarshalIns, err = UnMarshalRedisInstanceByCmdb(instances, - constvar.TendisplusCluster, constvar.TendisplusMetaType) - - if err != nil { - return nil, err - } - - for _, uIns := range unmarshalIns { - ret = append(ret, NewTendisplusDetectInstance(uIns, conf)) - } - - return ret, err -} - -// DeserializeTendisplus 反序列化从Agent上报上来的故障实例 -func DeserializeTendisplus(jsonInfo []byte, - conf *config.Config) (dbutil.DataBaseDetect, error) { - response := RedisDetectResponse{} - err := json.Unmarshal(jsonInfo, &response) - if err != nil { - log.Logger.Errorf("json unmarshal failed. jsoninfo:\n%s\n, err:%s", - string(jsonInfo), err.Error()) - return nil, err - } - ret := NewTendisplusDetectInstanceFromRsp(&response, conf) - return ret, nil -} - -// NewTendisplusSwitchInstance TODO -func NewTendisplusSwitchInstance(instances []interface{}, - conf *config.Config) ([]dbutil.DataBaseSwitch, error) { - var err error - var ret []dbutil.DataBaseSwitch - for _, v := range instances { - swIns, err := CreateRedisSwitchInfo(v, conf) - if err != nil { - log.Logger.Errorf("parse tendisplus switch instance failed,err:%s", - err.Error()) - continue - } - - if swIns.MetaType != constvar.TendisplusMetaType { - log.Logger.Errorf("Create tendisplus switch while the metaType[%s] != %s", - swIns.MetaType, constvar.TendisplusMetaType) - continue - } - - pw := TendisplusSwitch{ - RedisSwitchInfo: *swIns, - } - - passwd, err := GetInstancePassByCluster( - constvar.Tendisplus, pw.Cluster, conf, - ) - if err != nil { - log.Logger.Errorf("get tendisplus switch passwd failed,err:%s,info:%s", - err.Error(), pw.ShowSwitchInstanceInfo()) - } else { - pw.Pass = passwd - } - - ret = append(ret, &pw) - } - - return ret, err -} diff --git a/dbm-services/common/dbha/ha-module/dbmodule/redis/tendisplus_detect.go b/dbm-services/common/dbha/ha-module/dbmodule/redis/tendisplus_detect.go index b2cc7fd3b0..f346df37af 100644 --- a/dbm-services/common/dbha/ha-module/dbmodule/redis/tendisplus_detect.go +++ b/dbm-services/common/dbha/ha-module/dbmodule/redis/tendisplus_detect.go @@ -13,12 +13,12 @@ import ( "dbm-services/common/dbha/ha-module/util" ) -// TendisplusDetectInstance TODO +// TendisplusDetectInstance tendisplus detect instance type TendisplusDetectInstance struct { RedisDetectBase } -// Detection TODO +// Detection detect tendisplus instance func (ins *TendisplusDetectInstance) Detection() error { err := ins.DoTendisDetection() if err == nil && ins.Status == constvar.DBCheckSuccess { @@ -105,7 +105,7 @@ func (ins *TendisplusDetectInstance) DoTendisDetection() error { return nil } -// Serialization TODO +// Serialization serialize tendisplus instance func (ins *TendisplusDetectInstance) Serialization() ([]byte, error) { response := RedisDetectResponse{ BaseDetectDBResponse: ins.NewDBResponse(), @@ -120,7 +120,7 @@ func (ins *TendisplusDetectInstance) Serialization() ([]byte, error) { return resByte, nil } -// GetRole TODO +// GetRole get role information func (ins *TendisplusDetectInstance) GetRole(info string) (string, error) { beginPos := strings.Index(info, "role:") if beginPos < 0 { @@ -141,7 +141,7 @@ func (ins *TendisplusDetectInstance) GetRole(info string) (string, error) { return roleInfo, nil } -// DoSetCheck TODO +// DoSetCheck check set cmd is ok or not func (ins *TendisplusDetectInstance) DoSetCheck() error { r := &client.RedisClient{} addr := fmt.Sprintf("%s:%d", ins.Ip, ins.Port) @@ -180,25 +180,29 @@ func (ins *TendisplusDetectInstance) DoSetCheck() error { } } -// ShowDetectionInfo TODO +// ShowDetectionInfo show detect instance information func (ins *TendisplusDetectInstance) ShowDetectionInfo() string { str := fmt.Sprintf("ip:%s, port:%d, status:%s, DBType:%s", ins.Ip, ins.Port, ins.Status, ins.DBType) return str } -// NewTendisplusDetectInstance TODO +// NewTendisplusDetectInstance create tendisplus detect ins, +// +// used by FetchDBCallback func NewTendisplusDetectInstance(ins *RedisDetectInfoFromCmDB, conf *config.Config) *TendisplusDetectInstance { return &TendisplusDetectInstance{ - RedisDetectBase: *GetDetectBaseByInfo(ins, constvar.Tendisplus, conf), + RedisDetectBase: *GetDetectBaseByInfo(ins, constvar.TendisplusMetaType, conf), } } -// NewTendisplusDetectInstanceFromRsp TODO +// NewTendisplusDetectInstanceFromRsp create tendisplus detect ins, +// +// used by gm/DeserializeCallback func NewTendisplusDetectInstanceFromRsp(ins *RedisDetectResponse, conf *config.Config) *TendisplusDetectInstance { return &TendisplusDetectInstance{ - RedisDetectBase: *GetDetectBaseByRsp(ins, constvar.Tendisplus, conf), + RedisDetectBase: *GetDetectBaseByRsp(ins, constvar.TendisplusMetaType, conf), } } diff --git a/dbm-services/common/dbha/ha-module/dbmodule/redis/tendisplus_switch.go b/dbm-services/common/dbha/ha-module/dbmodule/redis/tendisplus_switch.go index c1ebe6a9ea..999922237c 100644 --- a/dbm-services/common/dbha/ha-module/dbmodule/redis/tendisplus_switch.go +++ b/dbm-services/common/dbha/ha-module/dbmodule/redis/tendisplus_switch.go @@ -6,21 +6,23 @@ import ( "dbm-services/common/dbha/ha-module/client" "dbm-services/common/dbha/ha-module/constvar" + "dbm-services/common/dbha/ha-module/dbutil" "dbm-services/common/dbha/ha-module/log" ) -// TendisplusSwitch TODO +// TendisplusSwitch tendisplus switch instance type TendisplusSwitch struct { RedisSwitchInfo - slave2M *RedisSlaveInfo + // the slave already switched to master + slave2M *dbutil.SlaveInfo } -// CheckSwitch TODO +// CheckSwitch nothing to check func (ins *TendisplusSwitch) CheckSwitch() (bool, error) { return true, nil } -// DoSwitch TODO +// DoSwitch only check the status of tendisplus instance func (ins *TendisplusSwitch) DoSwitch() error { log.Logger.Infof("redis do switch. info:{%s}", ins.ShowSwitchInstanceInfo()) slave2Master := false @@ -53,7 +55,7 @@ func (ins *TendisplusSwitch) DoSwitch() error { } } -// ShowSwitchInstanceInfo TODO +// ShowSwitchInstanceInfo show switch instance func (ins *TendisplusSwitch) ShowSwitchInstanceInfo() string { format := `<%s#%d IDC:%s Status:%s App:%s ClusterType:%s MachineType:%s Cluster:%s> switch` str := fmt.Sprintf( @@ -79,7 +81,7 @@ func (ins *TendisplusSwitch) CheckConfig() bool { } // CheckSlaveMaster check if the slave of this instance is change to master role -func (ins *TendisplusSwitch) CheckSlaveMaster(slave *RedisSlaveInfo) (bool, error) { +func (ins *TendisplusSwitch) CheckSlaveMaster(slave *dbutil.SlaveInfo) (bool, error) { r := &client.RedisClient{} addr := fmt.Sprintf("%s:%d", slave.Ip, slave.Port) r.Init(addr, ins.Pass, ins.Timeout, 0) diff --git a/dbm-services/common/dbha/ha-module/dbmodule/redis/twemproxy_callback.go b/dbm-services/common/dbha/ha-module/dbmodule/redis/twemproxy_callback.go deleted file mode 100644 index 26affc0eb0..0000000000 --- a/dbm-services/common/dbha/ha-module/dbmodule/redis/twemproxy_callback.go +++ /dev/null @@ -1,92 +0,0 @@ -package redis - -import ( - "encoding/json" - - "dbm-services/common/dbha/ha-module/config" - "dbm-services/common/dbha/ha-module/constvar" - "dbm-services/common/dbha/ha-module/dbutil" - "dbm-services/common/dbha/ha-module/log" -) - -// NewTwemproxyInstanceByCmdb Agent通过CMDB获取的信息来生成需要探测的实例 -func NewTwemproxyInstanceByCmdb(instances []interface{}, - conf *config.Config) ([]dbutil.DataBaseDetect, error) { - var ( - err error - unmarshalIns []*RedisDetectInfoFromCmDB - ret []dbutil.DataBaseDetect - ) - - unmarshalIns, err = UnMarshalRedisInstanceByCmdb(instances, - constvar.RedisCluster, constvar.TwemproxyMetaType) - - if err != nil { - return nil, err - } - - for _, uIns := range unmarshalIns { - ret = append(ret, NewTwemproxyDetectInstance(uIns, conf)) - } - - return ret, err -} - -// DeserializeTwemproxy 反序列化从Agent上报上来的故障实例 -func DeserializeTwemproxy(jsonInfo []byte, - conf *config.Config) (dbutil.DataBaseDetect, error) { - response := RedisDetectResponse{} - err := json.Unmarshal(jsonInfo, &response) - if err != nil { - log.Logger.Errorf("json unmarshal failed. jsoninfo:\n%s\n, err:%s", - string(jsonInfo), err.Error()) - return nil, err - } - ret := NewTwemproxyDetectInstanceFromRsp(&response, conf) - return ret, nil -} - -// NewTwemproxySwitchInstance TODO -func NewTwemproxySwitchInstance(instances []interface{}, - conf *config.Config) ([]dbutil.DataBaseSwitch, error) { - var err error - var ret []dbutil.DataBaseSwitch - for _, v := range instances { - swIns, err := CreateRedisProxySwitchInfo(v, conf) - if err != nil { - log.Logger.Errorf("parse twemproxy switch instance failed,err:%s", - err.Error()) - continue - } - - if swIns.MetaType != constvar.TwemproxyMetaType { - log.Logger.Errorf("Create Twemproxy switch while the metaType[%s] != %s", - swIns.MetaType, constvar.TwemproxyMetaType) - continue - } - if swIns.CheckFetchEntryDetail() { - edErr := swIns.GetEntryDetailInfo() - if edErr != nil { - log.Logger.Errorf("GetEntryDetail failed in NewTwemproxySwitch,err:%s", - edErr.Error()) - } - } - - pw := TwemproxySwitch{ - RedisProxySwitchInfo: *swIns, - } - - passwd, err := GetInstancePassByCluster( - constvar.Twemproxy, pw.Cluster, conf, - ) - if err != nil { - log.Logger.Errorf("get twemproxy switch passwd failed,err:%s,info:%s", - err.Error(), pw.ShowSwitchInstanceInfo()) - } else { - pw.Pass = passwd - } - ret = append(ret, &pw) - } - - return ret, err -} diff --git a/dbm-services/common/dbha/ha-module/dbmodule/redis/twemproxy_detect.go b/dbm-services/common/dbha/ha-module/dbmodule/redis/twemproxy_detect.go index 2e38e46cec..8466cbf58d 100644 --- a/dbm-services/common/dbha/ha-module/dbmodule/redis/twemproxy_detect.go +++ b/dbm-services/common/dbha/ha-module/dbmodule/redis/twemproxy_detect.go @@ -12,12 +12,12 @@ import ( "dbm-services/common/dbha/ha-module/util" ) -// TwemproxyDetectInstance TODO +// TwemproxyDetectInstance twemproxy detect instance type TwemproxyDetectInstance struct { RedisDetectBase } -// Detection TODO +// Detection detect twemproxy instance func (ins *TwemproxyDetectInstance) Detection() error { err := ins.DoTwemproxyDetection() if err == nil && ins.Status == constvar.DBCheckSuccess { @@ -96,7 +96,7 @@ func (ins *TwemproxyDetectInstance) DoTwemproxyDetection() error { } } -// Serialization TODO +// Serialization serialize detect instance func (ins *TwemproxyDetectInstance) Serialization() ([]byte, error) { response := RedisDetectResponse{ BaseDetectDBResponse: ins.NewDBResponse(), @@ -111,25 +111,29 @@ func (ins *TwemproxyDetectInstance) Serialization() ([]byte, error) { return resByte, nil } -// ShowDetectionInfo TODO +// ShowDetectionInfo show detect instance information func (ins *TwemproxyDetectInstance) ShowDetectionInfo() string { str := fmt.Sprintf("ip:%s, port:%d, status:%s, DBType:%s", ins.Ip, ins.Port, ins.Status, ins.DBType) return str } -// NewTwemproxyDetectInstance TODO +// NewTwemproxyDetectInstance create twemproxy detect ins, +// +// used by FetchDBCallback func NewTwemproxyDetectInstance(ins *RedisDetectInfoFromCmDB, conf *config.Config) *TwemproxyDetectInstance { return &TwemproxyDetectInstance{ - RedisDetectBase: *GetDetectBaseByInfo(ins, constvar.Twemproxy, conf), + RedisDetectBase: *GetDetectBaseByInfo(ins, constvar.TwemproxyMetaType, conf), } } -// NewTwemproxyDetectInstanceFromRsp TODO +// NewTwemproxyDetectInstanceFromRsp create twemproxy detect ins, +// +// used by gm/DeserializeCallback func NewTwemproxyDetectInstanceFromRsp(ins *RedisDetectResponse, conf *config.Config) *TwemproxyDetectInstance { return &TwemproxyDetectInstance{ - RedisDetectBase: *GetDetectBaseByRsp(ins, constvar.Twemproxy, conf), + RedisDetectBase: *GetDetectBaseByRsp(ins, constvar.TwemproxyMetaType, conf), } } diff --git a/dbm-services/common/dbha/ha-module/dbmodule/redis/twemproxy_switch.go b/dbm-services/common/dbha/ha-module/dbmodule/redis/twemproxy_switch.go index bb4d044149..ce6ecb79ec 100644 --- a/dbm-services/common/dbha/ha-module/dbmodule/redis/twemproxy_switch.go +++ b/dbm-services/common/dbha/ha-module/dbmodule/redis/twemproxy_switch.go @@ -7,17 +7,17 @@ import ( "dbm-services/common/dbha/ha-module/log" ) -// TwemproxySwitch TODO +// TwemproxySwitch twemproxy switch instance type TwemproxySwitch struct { RedisProxySwitchInfo } -// CheckSwitch TODO +// CheckSwitch nothing to check func (ins *TwemproxySwitch) CheckSwitch() (bool, error) { return true, nil } -// DoSwitch TODO +// DoSwitch kick twemproxy from gateway func (ins *TwemproxySwitch) DoSwitch() error { ins.ReportLogs(constvar.InfoResult, fmt.Sprintf("handle twemproxy switch[%s:%d]", ins.Ip, ins.Port)) @@ -53,12 +53,12 @@ func (ins *TwemproxySwitch) RollBack() error { return nil } -// UpdateMetaInfo TODO +// UpdateMetaInfo nothing to update func (ins *TwemproxySwitch) UpdateMetaInfo() error { return nil } -// ShowSwitchInstanceInfo TODO +// ShowSwitchInstanceInfo show switch instance information func (ins *TwemproxySwitch) ShowSwitchInstanceInfo() string { format := `<%s#%d IDC:%s Status:%s App:%s ClusterType:%s MachineType:%s Cluster:%s> switch` str := fmt.Sprintf( diff --git a/dbm-services/common/dbha/ha-module/dbmodule/register.go b/dbm-services/common/dbha/ha-module/dbmodule/register.go index 106d0b95b4..fd8cf91597 100644 --- a/dbm-services/common/dbha/ha-module/dbmodule/register.go +++ b/dbm-services/common/dbha/ha-module/dbmodule/register.go @@ -7,7 +7,6 @@ import ( "dbm-services/common/dbha/ha-module/dbmodule/redis" "dbm-services/common/dbha/ha-module/dbmodule/riak" "dbm-services/common/dbha/ha-module/dbutil" - "dbm-services/common/dbha/ha-module/types" ) // FetchDBCallback Agent将从cmdb获取的db实例信息转换为DataBaseDetect用于探测 @@ -30,11 +29,11 @@ type Callback struct { } // DBCallbackMap map for agent handler different dbType -var DBCallbackMap map[types.DBType]Callback +var DBCallbackMap map[string]Callback // TODO map key try to instead of cluster type func init() { - DBCallbackMap = map[types.DBType]Callback{} + DBCallbackMap = map[string]Callback{} //TenDBHA used DBCallbackMap[constvar.DetectTenDBHA] = Callback{ FetchDBCallback: dbmysql.NewMySQLClusterByCmDB, @@ -49,25 +48,18 @@ func init() { GetSwitchInstanceInformation: dbmysql.NewMySQLSwitchInstance, } - DBCallbackMap[constvar.TendisCache] = Callback{ - FetchDBCallback: redis.NewRedisInstanceByCmdb, - DeserializeCallback: redis.DeserializeRedis, - GetSwitchInstanceInformation: redis.NewRedisSwitchInstance, + //TwemproxyRedisInstance used + DBCallbackMap[constvar.DetectRedis] = Callback{ + FetchDBCallback: redis.RedisClusterNewIns, + DeserializeCallback: redis.RedisClusterDeserialize, + GetSwitchInstanceInformation: redis.RedisClusterNewSwitchIns, } - DBCallbackMap[constvar.Twemproxy] = Callback{ - FetchDBCallback: redis.NewTwemproxyInstanceByCmdb, - DeserializeCallback: redis.DeserializeTwemproxy, - GetSwitchInstanceInformation: redis.NewTwemproxySwitchInstance, - } - DBCallbackMap[constvar.Predixy] = Callback{ - FetchDBCallback: redis.NewPredixyInstanceByCmdb, - DeserializeCallback: redis.DeserializePredixy, - GetSwitchInstanceInformation: redis.NewPredixySwitchInstance, - } - DBCallbackMap[constvar.Tendisplus] = Callback{ - FetchDBCallback: redis.NewTendisplusInstanceByCmdb, - DeserializeCallback: redis.DeserializeTendisplus, - GetSwitchInstanceInformation: redis.NewTendisplusSwitchInstance, + + //PredixyTendisplusCluster used + DBCallbackMap[constvar.DetectTendisplus] = Callback{ + FetchDBCallback: redis.TendisClusterNewIns, + DeserializeCallback: redis.TendisClusterDeserialize, + GetSwitchInstanceInformation: redis.TendisClusterNewSwitchIns, } DBCallbackMap[constvar.Riak] = Callback{ diff --git a/dbm-services/common/dbha/ha-module/dbutil/db_detect.go b/dbm-services/common/dbha/ha-module/dbutil/db_detect.go index c58932b8d8..fe27bdbeb6 100644 --- a/dbm-services/common/dbha/ha-module/dbutil/db_detect.go +++ b/dbm-services/common/dbha/ha-module/dbutil/db_detect.go @@ -12,6 +12,35 @@ import ( "golang.org/x/crypto/ssh" ) +// SlaveInfo defined slave switch info +type SlaveInfo struct { + Ip string `json:"ip"` + Port int `json:"port"` + IsStandBy bool `json:"is_stand_by"` + Status string `json:"status"` + BinlogFile string + BinlogPosition string +} + +// DBInstanceInfoDetail instance detail info from cmdb api +type DBInstanceInfoDetail struct { + IP string `json:"ip"` + Port int `json:"port"` + AdminPort int `json:"admin_port"` + BKIdcCityID int `json:"bk_idc_city_id"` + InstanceRole string `json:"instance_role"` + //only TenDBCluster's spider node used + SpiderRole string `json:"spider_role"` + Status string `json:"status"` + Cluster string `json:"cluster"` + BKBizID int `json:"bk_biz_id"` + ClusterType string `json:"cluster_type"` + MachineType string `json:"machine_type"` + Receiver []SlaveInfo `json:"receiver"` + ProxyInstanceSet []ProxyInfo `json:"proxyinstance_set"` + BindEntry BindEntry `json:"bind_entry"` +} + // DataBaseDetect interface type DataBaseDetect interface { Detection() error diff --git a/dbm-services/common/dbha/ha-module/dbutil/db_switch.go b/dbm-services/common/dbha/ha-module/dbutil/db_switch.go index e0a9a35b2d..115ed04090 100644 --- a/dbm-services/common/dbha/ha-module/dbutil/db_switch.go +++ b/dbm-services/common/dbha/ha-module/dbutil/db_switch.go @@ -35,20 +35,35 @@ type DataBaseSwitch interface { ReportLogs(result string, comment string) bool } +// PolarisInfo polaris detail info, response by cmdb api +type PolarisInfo struct { + Service string `json:"polaris_name"` + Token string `json:"polaris_token"` + L5 string `json:"polaris_l5"` +} + +// CLBInfo clb detail info, response by cmdb api +type ClbInfo struct { + Region string `json:"clb_region"` + LoadBalanceId string `json:"clb_id"` + ListenId string `json:"listener_id"` +} + // DnsInfo dns detail info, response by cmdb api type DnsInfo struct { DomainName string `json:"domain"` //master_entry, slave_entry - EntryRole string `json:"entry_role"` - BindIps []string `json:"bind_ips"` - BindPort int `json:"bind_port"` + EntryRole string `json:"entry_role"` + BindIps []string `json:"bind_ips"` + BindPort int `json:"bind_port"` + ForwardEntryId int `json:"forward_entry_id"` } // BindEntry TODO type BindEntry struct { Dns []DnsInfo Polaris []interface{} - CLB []interface{} + Clb []interface{} } // ProxyInfo TODO @@ -183,13 +198,69 @@ func (ins *BaseSwitch) DeleteNameService(entry BindEntry) error { } } - if entry.CLB != nil { + if entry.Clb != nil { ins.ReportLogs(constvar.InfoResult, fmt.Sprintf("try to release clb entry")) - //TODO + /*clbClient := client.NewNameServiceClient(&conf.DNS.ClbConf, conf.GetCloudId()) + for _, clb := range entry.Clb { + addr := fmt.Sprintf("%s:%d", ins.Ip, ins.Port) + ips, err := clbClient.ClbGetTargets( + clb.Region, clb.LoadBalanceId, clb.ListenId, + ) + if err != nil { + ins.ReportLogs(constvar.FailResult, + fmt.Sprintf("get Clb[%s:%s:%s] Targets failed:%s", + clb.Region, clb.LoadBalanceId, clb.ListenId, err.Error())) + continue + } + + for _, ip := range ips { + if ip != addr { + continue + } + + err := clbClient.ClbDeRegister( + clb.Region, clb.LoadBalanceId, clb.ListenId, addr, + ) + if err != nil { + ins.ReportLogs(constvar.FailResult, + fmt.Sprintf("delte %s from clb[%s:%s:%s] failed:%s", + addr, clb.Region, clb.LoadBalanceId, clb.ListenId, err.Error())) + clbFlag = false + } + break + } + }*/ } + if entry.Polaris != nil { ins.ReportLogs(constvar.InfoResult, fmt.Sprintf("try to release polaris entry")) - //TODO + /*polarisClient := client.NewNameServiceClient(&conf.DNS.PolarisConf, conf.GetCloudId()) + for _, pinfo := range entry.Polaris { + addr := fmt.Sprintf("%s:%d", ins.Ip, ins.Port) + ips, err := polarisClient.GetPolarisTargets(pinfo.Service) + if err != nil { + ins.ReportLogs(constvar.FailResult, + fmt.Sprintf("get Polaris[%s:%s] Targets failed,err:%s", + pinfo.Service, pinfo.Token, err.Error())) + continue + } + + for _, ip := range ips { + if ip != addr { + continue + } + + err := polarisClient.PolarisUnBindTarget( + pinfo.Service, pinfo.Token, addr) + if err != nil { + ins.ReportLogs(constvar.FailResult, + fmt.Sprintf("delete [%s] from polaris %s:%s failed:%s", + addr, pinfo.Service, pinfo.Token, err.Error())) + polarisFlag = false + } + break + } + }*/ } if !(dnsFlag && clbFlag && polarisFlag) { diff --git a/dbm-services/common/dbha/ha-module/gm/connection.go b/dbm-services/common/dbha/ha-module/gm/connection.go index 1d94b8f8b2..5a52067891 100644 --- a/dbm-services/common/dbha/ha-module/gm/connection.go +++ b/dbm-services/common/dbha/ha-module/gm/connection.go @@ -10,7 +10,6 @@ import ( "dbm-services/common/dbha/ha-module/config" "dbm-services/common/dbha/ha-module/dbmodule" "dbm-services/common/dbha/ha-module/log" - "dbm-services/common/dbha/ha-module/types" ) type parseStatus int @@ -46,7 +45,7 @@ const MaxBodyLength int = 128 * 1024 // Package TODO type Package struct { Header string - DBType string + DetectType string BodyLength int Body []byte } @@ -124,20 +123,20 @@ func (conn *AgentConnection) parse(readLen int) error { conn.status = ParseType case ParseType: if conn.Buffer[i] == '\r' { - _, ok := dbmodule.DBCallbackMap[types.DBType(conn.netPackage.DBType)] + _, ok := dbmodule.DBCallbackMap[conn.netPackage.DetectType] if !ok { err = fmt.Errorf("parse failed, can't find dbtype:%s, status ParseType, index %d", - conn.netPackage.DBType, i) + conn.netPackage.DetectType, i) log.Logger.Errorf(err.Error()) break } conn.status = ParseTypeLF - } else if conn.Buffer[i] != '\r' && len(conn.netPackage.DBType) > MaxDBTypeLength { + } else if conn.Buffer[i] != '\r' && len(conn.netPackage.DetectType) > MaxDBTypeLength { err = fmt.Errorf("parse failed, len(DBType) > MaxDBtypeLen, status ParseType, index %d", i) log.Logger.Errorf(err.Error()) break } else { - conn.netPackage.DBType += string(conn.Buffer[i]) + conn.netPackage.DetectType += string(conn.Buffer[i]) } case ParseTypeLF: if conn.Buffer[i] != '\n' { @@ -182,7 +181,7 @@ func (conn *AgentConnection) parse(readLen int) error { // unpack success // replay ok log.Logger.Infof("process net package success. Type:%s, Body:%s", - conn.netPackage.DBType, conn.netPackage.Body) + conn.netPackage.DetectType, conn.netPackage.Body) n, err := conn.NetConnection.Write([]byte("OK")) if err != nil { log.Logger.Error("write failed. agent ip:", conn.Ip, " port:", conn.Port) @@ -207,7 +206,7 @@ func (conn *AgentConnection) parse(readLen int) error { func (conn *AgentConnection) resetPackage() { conn.netPackage.Header = "" - conn.netPackage.DBType = "" + conn.netPackage.DetectType = "" conn.netPackage.BodyLength = 0 conn.netPackage.Body = []byte{} conn.status = Idle @@ -216,9 +215,9 @@ func (conn *AgentConnection) resetPackage() { // processPackage 将一个完整的包处理并传给gdm func (conn *AgentConnection) processPackage() error { var err error - cb, ok := dbmodule.DBCallbackMap[types.DBType(conn.netPackage.DBType)] + cb, ok := dbmodule.DBCallbackMap[conn.netPackage.DetectType] if !ok { - err = fmt.Errorf("can't find %s instance callback", conn.netPackage.DBType) + err = fmt.Errorf("can't find %s instance callback", conn.netPackage.DetectType) log.Logger.Errorf(err.Error()) return err } diff --git a/dbm-services/common/dbha/ha-module/gm/gqa.go b/dbm-services/common/dbha/ha-module/gm/gqa.go index fa60ddbc0d..b0f45c2aa3 100644 --- a/dbm-services/common/dbha/ha-module/gm/gqa.go +++ b/dbm-services/common/dbha/ha-module/gm/gqa.go @@ -1,7 +1,6 @@ package gm import ( - "dbm-services/common/dbha/ha-module/types" "fmt" "time" @@ -211,7 +210,7 @@ func (gqa *GQA) getAllInstanceFromCMDB( log.Logger.Infof("gqa get mysql instance number:%d", len(instances)) } - cb, ok := dbmodule.DBCallbackMap[types.DBType(instance.db.GetDetectType())] + cb, ok := dbmodule.DBCallbackMap[instance.db.GetDetectType()] if !ok { err = fmt.Errorf("can't find %s instance callback", instance.db.GetDetectType()) log.Logger.Errorf(err.Error()) diff --git a/dbm-services/common/dbha/ha-module/ha.yaml b/dbm-services/common/dbha/ha-module/ha.yaml index b8a01eeb9e..d2f3e0122b 100644 --- a/dbm-services/common/dbha/ha-module/ha.yaml +++ b/dbm-services/common/dbha/ha-module/ha.yaml @@ -77,6 +77,16 @@ dns: timeout: 10 bk_conf: bk_token: "xxxx" + clb_conf: + host: "clb-host" + port: 80 + url_pre: "/api/nameservice/clb" + timeout: 10 + polaris_conf: + host: "polaris-host" + port: 80 + url_pre: "/api/nameservice/polaris" + timeout: 10 ssh: port: 36000 user: "dbmysql"