moremind commented on code in PR #5659:
URL: https://github.com/apache/shenyu/pull/5659#discussion_r1809028133


##########
shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImpl.java:
##########
@@ -196,7 +200,43 @@ public String doRegisterURI(final String selectorName, 
final List<URIRegisterDTO
         }
         return ShenyuResultMessage.SUCCESS;
     }
-
+    
+    @Override
+    public String doHeartbeat(final String selectorName, final 
List<URIRegisterDTO> uriList) {
+        if (CollectionUtils.isEmpty(uriList)) {
+            return "";
+        }
+        String pluginName = PluginNameAdapter.rpcTypeAdapter(rpcType());
+        // todo:[To be refactored with namespace] Temporarily hardcode
+        SelectorDO selectorDO = 
selectorService.findByNameAndPluginNameAndNamespaceId(selectorName, pluginName, 
SYS_DEFAULT_NAMESPACE_ID);
+        if (Objects.isNull(selectorDO)) {
+            throw new ShenyuException("doHeartbeat Failed to execute,wait to 
retry.");
+        }
+        // fetch UPSTREAM_MAP data from db
+        //upstreamCheckService.fetchUpstreamData();
+        //update upstream
+        List<URIRegisterDTO> validUriList = uriList.stream().filter(dto -> 
Objects.nonNull(dto.getPort()) && 
StringUtils.isNotBlank(dto.getHost())).toList();
+        if (CollectionUtils.isEmpty(validUriList)) {
+            return null;
+        }
+        // discovery publish change event.
+        String selectorId = selectorDO.getId();
+        // change live node status to TRUE
+        validUriList.forEach(uriRegisterDTO -> {
+            DiscoveryUpstreamDTO discoveryUpstreamDTO = 
CommonUpstreamUtils.buildDefaultDiscoveryUpstreamDTO(uriRegisterDTO.getHost(),
+                    uriRegisterDTO.getPort(),
+                    uriRegisterDTO.getProtocol(),
+                    uriRegisterDTO.getNamespaceId());
+            LOG.info("change alive selectorId={}|url={}", selectorId, 
discoveryUpstreamDTO.getUrl());
+            
discoveryUpstreamService.changeStatusBySelectorIdAndUrl(selectorId, 
discoveryUpstreamDTO.getUrl(), Boolean.TRUE);
+        });
+        
+        DiscoverySyncData discoverySyncData = fetch(selectorId, 
selectorDO.getName(), pluginName, SYS_DEFAULT_NAMESPACE_ID);

Review Comment:
   same question



##########
shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImpl.java:
##########
@@ -196,7 +200,43 @@ public String doRegisterURI(final String selectorName, 
final List<URIRegisterDTO
         }
         return ShenyuResultMessage.SUCCESS;
     }
-
+    
+    @Override
+    public String doHeartbeat(final String selectorName, final 
List<URIRegisterDTO> uriList) {
+        if (CollectionUtils.isEmpty(uriList)) {
+            return "";
+        }
+        String pluginName = PluginNameAdapter.rpcTypeAdapter(rpcType());
+        // todo:[To be refactored with namespace] Temporarily hardcode
+        SelectorDO selectorDO = 
selectorService.findByNameAndPluginNameAndNamespaceId(selectorName, pluginName, 
SYS_DEFAULT_NAMESPACE_ID);

Review Comment:
   use request namespaceId



##########
shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/FallbackShenyuClientRegisterServiceTest.java:
##########
@@ -72,7 +77,12 @@ static class 
MockFallbackShenyuClientRegisterServiceException extends FallbackSh
         String doRegisterURI(final String selectorName, final 
List<URIRegisterDTO> uriList) {
             throw new ShenyuException("Exception");
         }
-
+        
+        @Override
+        String doHeartbeat(final String selectorName, final 
List<URIRegisterDTO> uriList) {
+            throw new ShenyuException("Exception");

Review Comment:
   why exception?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to