dtk-client 0.7.4.1 → 0.7.5

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.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/bin/dtk +10 -3
  3. data/bin/dtk-shell +1 -1
  4. data/lib/command_helpers/git_repo.rb +26 -20
  5. data/lib/command_helpers/jenkins_client.rb +4 -3
  6. data/lib/command_helpers/service_importer.rb +37 -25
  7. data/lib/commands.rb +2 -2
  8. data/lib/commands/common/thor/assembly_workspace.rb +185 -173
  9. data/lib/commands/common/thor/base_command_helper.rb +42 -0
  10. data/lib/commands/common/thor/clone.rb +1 -1
  11. data/lib/commands/common/thor/module.rb +37 -58
  12. data/lib/commands/common/thor/module/import.rb +1 -1
  13. data/lib/commands/common/thor/pull_from_remote.rb +7 -12
  14. data/lib/commands/common/thor/purge_clone.rb +1 -1
  15. data/lib/commands/common/thor/push_clone_changes.rb +3 -1
  16. data/lib/commands/common/thor/task_status.rb +52 -75
  17. data/lib/commands/common/thor/task_status/refresh_mode.rb +56 -0
  18. data/lib/commands/common/thor/task_status/snapshot_mode.rb +11 -0
  19. data/lib/commands/common/thor/task_status/stream_mode.rb +31 -0
  20. data/lib/commands/common/thor/task_status/stream_mode/element.rb +90 -0
  21. data/lib/commands/common/thor/task_status/stream_mode/element/no_results.rb +10 -0
  22. data/lib/commands/common/thor/task_status/stream_mode/element/render.rb +88 -0
  23. data/lib/commands/common/thor/task_status/stream_mode/element/stage.rb +13 -0
  24. data/lib/commands/common/thor/task_status/stream_mode/element/task_end.rb +10 -0
  25. data/lib/commands/common/thor/task_status/stream_mode/element/task_start.rb +10 -0
  26. data/lib/commands/thor/account.rb +10 -8
  27. data/lib/commands/thor/assembly.rb +9 -2
  28. data/lib/commands/thor/component_module.rb +0 -52
  29. data/lib/commands/thor/library.rb +1 -0
  30. data/lib/commands/thor/node.rb +1 -36
  31. data/lib/commands/thor/node_template.rb +4 -47
  32. data/lib/commands/thor/service.rb +57 -46
  33. data/lib/commands/thor/service_module.rb +2 -49
  34. data/lib/commands/thor/target.rb +7 -7
  35. data/lib/commands/thor/workspace.rb +44 -27
  36. data/lib/context_router.rb +4 -0
  37. data/lib/core.rb +71 -99
  38. data/lib/domain/response.rb +9 -0
  39. data/lib/domain/response/error_handler.rb +61 -0
  40. data/lib/dtk-client/version.rb +1 -1
  41. data/lib/dtk_client.rb +14 -0
  42. data/lib/dtk_error.rb +91 -0
  43. data/lib/error.rb +3 -9
  44. data/lib/execute/cli_pure/cli_rerouter.rb +82 -0
  45. data/lib/parser/adapters/thor.rb +3 -0
  46. data/lib/shell.rb +2 -1
  47. data/lib/shell/domain/context_params.rb +2 -0
  48. data/lib/util/console.rb +1 -1
  49. data/lib/util/os_util.rb +1 -0
  50. data/lib/util/remote_dependency_util.rb +20 -3
  51. data/lib/view_processor/table_print.rb +7 -25
  52. metadata +17 -5
  53. data/lib/commands/common/thor/test_action_agent.rb +0 -39
  54. data/lib/commands/thor/repo.rb +0 -35
