dtk-client 0.7.1.1 → 0.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. checksums.yaml +5 -13
  2. data/Gemfile +1 -1
  3. data/Gemfile_dev +1 -0
  4. data/bin/dtk-execute +1 -18
  5. data/dtk-client.gemspec +1 -1
  6. data/lib/client.rb +0 -5
  7. data/lib/command_helpers/git_repo.rb +43 -12
  8. data/lib/commands/common/thor/assembly_workspace.rb +3 -3
  9. data/lib/commands/common/thor/module.rb +81 -7
  10. data/lib/commands/common/thor/module/import.rb +14 -4
  11. data/lib/commands/common/thor/pull_from_remote.rb +2 -0
  12. data/lib/commands/common/thor/push_clone_changes.rb +1 -1
  13. data/lib/commands/common/thor/push_to_remote.rb +18 -4
  14. data/lib/commands/common/thor/remotes.rb +54 -0
  15. data/lib/commands/common/thor/{set_required_params.rb → set_required_attributes.rb} +1 -1
  16. data/lib/commands/thor/component.rb +2 -2
  17. data/lib/commands/thor/component_module.rb +56 -7
  18. data/lib/commands/thor/dtk.rb +7 -7
  19. data/lib/commands/thor/node.rb +4 -4
  20. data/lib/commands/thor/node_group.rb +4 -4
  21. data/lib/commands/thor/remotes.rb +32 -0
  22. data/lib/commands/thor/service.rb +9 -5
  23. data/lib/commands/thor/service_module.rb +41 -5
  24. data/lib/commands/thor/test_module.rb +43 -3
  25. data/lib/commands/thor/workspace.rb +8 -4
  26. data/lib/core.rb +3 -0
  27. data/lib/domain/git_adapter.rb +15 -8
  28. data/lib/domain/response.rb +39 -26
  29. data/lib/dtk-client/version.rb +1 -1
  30. data/lib/execute.rb +1 -1
  31. data/lib/execute/command/api_call/service.rb +1 -0
  32. data/lib/execute/script.rb +50 -0
  33. data/lib/execute/script/add_tenant.rb +91 -0
  34. data/lib/execute/script/add_tenant_without_router.rb +87 -0
  35. data/lib/shell/context.rb +15 -9
  36. data/lib/shell/domain/context_params.rb +2 -0
  37. data/lib/shell/help_monkey_patch.rb +4 -0
  38. data/lib/util/os_util.rb +2 -1
  39. metadata +27 -24
  40. data/lib/execute/examples.rb +0 -3
  41. data/lib/execute/examples/add_tenant.rb +0 -42
@@ -10,7 +10,7 @@ module DTK::Client
10
10
 
11
11
  def self.valid_children()
12
12
  # [:"component-template"]
13
- [:component]
13
+ [:component, :remotes]
14
14
  end
15
15
 
16
16
  # this includes children of children - has to be sorted by n-level access
@@ -20,6 +20,10 @@ module DTK::Client
20
20
  [:component]
21
21
  end
22
22
 
23
+ def self.multi_context_children()
24
+ [[:component], [:remotes], [:component, :remotes]]
25
+ end
26
+
23
27
  def self.valid_child?(name_of_sub_context)
24
28
  return TestModule.valid_children().include?(name_of_sub_context.to_sym)
25
29
  end
@@ -32,6 +36,19 @@ module DTK::Client
32
36
  return :test_module, "test_module/list", nil
33
37
  end
34
38
 
39
+ def self.override_allowed_methods()
40
+ return DTK::Shell::OverrideTasks.new(
41
+ {
42
+ :command_only => {
43
+ :remotes => [
44
+ ["push-remote", "push-remote [REMOTE-NAME] [--force]", "# Push local changes to remote git repository"],
45
+ ["list-remotes", "list-remotes", "# List git remotes for given module"],
46
+ ["add-remote", "add-remote REMOTE-NAME REMOTE-URL", "# Add git remote for given module"],
47
+ ["remove-remote", "remove-remote REPO-NAME [-y]", "# Remove git remote for given module"] ]
48
+ }
49
+ })
50
+ end
51
+
35
52
  desc "delete TEST-MODULE-NAME [-y] [-p]", "Delete test module and all items contained in it. Optional parameter [-p] is to delete local directory."
