eurekaserver

package
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 42 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ParamAppId      string = "appId"
	ParamInstId     string = "instId"
	ParamValue      string = "value"
	ParamVip        string = "vipAddress"
	ParamSVip       string = "svipAddress"
	HeaderNamespace string = "x-namespace"
)
View Source
const (
	DefaultNamespace            = "default"
	DefaultRefreshInterval      = 10
	DefaultDetailExpireInterval = 60
	// DefaultEnableSelfPreservation whether to enable preservation mechanism
	DefaultEnableSelfPreservation = true
	// DefaultSelfPreservationPercent instances unhealthy percent over 85% (around 15 min instances),
	// it will return all checked instances
	DefaultSelfPreservationPercent = 85
	// DefaultSelfPreservationDuration instance unhealthy check point to preservation,
	// instances over 15 min won't get preservation
	DefaultSelfPreservationDuration = 15 * time.Minute
	DefaultListenIP                 = "0.0.0.0"
	DefaultListenPort               = 8761
)
View Source
const (
	SecureProtocol   = "HTTPS"
	InsecureProtocol = "HTTP"

	MetadataRegisterFrom        = "internal-register-from"
	MetadataAppGroupName        = "internal-eureka-app-group"
	MetadataCountryId           = "internal-eureka-country-id"
	MetadataDataCenterInfoClazz = "internal-eureka-dci-clazz"
	MetadataDataCenterInfoName  = "internal-eureka-dci-name"
	MetadataHostName            = "internal-eureka-hostname"
	MetadataRenewalInterval     = "internal-eureka-renewal-interval"
	MetadataDuration            = "internal-eureka-duration"
	MetadataHomePageUrl         = "internal-eureka-home-url"
	MetadataStatusPageUrl       = "internal-eureka-status-url"
	MetadataHealthCheckUrl      = "internal-eureka-health-url"
	MetadataVipAddress          = "internal-eureka-vip"
	MetadataSecureVipAddress    = "internal-eureka-secure-vip"
	MetadataInsecurePort        = "internal-eureka-insecure-port"
	MetadataInsecurePortEnabled = "internal-eureka-insecure-port-enabled"
	MetadataSecurePort          = "internal-eureka-secure-port"
	MetadataSecurePortEnabled   = "internal-eureka-secure-port-enabled"
	MetadataReplicate           = "internal-eureka-replicate"
	MetadataInstanceId          = "internal-eureka-instance-id"

	InternalMetadataStatus           = "internal-eureka-status"
	InternalMetadataOverriddenStatus = "internal-eureka-overriddenStatus"

	ServerEureka = "eureka"

	KeyRegion = "region"

	StatusOutOfService = "OUT_OF_SERVICE"
	StatusUp           = "UP"
	StatusDown         = "DOWN"
	StatusUnknown      = "UNKNOWN"

	ActionAdded    = "ADDED"
	ActionModified = "MODIFIED"
	ActionDeleted  = "DELETED"

	DefaultCountryIdInt            = 1
	DefaultDciClazz                = "com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo"
	DefaultDciName                 = "MyOwn"
	DefaultRenewInterval           = 30
	DefaultDuration                = 90
	DefaultUnhealthyExpireInterval = 180

	DefaultOwner        = "polaris"
	DefaultSSLPort      = 443
	DefaultInsecurePort = 8080

	CustomKeyDciClass = "dataCenterInfoClass"
	CustomKeyDciName  = "dataCenterInfoName"
)
View Source
const (
	MimeJsonWild = "application/*+json"
)

Variables

View Source
var (
	DefaultDataCenterInfo = &DataCenterInfo{
		Clazz: DefaultDciClazz,
		Name:  DefaultDciName,
	}
	DefaultCountryId = strconv.Itoa(DefaultCountryIdInt)

	CustomEurekaParameters = make(map[string]string)
)

Functions

func CastNanInf

func CastNanInf(b bool)

Cast "Nan", "Inf", "-Inf" XML values to 'float64'. By default, these values will be decoded as 'string'.

func ObjectToString

func ObjectToString(value interface{}) string

ObjectToString interface type to string

func RateLimitResponse

func RateLimitResponse(rsp *restful.Response)