@@ -0,0 +1,42 @@
1
+ module DTK::Client
2
+ class BaseCommandHelper
3
+ def initialize(command,context_params=nil)
4
+ @command = command
5
+ @context_params = context_params
6
+ @options = command.options
7
+ end
8
+
9
+ def print_external_dependencies(external_dependencies, location)
10
+ ambiguous = external_dependencies["ambiguous"]||[]
11
+ amb_sorted = ambiguous.map { |k,v| "#{k.split('/').last} (#{v.join(', ')})" }
12
+ inconsistent = external_dependencies["inconsistent"]||[]
13
+ possibly_missing = external_dependencies["possibly_missing"]||[]
14
+
15
+ OsUtil.print("There are inconsistent module dependencies mentioned #{location}: #{inconsistent.join(', ')}", :red) unless inconsistent.empty?
16
+ OsUtil.print("There are missing module dependencies mentioned #{location}: #{possibly_missing.join(', ')}", :yellow) unless possibly_missing.empty?
17
+ OsUtil.print("There are ambiguous module dependencies mentioned #{location}: '#{amb_sorted.join(', ')}'. One of the namespaces should be selected by editing the module_refs file", :yellow) if ambiguous && !ambiguous.empty?
18
+ end
19
+
20
+ private
21
+ def context_params()
22
+ @context_params || raise(DtkError, "[ERROR] @context_params is nil")
23
+ end
24
+
25
+ def retrieve_arguments(mapping, method_info = nil)
26
+ context_params.retrieve_arguments(mapping, method_info || @command.method_argument_names)
27
+ end
28
+
29
+ def get_namespace_and_name(*args)
30
+ @command.get_namespace_and_name(*args)
31
+ end
32
+
33
+ def rest_url(*args)
34
+ @command.rest_url(*args)
35
+ end
36
+
37
+ def post(*args)
38
+ @command.post(*args)
39
+ end
40
+
41
+ end
42
+ end
@@ -1,7 +1,7 @@
1
1
  dtk_require_common_commands('thor/common')
2
2
  module DTK::Client
3
3
  module CloneMixin
4
- extend Console
4
+ extend ::DTK::Client::Console
5
5
  include CommonMixin
6
6
  ##
7
7
  #
@@ -21,36 +21,9 @@ DEFAULT_COMMIT_MSG = "Initial commit."
21
21
  PULL_CATALOGS = ["dtkn"]
22
22
 
23
23
  module DTK::Client
24
+ dtk_require_common_commands('thor/base_command_helper')
24
25
  class CommonModule
25
26
  dtk_require_common_commands('thor/module/import')
26
-
27
- def initialize(command,context_params)
28
- @command = command
29
- @context_params = context_params
30
- @options = command.options
31
- end
32
-
33
- def print_external_dependencies(external_dependencies, location)
34
- ambiguous = external_dependencies["ambiguous"]||[]
35
- amb_sorted = ambiguous.map { |k,v| "#{k.split('/').last} (#{v.join(', ')})" }
36
- inconsistent = external_dependencies["inconsistent"]||[]
37
- possibly_missing = external_dependencies["possibly_missing"]||[]
38
-
39
- OsUtil.print("There are inconsistent module dependencies mentioned #{location}: #{inconsistent.join(', ')}", :red) unless inconsistent.empty?
40
- OsUtil.print("There are missing module dependencies mentioned #{location}: #{possibly_missing.join(', ')}", :yellow) unless possibly_missing.empty?
41
- OsUtil.print("There are ambiguous module dependencies mentioned #{location}: '#{amb_sorted.join(', ')}'. One of the namespaces should be selected by editing the module_refs file", :yellow) if ambiguous && !ambiguous.empty?
42
- end
43
-
44
- private
45
- # TODO: when we do this for other areas we can move these things up and use as common classes
46
- # helpers
47
- def retrieve_arguments(mapping, method_info = nil)
48
- @context_params.retrieve_arguments(mapping, method_info || @command.method_argument_names)
49
- end
50
-
51
- def get_namespace_and_name(*args)
52
- @command.get_namespace_and_name(*args)
53
- end
54
27
  end
