Class: Gizzard::Command
- Inherits:
-
Object
- Object
- Gizzard::Command
- Defined in:
- lib/gizzard/commands.rb
Direct Known Subclasses
AddHostCommand, AddPartitionCommand, AddforwardingCommand, AddlinkCommand, BaseTransformCommand, BusyCommand, CopyCommand, CreateCommand, CreateTableCommand, DeleteCommand, DeleteforwardingCommand, DumpCommand, FindCommand, FinishMigrateCommand, FinishReplicaCommand, FlushCommand, ForwardingsCommand, HostsCommand, InfoCommand, InjectCommand, LinksCommand, ListHostsCommand, LookupCommand, MarkbusyCommand, MarkunbusyCommand, PairCommand, ReloadCommand, RemoveHostCommand, RemovePartitionCommand, RepairTablesCommand, ReportCommand, SetupMigrateCommand, SetupReplicaCommand, SubtreeCommand, TablesCommand, TopologyCommand, UnlinkCommand, UnwrapCommand, WrapCommand
Instance Attribute Summary collapse
-
#argv ⇒ Object
readonly
Returns the value of attribute argv.
-
#buffer ⇒ Object
readonly
Returns the value of attribute buffer.
-
#command_options ⇒ Object
readonly
Returns the value of attribute command_options.
-
#global_options ⇒ Object
readonly
Returns the value of attribute global_options.
-
#job_injector ⇒ Object
readonly
Returns the value of attribute job_injector.
-
#manager ⇒ Object
readonly
Returns the value of attribute manager.
Class Method Summary collapse
- .classify(string) ⇒ Object
- .make_job_injector(global_options, log) ⇒ Object
- .make_manager(global_options, log) ⇒ Object
- .run(command_name, global_options, argv, subcommand_options, log) ⇒ Object
Instance Method Summary collapse
- #confirm!(message = "Continue?") ⇒ Object
-
#get_base_name(transformations) ⇒ Object
Infer the shard base_name from a list of transformations.
- #help!(message = nil) ⇒ Object
-
#initialize(manager, job_injector, global_options, argv, command_options) ⇒ Command
constructor
A new instance of Command.
- #output(string) ⇒ Object
- #require_tables ⇒ Object
- #require_template_options ⇒ Object
Constructor Details
#initialize(manager, job_injector, global_options, argv, command_options) ⇒ Command
Returns a new instance of Command.
47 48 49 50 51 52 53 |
# File 'lib/gizzard/commands.rb', line 47 def initialize(manager, job_injector, , argv, ) @manager = manager @job_injector = job_injector @global_options = @argv = argv @command_options = end |
Instance Attribute Details
#argv ⇒ Object (readonly)
Returns the value of attribute argv.
45 46 47 |
# File 'lib/gizzard/commands.rb', line 45 def argv @argv end |
#buffer ⇒ Object (readonly)
Returns the value of attribute buffer.
8 9 10 |
# File 'lib/gizzard/commands.rb', line 8 def buffer @buffer end |
#command_options ⇒ Object (readonly)
Returns the value of attribute command_options.
45 46 47 |
# File 'lib/gizzard/commands.rb', line 45 def @command_options end |
#global_options ⇒ Object (readonly)
Returns the value of attribute global_options.
45 46 47 |
# File 'lib/gizzard/commands.rb', line 45 def @global_options end |
#job_injector ⇒ Object (readonly)
Returns the value of attribute job_injector.
45 46 47 |
# File 'lib/gizzard/commands.rb', line 45 def job_injector @job_injector end |
#manager ⇒ Object (readonly)
Returns the value of attribute manager.
45 46 47 |
# File 'lib/gizzard/commands.rb', line 45 def manager @manager end |
Class Method Details
.classify(string) ⇒ Object
25 26 27 |
# File 'lib/gizzard/commands.rb', line 25 def classify(string) string.split(/\W+/).map{|s| s.capitalize }.join("") end |
.make_job_injector(global_options, log) ⇒ Object
39 40 41 42 |
# File 'lib/gizzard/commands.rb', line 39 def make_job_injector(, log) RetryProxy.new .retry, JobInjector.new(.hosts.first, .injector_port, log, true, .dry) end |
.make_manager(global_options, log) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/gizzard/commands.rb', line 29 def make_manager(, log) raise "No hosts specified" unless .hosts hosts = .hosts.map {|h| [h, .port].join(":") } Nameserver.new(hosts, :retries => .retry, :log => log, :framed => .framed, :dry_run => .dry) end |
.run(command_name, global_options, argv, subcommand_options, log) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/gizzard/commands.rb', line 11 def run(command_name, , argv, , log) command_class = Gizzard.const_get("#{classify(command_name)}Command") @manager ||= make_manager(, log) @job_injector ||= make_job_injector(, log) command = command_class.new(@manager, @job_injector, , argv, ) command.run if command.buffer && command_name = .render.shift run(command_name, , command.buffer, OpenStruct.new, log) end end |
Instance Method Details
#confirm!(message = "Continue?") ⇒ Object
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/gizzard/commands.rb', line 103 def confirm!(="Continue?") unless .force begin print "#{} (y/n) "; $stdout.flush resp = $stdin.gets.chomp.downcase puts "" end while resp != 'y' && resp != 'n' exit if resp == 'n' end end |
#get_base_name(transformations) ⇒ Object
Infer the shard base_name from a list of transformations
96 97 98 99 100 101 |
# File 'lib/gizzard/commands.rb', line 96 def get_base_name(transformations) # Gets the first valid tree from the map of transformations -> applicable trees # Trees are maps of forwardings -> shards. Gets the first valid shard from the this tree. # Gets the ShardId of that shard and pulls the base name out of the table prefix transformations.values.find {|v| v.is_a?(Hash) && !v.values.empty? }.values.find {|v| !v.nil?}.id.table_prefix.split('_').first end |
#help!(message = nil) ⇒ Object
55 56 57 |
# File 'lib/gizzard/commands.rb', line 55 def help!( = nil) raise HelpNeededError, end |
#output(string) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/gizzard/commands.rb', line 59 def output(string) if .render.any? @buffer ||= [] @buffer << string.strip else puts string end end |
#require_tables ⇒ Object
68 69 70 71 72 73 |
# File 'lib/gizzard/commands.rb', line 68 def require_tables if !.tables puts "Please specify tables to repair with the --tables flag" exit 1 end end |
#require_template_options ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/gizzard/commands.rb', line 75 def = . || {} if . && .[:simple] fail = false if ![:concrete] fail = true STDERR.puts "Please specify a concrete shard type with --concrete flag when using --simple" end if ![:source_type] fail = true STDERR.puts "Please specify a source data type with --source-type flag when using --simple" end if ![:dest_type] fail = true STDERR.puts "Please specify a destination data type with --dest-type flag when using --simple" end exit 1 if fail end end |