dtk-client 0.9.1 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/Gemfile +1 -3
- data/README.md +2 -121
- data/Rakefile +44 -0
- data/bin/dtk +10 -88
- data/dtk-client.gemspec +21 -44
- data/examples/simple/dtk.module.yaml +32 -0
- data/{lib/git-logs/git.log → examples/simple/test/README.md} +0 -0
- data/examples/spark/dtk.module.yaml +120 -0
- data/examples/with_repo_content/deploy/puppet/manifests/hostname.pp +54 -0
- data/examples/with_repo_content/dtk.module.yaml +49 -0
- data/examples/with_repo_content/test/README.txt +0 -0
- data/features/dtk.feature +8 -0
- data/features/step_definitions/dtk_steps.rb +6 -0
- data/features/support/env.rb +15 -0
- data/lib/cli/command/mixin.rb +101 -0
- data/lib/cli/command/module/clone.rb +42 -0
- data/lib/cli/command/module/install.rb +52 -0
- data/lib/cli/command/module/list.rb +31 -0
- data/lib/cli/command/module/list_assemblies.rb +39 -0
- data/lib/cli/command/module/push.rb +34 -0
- data/lib/cli/command/module/uninstall.rb +46 -0
- data/lib/cli/command/module.rb +33 -0
- data/lib/cli/command/options.rb +33 -0
- data/lib/cli/command/service/cancel_task.rb +33 -0
- data/lib/cli/command/service/converge.rb +37 -0
- data/lib/{parser/adapters/thor/common_option_defs.rb → cli/command/service/create_workspace.rb} +13 -17
- data/lib/cli/command/service/destroy.rb +47 -0
- data/lib/cli/command/service/edit.rb +47 -0
- data/lib/cli/command/service/exec.rb +42 -0
- data/lib/cli/command/service/exec_sync.rb +53 -0
- data/lib/cli/command/service/list.rb +30 -0
- data/lib/cli/command/service/list_actions.rb +39 -0
- data/lib/cli/command/service/list_attributes.rb +44 -0
- data/lib/cli/command/service/list_component_links.rb +33 -0
- data/lib/cli/command/service/list_components.rb +39 -0
- data/lib/cli/command/service/list_dependent_modules.rb +33 -0
- data/lib/cli/command/service/list_nodes.rb +33 -0
- data/lib/cli/command/service/list_violations.rb +33 -0
- data/lib/cli/command/service/pull.rb +32 -0
- data/lib/cli/command/service/push.rb +37 -0
- data/lib/{shell/parse_monkey_patch.rb → cli/command/service/set_default_target.rb} +9 -17
- data/lib/cli/command/service/set_required_attributes.rb +32 -0
- data/lib/cli/command/service/ssh.rb +42 -0
- data/lib/cli/command/service/stage.rb +55 -0
- data/lib/cli/command/service/start.rb +33 -0
- data/lib/{shell/context_aux.rb → cli/command/service/stop.rb} +10 -23
- data/lib/cli/command/service/task_status.rb +39 -0
- data/lib/cli/command/service.rb +55 -0
- data/lib/{commands.rb → cli/command/subcommand.rb} +22 -25
- data/lib/{bundler_monkey_patch.rb → cli/command/token/arg.rb} +6 -6
- data/lib/cli/command/token/class_mixin.rb +96 -0
- data/lib/cli/command/token/flag.rb +42 -0
- data/lib/{execute/command/rest_call.rb → cli/command/token/mixin.rb} +23 -14
- data/lib/cli/command/token/switch.rb +35 -0
- data/lib/cli/command/token.rb +76 -0
- data/lib/cli/command.rb +46 -0
- data/lib/cli/context/attributes.rb +50 -0
- data/lib/cli/context/type/module.rb +34 -0
- data/lib/{commands/thor/state_change.rb → cli/context/type/service.rb} +11 -5
- data/lib/cli/context/type/top.rb +32 -0
- data/lib/cli/context/type.rb +42 -0
- data/lib/cli/context.rb +174 -0
- data/lib/cli/directory_parser/file_system.rb +105 -0
- data/lib/{execute/command.rb → cli/directory_parser.rb} +14 -17
- data/lib/{execute.rb → cli/file_obj.rb} +13 -9
- data/lib/cli/processor/plugin/gli.rb +70 -0
- data/lib/cli/processor.rb +60 -0
- data/lib/cli/runner/dtkn_access.rb +75 -0
- data/lib/cli/runner.rb +58 -0
- data/lib/cli/version.rb +8 -0
- data/lib/{config → client/config}/cacert.pem +0 -0
- data/lib/client/config/default.conf +20 -0
- data/lib/client/config.rb +106 -0
- data/lib/client/configurator.rb +182 -0
- data/lib/client/conn.rb +197 -0
- data/lib/client/content_generator.rb +127 -0
- data/lib/client/error/subclasses.rb +105 -0
- data/lib/client/error.rb +98 -0
- data/lib/client/git_repo/adapter/git_gem/error_handler.rb +70 -0
- data/lib/client/git_repo/adapter/git_gem.rb +179 -0
- data/lib/client/git_repo.rb +122 -0
- data/lib/client/logger.rb +136 -0
- data/lib/client/operation/account.rb +66 -0
- data/lib/client/operation/client_module_dir/git_repo.rb +286 -0
- data/lib/client/operation/client_module_dir.rb +138 -0
- data/lib/client/operation/module/clone_module.rb +52 -0
- data/lib/client/operation/module/install/common_module.rb +58 -0
- data/lib/client/operation/module/install/external_module.rb +122 -0
- data/lib/client/operation/module/install.rb +91 -0
- data/lib/client/operation/module/install_from_catalog.rb +76 -0
- data/lib/client/operation/module/list.rb +34 -0
- data/lib/client/operation/module/list_assemblies.rb +35 -0
- data/lib/client/operation/module/push.rb +62 -0
- data/lib/client/operation/module/uninstall.rb +44 -0
- data/lib/client/operation/module.rb +58 -0
- data/lib/{commands/common/thor/reparse.rb → client/operation/module_service_common.rb} +27 -16
- data/lib/client/operation/service/cancel_task.rb +29 -0
- data/lib/client/operation/service/commit_and_push.rb +128 -0
- data/lib/client/operation/service/converge.rb +50 -0
- data/lib/{util/common_util.rb → client/operation/service/create_workspace.rb} +13 -13
- data/lib/client/operation/service/destroy.rb +42 -0
- data/lib/client/operation/service/edit.rb +54 -0
- data/lib/client/operation/service/exec.rb +73 -0
- data/lib/client/operation/service/list.rb +32 -0
- data/lib/client/operation/service/list_actions.rb +34 -0
- data/lib/{commands/thor/dependency.rb → client/operation/service/list_attributes.rb} +16 -12
- data/lib/client/operation/service/list_component_links.rb +29 -0
- data/lib/{commands/common/thor/pull_clone_changes.rb → client/operation/service/list_components.rb} +13 -7
- data/lib/client/operation/service/list_dependent_modules.rb +29 -0
- data/lib/client/operation/service/list_nodes.rb +29 -0
- data/lib/{commands/thor/project.rb → client/operation/service/list_violations.rb} +8 -13
- data/lib/client/operation/service/pull.rb +37 -0
- data/lib/client/operation/service/set_default_target.rb +31 -0
- data/lib/client/operation/service/set_required_attributes.rb +41 -0
- data/lib/client/operation/service/ssh.rb +118 -0
- data/lib/client/operation/service/stage.rb +54 -0
- data/lib/client/operation/service/start.rb +29 -0
- data/lib/client/operation/service/stop.rb +30 -0
- data/lib/{task_status → client/operation/service/task_status}/refresh_mode.rb +15 -25
- data/lib/{task_status → client/operation/service/task_status}/snapshot_mode.rb +4 -5
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/format.rb +1 -1
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/result/action.rb +1 -1
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/result/components.rb +1 -1
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/result/node_level.rb +1 -1
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/result.rb +4 -4
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/steps/action.rb +1 -1
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/steps/components.rb +1 -1
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/steps/node_level.rb +1 -1
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/steps.rb +4 -4
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task.rb +3 -3
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/no_results.rb +1 -1
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/render.rb +1 -1
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/stage/render.rb +1 -1
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/stage.rb +3 -3
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/task_end.rb +1 -1
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/task_start.rb +1 -1
- data/lib/{task_status → client/operation/service/task_status}/stream_mode/element.rb +13 -13
- data/lib/{task_status → client/operation/service/task_status}/stream_mode.rb +5 -9
- data/lib/client/operation/service/task_status.rb +77 -0
- data/lib/client/operation/service.rb +54 -0
- data/lib/client/operation.rb +67 -0
- data/lib/client/operation_args.rb +40 -0
- data/lib/{execute/execute_context/result_store.rb → client/render/view/simple.rb} +15 -14
- data/lib/client/render/view/table/processor.rb +248 -0
- data/lib/client/render/view/table.rb +75 -0
- data/lib/client/render.rb +113 -0
- data/lib/client/response/error_handler.rb +97 -0
- data/lib/client/response/render_helper.rb +78 -0
- data/lib/client/response/subclasses.rb +62 -0
- data/lib/client/response.rb +83 -0
- data/lib/client/session.rb +62 -0
- data/lib/client/util/auxiliary.rb +34 -0
- data/lib/client/util/console.rb +81 -0
- data/lib/client/util/disk_cacher.rb +66 -0
- data/lib/client/util/dtk_path.rb +28 -0
- data/lib/{search_hash.rb → client/util/hash_with_optional_keys.rb} +29 -21
- data/lib/client/util/interactive_wizard.rb +84 -0
- data/lib/client/util/module_ref.rb +92 -0
- data/lib/client/util/os_util/print.rb +121 -0
- data/lib/client/util/os_util.rb +122 -0
- data/lib/{commands/thor/utils.rb → client/util/post_body.rb} +1 -1
- data/lib/{execute/error_usage.rb → client/util/query_string_hash.rb} +2 -2
- data/lib/client/util/remote_dependency.rb +67 -0
- data/lib/client/util/ssh_util.rb +89 -0
- data/lib/client/util/validation.rb +28 -0
- data/lib/client/util.rb +18 -0
- data/lib/{util/permission_util.rb → dtk_cli.rb} +10 -9
- data/lib/dtk_client.rb +18 -14
- data/test/default_test.rb +14 -0
- data/test/test_helper.rb +9 -0
- metadata +196 -307
- data/Gemfile_dev +0 -13
- data/bin/dtk-execute +0 -32
- data/bin/dtk-shell +0 -31
- data/lib/auxiliary.rb +0 -61
- data/lib/client.rb +0 -58
- data/lib/command_helper.rb +0 -33
- data/lib/command_helpers/git_repo/merge.rb +0 -153
- data/lib/command_helpers/git_repo.rb +0 -589
- data/lib/command_helpers/jenkins_client/config_xml.rb +0 -288
- data/lib/command_helpers/jenkins_client.rb +0 -106
- data/lib/command_helpers/service_importer.rb +0 -251
- data/lib/command_helpers/service_link.rb +0 -33
- data/lib/command_helpers/test_module_creator.rb +0 -69
- data/lib/command_helpers/test_module_templates/dtk.model.yaml.eruby +0 -10
- data/lib/command_helpers/test_module_templates/spec_helper.rb.eruby +0 -10
- data/lib/command_helpers/test_module_templates/temp_component_spec.rb.eruby +0 -5
- data/lib/commands/common/thor/access_control.rb +0 -133
- data/lib/commands/common/thor/action_result_handler.rb +0 -74
- data/lib/commands/common/thor/assembly_template.rb +0 -92
- data/lib/commands/common/thor/assembly_workspace.rb +0 -1638
- data/lib/commands/common/thor/base_command_helper.rb +0 -59
- data/lib/commands/common/thor/clone.rb +0 -82
- data/lib/commands/common/thor/common.rb +0 -88
- data/lib/commands/common/thor/common_base.rb +0 -49
- data/lib/commands/common/thor/create_target.rb +0 -70
- data/lib/commands/common/thor/edit.rb +0 -255
- data/lib/commands/common/thor/inventory_parser.rb +0 -98
- data/lib/commands/common/thor/list_diffs.rb +0 -128
- data/lib/commands/common/thor/module/import.rb +0 -215
- data/lib/commands/common/thor/module.rb +0 -1011
- data/lib/commands/common/thor/node.rb +0 -53
- data/lib/commands/common/thor/poller.rb +0 -65
- data/lib/commands/common/thor/pull_from_remote.rb +0 -152
- data/lib/commands/common/thor/puppet_forge.rb +0 -72
- data/lib/commands/common/thor/purge_clone.rb +0 -101
- data/lib/commands/common/thor/push_clone_changes.rb +0 -162
- data/lib/commands/common/thor/push_to_remote.rb +0 -94
- data/lib/commands/common/thor/remotes.rb +0 -71
- data/lib/commands/common/thor/set_required_attributes.rb +0 -46
- data/lib/commands/thor/account.rb +0 -239
- data/lib/commands/thor/assembly.rb +0 -361
- data/lib/commands/thor/attribute.rb +0 -79
- data/lib/commands/thor/component.rb +0 -70
- data/lib/commands/thor/component_module.rb +0 -501
- data/lib/commands/thor/component_template.rb +0 -174
- data/lib/commands/thor/developer.rb +0 -144
- data/lib/commands/thor/dtk.rb +0 -152
- data/lib/commands/thor/library.rb +0 -125
- data/lib/commands/thor/node.rb +0 -504
- data/lib/commands/thor/node_group.rb +0 -203
- data/lib/commands/thor/node_template.rb +0 -94
- data/lib/commands/thor/provider.rb +0 -233
- data/lib/commands/thor/remotes.rb +0 -49
- data/lib/commands/thor/service.rb +0 -932
- data/lib/commands/thor/service_module.rb +0 -900
- data/lib/commands/thor/target.rb +0 -250
- data/lib/commands/thor/task.rb +0 -116
- data/lib/commands/thor/test_module.rb +0 -310
- data/lib/commands/thor/workspace.rb +0 -698
- data/lib/config/client.conf.header +0 -20
- data/lib/config/configuration.rb +0 -99
- data/lib/config/default.conf +0 -16
- data/lib/config/disk_cacher.rb +0 -80
- data/lib/configurator.rb +0 -176
- data/lib/context_router.rb +0 -44
- data/lib/core.rb +0 -489
- data/lib/domain/git_adapter.rb +0 -412
- data/lib/domain/git_error_handler.rb +0 -64
- data/lib/domain/response/error_handler.rb +0 -86
- data/lib/domain/response.rb +0 -285
- data/lib/dtk-client/version.rb +0 -20
- data/lib/dtk_constants.rb +0 -40
- data/lib/dtk_error.rb +0 -114
- data/lib/dtk_logger.rb +0 -113
- data/lib/error.rb +0 -85
- data/lib/execute/cli_pure/cli_rerouter.rb +0 -102
- data/lib/execute/command/api_call/map.rb +0 -60
- data/lib/execute/command/api_call/service.rb +0 -91
- data/lib/execute/command/api_call/translation_term.rb +0 -119
- data/lib/execute/command/api_call.rb +0 -60
- data/lib/execute/command_processor/rest_call.rb +0 -59
- data/lib/execute/command_processor.rb +0 -30
- data/lib/execute/execute_context.rb +0 -86
- data/lib/execute/script/add_tenant.rb +0 -121
- data/lib/execute/script.rb +0 -64
- data/lib/parser/adapters/option_parser.rb +0 -70
- data/lib/parser/adapters/thor.rb +0 -555
- data/lib/require_first.rb +0 -104
- data/lib/shell/context.rb +0 -1064
- data/lib/shell/domain/active_context.rb +0 -186
- data/lib/shell/domain/context_entity.rb +0 -89
- data/lib/shell/domain/context_params.rb +0 -223
- data/lib/shell/domain/override_tasks.rb +0 -88
- data/lib/shell/domain/shadow_entity.rb +0 -76
- data/lib/shell/header_shell.rb +0 -44
- data/lib/shell/help_monkey_patch.rb +0 -283
- data/lib/shell/interactive_wizard.rb +0 -256
- data/lib/shell/message_queue.rb +0 -63
- data/lib/shell/status_monitor.rb +0 -124
- data/lib/shell.rb +0 -261
- data/lib/task_status.rb +0 -83
- data/lib/util/console.rb +0 -235
- data/lib/util/dtk_puppet.rb +0 -65
- data/lib/util/module_util.rb +0 -66
- data/lib/util/os_util.rb +0 -385
- data/lib/util/remote_dependency_util.rb +0 -84
- data/lib/util/ssh_util.rb +0 -94
- data/lib/view_processor/augmented_simple_list.rb +0 -44
- data/lib/view_processor/hash_pretty_print.rb +0 -123
- data/lib/view_processor/simple_list.rb +0 -156
- data/lib/view_processor/table_print.rb +0 -309
- data/lib/view_processor.rb +0 -129
- data/puppet/manifests/init.pp +0 -72
- data/puppet/manifests/params.pp +0 -16
- data/puppet/r8meta.puppet.yml +0 -35
- data/puppet/templates/bash_profile.erb +0 -2
- data/puppet/templates/client.conf.erb +0 -1
- data/puppet/templates/dtkclient.erb +0 -2
- data/spec/component_module_spec.rb +0 -34
- data/spec/dependency_spec.rb +0 -6
- data/spec/dtk_shell_spec.rb +0 -13
- data/spec/dtk_spec.rb +0 -33
- data/spec/lib/spec_helper.rb +0 -10
- data/spec/lib/spec_thor.rb +0 -108
- data/spec/node_template_spec.rb +0 -24
- data/spec/project_spec.rb +0 -6
- data/spec/repo_spec.rb +0 -7
- data/spec/response_spec.rb +0 -52
- data/spec/service_module_spec.rb +0 -38
- data/spec/service_spec.rb +0 -50
- data/spec/state_change_spec.rb +0 -7
- data/spec/table_print_spec.rb +0 -48
- data/spec/target_spec.rb +0 -57
- data/spec/task_spec.rb +0 -28
- data/views/assembly/augmented_simple_list.rb +0 -12
- data/views/assembly_template/augmented_simple_list.rb +0 -12
- data/views/list_task/augmented_simple_list.rb +0 -12
@@ -17,21 +17,17 @@
|
|
17
17
|
#
|
18
18
|
require 'hirb'
|
19
19
|
module DTK::Client
|
20
|
-
class TaskStatus
|
20
|
+
class Operation::Service::TaskStatus
|
21
21
|
class StreamMode < self
|
22
|
-
|
22
|
+
require_relative('stream_mode/element')
|
23
23
|
|
24
24
|
def get_and_render(opts = {})
|
25
25
|
Element.get_and_render_task_start(self, opts)
|
26
26
|
Element.get_and_render_stages(self, {:wait => WaitWhenNoResults}.merge(opts))
|
27
|
-
|
27
|
+
return
|
28
28
|
end
|
29
29
|
|
30
|
-
WaitWhenNoResults = 5
|
31
|
-
# making this public for this class and its children
|
32
|
-
def post_call(*args)
|
33
|
-
super
|
34
|
-
end
|
30
|
+
WaitWhenNoResults = 5
|
35
31
|
|
36
32
|
private
|
37
33
|
|
@@ -39,7 +35,7 @@ module DTK::Client
|
|
39
35
|
# start_index: START_INDEX
|
40
36
|
# end_index: END_INDEX
|
41
37
|
# convention is start_position = 0 and end_position = 0 means top level task with start time
|
42
|
-
def
|
38
|
+
def self.query_string_hash(opts = {})
|
43
39
|
ret = super(opts)
|
44
40
|
ret.merge(:start_index => opts[:start_index], :end_index => opts[:end_index])
|
45
41
|
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 Operation::Service
|
20
|
+
class TaskStatus < self
|
21
|
+
require_relative('task_status/snapshot_mode')
|
22
|
+
require_relative('task_status/refresh_mode')
|
23
|
+
require_relative('task_status/stream_mode')
|
24
|
+
|
25
|
+
def initialize(mode, service_instance)
|
26
|
+
@mode = mode
|
27
|
+
@service_instance = service_instance
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.execute(args = Args.new)
|
31
|
+
wrap_operation(args) do |args|
|
32
|
+
service_instance = args.required(:service_instance)
|
33
|
+
task_status_mode = args[:mode]
|
34
|
+
|
35
|
+
if task_status_mode
|
36
|
+
task_status_with_mode(task_status_mode.to_sym, service_instance)
|
37
|
+
else
|
38
|
+
rest_call(service_instance).set_render_as_table!
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def rest_call(opts = {})
|
44
|
+
self.class.rest_call(@service_instance, opts)
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
LEGAL_MODES = [:refresh, :snapshot, :stream]
|
50
|
+
def self.task_status_with_mode(mode, service_instance, opts = {})
|
51
|
+
case mode
|
52
|
+
when :refresh
|
53
|
+
RefreshMode.new(mode, service_instance).task_status(opts)
|
54
|
+
when :snapshot
|
55
|
+
SnapshotMode.new(mode, service_instance).task_status(opts)
|
56
|
+
when :stream
|
57
|
+
StreamMode.new(mode, service_instance).get_and_render(opts)
|
58
|
+
else
|
59
|
+
raise Error::Usage.new("Illegal mode '#{mode}'; legal modes are: #{LEGAL_MODES.join(', ')}")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.rest_call(service_instance, opts = {})
|
64
|
+
rest_get("#{BaseRoute}/#{service_instance}/task_status", query_string_hash(opts))
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.query_string_hash(opts = {})
|
68
|
+
QueryStringHash.new(
|
69
|
+
:form? => opts[:form],
|
70
|
+
:wait_for? => opts[:wait_for],
|
71
|
+
:summarize_node_groups? => opts[:summarize]
|
72
|
+
)
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,54 @@
|
|
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 Operation
|
20
|
+
class Service < self
|
21
|
+
OPERATIONS = [
|
22
|
+
:commit_and_push,
|
23
|
+
:destroy,
|
24
|
+
:edit,
|
25
|
+
:pull,
|
26
|
+
:stage,
|
27
|
+
:converge,
|
28
|
+
:task_status,
|
29
|
+
:list,
|
30
|
+
:list_actions,
|
31
|
+
:list_attributes,
|
32
|
+
:list_component_links,
|
33
|
+
:list_dependent_modules,
|
34
|
+
:list_components,
|
35
|
+
:list_nodes,
|
36
|
+
:list_violations,
|
37
|
+
:start,
|
38
|
+
:stop,
|
39
|
+
:cancel_task,
|
40
|
+
:ssh,
|
41
|
+
:set_required_attributes,
|
42
|
+
:exec,
|
43
|
+
:set_default_target
|
44
|
+
# :create_workspace
|
45
|
+
]
|
46
|
+
OPERATIONS.each { |operation| require_relative("service/#{operation}") }
|
47
|
+
|
48
|
+
BaseRoute = 'services'
|
49
|
+
|
50
|
+
extend ModuleServiceCommon::ClassMixin
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,67 @@
|
|
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
|
+
# Abstract class that holds classes and methods for xecuting commands by
|
20
|
+
# make calls to server and performing client side operations
|
21
|
+
class Operation
|
22
|
+
|
23
|
+
require_relative('operation/module_service_common')
|
24
|
+
|
25
|
+
TYPES = [:account, :module, :service, :client_module_dir]
|
26
|
+
TYPES.each { |op_type| require_relative("operation/#{op_type}") }
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
# delegate rest calls to Session
|
31
|
+
def self.rest_post(route, post_body = {})
|
32
|
+
raise_error_if_notok_response do
|
33
|
+
Session.rest_post(route, post_body)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
def rest_post(route, post_body = {})
|
37
|
+
self.class.rest_post(route, post_body)
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.rest_get(route, query_string_hash = {})
|
41
|
+
raise_error_if_notok_response do
|
42
|
+
Session.rest_get(route, query_string_hash)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
def rest_get(route, query_string_hash = {})
|
46
|
+
self.class.rest_get(route, query_string_hash)
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.wrap_operation(args = Args.new, &block)
|
50
|
+
Response.wrap_as_response do
|
51
|
+
block.call(Args.convert(args))
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# This is used so can fail on not ok rest responses without needing to do explicit
|
56
|
+
# response.ok? checks in many places
|
57
|
+
def self.raise_error_if_notok_response(&block)
|
58
|
+
response = block.call
|
59
|
+
if response.ok?
|
60
|
+
response
|
61
|
+
else
|
62
|
+
raise Error::ServerNotOkResponse.new(response)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
@@ -0,0 +1,40 @@
|
|
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 Operation
|
20
|
+
class Args < ::Hash
|
21
|
+
def initialize(hash = {})
|
22
|
+
replace(hash)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.convert(ruby_hash_or_args)
|
26
|
+
ruby_hash_or_args.kind_of?(Args) ? ruby_hash_or_args : new(ruby_hash_or_args)
|
27
|
+
end
|
28
|
+
|
29
|
+
def required(key)
|
30
|
+
if has_key?(key)
|
31
|
+
self[key]
|
32
|
+
else
|
33
|
+
raise Error, "Args object missing the key '#{key}'"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
@@ -15,23 +15,24 @@
|
|
15
15
|
# See the License for the specific language governing permissions and
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
|
-
class DTK::Client::Execute
|
19
|
-
class ExecuteContext
|
20
|
-
class ResultStore < Hash
|
21
|
-
def store(result,result_index=nil)
|
22
|
-
self[result_index||Index.last] = result
|
23
|
-
end
|
24
18
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
19
|
+
require 'yaml'
|
20
|
+
module DTK::Client
|
21
|
+
class Render
|
22
|
+
class Simple < self
|
23
|
+
|
24
|
+
def render(data, _opts = {})
|
25
|
+
if data.kind_of?(Hash) or data.kind_of?(Array)
|
26
|
+
render_text(::DTK::DSL::YamlHelper.generate(data)) unless data.empty?
|
32
27
|
end
|
33
|
-
Last = :last
|
34
28
|
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def initialize(render_type, _opts = {})
|
33
|
+
super(render_type)
|
34
|
+
end
|
35
|
+
|
35
36
|
end
|
36
37
|
end
|
37
38
|
end
|
@@ -0,0 +1,248 @@
|
|
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
|
+
require 'ostruct'
|
20
|
+
require 'colorize'
|
21
|
+
require 'rest_client'
|
22
|
+
require 'json'
|
23
|
+
|
24
|
+
# we override String here to give power to our mutators defined in TableDefintions
|
25
|
+
class String
|
26
|
+
def get_date
|
27
|
+
DateTime.parse(self).strftime('%H:%M:%S %d/%m/%y') unless self.nil?
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
module DTK::Client
|
32
|
+
class Render::Table
|
33
|
+
class Processor
|
34
|
+
include Hirb::Console
|
35
|
+
|
36
|
+
# opts can have keys
|
37
|
+
# :print_error_table - Boolean (default: false)
|
38
|
+
def self.render(data, table_definition, opts = {})
|
39
|
+
new(table_definition).render(data, opts)
|
40
|
+
end
|
41
|
+
|
42
|
+
def initialize(table_definition)
|
43
|
+
@order_definition = table_definition.order_definition
|
44
|
+
@table_mapping = table_definition.mapping
|
45
|
+
@evaluated_data = []
|
46
|
+
@error_data = []
|
47
|
+
@action_data = []
|
48
|
+
end
|
49
|
+
private :initialize
|
50
|
+
|
51
|
+
|
52
|
+
def render(data, opts = {})
|
53
|
+
evaluate(data, opts)
|
54
|
+
print
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def evaluate(data, opts = {})
|
60
|
+
# very important since rest of the code expect array to be used
|
61
|
+
data = [data] unless data.kind_of?(Array)
|
62
|
+
|
63
|
+
print_error_table = opts[:print_error_table]
|
64
|
+
|
65
|
+
|
66
|
+
data.each do |data_element|
|
67
|
+
next if data_element['dtk_client_hidden']
|
68
|
+
structured_element = to_ostruct(data_element)
|
69
|
+
|
70
|
+
# we use array of OpenStruct to hold our evaluated values
|
71
|
+
evaluated_element = OpenStruct.new
|
72
|
+
error_element = OpenStruct.new
|
73
|
+
|
74
|
+
# based on mapping we set key = eval(value)
|
75
|
+
@table_mapping.each do |k, v|
|
76
|
+
begin
|
77
|
+
if print_error_table && k.include?('error')
|
78
|
+
error_message = value_of(structured_element, v)
|
79
|
+
|
80
|
+
# due to problems with space we have special way of handling error columns
|
81
|
+
# in such a way that those error will be specially printed later on
|
82
|
+
server_error = nil
|
83
|
+
|
84
|
+
# here we see if there was an error if not we will skip this
|
85
|
+
# if so we add it to @error_data
|
86
|
+
if error_message.empty?
|
87
|
+
# no error message just add it as regular element
|
88
|
+
evaluated_element.send("#{k}=",value_of(structured_element, v))
|
89
|
+
else
|
90
|
+
error_index = ""
|
91
|
+
error_type = value_of(structured_element,'errors.dtk_type') || ""
|
92
|
+
|
93
|
+
val = value_of(structured_element,'dtk_type')||''
|
94
|
+
# extract e.g. 3.1.1.1 from '3.1.1.1 action' etc.
|
95
|
+
error_index = "[ #{val.scan( /\d+[,.]?\d?[,.]?\d?[,.]?\d?[,.]?\d?/ ).first} ]"
|
96
|
+
|
97
|
+
# original table takes that index
|
98
|
+
evaluated_element.send("#{k}=", error_index)
|
99
|
+
# we set new error element
|
100
|
+
set_error_element!(error_element)
|
101
|
+
|
102
|
+
# add it with other
|
103
|
+
@error_data << error_element
|
104
|
+
end
|
105
|
+
else
|
106
|
+
evaluated_element.send("#{k}=", value_of(structured_element, v))
|
107
|
+
# eval "evaluated_element.#{k}=structured_element.#{v}"
|
108
|
+
end
|
109
|
+
rescue NoMethodError => e
|
110
|
+
unless e.message.include? "nil:NilClass"
|
111
|
+
# when chaining comands there are situations where more complex strcture
|
112
|
+
# e.g. external_ref.region will not be there. So we are handling that case
|
113
|
+
# make sure when in development to disable this TODO: better solution needed
|
114
|
+
raise Error, "Error with missing metadata occurred. There is a mistake in table metadata or unexpected data presented to table view."
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
@order_definition.delete('errors')
|
120
|
+
|
121
|
+
@evaluated_data << evaluated_element
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def set_error_element!(error_element)
|
126
|
+
error_element.id = error_index
|
127
|
+
case error_type
|
128
|
+
when 'user_error'
|
129
|
+
error_element.message = "[USER ERROR] #{error_message}"
|
130
|
+
when "test_error"
|
131
|
+
error_element.message = "[TEST ERROR] #{error_message}"
|
132
|
+
else
|
133
|
+
error_element.message = "[SERVER ERROR] #{error_message}"
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def print
|
138
|
+
filter_remove_underscore = Proc.new { |header| header.gsub('_',' ').upcase }
|
139
|
+
# hirb print out of our evaluated data in order defined
|
140
|
+
# Available options can be viewed here: http://tagaholic.me/hirb/doc/classes/Hirb/Helpers/Table.html#M000008
|
141
|
+
table(@evaluated_data,{:fields => @order_definition,:escape_special_chars => true, :resize => false, :vertical => false, :header_filter => filter_remove_underscore })
|
142
|
+
|
143
|
+
# in case there were error we print those errors
|
144
|
+
unless @error_data.empty?
|
145
|
+
printf "\nERRORS: \n\n"
|
146
|
+
@error_data.each do |error_row|
|
147
|
+
printf "%15s %s\n", error_row.id.colorize(:yellow), error_row.message.colorize(:red)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
unless @action_data.empty?
|
152
|
+
printf " \n"
|
153
|
+
#table(@error_data,{:fields => [ :id, :message ]})
|
154
|
+
printed = []
|
155
|
+
@action_data.each do |action_row|
|
156
|
+
message = action_row.message
|
157
|
+
printf "%15s %s\n", "INFO:".colorize(:yellow), message.colorize(:yellow) unless printed.include?(message)
|
158
|
+
printed << message
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
|
164
|
+
def to_ostruct(data)
|
165
|
+
result = data.inject({}) do |res, (k, v)|
|
166
|
+
k = safe_name(k)
|
167
|
+
case v
|
168
|
+
when Hash
|
169
|
+
res.store(k, to_ostruct(v))
|
170
|
+
res
|
171
|
+
when Array
|
172
|
+
res.store(k, v.each { |el| Hash === el ? to_ostruct(el) : el })
|
173
|
+
res
|
174
|
+
else
|
175
|
+
res.store(k,v)
|
176
|
+
res
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
OpenStruct.new(result)
|
181
|
+
end
|
182
|
+
|
183
|
+
def safe_name(identifier)
|
184
|
+
(identifier == 'id' || identifier == 'type') ? "dtk_#{identifier}" : identifier
|
185
|
+
end
|
186
|
+
|
187
|
+
def filter_remove_underscore(_field)
|
188
|
+
nil
|
189
|
+
end
|
190
|
+
|
191
|
+
# based on string sequence in mapped_command we are executing list of commands to follow
|
192
|
+
# so for value of "foo.bar.split('.').last" we will get 4 commands that will
|
193
|
+
# sequentaly be executed using values from previus results
|
194
|
+
def value_of(open_struct_object, mapped_command)
|
195
|
+
# split string by '.' delimiter keeping in mind to split when words only
|
196
|
+
commands = mapped_command.split(/\.(?=\w)/)
|
197
|
+
|
198
|
+
value = open_struct_object
|
199
|
+
commands.each do |command|
|
200
|
+
value = evaluate_command(value, command)
|
201
|
+
end
|
202
|
+
value
|
203
|
+
end
|
204
|
+
|
205
|
+
def evaluate_command(value, command)
|
206
|
+
case
|
207
|
+
when command.include?('map{')
|
208
|
+
matched_data = command.match(/\['(.+)'\]/)
|
209
|
+
|
210
|
+
my_lambda = lambda{|_x| _x.map{|r|r["#{matched_data[1]}"]||[]}}
|
211
|
+
value = my_lambda.call(value)
|
212
|
+
|
213
|
+
raise Error, "There is a mistake in table metadata: #{command.inspect}" if value.nil?
|
214
|
+
when command.include?('(')
|
215
|
+
# matches command and params e.g. split('.') => [1] split, [2] '.'
|
216
|
+
matched_data = command.match(/(.+)\((.+)\)/)
|
217
|
+
command, params = matched_data[1], matched_data[2]
|
218
|
+
value = value.send(command,params)
|
219
|
+
when command.include?('[')
|
220
|
+
# matches command such as first['foo']
|
221
|
+
matched_data = command.match(/(.+)\[(.+)\]/)
|
222
|
+
command, params = matched_data[1],matched_data[2]
|
223
|
+
|
224
|
+
value = evaluate_command(value,command)
|
225
|
+
value = value.send('[]',params)
|
226
|
+
when command.start_with?("list_")
|
227
|
+
matched_data = command.match(/list_(.+)/)
|
228
|
+
|
229
|
+
my_lambda = lambda{|_x| _x.map{|r|r["#{matched_data[1]}"]||[]}}
|
230
|
+
value = my_lambda.call(value)
|
231
|
+
|
232
|
+
raise Error, "There is a mistake in table metadata: #{command.inspect}" if value.nil?
|
233
|
+
when command.start_with?("count_")
|
234
|
+
matched_data = command.match(/count_(.+)/)
|
235
|
+
|
236
|
+
my_lambda = lambda{|_x| _x.map{|r|r["#{matched_data[1]}"]||[]}.flatten.size}
|
237
|
+
value = my_lambda.call(value)
|
238
|
+
|
239
|
+
raise Error, "There is a mistake in table metadata: #{command.inspect}" if value.nil?
|
240
|
+
else
|
241
|
+
value = value.send(command)
|
242
|
+
end
|
243
|
+
value
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
@@ -0,0 +1,75 @@
|
|
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
|
+
|
19
|
+
module DTK::Client
|
20
|
+
class Render
|
21
|
+
class Table < self
|
22
|
+
require_relative('table/processor')
|
23
|
+
|
24
|
+
# opts can have keys
|
25
|
+
# :semantic_datatype (required)
|
26
|
+
def initialize(render_type, opts = {})
|
27
|
+
unless semantic_datatype = opts[:semantic_datatype]
|
28
|
+
raise Error, 'Missing opts[:semantic_datatype] value'
|
29
|
+
end
|
30
|
+
super(render_type, semantic_datatype)
|
31
|
+
@table_definition = get_table_definition?(semantic_datatype)
|
32
|
+
end
|
33
|
+
|
34
|
+
# opts can have keys
|
35
|
+
# :print_error_table - Boolean (default: false)
|
36
|
+
# :table_definition - if set overrides the one associated with the object
|
37
|
+
def render(data, opts = {})
|
38
|
+
unless table_definition = opts[:table_definition] || @table_definition
|
39
|
+
raise Error, 'Missing table definition'
|
40
|
+
end
|
41
|
+
if data.empty?
|
42
|
+
render_text("Table is empty\n")
|
43
|
+
else
|
44
|
+
Processor.render(data, table_definition, opts)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
TableDefinition = Struct.new(:mapping, :order_definition)
|
51
|
+
def get_table_definition?(semantic_datatype)
|
52
|
+
if table_def_hash = (table_definitions || {})[table_def_index_from_semantic_datatype(semantic_datatype)]
|
53
|
+
TableDefinition.new(table_def_hash['mapping'], table_def_hash['order'])
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def table_def_index_from_semantic_datatype(semantic_datatype)
|
58
|
+
semantic_datatype.to_s
|
59
|
+
end
|
60
|
+
|
61
|
+
def table_definitions
|
62
|
+
# TODO: put back in caching after take into account :meta_table_ttl
|
63
|
+
# @@table_definitions_metadata ||= get_table_definitions_metadata
|
64
|
+
get_table_definitions
|
65
|
+
end
|
66
|
+
|
67
|
+
# get all table definitions from json file
|
68
|
+
def get_table_definitions
|
69
|
+
content = DiskCacher.new.fetch('table_metadata', Config[:meta_table_ttl])
|
70
|
+
raise Error, 'Table metadata is empty' if content.empty?
|
71
|
+
JSON.parse(content)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|