55
28
 
56
29
  module ModuleMixin
@@ -157,7 +130,7 @@ module DTK::Client
157
130
  unless method_opts[:no_error_msg]
158
131
  msg = "Module '#{module_name}' "
159
132
  if version then msg << "version #{version} has been deleted"
160
- else msg << "has been deleted"; end
133
+ else msg << "has been deleted"; end
161
134
  OsUtil.print(msg, :yellow)
162
135
  end
163
136
 
@@ -166,9 +139,9 @@ module DTK::Client
166
139
 
167
140
  def set_attribute_module_aux(context_params)
168
141
  if context_params.is_there_identifier?(:attribute)
169
- mapping = [REQ_MODULE_ID,:attribute_id!, :option_1]
142
+ mapping = [REQ_MODULE_ID, :attribute_id!, :option_1]
170
143
  else
171
- mapping = [REQ_MODULE_ID,:option_1!,:option_2]
144
+ mapping = [REQ_MODULE_ID, :option_1!, :option_2]
172
145
  end
173
146
 
174
147
  module_id, attribute_id, value = context_params.retrieve_arguments(mapping, method_argument_names)
@@ -181,13 +154,13 @@ module DTK::Client
181
154
  "#{module_type}_id".to_sym => module_id
182
155
  }
183
156
 
184
- post rest_url("attribute/set"), post_body
157
+ post rest_url('attribute/set'), post_body
185
158
  end
186
159
 
187
- def push_module_aux(context_params, internal_trigger=false, opts={})
160
+ def push_module_aux(context_params, internal_trigger = false, opts = {})
188
161
  module_type = get_module_type(context_params)
189
- module_id, module_name = context_params.retrieve_arguments([REQ_MODULE_ID, "#{module_type}_name".to_sym],method_argument_names)
190
- version = options["version"]
162
+ module_id, module_name = context_params.retrieve_arguments([REQ_MODULE_ID, "#{module_type}_name".to_sym], method_argument_names)
163
+ version = options['version']
191
164
 
192
165
  module_location = OsUtil.module_location(module_type, module_name, version)
193
166
 
@@ -196,8 +169,8 @@ module DTK::Client
196
169
  opts.merge!(:force => options.force?)
197
170
 
198
171
  reparse_aux(module_location)
199
- push_clone_changes_aux(module_type.to_sym, module_id, version, options["message"]||DEFAULT_COMMIT_MSG, internal_trigger, opts)
200
- end
172
+ push_clone_changes_aux(module_type.to_sym, module_id, version, options['message'] || DEFAULT_COMMIT_MSG, internal_trigger, opts)
173
+ end
201
174
 
202
175
  def create_test_module_aux(context_params)
203
176
  test_module_name = context_params.retrieve_arguments([:option_1!], method_argument_names)
@@ -209,10 +182,10 @@ module DTK::Client
209
182
  create_response = import(context_params)
210
183
 
211
184
  unless create_response.ok?
212
- error_msg = create_response['errors'].select { |er| er['message'].include? "cannot be created since it exists already" }
185
+ error_msg = create_response['errors'].select { |er| er['message'].include? 'cannot be created since it exists already' }
213
186
  if error_msg.empty?
214
187
  # If server response is not ok and module does not exist on server, delete cloned module, invoke delete method
215
- delete(context_params,:force_delete => true, :no_error_msg => true)
188
+ delete(context_params, :force_delete => true, :no_error_msg => true)
216
189
  end
217
190
 
218
191
  # remove temp directory
@@ -227,13 +200,13 @@ module DTK::Client
227
200
  end
228
201
 
229
202
  def import_module_aux(context_params)
230
- CommonModule::Import.new(self,context_params).from_file()
203
+ CommonModule::Import.new(self, context_params).from_file()
231
204
  end
232
205
 
233
206
  def install_module_aux(context_params)
234
207
  create_missing_clone_dirs()
