cnt2

package
v0.0.0-...-4df5db5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 26, 2021 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package pb is a generated protocol buffer package.

It is generated from these files:

cnt2.proto

It has these top-level messages:

RegisterRequest
RegisterResponse
QueryRequest
QueryResponse
ResponseMessage
ValueChangeResultRequest
ValueChangeResultResponse

Index

Constants

View Source
const (
	BUCKET_NAME = "cnt2_bucket"
)
View Source
const COMMON = "common"
View Source
const (
	Node_TTL = int64(30)
)

*

  • 流程:
  • 1.到ETCD拿GrpcServer的信息
  • 2.到ConfigCenter注册,拿到nodeId
  • 3.到etcd注册临时节点(/${appName}/nodes/${nodeId})
  • 4.到ConfigCenter查询当前profile下所有配置,写入本地副本
  • 5.订阅节点变化(/${appName}/profiles/${profile}),在服务端配置发生变化时更新本地副本
  • 6.配置发生变化是通知业务
  • 7.如果注册失败则去读本地文件

Variables

View Source
var (
	NetNameMap = make(map[string]int)
	NetTypeMap = make(map[int]string)
)
View Source
var ValueChangeResultRequest_ValueChangeResult_name = map[int32]string{
	0: "FAILED",
	1: "SUCCESS",
}
View Source
var ValueChangeResultRequest_ValueChangeResult_value = map[string]int32{
	"FAILED":  0,
	"SUCCESS": 1,
}

Functions

func ChooseBestAddress

func ChooseBestAddress(grpcServerInfos []GrpcServerInfo) ([]string, bool)

FIXME can be better?

func ExtractCntInfo

func ExtractCntInfo(nodeKey string) (string, string, string, bool)

* return app ,profile,key

func GenRegisterNodeKey

func GenRegisterNodeKey(app, profile, nodeId string) string

func GenWatchCnt2CommonKey

func GenWatchCnt2CommonKey(app string) string

func GenWatchCnt2Key

func GenWatchCnt2Key(app, profile string) string

func GenWatchGrpcServerKey

func GenWatchGrpcServerKey() string

func GetMyIPInfo

func GetMyIPInfo() []string

func NewSource

func NewSource(opts ...source.Option) (source.Source, error)

func RegisterConfigCenterServiceServer

func RegisterConfigCenterServiceServer(s *grpc.Server, srv ConfigCenterServiceServer)

func WithApp

func WithApp(n string) source.Option

set app for cnt2

func WithCachePath

func WithCachePath(f string) source.Option

set cache path for cnt2

func WithCommon

func WithCommon(wc int) source.Option

func WithEtcdAddrs

func WithEtcdAddrs(a string) source.Option

set etcd url for cnt2

func WithForceQueryAll

func WithForceQueryAll(f bool) source.Option

func WithProfile

func WithProfile(a string) source.Option

set profile for cnt2

func WithTimeOut

func WithTimeOut(to int) source.Option

Types

type ClientConfig

type ClientConfig struct {
	Endpoints     []string
	DialTimeout   time.Duration
	LocalFilePath string //指定本地缓存的存储地址,便于在配置中心不可用时,可以使用之前的配置
	App           string
	Profile       string
	EnableCommon  bool
}

type Cnt2Service

type Cnt2Service struct {
	*ClientConfig
	// contains filtered or unexported fields
}

func NewCnt2Service

func NewCnt2Service(ccfg *ClientConfig, forceQueryAll bool) (*Cnt2Service, error)

func (*Cnt2Service) Close

func (c2 *Cnt2Service) Close()

func (*Cnt2Service) GetAllConfig

func (c2 *Cnt2Service) GetAllConfig() map[string]string

func (*Cnt2Service) GetConfig

func (c2 *Cnt2Service) GetConfig(key string) (string, bool)

func (*Cnt2Service) InitGrpcServer

func (c2 *Cnt2Service) InitGrpcServer() (ConfigCenterServiceClient, error)

func (*Cnt2Service) WatchCnt2

func (c2 *Cnt2Service) WatchCnt2(configCenterClient ConfigCenterServiceClient)

监听Cnt2配置

func (*Cnt2Service) WatchCnt2Common

func (c2 *Cnt2Service) WatchCnt2Common(configCenterClient ConfigCenterServiceClient)

监听Cnt2公共配置

func (*Cnt2Service) WatchGrpcServer

func (c2 *Cnt2Service) WatchGrpcServer()

监听grpcServer 服务的变化

type Config

