Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[type:feat]The sync-data-http method adapts to the namespace transformation #5598

Merged
merged 36 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
e15cc58
sync frontend
Jul 17, 2024
1701c6a
commit
xcsnx Jul 18, 2024
2f46079
commit
Jul 18, 2024
0e9f036
Merge remote-tracking branch 'origin/syncFront' into feat_sync_namesp…
xcsnx Jul 19, 2024
89a56e3
fix e2e
xcsnx Jul 19, 2024
08d7e31
fix test
xcsnx Jul 19, 2024
7b01924
Merge branch 'master' into feat_sync_namespace_change
xcsnx Jul 19, 2024
3d993e8
Merge branch 'master' into feat_sync_namespace_change
xcsnx Jul 20, 2024
bd16403
Merge branch 'master' into feat_sync_namespace_change
Sep 14, 2024
523236f
fix
Sep 14, 2024
8088148
fix cr
Sep 15, 2024
e4d3e4b
Merge branch 'master' into feat_sync_namespace_change
xcsnx Sep 15, 2024
016db76
fix cr
Sep 15, 2024
c0ba599
Merge branch 'master' into feat_sync_namespace_change
Aias00 Sep 19, 2024
1cea6c3
Merge branch 'master' into feat_sync_namespace_change
Aias00 Sep 23, 2024
6a2f11a
Merge branch 'master' into feat_sync_namespace_change
Oct 10, 2024
f021ab9
fix cr
Oct 10, 2024
077ac60
Merge branch 'master' into feat_sync_namespace_change
Oct 13, 2024
e0656ff
final
Oct 13, 2024
d426de2
Merge branch 'master' into feat_sync_namespace_change
xcsnx Oct 13, 2024
9028d21
fix
Oct 13, 2024
b661354
fix
Oct 13, 2024
4be804f
fix
Oct 13, 2024
161c1a7
fix
Oct 13, 2024
33e0f87
fix uni test
Oct 13, 2024
86ed6ac
fix
Oct 13, 2024
0b1d8d2
fix
Oct 13, 2024
38a9976
fix
Oct 13, 2024
5c37591
Merge branch 'master' into feat_sync_namespace_change
Aias00 Oct 15, 2024
adb48be
Merge branch 'master' into feat_sync_namespace_change
xcsnx Oct 16, 2024
9a67d6d
fix
Oct 16, 2024
21770f4
fix
Oct 16, 2024
b052506
fix
Oct 16, 2024
b9e9686
fix
Oct 16, 2024
a6b25ba
fix
Oct 16, 2024
5572730
Merge branch 'master' into feat_sync_namespace_change
xcsnx Oct 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
package org.apache.shenyu.admin.config;

import org.apache.shenyu.admin.config.properties.HttpSyncProperties;
import org.apache.shenyu.admin.controller.ConfigController;
import org.apache.shenyu.admin.listener.http.HttpLongPollingDataChangedListener;
import org.apache.shenyu.admin.service.NamespaceService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
Expand All @@ -43,4 +45,16 @@ public HttpLongPollingDataChangedListener httpLongPollingDataChangedListener(fin
return new HttpLongPollingDataChangedListener(httpSyncProperties);
}