235
208
  resolve_direct_access(::DTK::Client::Configurator.check_direct_access)
236
- remote_module_name, version = context_params.retrieve_arguments([:option_1!, :option_2],method_argument_names)
209
+ remote_module_name, version = context_params.retrieve_arguments([:option_1!, :option_2], method_argument_names)
237
210
  # in case of auto-import via service import, we skip cloning to speed up a process
238
211
  skip_cloning = context_params.get_forwarded_options()['skip_cloning'] if context_params.get_forwarded_options()
239
212
  do_not_raise = context_params.get_forwarded_options()[:do_not_raise] if context_params.get_forwarded_options()
@@ -241,40 +214,44 @@ module DTK::Client
241
214
  module_type = get_module_type(context_params)
242
215
 
243
216
  # ignore_component_error = context_params.get_forwarded_options()[:ignore_component_error]||options.ignore? if context_params.get_forwarded_options()
244
- ignore_component_error = context_params.get_forwarded_options() ? context_params.get_forwarded_options()[:ignore_component_error] : options.ignore?
217
+ ignore_component_error = context_params.get_forwarded_options().empty? ? options.ignore? : context_params.get_forwarded_options()[:ignore_component_error]
245
218
  additional_message = context_params.get_forwarded_options()[:additional_message] if context_params.get_forwarded_options()
246
219
 
247
- remote_namespace, local_module_name = get_namespace_and_name(remote_module_name,':')
220
+ remote_namespace, local_module_name = get_namespace_and_name(remote_module_name, ':')
248
221
 
249
222
  if clone_dir = Helper(:git_repo).local_clone_dir_exists?(module_type.to_sym, local_module_name, :namespace => remote_namespace, :version => version)
250
- message = "Module's directory (#{clone_dir}) exists on client. To install this needs to be renamed or removed"
251
- message += ". To ignore this conflict and use existing component module please use -i switch (install REMOTE-SERVICE-NAME -i)." if additional_message
223
+ message = "Module's directory (#{clone_dir}) exists on client. To install this needs to be renamed or removed."
224
+ # message += '. To ignore this conflict and use existing component module please use -i switch (install REMOTE-SERVICE-NAME -i).' if additional_message
252
225
 
253
226
  raise DtkError, message unless ignore_component_error
254
227
  end
255
228
 
256
229
  post_body = {
257
- :remote_module_name => remote_module_name.sub(':','/'),
230
+ :remote_module_name => remote_module_name.sub(':', '/'),
258
231
  :local_module_name => local_module_name,
259
232
  :rsa_pub_key => SSHUtil.rsa_pub_key_content()
260
233
  }
261
234
  post_body.merge!(:do_not_raise => do_not_raise) if do_not_raise
262
235
  post_body.merge!(:ignore_component_error => ignore_component_error) if ignore_component_error
263
236
  post_body.merge!(:additional_message => additional_message) if additional_message
237
+ post_body.merge!(:skip_auto_install => skip_ainstall) if skip_ainstall
264
238
 
265
239
  response = post rest_url("#{module_type}/import"), post_body
266
- are_there_warnings = RemoteDependencyUtil.print_dependency_warnings(response)
240
+
241
+ # print permission warnings and then check for other warnings
242
+ are_there_warnings = RemoteDependencyUtil.check_permission_warnings(response)
243
+ are_there_warnings ||= RemoteDependencyUtil.print_dependency_warnings(response, nil, :ignore_permission_warnings => true)
267
244
 
268
245
  # prompt to see if user is ready to continue with warnings/errors
269
246
  if are_there_warnings
270
- return false unless Console.confirmation_prompt("Do you still want to proceed with import"+'?')
247
+ return false unless Console.confirmation_prompt('Do you still want to proceed with import' + '?')
271
248
  end
272
249
 
273
250
  # case when we need to import additional components
