hadoop-killer 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +41 -0
- data/Rakefile +1 -0
- data/bin/hdkiller +6 -0
- data/config/policy.yml +6 -0
- data/hadoop-killer.gemspec +19 -0
- data/lib/hadoop-killer/hdkiller.rb +150 -0
- data/lib/hadoop-killer/version.rb +5 -0
- metadata +55 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 44df609d7222472c820c8bf58db1d4f1aec5fe6b
|
4
|
+
data.tar.gz: 1d6eaaa6b3f61b1d0916dbed2e8f380384de9dc4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c84905df834f314d890a8c1c325a5cfbb0d9b304c4827664c2da8c537a124543d520cfd3316706b62362fb4b92b01de9bd32f34143a26e904e53f129020f60d7
|
7
|
+
data.tar.gz: 1f61a8203ef47eeb560f0a7c80dc0302639ff67b20cf120b86895a9024a7f5a42bc7e6a285f7ea841833fb2f995fc3017f693de1dcffe36ab2910f2fa5e8b4af
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 OZAWA
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Hadoop::Killer
|
2
|
+
|
3
|
+
Hadoop is a de fact standard analysis software. One sofisticated feature in Hadoop is fault torelance.
|
4
|
+
However, there is a one missing tool for hadoop development - fault injector, like ChaosMonkey.
|
5
|
+
`hadoop-killer` provides process-level fault injection by killing user-specified Java processes at user-specified probability.
|
6
|
+
|
7
|
+
## Requirement
|
8
|
+
|
9
|
+
* JDK 1.5 or later
|
10
|
+
* ruby 1.9.3
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
$ gem install hadoop-killer
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
Edit config/policy.yml:
|
19
|
+
|
20
|
+
kill:
|
21
|
+
target : "YarnChild" # target daemon name
|
22
|
+
max: 3 # max count of killing.
|
23
|
+
probability: 20 # kill daemons at 20% of the time
|
24
|
+
interval: 1 # each 1 seconds.
|
25
|
+
|
26
|
+
Launch `hadoop-killer`:
|
27
|
+
|
28
|
+
bin/hdkiller
|
29
|
+
|
30
|
+
## TODO
|
31
|
+
|
32
|
+
1. Log-based process killing - if specified lines appears specified log, kill the container.
|
33
|
+
2. Cluster support - current version only supports local process.
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
1. Fork it
|
38
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
39
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
40
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
41
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/hdkiller
ADDED
data/config/policy.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'hadoop-killer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "hadoop-killer"
|
8
|
+
gem.version = Hadoop::Killer::VERSION
|
9
|
+
gem.authors = ["Tsuyoshi Ozawa"]
|
10
|
+
gem.email = ["ozawa.tsuyoshi@gmail.com"]
|
11
|
+
gem.description = %q{Kill hadoop daemons for debugging, testing, and development.}
|
12
|
+
gem.summary = %q{Hadoop daemons killer for easily debug, test, development}
|
13
|
+
gem.homepage = "https://github.com/oza/hadoop-killer"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
end
|
@@ -0,0 +1,150 @@
|
|
1
|
+
require "hadoop-killer/version"
|
2
|
+
require 'yaml'
|
3
|
+
require 'open3'
|
4
|
+
require 'syslog'
|
5
|
+
require 'fileutils'
|
6
|
+
require 'pathname'
|
7
|
+
require 'optparse'
|
8
|
+
require 'timers'
|
9
|
+
require 'logger'
|
10
|
+
|
11
|
+
module Hadoop
|
12
|
+
module DevUitl
|
13
|
+
module ProcessKiller
|
14
|
+
|
15
|
+
class Watcher
|
16
|
+
|
17
|
+
class NoSuchEventError < StandardError
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(yaml)
|
21
|
+
parse_yaml(yaml)
|
22
|
+
end
|
23
|
+
|
24
|
+
def parse_yaml(config_file)
|
25
|
+
@config = load_yaml(config_file)
|
26
|
+
@kill_config = @config['kill']
|
27
|
+
@target = @kill_config['target'].to_s
|
28
|
+
@max = @kill_config['max'].to_i
|
29
|
+
@probability = @kill_config['probability'].to_i
|
30
|
+
@interval = @kill_config['interval'].to_i
|
31
|
+
|
32
|
+
if @probability == 0
|
33
|
+
$stderr.puts "'probability' must be larger than 0."
|
34
|
+
exit 1
|
35
|
+
end
|
36
|
+
|
37
|
+
@failure_cnt = 0
|
38
|
+
@logger = Logger.new(STDOUT)
|
39
|
+
@logger.level = Logger::INFO
|
40
|
+
#@logger.level = Logger::DEBUG
|
41
|
+
|
42
|
+
@logger.debug("=== Option info ===")
|
43
|
+
@logger.debug("target :" + @target)
|
44
|
+
@logger.debug("probability :" + @probability.to_s)
|
45
|
+
@logger.debug("interval :" + @interval.to_s)
|
46
|
+
@logger.debug("max :" + @max.to_s)
|
47
|
+
end
|
48
|
+
|
49
|
+
def load_yaml(file)
|
50
|
+
config_path = File.join(File.dirname(__FILE__), '../../config')
|
51
|
+
config_file = File.join(config_path, file)
|
52
|
+
# puts config_file
|
53
|
+
|
54
|
+
begin
|
55
|
+
config = YAML.load_file(config_file)
|
56
|
+
rescue => e
|
57
|
+
$stderr.puts "Could not read configuration file: #{e}"
|
58
|
+
exit 1
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def exec_cmd(cmd, stdin=nil)
|
63
|
+
o, e, s = Open3.capture3(cmd, :stdin_data => stdin)
|
64
|
+
return [o, e, s]
|
65
|
+
end
|
66
|
+
|
67
|
+
def parse_result(output)
|
68
|
+
ary = output.split("\n").map do |e|
|
69
|
+
key, value = e.split(" ")
|
70
|
+
[key.to_i, value.to_s]
|
71
|
+
end
|
72
|
+
Hash[ary]
|
73
|
+
end
|
74
|
+
|
75
|
+
def jps
|
76
|
+
cmd = "jps"
|
77
|
+
o, e, s = exec_cmd(cmd)
|
78
|
+
# Transform results of jps command as hashmap.
|
79
|
+
parse_result(o)
|
80
|
+
end
|
81
|
+
|
82
|
+
def happen_event?(name)
|
83
|
+
f1 = @failure_cnt < @max
|
84
|
+
if name.nil? || name.empty?
|
85
|
+
@logger.debug("#{name} is nil or empty")
|
86
|
+
return false
|
87
|
+
end
|
88
|
+
f2 = !name.scan(/#{@target}/).empty?
|
89
|
+
f3 = rand(100) < @probability
|
90
|
+
@logger.debug("cnt: #{f1.to_s}, scan: #{f2.to_s} rand #{f3.to_s}")
|
91
|
+
f1 && f2 && f3
|
92
|
+
end
|
93
|
+
|
94
|
+
def kill(pid)
|
95
|
+
begin
|
96
|
+
Process.kill("KILL", pid)
|
97
|
+
rescue Errno::ESRCH, RangeError => e
|
98
|
+
@logger.debug("Pid #{pid} may exit, so ignore it.")
|
99
|
+
rescue Errno::EPERM => e
|
100
|
+
@logger.fatal("Doesn't kill the program because of permission.")
|
101
|
+
exit 1
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def may_kill(processes)
|
106
|
+
processes.each do |p|
|
107
|
+
pid, name = p
|
108
|
+
if (happen_event?(name))
|
109
|
+
@logger.debug("try to kill #{name}(#{pid})")
|
110
|
+
kill(pid)
|
111
|
+
@failure_cnt += 1
|
112
|
+
@logger.info("Killed pid #{pid} name #{name}")
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def handle_event(event)
|
118
|
+
case event
|
119
|
+
when :kill
|
120
|
+
if (@failure_cnt > @max)
|
121
|
+
exit 0
|
122
|
+
end
|
123
|
+
|
124
|
+
processes = jps
|
125
|
+
may_kill(processes)
|
126
|
+
else
|
127
|
+
throw NoSuchEventError.new
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def start
|
132
|
+
timer = Timers.new
|
133
|
+
every_five_seconds = timer.every(1) do
|
134
|
+
handle_event(:kill)
|
135
|
+
end
|
136
|
+
|
137
|
+
loop do
|
138
|
+
timer.wait
|
139
|
+
sleep @interval
|
140
|
+
end
|
141
|
+
puts "Stopped."
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
end # Killer
|
146
|
+
end # DevUtil
|
147
|
+
end # Hadoop
|
148
|
+
|
149
|
+
hdkiller = Hadoop::DevUitl::ProcessKiller::Watcher.new("policy.yml")
|
150
|
+
hdkiller.start()
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hadoop-killer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tsuyoshi Ozawa
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-24 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Kill hadoop daemons for debugging, testing, and development.
|
14
|
+
email:
|
15
|
+
- ozawa.tsuyoshi@gmail.com
|
16
|
+
executables:
|
17
|
+
- hdkiller
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- ".gitignore"
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE.txt
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- bin/hdkiller
|
27
|
+
- config/policy.yml
|
28
|
+
- hadoop-killer.gemspec
|
29
|
+
- lib/hadoop-killer/hdkiller.rb
|
30
|
+
- lib/hadoop-killer/version.rb
|
31
|
+
homepage: https://github.com/oza/hadoop-killer
|
32
|
+
licenses: []
|
33
|
+
metadata: {}
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirements: []
|
49
|
+
rubyforge_project:
|
50
|
+
rubygems_version: 2.2.2
|
51
|
+
signing_key:
|
52
|
+
specification_version: 4
|
53
|
+
summary: Hadoop daemons killer for easily debug, test, development
|
54
|
+
test_files: []
|
55
|
+
has_rdoc:
|