mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-12 06:53:42 +08:00
路由修改
This commit is contained in:
@@ -6,11 +6,13 @@ import com.gitee.easyopen.annotation.ApiService;
|
||||
import com.gitee.easyopen.doc.annotation.ApiDoc;
|
||||
import com.gitee.easyopen.doc.annotation.ApiDocMethod;
|
||||
import com.gitee.sop.adminserver.api.service.param.RouteSearchParam;
|
||||
import com.gitee.sop.adminserver.api.service.param.UpdateRouteParam;
|
||||
import com.gitee.sop.adminserver.bean.GatewayRouteDefinition;
|
||||
import com.gitee.sop.adminserver.bean.SopAdminConstants;
|
||||
import com.gitee.sop.adminserver.bean.ZookeeperContext;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.curator.framework.recipes.cache.ChildData;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -54,4 +56,15 @@ public class RouteListApi {
|
||||
return routeDefinitionList;
|
||||
}
|
||||
|
||||
@Api(name = "route.update")
|
||||
@ApiDocMethod(description = "修改路由")
|
||||
void updateRoute(UpdateRouteParam param) throws Exception {
|
||||
String serviceIdPath = ZookeeperContext.getSopRouteRootPath(param.getProfile()) + "/" + param.getServiceId();
|
||||
String zookeeperRoutePath = serviceIdPath + "/" + param.getId();
|
||||
String data = ZookeeperContext.getData(zookeeperRoutePath);
|
||||
GatewayRouteDefinition routeDefinition = JSON.parseObject(data, GatewayRouteDefinition.class);
|
||||
BeanUtils.copyProperties(param, routeDefinition);
|
||||
ZookeeperContext.setData(zookeeperRoutePath, JSON.toJSONString(routeDefinition));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,57 @@
|
||||
package com.gitee.sop.adminserver.api.service.param;
|
||||
|
||||
import com.gitee.easyopen.doc.annotation.ApiDocField;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* @author tanghc
|
||||
*/
|
||||
@Data
|
||||
public class UpdateRouteParam {
|
||||
|
||||
@NotBlank(message = "profile不能为空")
|
||||
@ApiDocField(description = "profile")
|
||||
private String profile;
|
||||
|
||||
@NotBlank(message = "serviceId不能为空")
|
||||
@ApiDocField(description = "serviceId")
|
||||
private String serviceId;
|
||||
|
||||
/**
|
||||
* 路由的Id
|
||||
*/
|
||||
@NotBlank(message = "id不能为空")
|
||||
@ApiDocField(description = "路由id")
|
||||
private String id = "";
|
||||
|
||||
/**
|
||||
* 路由规则转发的目标uri
|
||||
*/
|
||||
@NotBlank(message = "uri不能为空")
|
||||
@ApiDocField(description = "路由uri")
|
||||
private String uri;
|
||||
|
||||
/**
|
||||
* uri后面跟的path
|
||||
*/
|
||||
@ApiDocField(description = "路由path")
|
||||
private String path;
|
||||
|
||||
|
||||
/**
|
||||
* 是否忽略验证,业务参数验证除外
|
||||
*/
|
||||
@NotNull
|
||||
@ApiDocField(description = "是否忽略验证")
|
||||
private Boolean ignoreValidate;
|
||||
|
||||
/**
|
||||
* 是否禁用
|
||||
*/
|
||||
@NotNull
|
||||
@ApiDocField(description = "是否禁用")
|
||||
private Boolean disabled;
|
||||
}
|
@@ -10,16 +10,43 @@ import java.util.List;
|
||||
*/
|
||||
@Data
|
||||
public class GatewayRouteDefinition {
|
||||
/** 路由的Id */
|
||||
/**
|
||||
* 路由的Id
|
||||
*/
|
||||
private String id = "";
|
||||
/** 路由断言集合配置 */
|
||||
|
||||
/**
|
||||
* 路由断言集合配置
|
||||
*/
|
||||
private List<GatewayPredicateDefinition> predicates = new ArrayList<>();
|
||||
/** 路由过滤器集合配置 */
|
||||
|
||||
/**
|
||||
* 路由过滤器集合配置
|
||||
*/
|
||||
private List<GatewayFilterDefinition> filters = new ArrayList<>();
|
||||
/** 路由规则转发的目标uri */
|
||||
|
||||
/**
|
||||
* 路由规则转发的目标uri
|
||||
*/
|
||||
private String uri;
|
||||
/** 路由执行的顺序 */
|
||||
|
||||
/**
|
||||
* uri后面跟的path
|
||||
*/
|
||||
private String path;
|
||||
|
||||
/**
|
||||
* 路由执行的顺序
|
||||
*/
|
||||
private int order = 0;
|
||||
/** 是否忽略验证,业务参数验证除外 */
|
||||
|
||||
/**
|
||||
* 是否忽略验证,业务参数验证除外
|
||||
*/
|
||||
private boolean ignoreValidate;
|
||||
|
||||
/**
|
||||
* 是否禁用
|
||||
*/
|
||||
private boolean disabled;
|
||||
}
|
@@ -7,6 +7,7 @@ import org.apache.curator.framework.CuratorFrameworkFactory;
|
||||
import org.apache.curator.framework.recipes.cache.ChildData;
|
||||
import org.apache.curator.framework.recipes.cache.PathChildrenCache;
|
||||
import org.apache.curator.retry.ExponentialBackoffRetry;
|
||||
import org.apache.zookeeper.data.Stat;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@@ -68,6 +69,18 @@ public class ZookeeperContext {
|
||||
}
|
||||
}
|
||||
|
||||
public static Stat setData(String path, String data) throws Exception {
|
||||
return getClient().setData().forPath(path, data.getBytes());
|
||||
}
|
||||
|
||||
public static String getData(String path) throws Exception {
|
||||
if (!isPathExist(path)) {
|
||||
return null;
|
||||
}
|
||||
byte[] data = getClient().getData().forPath(path);
|
||||
return new String(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取子节点数据
|
||||
* @param parentPath 父节点
|
||||
|
Reference in New Issue
Block a user