4646import com .tencent .polaris .client .util .NamedThreadFactory ;
4747import com .tencent .polaris .logging .LoggerFactory ;
4848import com .tencent .polaris .plugins .connector .common .ServiceUpdateTask ;
49+ import com .tencent .polaris .specification .api .v1 .model .ModelProto .Location ;
4950import com .tencent .polaris .specification .api .v1 .service .manage .ResponseProto ;
5051import com .tencent .polaris .specification .api .v1 .service .manage .ServiceProto ;
5152import java .nio .charset .StandardCharsets ;
@@ -112,8 +113,8 @@ public void asyncGetInstances(ServiceUpdateTask serviceUpdateTask) {
112113 .setHost (StringValue .of (nacosInstance .getIp ()))
113114 .setPort (UInt32Value .of (nacosInstance .getPort ()))
114115 .setHealthy (BoolValue .of (nacosInstance .isHealthy ()))
115- .setIsolate (BoolValue .of (false ))
116- .setWeight (UInt32Value .of ((int ) nacosInstance .getWeight ()));
116+ .setIsolate (BoolValue .of (! nacosInstance . isEnabled () ))
117+ .setWeight (UInt32Value .of (100 * (int ) nacosInstance .getWeight ()));
117118 if (StringUtils .isNotBlank (nacosInstance .getInstanceId ())) {
118119 instanceBuilder .setId (StringValue .of (nacosInstance .getInstanceId ()));
119120 } else {
@@ -132,6 +133,31 @@ public void asyncGetInstances(ServiceUpdateTask serviceUpdateTask) {
132133 .putMetadata ("nacos.group" , nacosContext .getGroupName ())
133134 .putMetadata ("nacos.ephemeral" , String .valueOf (nacosInstance .isEphemeral ()));
134135 }
136+ String protocol = metadata .getOrDefault ("protocol" , "" );
137+ String version = metadata .getOrDefault ("version" , "" );
138+ if (StringUtils .isNotEmpty (protocol )) {
139+ instanceBuilder .setProtocol (StringValue .of (protocol ));
140+ }
141+ if (StringUtils .isNotEmpty (version )) {
142+ instanceBuilder .setVersion (StringValue .of (version ));
143+ }
144+
145+ String region = metadata .getOrDefault ("region" , "" );
146+ String zone = metadata .getOrDefault ("zone" , "" );
147+ String campus = metadata .getOrDefault ("campus" , "" );
148+ instanceBuilder .putMetadata (SERVER_CONNECTOR_TYPE , SERVER_CONNECTOR_NACOS );
149+ Location .Builder locationBuilder = Location .newBuilder ();
150+ if (StringUtils .isNotEmpty (region )) {
151+ locationBuilder .setRegion (StringValue .of (region ));
152+ }
153+ if (StringUtils .isNotEmpty (zone )) {
154+ locationBuilder .setZone (StringValue .of (zone ));
155+ }
156+ if (StringUtils .isNotEmpty (campus )) {
157+ locationBuilder .setCampus (StringValue .of (campus ));
158+ }
159+
160+ instanceBuilder .setLocation (locationBuilder .build ());
135161 instanceBuilder .setNamespace (
136162 StringValue .of (serviceUpdateTask .getServiceEventKey ().getNamespace ()));
137163
@@ -281,7 +307,8 @@ protected void doDestroy() {
281307 try {
282308 namingService .unsubscribe (entry .getKey (), nacosContext .getGroupName (), entry .getValue ());
283309 } catch (NacosException e ) {
284- LOG .error ("[NacosConnector] unsubscribe service {} in group {} failed. " , entry .getKey (), nacosContext .getGroupName ());
310+ LOG .error ("[NacosConnector] unsubscribe service {} in group {} failed. " , entry .getKey (),
311+ nacosContext .getGroupName ());
285312 }
286313 }
287314 ThreadPoolUtils .waitAndStopThreadPools (new ExecutorService []{refreshExecutor });
0 commit comments