type Config struct {
	App         string            `json:"app"`
	Profile     string            `json:"profile"`
	Key         string            `json:"key"`
	Version     int64             `json:"version"`
	PublishInfo ConfigPublishInfo `json:"publishInfo"`
	Value       string            `json:"value"`
}

func (*Config) FromJson

func (config *Config) FromJson(val string) *Config

func (*Config) ToJson

func (config *Config) ToJson() string

type ConfigCenterServiceClient

type ConfigCenterServiceClient interface {
	// 根据appId,profile 查询
	QueryAll(ctx context.Context, in *QueryRequest, opts ...grpc.CallOption) (*QueryResponse, error)
	// 根据appId,profile,key,keyVersion查询,keyVersion=0时,返回最新数据,否则返回指定版本数据
	QueryKey(ctx context.Context, in *QueryRequest, opts ...grpc.CallOption) (*ResponseMessage, error)
	//  发布处理结果通知(灰度才会有这个回调通知)
	ValueChangeResultNotify(ctx context.Context, in *ValueChangeResultRequest, opts ...grpc.CallOption) (*ValueChangeResultResponse, error)
	// 启动的时候注册服务:获取服务id
	RegisterClient(ctx context.Context, in *RegisterRequest, opts ...grpc.CallOption) (*RegisterResponse, error)
}

func NewConfigCenterServiceClient

func NewConfigCenterServiceClient(cc *grpc.ClientConn) ConfigCenterServiceClient

type ConfigCenterServiceServer

type ConfigCenterServiceServer interface {
	// 根据appId,profile 查询
	QueryAll(context.Context, *QueryRequest) (*QueryResponse, error)
	// 根据appId,profile,key,keyVersion查询,keyVersion=0时,返回最新数据,否则返回指定版本数据
	QueryKey(context.Context, *QueryRequest) (*ResponseMessage, error)
	//  发布处理结果通知(灰度才会有这个回调通知)
	ValueChangeResultNotify(context.Context, *ValueChangeResultRequest) (*ValueChangeResultResponse, error)
	// 启动的时候注册服务:获取服务id
	RegisterClient(context.Context, *RegisterRequest) (*RegisterResponse, error)
}

type ConfigPublishInfo

type ConfigPublishInfo struct {
	PublishId    int64       `json:"publishId"`
	Key          string      `json:"key"`
	Version      int64       `json:"version"`
	PublishNodes StringArray `json:"publishNodes"`
}

type GrpcServerBalancer

type GrpcServerBalancer struct {
	// contains filtered or unexported fields
}

func (*GrpcServerBalancer) Init

func (c *GrpcServerBalancer) Init()

type GrpcServerChan

type GrpcServerChan struct {
	// contains filtered or unexported fields
}

type GrpcServerInfo

type GrpcServerInfo struct {
	ServerIP map[int]string `json:"serverIP"`
	Port     int            `json:"port"`
	GroupId  int            `json:"groupId"`
}

func ParseGrpcServerInfoFromEtcd

func ParseGrpcServerInfoFromEtcd(client *clientv3.Client) ([]GrpcServerInfo, error)

type HostIP

type HostIP struct {
	Type NetType
	Ip   string
}

type HostInfo

type HostInfo struct {
	Ips     []HostIP
	GroupId int
}

func InitHostInfo

func InitHostInfo() HostInfo

type LocalStore

type LocalStore struct {
	Db *bolt.DB
	// contains filtered or unexported fields
}

func InitLocalStore

func InitLocalStore(app, path string) (*LocalStore, error)

func (*LocalStore) Clean

func (ls *LocalStore) Clean()

func (*LocalStore) Del

func (ls *LocalStore) Del(app, profile, key string) error

func (*LocalStore) Get

func (ls *LocalStore) Get(app, profile, key string) string

func (*LocalStore) GetAll

func (ls *LocalStore) GetAll(app, profile string) map[string]string

func (*LocalStore) GetConfig

func (ls *LocalStore) GetConfig(app, profile, key string) (*Config, error)

func (*LocalStore) Has

func (ls *LocalStore) Has(app, profile, key string) bool

func (*LocalStore) Put

func (ls *LocalStore) Put(app, profile, key, value string) error

func (*LocalStore) Recreate

func (ls *LocalStore) Recreate() error

type NetType

type NetType struct {
	Name string
	Val  int
}

type Node

type Node struct {
	NodeId       string `json:"nodeId"`
	App          string `json:"app"`
	Profile      string `json:"profile"`
	Sip          string `json:"sip"`
	Pid          int    `json:"pid"`
	RegisterTime int64  `json:"registerTime"`
}

type QueryRequest

