Change type of ServiceConfig.path2methodToApiConfigMapMap to Map<String, Map<Object, GatewayGroup2apiConfig>> #189
This commit is contained in:
@@ -46,17 +46,19 @@ public class ApiConfig {
|
|||||||
static final byte CALLBACK = 4;
|
static final byte CALLBACK = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final int DELETED = 1;
|
public static final int DELETED = 1;
|
||||||
|
|
||||||
public static final char ALLOW = 'a';
|
public static final char ALLOW = 'a';
|
||||||
|
|
||||||
public static final char FORBID = 'f';
|
public static final char FORBID = 'f';
|
||||||
|
|
||||||
private static final String match_all = "/**";
|
public static final String ALL_METHOD = "AM";
|
||||||
|
|
||||||
private static final int ENABLE = 1;
|
private static final String match_all = "/**";
|
||||||
|
|
||||||
private static final int UNABLE = 0;
|
private static final int ENABLE = 1;
|
||||||
|
|
||||||
|
private static final int UNABLE = 0;
|
||||||
|
|
||||||
public int id; // tb_api_auth.id
|
public int id; // tb_api_auth.id
|
||||||
|
|
||||||
@@ -68,7 +70,10 @@ public class ApiConfig {
|
|||||||
|
|
||||||
public String backendService;
|
public String backendService;
|
||||||
|
|
||||||
public HttpMethod method = HttpMethod.TRACE;
|
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
|
||||||
|
public HttpMethod method;
|
||||||
|
|
||||||
|
public Object fizzMethod = ALL_METHOD;
|
||||||
|
|
||||||
public String path = match_all;
|
public String path = match_all;
|
||||||
|
|
||||||
@@ -76,8 +81,6 @@ public class ApiConfig {
|
|||||||
|
|
||||||
public String backendPath;
|
public String backendPath;
|
||||||
|
|
||||||
// public Set<String> apps = Stream.of(App.ALL_APP).collect(Collectors.toSet());
|
|
||||||
|
|
||||||
@JsonProperty("proxyMode")
|
@JsonProperty("proxyMode")
|
||||||
public byte type = Type.SERVICE_DISCOVERY;
|
public byte type = Type.SERVICE_DISCOVERY;
|
||||||
|
|
||||||
@@ -124,19 +127,6 @@ public class ApiConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void setApp(String as) {
|
|
||||||
// apps.remove(App.ALL_APP);
|
|
||||||
// if (StringUtils.isBlank(as)) {
|
|
||||||
// apps.add("*");
|
|
||||||
// } else {
|
|
||||||
// Arrays.stream(StringUtils.split(as, ',')).forEach(
|
|
||||||
// a -> {
|
|
||||||
// apps.add(a.trim());
|
|
||||||
// }
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
public void setPath(String p) {
|
public void setPath(String p) {
|
||||||
if (StringUtils.isNotBlank(p)) {
|
if (StringUtils.isNotBlank(p)) {
|
||||||
if ("/".equals(p)) {
|
if ("/".equals(p)) {
|
||||||
@@ -155,7 +145,9 @@ public class ApiConfig {
|
|||||||
public void setMethod(String m) {
|
public void setMethod(String m) {
|
||||||
method = HttpMethod.resolve(m);
|
method = HttpMethod.resolve(m);
|
||||||
if (method == null) {
|
if (method == null) {
|
||||||
method = HttpMethod.TRACE;
|
fizzMethod = ALL_METHOD;
|
||||||
|
} else {
|
||||||
|
fizzMethod = method;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,9 +41,9 @@ public class ServiceConfig {
|
|||||||
public String id;
|
public String id;
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
public Map<Integer, ApiConfig> apiConfigMap = new HashMap<>(32);
|
public Map<Integer, ApiConfig> apiConfigMap = new HashMap<>();
|
||||||
|
|
||||||
public Map<String, EnumMap<HttpMethod, GatewayGroup2apiConfig>> path2methodToApiConfigMapMap = new HashMap<>(6);
|
public Map<String, Map<Object, GatewayGroup2apiConfig>> path2methodToApiConfigMapMap = new HashMap<>();
|
||||||
|
|
||||||
public ServiceConfig(String id) {
|
public ServiceConfig(String id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
@@ -51,18 +51,18 @@ public class ServiceConfig {
|
|||||||
|
|
||||||
public void add(ApiConfig ac) {
|
public void add(ApiConfig ac) {
|
||||||
apiConfigMap.put(ac.id, ac);
|
apiConfigMap.put(ac.id, ac);
|
||||||
EnumMap<HttpMethod, GatewayGroup2apiConfig> method2apiConfigMap = path2methodToApiConfigMapMap.get(ac.path);
|
Map<Object, GatewayGroup2apiConfig> method2apiConfigMap = path2methodToApiConfigMapMap.get(ac.path);
|
||||||
if (method2apiConfigMap == null) {
|
if (method2apiConfigMap == null) {
|
||||||
method2apiConfigMap = new EnumMap<>(HttpMethod.class);
|
method2apiConfigMap = new HashMap<Object, GatewayGroup2apiConfig>();
|
||||||
GatewayGroup2apiConfig gatewayGroup2apiConfig = new GatewayGroup2apiConfig();
|
GatewayGroup2apiConfig gatewayGroup2apiConfig = new GatewayGroup2apiConfig();
|
||||||
gatewayGroup2apiConfig.add(ac);
|
gatewayGroup2apiConfig.add(ac);
|
||||||
method2apiConfigMap.put(ac.method, gatewayGroup2apiConfig);
|
method2apiConfigMap.put(ac.fizzMethod, gatewayGroup2apiConfig);
|
||||||
path2methodToApiConfigMapMap.put(ac.path, method2apiConfigMap);
|
path2methodToApiConfigMapMap.put(ac.path, method2apiConfigMap);
|
||||||
} else {
|
} else {
|
||||||
GatewayGroup2apiConfig gatewayGroup2apiConfig = method2apiConfigMap.get(ac.method);
|
GatewayGroup2apiConfig gatewayGroup2apiConfig = method2apiConfigMap.get(ac.fizzMethod);
|
||||||
if (gatewayGroup2apiConfig == null) {
|
if (gatewayGroup2apiConfig == null) {
|
||||||
gatewayGroup2apiConfig = new GatewayGroup2apiConfig();
|
gatewayGroup2apiConfig = new GatewayGroup2apiConfig();
|
||||||
method2apiConfigMap.put(ac.method, gatewayGroup2apiConfig);
|
method2apiConfigMap.put(ac.fizzMethod, gatewayGroup2apiConfig);
|
||||||
}
|
}
|
||||||
gatewayGroup2apiConfig.add(ac);
|
gatewayGroup2apiConfig.add(ac);
|
||||||
}
|
}
|
||||||
@@ -71,18 +71,18 @@ public class ServiceConfig {
|
|||||||
|
|
||||||
public void remove(ApiConfig ac) {
|
public void remove(ApiConfig ac) {
|
||||||
ApiConfig remove = apiConfigMap.remove(ac.id);
|
ApiConfig remove = apiConfigMap.remove(ac.id);
|
||||||
Map<HttpMethod, GatewayGroup2apiConfig> method2apiConfigMap = path2methodToApiConfigMapMap.get(ac.path);
|
Map<Object, GatewayGroup2apiConfig> method2apiConfigMap = path2methodToApiConfigMapMap.get(ac.path);
|
||||||
if (method2apiConfigMap == null) {
|
if (method2apiConfigMap == null) {
|
||||||
log.info("no config to delete for " + ac.service + ' ' + ac.path);
|
log.info("no config to delete for " + ac.service + ' ' + ac.path);
|
||||||
} else {
|
} else {
|
||||||
GatewayGroup2apiConfig gatewayGroup2apiConfig = method2apiConfigMap.get(ac.method);
|
GatewayGroup2apiConfig gatewayGroup2apiConfig = method2apiConfigMap.get(ac.fizzMethod);
|
||||||
if (gatewayGroup2apiConfig == null) {
|
if (gatewayGroup2apiConfig == null) {
|
||||||
log.info("no config to delete for " + ac.service + ' ' + ac.method + ' ' + ac.path);
|
log.info("no config to delete for " + ac.service + ' ' + ac.fizzMethod + ' ' + ac.path);
|
||||||
} else {
|
} else {
|
||||||
log.info(id + " remove " + ac);
|
log.info(id + " remove " + ac);
|
||||||
gatewayGroup2apiConfig.remove(ac);
|
gatewayGroup2apiConfig.remove(ac);
|
||||||
if (gatewayGroup2apiConfig.getConfigMap().isEmpty()) {
|
if (gatewayGroup2apiConfig.getConfigMap().isEmpty()) {
|
||||||
method2apiConfigMap.remove(ac.method);
|
method2apiConfigMap.remove(ac.fizzMethod);
|
||||||
if (method2apiConfigMap.isEmpty()) {
|
if (method2apiConfigMap.isEmpty()) {
|
||||||
path2methodToApiConfigMapMap.remove(ac.path);
|
path2methodToApiConfigMapMap.remove(ac.path);
|
||||||
}
|
}
|
||||||
@@ -94,18 +94,18 @@ public class ServiceConfig {
|
|||||||
public void update(ApiConfig ac) {
|
public void update(ApiConfig ac) {
|
||||||
ApiConfig prev = apiConfigMap.put(ac.id, ac);
|
ApiConfig prev = apiConfigMap.put(ac.id, ac);
|
||||||
log.info(prev + " is updated by " + ac + " in api config map");
|
log.info(prev + " is updated by " + ac + " in api config map");
|
||||||
EnumMap<HttpMethod, GatewayGroup2apiConfig> method2apiConfigMap = path2methodToApiConfigMapMap.get(ac.path);
|
Map<Object, GatewayGroup2apiConfig> method2apiConfigMap = path2methodToApiConfigMapMap.get(ac.path);
|
||||||
if (method2apiConfigMap == null) {
|
if (method2apiConfigMap == null) {
|
||||||
method2apiConfigMap = new EnumMap<>(HttpMethod.class);
|
method2apiConfigMap = new HashMap<Object, GatewayGroup2apiConfig>();
|
||||||
GatewayGroup2apiConfig gatewayGroup2apiConfig = new GatewayGroup2apiConfig();
|
GatewayGroup2apiConfig gatewayGroup2apiConfig = new GatewayGroup2apiConfig();
|
||||||
gatewayGroup2apiConfig.add(ac);
|
gatewayGroup2apiConfig.add(ac);
|
||||||
method2apiConfigMap.put(ac.method, gatewayGroup2apiConfig);
|
method2apiConfigMap.put(ac.fizzMethod, gatewayGroup2apiConfig);
|
||||||
path2methodToApiConfigMapMap.put(ac.path, method2apiConfigMap);
|
path2methodToApiConfigMapMap.put(ac.path, method2apiConfigMap);
|
||||||
} else {
|
} else {
|
||||||
GatewayGroup2apiConfig gatewayGroup2apiConfig = method2apiConfigMap.get(ac.method);
|
GatewayGroup2apiConfig gatewayGroup2apiConfig = method2apiConfigMap.get(ac.fizzMethod);
|
||||||
if (gatewayGroup2apiConfig == null) {
|
if (gatewayGroup2apiConfig == null) {
|
||||||
gatewayGroup2apiConfig = new GatewayGroup2apiConfig();
|
gatewayGroup2apiConfig = new GatewayGroup2apiConfig();
|
||||||
method2apiConfigMap.put(ac.method, gatewayGroup2apiConfig);
|
method2apiConfigMap.put(ac.fizzMethod, gatewayGroup2apiConfig);
|
||||||
gatewayGroup2apiConfig.add(ac);
|
gatewayGroup2apiConfig.add(ac);
|
||||||
} else {
|
} else {
|
||||||
log.info(id + " update " + ac);
|
log.info(id + " update " + ac);
|
||||||
@@ -119,12 +119,12 @@ public class ServiceConfig {
|
|||||||
|
|
||||||
List<GatewayGroup2apiConfig> matchGatewayGroup2apiConfigs = ThreadContext.getArrayList(gg2acs, GatewayGroup2apiConfig.class);
|
List<GatewayGroup2apiConfig> matchGatewayGroup2apiConfigs = ThreadContext.getArrayList(gg2acs, GatewayGroup2apiConfig.class);
|
||||||
|
|
||||||
Set<Map.Entry<String, EnumMap<HttpMethod, GatewayGroup2apiConfig>>> es = path2methodToApiConfigMapMap.entrySet();
|
Set<Map.Entry<String, Map<Object, GatewayGroup2apiConfig>>> es = path2methodToApiConfigMapMap.entrySet();
|
||||||
for (Map.Entry<String, EnumMap<HttpMethod, GatewayGroup2apiConfig>> e : es) {
|
for (Map.Entry<String, Map<Object, GatewayGroup2apiConfig>> e : es) {
|
||||||
EnumMap<HttpMethod, GatewayGroup2apiConfig> method2gatewayGroupToApiConfigMap = e.getValue();
|
Map<Object, GatewayGroup2apiConfig> method2gatewayGroupToApiConfigMap = e.getValue();
|
||||||
GatewayGroup2apiConfig gatewayGroup2apiConfig = method2gatewayGroupToApiConfigMap.get(method);
|
GatewayGroup2apiConfig gatewayGroup2apiConfig = method2gatewayGroupToApiConfigMap.get(method);
|
||||||
if (gatewayGroup2apiConfig == null) {
|
if (gatewayGroup2apiConfig == null) {
|
||||||
gatewayGroup2apiConfig = method2gatewayGroupToApiConfigMap.get(HttpMethod.TRACE);
|
gatewayGroup2apiConfig = method2gatewayGroupToApiConfigMap.get(ApiConfig.ALL_METHOD);
|
||||||
}
|
}
|
||||||
if (gatewayGroup2apiConfig != null) {
|
if (gatewayGroup2apiConfig != null) {
|
||||||
String pathPattern = e.getKey();
|
String pathPattern = e.getKey();
|
||||||
|
|||||||
Reference in New Issue
Block a user