ubalo 0.16 → 0.17

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.
data/bin/ubalo CHANGED
@@ -187,7 +187,7 @@ desc 'Show information about a pod'
187
187
  command :pod do |c|
188
188
  c.action do |global_options,options,args|
189
189
  pod.refresh!
190
- puts pod.printable_result
190
+ puts pod.full_printable_result
191
191
  end
192
192
  end
193
193
 
@@ -219,7 +219,7 @@ command :task do |c|
219
219
  task = pod.latest_task
220
220
  end
221
221
 
222
- puts task.printable_result
222
+ puts task.full_printable_result
223
223
  end
224
224
  end
225
225
 
@@ -253,7 +253,7 @@ command 'task:stop' do |c|
253
253
  task.refresh!
254
254
  task.complete?
255
255
  end
256
- puts task.printable_result
256
+ puts task.full_printable_result
257
257
  end
258
258
  end
259
259
 
data/lib/ubalo.rb CHANGED
@@ -9,6 +9,7 @@ require "ubalo/util"
9
9
  require "ubalo/account"
10
10
  require "ubalo/pod"
11
11
  require "ubalo/pod_archive"
12
+ require "ubalo/container_process"
12
13
  require "ubalo/task"
13
14
  require "ubalo/pod_dir"
14
15
  require "ubalo/tailer"
data/lib/ubalo/account.rb CHANGED
@@ -88,6 +88,10 @@ module Ubalo
88
88
  PodArchive.create_with_json(self, archive_json)
89
89
  end
90
90
 
91
+ def container_process_from_json(container_process_json)
92
+ ContainerProcess.create_with_json(self, container_process_json)
93
+ end
94
+
91
95
  def pods
92
96
  request(:get, "/pods").map do |pod_json|
93
97
  pod_from_json(pod_json)
@@ -0,0 +1,71 @@
1
+ module Ubalo
2
+ class ContainerProcess
3
+ include Ubalo::Util
4
+
5
+ def self.create_with_json(account, json)
6
+ container_process = new(account)
7
+ container_process.update_attributes(json)
8
+ container_process
9
+ end
10
+
11
+ attr_reader :state, :exit_type, :exit_result, :output
12
+
13
+ def initialize(account)
14
+ @account = account
15
+ end
16
+
17
+ def update_attributes(attributes)
18
+ @state = attributes.fetch('state')
19
+ @started_at = parse_datetime(attributes.fetch('started_at'))
20
+ @stopped_at = parse_datetime(attributes.fetch('stopped_at'))
21
+ @exit_type = attributes.fetch('exit_type')
22
+ @exit_result = attributes.fetch('exit_result')
23
+ @output = attributes.fetch('output')
24
+ end
25
+
26
+ def tail(running_message, final_message)
27
+ tailer = Ubalo::Tailer.new(logger)
28
+ logger.poll do
29
+ yield
30
+
31
+ message = "(#{runtime}) #{running_message}..."
32
+ if completed?
33
+ message << "#{final_message}. Exit status: #{exit_result}"
34
+ end
35
+
36
+ tailer.update(@output, message)
37
+ completed?
38
+ end
39
+ end
40
+
41
+ def printable_result
42
+ s = ""
43
+ s << "status: #{exit_result}\n"
44
+ s << "runtime: #{runtime}\n"
45
+
46
+ if output and output.length > 0
47
+ s << "stdout/stderr:\n"
48
+ s << Util.indent(output)
49
+ end
50
+ s
51
+ end
52
+
53
+ def completed?
54
+ @state == 'complete'
55
+ end
56
+
57
+ def runtime
58
+ if @started_at
59
+ days = ((@stopped_at || DateTime.now) - @started_at)
60
+ minutes, seconds = (days * 86400).divmod(60)
61
+ "%d:%02d s" % [minutes, seconds]
62
+ end
63
+ end
64
+
65
+ def parse_datetime(string)
66
+ if string
67
+ DateTime.parse(string)
68
+ end
69
+ end
70
+ end
71
+ end
data/lib/ubalo/pod.rb CHANGED
@@ -100,10 +100,18 @@ module Ubalo
100
100
  end
101
101
 
102
102
  def tail_process