type QueryRequest struct {
	App        string `protobuf:"bytes,1,opt,name=app" json:"app,omitempty"`
	Profile    string `protobuf:"bytes,2,opt,name=profile" json:"profile,omitempty"`
	Key        string `protobuf:"bytes,3,opt,name=key" json:"key,omitempty"`
	KeyVersion int64  `protobuf:"varint,4,opt,name=key_version,json=keyVersion" json:"key_version,omitempty"`
}

func (*QueryRequest) Descriptor

func (*QueryRequest) Descriptor() ([]byte, []int)

func (*QueryRequest) GetApp

func (m *QueryRequest) GetApp() string

func (*QueryRequest) GetKey

func (m *QueryRequest) GetKey() string

func (*QueryRequest) GetKeyVersion

func (m *QueryRequest) GetKeyVersion() int64

func (*QueryRequest) GetProfile

func (m *QueryRequest) GetProfile() string

func (*QueryRequest) ProtoMessage

func (*QueryRequest) ProtoMessage()

func (*QueryRequest) Reset

func (m *QueryRequest) Reset()

func (*QueryRequest) String

func (m *QueryRequest) String() string

type QueryResponse

type QueryResponse struct {
	Result []*ResponseMessage `protobuf:"bytes,1,rep,name=result" json:"result,omitempty"`
}

func (*QueryResponse) Descriptor

func (*QueryResponse) Descriptor() ([]byte, []int)

func (*QueryResponse) GetResult

func (m *QueryResponse) GetResult() []*ResponseMessage

func (*QueryResponse) ProtoMessage

func (*QueryResponse) ProtoMessage()

func (*QueryResponse) Reset

func (m *QueryResponse) Reset()

func (*QueryResponse) String

func (m *QueryResponse) String() string

type RegisterRequest

type RegisterRequest struct {
	App      string `protobuf:"bytes,1,opt,name=app" json:"app,omitempty"`
	Profile  string `protobuf:"bytes,2,opt,name=profile" json:"profile,omitempty"`
	ServerIp string `protobuf:"bytes,3,opt,name=server_ip,json=serverIp" json:"server_ip,omitempty"`
	Pid      string `protobuf:"bytes,4,opt,name=pid" json:"pid,omitempty"`
}

func (*RegisterRequest) Descriptor

func (*RegisterRequest) Descriptor() ([]byte, []int)

func (*RegisterRequest) GetApp

func (m *RegisterRequest) GetApp() string

func (*RegisterRequest) GetPid

func (m *RegisterRequest) GetPid() string

func (*RegisterRequest) GetProfile

func (m *RegisterRequest) GetProfile() string

func (*RegisterRequest) GetServerIp

func (m *RegisterRequest) GetServerIp() string

func (*RegisterRequest) ProtoMessage

func (*RegisterRequest) ProtoMessage()

func (*RegisterRequest) Reset

func (m *RegisterRequest) Reset()

func (*RegisterRequest) String

func (m *RegisterRequest) String() string

type RegisterResponse

type RegisterResponse struct {
	Result int32  `protobuf:"varint,1,opt,name=result" json:"result,omitempty"`
	NodeId string `protobuf:"bytes,2,opt,name=node_id,json=nodeId" json:"node_id,omitempty"`
}

func (*RegisterResponse) Descriptor

func (*RegisterResponse) Descriptor() ([]byte, []int)

func (*RegisterResponse) GetNodeId

func (m *RegisterResponse) GetNodeId() string

func (*RegisterResponse) GetResult

func (m *RegisterResponse) GetResult() int32

func (*RegisterResponse) ProtoMessage

func (*RegisterResponse) ProtoMessage()

func (*RegisterResponse) Reset

func (m *RegisterResponse) Reset()

func (*RegisterResponse) String

func (m *RegisterResponse) String() string

type ResponseMessage

type ResponseMessage struct {
	Key     string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"`
	Profile string `protobuf:"bytes,2,opt,name=profile" json:"profile,omitempty"`
	Path    string `protobuf:"bytes,3,opt,name=path" json:"path,omitempty"`
	Value   string `protobuf:"bytes,4,opt,name=value" json:"value,omitempty"`
	Version int64  `protobuf:"varint,5,opt,name=version" json:"version,omitempty"`
}

func (*ResponseMessage) Descriptor

func (*ResponseMessage) Descriptor() ([]byte, []int)

func (*ResponseMessage) GetKey

func (m *ResponseMessage) GetKey() string

func (*ResponseMessage) GetPath

func (m *ResponseMessage) GetPath() string

func (*ResponseMessage) GetProfile