36
53
  method_option :force, :aliases => '-y', :type => :boolean, :default => false
37
54
  method_option :purge, :aliases => '-p', :type => :boolean, :default => false
@@ -202,7 +219,7 @@ module DTK::Client
202
219
  push_module_aux(context_params, internal_trigger)
203
220
  end
204
221
 
205
- desc "TEST-MODULE-NAME/ID push-dtkn [-n NAMESPACE]", "Push changes from local copy of test module to remote repository (dtkn)."
222
+ desc "TEST-MODULE-NAME/ID push-dtkn [-n NAMESPACE] [--force]", "Push changes from local copy of test module to remote repository (dtkn)."
206
223
  method_option "message",:aliases => "-m" ,
207
224
  :type => :string,
208
225
  :banner => "COMMIT-MSG",
@@ -212,7 +229,7 @@ module DTK::Client
212
229
  :banner => "NAMESPACE",
213
230
  :desc => "Remote namespace"
214
231
  #hidden option for dev
215
- method_option 'force-parse', :aliases => '-f', :type => :boolean, :default => false
232
+ method_option :force, :type => :boolean, :default => false, :aliases => '-f'
216
233
  def push_dtkn(context_params, internal_trigger=false)
217
234
  push_dtkn_module_aux(context_params, internal_trigger)
218
235
  end
@@ -225,6 +242,29 @@ module DTK::Client
225
242
  # list_diffs_module_aux(context_params)
226
243
  end
227
244
 
245
+ # REMOTE INTERACTION
246
+
247
+ desc "HIDE_FROM_BASE push-remote [REMOTE-NAME] [--force]", "Push local changes to remote git repository"
248
+ method_option :force, :type => :boolean, :default => false
249
+ def push_remote(context_params)
250
+ push_remote_module_aux(context_params)
251
+ end
252
+
253
+ desc "HIDE_FROM_BASE list-remotes", "List git remotes for given module"
254
+ def list_remotes(context_params)
255
+ remote_list_aux(context_params)
256
+ end
257
+
258
+ desc "HIDE_FROM_BASE add-remote REMOTE-NAME REMOTE-URL", "Add git remote for given module"
259
+ def add_remote(context_params)
260
+ remote_add_aux(context_params)
261
+ end
262
+
263
+ desc "HIDE_FROM_BASE remove-remote REPO-NAME [-y]", "Remove git remote for given module"
264
+ method_option :force, :aliases => '-y', :type => :boolean, :default => false
265
+ def remove_remote(context_params)
266
+ remote_remove_aux(context_params)
267
+ end
228
268
 
229
269
  #
230
270
  # DEVELOPMENT MODE METHODS
@@ -128,7 +128,8 @@ module DTK::Client
128
128
  ['list-components',"list-components","# List components."]
129
129
  ],