274
- if (response.ok? && !skip_ainstall && (missing_components = response.data(:missing_module_components)))
251
+ if response.ok? && !skip_ainstall && (missing_components = response.data(:missing_module_components))
275
252
  required_components = response.data(:required_modules)
276
- opts = {:do_not_raise=>true}
277
- module_opts = ignore_component_error ? opts.merge(:ignore_component_error => true) : opts.merge(:additional_message=>true)
253
+ opts = { :do_not_raise => true }
254
+ module_opts = ignore_component_error ? opts.merge(:ignore_component_error => true) : opts.merge(:additional_message => true)
278
255
  module_opts.merge!(:update_none => true) if options.update_none?
279
256
 
280
257
  continue = trigger_module_auto_import(missing_components, required_components, module_opts)
@@ -286,11 +263,10 @@ module DTK::Client
286
263
  response = post rest_url("#{module_type}/import"), post_body
287
264
 
288
265
  # we set skip cloning since it is already done by import
289
- puts " Done"
266
+ puts ' Done'
290
267
  end
291
268
 
292
- return response if(!response.ok? || response.data(:does_not_exist))
293
- # module_name,repo_url,branch,version = response.data(:module_name, :repo_url, :workspace_branch, :version)
269
+ return response if !response.ok? || response.data(:does_not_exist)
294
270
  module_id, module_name, namespace, repo_url, branch, version = response.data(:module_id, :module_name, :namespace, :repo_url, :workspace_branch, :version)
295
271
 
296
272
  if error = response.data(:dsl_parse_error)
@@ -309,13 +285,13 @@ module DTK::Client
309
285
 
310
286
  def delete_from_catalog_aux(context_params)
311
287
  module_type = get_module_type(context_params)
312
- remote_module_name = context_params.retrieve_arguments([:option_1!],method_argument_names)
288
+ remote_module_name = context_params.retrieve_arguments([:option_1!], method_argument_names)
313
289
 
314
290
  # remote_module_name can be namespace:name or namespace/name
315
291
  remote_namespace, remote_module_name = get_namespace_and_name(remote_module_name, ':')
316
292
 
317
293
  unless options.force? || options.confirmed?
318
- return unless Console.confirmation_prompt("Are you sure you want to delete remote #{module_type} '#{remote_namespace.nil? ? '' : remote_namespace+'/'}#{remote_module_name}' and all items contained in it"+'?')
294
+ return unless Console.confirmation_prompt("Are you sure you want to delete remote #{module_type} '#{remote_namespace.nil? ? '' : remote_namespace + '/'}#{remote_module_name}' and all items contained in it" + '?')
319
295
  end
320
296
 
