|
|
@ -18,9 +18,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
package com.tencent.cloud.polaris.router.grayrelease.gateway;
|
|
|
|
package com.tencent.cloud.polaris.router.grayrelease.gateway;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.core.env.Environment;
|
|
|
|
import org.springframework.core.env.Environment;
|
|
|
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestHeader;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
|
@ -34,14 +39,36 @@ public class GatewayController {
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private RouterService routerService;
|
|
|
|
private RouterService routerService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final Map<Integer, String> uidMapping;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public GatewayController() {
|
|
|
|
|
|
|
|
String mapping = System.getenv("uid_env_mapping");
|
|
|
|
|
|
|
|
uidMapping = parseUidMapping(mapping);
|
|
|
|
|
|
|
|
System.out.println("parsed mapping is " + uidMapping);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Get information of callee.
|
|
|
|
* Get information of callee.
|
|
|
|
* @return information of callee
|
|
|
|
* @return information of callee
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@GetMapping("/entry")
|
|
|
|
@GetMapping("/route_rule")
|
|
|
|
public String rest() {
|
|
|
|
public String routeRule(@RequestHeader("uid") int userId) {
|
|
|
|
String appName = environment.getProperty("spring.application.name");
|
|
|
|
String appName = environment.getProperty("spring.application.name");
|
|
|
|
String resp = routerService.rest();
|
|
|
|
String resp = routerService.restByUser(userId);
|
|
|
|
return appName + " -> " + resp;
|
|
|
|
return appName + " -> " + resp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Map<Integer, String> parseUidMapping(String mapText) {
|
|
|
|
|
|
|
|
Map<Integer, String> result = new HashMap<>();
|
|
|
|
|
|
|
|
if (!StringUtils.hasText(mapText)) {
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String[] tokens = mapText.split("\\|");
|
|
|
|
|
|
|
|
for (String token : tokens) {
|
|
|
|
|
|
|
|
String[] pairs = token.split(":");
|
|
|
|
|
|
|
|
result.put(Integer.parseInt(pairs[0]), pairs[1]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|