专栏首页码匠的流水账聊聊kingbus的startAdminServer
原创

聊聊kingbus的startAdminServer

本文主要研究一下kingbus的startAdminServer

startAdminServer

kingbus/server/server.go

func (s *KingbusServer) startAdminServer(urls types.URLs) error {
    if len(urls) != 1 {
        return ErrArgs
    }
    addr := urls[0].Host
    s.adminSvr = api.NewAdminServer(addr, s, s.cluster)
    return nil
}
  • startAdminServer方法主要是执行api.NewAdminServer

NewAdminServer

kingbus/api/api_server.go

//AdminServer is a server for handling api call
type AdminServer struct {
    AdminAddr string
    web       *echo.Echo
    mh        *MembershipHandler
    bs        *BinlogSyncerHandler
    bm        *BinlogServerHandler
}
​
//NewAdminServer creates a admin server
func NewAdminServer(addr string, svr Server, cluster Cluster) *AdminServer {
    adminServer := new(AdminServer)
​
    adminServer.AdminAddr = addr
    adminServer.web = echo.New()
    adminServer.web.HideBanner = true
    adminServer.web.HidePort = true
​
    adminServer.mh = &MembershipHandler{
        svr:     svr,
        cluster: cluster,
        timeout: adminAPITimeout,
    }
    adminServer.bs = &BinlogSyncerHandler{
        svr:     svr,
        cluster: cluster,
    }
    adminServer.bm = &BinlogServerHandler{
        svr: svr,
    }
    return adminServer
}
  • NewAdminServer创建adminServer,并设置了MembershipHandler、BinlogSyncerHandler、BinlogServerHandler

Run

kingbus/api/api_server.go

func (s *AdminServer) Run() {
    s.RegisterMiddleware()
    s.RegisterURL()
    err := s.web.Start(s.AdminAddr)
    if err != nil {
        log.Log.Infof("admin server start error,err:%s", err)
    }
}
  • Run方法执行RegisterMiddleware、RegisterURL以及s.web.Start(s.AdminAddr)

RegisterMiddleware

kingbus/api/api_server.go

//RegisterMiddleware implements register middleware in web
func (s *AdminServer) RegisterMiddleware() {
    loggerConfig := mw.LoggerConfig{
        Skipper: mw.DefaultSkipper,
        Format: `{"time":"${time_rfc3339_nano}","id":"${id}","remote_ip":"${remote_ip}","host":"${host}",` +
            `"method":"${method}","uri":"${uri}","status":${status}, "latency":${latency},` +
            `"latency_human":"${latency_human}","bytes_in":${bytes_in},` +
            `"bytes_out":${bytes_out}}` + "\n",
        CustomTimeFormat: "2006-01-02 15:04:05.00000",
        Output:           log.NewWriter(),
    }
    s.web.Use(mw.LoggerWithConfig(loggerConfig))
    s.web.Use(mw.Recover())
}
  • RegisterMiddleware方法主要执行web.Use(mw.LoggerWithConfig(loggerConfig))、web.Use(mw.Recover())

RegisterURL

kingbus/api/api_server.go

//RegisterURL implements url binding
func (s *AdminServer) RegisterURL() {
    //member handler
    s.web.GET("/members", s.mh.GetMembers)
    s.web.POST("/members", s.mh.AddMember)
    s.web.PUT("/members", s.mh.UpdateMember)
    s.web.DELETE("/members", s.mh.DeleteMember)
    s.web.GET("/cluster", s.mh.GetCluster)
    s.web.PUT("/admin/url", s.mh.UpdateAdminURL)
​
    //binlog syncer handler
    s.web.PUT("/binlog/syncer/start", s.bs.StartBinlogSyncer)
    s.web.PUT("/binlog/syncer/stop", s.bs.StopBinlogSyncer)
    s.web.GET("/binlog/syncer/status", s.bs.GetBinlogSyncerStatus)
​
    //binlog server handler
    s.web.PUT("/binlog/server/start", s.bm.StartBinlogServer)
    s.web.PUT("/binlog/server/stop", s.bm.StopBinlogServer)
    s.web.GET("/binlog/server/status", s.bm.GetBinlogServerStatus)
}
  • RegisterURL方法给web注册了members、binlog/syncer、binlog/server相关方法

小结

startAdminServer方法主要是执行api.NewAdminServer;NewAdminServer创建adminServer,并设置了MembershipHandler、BinlogSyncerHandler、BinlogServerHandler

doc

原创声明,本文系作者授权云+社区发表,未经许可,不得转载。

如有侵权,请联系 yunjia_community@tencent.com 删除。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • 聊聊kingbus的startAdminServer

    startAdminServer方法主要是执行api.NewAdminServer;NewAdminServer创建adminServer,并设置了Member...

    codecraft
  • 聊聊claudb的NotificationManager

    claudb-1.7.1/src/main/java/com/github/tonivade/claudb/event/NotificationManager....

    codecraft
  • 聊聊claudb的NotificationManager

    claudb-1.7.1/src/main/java/com/github/tonivade/claudb/event/NotificationManager....

    codecraft
  • 聊聊kingbus的startAdminServer

    startAdminServer方法主要是执行api.NewAdminServer;NewAdminServer创建adminServer,并设置了Member...

    codecraft
  • IIS7部署报错 500.22错误 检查到这集成托管模式下不使用的ASP.NET配置

      公司的一个项目,环境为: .Net 4.0 + MVC3,部署在 Windows Server 2003R2 IIS6.0上面运行正常,迁移到新服务器 Wi...

    张传宁老师
  • 【Java数据结构学习笔记之一】线性表的存储结构及其代码实现

    应用程序后在那个的数据大致有四种基本的逻辑结构: 集合:数据元素之间只有"同属于一个集合"的关系 线性结构:数据元素之间存在一个对一个的关系 树形结构:数...

    Angel_Kitty
  • 【python-leetcode103-树的宽度遍历】二叉树的锯齿形层次遍历

    给定一个二叉树,返回其节点值的锯齿形层次遍历。(即先从左往右,再从右往左进行下一层遍历,以此类推,层与层之间交替进行)。

    绝命生
  • 【Hadoop学习笔记】——HDFS

    版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/huyuyang6688/article/...

    DannyHoo
  • zk中如何防止羊群效应

    那么问题来了?如果同时有1000个客户端发起请求并创建临时节点,都会去监听A结点的变化,然后A删除节点的时候会通知其他节点,这样是否会太影响并耗费资源了?那么怎...

    奕仁
  • LeetCode 系列 100. 相同的树

    100. 相同的树: https://leetcode-cn.com/problems/same-tree/

    村雨遥

扫码关注云+社区

领取腾讯云代金券