Skip to content

Commit

Permalink
Update brick_layout_chained to work around regression.
Browse files Browse the repository at this point in the history
See the previous commit for more informatio on the regression.
  • Loading branch information
purpleidea committed Oct 21, 2014
1 parent 06af205 commit 6dfaa84
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 38 deletions.
42 changes: 4 additions & 38 deletions lib/puppet/parser/functions/brick_layout_chained.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ module Puppet::Parser::Functions

Puppet::Parser::Functions.function('warning') # load function
Puppet::Parser::Functions.function('brick_str_to_hash') # load function
Puppet::Parser::Functions.function('get_hostlist') # load function
Puppet::Parser::Functions.function('get_brickstacks') # load function
# signature: replica, bricks -> bricks
unless args.length == 2
raise Puppet::ParseError, "brick_layout_chained(): wrong number of arguments (#{args.length}; must be 2)"
Expand All @@ -45,49 +47,13 @@ module Puppet::Parser::Functions
replica = args[0].to_i # convert from string if needed
bricks = args[1]

def get_hostlist(bricks)
hosts = []
bricks.each do |x|
key = x['host']
val = x['path']

if not hosts.include?(key)
hosts.push(key)
end
end
return hosts
end

def get_brickstacks(bricks, sort=false)
stacks = {}
hosts = get_hostlist(bricks)
bricks.each do |x|
key = x['host']
val = x['path']
if not stacks.include?(key); stacks[key] = []; end # initialize
stacks[key].push(val)
end

# optionally sort the paths in each individual host stack...
if sort
sorted_stacks = {}
stacks.each do |k, v|
# TODO: there should probably be a proper 'sorted' function for
# paths, in case they aren't numbered sanely _WITH_ padding.
sorted_stacks[k] = v.sort
end
return sorted_stacks
end
return stacks
end

final = []
pointer = 0
parsed = function_brick_str_to_hash([bricks])
# TODO: there should probably be a proper 'sorted' function for
# hostnames, in case they aren't numbered sanely _WITH_ padding.
hosts = get_hostlist(parsed).sort
brickstack = get_brickstacks(parsed, sort=true)
hosts = function_get_hostlist([parsed]).sort
brickstack = function_get_brickstacks([parsed, true])

if bricks.length == 0; return []; end

Expand Down
64 changes: 64 additions & 0 deletions lib/puppet/parser/functions/get_brickstacks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# GlusterFS module by James
# Copyright (C) 2010-2013+ James Shubin
# Written by James Shubin <james@shubin.ca>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

module Puppet::Parser::Functions
newfunction(:get_brickstacks, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
Helper function for the brick layout algorithms.
ENDHEREDOC

Puppet::Parser::Functions.function('get_hostlist') # load function

# signature: replica, bricks -> bricks
unless args.length == 2
raise Puppet::ParseError, "get_brickstacks(): wrong number of arguments (#{args.length}; must be 2)"
end
unless args[0].is_a?(Array)
raise Puppet::ParseError, "get_brickstacks(): expects the first argument to be an array, got #{args[0].inspect} which is of type #{args[0].class}"
end
unless args[1].is_a?(TrueClass) or args[1].is_a?(FalseClass)
raise Puppet::ParseError, "get_brickstacks(): expects the second argument to be a boolean, got #{args[1].inspect} which is of type #{args[1].class}"
end

bricks = args[0]
sort = args[1]

stacks = {}
hosts = function_get_hostlist([bricks])
bricks.each do |x|
key = x['host']
val = x['path']
if not stacks.include?(key); stacks[key] = []; end # initialize
stacks[key].push(val)
end

# optionally sort the paths in each individual host stack...
if sort
sorted_stacks = {}
stacks.each do |k, v|
# TODO: there should probably be a proper 'sorted' function for
# paths, in case they aren't numbered sanely _WITH_ padding.
sorted_stacks[k] = v.sort
end
stacks = sorted_stacks
end

stacks # return
end
end

# vim: ts=8
48 changes: 48 additions & 0 deletions lib/puppet/parser/functions/get_hostlist.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# GlusterFS module by James
# Copyright (C) 2010-2013+ James Shubin
# Written by James Shubin <james@shubin.ca>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

module Puppet::Parser::Functions
newfunction(:get_hostlist, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
Helper function for the brick layout algorithms.
ENDHEREDOC

# signature: replica, bricks -> bricks
unless args.length == 1
raise Puppet::ParseError, "get_hostlist(): wrong number of arguments (#{args.length}; must be 1)"
end
unless args[0].is_a?(Array)
raise Puppet::ParseError, "get_hostlist(): expects the first argument to be an array, got #{args[0].inspect} which is of type #{args[0].class}"
end

bricks = args[0]

hosts = []
bricks.each do |x|
key = x['host']
val = x['path']

if not hosts.include?(key)
hosts.push(key)
end
end

hosts # return
end
end

# vim: ts=8

0 comments on commit 6dfaa84

Please sign in to comment.