gizzmo 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,177 @@
1
+ Copyright (c) 2010 Twitter, Inc.
2
+
3
+
4
+ Apache License
5
+ Version 2.0, January 2004
6
+ http://www.apache.org/licenses/
7
+
8
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
9
+
10
+ 1. Definitions.
11
+
12
+ "License" shall mean the terms and conditions for use, reproduction,
13
+ and distribution as defined by Sections 1 through 9 of this document.
14
+
15
+ "Licensor" shall mean the copyright owner or entity authorized by
16
+ the copyright owner that is granting the License.
17
+
18
+ "Legal Entity" shall mean the union of the acting entity and all
19
+ other entities that control, are controlled by, or are under common
20
+ control with that entity. For the purposes of this definition,
21
+ "control" means (i) the power, direct or indirect, to cause the
22
+ direction or management of such entity, whether by contract or
23
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
24
+ outstanding shares, or (iii) beneficial ownership of such entity.
25
+
26
+ "You" (or "Your") shall mean an individual or Legal Entity
27
+ exercising permissions granted by this License.
28
+
29
+ "Source" form shall mean the preferred form for making modifications,
30
+ including but not limited to software source code, documentation
31
+ source, and configuration files.
32
+
33
+ "Object" form shall mean any form resulting from mechanical
34
+ transformation or translation of a Source form, including but
35
+ not limited to compiled object code, generated documentation,
36
+ and conversions to other media types.
37
+
38
+ "Work" shall mean the work of authorship, whether in Source or
39
+ Object form, made available under the License, as indicated by a
40
+ copyright notice that is included in or attached to the work
41
+ (an example is provided in the Appendix below).
42
+
43
+ "Derivative Works" shall mean any work, whether in Source or Object
44
+ form, that is based on (or derived from) the Work and for which the
45
+ editorial revisions, annotations, elaborations, or other modifications
46
+ represent, as a whole, an original work of authorship. For the purposes
47
+ of this License, Derivative Works shall not include works that remain
48
+ separable from, or merely link (or bind by name) to the interfaces of,
49
+ the Work and Derivative Works thereof.
50
+
51
+ "Contribution" shall mean any work of authorship, including
52
+ the original version of the Work and any modifications or additions
53
+ to that Work or Derivative Works thereof, that is intentionally
54
+ submitted to Licensor for inclusion in the Work by the copyright owner
55
+ or by an individual or Legal Entity authorized to submit on behalf of
56
+ the copyright owner. For the purposes of this definition, "submitted"
57
+ means any form of electronic, verbal, or written communication sent
58
+ to the Licensor or its representatives, including but not limited to
59
+ communication on electronic mailing lists, source code control systems,
60
+ and issue tracking systems that are managed by, or on behalf of, the
61
+ Licensor for the purpose of discussing and improving the Work, but
62
+ excluding communication that is conspicuously marked or otherwise
63
+ designated in writing by the copyright owner as "Not a Contribution."
64
+
65
+ "Contributor" shall mean Licensor and any individual or Legal Entity
66
+ on behalf of whom a Contribution has been received by Licensor and
67
+ subsequently incorporated within the Work.
68
+
69
+ 2. Grant of Copyright License. Subject to the terms and conditions of
70
+ this License, each Contributor hereby grants to You a perpetual,
71
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
72
+ copyright license to reproduce, prepare Derivative Works of,
73
+ publicly display, publicly perform, sublicense, and distribute the
74
+ Work and such Derivative Works in Source or Object form.
75
+
76
+ 3. Grant of Patent License. Subject to the terms and conditions of
77
+ this License, each Contributor hereby grants to You a perpetual,
78
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
79
+ (except as stated in this section) patent license to make, have made,
80
+ use, offer to sell, sell, import, and otherwise transfer the Work,
81
+ where such license applies only to those patent claims licensable
82
+ by such Contributor that are necessarily infringed by their
83
+ Contribution(s) alone or by combination of their Contribution(s)
84
+ with the Work to which such Contribution(s) was submitted. If You
85
+ institute patent litigation against any entity (including a
86
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
87
+ or a Contribution incorporated within the Work constitutes direct
88
+ or contributory patent infringement, then any patent licenses
89
+ granted to You under this License for that Work shall terminate
90
+ as of the date such litigation is filed.
91
+
92
+ 4. Redistribution. You may reproduce and distribute copies of the
93
+ Work or Derivative Works thereof in any medium, with or without
94
+ modifications, and in Source or Object form, provided that You
95
+ meet the following conditions:
96
+
97
+ (a) You must give any other recipients of the Work or
98
+ Derivative Works a copy of this License; and
99
+
100
+ (b) You must cause any modified files to carry prominent notices
101
+ stating that You changed the files; and
102
+
103
+ (c) You must retain, in the Source form of any Derivative Works
104
+ that You distribute, all copyright, patent, trademark, and
105
+ attribution notices from the Source form of the Work,
106
+ excluding those notices that do not pertain to any part of
107
+ the Derivative Works; and
108
+
109
+ (d) If the Work includes a "NOTICE" text file as part of its
110
+ distribution, then any Derivative Works that You distribute must
111
+ include a readable copy of the attribution notices contained
112
+ within such NOTICE file, excluding those notices that do not
113
+ pertain to any part of the Derivative Works, in at least one
114
+ of the following places: within a NOTICE text file distributed
115
+ as part of the Derivative Works; within the Source form or
116
+ documentation, if provided along with the Derivative Works; or,
117
+ within a display generated by the Derivative Works, if and
118
+ wherever such third-party notices normally appear. The contents
119
+ of the NOTICE file are for informational purposes only and
120
+ do not modify the License. You may add Your own attribution
121
+ notices within Derivative Works that You distribute, alongside
122
+ or as an addendum to the NOTICE text from the Work, provided
123
+ that such additional attribution notices cannot be construed
124
+ as modifying the License.
125
+
126
+ You may add Your own copyright statement to Your modifications and
127
+ may provide additional or different license terms and conditions
128
+ for use, reproduction, or distribution of Your modifications, or
129
+ for any such Derivative Works as a whole, provided Your use,
130
+ reproduction, and distribution of the Work otherwise complies with
131
+ the conditions stated in this License.
132
+
133
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
134
+ any Contribution intentionally submitted for inclusion in the Work
135
+ by You to the Licensor shall be under the terms and conditions of
136
+ this License, without any additional terms or conditions.
137
+ Notwithstanding the above, nothing herein shall supersede or modify
138
+ the terms of any separate license agreement you may have executed
139
+ with Licensor regarding such Contributions.
140
+
141
+ 6. Trademarks. This License does not grant permission to use the trade
142
+ names, trademarks, service marks, or product names of the Licensor,
143
+ except as required for reasonable and customary use in describing the
144
+ origin of the Work and reproducing the content of the NOTICE file.
145
+
146
+ 7. Disclaimer of Warranty. Unless required by applicable law or
147
+ agreed to in writing, Licensor provides the Work (and each
148
+ Contributor provides its Contributions) on an "AS IS" BASIS,
149
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
150
+ implied, including, without limitation, any warranties or conditions
151
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
152
+ PARTICULAR PURPOSE. You are solely responsible for determining the
153
+ appropriateness of using or redistributing the Work and assume any
154
+ risks associated with Your exercise of permissions under this License.
155
+
156
+ 8. Limitation of Liability. In no event and under no legal theory,
157
+ whether in tort (including negligence), contract, or otherwise,
158
+ unless required by applicable law (such as deliberate and grossly
159
+ negligent acts) or agreed to in writing, shall any Contributor be
160
+ liable to You for damages, including any direct, indirect, special,
161
+ incidental, or consequential damages of any character arising as a
162
+ result of this License or out of the use or inability to use the
163
+ Work (including but not limited to damages for loss of goodwill,
164
+ work stoppage, computer failure or malfunction, or any and all
165
+ other commercial damages or losses), even if such Contributor
166
+ has been advised of the possibility of such damages.
167
+
168
+ 9. Accepting Warranty or Additional Liability. While redistributing
169
+ the Work or Derivative Works thereof, You may choose to offer,
170
+ and charge a fee for, acceptance of support, warranty, indemnity,
171
+ or other liability obligations and/or rights consistent with this
172
+ License. However, in accepting such obligations, You may act only
173
+ on Your own behalf and on Your sole responsibility, not on behalf
174
+ of any other Contributor, and only if You agree to indemnify,
175
+ defend, and hold each Contributor harmless for any liability
176
+ incurred by, or claims asserted against, such Contributor by reason
177
+ of your accepting any such warranty or additional liability.
data/README.rdoc ADDED
@@ -0,0 +1,45 @@
1
+ = gizzmo
2
+
3
+ Gizzmo is a command-line client for managing gizzard clusters.
4
+
5
+ == Installation and setup
6
+
7
+ Installation is a simple gem install. You may find it useful to create a ~/.gizzmorc file, which is simply YAML key/values. The keys are the long-style command line option keys converted into Ruby-style variables. A common .gizzmorc will simply be:
8
+
9
+ host: localhost
10
+ port: 7917
11
+
12
+ == Usage
13
+
14
+ Run `gizzmo help` for up-to-date usage.
15
+
16
+ == Recipes
17
+
18
+ === Block and unblock a shard
19
+
20
+ BLOCKER=`gizzmo wrap com.twitter.gizzard.shards.BlockedShard a_shard`
21
+
22
+ gizzmo unwrap $BLOCKER
23
+
24
+ === Reweight a shard safely (the hard way)
25
+
26
+ NEW_WEIGHT=1
27
+ REPL=`gizzmo wrap com.twitter.service.flock.edges.ReplicatingShard a_shard`
28
+ PARENT=`gizzmo links $REPL | cut -f 1 | grep -v $REPL | head -1`
29
+ gizzmo addlink $PARENT a_shard $NEW_WEIGHT
30
+ gizzmo unwrap $REPL
31
+
32
+ == Running tests
33
+
34
+ The tests may be somewhat difficult to run outside of Twitter. They assume the following:
35
+
36
+ 1. You have a running FlockDB development environment exposing a ShardManager over thrift on localhost:7917
37
+ 2. You don't mind blowing away the data in your dev environment.
38
+ 3. Your MySQL username and password are in the environment variables DB_USERNAME and DB_PASSWORD
39
+
40
+ Assuming you've put together the dependencies, ./test/test.sh should run fine.
41
+
42
+ == Copyright
43
+
44
+ Copyright (c) 2010 Twitter, Inc. See LICENSE for details.
45
+
data/Rakefile ADDED
@@ -0,0 +1,58 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "gizzmo"
8
+ gem.summary = %Q{Gizzmo is a command-line client for managing gizzard clusters.}
9
+ gem.description = %Q{Gizzmo is a command-line client for managing gizzard clusters.}
10
+ gem.email = "kmaxwell@twitter.com"
11
+ gem.homepage = "http://github.com/twitter/gizzmo"
12
+ gem.authors = ["Kyle Maxwell"]
13
+ end
14
+ Jeweler::GemcutterTasks.new
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
17
+ end
18
+
19
+ require 'rake/testtask'
20
+ Rake::TestTask.new(:test) do |test|
21
+ test.libs << 'lib' << 'test'
22
+ test.pattern = 'test/**/test_*.rb'
23
+ test.verbose = true
24
+ end
25
+
26
+ begin
27
+ require 'rcov/rcovtask'
28
+ Rcov::RcovTask.new do |test|
29
+ test.libs << 'test'
30
+ test.pattern = 'test/**/test_*.rb'
31
+ test.verbose = true
32
+ end
33
+ rescue LoadError
34
+ task :rcov do
35
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
36
+ end
37
+ end
38
+
39
+ task :test do
40
+ puts
41
+ puts "=" * 79
42
+ puts "You might want to read the README before running tests."
43
+ puts "=" * 79
44
+ sleep 2
45
+ exec File.join(File.dirname(__FILE__), "test", "test.sh")
46
+ end
47
+
48
+ task :default => :test
49
+
50
+ require 'rake/rdoctask'
51
+ Rake::RDocTask.new do |rdoc|
52
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
53
+
54
+ rdoc.rdoc_dir = 'rdoc'
55
+ rdoc.title = "gizzmo #{version}"
56
+ rdoc.rdoc_files.include('README*')
57
+ rdoc.rdoc_files.include('lib/**/*.rb')
58
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.4
data/bin/gizzmo ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ $: << File.dirname(__FILE__) + "/../lib"
3
+ load "gizzmo.rb"
data/gizzmo.gemspec ADDED
@@ -0,0 +1,72 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{gizzmo}
8
+ s.version = "0.1.4"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Kyle Maxwell"]
12
+ s.date = %q{2010-06-30}
13
+ s.default_executable = %q{gizzmo}
14
+ s.description = %q{Gizzmo is a command-line client for managing gizzard clusters.}
15
+ s.email = %q{kmaxwell@twitter.com}
16
+ s.executables = ["gizzmo"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".gitignore",
24
+ "LICENSE",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/gizzmo",
29
+ "gizzmo.gemspec",
30
+ "lib/gizzard.rb",
31
+ "lib/gizzard/commands.rb",
32
+ "lib/gizzard/thrift.rb",
33
+ "lib/gizzmo.rb",
34
+ "lib/vendor/thrift_client/simple.rb",
35
+ "test/config.yaml",
36
+ "test/expected/dry-wrap-table_b_0.txt",
37
+ "test/expected/empty-file.txt",
38
+ "test/expected/find-only-sql-shard-type.txt",
39
+ "test/expected/help-info.txt",
40
+ "test/expected/info.txt",
41
+ "test/expected/links-for-replicating_table_b_0.txt",
42
+ "test/expected/links-for-table_b_0.txt",
43
+ "test/expected/links-for-table_repl_0.txt",
44
+ "test/expected/original-find.txt",
45
+ "test/expected/subtree.txt",
46
+ "test/expected/unwrapped-replicating_table_b_0.txt",
47
+ "test/expected/unwrapped-table_b_0.txt",
48
+ "test/expected/wrap-table_b_0.txt",
49
+ "test/helper.rb",
50
+ "test/recreate.sql",
51
+ "test/test.sh"
52
+ ]
53
+ s.homepage = %q{http://github.com/twitter/gizzmo}
54
+ s.rdoc_options = ["--charset=UTF-8"]
55
+ s.require_paths = ["lib"]
56
+ s.rubygems_version = %q{1.3.6}
57
+ s.summary = %q{Gizzmo is a command-line client for managing gizzard clusters.}
58
+ s.test_files = [
59
+ "test/helper.rb"
60
+ ]
61
+
62
+ if s.respond_to? :specification_version then
63
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
64
+ s.specification_version = 3
65
+
66
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
67
+ else
68
+ end
69
+ else
70
+ end
71
+ end
72
+
data/lib/gizzard.rb ADDED
@@ -0,0 +1,4 @@
1
+ $: << File.dirname(__FILE__)
2
+ module Gizzard; end
3
+ require "gizzard/thrift"
4
+ require "gizzard/commands"
@@ -0,0 +1,195 @@
1
+ require "pp"
2
+ module Gizzard
3
+ class Command
4
+ include Thrift
5
+
6
+ def self.run(command_name, *args)
7
+ Gizzard.const_get("#{classify(command_name)}Command").new(*args).run
8
+ end
9
+
10
+ def self.classify(string)
11
+ string.split(/\W+/).map{|s| s.capitalize }.join("")
12
+ end
13
+
14
+ attr_reader :service, :global_options, :argv, :command_options
15
+ def initialize(service, global_options, argv, command_options)
16
+ @service = service
17
+ @global_options = global_options
18
+ @argv = argv
19
+ @command_options = command_options
20
+ end
21
+
22
+ def help!(message = nil)
23
+ raise HelpNeededError, message
24
+ end
25
+ end
26
+
27
+ class SubtreeCommand < Command
28
+ def run
29
+ @roots = []
30
+ argv.each do |arg|
31
+ @id = ShardId.parse(arg)
32
+ @roots << up(@id)
33
+ end
34
+ @roots.uniq.each do |root|
35
+ puts root.to_unix
36
+ down(root, 1)
37
+ end
38
+ end
39
+
40
+ def up(id)
41
+ links = service.list_upward_links(id)
42
+ if links.empty?
43
+ id
44
+ else
45
+ links.map{|link| link.up_id }.find{|up_id| up(up_id) }
46
+ end
47
+ end
48
+
49
+ def down(id, depth = 0)
50
+ service.list_downward_links(id).map do |link|
51
+ printable = " " * depth + link.down_id.to_unix
52
+ puts printable
53
+ down(link.down_id, depth + 1)
54
+ end
55
+ end
56
+ end
57
+
58
+ class ReloadCommand < Command
59
+ def run
60
+ puts "Are you sure? Reloading will affect production services immediately! (Type 'yes')"
61
+ if gets.chomp == "yes"
62
+ service.reload_forwardings
63
+ else
64
+ STDERR.puts "aborted"
65
+ end
66
+ end
67
+ end
68
+
69
+ class DeleteCommand < Command
70
+ def run
71
+ argv.each do |arg|
72
+ id = ShardId.parse(arg)
73
+ service.delete_shard(id)
74
+ puts id.to_unix
75
+ end
76
+ end
77
+ end
78
+
79
+ class AddlinkCommand < Command
80
+ def run
81
+ up_id, down_id, weight = argv
82
+ help! if argv.length != 3
83
+ weight = weight.to_i
84
+ up_id = ShardId.parse(up_id)
85
+ down_id = ShardId.parse(down_id)
86
+ link = LinkInfo.new(up_id, down_id, weight)
87
+ service.add_link(link.up_id, link.down_id, link.weight)
88
+ puts link.to_unix
89
+ end
90
+ end
91
+
92
+ class UnlinkCommand < Command
93
+ def run
94
+ up_id, down_id = argv
95
+ up_id = ShardId.parse(up_id)
96
+ down_id = ShardId.parse(down_id)
97
+ service.remove_link(up_id, down_id)
98
+ end
99
+ end
100
+
101
+ class UnwrapCommand < Command
102
+ def run
103
+ shard_ids = argv
104
+ help! "No shards specified" if shard_ids.empty?
105
+ shard_ids.each do |shard_id_string|
106
+ shard_id = ShardId.parse(shard_id_string)
107
+ service.list_upward_links(shard_id).each do |uplink|
108
+ service.list_downward_links(shard_id).each do |downlink|
109
+ service.add_link(uplink.up_id, downlink.down_id, uplink.weight)
110
+ new_link = LinkInfo.new(uplink.up_id, downlink.down_id, uplink.weight)
111
+ service.remove_link(uplink.up_id, uplink.down_id)
112
+ service.remove_link(downlink.up_id, downlink.down_id)
113
+ puts new_link.to_unix
114
+ end
115
+ end
116
+ service.delete_shard shard_id
117
+ end
118
+ end
119
+ end
120
+
121
+ class CreateCommand < Command
122
+ def run
123
+ help! if argv.length != 3
124
+ host, table, class_name = argv
125
+ busy = 0
126
+ source_type = command_options.source_type || ""
127
+ destination_type = command_options.destination_type || ""
128
+ service.create_shard(ShardInfo.new(shard_id = ShardId.new(host, table), class_name, source_type, destination_type, busy))
129
+ service.get_shard(shard_id)
130
+ puts shard_id.to_unix
131
+ end
132
+ end
133
+
134
+ class LinksCommand < Command
135
+ def run
136
+ shard_ids = @argv
137
+ shard_ids.each do |shard_id_text|
138
+ shard_id = ShardId.parse(shard_id_text)
139
+ service.list_upward_links(shard_id).each do |link_info|
140
+ puts link_info.to_unix
141
+ end
142
+ service.list_downward_links(shard_id).each do |link_info|
143
+ puts link_info.to_unix
144
+ end
145
+ end
146
+ end
147
+ end
148
+
149
+ class InfoCommand < Command
150
+ def run
151
+ shard_ids = @argv
152
+ shard_ids.each do |shard_id|
153
+ shard_info = service.get_shard(ShardId.parse(shard_id))
154
+ puts shard_info.to_unix
155
+ end
156
+ end
157
+ end
158
+
159
+ class WrapCommand < Command
160
+ def self.derive_wrapper_shard_id(shard_info, wrapping_class_name)
161
+ prefix_prefix = wrapping_class_name.split(".").last.downcase.gsub("shard", "") + "_"
162
+ ShardId.new("localhost", prefix_prefix + shard_info.id.table_prefix)
163
+ end
164
+
165
+ def run
166
+ class_name, *shard_ids = @argv
167
+ help! "No shards specified" if shard_ids.empty?
168
+ shard_ids.each do |shard_id_string|
169
+ shard_id = ShardId.parse(shard_id_string)
170
+ shard_info = service.get_shard(shard_id)
171
+ service.create_shard(ShardInfo.new(wrapper_id = self.class.derive_wrapper_shard_id(shard_info, class_name), class_name, "", "", 0))
172
+
173
+ existing_links = service.list_upward_links(shard_id)
174
+ unless existing_links.include?(LinkInfo.new(wrapper_id, shard_id, 1))
175
+ service.add_link(wrapper_id, shard_id, 1)
176
+ existing_links.each do |link_info|
177
+ service.add_link(link_info.up_id, wrapper_id, link_info.weight)
178
+ service.remove_link(link_info.up_id, link_info.down_id)
179
+ end
180
+ end
181
+ puts wrapper_id.to_unix
182
+ end
183
+ end
184
+ end
185
+
186
+ class FindCommand < Command
187
+ def run
188
+ help!("host is a required option") unless command_options.shard_host
189
+ service.shards_for_hostname(command_options.shard_host).each do |shard|
190
+ next if command_options.shard_type && shard.class_name !~ Regexp.new(command_options.shard_type)
191
+ puts shard.id.to_unix
192
+ end
193
+ end
194
+ end
195
+ end