25
25
import com .alibaba .nacos .common .utils .JacksonUtils ;
26
26
import com .alibaba .nacos .core .utils .WebUtils ;
27
27
import com .alibaba .nacos .naming .core .Instance ;
28
- import com .alibaba .nacos .naming .core .InstanceService ;
28
+ import com .alibaba .nacos .naming .core .InstanceOperatorClientImpl ;
29
29
import com .alibaba .nacos .naming .core .Service ;
30
30
import com .alibaba .nacos .naming .core .ServiceManager ;
31
31
import com .alibaba .nacos .naming .healthcheck .RsInfo ;
71
71
*/
72
72
@ RestController
73
73
@ RequestMapping (UtilsAndCommons .NACOS_NAMING_CONTEXT + "/instance" )
74
- @ SuppressWarnings ("PMD.RemoveCommentedCodeRule" )
75
74
public class InstanceController {
76
75
77
76
@ Autowired
@@ -84,8 +83,12 @@ public class InstanceController {
84
83
private ServiceManager serviceManager ;
85
84
86
85
@ Autowired
87
- private InstanceService instanceService ;
86
+ private InstanceOperatorClientImpl instanceService ;
88
87
88
+ /**
89
+ * Move to {@link com.alibaba.nacos.naming.core.InstanceOperatorServiceImpl}.
90
+ */
91
+ @ Deprecated
89
92
private DataSource pushDataSource = new DataSource () {
90
93
91
94
@ Override
@@ -126,7 +129,6 @@ public String register(HttpServletRequest request) throws Exception {
126
129
127
130
final Instance instance = parseInstance (request );
128
131
129
- // serviceManager.registerInstance(namespaceId, serviceName, instance);
130
132
instanceService .registerInstance (namespaceId , serviceName , instance );
131
133
return "ok" ;
132
134
}
@@ -147,13 +149,6 @@ public String deregister(HttpServletRequest request) throws Exception {
147
149
String serviceName = WebUtils .required (request , CommonParams .SERVICE_NAME );
148
150
checkServiceNameFormat (serviceName );
149
151
150
- // Service service = serviceManager.getService(namespaceId, serviceName);
151
- // if (service == null) {
152
- // Loggers.SRV_LOG.warn("remove instance from non-exist service: {}", serviceName);
153
- // return "ok";
154
- // }
155
- // serviceManager.removeInstance(namespaceId, serviceName, instance.isEphemeral(), instance);
156
-
157
152
instanceService .removeInstance (namespaceId , serviceName , instance );
158
153
return "ok" ;
159
154
}
@@ -259,20 +254,17 @@ public Object list(HttpServletRequest request) throws Exception {
259
254
String clusters = WebUtils .optional (request , "clusters" , StringUtils .EMPTY );
260
255
String clientIP = WebUtils .optional (request , "clientIP" , StringUtils .EMPTY );
261
256
int udpPort = Integer .parseInt (WebUtils .optional (request , "udpPort" , "0" ));
262
- String env = WebUtils .optional (request , "env" , StringUtils .EMPTY );
257
+ boolean healthyOnly = Boolean .parseBoolean (WebUtils .optional (request , "healthyOnly" , "false" ));
258
+
263
259
boolean isCheck = Boolean .parseBoolean (WebUtils .optional (request , "isCheck" , "false" ));
264
260
265
261
String app = WebUtils .optional (request , "app" , StringUtils .EMPTY );
266
-
262
+ String env = WebUtils . optional ( request , "env" , StringUtils . EMPTY );
267
263
String tenant = WebUtils .optional (request , "tid" , StringUtils .EMPTY );
268
264
269
- boolean healthyOnly = Boolean .parseBoolean (WebUtils .optional (request , "healthyOnly" , "false" ));
270
-
271
265
Subscriber subscriber =
272
- udpPort > 0 ? new Subscriber (clientIP + ":" + udpPort , agent , app , clientIP , namespaceId , serviceName )
273
- : null ;
274
- // return doSrvIpxt(namespaceId, serviceName, agent, clusters, clientIP, udpPort, env, isCheck, app, tenant,
275
- // healthyOnly);
266
+ udpPort > 0 ? new Subscriber (clientIP + ":" + udpPort , agent , app , clientIP , namespaceId , serviceName ,
267
+ udpPort ) : null ;
276
268
return instanceService .listInstance (namespaceId , serviceName , subscriber , clusters , healthyOnly );
277
269
}
278
270
@@ -365,47 +357,6 @@ public ObjectNode beat(HttpServletRequest request) throws Exception {
365
357
checkServiceNameFormat (serviceName );
366
358
Loggers .SRV_LOG .debug ("[CLIENT-BEAT] full arguments: beat: {}, serviceName: {}" , clientBeat , serviceName );
367
359
368
- // Instance instance = serviceManager.getInstance(namespaceId, serviceName, clusterName, ip, port);
369
- //
370
- // if (instance == null) {
371
- // if (clientBeat == null) {
372
- // result.put(CommonParams.CODE, NamingResponseCode.RESOURCE_NOT_FOUND);
373
- // return result;
374
- // }
375
- //
376
- // Loggers.SRV_LOG.warn("[CLIENT-BEAT] The instance has been removed for health mechanism, "
377
- // + "perform data compensation operations, beat: {}, serviceName: {}", clientBeat, serviceName);
378
- //
379
- // instance = new Instance();
380
- // instance.setPort(clientBeat.getPort());
381
- // instance.setIp(clientBeat.getIp());
382
- // instance.setWeight(clientBeat.getWeight());
383
- // instance.setMetadata(clientBeat.getMetadata());
384
- // instance.setClusterName(clusterName);
385
- // instance.setServiceName(serviceName);
386
- // instance.setInstanceId(instance.getInstanceId());
387
- // instance.setEphemeral(clientBeat.isEphemeral());
388
- //
389
- // serviceManager.registerInstance(namespaceId, serviceName, instance);
390
- // }
391
- //
392
- // Service service = serviceManager.getService(namespaceId, serviceName);
393
- //
394
- // if (service == null) {
395
- // throw new NacosException(NacosException.SERVER_ERROR,
396
- // "service not found: " + serviceName + "@" + namespaceId);
397
- // }
398
- // if (clientBeat == null) {
399
- // clientBeat = new RsInfo();
400
- // clientBeat.setIp(ip);
401
- // clientBeat.setPort(port);
402
- // clientBeat.setCluster(clusterName);
403
- // }
404
- // service.processClientBeat(clientBeat);
405
- // result.put(CommonParams.CODE, NamingResponseCode.OK);
406
- // if (instance.containsMetadata(PreservedMetadataKeys.HEART_BEAT_INTERVAL)) {
407
- // result.put(SwitchEntry.CLIENT_BEAT_INTERVAL, instance.getInstanceHeartBeatInterval());
408
- // }
409
360
int resultCode = instanceService .handleBeat (namespaceId , serviceName , ip , port , clusterName , clientBeat );
410
361
result .put (CommonParams .CODE , resultCode );
411
362
result .put (SwitchEntry .CLIENT_BEAT_INTERVAL ,
@@ -550,7 +501,10 @@ private void checkIfDisabled(Service service) throws Exception {
550
501
* @param healthyOnly whether only for healthy check
551
502
* @return service full information with instances
552
503
* @throws Exception any error during handle
504
+ * @deprecated will be replace by {@link com.alibaba.nacos.naming.core.InstanceOperator#listInstance(String, String,
505
+ * Subscriber, String, boolean)}
553
506
*/
507
+ @ Deprecated
554
508
public ObjectNode doSrvIpxt (String namespaceId , String serviceName , String agent , String clusters , String clientIP ,
555
509
int udpPort , String env , boolean isCheck , String app , String tid , boolean healthyOnly ) throws Exception {
556
510
0 commit comments