/**
* configController.
*
* @param httpLongPollingDataChangedListener httpLongPollingDataChangedListener
* @param namespaceService namespaceService
* @return {@link ConfigController}
*/
@Bean
@ConditionalOnMissingBean(ConfigController.class)
public ConfigController configController(final HttpLongPollingDataChangedListener httpLongPollingDataChangedListener, final NamespaceService namespaceService) {
return new ConfigController(httpLongPollingDataChangedListener, namespaceService);
xcsnx marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@
package org.apache.shenyu.admin.controller;

import com.google.common.collect.Maps;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.shenyu.admin.exception.ShenyuAdminException;
import org.apache.shenyu.admin.listener.http.HttpLongPollingDataChangedListener;
import org.apache.shenyu.admin.model.result.ShenyuAdminResult;
import org.apache.shenyu.admin.model.vo.NamespaceVO;
import org.apache.shenyu.admin.service.NamespaceService;
import org.apache.shenyu.admin.utils.ShenyuResultMessage;
import org.apache.shenyu.common.dto.ConfigData;
import org.apache.shenyu.common.enums.ConfigGroupEnum;
Expand All @@ -35,36 +40,50 @@

import java.util.Map;

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

/**
* This Controller only when HttpLongPollingDataChangedListener exist, will take effect.
*/
@ResponseBody
@RequestMapping("/configs")
@RestController
public class ConfigController {

private final HttpLongPollingDataChangedListener longPollingListener;

public ConfigController(final HttpLongPollingDataChangedListener longPollingListener) {

private final NamespaceService namespaceService;

public ConfigController(final HttpLongPollingDataChangedListener longPollingListener, final NamespaceService namespaceService) {
this.longPollingListener = longPollingListener;
this.namespaceService = namespaceService;
}

/**
* Fetch configs shenyu result.
*
* @param groupKeys the group keys
* @param namespaceIdParams namespaceIdParams
* @return the shenyu result
*/
@GetMapping("/fetch")
public ShenyuAdminResult fetchConfigs(@NotNull final String[] groupKeys) {
public ShenyuAdminResult fetchConfigs(@NotNull final String[] groupKeys, final String namespaceIdParams) {
String namespaceId = namespaceIdParams;
NamespaceVO existNamespace = namespaceService.findById(namespaceId);
if (StringUtils.isNotEmpty(namespaceId) && ObjectUtils.isEmpty(existNamespace)) {
throw new ShenyuAdminException("namespaceId is not exist");
}
if (StringUtils.isEmpty(namespaceId)) {
moremind marked this conversation as resolved.
Show resolved Hide resolved
namespaceId = SYS_DEFAULT_NAMESPACE_ID;
}
Map<String, ConfigData<?>> result = Maps.newHashMap();
for (String groupKey : groupKeys) {
ConfigData<?> data = longPollingListener.fetchConfig(ConfigGroupEnum.valueOf(groupKey));
ConfigData<?> data = longPollingListener.fetchConfig(ConfigGroupEnum.valueOf(groupKey), namespaceId);
result.put(groupKey, data);
}
return ShenyuAdminResult.success(ShenyuResultMessage.SUCCESS, result);
}

/**
* Listener.
*
Expand All @@ -75,5 +94,5 @@ public ShenyuAdminResult fetchConfigs(@NotNull final String[] groupKeys) {
public void listener(final HttpServletRequest request, final HttpServletResponse response) {
longPollingListener.doLongPolling(request, response);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public void changeUpstream(final ProxySelectorDTO proxySelectorDTO, final List<D
discoverySyncData.setSelectorName(proxySelectorDTO.getName());
List<DiscoveryUpstreamData> upstreamDataList = upstreamDTOS.stream().map(DiscoveryTransfer.INSTANCE::mapToData).collect(Collectors.toList());
discoverySyncData.setUpstreamDataList(upstreamDataList);
discoverySyncData.setNamespaceId(proxySelectorDTO.getNamespaceId());
DataChangedEvent dataChangedEvent = new DataChangedEvent(ConfigGroupEnum.DISCOVER_UPSTREAM, DataEventTypeEnum.UPDATE, Collections.singletonList(discoverySyncData));
eventPublisher.publishEvent(dataChangedEvent);
DiscoveryStreamUpdatedEvent discoveryStreamUpdatedEvent = new DiscoveryStreamUpdatedEvent(discoverySyncData, LOCAL_DISCOVERY_UPSTREAM_UPDATE);
Expand All @@ -108,6 +109,7 @@ public void fetchAll(final DiscoveryHandlerDTO discoveryHandlerDTO, final ProxyS
discoverySyncData.setSelectorName(proxySelectorDTO.getName());
List<DiscoveryUpstreamData> upstreamDataList = discoveryUpstreamDOS.stream().map(DiscoveryTransfer.INSTANCE::mapToData).collect(Collectors.toList());
discoverySyncData.setUpstreamDataList(upstreamDataList);
discoverySyncData.setNamespaceId(proxySelectorDTO.getNamespaceId());
DataChangedEvent dataChangedEvent = new DataChangedEvent(ConfigGroupEnum.DISCOVER_UPSTREAM, DataEventTypeEnum.UPDATE, Collections.singletonList(discoverySyncData));
eventPublisher.publishEvent(dataChangedEvent);
}
Expand Down
Loading
Loading