2018-05-04 17:39:57 -04:00
|
|
|
local util = require("util")
|
|
|
|
|
|
2019-05-25 23:50:18 -04:00
|
|
|
local string_format = string.format
|
|
|
|
|
local ngx_log = ngx.log
|
|
|
|
|
local INFO = ngx.INFO
|
2020-06-06 23:07:06 +08:00
|
|
|
local setmetatable = setmetatable
|
2019-05-25 23:50:18 -04:00
|
|
|
|
2018-05-04 17:39:57 -04:00
|
|
|
local _M = {}
|
|
|
|
|
|
2018-05-18 17:36:43 -04:00
|
|
|
function _M.new(self, o)
|
|
|
|
|
o = o or {}
|
|
|
|
|
setmetatable(o, self)
|
|
|
|
|
self.__index = self
|
|
|
|
|
return o
|
2018-05-09 11:26:04 -04:00
|
|
|
end
|
|
|
|
|
|
2021-07-29 14:23:19 -07:00
|
|
|
function _M.is_affinitized()
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
|
2018-05-18 17:36:43 -04:00
|
|
|
function _M.sync(self, backend)
|
2018-09-18 14:05:32 -04:00
|
|
|
self.traffic_shaping_policy = backend.trafficShapingPolicy
|
|
|
|
|
self.alternative_backends = backend.alternativeBackends
|
|
|
|
|
|
2018-05-18 17:36:43 -04:00
|
|
|
local nodes = util.get_nodes(backend.endpoints)
|
|
|
|
|
local changed = not util.deep_compare(self.instance.nodes, nodes)
|
|
|
|
|
if not changed then
|
|
|
|
|
return
|
2018-05-04 17:39:57 -04:00
|
|
|
end
|
|
|
|
|
|
2019-05-25 23:50:18 -04:00
|
|
|
ngx_log(INFO, string_format("[%s] nodes have changed for backend %s", self.name, backend.name))
|
|
|
|
|
|
2018-05-18 17:36:43 -04:00
|
|
|
self.instance:reinit(nodes)
|
2018-05-04 17:39:57 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return _M
|