Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dao) do not spawn cluster when outside of ngx_lua #812

Merged
merged 1 commit into from
Dec 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions kong/dao/cassandra/factory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ local stringy = require "stringy"
local Object = require "classic"
local utils = require "kong.tools.utils"

if ngx ~= nil and type(ngx.get_phase) == "function" and ngx.get_phase() == "init" then
if ngx ~= nil and type(ngx.get_phase) == "function" and ngx.get_phase() == "init" and not ngx.stub then
cassandra.set_log_level("INFO")
else
cassandra.set_log_level("QUIET")
Expand All @@ -30,14 +30,16 @@ end

-- Instantiate a Cassandra Factory and all its DAOs for various entities
-- @param `properties` Cassandra properties
function CassandraFactory:new(properties, plugins)
function CassandraFactory:new(properties, plugins, spawn_cluster)
self.properties = properties
self.type = "cassandra"
self.daos = {}

local ok, err = cassandra.spawn_cluster(self:get_session_options())
if not ok then
error(err)
if spawn_cluster then
local ok, err = cassandra.spawn_cluster(self:get_session_options())
if not ok then
error(err)
end
end

-- Load core entities DAOs
Expand Down
2 changes: 1 addition & 1 deletion kong/kong.lua
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ local Kong = {}
-- it will be thrown and needs to be catched in `init_by_lua`.
function Kong.init()
configuration = config_loader.load(os.getenv("KONG_CONF"))
dao = dao_loader.load(configuration)
dao = dao_loader.load(configuration, true)
loaded_plugins = load_node_plugins(configuration)
process_id = utils.random_string()
ngx.update_time()
Expand Down
4 changes: 2 additions & 2 deletions kong/tools/dao_loader.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
local _M = {}

function _M.load(config)
function _M.load(config, spawn_cluster)
local DaoFactory = require("kong.dao."..config.database..".factory")
return DaoFactory(config.dao_config, config.plugins_available)
return DaoFactory(config.dao_config, config.plugins_available, spawn_cluster)
end

return _M
3 changes: 2 additions & 1 deletion kong/tools/ngx_stub.lua
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,11 @@ local shared_mt = {
}

_G.ngx = {
stub = true,
req = {},
ctx = {},
header = {},
get_phase = function() return "not_ngx_lua" end,
get_phase = function() return "init" end,
exit = function() end,
say = function() end,
log = function() end,
Expand Down