lib/gizzmo.rb in gizzmo-0.10.0 vs lib/gizzmo.rb in gizzmo-0.10.1
- old
+ new
@@ -5,23 +5,38 @@
require "ostruct"
require "gizzard"
require "yaml"
DOC_STRINGS = {
- "create" => "Create shard(s) of a given Java/Scala class. If you don't know the list of available classes, you can just try a bogus class, and the exception will include a list of valid classes.",
- "wrap" => "Wrapping creates a new (virtual, e.g. blocking, replicating, etc.) shard, and relinks SHARD_ID_TO_WRAP's parent links to run through the new shard.",
+ "addforwarding" => "Add a forwarding from a graph_id / base_source_id to a given shard.",
+ "addlink" => "Add a relationship link between two shards.",
+ "create" => "Create shard(s) of a given Java/Scala class. If you don't know the list of available classes, you can just try a bogus class, and the exception will include a list of valid classes.",
+ "drill" => "Show shard trees for replicas of a given structure signature (from 'report').",
+ "find" => "Show all shards with a given hostname.",
+ "finish-replica" => "Remove the write-only barrier in front of a shard that's finished being copied after 'setup-replica'.",
+ "flush" => "Flush error queue for a given priority.",
+ "forwardings" => "Get a list of all forwardings.",
+ "hosts" => "List hosts used in shard names in the forwarding table and replicas.",
+ "info" => "Show id/class/busy for shards.",
"inject" => "Inject jobs (as literal json) into the server. Jobs can be linefeed-terminated from stdin, or passed as arguments. Priority is server-defined, but typically lower numbers (like 1) are lower priority.",
+ "links" => "List parent & child links for shards.",
"lookup" => "Lookup the shard id that holds the record for a given table / source_id.",
- "flush" => "Flush error queue for a given priority."
+ "markbusy" => "Mark a shard as busy.",
+ "pair" => "Report the replica pairing structure for a list of hosts.",
+ "reload" => "Instruct an appserver to reload its nameserver state.",
+ "report" => "Show each unique replica structure for a given list of shards. Usually this shard list comes from << gizzmo forwardings | awk '{ print $3 }' >>.",
+ "setup-replica" => "Add a replica to be parallel to an existing replica, in write-only mode, ready to be copied to.",
+ "wrap" => "Wrapping creates a new (virtual, e.g. blocking, replicating, etc.) shard, and relinks SHARD_ID_TO_WRAP's parent links to run through the new shard.",
}
ORIGINAL_ARGV = ARGV.dup
zero = File.basename($0)
# Container for parsed options
global_options = OpenStruct.new
global_options.render = []
+global_options.framed = false
subcommand_options = OpenStruct.new
# Leftover arguments
argv = nil
@@ -59,10 +74,16 @@
opts.separator(substr)
end
opts.separator("")
end
+def load_config(options, filename)
+ YAML.load(File.open(filename)).each do |k, v|
+ options.send("#{k}=", v)
+ end
+end
+
subcommands = {
'create' => OptionParser.new do |opts|
opts.banner = "Usage: #{zero} create [options] CLASS_NAME SHARD_ID [MORE SHARD_IDS...]"
separators(opts, DOC_STRINGS["create"])
@@ -161,10 +182,20 @@
end
end,
'links' => OptionParser.new do |opts|
opts.banner = "Usage: #{zero} links SHARD_ID [MORE SHARD_IDS...]"
separators(opts, DOC_STRINGS["links"])
+
+ opts.on("--ids", "Show shard ids only") do
+ subcommand_options.ids = true
+ end
+ opts.on("--up", "Show uplinks only") do
+ subcommand_options.up = true
+ end
+ opts.on("--down", "show downlinks only") do
+ subcommand_options.down = true
+ end
end,
'info' => OptionParser.new do |opts|
opts.banner = "Usage: #{zero} info SHARD_ID [MORE SHARD_IDS...]"
separators(opts, DOC_STRINGS["info"])
end,
@@ -207,10 +238,18 @@
end,
'busy' => OptionParser.new do |opts|
opts.banner = "Usage: #{zero} busy"
separators(opts, DOC_STRINGS["busy"])
end,
+ 'setup-replica' => OptionParser.new do |opts|
+ opts.banner = "Usage: #{zero} setup-replica SOURCE_SHARD_ID DESTINATION_SHARD_ID"
+ separators(opts, DOC_STRINGS["setup-replica"])
+ end,
+ 'finish-replica' => OptionParser.new do |opts|
+ opts.banner = "Usage: #{zero} finish-replica SOURCE_SHARD_ID DESTINATION_SHARD_ID"
+ separators(opts, DOC_STRINGS["finish-replica"])
+ end,
'setup-migrate' => OptionParser.new do |opts|
opts.banner = "Usage: #{zero} setup-migrate SOURCE_SHARD_ID DESTINATION_SHARD_ID"
separators(opts, DOC_STRINGS["setup-migrate"])
end,
'finish-migrate' => OptionParser.new do |opts|
@@ -229,10 +268,14 @@
subcommand_options.flush_all = true
end
end
}
+if ENV['GIZZMORC']
+ load_config(global_options, ENV['GIZZMORC'])
+end
+
global = OptionParser.new do |opts|
opts.banner = "Usage: #{zero} [global-options] SUBCOMMAND [subcommand-options]"
opts.separator ""
opts.separator "Gizzmo is a tool for manipulating the forwardings and replication structure of"
opts.separator "Gizzard-based datastores. It can also perform bulk job operations."
@@ -241,11 +284,11 @@
opts.separator "also useful to remember that global options come *before* the subcommand, while"
opts.separator "subcommand options come *after* the subcommand."
opts.separator ""
opts.separator "You may find it useful to create a ~/.gizzmorc file, which is simply YAML"
opts.separator "key/value pairs corresponding to options you want by default. A common .gizzmorc"
- opts.separator "simply contain:"
+ opts.separator "simply contains:"
opts.separator ""
opts.separator " host: localhost"
opts.separator " port: 7917"
opts.separator ""
opts.separator "Subcommands:"
@@ -268,10 +311,14 @@
opts.on("-P", "--port=PORT", "PORT of remote thrift service") do |port|
global_options.port = port.to_i
end
+ opts.on("-F", "--framed", "use the thrift framed transport") do |framed|
+ global_options.framed = true
+ end
+
opts.on("-r", "--retry=TIMES", "TIMES to retry the command") do |r|
global_options.retry = r
end
opts.on("-t", "--timeout=SECONDS", "SECONDS to let the command run") do |r|
@@ -288,14 +335,12 @@
opts.on("-D", "--dry-run", "") do |port|
global_options.dry = true
end
- opts.on("-C", "--config=YAML_FILE", "YAML_FILE of option key/values") do |file|
- YAML.load(File.open(file)).each do |k, v|
- global_options.send("#{k}=", v)
- end
+ opts.on("-C", "--config=YAML_FILE", "YAML_FILE of option key/values") do |filename|
+ load_config(global_options, filename)
end
opts.on("-L", "--log=LOG_FILE", "Path to LOG_FILE") do |file|
global_options.log = file
end
@@ -368,10 +413,10 @@
else
yield
end
end
-begin
+begin
custom_timeout(global_options.timeout) do
Gizzard::Command.run(subcommand_name, global_options, argv, subcommand_options, log)
end
rescue HelpNeededError => e
if e.class.name != e.message