Skip to content

Commit

Permalink
Fixes nil responses and more single quotes matches
Browse files Browse the repository at this point in the history
  • Loading branch information
dude051 committed May 29, 2015
1 parent 0667764 commit 01a4b9e
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions providers/cluster.rb
Expand Up @@ -65,8 +65,7 @@ def match_pattern_cluster_status(cluster_status, pattern)
Chef::Application.fatal!('[rabbitmq_cluster] cluster_status should not be empty')
end
match = cluster_status.match(pattern)
result = match && match[2]
result
match && match[2]
end

# Get currently joined cluster name from result string of "rabbitmqctl cluster_status"
Expand All @@ -81,25 +80,26 @@ def current_cluster_name(cluster_status)
def running_nodes(cluster_status)
pattern = '({running_nodes,\[\'*)(.*?)(\'*\]})'
match = match_pattern_cluster_status(cluster_status, pattern)
result = match && match.split(',')
result = match && match.gsub!(/'/, '').split(',')
Chef::Log.debug("[rabbitmq_cluster] running_nodes : #{result}")
result
end

# Get disc nodes
def disc_nodes(cluster_status)
pattern = '({disc,\[\'*)(.*?)(\'*\]})'
result = match_pattern_cluster_status(cluster_status, pattern)
match = match_pattern_cluster_status(cluster_status, pattern)
result = match && match.gsub!(/'/, '').split(',')
Chef::Log.debug("[rabbitmq_cluster] disc_nodes : #{result}")
result.split(',')
!result.nil? ? result : []
end

# Get ram nodes
def ram_nodes(cluster_status)
pattern = '({ram,\[\'*)(.*?)(\'*\]})'
result = match_pattern_cluster_status(cluster_status, pattern)
match = match_pattern_cluster_status(cluster_status, pattern)
result = match && match.gsub!(/'/, '').split(',')
Chef::Log.debug("[rabbitmq_cluster] ram_nodes : #{result}")
result.split(',')
!result.nil? ? result : []
end

# Get node name
Expand All @@ -110,8 +110,7 @@ def node_name
cmd = get_shellout(cmd)
cmd.run_command
cmd.error!
result = cmd.stdout.chomp
result.gsub!(/'/, '')
result = cmd.stdout.chomp.gsub!(/'/, '')
Chef::Log.debug("[rabbitmq_cluster] node name : #{result}")
result
end
Expand All @@ -124,6 +123,7 @@ def current_cluster_node_type(node_name, cluster_status)
elsif ram_nodes(cluster_status).include?(node_name)
var_cluster_node_type = 'ram'
end
Chef::Log.debug("[rabbitmq_cluster] current cluster node type : #{var_cluster_node_type}")
var_cluster_node_type
end

Expand Down Expand Up @@ -234,7 +234,7 @@ def change_cluster_node_type(cluster_node_type)
var_cluster_status = cluster_status
var_node_name = node_name
var_current_cluster_node_type = current_cluster_node_type(var_node_name, var_cluster_status)
var_cluster_node_type = parse_cluster_nodes_string(new_resource.cluster_nodes).select { |node| node['name'] == var_node_name }.first['type'] # ~FC039
var_cluster_node_type = parse_cluster_nodes_string(new_resource.cluster_nodes).each { |node| node['name'] == var_node_name }.first['type'] # ~FC039

This comment has been minimized.

Copy link
@iramello

iramello Apr 4, 2016

This does not work in AWS Opsworks and Chef 11.10. Using select here works fine.

This comment has been minimized.

Copy link
@jjasghar

jjasghar Apr 4, 2016

Contributor

I'm sorry but you'll have to fork this cookbook if you want to run chef 11 and ops works.

Please read the readme for what we officially support.


if var_current_cluster_node_type == var_cluster_node_type
Chef::Log.warn('[rabbitmq_cluster] Skip changing cluster node type : trying to change to same cluster node type')
Expand Down

0 comments on commit 01a4b9e

Please sign in to comment.