130
130
  :utils => [
131
- ['execute-tests',"execute-tests [--component COMPONENT-NAME] [--timeout TIMEOUT]","# Execute tests. --component filters execution per component, --timeout changes default execution timeout."],
131
+ # TODO: DTK-2027 might subsume by the dtk actions; currently server changes does not support this command
132
+ # ['execute-tests',"execute-tests [--component COMPONENT-NAME] [--timeout TIMEOUT]","# Execute tests. --component filters execution per component, --timeout changes default execution timeout."],
132
133
  ['get-netstats',"get-netstats","# Get netstats."],
133
134
  ['get-ps',"get-ps [--filter PATTERN]","# Get ps."],
134
135
  ['grep',"grep LOG-PATH NODE-ID-PATTERN GREP-PATTERN [--first]","# Grep log from multiple nodes. --first option returns first match (latest log entry)."],
@@ -382,6 +383,8 @@ module DTK::Client
382
383
  get_netstats_aux(context_params)
383
384
  end
384
385
 
386
+ =begin
387
+ # TODO: DTK-2027 might subsume by the dtk actions; currently server changes does not support this command
385
388
  # using HIDE_FROM_BASE to hide this command from base context (dtk:/workspace>)
386
389
  desc "HIDE_FROM_BASE execute-tests [--component COMPONENT-NAME] [--timeout TIMEOUT]", "Execute tests. --component filters execution per component, --timeout changes default execution timeout"
387
390
  method_option :component, :type => :string, :desc => "Component name"
@@ -389,6 +392,7 @@ module DTK::Client
389
392
  def execute_tests(context_params)
390
393
  execute_tests_aux(context_params)
391
394
  end
395
+ =end
392
396
 
393
397
  # using HIDE_FROM_BASE to hide this command from base context (dtk:/workspace>)
394
398
  desc "HIDE_FROM_BASE get-ps [--filter PATTERN]", "Get ps"
@@ -515,10 +519,10 @@ module DTK::Client
515
519
  set_attribute_aux(context_params)
516
520
  end
517
521
 
518
- desc "WORKSPACE-NAME/ID set-required-params", "Interactive dialog to set required params that are not currently set"
519
- def set_required_params(context_params)
522
+ desc "WORKSPACE-NAME/ID set-required-attributes", "Interactive dialog to set required attributes that are not currently set"
523
+ def set_required_attributes(context_params)
520
524
  workspace_id = context_params.retrieve_arguments([:workspace_id!],method_argument_names)
521
- set_required_params_aux(workspace_id,:assembly,:instance)
525
+ set_required_attributes_aux(workspace_id,:assembly,:instance)
522
526
  end
523
527
 
524
528
  # desc "WORKSPACE-NAME/ID start [NODE-ID-PATTERN]", "Starts all workspace's nodes, specific nodes can be selected via node id regex."
data/lib/core.rb CHANGED
@@ -7,9 +7,12 @@ require 'colorize'
7
7
  require 'json'
8
8
  require 'pp'
9
9
 
10
+ # Development Gems
10
11
  if ::DTK::Configuration.get(:development_mode)
11
12
  require 'ap'
13
+ require 'looksee'
12
14
  end
15
+
13
16
  #TODO: for testing; fix by pass in commadn line argument
14
17
  #RestClient.log = STDOUT
15
18
 
@@ -6,7 +6,14 @@ module DTK
6
6
  attr_accessor :git_repo
7
7
 
8
8
  def initialize(repo_dir, local_branch_name = nil)
9
- @git_repo = Git.init(repo_dir)
9
+
10
+ if DTK::Configuration.get(:debug_grit)
11
+ logger = Logger.new(STDOUT)
12
+ logger.level = Logger::INFO
13
+ @git_repo = Git.init(repo_dir, :log => logger)
14
+ else
15
+ @git_repo = Git.init(repo_dir)
16
+ end
10
17
  # If we want to log GIT interaction
11
18
  # @git_repo = Git.init(repo_dir, :log => Logger.new(STDOUT))
12
19
  @local_branch_name = local_branch_name
@@ -98,9 +105,9 @@ module DTK
98
105
  end
99
106
 
100
107
  def add_remote(name, url)
101
- unless is_there_remote?(name)
102
- @git_repo.add_remote(name, url)
103
- end
108
+ @git_repo.remove_remote(name) if is_there_remote?(name)
109
+
110
+ @git_repo.add_remote(name, url)
104
111
  end
105
112
 
106
113
  def fetch(remote = 'origin')
@@ -172,14 +179,14 @@ module DTK
172
179
  end
173
180
  end
174
181
 
175
- def push(remote_branch_ref)
182
+ def push(remote_branch_ref, opts={})
176
183
  remote, remote_branch = remote_branch_ref.split('/')
177
- push_with_remote(remote, remote_branch)
184
+ push_with_remote(remote, remote_branch, opts)
178
185
  end
179
186
 
180
- def push_with_remote(remote, remote_branch)
187
+ def push_with_remote(remote, remote_branch, opts={})
181
188
  branch_for_push = "#{local_branch_name}:refs/heads/#{remote_branch||local_branch_name}"
182
- @git_repo.push(remote, branch_for_push)
189
+ @git_repo.push(remote, branch_for_push, opts)
183
190
  end
184
191
 
185
192
  def add_file(file_rel_path, content)
@@ -1,6 +1,7 @@
1
- # This is wrapper for holding rest response information as well as
2
- # passing selection of ViewProcessor from Thor selection to render view
1
+ # This is wrapper for holding rest response information as well as
2
+ # passing selection of ViewProcessor from Thor selection to render view
3
3
  # selection
4
+ require 'git'
4
5
 
5
6
  module DTK
6
7
  module Client
@@ -17,16 +18,16 @@ module DTK
17
18
  end
18
19
 
19
20
  def initialize(command_class=nil,hash={})
20
- super(hash)
21
+ super(hash)
21
22
  @command_class = command_class
22
23
  @skip_render = false
23
24
  @print_error_table = false
24
25
  # default values
25
- @render_view = RenderView::AUG_SIMPLE_LIST
26
+ @render_view = RenderView::AUG_SIMPLE_LIST
26
27
  @render_data_type = nil
27
28
  end
28
29
 
29
- def clone_me()
30
+ def clone_me()
30
31
  return Marshal.load(Marshal.dump(self))
31
32
  end
32
33
 
@@ -34,21 +35,33 @@ module DTK
34
35
  begin
35
36
  results = (block ? yield : data)
36
37
  Ok.new(results)
37
- rescue ErrorUsage => e
38
- Error::Usage.new("message"=> e.to_s)
39
- rescue => e
40
- error_hash = {
41
- "message"=> e.message,
42
- "backtrace" => e.backtrace,
43
- "on_client" => true
44
- }
45
-
46
- if DTK::Configuration.get(:development_mode)
47
- DtkLogger.instance.error_pp("Error inside wrapper DEV ONLY: #{e.message}", e.backtrace)
38
+
39
+ rescue Git::GitExecuteError => e
40
+ if e.message.include?('Please make sure you have the correct access rights')
41
+ error_msg = "You do not have git access from this client, please add following SSH key in your git account: \n\n"
42
+ error_msg += SSHUtil.rsa_pub_key_content() + "\n"
43
+ raise DTK::Client::DtkError, error_msg
48
44
  end
45
+ handle_error_in_wrapper(e)
46
+ rescue ErrorUsage => e
47
+ Error::Usage.new("message"=> e.to_s)
48
+ rescue => e
49
+ handle_error_in_wrapper(e)
50
+ end
51
+ end
52
+
53
+ def self.handle_error_in_wrapper(exception)
54
+ error_hash = {
55
+ "message"=> exception.message,
56
+ "backtrace" => exception.backtrace,
57
+ "on_client" => true
58
+ }
49
59
 
50
- Error::Internal.new(error_hash)
60
+ if DTK::Configuration.get(:development_mode)
61
+ DtkLogger.instance.error_pp("Error inside wrapper DEV ONLY: #{exception.message}", exception.backtrace)
51
62
  end
63
+
64
+ Error::Internal.new(error_hash)
52
65
  end
53
66
 
54
67
  def get_label_for_column_name(column, type)
@@ -69,7 +82,7 @@ module DTK
69
82
  "target:" => "TARGET:"
70
83
  }