func (m *ResponseMessage) GetProfile() string

func (*ResponseMessage) GetValue

func (m *ResponseMessage) GetValue() string

func (*ResponseMessage) GetVersion

func (m *ResponseMessage) GetVersion() int64

func (*ResponseMessage) ProtoMessage

func (*ResponseMessage) ProtoMessage()

func (*ResponseMessage) Reset

func (m *ResponseMessage) Reset()

func (*ResponseMessage) String

func (m *ResponseMessage) String() string

type StringArray

type StringArray []string

func (StringArray) Contains

func (array StringArray) Contains(val string) bool

func (StringArray) Remove

func (array StringArray) Remove(target string) StringArray

type ValueChangeResultRequest

type ValueChangeResultRequest struct {
	NodeId   string                                     `protobuf:"bytes,1,opt,name=node_id,json=nodeId" json:"node_id,omitempty"`
	App      string                                     `protobuf:"bytes,2,opt,name=app" json:"app,omitempty"`
	Profile  string                                     `protobuf:"bytes,3,opt,name=profile" json:"profile,omitempty"`
	Key      string                                     `protobuf:"bytes,4,opt,name=key" json:"key,omitempty"`
	DeployId string                                     `protobuf:"bytes,5,opt,name=deploy_id,json=deployId" json:"deploy_id,omitempty"`
	Result   ValueChangeResultRequest_ValueChangeResult `protobuf:"varint,6,opt,name=result,enum=pb.ValueChangeResultRequest_ValueChangeResult" json:"result,omitempty"`
	Msg      string                                     `protobuf:"bytes,7,opt,name=msg" json:"msg,omitempty"`
	Version  int64                                      `protobuf:"varint,8,opt,name=version" json:"version,omitempty"`
}

func (*ValueChangeResultRequest) Descriptor

func (*ValueChangeResultRequest) Descriptor() ([]byte, []int)

func (*ValueChangeResultRequest) GetApp

func (m *ValueChangeResultRequest) GetApp() string

func (*ValueChangeResultRequest) GetDeployId

func (m *ValueChangeResultRequest) GetDeployId() string

func (*ValueChangeResultRequest) GetKey

func (m *ValueChangeResultRequest) GetKey() string

func (*ValueChangeResultRequest) GetMsg

func (m *ValueChangeResultRequest) GetMsg() string

func (*ValueChangeResultRequest) GetNodeId

func (m *ValueChangeResultRequest) GetNodeId() string

func (*ValueChangeResultRequest) GetProfile

func (m *ValueChangeResultRequest) GetProfile() string

func (*ValueChangeResultRequest) GetResult

func (*ValueChangeResultRequest) GetVersion

func (m *ValueChangeResultRequest) GetVersion() int64

func (*ValueChangeResultRequest) ProtoMessage

func (*ValueChangeResultRequest) ProtoMessage()

func (*ValueChangeResultRequest) Reset

func (m *ValueChangeResultRequest) Reset()

func (*ValueChangeResultRequest) String

func (m *ValueChangeResultRequest) String() string

type ValueChangeResultRequest_ValueChangeResult

type ValueChangeResultRequest_ValueChangeResult int32
const (
	ValueChangeResultRequest_FAILED  ValueChangeResultRequest_ValueChangeResult = 0
	ValueChangeResultRequest_SUCCESS ValueChangeResultRequest_ValueChangeResult = 1
)

func (ValueChangeResultRequest_ValueChangeResult) EnumDescriptor

func (ValueChangeResultRequest_ValueChangeResult) EnumDescriptor() ([]byte, []int)

func (ValueChangeResultRequest_ValueChangeResult) String

type ValueChangeResultResponse

type ValueChangeResultResponse struct {
	Status int32  `protobuf:"varint,1,opt,name=status" json:"status,omitempty"`
	Msg    string `protobuf:"bytes,2,opt,name=msg" json:"msg,omitempty"`
}

func (*ValueChangeResultResponse) Descriptor

func (*ValueChangeResultResponse) Descriptor() ([]byte, []int)

func (*ValueChangeResultResponse) GetMsg

func (m *ValueChangeResultResponse) GetMsg() string

func (*ValueChangeResultResponse) GetStatus

func (m *ValueChangeResultResponse) GetStatus() int32

func (*ValueChangeResultResponse) ProtoMessage

func (*ValueChangeResultResponse) ProtoMessage()

func (*ValueChangeResultResponse) Reset

func (m *ValueChangeResultResponse) Reset()

func (*ValueChangeResultResponse) String

func (m *ValueChangeResultResponse) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL