@@ -23,12 +23,14 @@ import (
23
23
"strconv"
24
24
25
25
"github.com/golang/protobuf/ptypes/wrappers"
26
+ apimodel "github.com/polarismesh/specification/source/go/api/v1/model"
27
+ apiservice "github.com/polarismesh/specification/source/go/api/v1/service_manage"
26
28
27
29
api "github.com/polarismesh/polaris/common/api/v1"
28
30
)
29
31
30
- func buildBaseInstance (instance * InstanceInfo , namespace string , appId string , replicated bool ) * api .Instance {
31
- targetInstance := & api .Instance {}
32
+ func buildBaseInstance (instance * InstanceInfo , namespace string , appId string , replicated bool ) * apiservice .Instance {
33
+ targetInstance := & apiservice .Instance {}
32
34
eurekaMetadata := make (map [string ]string )
33
35
34
36
eurekaMetadata [MetadataRegisterFrom ] = ServerEureka
@@ -74,7 +76,7 @@ func buildBaseInstance(instance *InstanceInfo, namespace string, appId string, r
74
76
targetInstance .Namespace = & wrappers.StringValue {Value : namespace }
75
77
targetInstance .Host = & wrappers.StringValue {Value : instance .IpAddr }
76
78
if instance .Metadata != nil && len (instance .Metadata .Meta ) > 0 {
77
- targetInstance .Location = & api .Location {}
79
+ targetInstance .Location = & apimodel .Location {}
78
80
for k , v := range instance .Metadata .Meta {
79
81
strValue := ObjectToString (v )
80
82
switch k {
@@ -94,7 +96,7 @@ func buildBaseInstance(instance *InstanceInfo, namespace string, appId string, r
94
96
return targetInstance
95
97
}
96
98
97
- func buildHealthCheck (instance * InstanceInfo , targetInstance * api .Instance , eurekaMetadata map [string ]string ) {
99
+ func buildHealthCheck (instance * InstanceInfo , targetInstance * apiservice .Instance , eurekaMetadata map [string ]string ) {
98
100
leaseInfo := instance .LeaseInfo
99
101
var durationInSecs int
100
102
var renewalIntervalInSecs int
@@ -118,13 +120,13 @@ func buildHealthCheck(instance *InstanceInfo, targetInstance *api.Instance, eure
118
120
ttl := uint32 (math .Min (durationMin , float64 (renewalIntervalInSecs )))
119
121
120
122
targetInstance .EnableHealthCheck = & wrappers.BoolValue {Value : true }
121
- targetInstance .HealthCheck = & api .HealthCheck {
122
- Type : api .HealthCheck_HEARTBEAT ,
123
- Heartbeat : & api .HeartbeatHealthCheck {Ttl : & wrappers.UInt32Value {Value : ttl }},
123
+ targetInstance .HealthCheck = & apiservice .HealthCheck {
124
+ Type : apiservice .HealthCheck_HEARTBEAT ,
125
+ Heartbeat : & apiservice .HeartbeatHealthCheck {Ttl : & wrappers.UInt32Value {Value : ttl }},
124
126
}
125
127
}
126
128
127
- func buildStatus (instance * InstanceInfo , targetInstance * api .Instance ) {
129
+ func buildStatus (instance * InstanceInfo , targetInstance * apiservice .Instance ) {
128
130
// 由于eureka的实例都会自动报心跳,心跳由北极星接管,因此客户端报上来的人工状态OUT_OF_SERVICE,通过isolate来进行代替
129
131
status := instance .Status
130
132
if status == "OUT_OF_SERVICE" {
@@ -136,7 +138,8 @@ func buildStatus(instance *InstanceInfo, targetInstance *api.Instance) {
136
138
}
137
139
}
138
140
139
- func convertEurekaInstance (instance * InstanceInfo , namespace string , appId string , replicated bool ) * api.Instance {
141
+ func convertEurekaInstance (
142
+ instance * InstanceInfo , namespace string , appId string , replicated bool ) * apiservice.Instance {
140
143
var secureEnable bool
141
144
var securePort int
142
145
var insecureEnable bool
@@ -185,10 +188,10 @@ func (h *EurekaServer) registerInstances(ctx context.Context, appId string, inst
185
188
}
186
189
// 5. 如果报服务不存在,对服务进行注册
187
190
if resp .Code .Value == api .NotFoundResource {
188
- svc := & api .Service {}
191
+ svc := & apiservice .Service {}
189
192
svc .Namespace = & wrappers.StringValue {Value : h .namespace }
190
193
svc .Name = & wrappers.StringValue {Value : appId }
191
- svcResp := h .namingServer .CreateServices (ctx , []* api .Service {svc })
194
+ svcResp := h .namingServer .CreateServices (ctx , []* apiservice .Service {svc })
192
195
svcCreateCode := svcResp .GetCode ().GetValue ()
193
196
if svcCreateCode != api .ExecuteSuccess && svcCreateCode != api .ExistedResource {
194
197
return svcCreateCode
@@ -201,7 +204,7 @@ func (h *EurekaServer) registerInstances(ctx context.Context, appId string, inst
201
204
}
202
205
203
206
func (h * EurekaServer ) deregisterInstance (ctx context.Context , appId string , instanceId string ) uint32 {
204
- resp := h .namingServer .DeregisterInstance (ctx , & api .Instance {Id : & wrappers.StringValue {Value : instanceId }})
207
+ resp := h .namingServer .DeregisterInstance (ctx , & apiservice .Instance {Id : & wrappers.StringValue {Value : instanceId }})
205
208
return resp .GetCode ().GetValue ()
206
209
}
207
210
@@ -211,12 +214,12 @@ func (h *EurekaServer) updateStatus(ctx context.Context, appId string, instanceI
211
214
isolated = true
212
215
}
213
216
resp := h .namingServer .UpdateInstances (ctx ,
214
- []* api .Instance {{Id : & wrappers.StringValue {Value : instanceId }, Isolate : & wrappers.BoolValue {Value : isolated }}})
217
+ []* apiservice .Instance {{Id : & wrappers.StringValue {Value : instanceId }, Isolate : & wrappers.BoolValue {Value : isolated }}})
215
218
return resp .GetCode ().GetValue ()
216
219
}
217
220
218
221
func (h * EurekaServer ) renew (ctx context.Context , appId string , instanceId string ) uint32 {
219
- resp := h .healthCheckServer .Report (ctx , & api .Instance {Id : & wrappers.StringValue {Value : instanceId }})
222
+ resp := h .healthCheckServer .Report (ctx , & apiservice .Instance {Id : & wrappers.StringValue {Value : instanceId }})
220
223
code := resp .GetCode ().GetValue ()
221
224
222
225
// 如果目标实例存在,但是没有开启心跳,对于 eureka 来说,仍然属于心跳上报成功
@@ -229,6 +232,6 @@ func (h *EurekaServer) renew(ctx context.Context, appId string, instanceId strin
229
232
230
233
func (h * EurekaServer ) updateMetadata (ctx context.Context , instanceId string , metadata map [string ]string ) uint32 {
231
234
resp := h .namingServer .UpdateInstances (ctx ,
232
- []* api .Instance {{Id : & wrappers.StringValue {Value : instanceId }, Metadata : metadata }})
235
+ []* apiservice .Instance {{Id : & wrappers.StringValue {Value : instanceId }, Metadata : metadata }})
233
236
return resp .GetCode ().GetValue ()
234
237
}
0 commit comments