mamiya 0.0.1.alpha22 → 0.0.1.alpha23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mamiya/agent.rb +6 -2
- data/lib/mamiya/agent/task_queue.rb +3 -2
- data/lib/mamiya/cli/client.rb +5 -5
- data/lib/mamiya/configuration.rb +2 -0
- data/lib/mamiya/logger.rb +11 -1
- data/lib/mamiya/master/agent_monitor.rb +1 -1
- data/lib/mamiya/script.rb +48 -4
- data/lib/mamiya/steps/switch.rb +1 -0
- data/lib/mamiya/version.rb +1 -1
- data/mamiya.gemspec +1 -0
- data/spec/script_spec.rb +11 -4
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46e8f4b3cd898fb6448e6cd4d5e8161c2fac101b
|
4
|
+
data.tar.gz: d921dadc048b7bfc587ec71a25d2cf14323dbe53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1169ca11bfc342862c8fc46fff5e91423a4d06ef2cab4f80b36275129e4b8f12047719b0459fc513d0e6091d1f43ccaa22834f9fa88ae0696a91e44e53268fc
|
7
|
+
data.tar.gz: b4906b0a1110d80ac1e82f7fecdbe22fc4b782203fdfcb83840cf3ecca4a3126334f02159e3966d93984e06ae556b0afb6c41dddb3786b9af603c924b74d986b
|
data/lib/mamiya/agent.rb
CHANGED
@@ -18,6 +18,8 @@ require 'mamiya/agent/tasks/clean'
|
|
18
18
|
require 'mamiya/agent/handlers/task'
|
19
19
|
require 'mamiya/agent/actions'
|
20
20
|
|
21
|
+
require 'sigdump/setup' unless ENV['DISABLE_SIGDUMP'] == '1'
|
22
|
+
|
21
23
|
module Mamiya
|
22
24
|
class Agent
|
23
25
|
include Mamiya::Agent::Actions
|
@@ -205,8 +207,10 @@ module Mamiya
|
|
205
207
|
|
206
208
|
class_name = type.capitalize.gsub(/-./) { |_| _[1].upcase }
|
207
209
|
|
208
|
-
|
209
|
-
|
210
|
+
if config.debug_all_events
|
211
|
+
logger.debug "Received user event #{type}"
|
212
|
+
logger.debug payload.inspect
|
213
|
+
end
|
210
214
|
|
211
215
|
if Handlers.const_defined?(class_name)
|
212
216
|
handler = Handlers.const_get(class_name).new(self, event)
|
@@ -18,7 +18,7 @@ module Mamiya
|
|
18
18
|
@queueing_thread = nil
|
19
19
|
@lifecycle_mutex = Mutex.new
|
20
20
|
@terminate = false
|
21
|
-
@logger = logger['task_queue']
|
21
|
+
@logger = logger.with_clean_progname['task_queue']
|
22
22
|
end
|
23
23
|
|
24
24
|
attr_reader :worker_threads, :task_classes, :agent
|
@@ -118,7 +118,8 @@ module Mamiya
|
|
118
118
|
status[:pending].delete task
|
119
119
|
status[:working] = task
|
120
120
|
end
|
121
|
-
|
121
|
+
task_logger = @logger.with_clean_progname
|
122
|
+
task_class.new(self, task, agent: @agent, logger: task_logger).execute
|
122
123
|
rescue Exception => e
|
123
124
|
@logger.error "#{task_class} worker catched error: #{e}\n\t#{e.backtrace.join("\n\t")}"
|
124
125
|
ensure
|
data/lib/mamiya/cli/client.rb
CHANGED
@@ -133,7 +133,7 @@ not distributed: #{dist['not_distributed_count']} agents
|
|
133
133
|
params = options[:labels] ?
|
134
134
|
{labels: Mamiya::Util::LabelMatcher.parse_string_expr(options[:labels])} : {}
|
135
135
|
|
136
|
-
p master_post("/packages/#{application}/#{package}/distribute", params
|
136
|
+
p master_post("/packages/#{application}/#{package}/distribute", params.merge(type: :json))
|
137
137
|
end
|
138
138
|
|
139
139
|
desc "prepare PACKAGE", "order preparing package to agents"
|
@@ -142,7 +142,7 @@ not distributed: #{dist['not_distributed_count']} agents
|
|
142
142
|
params = options[:labels] ?
|
143
143
|
{labels: Mamiya::Util::LabelMatcher.parse_string_expr(options[:labels])} : {}
|
144
144
|
|
145
|
-
p master_post("/packages/#{application}/#{package}/prepare", params
|
145
|
+
p master_post("/packages/#{application}/#{package}/prepare", params.merge(type: :json))
|
146
146
|
end
|
147
147
|
|
148
148
|
desc "refresh", "order refreshing agent status"
|
@@ -181,17 +181,17 @@ not distributed: #{dist['not_distributed_count']} agents
|
|
181
181
|
end
|
182
182
|
end
|
183
183
|
|
184
|
-
def master_post(path, data=''
|
184
|
+
def master_post(path, data='')
|
185
185
|
response = nil
|
186
186
|
master_http.start do |http|
|
187
187
|
headers = {}
|
188
188
|
|
189
189
|
if Hash === data
|
190
|
-
case type
|
190
|
+
case data.delete(:type) || :query
|
191
191
|
when :json
|
192
192
|
data = data.to_json
|
193
193
|
headers['Content-Type'] = 'application/json'
|
194
|
-
when :
|
194
|
+
when :query
|
195
195
|
data = Rack::Utils.build_nested_query(data)
|
196
196
|
end
|
197
197
|
end
|
data/lib/mamiya/configuration.rb
CHANGED
data/lib/mamiya/logger.rb
CHANGED
@@ -55,11 +55,21 @@ module Mamiya
|
|
55
55
|
@logdev.remove_output(*outputs)
|
56
56
|
end
|
57
57
|
|
58
|
+
def with_clean_progname
|
59
|
+
self.dup.tap do |new|
|
60
|
+
new.progname = nil
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
58
64
|
def [](progname)
|
59
65
|
self.dup.tap do |new_logger|
|
60
66
|
new_logger.instance_eval do
|
61
67
|
@logger = @logger.dup
|
62
|
-
@logger.progname
|
68
|
+
if @logger.progname && !@logger.progname.empty?
|
69
|
+
@logger.progname += "/#{progname}"
|
70
|
+
else
|
71
|
+
@logger.progname = progname
|
72
|
+
end
|
63
73
|
end
|
64
74
|
end
|
65
75
|
end
|
data/lib/mamiya/script.rb
CHANGED
@@ -56,7 +56,9 @@ module Mamiya
|
|
56
56
|
def run(*args, allow_failure: false)
|
57
57
|
# TODO: Stop when fail
|
58
58
|
actual = -> do
|
59
|
-
|
59
|
+
started_at = Time.now
|
60
|
+
run_id = generate_run_id()
|
61
|
+
logger = self.logger["run:#{run_id}"]
|
60
62
|
|
61
63
|
logger.info("$ #{args.shelljoin}")
|
62
64
|
|
@@ -68,18 +70,32 @@ module Mamiya
|
|
68
70
|
[out_w, err_w].each(&:close)
|
69
71
|
|
70
72
|
buf = ""
|
73
|
+
last_out = Time.now
|
71
74
|
|
72
|
-
ths = {:
|
75
|
+
ths = {:info => out_r, :warn => err_r}.map do |severity, io|
|
73
76
|
Thread.new {
|
74
77
|
until io.eof?
|
75
78
|
str = io.gets
|
76
79
|
logger.__send__(severity, str.chomp)
|
77
80
|
buf << str
|
81
|
+
last_out = Time.now
|
78
82
|
end
|
79
83
|
}.tap { |_| _.abort_on_exception = true }
|
80
84
|
end
|
81
85
|
|
86
|
+
timekeeper_th = Thread.new do
|
87
|
+
l = logger['timekeeper']
|
88
|
+
loop do
|
89
|
+
if 90 < (Time.now - last_out)
|
90
|
+
l.warn "pid #{pid} still running; since #{started_at}"
|
91
|
+
end
|
92
|
+
sleep 60
|
93
|
+
end
|
94
|
+
end
|
95
|
+
timekeeper_th.abort_on_exception = true
|
96
|
+
|
82
97
|
pid, status = Process.waitpid2(pid)
|
98
|
+
timekeeper_th.kill if timekeeper_th.alive?
|
83
99
|
|
84
100
|
begin
|
85
101
|
timeout(3) { ths.each(&:join) }
|
@@ -90,15 +106,20 @@ module Mamiya
|
|
90
106
|
[out_r, err_r].each(&:close)
|
91
107
|
|
92
108
|
unless allow_failure || status.success?
|
93
|
-
|
94
|
-
"Excecution failed (" \
|
109
|
+
failure_msg = "Execution failed (" \
|
95
110
|
"status=#{status.exitstatus}" \
|
96
111
|
" pid=#{status.pid}" \
|
97
112
|
"#{status.signaled? ? "termsig=#{status.termsig.inspect} stopsig=#{status.stopsig.inspect}" : nil}" \
|
98
113
|
"#{status.stopped? ? " stopped" : nil}" \
|
99
114
|
"): #{args.inspect}"
|
115
|
+
|
116
|
+
logger.error failure_msg
|
117
|
+
raise CommandFailed, failure_msg
|
118
|
+
|
100
119
|
end
|
101
120
|
|
121
|
+
logger.info "pid #{pid} completed: #{args.inspect}"
|
122
|
+
|
102
123
|
buf
|
103
124
|
end
|
104
125
|
|
@@ -133,5 +154,28 @@ module Mamiya
|
|
133
154
|
def current_path
|
134
155
|
deploy_to && deploy_to.join('current')
|
135
156
|
end
|
157
|
+
|
158
|
+
private
|
159
|
+
|
160
|
+
RUN_ID_BASE_TIME = Time.new(2014,01,01,0,0,0).to_i
|
161
|
+
def generate_run_id
|
162
|
+
(@run_id_mutex ||= Mutex.new).synchronize do
|
163
|
+
t = Time.now.to_i
|
164
|
+
id = (t - RUN_ID_BASE_TIME).to_i.to_s(36)
|
165
|
+
|
166
|
+
@last_run_id_time ||= 0
|
167
|
+
if (t - @last_run_id_time) < 1
|
168
|
+
@run_id_seq ||= 0
|
169
|
+
@run_id_seq += 1
|
170
|
+
id << @run_id_seq.to_s(36)
|
171
|
+
else
|
172
|
+
@run_id_seq = nil
|
173
|
+
id << '0'
|
174
|
+
end
|
175
|
+
|
176
|
+
@last_run_id_time = t
|
177
|
+
id
|
178
|
+
end
|
179
|
+
end
|
136
180
|
end
|
137
181
|
end
|
data/lib/mamiya/steps/switch.rb
CHANGED
data/lib/mamiya/version.rb
CHANGED
data/mamiya.gemspec
CHANGED
data/spec/script_spec.rb
CHANGED
@@ -15,7 +15,7 @@ describe Mamiya::Script do
|
|
15
15
|
let(:logger) {
|
16
16
|
double("logger").tap do |_|
|
17
17
|
_.stub(:[]) { _ }
|
18
|
-
%i(info warn debug).each do |severity|
|
18
|
+
%i(info warn debug error).each do |severity|
|
19
19
|
_.stub(severity) { |*args| log << [severity, *args]; _ }
|
20
20
|
end
|
21
21
|
end
|
@@ -38,6 +38,14 @@ describe Mamiya::Script do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
context "when the command failed" do
|
41
|
+
it "logs error" do
|
42
|
+
begin
|
43
|
+
script.run("false")
|
44
|
+
rescue Mamiya::Script::CommandFailed
|
45
|
+
end
|
46
|
+
expect(log.map(&:first)).to include(:error)
|
47
|
+
end
|
48
|
+
|
41
49
|
it "raises error" do
|
42
50
|
expect {
|
43
51
|
script.run("false")
|
@@ -53,15 +61,14 @@ describe Mamiya::Script do
|
|
53
61
|
end
|
54
62
|
end
|
55
63
|
|
56
|
-
|
57
64
|
it "logs command as information" do
|
58
65
|
script.run("echo", "foo", "bar'", " baz")
|
59
66
|
expect(log).to include([:info, "$ echo foo bar\\' \\ baz"])
|
60
67
|
end
|
61
68
|
|
62
|
-
it "logs stdout as
|
69
|
+
it "logs stdout as info" do
|
63
70
|
script.run("echo", "foo")
|
64
|
-
expect(log).to include([:
|
71
|
+
expect(log).to include([:info, "foo"])
|
65
72
|
end
|
66
73
|
|
67
74
|
it "logs stderr as warn" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mamiya
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.
|
4
|
+
version: 0.0.1.alpha23
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shota Fukumori (sora_h)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 1.4.5
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: sigdump
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: rspec
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|