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

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

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

Loading…
Cancel
Save