This is an automated email from the ASF dual-hosted git repository.
hefengen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 09e4c4a8fc [type:bugfix] fix http sync ci error (#5774)
09e4c4a8fc is described below
commit 09e4c4a8fceb9edc46285772476cedfca2277e84
Author: aias00 <[email protected]>
AuthorDate: Wed Nov 20 08:43:19 2024 +0800
[type:bugfix] fix http sync ci error (#5774)
* [type:bugfix] fix http sync ci error
* [type:bugfix] fix http sync ci error
* [type:bugfix] fix http sync ci error
* [type:bugfix] fix http sync ci error
* [type:bugfix] fix http sync ci error
* [type:bugfix] fix http sync ci error
* [type:bugfix] fix jdbc cluster ci error
* [type:bugfix] fix jdbc cluster ci error
* [type:bugfix] fix http sync ci error
* [type:bugfix] fix http sync ci error
* [type:bugfix] fix http sync ci error
* Update ConfigController.java
* Update ConfigController.java
* [type:bugfix] fix http sync ci error
* [type:bugfix] fix http sync ci error
* [type:bugfix] fix http sync ci error
* [type:bugfix] fix http sync ci error
* [type:bugfix] fix http sync ci error
* [type:bugfix] fix http sync ci error
* [type:bugfix] fix http sync ci error
* [type:bugfix] fix http sync ci error
* [type:bugfix] fix http sync ci error
* [type:bugfix] fix http sync ci error
* [type:bugfix] fix http sync ci error
* [type:bugfix] fix http sync ci error
* [type:bugfix] fix http sync ci error
* [type:bugfix] fix http sync ci error, decrease error log
* [type:bugfix] fix http sync ci error
* [type:bugfix] fix http sync ci error
* [type:bugfix] fix http sync ci error
* [type:bugfix] fix http sync ci error
* [type:bugfix] fix http sync ci error
* [type:bugfix] fix http sync ci error
* [type:bugfix] fix http sync ci error
* [type:bugfix] fix http sync ci error temp
* [type:bugfix] fix http sync ci error
* [type:bugfix] fix http sync ci error
---------
Co-authored-by: moremind <[email protected]>
---
.../admin/config/ClusterJdbcConfiguration.java | 1 +
.../config/HttpLongPollingSyncConfiguration.java | 10 ++++++--
.../admin/config/properties/ClusterProperties.java | 2 +-
.../shenyu/admin/controller/ConfigController.java | 30 ++++++++++++----------
.../service/impl/DataPermissionServiceImpl.java | 4 +--
shenyu-admin/src/test/resources/application.yml | 4 +--
.../shenyu/sync/data/http/HttpSyncDataService.java | 5 ++++
7 files changed, 35 insertions(+), 21 deletions(-)
diff --git
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/config/ClusterJdbcConfiguration.java
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/config/ClusterJdbcConfiguration.java
index bf71574187..ff0517839c 100644
---
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/config/ClusterJdbcConfiguration.java
+++
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/config/ClusterJdbcConfiguration.java
@@ -71,6 +71,7 @@ public class ClusterJdbcConfiguration {
}
DefaultLockRepository defaultLockRepository = new
DefaultLockRepository(dataSource, fullPath);
defaultLockRepository.setPrefix("SHENYU_");
+ // set lock ttl
long millis =
TimeUnit.SECONDS.toMillis(clusterProperties.getLockTtl());
defaultLockRepository.setTimeToLive(Long.valueOf(millis).intValue());
return defaultLockRepository;
diff --git
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/config/HttpLongPollingSyncConfiguration.java
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/config/HttpLongPollingSyncConfiguration.java
index a974535754..2e504e8510 100644
---
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/config/HttpLongPollingSyncConfiguration.java
+++
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/config/HttpLongPollingSyncConfiguration.java
@@ -19,6 +19,8 @@ package org.apache.shenyu.admin.config;
import org.apache.shenyu.admin.config.properties.HttpSyncProperties;
import
org.apache.shenyu.admin.listener.http.HttpLongPollingDataChangedListener;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import
org.springframework.boot.context.properties.EnableConfigurationProperties;
@@ -30,8 +32,11 @@ import org.springframework.context.annotation.Configuration;
*/
@Configuration
@EnableConfigurationProperties(HttpSyncProperties.class)
+@ConditionalOnProperty(prefix = "shenyu.sync.http", name = "enabled",
havingValue = "true")
public class HttpLongPollingSyncConfiguration {
-
+
+ private static final Logger LOG =
LoggerFactory.getLogger(HttpLongPollingSyncConfiguration.class);
+
/**
* httpLongPollingDataChangedListener.
*
@@ -39,9 +44,10 @@ public class HttpLongPollingSyncConfiguration {
* @return {@link HttpLongPollingDataChangedListener}
*/
@Bean
- @ConditionalOnProperty(name = "shenyu.sync.http.enabled", havingValue =
"true")
@ConditionalOnMissingBean(HttpLongPollingDataChangedListener.class)
public HttpLongPollingDataChangedListener
httpLongPollingDataChangedListener(final HttpSyncProperties httpSyncProperties)
{
+ LOG.info("you use http long polling sync");
return new HttpLongPollingDataChangedListener(httpSyncProperties);
}
+
}
diff --git
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/config/properties/ClusterProperties.java
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/config/properties/ClusterProperties.java
index cc38863f3b..6c5da4a408 100644
---
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/config/properties/ClusterProperties.java
+++
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/config/properties/ClusterProperties.java
@@ -71,7 +71,7 @@ public class ClusterProperties {
/**
* cluster master lock time to live.
*/
- private Long lockTtl = 15L;
+ private Long lockTtl = 30L;
/**
* Gets the value of enabled.
diff --git
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/ConfigController.java
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/ConfigController.java
index 9c43d0df90..6aff3d3c57 100644
---
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/ConfigController.java
+++
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/ConfigController.java
@@ -31,7 +31,7 @@ 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;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -40,24 +40,26 @@ import
org.springframework.web.bind.annotation.RestController;
import java.util.Map;
+
/**
* This Controller only when HttpLongPollingDataChangedListener exist, will
take effect.
*/
+@RestController
@ResponseBody
@RequestMapping("/configs")
-@RestController
-@ConditionalOnBean(HttpLongPollingDataChangedListener.class)
+@ConditionalOnProperty(prefix = "shenyu.sync.http", name = "enabled",
havingValue = "true")
public class ConfigController {
-
- private final HttpLongPollingDataChangedListener longPollingListener;
-
+
+ private final HttpLongPollingDataChangedListener
httpLongPollingDataChangedListener;
+
private final NamespaceService namespaceService;
-
- public ConfigController(final HttpLongPollingDataChangedListener
longPollingListener, final NamespaceService namespaceService) {
- this.longPollingListener = longPollingListener;
+
+ public ConfigController(final HttpLongPollingDataChangedListener
httpLongPollingDataChangedListener,
+ final NamespaceService namespaceService) {
+ this.httpLongPollingDataChangedListener =
httpLongPollingDataChangedListener;
this.namespaceService = namespaceService;
}
-
+
/**
* Fetch configs shenyu result.
*
@@ -76,12 +78,12 @@ public class ConfigController {
}
Map<String, ConfigData<?>> result = Maps.newHashMap();
for (String groupKey : groupKeys) {
- ConfigData<?> data =
longPollingListener.fetchConfig(ConfigGroupEnum.valueOf(groupKey), namespaceId);
+ ConfigData<?> data =
httpLongPollingDataChangedListener.fetchConfig(ConfigGroupEnum.valueOf(groupKey),
namespaceId);
result.put(groupKey, data);
}
return ShenyuAdminResult.success(ShenyuResultMessage.SUCCESS, result);
}
-
+
/**
* Listener.
*
@@ -90,7 +92,7 @@ public class ConfigController {
*/
@PostMapping(value = "/listener")
public void listener(final HttpServletRequest request, final
HttpServletResponse response) {
- longPollingListener.doLongPolling(request, response);
+ httpLongPollingDataChangedListener.doLongPolling(request, response);
}
-
+
}
diff --git
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DataPermissionServiceImpl.java
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DataPermissionServiceImpl.java
index 68e0d7517c..f4f5125f7c 100644
---
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DataPermissionServiceImpl.java
+++
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DataPermissionServiceImpl.java
@@ -275,7 +275,7 @@ public class DataPermissionServiceImpl implements
DataPermissionService {
try {
existed =
dataPermissionMapper.existed(JwtUtils.getUserInfo().getUserId());
} catch (Exception e) {
- LOG.error("check user existed error", e);
+ LOG.error("check user existed error");
existed = false;
}
if (Boolean.TRUE.equals(existed)) {
@@ -314,7 +314,7 @@ public class DataPermissionServiceImpl implements
DataPermissionService {
try {
existed =
dataPermissionMapper.existed(JwtUtils.getUserInfo().getUserId());
} catch (Exception e) {
- LOG.error("check user existed error", e);
+ LOG.error("check user existed error");
existed = false;
}
if (Boolean.TRUE.equals(existed)) {
diff --git a/shenyu-admin/src/test/resources/application.yml
b/shenyu-admin/src/test/resources/application.yml
index 5884b8b793..764e8b2d33 100644
--- a/shenyu-admin/src/test/resources/application.yml
+++ b/shenyu-admin/src/test/resources/application.yml
@@ -49,8 +49,8 @@ shenyu:
# url: localhost:2181
# sessionTimeout: 5000
# connectionTimeout: 2000
-# http:
-# enabled: true
+ http:
+ enabled: false
# nacos:
# url: localhost:8848
# namespace: 1c10d748-af86-43b9-8265-75f487d20c6c
diff --git
a/shenyu-sync-data-center/shenyu-sync-data-http/src/main/java/org/apache/shenyu/sync/data/http/HttpSyncDataService.java
b/shenyu-sync-data-center/shenyu-sync-data-http/src/main/java/org/apache/shenyu/sync/data/http/HttpSyncDataService.java
index 1c268e90c0..2da578e00f 100644
---
a/shenyu-sync-data-center/shenyu-sync-data-http/src/main/java/org/apache/shenyu/sync/data/http/HttpSyncDataService.java
+++
b/shenyu-sync-data-center/shenyu-sync-data-http/src/main/java/org/apache/shenyu/sync/data/http/HttpSyncDataService.java
@@ -20,6 +20,7 @@ package org.apache.shenyu.sync.data.http;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import okhttp3.Headers;
import okhttp3.OkHttpClient;
@@ -219,6 +220,10 @@ public class HttpSyncDataService implements
SyncDataService {
String json = responseBody.string();
LOG.info("listener result: [{}]", json);
JsonObject responseFromServer = GsonUtils.getGson().fromJson(json,
JsonObject.class);
+ JsonElement element = responseFromServer.get("data");
+ if (element.isJsonNull()) {
+ return;
+ }
groupJson = responseFromServer.getAsJsonArray("data");
} catch (IOException e) {
String message = String.format("listener configs fail,
server:[%s], %s", server, e.getMessage());