321
297
  post_body = {
@@ -330,7 +306,7 @@ module DTK::Client
330
306
 
331
307
  def publish_module_aux(context_params)
332
308
  module_type = get_module_type(context_params)
333
- module_id, input_remote_name = context_params.retrieve_arguments([REQ_MODULE_ID, :option_1],method_argument_names)
309
+ module_id, input_remote_name = context_params.retrieve_arguments([REQ_MODULE_ID, :option_1], method_argument_names)
334
310
 
335
311
  post_body = {
336
312
  "#{module_type}_id".to_sym => module_id,
@@ -354,6 +330,7 @@ module DTK::Client
354
330
  version = options.version
355
331
  module_type = get_module_type(context_params)
356
332
  skip_recursive_pull = context_params.get_forwarded_options()[:skip_recursive_pull]
333
+ ignore_dependency_merge_conflict = context_params.get_forwarded_options()[:skip_recursive_pull]
357
334
 
358
335
  raise DtkValidationError, "You have to provide valid catalog to pull changes from! Valid catalogs: #{PULL_CATALOGS}" unless catalog
359
336
 
@@ -365,9 +342,11 @@ module DTK::Client
365
342
  :force => options.force?,
366
343
  :version => version,
367
344
  :remote_namespace => options.namespace,
368
- :skip_recursive_pull => skip_recursive_pull
345
+ :skip_recursive_pull => skip_recursive_pull,
346
+ :ignore_dependency_merge_conflict => ignore_dependency_merge_conflict
369
347
  }
370
348
 
349
+ opts.merge!(:do_not_raise => true) if (context_params.get_forwarded_options()||{})[:do_not_raise]
371
350
  response = pull_from_remote_aux(module_type.to_sym, module_id, opts)
372
351
  return response unless response.ok?
373
352
 
@@ -4,7 +4,7 @@ dtk_require_from_base("command_helper")
4
4
 
5
5
  module DTK::Client
6
6
  class CommonModule
7
- class Import < self
7
+ class Import < BaseCommandHelper
8
8
  include CommandBase
9
9
  include CommandHelperMixin
10
10
  include PushCloneChangesMixin
@@ -34,7 +34,7 @@ module DTK::Client
34
34
  unless rsa_pub_key
35
35
  raise DtkError,"No File found at (#{path_to_key}). Path is wrong or it is necessary to generate the public rsa key (e.g., run ssh-keygen -t rsa)"
36
36
  end
37
- opts_perform_locally = remote_params.merge(:full_module_name => full_module_name, :force => opts[:force])
37
+ opts_perform_locally = remote_params.merge(:full_module_name => full_module_name, :force => opts[:force], :do_not_raise => opts[:do_not_raise], :ignore_dependency_merge_conflict => opts[:ignore_dependency_merge_conflict])
38
38
  PullFromRemote.perform_locally(self,module_type,module_id,module_name,opts_perform_locally)
39
39
  else
40
40
  # TODO: see if this works correctly
@@ -47,10 +47,11 @@ module DTK::Client
47
47
  ##
48
48
  #
49
49
  # module_type: will be :component_module or :service_module
50
- def import_module_component_dependencies(module_type, module_id, remote_namespace=nil)
50
+ def import_module_component_dependencies(module_type, module_id, remote_namespace = nil)
51
51
  response = resolve_pull_from_remote_on_server(module_type, module_id, remote_namespace)
52
52
 
53
53
  print "Resolving dependencies please wait ... "
54
+ RemoteDependencyUtil.check_permission_warnings(response)
54
55
 
55
56
  # install them all!
56
57
  if (response.ok? && !(missing_components = response.data(:missing_modules)).empty?)
@@ -91,21 +92,15 @@ module DTK::Client
91
92
  response = cmd_obj.Helper(:git_repo).pull_changes(module_type,module_name,opts)
92
93
 
93
94
  # return response unless response.ok?
94
- if (response.data[:diffs].nil? || response.data[:diffs].empty?)
95
- puts "No changes to pull from remote."
95
+ if custom_message = response.data[:custom_message]
96
+ puts custom_message
97
+ elsif (response.data[:diffs].nil? || response.data[:diffs].empty?)
98
+ puts "No changes to pull from remote." unless response['errors']
96
99
  else
97
100
  puts "Changes pulled from remote"
98
101
  end
99
102
 
100
103
  return response
101
-
102
- # removing this for now, because we will use push-clone-changes as part of pull-from-remote command
103
- # post_body = {
104
- # id_field(module_type) => module_id,
105
- # :commit_sha => response.data[:commit_sha],
106
- # :json_diffs => JSON.generate(response.data[:diffs])
107
- # }
108
- # post rest_url("#{module_type}/update_model_from_clone"), post_body
109
104
  end
110
105
 
111
106
  def self.perform_on_server(cmd_obj,module_type,module_id,module_name,remote_params)
@@ -1,6 +1,6 @@
1
1
  module DTK::Client
2
2
  module PurgeCloneMixin
3
- def purge_clone_aux(module_type,opts={})
3
+ def purge_clone_aux(module_type, opts = {})
4
4
  module_name = opts[:module_name]
5
5
  version = opts[:version]
6
6
  opts_module_loc = (opts[:assembly_module] ? {:assembly_module => opts[:assembly_module]} : Hash.new)
@@ -16,7 +16,7 @@ module DTK::Client
16
16
 
17
17
  unless File.directory?(module_location)
18
18
  return if opts[:skip_cloning]
19
- if Console.confirmation_prompt("Push not possible, module '#{module_name}#{version && "-#{version}"}' has not been cloned. Would you like to clone module now"+'?')
19
+ if opts[:force_clone] || Console.confirmation_prompt("Push not possible, module '#{module_name}#{version && "-#{version}"}' has not been cloned. Would you like to clone module now"+'?')
20
20
  clone_aux(module_type, module_id, version, true, true, opts)
21
21
  else
22
22
  return
@@ -32,12 +32,14 @@ module DTK::Client
32
32
  repo_obj = response.data(:repo_obj)
33
33
  json_diffs = JSON.generate(response.data(:diffs))
34
34
  post_body = get_workspace_branch_info_post_body(module_type, module_id, version, opts).merge(:json_diffs => json_diffs, :commit_sha => commit_sha)
35
+
35
36
  post_body.merge!(:modification_type => opts[:modification_type]) if opts[:modification_type]
36
37
  post_body.merge!(:force_parse => true) if options['force-parse'] || opts[:force_parse]
37
38
  post_body.merge!(:update_from_includes => true) if opts[:update_from_includes]
38
39
  post_body.merge!(:service_instance_module => true) if opts[:service_instance_module]
39
40
  post_body.merge!(:current_branch_sha => opts[:current_branch_sha]) if opts[:current_branch_sha]
40
41
  post_body.merge!(:force => opts[:force]) if opts[:force]
42
+ post_body.merge!(:task_action => opts[:task_action]) if opts[:task_action]
41
43
 
42
44
  if opts[:set_parsed_false]
43
45
  post_body.merge!(:set_parsed_false => true)
@@ -1,86 +1,63 @@
1
1
  module DTK::Client
2
2
  module TaskStatusMixin
3
- def task_status_aux(id,type,opts={})
4
- if opts[:wait]
5
- # there will be infinite loop until intereputed with CTRL+C
6
- begin
7
- response = nil
8
- loop do
9
- response = task_status_aux_post(id,type,opts)
10
- raise DTK::Client::DtkError, "[ERROR] #{response['errors'].first['message']}." if response["status"].eql?('notok')
11
-
12
- # stop pulling when top level task succeds, fails or timeout
13
- if response and response.data and response.data.first
14
- #TODO: may fix in server, but now top can have non executing state but a concurrent branch can execute; so
15
- #chanding bloew for time being
16
- #break unless response.data.first["status"].eql? "executing"
17
- # TODO: There is bug where we do not see executing status on start so we have to wait until at
18
- # least one 'successed' has been found
19
-
20
- top_task_failed = response.data.first['status'].eql?('failed')
21
- is_pending = (response.data.select {|r|r["status"].nil? }).size > 0
22
- is_executing = (response.data.select {|r|r["status"].eql? "executing"}).size > 0
23
- is_failed = (response.data.select {|r|r["status"].eql? "failed"}).size > 0
24
- is_cancelled = response.data.first["status"].eql?("cancelled")
25
-
26
- # commented out because of DTK-1804
27
- # when some of the converge tasks fail, stop task-status --wait and set task status to '' for remaining tasks which are not executed
28
- # if is_failed
29
- # response.data.each {|r| (r["status"] = "") if r["status"].eql?("executing")}
30
- # is_cancelled = true
31
- # end
32
- is_cancelled = true if top_task_failed
33
-
34
- unless (is_executing || is_pending) && !is_cancelled
35
- system('clear')
36
- response.print_error_table = true
37
- response.render_table(:task_status)
38
- return response
39
- end
40
- end
41
-
42
- response.render_table(:task_status)
43
- system('clear')
44
- response.render_data(true)
45
-
46
- Console.wait_animation("Watching '#{type}' task status [ #{DEBUG_SLEEP_TIME} seconds refresh ] ",DEBUG_SLEEP_TIME)
47
- end
48
- rescue Interrupt => e
49
- puts ""
50
- # this tells rest of the flow to skip rendering of this response
51
- response.skip_render = true unless response.nil?
52
- end
3
+ def task_status_aux(mode, object_id, object_type, opts={})
4
+ case mode
5
+ when :refresh
6
+ TaskStatus::RefreshMode.new(self,mode,object_id,object_type).task_status(opts)
7
+ when :snapshot
8
+ TaskStatus::SnapshotMode.new(self,mode,object_id,object_type).task_status(opts)
9
+ when :stream
10
+ assembly_or_workspace_id = object_id
11
+ task_status_stream(assembly_or_workspace_id)
53
12
  else
54
- response = task_status_aux_post(id,type,opts)
55
- response.print_error_table = true
56
- response.render_table(:task_status)
57
- end
13
+ legal_modes = [:refresh,:snapshot,:stream]
14
+ raise DtkError::Usage.new("Illegal mode '#{mode}'; legal modes are: #{legal_modes.join(', ')}")
58
15
  end
16
+ end
17
+
18
+ def task_status_stream(assembly_or_workspace_id)
19
+ TaskStatus::StreamMode.new(self,:stream,assembly_or_workspace_id,:assembly).get_and_render()
20
+ end
59
21
 
60
- def list_task_info_aux(type, id)
61
- id_sym = "#{type}_id".to_sym
62
- post_body = {
63
- id_sym => id,
64
- :format => :list
65
- }
66
- response = post rest_url("#{type}/task_status"), post_body
67
-
68
- raise DTK::Client::DtkError, "[SERVER ERROR] #{response['errors'].first['message']}." if response["status"].eql?('notok')
69
-
70
- response.override_command_class("list_task")
71
- puts response.render_data
22
+ def list_task_info_aux(object_type, object_id)
23
+ response = TaskStatus.new(self,object_id,object_type).post_call(:form => :list)
24
+ unless response.ok?
25
+ DtkError.raise_error(response)
72
26
  end
27
+ response.override_command_class("list_task")
28
+ puts response.render_data
29
+ end
30
+ end
31
+
32
+ dtk_require_common_commands('thor/base_command_helper')
33
+ class TaskStatus < BaseCommandHelper
34
+ require File.expand_path('task_status/snapshot_mode',File.dirname(__FILE__))
35
+ require File.expand_path('task_status/refresh_mode',File.dirname(__FILE__))
36
+ require File.expand_path('task_status/stream_mode',File.dirname(__FILE__))
73
37
 
74
- private
75
- def task_status_aux_post(id,type,opts={})
76
- id_field = "#{type}_id".to_sym
77
- post_body_hash = {
78
- id_field => id,
79
- :format => :table,
80
- :summarize_node_groups? => opts[:summarize]
81
- }
82
- post rest_url("#{type}/task_status"), PostBody.new(post_body_hash)
38
+ def initialize(command,mode,object_id,object_type)
39
+ super(command)
40
+ @mode = mode
41
+ @object_id = object_id
42
+ @object_type = object_type
43
+ end
44
+
45
+ private
46
+ def post_body(opts={})
47
+ id_field = "#{@object_type}_id".to_sym
48
+ PostBody.new(
49
+ id_field => @object_id,
50
+ :form? => opts[:form],
51
+ :summarize_node_groups? => opts[:summarize]
52
+ )
53
+ end
54
+ def post_call(opts={})
55
+ response = post rest_url("#{@object_type}/task_status"), post_body(opts)
56
+ unless response.ok?
57
+ DtkError.raise_error(response)
83
58
  end
59
+ response
84
60
  end
85
61
 
62
+ end
86
63
  end