103
- tailer = Ubalo::Tailer.new(logger)
104
- tailer.poll_on("Waiting for #{fullname.inspect} to compile") do
103
+ logger.poll_on("Waiting for process to start") do
104
+ refresh!
105
+ compilation_process
106
+ end
107
+
108
+ logger.puts "Compilation process output:"
109
+ compilation_process.tail("Compiling #{fullname}", "compiled") do
110
+ refresh!
111
+ end
112
+
113
+ logger.poll_on("Waiting for container to stop") do
105
114
  refresh!
106
- tailer.update(process_output)
107
115
  compiled?
108
116
  end
109
117
  end
@@ -121,14 +129,13 @@ module Ubalo
121
129
  s = ""
122
130
  s << " name: #{fullname}\n"
123
131
  s << " state: #{state}\n"
132
+ s
133
+ end
124
134
 
135
+ def full_printable_result
136
+ s = printable_result
125
137
  if compilation_process
126
- s << "status: #{compilation_process.fetch('exit_result')}\n"
127
-
128
- if process_output = compilation_process.fetch('output') and process_output.length > 0
129
- s << "stdout/stderr:\n"
130
- s << Util.indent(process_output)
131
- end
138
+ s << compilation_process.printable_result
132
139
  end
133
140
  s
134
141
  end
@@ -141,16 +148,6 @@ module Ubalo
141
148
  fullname == other.fullname
142
149
  end
143
150
 
144
- attr_reader :compilation_process
145
-
146
- def process_output
147
- if compilation_process
148
- if data = compilation_process.fetch('output')
149
- data
150
- end
151
- end
152
- end
153
-
154
151
  def url
155
152
  @account.url_for(path_prefix)
156
153
  end
@@ -158,7 +155,17 @@ module Ubalo
158
155
  private
159
156
  def update_attributes(attributes)
160
157
  @state = attributes['state']
161
- @compilation_process = attributes['compilation_process']
158
+
159
+ if compilation_process_attr = attributes['compilation_process']
160
+ if @compilation_process
161
+ @compilation_process.update_attributes(compilation_process_attr)
162
+ else
163
+ @compilation_process = @account.container_process_from_json(compilation_process_attr)
164
+ end
165
+ else
166
+ @compilation_process = nil
167
+ end
168
+
162
169
  if archive_attr = attributes['archive']
163
170
  @archive = @account.archive_from_json(archive_attr)
164
171
  end
data/lib/ubalo/tailer.rb CHANGED
@@ -6,16 +6,7 @@ module Ubalo
6
6
  @lines = 0
7
7
  end
8
8
 
9
- def poll_on(message)
10
- @message = message
11
-
12
- @logger.puts "stdout/stderr: "
13
- @logger.poll do
14
- yield
15
- end
16
- end
17
-
18
- def update(output)
9
+ def update(output, message)
19
10
  @lines.times do
20
11
  @logger.print "\e[A"
21
12
  @logger.print " " * Integer(ENV.fetch("COLUMNS", 80))
@@ -30,7 +21,7 @@ module Ubalo
30
21
  end
31
22
 
32
23
  puts ""
33
- puts @message
24
+ puts message
34
25
  end
35
26
 
36
27
  def puts(str)
data/lib/ubalo/task.rb CHANGED
@@ -27,10 +27,18 @@ module Ubalo
27
27
  end
28
28
 
29
29
  def tail_process
30
- tailer = Ubalo::Tailer.new(logger)
31
- tailer.poll_on("Waiting for task #{label.inspect}") do
30
+ logger.poll_on("Waiting for process to start") do
31
+ refresh!
32
+ container_process
33
+ end
34
+
35
+ puts "Task process output:"
36
+ container_process.tail("Running #{label.inspect}", "completed") do
37
+ refresh!
38
+ end
39
+
40
+ logger.poll_on("Waiting for container to stop") do
32
41
  refresh!
33
- tailer.update(process_output)
34
42
  complete?
35
43
  end
36
44
  end
@@ -62,18 +70,8 @@ module Ubalo
62
70
  end
63
71
  end
64
72
  s << " state: #{state}\n"
