Skip to content

Commit

Permalink
Merge pull request #803 from Mashape/feat/cassandra-driver
Browse files Browse the repository at this point in the history
feat(dao) switch to lua-cassandra 0.4.0
  • Loading branch information
thibaultcha committed Dec 18, 2015
2 parents d3a6fe9 + 1ab5d1c commit 3bff456
Show file tree
Hide file tree
Showing 30 changed files with 830 additions and 746 deletions.
2 changes: 0 additions & 2 deletions bin/kong
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,5 @@ elseif not commands[cmd] then
os.exit(1)
end

require "kong.tools.ngx_stub"

-- Load and execute desired command
require(commands[cmd])
2 changes: 1 addition & 1 deletion kong-0.5.4-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies = {
"yaml ~> 1.1.2-1",
"lapis ~> 1.3.1-1",
"stringy ~> 0.4-1",
"lua-cassandra ~> 0.3.6-0",
"lua-cassandra ~> 0.4.0-0",
"multipart ~> 0.2-1",
"lua-path ~> 0.2.3-1",
"lua-cjson ~> 2.1.0-1",
Expand Down
41 changes: 17 additions & 24 deletions kong.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,53 +64,44 @@
# contact_points:
# - "localhost:9042"

# timeout: 1000

# keyspace: kong

######
## Time (in milliseconds) for which sockets will be keep alive.
## for being eventually re-used before being closed.
# keepalive: 60000
## Name of the keyspace used by Kong. Will be created if it does not exist.
# keyspace: kong

######
## Keyspace options. Set those before running Kong or any migration.
## Those settings will be used to create a keyspace with the desired options
## when first running the migrations.
## See http://docs.datastax.com/en/cql/3.1/cql/cql_reference/create_keyspace_r.html

######
## The name of the replica placement strategy class for the new keyspace.
## The name of the replica placement strategy class for the keyspace.
## Can be "SimpleStrategy" or "NetworkTopologyStrategy".
# replication_strategy: SimpleStrategy

######
## For SimpleStrategy only.
## The number of replicas of data on multiple nodes.
# replication_factor: 1

######
## For NetworkTopologyStrategy only.
## The number of replicas of data on multiple nodes in each data center.
# data_centers:
# dc1: 2
# dc2: 3

######
## If true, will enable client-to-node encryption.
# ssl: false

######
## If true, will verify the SSL certificate in use.
## `ssl_certificate` must be provided.
# ssl_verify: false

######
## **Absolute path** to the certificate authority file for your cluster.
# ssl_certificate: "/path/to/cluster-ca-certificate.pem"
#####
## Client-to-node TLS options.
## `enabled`: if true, will connect to your Cassandra instance using TLS.
## `verify`: if true, will verify the server certificate using the given CA file.
## `certificate_authority`: an absolute path to the trusted CA certificate in PEM format used to verify the server certificate.
## For additional SSL settings, see the ngx_lua `lua_ssl_*` directives.
# ssl:
# enabled: false
# verify: false
# certificate_authority: "/path/to/cluster-ca-certificate.pem"

######
## If the cluster as authentication enabled, provide a user and a password here.
## Cluster authentication options. Provide a user and a password here if your cluster uses the
## PasswordAuthenticator scheme.
# user: cassandra
# password: cassandra

Expand Down Expand Up @@ -196,6 +187,8 @@ nginx: |
lua_max_pending_timers 16384;
lua_shared_dict locks 100k;
lua_shared_dict cache {{memory_cache_size}}m;
lua_shared_dict cassandra 1m;
lua_shared_dict cassandra_prepared 5m;
lua_socket_log_errors off;
{{lua_ssl_trusted_certificate}}
Expand Down
10 changes: 5 additions & 5 deletions kong/cli/migrations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ if args.command == "list" then
elseif migrations then
cutils.logger:info(string.format(
"Executed migrations for keyspace %s (%s):",
cutils.colors.yellow(dao_factory._properties.keyspace),
cutils.colors.yellow(dao_factory.properties.keyspace),
dao_factory.type
))

Expand All @@ -63,7 +63,7 @@ if args.command == "list" then
cutils.logger:info(string.format(
"No migrations have been run yet for %s on keyspace: %s",
cutils.colors.yellow(dao_factory.type),
cutils.colors.yellow(dao_factory._properties.keyspace)
cutils.colors.yellow(dao_factory.properties.keyspace)
))
end

Expand All @@ -73,7 +73,7 @@ elseif args.command == "up" then
cutils.logger:info(string.format(
"Migrating %s on keyspace \"%s\" (%s)",
cutils.colors.yellow(identifier),
cutils.colors.yellow(dao_factory._properties.keyspace),
cutils.colors.yellow(dao_factory.properties.keyspace),
dao_factory.type
))
end
Expand Down Expand Up @@ -110,7 +110,7 @@ elseif args.command == "down" then
cutils.logger:info(string.format(
"Rollbacking %s in keyspace \"%s\" (%s)",
cutils.colors.yellow(identifier),
cutils.colors.yellow(dao_factory._properties.keyspace),
cutils.colors.yellow(dao_factory.properties.keyspace),
dao_factory.type
))
end
Expand All @@ -130,7 +130,7 @@ elseif args.command == "down" then

elseif args.command == "reset" then

local keyspace = dao_factory._properties.keyspace
local keyspace = dao_factory.properties.keyspace

cutils.logger:info(string.format(
"Resetting \"%s\" keyspace (%s)",
Expand Down
10 changes: 5 additions & 5 deletions kong/cli/utils/signal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ local function prepare_database(args_config)
cutils.logger:info(string.format(
"Migrating %s on keyspace \"%s\" (%s)",
cutils.colors.yellow(identifier),
cutils.colors.yellow(dao_factory._properties.keyspace),
cutils.colors.yellow(dao_factory.properties.keyspace),
dao_factory.type
))
end
Expand Down Expand Up @@ -230,7 +230,7 @@ end
-- Checks whether a port is available. Exits the application if not available.
-- @param port The port to check
-- @param name Functional name the port is used for (display name)
-- @param timeout (optional) Timeout in seconds after which a failure is logged
-- @param timeout (optional) Timeout in seconds after which a failure is logged
-- and application exit is performed, if not provided then it will fail at once without retries.
local function check_port(port, name, timeout)
local expire = socket.gettime() + (timeout or 0)
Expand Down Expand Up @@ -267,9 +267,9 @@ function _M.send_signal(args_config, signal)
if not signal then signal = START end

if signal == START then
local ports = {
["Kong proxy"] = kong_config.proxy_port,
["Kong proxy ssl"] = kong_config.proxy_ssl_port,
local ports = {
["Kong proxy"] = kong_config.proxy_port,
["Kong proxy ssl"] = kong_config.proxy_ssl_port,
["Kong admin api"] = kong_config.admin_api_port
}
for name, port in pairs(ports) do
Expand Down
14 changes: 9 additions & 5 deletions kong/dao/cassandra/apis.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ local BaseDao = require "kong.dao.cassandra.base_dao"
local apis_schema = require "kong.dao.schemas.apis"
local query_builder = require "kong.dao.cassandra.query_builder"

local ipairs = ipairs
local table_insert = table.insert

local Apis = BaseDao:extend()

function Apis:new(properties)
Expand All @@ -13,13 +16,14 @@ end
function Apis:find_all()
local apis = {}
local select_q = query_builder.select(self._table)
for rows, err in Apis.super.execute(self, select_q, nil, nil, {auto_paging=true}) do

for rows, err in self:execute(select_q, nil, {auto_paging = true}) do
if err then
return nil, err
end

for _, row in ipairs(rows) do
table.insert(apis, row)
elseif rows ~= nil then
for _, row in ipairs(rows) do
table_insert(apis, row)
end
end
end

Expand Down
Loading

0 comments on commit 3bff456

Please sign in to comment.