Merge branch 'develop' into registry-nacos

pull/1/head
tanghc 5 years ago
commit 2dd0f19328
  1. 13
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/bean/ZookeeperContext.java
  2. 13
      sop-admin/sop-admin-server/src/main/java/com/gitee/sop/adminserver/service/RoutePermissionService.java
  3. 2
      sop-gateway/src/main/java/com/gitee/sop/gateway/manager/DbIsvRoutePermissionManager.java

@ -22,7 +22,6 @@ import org.springframework.util.Assert;
import java.io.Closeable;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
import static com.gitee.sop.adminserver.bean.SopAdminConstants.SOP_MSG_CHANNEL_PATH;
@ -283,11 +282,11 @@ public class ZookeeperContext {
* 监听一个节点
*
* @param path
* @param onChange 节点修改后触发
* @param listenCallback 回调
* @return 返回path
* @throws Exception
*/
public static void listenTempPath(String path, Consumer<String> onChange) throws Exception {
public static void listenTempPath(String path, ListenCallback listenCallback) throws Exception {
String initData = "{}";
CuratorFramework client = createClient();
client.create()
@ -302,8 +301,8 @@ public class ZookeeperContext {
public void nodeChanged() throws Exception {
byte[] nodeData = cache.getCurrentData().getData();
String data = new String(nodeData);
if (!initData.equals(data)) {
onChange.accept(data);
if (StringUtils.isNotBlank(data) && !initData.equals(data)) {
listenCallback.onError(data);
new Thread(new ZKClose(cache, client)).start();
}
}
@ -311,6 +310,10 @@ public class ZookeeperContext {
cache.start();
}
public interface ListenCallback {
void onError(String errorMsg);
}
static class ZKClose implements Runnable {
Closeable[] closes;

@ -96,15 +96,12 @@ public class RoutePermissionService {
/**
* 推送所有路由权限到zookeeper
*/
public synchronized void sendRoutePermissionReloadMsg(RoutePermissionParam oldRoutePermission) throws Exception {
public void sendRoutePermissionReloadMsg(RoutePermissionParam oldRoutePermission) throws Exception {
String listenPath = SopAdminConstants.RELOAD_ROUTE_PERMISSION_PATH + "/" + System.currentTimeMillis();
ZookeeperContext.listenTempPath(listenPath, code -> {
// 0成功
if (!"0".equals(code)) {
log.error("推送所有路由权限到zookeeper失败,进行回滚,msg: {},oldRoutePermission:{}", code, JSON.toJSONString(oldRoutePermission));
// 回滚
this.updateRoutePermission(oldRoutePermission);
}
ZookeeperContext.listenTempPath(listenPath, errorMsg -> {
log.error("推送所有路由权限到zookeeper失败,进行回滚,errorMsg: {},oldRoutePermission:{}", errorMsg, JSON.toJSONString(oldRoutePermission));
// 回滚
updateRoutePermission(oldRoutePermission);
});
IsvRoutePermission isvRoutePermission = new IsvRoutePermission();
isvRoutePermission.setListenPath(listenPath);

@ -129,7 +129,7 @@ public class DbIsvRoutePermissionManager extends DefaultIsvRoutePermissionManage
case "reload":
log.info("重新加载路由权限信息,isvRoutePermission:{}", isvRoutePermission);
String listenPath = isvRoutePermission.getListenPath();
String code = "0";
String code = "";
try {
load();
} catch (Exception e) {

Loading…
Cancel
Save