65
-
66
- if container_process
67
- s << "status: #{container_process.fetch('exit_result')}\n"
68
- end
69
-
70
73
  s << " time: #{'%.1f' % elapsed_time} s\n"
71
74
 
72
- if process_output
73
- s << "stdout/stderr:\n"
74
- s << Util.indent(process_output)
75
- end
76
-
77
75
  if output?
78
76
  if @output_error
79
77
  s << "! Parse error in output: #{@output_error.message}"
@@ -85,12 +83,12 @@ module Ubalo
85
83
  s
86
84
  end
87
85
 
88
- def process_output
86
+ def full_printable_result
87
+ s = printable_result
89
88
  if container_process
90
- if data = container_process.fetch('output')
91
- data
92
- end
89
+ s << container_process.printable_result
93
90
  end
91
+ s
94
92
  end
95
93
 
96
94
  def pretty_argv
@@ -108,9 +106,18 @@ module Ubalo
108
106
  def update_attributes(attributes)
109
107
  @state = attributes['state']
110
108
  @argv = attributes['argv']
111
- @arg = attributes['arg']
112
109
  @pod_name = attributes['pod_name']
113
- @container_process = attributes['container_process']
110
+
111
+ if container_process_attr = attributes['container_process']
112
+ if @container_process
113
+ @container_process.update_attributes(container_process_attr)
114
+ else
115
+ @container_process = @account.container_process_from_json(container_process_attr)
116
+ end
117
+ else
118
+ @container_process = nil
119
+ end
120
+
114
121
  @submitted_at = attributes['submitted_at']
115
122
  @elapsed_time = attributes['elapsed_time']
116
123
 
@@ -131,7 +138,7 @@ module Ubalo
131
138
  end
132
139
 
133
140
  def arg?
134
- @arg || @arg_error
141
+ defined?(@arg) || defined?(@arg_error)
135
142
  end
136
143
 
137
144
  def parse_output(raw)
@@ -146,7 +153,7 @@ module Ubalo
146
153
  end
147
154
 
148
155
  def output?
149
- @output || @output_error
156
+ defined?(@output) || defined?(@output_error)
150
157
  end
151
158
 
152
159
  def request method, path = nil, options = {}
data/lib/ubalo/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Ubalo
2
2
  unless const_defined?('VERSION')
3
- VERSION = "0.16"
3
+ VERSION = "0.17"
4
4
  end
5
5
 
6
6
  def self.version
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ubalo
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.16'
4
+ version: '0.17'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-04 00:00:00.000000000 Z
12
+ date: 2012-06-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gli
16
- requirement: &70197562743800 !ruby/object:Gem::Requirement
16
+ requirement: &70211396093500 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70197562743800
24
+ version_requirements: *70211396093500
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: highline
27
- requirement: &70197562711140 !ruby/object:Gem::Requirement
27
+ requirement: &70211396071860 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70197562711140
35
+ version_requirements: *70211396071860
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: json
38
- requirement: &70197562707560 !ruby/object:Gem::Requirement
38
+ requirement: &70211396068360 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70197562707560
46
+ version_requirements: *70211396068360
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rest-client
49
- requirement: &70197562706240 !ruby/object:Gem::Requirement
49
+ requirement: &70211396067300 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.6.3
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70197562706240
57
+ version_requirements: *70211396067300
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: archive-tar-minitar
60
- requirement: &70197562705480 !ruby/object:Gem::Requirement
60
+ requirement: &70211396066140 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70197562705480
68
+ version_requirements: *70211396066140
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: launchy
71
- requirement: &70197562704740 !ruby/object:Gem::Requirement
71
+ requirement: &70211396065480 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70197562704740
79
+ version_requirements: *70211396065480
80
80
  description: CLI and API client for Ubalo
81
81
  email: dev@ubalo.com
82
82
  executables:
@@ -85,6 +85,7 @@ extensions: []
85
85
  extra_rdoc_files: []
86
86
  files:
87
87
  - lib/ubalo/account.rb
88
+ - lib/ubalo/container_process.rb
88
89
  - lib/ubalo/pod.rb
89
90
  - lib/ubalo/pod_archive.rb
90
91
  - lib/ubalo/pod_dir.rb