dtk-shell 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (191) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +5 -0
  3. data/Gemfile_dev +13 -0
  4. data/README.md +121 -0
  5. data/bin/dtk-execute +32 -0
  6. data/bin/dtk-run +92 -0
  7. data/bin/dtk-shell +31 -0
  8. data/dtk-shell.gemspec +50 -0
  9. data/lib/auxiliary.rb +61 -0
  10. data/lib/bundler_monkey_patch.rb +26 -0
  11. data/lib/client.rb +58 -0
  12. data/lib/command_helper.rb +33 -0
  13. data/lib/command_helpers/git_repo.rb +589 -0
  14. data/lib/command_helpers/git_repo/merge.rb +153 -0
  15. data/lib/command_helpers/jenkins_client.rb +106 -0
  16. data/lib/command_helpers/jenkins_client/config_xml.rb +288 -0
  17. data/lib/command_helpers/service_importer.rb +251 -0
  18. data/lib/command_helpers/service_link.rb +33 -0
  19. data/lib/command_helpers/test_module_creator.rb +69 -0
  20. data/lib/command_helpers/test_module_templates/dtk.model.yaml.eruby +10 -0
  21. data/lib/command_helpers/test_module_templates/spec_helper.rb.eruby +10 -0
  22. data/lib/command_helpers/test_module_templates/temp_component_spec.rb.eruby +5 -0
  23. data/lib/commands.rb +57 -0
  24. data/lib/commands/common/thor/access_control.rb +133 -0
  25. data/lib/commands/common/thor/action_result_handler.rb +74 -0
  26. data/lib/commands/common/thor/assembly_template.rb +92 -0
  27. data/lib/commands/common/thor/assembly_workspace.rb +1801 -0
  28. data/lib/commands/common/thor/base_command_helper.rb +59 -0
  29. data/lib/commands/common/thor/clone.rb +82 -0
  30. data/lib/commands/common/thor/common.rb +88 -0
  31. data/lib/commands/common/thor/common_base.rb +49 -0
  32. data/lib/commands/common/thor/create_target.rb +70 -0
  33. data/lib/commands/common/thor/edit.rb +255 -0
  34. data/lib/commands/common/thor/inventory_parser.rb +98 -0
  35. data/lib/commands/common/thor/list_diffs.rb +128 -0
  36. data/lib/commands/common/thor/module.rb +1011 -0
  37. data/lib/commands/common/thor/module/import.rb +210 -0
  38. data/lib/commands/common/thor/node.rb +53 -0
  39. data/lib/commands/common/thor/poller.rb +65 -0
  40. data/lib/commands/common/thor/pull_clone_changes.rb +28 -0
  41. data/lib/commands/common/thor/pull_from_remote.rb +152 -0
  42. data/lib/commands/common/thor/puppet_forge.rb +72 -0
  43. data/lib/commands/common/thor/purge_clone.rb +101 -0
  44. data/lib/commands/common/thor/push_clone_changes.rb +162 -0
  45. data/lib/commands/common/thor/push_to_remote.rb +94 -0
  46. data/lib/commands/common/thor/remotes.rb +71 -0
  47. data/lib/commands/common/thor/reparse.rb +40 -0
  48. data/lib/commands/common/thor/set_required_attributes.rb +46 -0
  49. data/lib/commands/thor/account.rb +239 -0
  50. data/lib/commands/thor/assembly.rb +356 -0
  51. data/lib/commands/thor/attribute.rb +79 -0
  52. data/lib/commands/thor/component.rb +70 -0
  53. data/lib/commands/thor/component_module.rb +501 -0
  54. data/lib/commands/thor/component_template.rb +174 -0
  55. data/lib/commands/thor/dependency.rb +34 -0
  56. data/lib/commands/thor/developer.rb +144 -0
  57. data/lib/commands/thor/dtk.rb +152 -0
  58. data/lib/commands/thor/library.rb +125 -0
  59. data/lib/commands/thor/node.rb +504 -0
  60. data/lib/commands/thor/node_template.rb +94 -0
  61. data/lib/commands/thor/project.rb +34 -0
  62. data/lib/commands/thor/provider.rb +233 -0
  63. data/lib/commands/thor/remotes.rb +49 -0
  64. data/lib/commands/thor/service.rb +941 -0
  65. data/lib/commands/thor/service_module.rb +914 -0
  66. data/lib/commands/thor/state_change.rb +25 -0
  67. data/lib/commands/thor/target.rb +250 -0
  68. data/lib/commands/thor/task.rb +116 -0
  69. data/lib/commands/thor/test_module.rb +310 -0
  70. data/lib/commands/thor/utils.rb +21 -0
  71. data/lib/commands/thor/workspace.rb +685 -0
  72. data/lib/config/cacert.pem +3785 -0
  73. data/lib/config/client.conf.header +20 -0
  74. data/lib/config/configuration.rb +99 -0
  75. data/lib/config/default.conf +16 -0
  76. data/lib/config/disk_cacher.rb +80 -0
  77. data/lib/configurator.rb +176 -0
  78. data/lib/context_router.rb +44 -0
  79. data/lib/core.rb +497 -0
  80. data/lib/domain/git_adapter.rb +412 -0
  81. data/lib/domain/git_error_handler.rb +64 -0
  82. data/lib/domain/response.rb +285 -0
  83. data/lib/domain/response/error_handler.rb +86 -0
  84. data/lib/dtk-shell/version.rb +20 -0
  85. data/lib/dtk_constants.rb +40 -0
  86. data/lib/dtk_error.rb +114 -0
  87. data/lib/dtk_logger.rb +126 -0
  88. data/lib/dtk_shell.rb +31 -0
  89. data/lib/error.rb +85 -0
  90. data/lib/execute.rb +29 -0
  91. data/lib/execute/cli_pure/cli_rerouter.rb +102 -0
  92. data/lib/execute/command.rb +40 -0
  93. data/lib/execute/command/api_call.rb +60 -0
  94. data/lib/execute/command/api_call/map.rb +60 -0
  95. data/lib/execute/command/api_call/service.rb +91 -0
  96. data/lib/execute/command/api_call/translation_term.rb +119 -0
  97. data/lib/execute/command/rest_call.rb +37 -0
  98. data/lib/execute/command_processor.rb +30 -0
  99. data/lib/execute/command_processor/rest_call.rb +59 -0
  100. data/lib/execute/error_usage.rb +21 -0
  101. data/lib/execute/execute_context.rb +86 -0
  102. data/lib/execute/execute_context/result_store.rb +37 -0
  103. data/lib/execute/script.rb +64 -0
  104. data/lib/execute/script/add_tenant.rb +121 -0
  105. data/lib/git-logs/git.log +0 -0
  106. data/lib/parser/adapters/option_parser.rb +70 -0
  107. data/lib/parser/adapters/thor.rb +555 -0
  108. data/lib/parser/adapters/thor/common_option_defs.rb +40 -0
  109. data/lib/require_first.rb +104 -0
  110. data/lib/search_hash.rb +44 -0
  111. data/lib/shell.rb +261 -0
  112. data/lib/shell/context.rb +1065 -0
  113. data/lib/shell/context_aux.rb +46 -0
  114. data/lib/shell/domain/active_context.rb +186 -0
  115. data/lib/shell/domain/context_entity.rb +89 -0
  116. data/lib/shell/domain/context_params.rb +223 -0
  117. data/lib/shell/domain/override_tasks.rb +88 -0
  118. data/lib/shell/domain/shadow_entity.rb +76 -0
  119. data/lib/shell/header_shell.rb +44 -0
  120. data/lib/shell/help_monkey_patch.rb +283 -0
  121. data/lib/shell/interactive_wizard.rb +225 -0
  122. data/lib/shell/message_queue.rb +63 -0
  123. data/lib/shell/parse_monkey_patch.rb +39 -0
  124. data/lib/shell/status_monitor.rb +124 -0
  125. data/lib/task_status.rb +83 -0
  126. data/lib/task_status/refresh_mode.rb +77 -0
  127. data/lib/task_status/snapshot_mode.rb +28 -0
  128. data/lib/task_status/stream_mode.rb +48 -0
  129. data/lib/task_status/stream_mode/element.rb +101 -0
  130. data/lib/task_status/stream_mode/element/format.rb +101 -0
  131. data/lib/task_status/stream_mode/element/hierarchical_task.rb +100 -0
  132. data/lib/task_status/stream_mode/element/hierarchical_task/result.rb +72 -0
  133. data/lib/task_status/stream_mode/element/hierarchical_task/result/action.rb +93 -0
  134. data/lib/task_status/stream_mode/element/hierarchical_task/result/components.rb +26 -0
  135. data/lib/task_status/stream_mode/element/hierarchical_task/result/node_level.rb +26 -0
  136. data/lib/task_status/stream_mode/element/hierarchical_task/steps.rb +34 -0
  137. data/lib/task_status/stream_mode/element/hierarchical_task/steps/action.rb +53 -0
  138. data/lib/task_status/stream_mode/element/hierarchical_task/steps/components.rb +53 -0
  139. data/lib/task_status/stream_mode/element/hierarchical_task/steps/node_level.rb +42 -0
  140. data/lib/task_status/stream_mode/element/no_results.rb +26 -0
  141. data/lib/task_status/stream_mode/element/render.rb +59 -0
  142. data/lib/task_status/stream_mode/element/stage.rb +84 -0
  143. data/lib/task_status/stream_mode/element/stage/render.rb +76 -0
  144. data/lib/task_status/stream_mode/element/task_end.rb +35 -0
  145. data/lib/task_status/stream_mode/element/task_start.rb +37 -0
  146. data/lib/util/common_util.rb +37 -0
  147. data/lib/util/console.rb +235 -0
  148. data/lib/util/dtk_puppet.rb +65 -0
  149. data/lib/util/module_util.rb +66 -0
  150. data/lib/util/os_util.rb +385 -0
  151. data/lib/util/permission_util.rb +31 -0
  152. data/lib/util/remote_dependency_util.rb +84 -0
  153. data/lib/util/ssh_util.rb +94 -0
  154. data/lib/view_processor.rb +129 -0
  155. data/lib/view_processor/augmented_simple_list.rb +44 -0
  156. data/lib/view_processor/hash_pretty_print.rb +123 -0
  157. data/lib/view_processor/simple_list.rb +156 -0
  158. data/lib/view_processor/table_print.rb +309 -0
  159. data/lib/violation.rb +86 -0
  160. data/lib/violation/attribute.rb +76 -0
  161. data/lib/violation/fix.rb +26 -0
  162. data/lib/violation/fix/result.rb +73 -0
  163. data/lib/violation/fix/result/error.rb +34 -0
  164. data/lib/violation/fix/set_attribute.rb +41 -0
  165. data/lib/violation/sub_classes.rb +60 -0
  166. data/puppet/manifests/init.pp +72 -0
  167. data/puppet/manifests/params.pp +16 -0
  168. data/puppet/r8meta.puppet.yml +35 -0
  169. data/puppet/templates/bash_profile.erb +2 -0
  170. data/puppet/templates/client.conf.erb +1 -0
  171. data/puppet/templates/dtkclient.erb +2 -0
  172. data/spec/component_module_spec.rb +34 -0
  173. data/spec/dependency_spec.rb +6 -0
  174. data/spec/dtk_shell_spec.rb +13 -0
  175. data/spec/dtk_spec.rb +33 -0
  176. data/spec/lib/spec_helper.rb +10 -0
  177. data/spec/lib/spec_thor.rb +108 -0
  178. data/spec/node_template_spec.rb +24 -0
  179. data/spec/project_spec.rb +6 -0
  180. data/spec/repo_spec.rb +7 -0
  181. data/spec/response_spec.rb +52 -0
  182. data/spec/service_module_spec.rb +38 -0
  183. data/spec/service_spec.rb +50 -0
  184. data/spec/state_change_spec.rb +7 -0
  185. data/spec/table_print_spec.rb +48 -0
  186. data/spec/target_spec.rb +57 -0
  187. data/spec/task_spec.rb +28 -0
  188. data/views/assembly/augmented_simple_list.rb +12 -0
  189. data/views/assembly_template/augmented_simple_list.rb +12 -0
  190. data/views/list_task/augmented_simple_list.rb +12 -0
  191. metadata +421 -0
