Class: Gizzard::RebalanceCommand
- Inherits:
-
BaseTransformCommand
- Object
- Command
- BaseTransformCommand
- Gizzard::RebalanceCommand
- Defined in:
- lib/gizzard/commands.rb
Instance Attribute Summary
Attributes inherited from Command
#argv, #buffer, #command_options, #global_options, #job_injector, #manager
Instance Method Summary collapse
Methods inherited from BaseTransformCommand
Methods inherited from Command
classify, #confirm!, #get_base_name, #help!, #initialize, make_job_injector, make_manager, #output, #require_tables, #require_template_options, run
Constructor Details
This class inherits a constructor from Gizzard::Command
Instance Method Details
#get_transformations ⇒ Object
908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 |
# File 'lib/gizzard/commands.rb', line 908 def get_transformations help!("must have an even number of arguments") unless @argv.length % 2 == 0 require_tables = . || {} manifest = manager.manifest(*.tables) copy_wrapper = [:copy_wrapper] transformations = {} dest_templates_and_weights = {} @argv.each_slice(2) do |(weight_s, to_template_s)| to = ShardTemplate.parse(to_template_s) weight = weight_s.to_i dest_templates_and_weights[to] = weight end .tables.inject({}) do |all, table| trees = manifest.trees.reject {|(f, s)| f.table_id != table } rebalancer = Rebalancer.new(trees, dest_templates_and_weights, copy_wrapper) all.update(rebalancer.transformations) {|t,a,b| a.merge b } end end |