RateLimitResponse http答复简单封装

Types

type Application

type Application struct {
	XMLName struct{} `json:"-" xml:"application"`

	Name string `json:"name" xml:"name"`

	Instance []*InstanceInfo `json:"instance" xml:"instance"`

	InstanceMap map[string]*InstanceInfo `json:"-" xml:"-"`

	Revision string `json:"-" xml:"-"`

	StatusCounts map[string]int `json:"-" xml:"-"`
}

Application 服务数据

func (*Application) GetInstance

func (a *Application) GetInstance(instId string) *InstanceInfo

GetInstance 获取eureka实例

type ApplicationResponse

type ApplicationResponse struct {
	Application *Application `json:"application"`
}

ApplicationResponse 单个服务拉取响应

type Applications

type Applications struct {
	XMLName struct{} `json:"-" xml:"applications"`

	VersionsDelta string `json:"versions__delta" xml:"versions__delta"`

	AppsHashCode string `json:"apps__hashcode" xml:"apps__hashcode"`

	Application []*Application `json:"application" xml:"application"`

	ApplicationMap map[string]*Application `json:"-" xml:"-"`
}

Applications 服务列表

func (*Applications) GetApplication

func (a *Applications) GetApplication(appId string) *Application

GetApplication 获取eureka应用

func (*Applications) GetInstance

func (a *Applications) GetInstance(instId string) *InstanceInfo

GetInstance get instance by instanceId

type ApplicationsBuilder

type ApplicationsBuilder struct {

	// autoincrement version
	VersionIncrement int64
	// contains filtered or unexported fields
}

ApplicationsBuilder builder to do application construct

func (*ApplicationsBuilder) BuildApplications

func (a *ApplicationsBuilder) BuildApplications(oldAppsCache *ApplicationsRespCache) *ApplicationsRespCache

BuildApplications build applications cache with compare to the latest cache

type ApplicationsRespCache

type ApplicationsRespCache struct {
	AppsResp  *ApplicationsResponse
	Revision  string
	JsonBytes []byte
	XmlBytes  []byte
	// contains filtered or unexported fields
}

ApplicationsRespCache 全量服务缓存

func BuildApplicationsForVip

func BuildApplicationsForVip(key *VipCacheKey, appsCache *ApplicationsRespCache) *ApplicationsRespCache

BuildApplicationsForVip build applications with target vip

type ApplicationsResponse

type ApplicationsResponse struct {
	Applications *Applications `json:"applications"`
}

ApplicationsResponse 服务拉取应答

type ApplicationsWorker

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

ApplicationsWorker 应用缓存协程

func NewApplicationsWorker

func NewApplicationsWorker(interval time.Duration,
	deltaExpireInterval time.Duration, enableSelfPreservation bool,
	namingServer service.DiscoverServer, healthCheckServer *healthcheck.Server, namespace string) *ApplicationsWorker

NewApplicationsWorker 构造函数

func (*ApplicationsWorker) GetCachedAppsWithLoad

func (a *ApplicationsWorker) GetCachedAppsWithLoad() *ApplicationsRespCache

GetCachedAppsWithLoad 从缓存中获取全量服务信息,如果不存在就读取

func (*ApplicationsWorker) GetDeltaApps

func (a *ApplicationsWorker) GetDeltaApps() *ApplicationsRespCache

GetDeltaApps 从缓存获取增量服务数据

func (*ApplicationsWorker) GetVipApps

GetVipApps 从缓存中读取VIP资源

func (*ApplicationsWorker) IsStarted

func (a *ApplicationsWorker) IsStarted() bool

IsStarted 是否已经启动

func (*ApplicationsWorker) StartWorker

func (a *ApplicationsWorker) StartWorker() context.Context

StartWorker 启动缓存构建器

func (*ApplicationsWorker) Stop

func (a *ApplicationsWorker) Stop()

Stop 结束任务

type ApplicationsWorkers added in v1.17.0

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

func NewApplicationsWorkers added in v1.17.0

func NewApplicationsWorkers(interval time.Duration,
	deltaExpireInterval time.Duration, enableSelfPreservation bool,
	namingServer service.DiscoverServer, healthCheckServer *healthcheck.Server,
	namespaces ...string) *ApplicationsWorkers

func (*ApplicationsWorkers) Get added in v1.17.0

func (a *ApplicationsWorkers) Get(namespace string) *ApplicationsWorker

func (*ApplicationsWorkers) Stop added in v1.17.0

func (a *ApplicationsWorkers) Stop()

type DataCenterInfo

type DataCenterInfo struct {
	Clazz string `json:"@class" xml:"class,attr"`

	Name string `json:"name" xml:"name"`
}

DataCenterInfo 数据中心信息

type EurekaInstanceChain added in v1.17.6

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

func (*EurekaInstanceChain) AfterUpdate added in v1.17.6

func (c *EurekaInstanceChain) AfterUpdate(ctx context.Context, instances ...*model.Instance)

type EurekaInstanceEventHandler added in v1.15.0

type EurekaInstanceEventHandler struct {
	*service.BaseInstanceEventHandler
	// contains filtered or unexported fields
}

func (*EurekaInstanceEventHandler) OnEvent added in v1.15.0

func (e *EurekaInstanceEventHandler) OnEvent(ctx context.Context, any2 any) error

type EurekaServer

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

EurekaServer is the Eureka server

func (*EurekaServer) BatchReplication

func (h *EurekaServer) BatchReplication(req *restful.Request, rsp *restful.Response)

BatchReplication do the server request replication

func (*EurekaServer) CancelInstance

func (h *EurekaServer) CancelInstance(req *restful.Request, rsp *restful.Response)

CancelInstance 实例反注册

func (*EurekaServer) DeleteStatus

func (h *EurekaServer) DeleteStatus(req *restful.Request, rsp *restful.Response)

DeleteStatus 关闭强制隔离

func (*EurekaServer) GetAllApplications

func (h *EurekaServer) GetAllApplications(req *restful.Request, rsp *restful.Response)

GetAllApplications 全量拉取服务实例信息

func (*EurekaServer) GetAppInstance

func (h *EurekaServer) GetAppInstance(req *restful.Request, rsp *restful.Response)

GetAppInstance 拉取应用下某个实例的信息

func (*EurekaServer) GetApplication

func (h *EurekaServer) GetApplication(req *restful.Request, rsp *restful.Response)

GetApplication 拉取单个服务实例信息

func (*EurekaServer) GetDeltaApplications

func (h *EurekaServer) GetDeltaApplications(req *restful.Request, rsp *restful.Response)

GetDeltaApplications 增量拉取服务实例信息

func (*EurekaServer) GetEurekaServer

func (h *EurekaServer) GetEurekaServer() *restful.WebService

GetEurekaServer eureka web server

func (*EurekaServer) GetEurekaV1Server

func (h *EurekaServer) GetEurekaV1Server() *restful.WebService

GetEurekaV1Server eureka v1 web server

func (*EurekaServer) GetEurekaV2Server

func (h *EurekaServer) GetEurekaV2Server() *restful.WebService

GetEurekaV2Server eureka v2 web server

func (*EurekaServer) GetInstance

func (h *EurekaServer) GetInstance(req *restful.Request, rsp *restful.Response)

GetInstance query instance by id

func (*EurekaServer) GetPort

func (h *EurekaServer) GetPort() uint32

GetPort 获取端口

func (*EurekaServer) GetProtocol

func (h *EurekaServer) GetProtocol() string

GetProtocol 获取协议

func (*EurekaServer) Initialize

func (h *EurekaServer) Initialize(ctx context.Context, option map[string]interface{},
	api map[string]apiserver.APIConfig) error

Initialize 初始化HTTP API服务器

func (*EurekaServer) QueryBySVipAddress

func (h *EurekaServer) QueryBySVipAddress(req *restful.Request, rsp *restful.Response)

QueryBySVipAddress query for all instances under a particular secure vip address

func (*EurekaServer) QueryByVipAddress

func (h *EurekaServer) QueryByVipAddress(req *restful.Request, rsp *restful.Response)

QueryByVipAddress query for all instances under a particular vip address

func (*EurekaServer) RegisterApplication

func (h *EurekaServer) RegisterApplication(req *restful.Request, rsp *restful.Response)

RegisterApplication 服务注册

func (*EurekaServer) RenewInstance

