Skip to content

Commit

Permalink
[type:feat]fix upstreamCheck (apache#5742)
Browse files Browse the repository at this point in the history
* fix

* fix

---------

Co-authored-by: ‘xcsnx’ <‘1192709687@qq.com’>
Co-authored-by: aias00 <rokkki@163.com>
Co-authored-by: moremind <hefengen@apache.org>
  • Loading branch information
4 people authored Nov 5, 2024
1 parent 273ac4c commit 376e76b
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ public interface SelectorMapper extends ExistProvider {
*/
List<SelectorDO> findByPluginIdsAndNamespaceId(@Param("list") List<String> pluginIds, String namespaceId);

/**
* Find list by plugin id.
*
* @param pluginIds the plugin ids
* @return the list
*/
List<SelectorDO> findByPluginIds(@Param("list") List<String> pluginIds);

/**
* select list by name and namespaceId.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ public int updateSelective(final SelectorDO selectorDO) {
@Override
@Transactional(rollbackFor = Exception.class)
public int deleteByNamespaceId(final List<String> ids, final String namespaceId) {
//todo:[Namespace] To be renovated
final List<SelectorDO> selectors = selectorMapper.selectByIdSet(new TreeSet<>(ids));
List<PluginDO> pluginDOS = pluginMapper.selectByIds(ListUtil.map(selectors, SelectorDO::getPluginId));
unbindDiscovery(selectors, pluginDOS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ public SyncDataServiceImpl(final AppAuthService appAuthService,
this.discoveryService = discoveryService;
}

//todo:[Namespace] Synchronize based on namespaceId
@Override
public boolean syncAll(final DataEventTypeEnum type) {
appAuthService.syncData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import static org.apache.shenyu.common.constant.Constants.SYS_DEFAULT_NAMESPACE_ID;

/**
* This is the upstream check service.
*/
Expand Down Expand Up @@ -447,8 +445,7 @@ public void fetchUpstreamData() {
}
Map<String, String> pluginMap = pluginDOList.stream().filter(Objects::nonNull)
.collect(Collectors.toMap(PluginDO::getId, PluginDO::getName, (value1, value2) -> value1));
// todo:[To be refactored with namespace] Temporarily hardcode
final List<SelectorDO> selectorDOList = selectorMapper.findByPluginIdsAndNamespaceId(new ArrayList<>(pluginMap.keySet()), SYS_DEFAULT_NAMESPACE_ID);
final List<SelectorDO> selectorDOList = selectorMapper.findByPluginIds(new ArrayList<>(pluginMap.keySet()));
long currentTimeMillis = System.currentTimeMillis();
Optional.ofNullable(selectorDOList).orElseGet(ArrayList::new).stream()
.filter(Objects::nonNull)
Expand Down
10 changes: 10 additions & 0 deletions shenyu-admin/src/main/resources/mappers/selector-sqlmap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,16 @@
AND namespace_id = #{namespaceId, jdbcType=VARCHAR}
</select>

<select id="findByPluginIds" parameterType="java.util.List" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List"/>
FROM selector
WHERE plugin_id IN
<foreach item="id" collection="list" open="(" separator="," close=")">
#{id, jdbcType=VARCHAR}
</foreach>
</select>

<select id="countByQuery" parameterType="org.apache.shenyu.admin.model.query.SelectorQuery"
resultType="java.lang.Integer">
SELECT COUNT(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,11 @@
import java.util.Set;
import java.util.concurrent.ScheduledThreadPoolExecutor;

import static org.hamcrest.Matchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mockStatic;
Expand Down Expand Up @@ -258,7 +257,7 @@ public void testFetchUpstreamData() {
.status(0)
.build();
when(pluginMapper.selectByNames(anyList())).thenReturn(Lists.newArrayList(pluginDO));
when(selectorMapper.findByPluginIdsAndNamespaceId(anyList(), any())).thenReturn(Lists.newArrayList(selectorDOWithUrlError, selectorDOWithUrlReachable));
when(selectorMapper.findByPluginIds(anyList())).thenReturn(Lists.newArrayList(selectorDOWithUrlError, selectorDOWithUrlReachable));
when(discoveryUpstreamService.findBySelectorId(anyString())).thenReturn(Lists.newArrayList(discoveryUpstreamData));
upstreamCheckService.fetchUpstreamData();
assertTrue(upstreamMap.containsKey(MOCK_SELECTOR_NAME));
Expand Down

0 comments on commit 376e76b

Please sign in to comment.