WillemJiang commented on a change in pull request #704: [SCB-582]Provide a way 
to protect instance removal
URL: 
https://github.com/apache/incubator-servicecomb-java-chassis/pull/704#discussion_r189133149
 
 

 ##########
 File path: 
service-registry/src/main/java/org/apache/servicecomb/serviceregistry/consumer/MicroserviceVersions.java
 ##########
 @@ -169,6 +166,28 @@ private void setInstances(List<MicroserviceInstance> 
pulledInstances, String rev
     }
   }
 
+  private List<MicroserviceInstance> mergeInstances(List<MicroserviceInstance> 
pulledInstances,
+      List<MicroserviceInstance> inUseInstances) {
+    List<MicroserviceInstance> upInstances = pulledInstances
+        .stream()
+        .filter(instance -> {
+          return MicroserviceInstanceStatus.UP.equals(instance.getStatus());
+        })
+        .collect(Collectors.toList());
+    if (upInstances.isEmpty() && inUseInstances != null && 
ServiceRegistryConfig.INSTANCE.isEmptyInstanceProtectionEnabled()) {
+      MicroserviceInstancePing ping = 
SPIServiceUtils.getPriorityHighestService(MicroserviceInstancePing.class);
+      inUseInstances.stream()
+          .forEach(instance -> {
+            if (!upInstances.contains(instance)) {
+              if (ping.ping(instance)) {
 
 Review comment:
   As the ping method could take some time. It could take a while if there are 
lots of upInstances need to be merged.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to