From 56626a61a514ff125f43e5ff8039138f9d9cb0b0 Mon Sep 17 00:00:00 2001 From: andrewshan Date: Mon, 1 Nov 2021 17:29:01 +0800 Subject: [PATCH 1/2] fix: default config not valid --- common/utils/funcs.go | 6 +++++ healthcheck/check.go | 3 +-- polaris-server.yaml | 13 ++--------- store/boltdb/default.go | 51 +++++++++++++++++++++++++++++++++++++++++ store/sqldb/service.go | 4 ++-- version | 2 +- 6 files changed, 63 insertions(+), 16 deletions(-) diff --git a/common/utils/funcs.go b/common/utils/funcs.go index 4e67288e8..8cd384715 100644 --- a/common/utils/funcs.go +++ b/common/utils/funcs.go @@ -118,3 +118,9 @@ func IsWildName(name string) bool { length := len(name) return length >= 1 && name[length-1:length] == "*" } + +// NewUUID 返回一个随机的UUID +func NewUUID() string { + uuidBytes := uuid.New() + return hex.EncodeToString(uuidBytes[:]) +} diff --git a/healthcheck/check.go b/healthcheck/check.go index 6d7d1bdb7..5b1837e90 100644 --- a/healthcheck/check.go +++ b/healthcheck/check.go @@ -26,7 +26,6 @@ import ( "github.com/polarismesh/polaris-server/common/srand" "github.com/polarismesh/polaris-server/common/timewheel" "github.com/polarismesh/polaris-server/common/utils" - "github.com/polarismesh/polaris-server/naming" "github.com/polarismesh/polaris-server/plugin" "sync" "sync/atomic" @@ -276,7 +275,7 @@ func setInsDbStatus(instance *api.Instance, status int) error { host := instance.GetHost().GetValue() port := instance.GetPort().GetValue() log.Infof("[Health Check][Check]addr:%s:%d id:%s set db status %d", host, port, id, status) - err := server.storage.SetInstanceHealthStatus(id, status, naming.NewUUID()) + err := server.storage.SetInstanceHealthStatus(id, status, utils.NewUUID()) if err != nil { log.Errorf("[Health Check][Check]id: %s set db status err:%s", id, err) return err diff --git a/polaris-server.yaml b/polaris-server.yaml index 9998b5942..ad75ea28b 100644 --- a/polaris-server.yaml +++ b/polaris-server.yaml @@ -14,21 +14,12 @@ bootstrap: # 注册为北极星服务 polaris_service: # probe_address: ##DB_ADDR## - enable_register: false + enable_register: true isolated: false services: - - name: polaris.discover - namespace: Polaris + - name: polaris.checker protocols: - grpcserver - - httpserver - - xdsserverv3 -# - l5pbserver - - name: polaris.healthcheck - namespace: Polaris - protocols: - - grpcserver - - httpserver # apiserver配置 apiservers: - name: httpserver # 协议名,全局唯一 diff --git a/store/boltdb/default.go b/store/boltdb/default.go index 5ca9d82f1..5c434fda1 100644 --- a/store/boltdb/default.go +++ b/store/boltdb/default.go @@ -19,7 +19,10 @@ package boltdb import ( "errors" + "github.com/polarismesh/polaris-server/common/model" + "github.com/polarismesh/polaris-server/common/utils" "github.com/polarismesh/polaris-server/store" + "time" ) const ( @@ -63,10 +66,58 @@ func (m *boltStore) Initialize(c *store.Config) error { _ = handler.Close() return err } + if err = m.initStoreData(); nil != err { + _ = handler.Close() + return err + } m.start = true return nil } +const ( + namespacePolaris = "Polaris" + ownerToInit = "polaris" +) + +var ( + namespacesToInit = []string{"default", namespacePolaris} + servicesToInit = []string{"polaris.checker", "polaris.monitor"} +) + +func (m *boltStore) initStoreData() error { + for _, namespace := range namespacesToInit { + curTime := time.Now() + err := m.AddNamespace(&model.Namespace{ + Name: namespace, + Token: utils.NewUUID(), + Owner: ownerToInit, + Valid: true, + CreateTime: curTime, + ModifyTime: curTime, + }) + if nil != err { + return err + } + } + for _, svc := range servicesToInit { + curTime := time.Now() + err := m.AddService(&model.Service{ + ID: utils.NewUUID(), + Name: svc, + Namespace: namespacePolaris, + Token: utils.NewUUID(), + Owner: ownerToInit, + Revision: utils.NewUUID(), + Valid: true, + CreateTime: curTime, + ModifyTime: curTime, + }) + if nil != err { + return err + } + } +} + func (m *boltStore) newStore() error { m.l5Store = &l5Store{handler: m.handler} if err := m.l5Store.InitL5Data(); nil != err { diff --git a/store/sqldb/service.go b/store/sqldb/service.go index 59192cd40..cf02ee9f0 100644 --- a/store/sqldb/service.go +++ b/store/sqldb/service.go @@ -20,7 +20,7 @@ package sqldb import ( "database/sql" "errors" - "github.com/polarismesh/polaris-server/naming" + "github.com/polarismesh/polaris-server/common/utils" "github.com/polarismesh/polaris-server/store" "strings" "time" @@ -1244,7 +1244,7 @@ func addOwnerServiceMap(tx *BaseTx, service, namespace, owner string) error { if len(owners) >= 1 { for i := 0; i < len(owners); i++ { addSql += "(?,?,?,?)," - args = append(args, naming.NewUUID(), owners[i], service, namespace) + args = append(args, utils.NewUUID(), owners[i], service, namespace) } if len(args) != 0 { addSql = strings.TrimSuffix(addSql, ",") diff --git a/version b/version index 8b3a0227b..23c38c241 100644 --- a/version +++ b/version @@ -1 +1 @@ -v1.3.0 \ No newline at end of file +v1.3.1 \ No newline at end of file From d15a75097fe96e5bef0a8de0a6e9c9006f2bcbf6 Mon Sep 17 00:00:00 2001 From: andrewshan Date: Mon, 1 Nov 2021 17:34:02 +0800 Subject: [PATCH 2/2] add return for funcs --- store/boltdb/default.go | 1 + 1 file changed, 1 insertion(+) diff --git a/store/boltdb/default.go b/store/boltdb/default.go index 5c434fda1..73be5254e 100644 --- a/store/boltdb/default.go +++ b/store/boltdb/default.go @@ -116,6 +116,7 @@ func (m *boltStore) initStoreData() error { return err } } + return nil } func (m *boltStore) newStore() error {