Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ops
/
yoho-ansible-roles
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
chunhua.zhang
6 years ago
Commit
fa56f0b0c80b516dcbc3fa1031cae9b09670ef68
1 parent
9cbc3af2
switch
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
0 deletions
roles/openresty/files/java-nginx-config/nginx/conf/lua/init_lua.lua
roles/openresty/files/java-nginx-config/nginx/conf/lua/switch_controller.lua
roles/openresty/files/java-nginx-config/nginx/conf/vhosts/erp.yoho.yohoops.org.conf
roles/openresty/templates/nginx.conf.j2
roles/openresty/files/java-nginx-config/nginx/conf/lua/init_lua.lua
View file @
fa56f0b
local
lrucache
=
require
"resty.lrucache"
local
switch_controller
=
require
"switch_controller"
-- init redis twemproxy config
...
...
@@ -20,6 +21,8 @@ lua_context.lua_conf_cache=ngx.shared.ngxconf
lua_context
.
configs
=
{}
--- init switch to aws percentage
switch_controller
.
init
()
ngx
.
shared
.
upstream
:
flush_all
()
ngx
.
shared
.
upstream
:
flush_expired
()
...
...
roles/openresty/files/java-nginx-config/nginx/conf/lua/switch_controller.lua
0 → 100644
View file @
fa56f0b
local
modname
=
...
local
M
=
{}
_G
[
modname
]
=
M
package.loaded
[
modname
]
=
M
-- switch.
-- switch_to_aws: http://erp.yoho.yohoops.org/switch/?method=switch&percentage=10
-- switch query: http://erp.yoho.yohoops.org/switch/?method=query
-- mal ip controller api --------
function
M
:
switch
()
local
method
=
http_request
.
get_req_param
(
"method"
)
if
method
==
"query"
then
local
percentage
=
lua_context
.
lua_conf_cache
:
get
(
"switch:percentage"
)
ngx
.
say
(
percentage
)
ngx
.
exit
(
ngx
.
HTTP_OK
)
end
if
method
==
"switch"
then
local
percentage
=
http_request
.
get_req_param
(
"percentage"
)
if
percentage
then
lua_context
.
lua_conf_cache
:
set
(
"switch:percentage"
,
percentage
)
ngx
.
exit
(
ngx
.
HTTP_OK
)
end
end
end
function
M
:
init
()
return
lua_context
.
lua_conf_cache
:
set
(
"switch:percentage"
,
0
)
end
function
M
:
get_percentage
()
return
lua_context
.
lua_conf_cache
:
get
(
"switch:percentage"
)
end
...
...
roles/openresty/files/java-nginx-config/nginx/conf/vhosts/erp.yoho.yohoops.org.conf
View file @
fa56f0b
...
...
@@ -36,6 +36,14 @@ server {
'
;
}
## switch management
location
= /
switch
{
content_by_lua
'
local
switch
=
require
"switch_controller"
;
switch
:
switch
();
'
;
}
location
= /
upstreams
{
content_by_lua_file
"conf/lua/upstream.lua"
;
}
...
...
roles/openresty/templates/nginx.conf.j2
View file @
fa56f0b
...
...
@@ -176,6 +176,12 @@ http
#apigatewayend
# upstream for yoho-core-java aws
upstream java-aws {
server java-gateway-431f16063270008f.elb.cn-north-1.amazonaws.com.cn:8080 max_fails=5 fail_timeout=3s;
keepalive 32;
}
#apigatewayend
# activity
...
...
Please
register
or
login
to post a comment