71
84
  end
72
-
85
+
73
86
  mappings[column]
74
87
  end
75
88
 
@@ -106,19 +119,19 @@ module DTK
106
119
 
107
120
  columns.each do |column|
108
121
  STDOUT << column
109
- end
122
+ end
110
123
  puts "\n"
111
124
  end
112
125
 
113
126
  def render_custom_info(type)
114
- puts "--- \n"
127
+ puts "--- \n"
115
128
 
116
129
  unless data.empty?
117
130
  data.each do |k,v|
118
131
  label = get_custom_labels(k, type)
119
132
  v = array_to_string(v) if v.is_a?(Array)
120
133
  STDOUT << " #{label} #{v}\n" if label
121
- end
134
+ end
122
135
  end
123
136
 
124
137
  puts "\n"
@@ -151,10 +164,10 @@ module DTK
151
164
  array_data.each do |a|
152
165
  info << "#{a.values.first},"
153
166
  end
154
-
167
+
155
168
  "#{info.gsub!(/,$/,'')}"
156
169
  end
157
-
170
+
158
171
 
159
172
  def render_data(print_error_table=false)
160
173
  unless @skip_render
@@ -174,7 +187,7 @@ module DTK
174
187
 
175
188
  # sending raw data from response
176
189
  rendered_data = ViewProcessor.render(@command_class, data, @render_view, @render_data_type, nil, @print_error_table)
