Authored by chunhua.zhang

support force uid to aws

@@ -28,6 +28,14 @@ function M:switch() @@ -28,6 +28,14 @@ function M:switch()
28 ngx.exit(ngx.HTTP_OK) 28 ngx.exit(ngx.HTTP_OK)
29 end 29 end
30 end 30 end
  31 + --- force uid to aws
  32 + if method == "force" then
  33 + local uid = http_request.get_req_param("uid")
  34 + if uid then
  35 + lua_context.lua_conf_cache:set("switch:uid", uid)
  36 + ngx.exit(ngx.HTTP_OK)
  37 + end
  38 + end
31 end 39 end
32 40
33 function M:init() 41 function M:init()
@@ -43,3 +51,12 @@ function M:get_percentage() @@ -43,3 +51,12 @@ function M:get_percentage()
43 return tonumber(per) 51 return tonumber(per)
44 end 52 end
45 end 53 end
  54 +
  55 +function M:get_force_uid()
  56 + local uid = lua_context.lua_conf_cache:get("switch:uid")
  57 + if uid then
  58 + return tonumber(uid)
  59 + else
  60 + return nil
  61 + end
  62 +end
@@ -69,18 +69,31 @@ end @@ -69,18 +69,31 @@ end
69 69
70 70
71 function get_redirect_url() 71 function get_redirect_url()
72 - local redirectPath = "/apigateway" ; 72 + local redirectPath = "/apigateway"
  73 + local awsPath = "/apiaws"
  74 +
73 init_read_body() 75 init_read_body()
  76 +
  77 + -- get params
74 local percentage = switch_controller.get_percentage() 78 local percentage = switch_controller.get_percentage()
  79 + local force_uid = switch_controller.get_force_uid()
  80 +
  81 + -- get uid
  82 + local uid = 0
  83 + local str_uid = http_request.get_req_param("uid")
  84 + if str_uid then
  85 + uid = tonumber(str_uid)
  86 + end
  87 + -- force uid
  88 + if force_uid and uid == force_uid then
  89 + return awsPath
  90 + end
  91 +
  92 + --- hash percentage
75 if percentage >= 1 then 93 if percentage >= 1 then
76 - local uid = http_request.get_req_param("uid")  
77 - if not uid then  
78 - uid = 0  
79 - end  
80 -  
81 - local hash = tonumber(uid) % 100 94 + local hash = uid % 100
82 if hash <= percentage then 95 if hash <= percentage then
83 - redirectPath = "/apiaws"; 96 + return awsPath
84 end 97 end
85 end 98 end
86 return redirectPath 99 return redirectPath