func (h *EurekaServer) RenewInstance(req *restful.Request, rsp *restful.Response)

RenewInstance 更新实例状态

func (*EurekaServer) Restart

func (h *EurekaServer) Restart(
	option map[string]interface{}, api map[string]apiserver.APIConfig, errCh chan error) error

Restart 重启eurekaServer

func (*EurekaServer) Run

func (h *EurekaServer) Run(errCh chan error)

Run 启动HTTP API服务器

func (*EurekaServer) Stop

func (h *EurekaServer) Stop()

Stop 结束eurekaServer的运行

func (*EurekaServer) UpdateMetadata

func (h *EurekaServer) UpdateMetadata(req *restful.Request, rsp *restful.Response)

UpdateMetadata updateStatus instance metadata

func (*EurekaServer) UpdateStatus

func (h *EurekaServer) UpdateStatus(req *restful.Request, rsp *restful.Response)

UpdateStatus 更新服务状态

type InstanceInfo

type InstanceInfo struct {
	XMLName struct{} `json:"-" xml:"instance"`

	InstanceId string `json:"instanceId" xml:"instanceId"`

	AppName string `json:"app" xml:"app"`

	AppGroupName string `json:"appGroupName" xml:"appGroupName,omitempty"`

	IpAddr string `json:"ipAddr" xml:"ipAddr"`

	Sid string `json:"sid" xml:"sid,omitempty"`

	Port *PortWrapper `json:"port" xml:"port,omitempty"`

	SecurePort *PortWrapper `json:"securePort" xml:"securePort,omitempty"`

	HomePageUrl string `json:"homePageUrl" xml:"homePageUrl,omitempty"`

	StatusPageUrl string `json:"statusPageUrl" xml:"statusPageUrl,omitempty"`

	HealthCheckUrl string `json:"healthCheckUrl" xml:"healthCheckUrl,omitempty"`

	SecureHealthCheckUrl string `json:"secureHealthCheckUrl" xml:"secureHealthCheckUrl,omitempty"`

	VipAddress string `json:"vipAddress" xml:"vipAddress,omitempty"`

	SecureVipAddress string `json:"secureVipAddress" xml:"secureVipAddress,omitempty"`

	CountryId interface{} `json:"countryId" xml:"countryId,omitempty"`

	DataCenterInfo *DataCenterInfo `json:"dataCenterInfo" xml:"dataCenterInfo"`

	HostName string `json:"hostName" xml:"hostName,omitempty"`

	Status string `json:"status" xml:"status"`

	OverriddenStatus string `json:"overriddenStatus" xml:"overriddenStatus,omitempty"`

	LeaseInfo *LeaseInfo `json:"leaseInfo" xml:"leaseInfo,omitempty"`

	IsCoordinatingDiscoveryServer interface{} `json:"isCoordinatingDiscoveryServer" xml:"isCoordinatingDiscoveryServer,omitempty"`

	Metadata *Metadata `json:"metadata" xml:"metadata"`

	LastUpdatedTimestamp interface{} `json:"lastUpdatedTimestamp" xml:"lastUpdatedTimestamp,omitempty"`

	LastDirtyTimestamp interface{} `json:"lastDirtyTimestamp" xml:"lastDirtyTimestamp,omitempty"`

	ActionType string `json:"actionType" xml:"actionType"`

	// 实际的北极星实例模型
	RealInstance *apiservice.Instance `json:"-" xml:"-"`
}

InstanceInfo 实例信息

func (*InstanceInfo) Clone

func (i *InstanceInfo) Clone(actionType string) *InstanceInfo

Clone 对实例进行拷贝

func (*InstanceInfo) Equals

func (i *InstanceInfo) Equals(another *InstanceInfo) bool

Equals 判断实例是否发生变更

type InstanceResponse

type InstanceResponse struct {
	InstanceInfo *InstanceInfo `json:"instance" xml:"instance"`
}

InstanceResponse 单个服务实例拉取响应

type Lease added in v1.15.0

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

func (*Lease) Expired added in v1.15.0

func (l *Lease) Expired(curTimeSec int64, deltaExpireInterval time.Duration) bool

Expired check lease expired

type LeaseInfo

