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/dtk_logger.rb
ADDED
@@ -0,0 +1,126 @@
|
|
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
|
+
# DtkLogger singleton to be used for logging.
|
20
|
+
#
|
21
|
+
require 'singleton'
|
22
|
+
require 'logger'
|
23
|
+
require 'colorize'
|
24
|
+
require 'pp'
|
25
|
+
|
26
|
+
require File.expand_path('./util/os_util', File.dirname(__FILE__))
|
27
|
+
|
28
|
+
class DtkLogger
|
29
|
+
|
30
|
+
#
|
31
|
+
LOG_FILE_NAME = 'client.log'
|
32
|
+
LOG_MB_SIZE = 2
|
33
|
+
LOG_NUMBER_OF_OLD_FILES = 10
|
34
|
+
DEVELOPMENT_MODE = DTK::Configuration.get(:development_mode)
|
35
|
+
|
36
|
+
include Singleton
|
37
|
+
|
38
|
+
def initialize
|
39
|
+
log_location_dir = DTK::Client::OsUtil.get_log_location()
|
40
|
+
begin
|
41
|
+
if File.directory?(log_location_dir)
|
42
|
+
file = File.open(file_path(), "a")
|
43
|
+
file.sync = true
|
44
|
+
@logger = Logger.new(file, LOG_NUMBER_OF_OLD_FILES, LOG_MB_SIZE * 1024000)
|
45
|
+
|
46
|
+
@logger.formatter = proc do |severity, datetime, progname, msg|
|
47
|
+
"[#{datetime}] #{severity} -- : #{msg}\n"
|
48
|
+
end
|
49
|
+
else
|
50
|
+
no_log_dir(log_location_dir)
|
51
|
+
end
|
52
|
+
rescue Errno::EACCES
|
53
|
+
no_log_permissions(log_location_dir)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def file_path()
|
58
|
+
"#{DTK::Client::OsUtil.get_log_location()}/#{LOG_FILE_NAME}"
|
59
|
+
end
|
60
|
+
|
61
|
+
LoggerMethods = [:debug, :info, :warn, :error, :fatal, :error_pp, :fatal_pp]
|
62
|
+
def self.method_missing(method, *args)
|
63
|
+
if LoggerMethods.include?(method)
|
64
|
+
instance.send(method, *args)
|
65
|
+
else
|
66
|
+
super(method, *args)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.respond_to?(method)
|
71
|
+
LoggerMethods.include?(method) or super(method)
|
72
|
+
end
|
73
|
+
|
74
|
+
def debug(log_text, sttdout_out=false)
|
75
|
+
puts log_text if sttdout_out || DEVELOPMENT_MODE
|
76
|
+
@logger.debug(log_text) if log_created?
|
77
|
+
end
|
78
|
+
|
79
|
+
def info(log_text, sttdout_out=false)
|
80
|
+
puts log_text if sttdout_out || DEVELOPMENT_MODE
|
81
|
+
@logger.info(log_text) if log_created?
|
82
|
+
end
|
83
|
+
|
84
|
+
def warn(log_text, sttdout_out=false)
|
85
|
+
DTK::Client::OsUtil.print(log_text, :yellow) if sttdout_out || DEVELOPMENT_MODE
|
86
|
+
@logger.warn(log_text) if log_created?
|
87
|
+
end
|
88
|
+
|
89
|
+
def error(log_text, sttdout_out=false)
|
90
|
+
DTK::Client::OsUtil.print(log_text, :red) if sttdout_out || DEVELOPMENT_MODE
|
91
|
+
@logger.error(log_text) if log_created?
|
92
|
+
end
|
93
|
+
|
94
|
+
def error_pp(message, backtrace, sttdout_out = true)
|
95
|
+
error(message, sttdout_out)
|
96
|
+
# we do not print this to STDOUT (will be overriden with DEVELOPMENT_MODE)s
|
97
|
+
error("#{message}\n" + PP.pp(backtrace, ""), false) if backtrace
|
98
|
+
end
|
99
|
+
|
100
|
+
def fatal_pp(message, backtrace, sttdout_out = true)
|
101
|
+
fatal(message, sttdout_out)
|
102
|
+
# we do not print this to STDOUT (will be overriden with DEVELOPMENT_MODE)
|
103
|
+
fatal("#{message}\n" + PP.pp(backtrace, ""), false) if backtrace
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
def fatal(log_text, sttdout_out=false)
|
108
|
+
puts log_text if sttdout_out || DEVELOPMENT_MODE
|
109
|
+
@logger.fatal(log_text) if log_created?
|
110
|
+
end
|
111
|
+
|
112
|
+
private
|
113
|
+
|
114
|
+
def log_created?
|
115
|
+
#no log found if @logger.nil?
|
116
|
+
return !@logger.nil?
|
117
|
+
end
|
118
|
+
|
119
|
+
def no_log_dir(dir)
|
120
|
+
puts "[WARNING] Log directory (#{dir}) does not exist; please add it manually or re-install DTK client."
|
121
|
+
end
|
122
|
+
|
123
|
+
def no_log_permissions(dir)
|
124
|
+
puts "[WARNING] User (#{DTK::Common::Aux.running_process_user()}) does not have permissions to create a log file in log directory (#{dir})"
|
125
|
+
end
|
126
|
+
end
|
data/lib/dtk_shell.rb
ADDED
@@ -0,0 +1,31 @@
|
|
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 File.expand_path('../client', __FILE__)
|
19
|
+
require File.expand_path('../configurator', __FILE__)
|
20
|
+
require File.expand_path('../parser/adapters/thor', __FILE__)
|
21
|
+
require File.expand_path('../shell/context', __FILE__)
|
22
|
+
require File.expand_path('../shell/domain/context_entity', __FILE__)
|
23
|
+
require File.expand_path('../shell/domain/active_context', __FILE__)
|
24
|
+
require File.expand_path('../shell/domain/context_params', __FILE__)
|
25
|
+
require File.expand_path('../shell/domain/override_tasks', __FILE__)
|
26
|
+
require File.expand_path('../shell/domain/shadow_entity', __FILE__)
|
27
|
+
require File.expand_path('../commands/thor/account', __FILE__)
|
28
|
+
require File.expand_path('../shell/parse_monkey_patch', __FILE__)
|
29
|
+
require File.expand_path('../shell/help_monkey_patch', __FILE__)
|
30
|
+
require File.expand_path('../execute/cli_pure/cli_rerouter', __FILE__)
|
31
|
+
require File.expand_path('../context_router', __FILE__)
|
data/lib/error.rb
ADDED
@@ -0,0 +1,85 @@
|
|
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
|
+
# Application expected errors will be handled trough DtkError. All else will be treaded
|
20
|
+
# as Internal Server error. Logs will be added to ~/dtk.log for developers to investigate
|
21
|
+
# issues more closely.
|
22
|
+
|
23
|
+
module DTK
|
24
|
+
module Client
|
25
|
+
class Error < NameError
|
26
|
+
end
|
27
|
+
|
28
|
+
# DtkError is child of Error; so order matters
|
29
|
+
require File.expand_path('dtk_error', File.dirname(__FILE__))
|
30
|
+
|
31
|
+
class DSLParsing < Error
|
32
|
+
def initialize(base_json_error,file_path=nil)
|
33
|
+
super(err_msg(base_json_error,file_path))
|
34
|
+
end
|
35
|
+
private
|
36
|
+
def err_msg(base_json_error,file_path=nil)
|
37
|
+
"#{base_json_error}: #{file_path}"
|
38
|
+
end
|
39
|
+
|
40
|
+
class JSONParsing < self
|
41
|
+
end
|
42
|
+
|
43
|
+
class YAMLParsing < self
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# class DtkValidationError < Error
|
48
|
+
|
49
|
+
# attr_accessor :skip_usage_info
|
50
|
+
|
51
|
+
# def initialize(msg, skip_usage_info = false)
|
52
|
+
# @skip_usage_info = skip_usage_info
|
53
|
+
# super(msg)
|
54
|
+
# end
|
55
|
+
# end
|
56
|
+
|
57
|
+
class DtkValidationError < Error
|
58
|
+
|
59
|
+
attr_accessor :display_usage_info
|
60
|
+
|
61
|
+
def initialize(msg, display_usage_info = false)
|
62
|
+
@display_usage_info = display_usage_info
|
63
|
+
super(msg)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# raise by developers to signal wrong usage of components
|
68
|
+
class DtkImplementationError < Error
|
69
|
+
end
|
70
|
+
|
71
|
+
class DtkLoginRequiredError < Error
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
module DTK
|
78
|
+
module Shell
|
79
|
+
class Error < DTK::Client::Error
|
80
|
+
end
|
81
|
+
|
82
|
+
class ExitSignal < DTK::Client::Error
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
data/lib/execute.rb
ADDED
@@ -0,0 +1,29 @@
|
|
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 Execute
|
20
|
+
# The order matters
|
21
|
+
dtk_require('execute/error_usage')
|
22
|
+
dtk_require('execute/command')
|
23
|
+
dtk_require('execute/command_processor')
|
24
|
+
dtk_require('execute/execute_context')
|
25
|
+
dtk_require('execute/script')
|
26
|
+
|
27
|
+
extend ExecuteContext::ClassMixin
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,102 @@
|
|
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
|
19
|
+
class CLIRerouter
|
20
|
+
|
21
|
+
ROUTER_DATA = {
|
22
|
+
:service_module => [
|
23
|
+
{ :regex => /service-module (?<service_module_id>[\w:\-]+) (?<method_name>stage) (?<assembly_id>[\w:\-]+) (?<instance_name>[\w:\-\.\:]+)/, :entity => 'assembly' },
|
24
|
+
{ :regex => /service-module (?<service_module_id>[\w:\-]+) (?<method_name>deploy) (?<assembly_id>[\w:\-]+) (?<instance_name>[\w:\-\.\:]+)/ }
|
25
|
+
],
|
26
|
+
:component_module => [
|
27
|
+
{ :regex => /component-module (?<component_module_id>[\w:\-]+) (?<method_name>clone)/ }
|
28
|
+
],
|
29
|
+
:service => [
|
30
|
+
{ :regex => /service (?<service_id>[\w:\-]+) (?<method_name>set-attribute) (?<name>[\w:\-\.\:]+) (?<value>[\w:\-\.\:]+)/ },
|
31
|
+
{ :regex => /service (?<service_id>[\w:\-]+) (?<method_name>converge)/ },
|
32
|
+
{ :regex => /service (?<method_name>delete-and-destroy) (?<instance_name>[\w:\-]+)/ }
|
33
|
+
]
|
34
|
+
}
|
35
|
+
|
36
|
+
def initialize(entity_name, args)
|
37
|
+
@cli_string = CLIRerouter.formulate_command_string(entity_name, args)
|
38
|
+
@entity_name = CLIRerouter.norm(entity_name)
|
39
|
+
|
40
|
+
ROUTER_DATA[@entity_name].each do |defintion|
|
41
|
+
if match = @cli_string.match(defintion[:regex])
|
42
|
+
@method_name = CLIRerouter.norm(match[:method_name])
|
43
|
+
|
44
|
+
# sometimes we need to override entity
|
45
|
+
@entity_name = defintion[:entity] if defintion[:entity]
|
46
|
+
|
47
|
+
# we need to filter out IDs
|
48
|
+
@entity_ids = match.names.collect { |k| k.to_s.end_with?('_id') ? { k => match[k] } : nil }.compact
|
49
|
+
|
50
|
+
if @entity_ids.empty?
|
51
|
+
# match 1 is method name, there is no id
|
52
|
+
@args = match[2, match.size]
|
53
|
+
else
|
54
|
+
# match 1, 2 are id and method name rest are args
|
55
|
+
@args = match[@entity_ids.size + 2, match.size]
|
56
|
+
end
|
57
|
+
|
58
|
+
break
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
@conn = ::DTK::Client::Session.get_connection()
|
63
|
+
exit if validate_connection(@conn)
|
64
|
+
end
|
65
|
+
|
66
|
+
def run
|
67
|
+
new_context_params = DTK::Shell::ContextParams.new
|
68
|
+
|
69
|
+
@entity_ids.each do |value_hash|
|
70
|
+
key = value_hash.keys.first
|
71
|
+
value = value_hash.values.first
|
72
|
+
entity_name_of_param = key.gsub('_id', '')
|
73
|
+
new_context_params.add_context_name_to_params(entity_name_of_param, entity_name_of_param, value)
|
74
|
+
end
|
75
|
+
|
76
|
+
new_context_params.method_arguments = @args
|
77
|
+
new_context_params.pure_cli_mode = true
|
78
|
+
DTK::Client::ContextRouter.routeTask(@entity_name, @method_name, new_context_params, @conn)
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.is_candidate?(entity_name, args)
|
82
|
+
cli = formulate_command_string(entity_name, args)
|
83
|
+
if definitions = ROUTER_DATA[norm(entity_name)]
|
84
|
+
is_match = definitions.find { |d| cli.match(d[:regex]) }
|
85
|
+
|
86
|
+
return true if is_match
|
87
|
+
end
|
88
|
+
|
89
|
+
return false
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
|
94
|
+
def self.norm(string_value)
|
95
|
+
return string_value ? string_value.gsub('-','_').to_sym : nil
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.formulate_command_string(entity_name, args)
|
99
|
+
"#{entity_name} #{args.join(' ')}".strip()
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -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
|
+
class DTK::Client::Execute
|
19
|
+
class Command
|
20
|
+
dtk_require('command/rest_call')
|
21
|
+
dtk_require('command/api_call')
|
22
|
+
|
23
|
+
attr_reader :result_var,:input_hash
|
24
|
+
def initialize(input_hash)
|
25
|
+
@input_hash = input_hash
|
26
|
+
@result_var = optional?(:result_var)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def required(key)
|
31
|
+
unless @input_hash.has_key?(key)
|
32
|
+
raise ErrorUsage.new("Missing required key '#{key}' in: #{@input_hash.inspect}")
|
33
|
+
end
|
34
|
+
@input_hash[key]
|
35
|
+
end
|
36
|
+
def optional?(key)
|
37
|
+
@input_hash[key]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,60 @@
|
|
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::Execute
|
19
|
+
class Command
|
20
|
+
class APICall < self
|
21
|
+
|
22
|
+
# order matters; having these defs before requires; plus order of these requires
|
23
|
+
def self.Required(key)
|
24
|
+
Required.new(key)
|
25
|
+
end
|
26
|
+
def self.PreviousResponse(response_key)
|
27
|
+
PreviousResponse.new(response_key)
|
28
|
+
end
|
29
|
+
dtk_require('api_call/translation_term')
|
30
|
+
dtk_require('api_call/map')
|
31
|
+
dtk_require('api_call/service')
|
32
|
+
|
33
|
+
|
34
|
+
# calss block where on one or more commands that achieve the api
|
35
|
+
def raw_executable_commands(&block)
|
36
|
+
method = required(:method).to_sym
|
37
|
+
case required(:object_type).to_sym
|
38
|
+
when :service
|
39
|
+
Service.raw_executable_commands(method,&block)
|
40
|
+
else
|
41
|
+
raise ErrorUsage.new("The object_type '#{object_type}' is not supported")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
def self.raw_executable_commands(method,&block)
|
47
|
+
if command_map = self::CommandMap[method]
|
48
|
+
array_form(command_map).each{|raw_command|block.call(raw_command)}
|
49
|
+
else
|
50
|
+
raise ErrorUsage.new("The method on '#{method}' on object type '#{object_type()}' is not supported")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.array_form(obj)
|
55
|
+
obj.kind_of?(Array) ? obj : [obj]
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|