177
-
190
+
178
191
  puts "\n" unless rendered_data
179
192
  return rendered_data
180
193
  else
@@ -230,14 +243,14 @@ module DTK
230
243
  def initialize(hash={})
231
244
  super(nil,{"errors" => [hash]})
232
245
  end
233
-
246
+
234
247
  class Usage < self
235
248
  def initialize(hash_or_string={})
236
249
  hash = (hash_or_string.kind_of?(String) ? {'message' => hash_or_string} : hash_or_string)
237
250
  super({"code" => "error"}.merge(hash))
238
251
  end
239
252
  end
240
-
253
+
241
254
  class Internal < self
242
255
  def initialize(hash={})
243
256
  super({"code" => "error"}.merge(hash).merge("internal" => true))
@@ -1,3 +1,3 @@
1
1
  module DtkClient
2
- VERSION="0.7.1.1"
2
+ VERSION="0.7.2"
3
3
  end
data/lib/execute.rb CHANGED
@@ -5,7 +5,7 @@ module DTK::Client
5
5
  dtk_require('execute/command')
6
6
  dtk_require('execute/command_processor')
7
7
  dtk_require('execute/execute_context')
8
- dtk_require('execute/examples')
8
+ dtk_require('execute/script')
9
9
 
10
10
  extend ExecuteContext::ClassMixin
11
11
  end
@@ -14,6 +14,7 @@ class DTK::Client::Execute
14
14
  :subtype => 'instance',
15
15
  :node_id => Required(:node),
16
16
  :component_template_id => Required(:component),
17
+ :namespace => Required(:namespace),
17
18
  :idempotent => Equal::OrDefault(true),
18
19
  :donot_update_workflow => Equal::OrDefault(false)
19
20
  }
