dtk-shell 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +5 -0
- data/Gemfile_dev +13 -0
- data/README.md +121 -0
- data/bin/dtk-execute +32 -0
- data/bin/dtk-run +92 -0
- data/bin/dtk-shell +31 -0
- data/dtk-shell.gemspec +50 -0
- data/lib/auxiliary.rb +61 -0
- data/lib/bundler_monkey_patch.rb +26 -0
- data/lib/client.rb +58 -0
- data/lib/command_helper.rb +33 -0
- data/lib/command_helpers/git_repo.rb +589 -0
- data/lib/command_helpers/git_repo/merge.rb +153 -0
- data/lib/command_helpers/jenkins_client.rb +106 -0
- data/lib/command_helpers/jenkins_client/config_xml.rb +288 -0
- data/lib/command_helpers/service_importer.rb +251 -0
- data/lib/command_helpers/service_link.rb +33 -0
- data/lib/command_helpers/test_module_creator.rb +69 -0
- data/lib/command_helpers/test_module_templates/dtk.model.yaml.eruby +10 -0
- data/lib/command_helpers/test_module_templates/spec_helper.rb.eruby +10 -0
- data/lib/command_helpers/test_module_templates/temp_component_spec.rb.eruby +5 -0
- data/lib/commands.rb +57 -0
- data/lib/commands/common/thor/access_control.rb +133 -0
- data/lib/commands/common/thor/action_result_handler.rb +74 -0
- data/lib/commands/common/thor/assembly_template.rb +92 -0
- data/lib/commands/common/thor/assembly_workspace.rb +1801 -0
- data/lib/commands/common/thor/base_command_helper.rb +59 -0
- data/lib/commands/common/thor/clone.rb +82 -0
- data/lib/commands/common/thor/common.rb +88 -0
- data/lib/commands/common/thor/common_base.rb +49 -0
- data/lib/commands/common/thor/create_target.rb +70 -0
- data/lib/commands/common/thor/edit.rb +255 -0
- data/lib/commands/common/thor/inventory_parser.rb +98 -0
- data/lib/commands/common/thor/list_diffs.rb +128 -0
- data/lib/commands/common/thor/module.rb +1011 -0
- data/lib/commands/common/thor/module/import.rb +210 -0
- data/lib/commands/common/thor/node.rb +53 -0
- data/lib/commands/common/thor/poller.rb +65 -0
- data/lib/commands/common/thor/pull_clone_changes.rb +28 -0
- data/lib/commands/common/thor/pull_from_remote.rb +152 -0
- data/lib/commands/common/thor/puppet_forge.rb +72 -0
- data/lib/commands/common/thor/purge_clone.rb +101 -0
- data/lib/commands/common/thor/push_clone_changes.rb +162 -0
- data/lib/commands/common/thor/push_to_remote.rb +94 -0
- data/lib/commands/common/thor/remotes.rb +71 -0
- data/lib/commands/common/thor/reparse.rb +40 -0
- data/lib/commands/common/thor/set_required_attributes.rb +46 -0
- data/lib/commands/thor/account.rb +239 -0
- data/lib/commands/thor/assembly.rb +356 -0
- data/lib/commands/thor/attribute.rb +79 -0
- data/lib/commands/thor/component.rb +70 -0
- data/lib/commands/thor/component_module.rb +501 -0
- data/lib/commands/thor/component_template.rb +174 -0
- data/lib/commands/thor/dependency.rb +34 -0
- data/lib/commands/thor/developer.rb +144 -0
- data/lib/commands/thor/dtk.rb +152 -0
- data/lib/commands/thor/library.rb +125 -0
- data/lib/commands/thor/node.rb +504 -0
- data/lib/commands/thor/node_template.rb +94 -0
- data/lib/commands/thor/project.rb +34 -0
- data/lib/commands/thor/provider.rb +233 -0
- data/lib/commands/thor/remotes.rb +49 -0
- data/lib/commands/thor/service.rb +941 -0
- data/lib/commands/thor/service_module.rb +914 -0
- data/lib/commands/thor/state_change.rb +25 -0
- data/lib/commands/thor/target.rb +250 -0
- data/lib/commands/thor/task.rb +116 -0
- data/lib/commands/thor/test_module.rb +310 -0
- data/lib/commands/thor/utils.rb +21 -0
- data/lib/commands/thor/workspace.rb +685 -0
- data/lib/config/cacert.pem +3785 -0
- data/lib/config/client.conf.header +20 -0
- data/lib/config/configuration.rb +99 -0
- data/lib/config/default.conf +16 -0
- data/lib/config/disk_cacher.rb +80 -0
- data/lib/configurator.rb +176 -0
- data/lib/context_router.rb +44 -0
- data/lib/core.rb +497 -0
- data/lib/domain/git_adapter.rb +412 -0
- data/lib/domain/git_error_handler.rb +64 -0
- data/lib/domain/response.rb +285 -0
- data/lib/domain/response/error_handler.rb +86 -0
- data/lib/dtk-shell/version.rb +20 -0
- data/lib/dtk_constants.rb +40 -0
- data/lib/dtk_error.rb +114 -0
- data/lib/dtk_logger.rb +126 -0
- data/lib/dtk_shell.rb +31 -0
- data/lib/error.rb +85 -0
- data/lib/execute.rb +29 -0
- data/lib/execute/cli_pure/cli_rerouter.rb +102 -0
- data/lib/execute/command.rb +40 -0
- data/lib/execute/command/api_call.rb +60 -0
- data/lib/execute/command/api_call/map.rb +60 -0
- data/lib/execute/command/api_call/service.rb +91 -0
- data/lib/execute/command/api_call/translation_term.rb +119 -0
- data/lib/execute/command/rest_call.rb +37 -0
- data/lib/execute/command_processor.rb +30 -0
- data/lib/execute/command_processor/rest_call.rb +59 -0
- data/lib/execute/error_usage.rb +21 -0
- data/lib/execute/execute_context.rb +86 -0
- data/lib/execute/execute_context/result_store.rb +37 -0
- data/lib/execute/script.rb +64 -0
- data/lib/execute/script/add_tenant.rb +121 -0
- data/lib/git-logs/git.log +0 -0
- data/lib/parser/adapters/option_parser.rb +70 -0
- data/lib/parser/adapters/thor.rb +555 -0
- data/lib/parser/adapters/thor/common_option_defs.rb +40 -0
- data/lib/require_first.rb +104 -0
- data/lib/search_hash.rb +44 -0
- data/lib/shell.rb +261 -0
- data/lib/shell/context.rb +1065 -0
- data/lib/shell/context_aux.rb +46 -0
- data/lib/shell/domain/active_context.rb +186 -0
- data/lib/shell/domain/context_entity.rb +89 -0
- data/lib/shell/domain/context_params.rb +223 -0
- data/lib/shell/domain/override_tasks.rb +88 -0
- data/lib/shell/domain/shadow_entity.rb +76 -0
- data/lib/shell/header_shell.rb +44 -0
- data/lib/shell/help_monkey_patch.rb +283 -0
- data/lib/shell/interactive_wizard.rb +225 -0
- data/lib/shell/message_queue.rb +63 -0
- data/lib/shell/parse_monkey_patch.rb +39 -0
- data/lib/shell/status_monitor.rb +124 -0
- data/lib/task_status.rb +83 -0
- data/lib/task_status/refresh_mode.rb +77 -0
- data/lib/task_status/snapshot_mode.rb +28 -0
- data/lib/task_status/stream_mode.rb +48 -0
- data/lib/task_status/stream_mode/element.rb +101 -0
- data/lib/task_status/stream_mode/element/format.rb +101 -0
- data/lib/task_status/stream_mode/element/hierarchical_task.rb +100 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/result.rb +72 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/result/action.rb +93 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/result/components.rb +26 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/result/node_level.rb +26 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/steps.rb +34 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/steps/action.rb +53 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/steps/components.rb +53 -0
- data/lib/task_status/stream_mode/element/hierarchical_task/steps/node_level.rb +42 -0
- data/lib/task_status/stream_mode/element/no_results.rb +26 -0
- data/lib/task_status/stream_mode/element/render.rb +59 -0
- data/lib/task_status/stream_mode/element/stage.rb +84 -0
- data/lib/task_status/stream_mode/element/stage/render.rb +76 -0
- data/lib/task_status/stream_mode/element/task_end.rb +35 -0
- data/lib/task_status/stream_mode/element/task_start.rb +37 -0
- data/lib/util/common_util.rb +37 -0
- data/lib/util/console.rb +235 -0
- data/lib/util/dtk_puppet.rb +65 -0
- data/lib/util/module_util.rb +66 -0
- data/lib/util/os_util.rb +385 -0
- data/lib/util/permission_util.rb +31 -0
- data/lib/util/remote_dependency_util.rb +84 -0
- data/lib/util/ssh_util.rb +94 -0
- data/lib/view_processor.rb +129 -0
- data/lib/view_processor/augmented_simple_list.rb +44 -0
- data/lib/view_processor/hash_pretty_print.rb +123 -0
- data/lib/view_processor/simple_list.rb +156 -0
- data/lib/view_processor/table_print.rb +309 -0
- data/lib/violation.rb +86 -0
- data/lib/violation/attribute.rb +76 -0
- data/lib/violation/fix.rb +26 -0
- data/lib/violation/fix/result.rb +73 -0
- data/lib/violation/fix/result/error.rb +34 -0
- data/lib/violation/fix/set_attribute.rb +41 -0
- data/lib/violation/sub_classes.rb +60 -0
- data/puppet/manifests/init.pp +72 -0
- data/puppet/manifests/params.pp +16 -0
- data/puppet/r8meta.puppet.yml +35 -0
- data/puppet/templates/bash_profile.erb +2 -0
- data/puppet/templates/client.conf.erb +1 -0
- data/puppet/templates/dtkclient.erb +2 -0
- data/spec/component_module_spec.rb +34 -0
- data/spec/dependency_spec.rb +6 -0
- data/spec/dtk_shell_spec.rb +13 -0
- data/spec/dtk_spec.rb +33 -0
- data/spec/lib/spec_helper.rb +10 -0
- data/spec/lib/spec_thor.rb +108 -0
- data/spec/node_template_spec.rb +24 -0
- data/spec/project_spec.rb +6 -0
- data/spec/repo_spec.rb +7 -0
- data/spec/response_spec.rb +52 -0
- data/spec/service_module_spec.rb +38 -0
- data/spec/service_spec.rb +50 -0
- data/spec/state_change_spec.rb +7 -0
- data/spec/table_print_spec.rb +48 -0
- data/spec/target_spec.rb +57 -0
- data/spec/task_spec.rb +28 -0
- data/views/assembly/augmented_simple_list.rb +12 -0
- data/views/assembly_template/augmented_simple_list.rb +12 -0
- data/views/list_task/augmented_simple_list.rb +12 -0
- metadata +421 -0
data/lib/task_status.rb
ADDED
@@ -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
|