Skip to content

Commit

Permalink
feat: support resource name
Browse files Browse the repository at this point in the history
  • Loading branch information
johzchen committed Jun 5, 2020
1 parent f615cf7 commit 56ee484
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 2 deletions.
14 changes: 13 additions & 1 deletion apisix/balancer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
local healthcheck = require("resty.healthcheck")
local healthcheck
local require = require
local roundrobin = require("resty.roundrobin")
local discovery = require("apisix.discovery.init").discovery
local resty_chash = require("resty.chash")
Expand All @@ -26,6 +27,7 @@ local str_gsub = string.gsub
local pairs = pairs
local ipairs = ipairs
local tostring = tostring

local set_more_tries = balancer.set_more_tries
local get_last_failure = balancer.get_last_failure
local set_timeouts = balancer.set_timeouts
Expand Down Expand Up @@ -82,6 +84,9 @@ end


local function create_checker(upstream, healthcheck_parent)
if healthcheck == nil then
healthcheck = require("resty.healthcheck")
end
local checker = healthcheck.new({
name = "upstream#" .. healthcheck_parent.key,
shm_name = "upstream-healthcheck",
Expand Down Expand Up @@ -378,5 +383,12 @@ function _M.init_worker()
end
end

function _M.upstreams()
if not upstreams_etcd then
return nil, nil
end

return upstreams_etcd.values, upstreams_etcd.conf_version
end

return _M
3 changes: 3 additions & 0 deletions apisix/schema_def.lua
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ local upstream_schema = {
description = "enable websocket for request",
type = "boolean"
},
name = {type = "string", maxLength = 50},
desc = {type = "string", maxLength = 256},
service_name = {type = "string", maxLength = 50},
id = id_schema
Expand Down Expand Up @@ -369,6 +370,7 @@ _M.route = {
},
uniqueItems = true,
},
name = {type = "string", maxLength = 50},
desc = {type = "string", maxLength = 256},
priority = {type = "integer", default = 0},

Expand Down Expand Up @@ -446,6 +448,7 @@ _M.service = {
plugins = plugins_schema,
upstream = upstream_schema,
upstream_id = id_schema,
name = {type = "string", maxLength = 50},
desc = {type = "string", maxLength = 256},
},
anyOf = {
Expand Down
42 changes: 42 additions & 0 deletions t/admin/routes.t
Original file line number Diff line number Diff line change
Expand Up @@ -1730,3 +1730,45 @@ GET /t
passed
--- no_error_log
[error]



=== TEST 47: set route(id: 1 + name: test name)
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"methods": ["GET"],
"upstream": {
"nodes": {
"127.0.0.1:8080": 1
},
"type": "roundrobin"
},
"name": "test name",
"uri": "/index.html"
}]],
[[{
"node": {
"value": {
"name": "test name"
},
"key": "/apisix/routes/1"
},
"action": "set"
}]]
)

ngx.status = code
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
--- no_error_log
[error]
46 changes: 46 additions & 0 deletions t/admin/services.t
Original file line number Diff line number Diff line change
Expand Up @@ -882,3 +882,49 @@ GET /t
200 passed
--- no_error_log
[error]



=== TEST 26: set service(id: 1 + test service name)
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/services/1',
ngx.HTTP_PUT,
[[{
"upstream": {
"nodes": {
"127.0.0.1:8080": 1
},
"type": "roundrobin"
},
"name": "test service name"
}]],
[[{
"node": {
"value": {
"upstream": {
"nodes": {
"127.0.0.1:8080": 1
},
"type": "roundrobin"
},
"name": "test service name"
},
"key": "/apisix/services/1"
},
"action": "set"
}]]
)

ngx.status = code
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
--- no_error_log
[error]
44 changes: 43 additions & 1 deletion t/admin/upstream.t
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@ GET /t



=== TEST 35: type chash, hash_on: consumer, don't need upstream key
=== TEST 35: type chash, hash_on: consumer, donot need upstream key
--- config
location /t {
content_by_lua_block {
Expand Down Expand Up @@ -1236,3 +1236,45 @@ GET /t
{"error_msg":"invalid configuration: property \"hash_on\" validation failed: matches non of the enum values"}
--- no_error_log
[error]



=== TEST 38: set upstream(id: 1 + name: test name)
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/upstreams/1',
ngx.HTTP_PUT,
[[{
"nodes": {
"127.0.0.1:8080": 1
},
"type": "roundrobin",
"name": "test upstream name"
}]],
[[{
"node": {
"value": {
"nodes": {
"127.0.0.1:8080": 1
},
"type": "roundrobin",
"name": "test upstream name"
},
"key": "/apisix/upstreams/1"
},
"action": "set"
}]]
)

ngx.status = code
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
--- no_error_log
[error]

0 comments on commit 56ee484

Please sign in to comment.