@@ -0,0 +1,50 @@
1
+ class DTK::Client::Execute
2
+ class Script < self
3
+ dtk_require('script/add_tenant')
4
+ dtk_require('script/add_tenant_without_router')
5
+ def self.execute()
6
+ script_class().execute_script()
7
+ end
8
+
9
+ private
10
+ Scripts = {
11
+ 'add-tenant' => AddTenant,
12
+ 'add-tenant-without-router' => AddTenantWithoutRouter
13
+ }
14
+
15
+ def self.script_class()
16
+ script_name = ARGV.size > 0 && ARGV[0]
17
+ unless script_class = script_name && Scripts[script_name]
18
+ legal_scripts = Scripts.keys
19
+ err_msg = (script_name ? "Unsupported script '#{script_name}'" : "Missing script name")
20
+ err_msg << "; supported scripts are (#{legal_scripts.join(',')})"
21
+ raise ErrorUsage.new(err_msg)
22
+ end
23
+ script_class
24
+ end
25
+
26
+ def self.execute_script()
27
+ params = ret_params_from_argv()
28
+ execute_with_params(params)
29
+ end
30
+
31
+ module OptionParserHelper
32
+ require 'optparse'
33
+ def process_params_from_options(banner,&block)
34
+ OptionParser.new do |opts|
35
+ opts.banner = banner
36
+ block.call(opts)
37
+ end.parse!
38
+ end
39
+
40
+ def show_help_and_exit(banner)
41
+ ARGV[0] = '--help'
42
+ OptionParser.new do |opts|
43
+ opts.banner = banner
44
+ end.parse!
45
+ end
46
+ end
47
+ extend OptionParserHelper
48
+ end
49
+ end
50
+
@@ -0,0 +1,91 @@
1
+ class DTK::Client::Execute::Script
2
+ class AddTenant < self
3
+ def self.ret_params_from_argv()
4
+ banner = "Usage: dtk-execute add-tenant TENANT-NAME CATALOG-USERNAME -p PASSWORD [-s SERVICE-INSTANCE]"
5
+ tenant_name = catalog_username = tenant_number = nil
6
+ if ARGV.size > 2
7
+ tenant_name = ARGV[1]
8
+ if tenant_name =~ /^dtk([0-9]+)$/
9
+ tenant_number = $1
10
+ else
11
+ raise ErrorUsage.new("TENANT-NAME must be of form 'dtkNUMs', like dtk601")
12
+ end
13
+ catalog_username = ARGV[2]
14
+ else
15
+ show_help_and_exit(banner)
16
+ end
17
+
18
+ params = Hash.new
19
+ process_params_from_options(banner) do |opts|
20
+ opts.on( '-p', '--password PASSWORD', "Password for tenant and catalog" ) do |pw|
21
+ params[:password] = pw
22
+ end
23
+ opts.on( '-s', '--service SERVICE-INSTANCE', "Name of Service instance" ) do |s|
24
+ params[:service_instance] = s
25
+ end
26
+ end
27
+
28
+ # TODO: use opt parser to enforce that :password option is manditory
29
+ unless password = params[:password]
30
+ raise ErrorUsage.new("Password is mandatory; use -p commnd line option")
31
+ end
32
+ service_instance = params[:service_instance] || "dtkhost#{tenant_number[0]}"
33
+ to_add = {
34
+ :tenant_name => tenant_name,
35
+ :catalog_username => catalog_username,
36
+ :service_instance => service_instance
37
+ }
38
+ params.merge(to_add)
39
+ end
40
+
41
+ def self.execute_with_params(params)
42
+ tenant_name = params[:tenant_name]
43
+ catalog_username = params[:catalog_username]
44
+ service = params[:service_instance]
45
+ password = params[:password]
46
+ server_node = params[:server_node_name] || 'server'
47
+ router_node = params[:router_node_name] || 'router'
48
+
49
+ component_with_namespace = "dtk-meta-user:dtk_tenant[#{tenant_name}]"
50
+ component_namespace, component = (component_with_namespace =~ /(^[^:]+):(.+$)/; [$1,$2])
51
+
52
+ av_pairs = {
53
+ :catalog_username => catalog_username,
54
+ :tenant_password => password,
55
+ :catalog_password => password
56
+ }
57
+
58
+ ExecuteContext(:print_results => true) do
59
+ result = call 'service/add_component',
60
+ :service => service,
61
+ :node => server_node,
62
+ :component => component,
63
+ :namespace => component_namespace,
64
+ :donot_update_workflow => true
65
+
66
+ av_pairs.each_pair do |a,v|
67
+ result = call 'service/set_attribute',
68
+ :service => service,
69
+ :attribute_path => "#{server_node}/#{component}/#{a}",
70
+ :value => v
71
+ end
72
+
73
+ result = call 'service/link_components',
74
+ :service => service,
75
+ :input_component => "#{server_node}/#{component}",
76
+ :output_component => "#{server_node}/dtk_postgresql::databases"
77
+
78
+ result = call 'service/link_components',
79
+ :service => service,
80
+ :input_component => "#{server_node}/#{component}",
81
+ :output_component => "#{router_node}/dtk_nginx::vhosts_for_router"
82
+
83
+ result = call 'service/execute_workflow',
84
+ :service => service,
85
+ :workflow_name => 'add_tenant',
86
+ :workflow_params => {'name' => tenant_name}
87
+
88
+ end
89
+ end
90
+ end
91
+ end