Skip to content

Commit

Permalink
Merge pull request polarismesh#130 from andrewshan/main
Browse files Browse the repository at this point in the history
fix: default config not valid
  • Loading branch information
andrewshan authored Nov 1, 2021
2 parents 08f88c4 + d15a750 commit 49b81f7
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 16 deletions.
6 changes: 6 additions & 0 deletions common/utils/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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[:])
}
3 changes: 1 addition & 2 deletions healthcheck/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
13 changes: 2 additions & 11 deletions polaris-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 # 协议名,全局唯一
Expand Down
52 changes: 52 additions & 0 deletions store/boltdb/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -63,10 +66,59 @@ 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
}
}
return nil
}

func (m *boltStore) newStore() error {
m.l5Store = &l5Store{handler: m.handler}
if err := m.l5Store.InitL5Data(); nil != err {
Expand Down
4 changes: 2 additions & 2 deletions store/sqldb/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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, ",")
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.3.0
v1.3.1

0 comments on commit 49b81f7

Please sign in to comment.