themigrator 0.1.19 → 0.1.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/themigrator/migration.rb +1 -1
- data/lib/themigrator/migration_progress.rb +11 -2
- data/lib/themigrator/migrator.rb +2 -0
- data/lib/themigrator/ui.rb +9 -4
- data/lib/themigrator/ui/log_area.rb +25 -8
- data/lib/themigrator/ui/progress_window.rb +43 -23
- data/lib/themigrator/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f5530e5706123be2d5d7f06a9f9c65d9f03ecc1
|
4
|
+
data.tar.gz: 0ae9b1e49e998f577a40278839143f1d4a45aca9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 166ac6e07b90e24984336abaeaac1259bf7aff61dca598dd804f7bb4c1840433062da829a9ef5c9c0db93dd06161e3bd170ab12c7cfe3b815ab5351255bd3922
|
7
|
+
data.tar.gz: fa0c27907ef9de30c452d3b2f269413271015392abbb245fadfad98d9d0ddf78fe4eef30c15643e24221b7e5ff6cd4df92945c508a9af735bb4201bf811c84d3
|
@@ -90,6 +90,7 @@ module Themigrator
|
|
90
90
|
case line
|
91
91
|
when /start PID=(\d+)/
|
92
92
|
@pid = Regexp.last_match(1).to_i
|
93
|
+
@status = "running"
|
93
94
|
when /roles: (.+)/
|
94
95
|
@roles = Regexp.last_match(1).strip.split.sort
|
95
96
|
call_cbk(:has_roles, @roles)
|
@@ -97,6 +98,7 @@ module Themigrator
|
|
97
98
|
action = Regexp.last_match(1)
|
98
99
|
@current_action = action
|
99
100
|
@actions[action][:start_time] = time
|
101
|
+
@actions[action][:status] = "running"
|
100
102
|
call_cbk(:start_action, action)
|
101
103
|
|
102
104
|
when /(#{scripts}) => (done|fail) \(([0-9\.]+) ms\)/
|
@@ -104,31 +106,38 @@ module Themigrator
|
|
104
106
|
success = to_success(Regexp.last_match(2))
|
105
107
|
run_time = Regexp.last_match(3).to_f
|
106
108
|
|
109
|
+
@status = "fail" if !success
|
107
110
|
@actions[action][:end_time] = time
|
108
111
|
@actions[action][:run_time] = run_time
|
109
112
|
@actions[action][:success] = success
|
113
|
+
@actions[action][:status] = Regexp.last_match(2)
|
110
114
|
@current_action = nil
|
111
115
|
|
112
116
|
when /(#{scripts}) \| (.*) => start/
|
113
117
|
action = Regexp.last_match(1)
|
114
118
|
role = Regexp.last_match(2)
|
115
119
|
@actions[action][:roles][role][:start_time] = time
|
120
|
+
@actions[action][:roles][role][:status] = "running"
|
116
121
|
call_cbk(:start_role_action, role, action)
|
117
|
-
when /(#{scripts}) \| (
|
122
|
+
when /(#{scripts}) \| ([^ ]+) => exited with (\d+) \(([0-9\.]+) ms\)/
|
118
123
|
action = Regexp.last_match(1)
|
119
124
|
role = Regexp.last_match(2)
|
120
125
|
exitcode = Regexp.last_match(3).to_i
|
121
126
|
success = exitcode.zero?
|
122
127
|
run_time = Regexp.last_match(4).to_f
|
128
|
+
status = exitcode == 0 ? "done" : "Exited with #{exitcode}"
|
129
|
+
@status = "fail" if !success
|
123
130
|
@actions[action][:roles][role][:end_time] = time
|
124
131
|
@actions[action][:roles][role][:exitcode] = exitcode
|
125
132
|
@actions[action][:roles][role][:success] = success
|
126
133
|
@actions[action][:roles][role][:run_time] = run_time
|
134
|
+
@actions[action][:roles][role][:status] = status
|
127
135
|
when /end => (done|fail) \(([0-9.]+) ms\)/
|
136
|
+
@status = "fail" if $1 == "fail"
|
128
137
|
@current_action = nil
|
129
138
|
@run_time = Regexp.last_match(3).to_f
|
130
139
|
else
|
131
|
-
raise line.inspect
|
140
|
+
raise line.inspect + " #{scripts} "
|
132
141
|
end
|
133
142
|
end
|
134
143
|
|
data/lib/themigrator/migrator.rb
CHANGED
@@ -56,6 +56,7 @@ module Themigrator
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def run_action_and_wait(action)
|
59
|
+
sleep 0.5
|
59
60
|
log "#{action} => start"
|
60
61
|
script_pool = ScriptPool.new
|
61
62
|
|
@@ -75,6 +76,7 @@ module Themigrator
|
|
75
76
|
|
76
77
|
ok = script_pool.run_and_wait
|
77
78
|
log("#{action} => #{ok ? 'done' : 'fail'} (#{script_pool.run_time * 1000} ms)")
|
79
|
+
sleep 0.5
|
78
80
|
ok
|
79
81
|
end
|
80
82
|
|
data/lib/themigrator/ui.rb
CHANGED
@@ -80,8 +80,14 @@ module Themigrator
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
+
def progress_window_status
|
84
|
+
status = Themigrator::Migration::ACTIONS.dup
|
85
|
+
status[-1] = "rollback" if @pm.status == "fail"
|
86
|
+
status.map(&:dup)
|
87
|
+
end
|
88
|
+
|
83
89
|
def next_action
|
84
|
-
scripts =
|
90
|
+
scripts = progress_window_status
|
85
91
|
current_index = scripts.index(@current_action)
|
86
92
|
if current_index.nil?
|
87
93
|
switch_action(scripts.first)
|
@@ -94,7 +100,7 @@ module Themigrator
|
|
94
100
|
end
|
95
101
|
|
96
102
|
def previous_action
|
97
|
-
scripts =
|
103
|
+
scripts = progress_window_status
|
98
104
|
current_index = scripts.index(@current_action)
|
99
105
|
if current_index.nil?
|
100
106
|
switch_action(scripts.first)
|
@@ -118,7 +124,7 @@ module Themigrator
|
|
118
124
|
|
119
125
|
def has_roles(roles)
|
120
126
|
@roles = roles.sort
|
121
|
-
initialize_log_area(@roles)
|
127
|
+
initialize_log_area(@roles, @pm)
|
122
128
|
end
|
123
129
|
|
124
130
|
def start_role_action(role, action)
|
@@ -146,7 +152,6 @@ module Themigrator
|
|
146
152
|
return if @current_action == action
|
147
153
|
UILOG.debug("switch action from #{@current_index} to #{action}")
|
148
154
|
la_switch_action(action)
|
149
|
-
pg_set_action(action)
|
150
155
|
@current_action = action
|
151
156
|
rescue => e
|
152
157
|
ui_log_exception(e)
|
@@ -7,7 +7,7 @@ module Themigrator
|
|
7
7
|
include Curses
|
8
8
|
|
9
9
|
class LogWindow < Window
|
10
|
-
attr_accessor :role, :action
|
10
|
+
attr_accessor :role, :action, :progress_monitor
|
11
11
|
def initialize(height, width, top, left)
|
12
12
|
@height = height
|
13
13
|
@width = width
|
@@ -24,14 +24,22 @@ module Themigrator
|
|
24
24
|
def redraw
|
25
25
|
clear
|
26
26
|
@inner_win.clear
|
27
|
-
setpos(0, 0)
|
28
|
-
box('|', '-')
|
29
|
-
addstr(name)
|
30
|
-
log('redraw')
|
31
|
-
refresh
|
32
27
|
render(true)
|
33
28
|
end
|
34
29
|
|
30
|
+
def render_title(force = false)
|
31
|
+
n = name
|
32
|
+
return if !force && @previous_title == n
|
33
|
+
@previous_title = n
|
34
|
+
start = (@width - n.size ) / 2
|
35
|
+
start = 1 if start < 1
|
36
|
+
setpos(0,start)
|
37
|
+
box(?|, ?-)
|
38
|
+
addstr(n)
|
39
|
+
log('redraw')
|
40
|
+
refresh
|
41
|
+
end
|
42
|
+
|
35
43
|
def nextpage
|
36
44
|
@scroll += 5
|
37
45
|
@scroll = -1 if @scroll > -1
|
@@ -49,15 +57,22 @@ module Themigrator
|
|
49
57
|
end
|
50
58
|
|
51
59
|
def name
|
52
|
-
|
60
|
+
"#{role} (#{status})"
|
53
61
|
end
|
54
62
|
|
63
|
+
def status
|
64
|
+
info = self.progress_monitor.actions[action][:roles][role][:status]
|
65
|
+
rescue => e
|
66
|
+
e.inspect
|
67
|
+
end
|
68
|
+
|
55
69
|
def append(msg)
|
56
70
|
@buffer << msg
|
57
71
|
end
|
58
72
|
|
59
73
|
def render(force = false)
|
60
74
|
# refresh
|
75
|
+
render_title(force)
|
61
76
|
render_inner_win(force)
|
62
77
|
end
|
63
78
|
|
@@ -95,7 +110,8 @@ module Themigrator
|
|
95
110
|
end
|
96
111
|
end
|
97
112
|
|
98
|
-
def initialize_log_area(roles)
|
113
|
+
def initialize_log_area(roles, progress_monitor)
|
114
|
+
@la_pm = progress_monitor
|
99
115
|
@la_roles = roles
|
100
116
|
@la_scripts = Themigrator::Migration::SCRIPTS
|
101
117
|
@la_actions = Themigrator::Migration::ACTIONS
|
@@ -116,6 +132,7 @@ module Themigrator
|
|
116
132
|
w = LogWindow.new(column_height, column_width - 1, top, left)
|
117
133
|
w.role = role
|
118
134
|
w.action = action
|
135
|
+
w.progress_monitor = @la_pm
|
119
136
|
role_windows[role] = w
|
120
137
|
end
|
121
138
|
h[action] = role_windows
|
@@ -11,10 +11,6 @@ module Themigrator
|
|
11
11
|
progress_window.refresh
|
12
12
|
end
|
13
13
|
|
14
|
-
def pg_set_action(action)
|
15
|
-
@pg_action = action
|
16
|
-
end
|
17
|
-
|
18
14
|
def progress_window
|
19
15
|
@progress_widnow ||= Window.new(@lines - 2, @cols, @lines - 2, 0).tap do |w|
|
20
16
|
w.attrset(A_DIM)
|
@@ -25,26 +21,50 @@ module Themigrator
|
|
25
21
|
@pw_status = msg.map(&:to_s).join(' ')
|
26
22
|
end
|
27
23
|
|
24
|
+
|
25
|
+
|
26
|
+
# def build_status_line
|
27
|
+
# scripts = progress_window_status
|
28
|
+
# width = scripts.map(&:size).inject(&:+)
|
29
|
+
# free_space = @cols - width
|
30
|
+
# sep_space = scripts.size - 1
|
31
|
+
# inline_space = ((free_space - sep_space) / scripts.size - 1) / 2
|
32
|
+
#
|
33
|
+
# action_msg = []
|
34
|
+
# scripts.map do |script|
|
35
|
+
# a = ''
|
36
|
+
# inline_space.times { a << ' ' }
|
37
|
+
# a << if defined?(@pg_action) && @pg_action.to_s == script.to_s
|
38
|
+
# script.upcase
|
39
|
+
# else
|
40
|
+
# script.downcase
|
41
|
+
# end
|
42
|
+
# inline_space.times { a << ' ' }
|
43
|
+
# action_msg << a
|
44
|
+
# end
|
45
|
+
# action_msg.join('>')
|
46
|
+
# end
|
47
|
+
|
28
48
|
def build_status_line
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
49
|
+
width = @cols
|
50
|
+
ncols = progress_window_status.size
|
51
|
+
col_width = (width / ncols) - 1
|
52
|
+
cols = []
|
53
|
+
ncols.times do |i|
|
54
|
+
cols[i] = build_status_line_column(index: i,width: col_width)
|
55
|
+
end
|
56
|
+
cols.join(?>)
|
57
|
+
rescue => e
|
58
|
+
e.inspect
|
59
|
+
end
|
60
|
+
|
61
|
+
def build_status_line_column(index:, width:)
|
62
|
+
title = progress_window_status[index]
|
63
|
+
title.upcase! if title == @current_action
|
64
|
+
|
65
|
+
padding = (width - title.size) / 2
|
66
|
+
padding = 0 if padding < 0
|
67
|
+
"%#{padding}s%-#{width - padding}s" % [ "", title ]
|
48
68
|
end
|
49
69
|
end
|
50
70
|
end
|
data/lib/themigrator/version.rb
CHANGED