Skip to content

Commit

Permalink
[type:bugfix] fix namespace sync all button error (#5769)
Browse files Browse the repository at this point in the history
* [type:bugfix] fix sync all error

* [type:bugfix] fix sync all error

* [type:bugfix] fix sync all error

* [type:bugfix] fix http sync error
  • Loading branch information
Aias00 authored Nov 25, 2024
1 parent 78d35a0 commit 14618d7
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
public class HttpLongPollingSyncConfiguration {

private static final Logger LOG = LoggerFactory.getLogger(HttpLongPollingSyncConfiguration.class);

/**
* httpLongPollingDataChangedListener.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ public void onMessage(final String message, final Session session) {
if (Objects.equals(message, DataEventTypeEnum.MYSELF.name())) {
try {
ThreadLocalUtils.put(SESSION_KEY, session);
SpringBeanUtils.getInstance().getBean(SyncDataService.class).syncAll(DataEventTypeEnum.MYSELF);
String namespaceId = getNamespaceId(session);
SpringBeanUtils.getInstance().getBean(SyncDataService.class).syncAllByNamespaceId(DataEventTypeEnum.MYSELF, namespaceId);
} finally {
ThreadLocalUtils.clear();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ public class WebsocketDataChangedListener implements DataChangedListener {
public void onPluginChanged(final List<PluginData> pluginDataList, final DataEventTypeEnum eventType) {
WebsocketData<PluginData> websocketData =
new WebsocketData<>(ConfigGroupEnum.PLUGIN.name(), eventType.name(), pluginDataList);
String namespaceId = pluginDataList.stream().map(value -> StringUtils.defaultString(value.getNamespaceId(), SYS_DEFAULT_NAMESPACE_ID)).findFirst().get();
WebsocketCollector.send(namespaceId, GsonUtils.getInstance().toJson(websocketData), eventType);
if (CollectionUtils.isNotEmpty(pluginDataList)) {
String namespaceId = pluginDataList.stream().map(value -> StringUtils.defaultString(value.getNamespaceId(), SYS_DEFAULT_NAMESPACE_ID)).findFirst().get();
WebsocketCollector.send(namespaceId, GsonUtils.getInstance().toJson(websocketData), eventType);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@
p.plugin_jar AS pluginJar
FROM namespace_plugin_rel npr
LEFT JOIN plugin p ON p.id = npr.plugin_id
WHERE npr.namespace_id=#{namespaceId}
WHERE npr.namespace_id=#{namespaceId, jdbcType=VARCHAR}
ORDER BY
sort,
npr.id ASC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ public void testOnMessage() {
ConfigurableApplicationContext context = mock(ConfigurableApplicationContext.class);
SpringBeanUtils.getInstance().setApplicationContext(context);
when(SpringBeanUtils.getInstance().getBean(SyncDataService.class)).thenReturn(syncDataService);
when(syncDataService.syncAll(DataEventTypeEnum.MYSELF)).thenReturn(true);
when(syncDataService.syncAllByNamespaceId(DataEventTypeEnum.MYSELF, Constants.SYS_DEFAULT_NAMESPACE_ID)).thenReturn(true);
websocketCollector.onOpen(session);
websocketCollector.onMessage(DataEventTypeEnum.MYSELF.name(), session);
assertEquals(1L, getSessionSetSize());
verify(syncDataService, times(1)).syncAll(DataEventTypeEnum.MYSELF);
verify(syncDataService, times(1)).syncAllByNamespaceId(DataEventTypeEnum.MYSELF, Constants.SYS_DEFAULT_NAMESPACE_ID);
doNothing().when(loggerSpy).warn(anyString(), anyString());
websocketCollector.onClose(session);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public ShenyuWebsocketClient(final URI serverUri, final Map<String, String> head
final String namespaceId) {
super(serverUri, headers);
this.namespaceId = namespaceId;
LOG.info("shenyu bootstrap websocket namespaceId:{}", namespaceId);
LOG.info("shenyu bootstrap websocket namespaceId: {}", namespaceId);
this.addHeader(Constants.SHENYU_NAMESPACE_ID, namespaceId);
this.websocketDataHandler = new WebsocketDataHandler(pluginDataSubscriber, metaDataSubscribers, authDataSubscribers, proxySelectorDataSubscribers, discoveryUpstreamDataSubscribers);
this.timer = WheelTimerFactory.getSharedTimer();
Expand Down

0 comments on commit 14618d7

Please sign in to comment.