lib/helpers/data.rb in gaptool-server-0.6.6 vs lib/helpers/data.rb in gaptool-server-0.7.0
- old
+ new
@@ -37,11 +37,11 @@
def self.overwrite_hash(key, data)
if !key.nil? && !data.nil? && !data.empty?
$redis.multi do
$redis.del(key)
- $redis.hmset(key, *data.select{ |k,v| !v.nil? && ((v.is_a?(String) && !v.empty?) || !!v == v)}.flatten)
+ $redis.hmset(key, *data.select{ |k,v| !v.nil? && ((v.is_a?(String) && !v.empty?) || (v.is_a?(Integer)) || !!v == v)}.flatten)
end
end
end
def self.set_server_data_attr(instance, attr, value)
@@ -150,16 +150,21 @@
rs['terminable'] = false
else
rs.delete('terminable')
end
+ if !rs['hidden'].nil? && rs['hidden'] == "true"
+ rs['hidden'] = true
+ end
+
if opts[:force_runlist] && rs['chef_runlist'].nil?
rs['chef_runlist'] = default_runlist
end
rs.delete_if {|k,v| v.nil? || (!!v != v && v.empty?)}
- rs['apps'] = apps_in_role(rs['role'])
+ rs['launch_time'] = rs['launch_time'].to_i if rs['launch_time']
+ rs['apps'] = apps_in_role(rs['role'], rs['environment'])
rs
end
def self.save_role_data(role, data)
return if role.nil? || data.nil?
@@ -170,20 +175,20 @@
if data['sg']
sgs = data.delete("sg") || {}
overwrite_hash("role:#{role}:sg", sgs)
end
if data['apps']
- apps = data.delete("apps") || []
- apps.each {|a| add_app(a, role)}
+ apps = data.delete("apps")
+ apps.each {|env, app| add_app(app, role, env)}
end
overwrite_hash("role:#{role}", data)
$redis.sadd("roles", role)
end
- def self.get_role_data(role)
+ def self.get_role_data(role, environment=nil)
res = $redis.hgetall("role:#{role}")
- res['apps'] = apps_in_role(role)
+ res['apps'] = environment ? apps_in_role(role, environment) : []
res['amis'] = $redis.hgetall("role:#{role}:amis")
res['sg'] = $redis.hgetall("role:#{role}:sg")
res
end
@@ -229,46 +234,48 @@
def self.roles
Hash[$redis.smembers("roles").map {|r| [r, get_role_data(r)] }]
end
- def self.add_app(name, role)
+ def self.add_app(name, role, environment)
return if name.nil? || role.nil?
$redis.multi do
$redis.sadd("apps", name)
- $redis.sadd("role:#{role}:apps", name)
- $redis.set("app:#{name}", role)
+ $redis.sadd("apps:#{environment}", name)
+ $redis.sadd("role:#{role}:#{environment}:apps", name)
+ $redis.hset("app:#{name}", environment, role)
end
end
def self.remove_app(name)
return if name.nil?
key = "app:#{name}"
$redis.watch(key) do
- role = $redis.get(key)
- if !role.nil?
+ roles = $redis.hgetall(key)
+ if !roles.nil?
$redis.multi do |m|
m.del(key)
m.srem("apps", name)
- m.srem("role:#{role}:apps", name)
+ roles.each do |env, role|
+ m.srem("role:#{role}:#{env}:apps", name)
+ end
end
else
$redis.unwatch
end
end
end
def self.get_app_data(app)
- role = $redis.get("app:#{app}")
- return {"role" => role } unless role.nil?
+ return $redis.hgetall("app:#{app}")
end
def self.apps
$redis.smembers("apps")
end
- def self.apps_in_role(role)
- $redis.smembers("role:#{role}:apps")
+ def self.apps_in_role(role, environment)
+ $redis.smembers("role:#{role}:#{environment}:apps")
end
def self.stringify_apps(rs)
if !rs.nil? && !rs['apps'].nil?
rs['apps'] = rs['apps'].to_json