Skip to content

Commit

Permalink
[type:bugfix] proxy.selector and discovery not delete when delete div…
Browse files Browse the repository at this point in the history
…ide selector. (apache#5845)
  • Loading branch information
Wweiei authored Dec 11, 2024
1 parent 5bd99ef commit 7b74602
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@ public void removeProxySelector(final DiscoveryHandlerDTO discoveryHandlerDTO, f
});
}

@Override
public void removeSelectorUpstream(final ProxySelectorDTO proxySelectorDTO) {
DiscoverySyncData discoverySyncData = new DiscoverySyncData();
discoverySyncData.setPluginName(proxySelectorDTO.getPluginName());
discoverySyncData.setSelectorId(proxySelectorDTO.getId());
discoverySyncData.setSelectorName(proxySelectorDTO.getName());
discoverySyncData.setNamespaceId(proxySelectorDTO.getNamespaceId());
DataChangedEvent dataChangedEvent = new DataChangedEvent(ConfigGroupEnum.DISCOVER_UPSTREAM, DataEventTypeEnum.DELETE, Collections.singletonList(discoverySyncData));
eventPublisher.publishEvent(dataChangedEvent);
}

@Override
public void changeUpstream(final ProxySelectorDTO proxySelectorDTO, final List<DiscoveryUpstreamDTO> upstreamDTOS) {
DiscoverySyncData discoverySyncData = new DiscoverySyncData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,11 @@ public interface DiscoveryProcessor {
*/
void fetchAll(DiscoveryHandlerDTO discoveryHandlerDTO, ProxySelectorDTO proxySelectorDTO);

/**
* remove selector upstream.
*
* @param proxySelectorDTO proxySelectorDTO
*/
void removeSelectorUpstream(ProxySelectorDTO proxySelectorDTO);

}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ public void removeProxySelector(final DiscoveryHandlerDTO discoveryHandlerDTO, f
eventPublisher.publishEvent(dataChangedEvent);
}

@Override
public void removeSelectorUpstream(final ProxySelectorDTO proxySelectorDTO) {
DiscoverySyncData discoverySyncData = new DiscoverySyncData();
discoverySyncData.setPluginName(proxySelectorDTO.getPluginName());
discoverySyncData.setSelectorId(proxySelectorDTO.getId());
discoverySyncData.setSelectorName(proxySelectorDTO.getName());
discoverySyncData.setNamespaceId(proxySelectorDTO.getNamespaceId());
DataChangedEvent dataChangedEvent = new DataChangedEvent(ConfigGroupEnum.DISCOVER_UPSTREAM, DataEventTypeEnum.DELETE, Collections.singletonList(discoverySyncData));
eventPublisher.publishEvent(dataChangedEvent);
}

@Override
public void changeUpstream(final ProxySelectorDTO proxySelectorDTO, final List<DiscoveryUpstreamDTO> upstreamDTOS) {
DiscoverySyncData discoverySyncData = new DiscoverySyncData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,14 @@ private void unbindDiscovery(final List<SelectorDO> selectors, final List<Plugin
if (Objects.nonNull(discoveryDO)) {
final DiscoveryProcessor discoveryProcessor = discoveryProcessorHolder.chooseProcessor(discoveryDO.getType());
ProxySelectorDTO proxySelectorDTO = new ProxySelectorDTO();
proxySelectorDTO.setId(selector.getId());
proxySelectorDTO.setName(selector.getName());
proxySelectorDTO.setPluginName(pluginMap.getOrDefault(selector.getId(), ""));
proxySelectorDTO.setPluginName(pluginMap.getOrDefault(selector.getPluginId(), ""));
proxySelectorDTO.setNamespaceId(selector.getNamespaceId());
discoveryProcessor.removeProxySelector(DiscoveryTransfer.INSTANCE.mapToDTO(discoveryHandlerDO), proxySelectorDTO);
if (DiscoveryLevel.SELECTOR.getCode().equals(discoveryDO.getLevel())) {
discoveryProcessor.removeDiscovery(discoveryDO);
discoveryProcessor.removeSelectorUpstream(proxySelectorDTO);
discoveryMapper.delete(discoveryDO.getId());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ public void testChangeUpstream() {
verify(eventPublisher).publishEvent(any(DataChangedEvent.class));
}

@Test
public void testRemoveSelectorUpstream() {
doNothing().when(eventPublisher).publishEvent(any(DataChangedEvent.class));
localDiscoveryProcessor.removeSelectorUpstream(new ProxySelectorDTO());
verify(eventPublisher).publishEvent(any(DataChangedEvent.class));
}

@Test
public void testFetchAll() {
List<DiscoveryUpstreamDO> discoveryUpstreamDOS = new ArrayList<>();
Expand Down

0 comments on commit 7b74602

Please sign in to comment.