@@ -0,0 +1,83 @@
1
+ #
2
+ # Copyright (C) 2010-2016 dtk contributors
3
+ #
4
+ # This file is part of the dtk project.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module DTK::Client
19
+ module TaskStatusMixin
20
+ def task_status_aux(mode, object_id, object_type, opts = {})
21
+ case mode
22
+ when :refresh
23
+ TaskStatus::RefreshMode.new(self, mode, object_id, object_type).task_status(opts)
24
+ when :snapshot
25
+ TaskStatus::SnapshotMode.new(self, mode, object_id, object_type).task_status(opts)
26
+ when :stream
27
+ assembly_or_workspace_id = object_id
28
+ task_status_stream(assembly_or_workspace_id)
29
+ else
30
+ legal_modes = [:refresh, :snapshot, :stream]
31
+ raise DtkError::Usage.new("Illegal mode '#{mode}'; legal modes are: #{legal_modes.join(', ')}")
32
+ end
33
+ end
34
+
35
+ def task_status_stream(assembly_or_workspace_id, opts = {})
36
+ TaskStatus::StreamMode.new(self, :stream, assembly_or_workspace_id, :assembly).get_and_render(opts)
37
+ end
38
+
39
+ def list_task_info_aux(object_type, object_id)
40
+ response = TaskStatus.new(self, object_id, object_type).post_call(:form => :list)
41
+ unless response.ok?
42
+ DtkError.raise_error(response)
43
+ end
44
+ response.override_command_class("list_task")
45
+ puts response.render_data
46
+ end
47
+ end
48
+
49
+ dtk_require_common_commands('thor/base_command_helper')
50
+ class TaskStatus < BaseCommandHelper
51
+ require File.expand_path('task_status/snapshot_mode', File.dirname(__FILE__))
52
+ require File.expand_path('task_status/refresh_mode', File.dirname(__FILE__))
53
+ require File.expand_path('task_status/stream_mode', File.dirname(__FILE__))
54
+
55
+ def initialize(command, mode, object_id, object_type)
56
+ super(command)
57
+ @mode = mode
58
+ @object_id = object_id
59
+ @object_type = object_type
60
+ end
61
+
62
+ private
63
+
64
+ def post_body(opts = {})
65
+ id_field = "#{@object_type}_id".to_sym
66
+ PostBody.new(
67
+ id_field => @object_id,
68
+ :form? => opts[:form],
69
+ :wait_for? => opts[:wait_for],
70
+ :summarize_node_groups? => opts[:summarize]
71
+ )
72
+ end
73
+
74
+ def post_call(opts={})
75
+ response = post rest_url("#{@object_type}/task_status"), post_body(opts)
76
+ unless response.ok?
77
+ DtkError.raise_error(response)
78
+ end
79
+ response
80
+ end
81
+
82
+ end
83
+ end
@@ -0,0 +1,77 @@
1
+ #
2
+ # Copyright (C) 2010-2016 dtk contributors
3
+ #
4
+ # This file is part of the dtk project.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module DTK::Client
19
+ class TaskStatus
20
+ class RefreshMode < self
21
+ DEBUG_SLEEP_TIME = DTK::Configuration.get(:debug_task_frequency)
22
+
23
+ def task_status(opts={})
24
+ begin
25
+ response = nil
26
+ loop do
27
+ response = post_call(opts)
28
+ return response unless response.ok?
29
+
30
+ # stop pulling when top level task succeds, fails or timeout
31
+ if response and response.data and response.data.first
32
+ return response if response.data.first["change_context"]
33
+ #TODO: may fix in server, but now top can have non executing state but a concurrent branch can execute; so
34
+ #chanding bloew for time being
35
+ #break unless response.data.first["status"].eql? "executing"
36
+ # TODO: There is bug where we do not see executing status on start so we have to wait until at
37
+ # least one 'successed' has been found
38
+
39
+ top_task_failed = response.data.first['status'].eql?('failed')
40
+ is_pending = (response.data.select {|r|r["status"].nil? }).size > 0
41
+ is_executing = (response.data.select {|r|r["status"].eql? "executing"}).size > 0
42
+ is_failed = (response.data.select {|r|r["status"].eql? "failed"}).size > 0
43
+ is_cancelled = response.data.first["status"].eql?("cancelled")
44
+
45
+ # commented out because of DTK-1804
46
+ # when some of the converge tasks fail, stop task-status --wait and set task status to '' for remaining tasks which are not executed
47
+ # if is_failed
48
+ # response.data.each {|r| (r["status"] = "") if r["status"].eql?("executing")}
49
+ # is_cancelled = true
50
+ # end
51
+ is_cancelled = true if top_task_failed
52
+
53
+ unless (is_executing || is_pending) && !is_cancelled
54
+ system('clear')
55
+ response.print_error_table = true
56
+ response.render_table(:task_status)
57
+ return response
58
+ end
59
+ end
60
+
61
+ response.render_table(:task_status)
62
+ system('clear')
63
+ response.render_data(true)
64
+
65
+ Console.wait_animation("Watching '#{@object_type}' task status [ #{DEBUG_SLEEP_TIME} seconds refresh ] ", DEBUG_SLEEP_TIME)
66
+ end
67
+ rescue Interrupt => e
68
+ puts ""
69
+ # this tells rest of the flow to skip rendering of this response
70
+ response.skip_render = true unless response.nil?
71
+ end
72
+
73
+ end
74
+ end
75
+ end
76
+ end
77
+
@@ -0,0 +1,28 @@
1
+ #
2
+ # Copyright (C) 2010-2016 dtk contributors
3
+ #
4
+ # This file is part of the dtk project.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module DTK::Client
19
+ class TaskStatus
20
+ class SnapshotMode < self
21
+ def task_status(opts={})
22
+ response = post_call(opts)
23
+ response.print_error_table = true
24
+ response.render_table(:task_status)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,48 @@
1
+ #
2
+ # Copyright (C) 2010-2016 dtk contributors
3
+ #
4
+ # This file is part of the dtk project.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ require 'hirb'
19
+ module DTK::Client
20
+ class TaskStatus
21
+ class StreamMode < self
22
+ require File.expand_path('stream_mode/element', File.dirname(__FILE__))
23
+
24
+ def get_and_render(opts = {})
25
+ Element.get_and_render_task_start(self, opts)
26
+ Element.get_and_render_stages(self, {:wait => WaitWhenNoResults}.merge(opts))
27
+ Response::Ok.new()
28
+ end
29
+
30
+ WaitWhenNoResults = 5 #in seconds
31
+ # making this public for this class and its children
32
+ def post_call(*args)
33
+ super
34
+ end
35
+
36
+ private
37
+
38
+ # This uses a cursor based interface to the server
39
+ # start_index: START_INDEX
40
+ # end_index: END_INDEX
41
+ # convention is start_position = 0 and end_position = 0 means top level task with start time
42
+ def post_body(opts = {})
43
+ ret = super(opts)
44
+ ret.merge(:start_index => opts[:start_index], :end_index => opts[:end_index])
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,101 @@
1
+ #
2
+ # Copyright (C) 2010-2016 dtk contributors
3
+ #
4
+ # This file is part of the dtk project.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module DTK::Client; class TaskStatus::StreamMode
19
+ class Element
20
+ require File.expand_path('element/format', File.dirname(__FILE__))
21
+ require File.expand_path('element/render', File.dirname(__FILE__))
22
+ require File.expand_path('element/hierarchical_task', File.dirname(__FILE__))
23
+ require File.expand_path('element/task_start', File.dirname(__FILE__))
24
+ require File.expand_path('element/task_end', File.dirname(__FILE__))
25
+ require File.expand_path('element/stage', File.dirname(__FILE__))
26
+ require File.expand_path('element/no_results', File.dirname(__FILE__))
27
+ include RenderMixin
28
+
29
+ def initialize(response_element, opts = {})
30
+ @response_element = response_element
31
+ @formatter = Format.new(response_element['type'])
32
+ @ignore_stage_level_info = opts[:ignore_stage_level_info]
33
+ end
34
+
35
+ def self.get_and_render_task_start(task_status_handle, opts = {})
36
+ render_elements(TaskStart.get(task_status_handle, opts))
37
+ end
38
+
39
+ def self.get_and_render_stages(task_status_handle, opts = {})
40
+ Stage.get_and_render_stages(task_status_handle, opts)
41
+ end
42
+
43
+ private
44
+
45
+ # opts will have
46
+ # :start_index
47
+ # :end_index
48
+ # opts can have
49
+ # :ignore_stage_level_info - Boolean
50
+ def self.get_task_status_elements(task_status_handle, element_type, opts = {})
51
+ response = task_status_handle.post_call(opts.merge(:form => :stream_form))
52
+ create_elements(response, opts)
53
+ end
54
+
55
+ # opts can have
56
+ # :ignore_stage_level_info - Boolean
57
+ def self.create_elements(response, opts = {})
58
+ response_elements = response.data
59
+ unless response_elements.kind_of?(Array)
60
+ raise DtkError::Client.new("Unexpected that response.data no at array")
61
+ end
62
+ response_elements.map { |el| create(el, opts) }
63
+ end
64
+ def self.create(response_element, opts)
65
+ type = response_element['type']
66
+ case type && type.to_sym
67
+ when :task_start then TaskStart.new(response_element, opts)
68
+ when :task_end then TaskEnd.new(response_element, opts)
69
+ when :stage then Stage.new(response_element, opts)
70
+ when :stage_start then Stage.new(response_element, {:just_render => :start}.merge(opts))
71
+ when :stage_end then Stage.new(response_element, {:just_render => :end}.merge(opts))
72
+ when :no_results then NoResults.new(response_element, opts)
73
+ else raise DtkError::Client.new("Unexpected element type '#{type}'")
74
+ end
75
+ end
76
+
77
+ def self.task_end?(elements)
78
+ elements.empty? or elements.last.kind_of?(TaskEnd)
79
+ end
80
+
81
+ def self.no_results_yet?(elements)
82
+ elements.find{|el|el.kind_of?(NoResults)}
83
+ end
84
+
85
+ def self.render_elements(elements)
86
+ elements.each{ |el| el.render }
87
+ end
88
+
89
+ def render_stage_steps(subtasks)
90
+ HierarchicalTask.render_steps(self, subtasks)
91
+ end
92
+
93
+ def render_stage_results(subtasks)
94
+ HierarchicalTask.render_results(self, subtasks)
95
+ end
96
+
97
+ def field?(field)
98
+ @response_element[field.to_s]
99
+ end
100
+ end
101
+ end; end
@@ -0,0 +1,101 @@
1
+ #
2
+ # Copyright (C) 2010-2016 dtk contributors
3
+ #
4
+ # This file is part of the dtk project.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ class DTK::Client::TaskStatus::StreamMode::Element
19
+ class Format < ::Hash
20
+ Settings = {
21
+ :task_start => {
22
+ },
23
+ :task_end => {
24
+ },
25
+ :stage => {
26
+ },
27
+ :stage_start => {
28
+ :border_symbol => '=',
29
+ },
30
+ :stage_end => {
31
+ :border_symbol => '-',
32
+ },
33
+ :default => {
34
+ :border_symbol => '=',
35
+ :border_size => 60,
36
+ :bracket_symbol => '=',
37
+ :bracket_size => 25,
38
+ :duration_accuracy => 1, # how many decimal places accuracy
39
+ :include_start_time => true,
40
+ :tab_size => 2, # how many spaces each tab has
41
+ }
42
+ }
43
+
44
+ def initialize(type)
45
+ super()
46
+ @type = type && type.to_sym
47
+ replace(Settings[:default].merge(Settings[@type] || {}))
48
+ end
49
+
50
+ def format(msg, params = {})
51
+ aug_msg = augment(msg, params)
52
+ params[:bracket] ? bracket(aug_msg) : aug_msg
53
+ end
54
+
55
+ def border
56
+ border_symbol = self[:border_symbol]
57
+ border_size = self[:border_size]
58
+ "#{border_symbol * border_size}"
59
+ end
60
+
61
+ def start_time_msg?(started_at)
62
+ if started_at
63
+ "TIME START: #{started_at}"
64
+ end
65
+ end
66
+
67
+ def formatted_duration?(duration)
68
+ if duration
69
+ "#{duration.round(self[:duration_accuracy])}s"
70
+ end
71
+ end
72
+
73
+ def duration_msg?(duration)
74
+ if formatted_duration = formatted_duration?(duration)
75
+ "DURATION: #{formatted_duration}"
76
+ end
77
+ end
78
+
79
+ private
80
+
81
+ def bracket(aug_msg)
82
+ bracket_symbol = self[:bracket_symbol]
83
+ bracket_size = self[:bracket_size]
84
+ "#{bracket_symbol * bracket_size} #{aug_msg} #{bracket_symbol * bracket_size}"
85
+ end
86
+
87
+ def augment(msg, params = {})
88
+ msg_prefix = ''
89
+ started_at = params[:started_at]
90
+ if started_at and self[:include_start_time]
91
+ msg_prefix << "#{started_at} "
92
+ end
93
+ ret = "#{msg_prefix}#{msg}"
94
+ if tabs = params[:tabs]
95
+ ident = ' ' * (tabs * self[:tab_size])
96
+ ret = ret.split("\n").map { |line| "#{ident}#{line}" }.join("\n")
97
+ end
98
+ ret
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,100 @@
1
+ #
2
+ # Copyright (C) 2010-2016 dtk contributors
3
+ #
4
+ # This file is part of the dtk project.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module DTK::Client; class TaskStatus::StreamMode::Element
19
+ class HierarchicalTask
20
+ require File.expand_path('hierarchical_task/result', File.dirname(__FILE__))
21
+ require File.expand_path('hierarchical_task/steps', File.dirname(__FILE__))
22
+
23
+ def initialize(element, hash)
24
+ @type = self.class.type(hash)
25
+ @element = element
26
+ @node_name = (hash['node'] || {})['name']
27
+ @is_node_group = self.class.has_node_group?(hash)
28
+ end
29
+
30
+ def self.render_results(element, stage_subtasks)
31
+ stage_subtasks && Results.render(element, stage_subtasks)
32
+ end
33
+
34
+ def self.render_steps(element, stage_subtasks)
35
+ stage_subtasks && Steps.render(element, stage_subtasks)
36
+ end
37
+
38
+ private
39
+
40
+
41
+ def self.base_subtasks(element, stage_subtasks, opts = {})
42
+ stage_subtasks.inject([]) do |a, subtask_hash|
43
+ if opts[:stop_at_node_group] and has_node_group?(subtask_hash)
44
+ a + [create(element, subtask_hash)]
45
+ elsif (subtask_hash['subtasks'] || []).empty?
46
+ a + [create(element, subtask_hash)]
47
+ else
48
+ a + base_subtasks(element, subtask_hash['subtasks'], opts)
49
+ end
50
+ end
51
+ end
52
+
53
+ def self.create(element, hash)
54
+ stage_type_class(hash).new(element, hash)
55
+ end
56
+
57
+ def self.type(hash)
58
+ hash['executable_action_type']
59
+ end
60
+
61
+ def self.stage_type_class(hash)
62
+ case type(hash)
63
+ when 'ComponentAction'
64
+ self::Action
65
+ when 'ConfigNode'
66
+ self::Components
67
+ else # they will be node level
68
+ self::NodeLevel
69
+ end
70
+ end
71
+
72
+ def self.has_node_group?(subtask_hash)
73
+ subtask_hash['node'] and subtask_hash['node']['type'] == 'group'
74
+ end
75
+
76
+ def render_line(*args)
77
+ @element.render_line(*args)
78
+ end
79
+
80
+ def render_empty_line
81
+ @element.render_empty_line
82
+ end
83
+
84
+ def render_node_term(opts = {})
85
+ if @node_name
86
+ if @is_node_group
87
+ render_line("NODE-GROUP: #{@node_name}", opts)
88
+ else
89
+ render_line("NODE: #{@node_name}", opts)
90
+ end
91
+ end
92
+ end
93
+
94
+ def node_term?
95
+ if @node_name
96
+ @is_node_group ? "node-group:#{@node_name}" : @node_name
97
+ end
98
+ end
99
+ end
100
+ end; end