type LeaseInfo struct {

	// Client settings
	RenewalIntervalInSecs int `json:"renewalIntervalInSecs" xml:"renewalIntervalInSecs"`

	DurationInSecs int `json:"durationInSecs" xml:"durationInSecs"`

	// Server populated
	RegistrationTimestamp int `json:"registrationTimestamp" xml:"registrationTimestamp"`

	LastRenewalTimestamp int `json:"lastRenewalTimestamp" xml:"lastRenewalTimestamp"`

	EvictionTimestamp int `json:"evictionTimestamp" xml:"evictionTimestamp"`

	ServiceUpTimestamp int `json:"serviceUpTimestamp" xml:"serviceUpTimestamp"`
}

LeaseInfo 租约信息

type Metadata

type Metadata struct {
	Raw []byte `xml:",innerxml" json:"-"`

	Attributes StringMap

	Meta StringMap
}

Metadata 元数据信息,xml 格式无法直接反序列化成 map[string]string 类型。这里通过 []byte 类型的 Raw 接收,并反序列化到 Meta 中。 反序列化后,polaris 在业务中只使用 Meta 字段。

func (*Metadata) MarshalJSON

func (i *Metadata) MarshalJSON() ([]byte, error)

MarshalJSON Metadata json 序列化方法

func (*Metadata) MarshalXML

func (i *Metadata) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML Metadata xml 序列化方法

func (*Metadata) UnmarshalJSON

func (i *Metadata) UnmarshalJSON(b []byte) error

UnmarshalJSON Metadata json 反序列化方法

func (*Metadata) UnmarshalXML

func (i *Metadata) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML Metadata xml 反序列化方法

type PortWrapper

type PortWrapper struct {
	Port interface{} `json:"$" xml:",chardata"`

	RealPort int `json:"-" xml:"-"`

	Enabled interface{} `json:"@enabled" xml:"enabled,attr"`

	RealEnable bool `json:"-" xml:"-"`
}

PortWrapper 端口包装类

func (*PortWrapper) UnmarshalXML

func (p *PortWrapper) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

UnmarshalXML PortWrapper xml 反序列化

type RegistrationRequest

type RegistrationRequest struct {
	Instance *InstanceInfo `json:"instance"`
}

RegistrationRequest 实例注册请求

type ReplicateWorker

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

func NewReplicateWorker

func NewReplicateWorker(ctx context.Context, namespace string, peers []string) *ReplicateWorker

func (*ReplicateWorker) AddReplicateTask

func (r *ReplicateWorker) AddReplicateTask(task *ReplicationInstance)

type ReplicateWorkers added in v1.17.0

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

func NewReplicateWorkers added in v1.17.0

func NewReplicateWorkers(ctx context.Context, namespacePeers map[string][]string) *ReplicateWorkers

func (*ReplicateWorkers) Get added in v1.17.0

func (r *ReplicateWorkers) Get(namespace string) (*ReplicateWorker, bool)

type ReplicationInstance

type ReplicationInstance struct {
	AppName            string        `json:"appName"`
	Id                 string        `json:"id"`
	LastDirtyTimestamp int64         `json:"lastDirtyTimestamp"`
	OverriddenStatus   string        `json:"overriddenStatus"`
	Status             string        `json:"status"`
	InstanceInfo       *InstanceInfo `json:"instanceInfo"`
	Action             string        `json:"action"`
}

ReplicationInstance request for instance replicate

type ReplicationInstanceResponse

type ReplicationInstanceResponse struct {
	StatusCode     int           `json:"statusCode"`
	ResponseEntity *InstanceInfo `json:"responseEntity"`
}

ReplicationInstanceResponse response for instance replicate process

type ReplicationList

type ReplicationList struct {
	ReplicationList []*ReplicationInstance `json:"replicationList"`
}

ReplicationList instances list to replicate

type ReplicationListResponse

type ReplicationListResponse struct {
	ResponseList []*ReplicationInstanceResponse `json:"responseList"`
}

ReplicationListResponse list for replicate instance response

type StringMap

type StringMap map[string]interface{}

StringMap is a map[string]string.

type VipCacheKey

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

VipCacheKey key for reference the vip cache

Jump to

Keyboard shortcuts

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