dtk-client 0.6.4 → 0.6.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d46ddda1f2067a87c86d33e8ca4c9f5a296240a7
4
- data.tar.gz: 52dc5c9d3fdcd9bfcd7eb61187b0af43033d7ae2
3
+ metadata.gz: 2817e488bead21b5b89b2a858c54a2ba8572dfa2
4
+ data.tar.gz: 9e06efff1beb26514abb4816bb38bc0b90f23ddd
5
5
  SHA512:
6
- metadata.gz: 14b2a72db3ec12725521967a979e5645e5072212d73a84ad02159aef55d51c60591e5757ca8018ccbfc4e3113a414c4adb44fd24e7115b087545aec9d1389911
7
- data.tar.gz: 9f0d95dbbb042c5059eb375bb001451d60863c17b7860e00ef72d31270cc9074ee98bd82dbbbda5af6c7d7257f3b713f357410910d884f2484390693e0b07a6e
6
+ metadata.gz: f0f6936dc5618b38729e7cfa3dc46666c45c71e9a4671b6fbf22d566a257659168304bbb4d468e3583797660a4e1ea4b3a41629c741a849ca33ca31c50ae8832
7
+ data.tar.gz: aeb6cf7b75d37b1daed90920c070e4a553b50bdb77388eca585a10263803272ea8ce39d4b5a2764475396dbd124b802be9ed19b7d7d2711a3e40679761a50eaf
@@ -15,24 +15,54 @@ module DTK::Client
15
15
  "Module '#{name}' has errors:\n #{errors.to_s}\nYou can fix errors in the DSL by invoking the 'edit' command.\n"
16
16
  end
17
17
 
18
+ ##
19
+ # Method will trigger pull from dtkn for each existing module
20
+ #
21
+
22
+ def trigger_module_auto_pull(required_modules)
23
+ if !required_modules.empty? && Console.confirmation_prompt("Do you want to update in addition to this module its dependent modules from the catalog?")
24
+ required_modules.each do |r_module|
25
+ module_name = full_module_name(r_module)
26
+ module_type = r_module['type']
27
+
28
+ print "Pulling latest #{module_type.gsub('_',' ')} code for '#{module_name}' ... "
29
+
30
+ new_context_params = DTK::Shell::ContextParams.new
31
+ new_context_params.add_context_to_params(module_type, module_type)
32
+ new_context_params.add_context_name_to_params(module_type, module_type, module_name)
33
+ new_context_params.forward_options( { :skip_recursive_pull => true })
34
+
35
+ response = ContextRouter.routeTask(module_type, "pull_dtkn", new_context_params, @conn)
36
+
37
+ raise DTK::Client::DtkError, response.error_message unless response.ok?
38
+
39
+ # in case there are diffs there was no ouput so we add 'Done'
40
+ puts 'Done.' unless response.data[:diffs].empty?
41
+ end
42
+ end
43
+ end
44
+
45
+
18
46
  ##
19
47
  # Method will trigger import for each missing module component
20
48
  #
21
- def trigger_module_component_import(missing_component_list, required_components, opts={})
49
+ def trigger_module_auto_import(missing_modules, required_modules, opts={})
22
50
  puts "Auto-importing missing module(s)"
23
- modules_to_import = missing_component_list
51
+ modules_to_import = missing_modules
24
52
 
25
- required_components.each do |r_module|
26
- module_name = "#{r_module['namespace']}/#{r_module['name']}"
27
- module_name += "-#{r_module['version']}" if r_module['version']
53
+ # Print out installed modules
54
+ required_modules.each do |r_module|
55
+ module_name = full_module_name(r_module)
28
56
  module_type = r_module['type']
57
+
29
58
  print "Using #{module_type.gsub('_',' ')} '#{module_name}'\n"
30
59
  end
31
60
 
61
+ # Trigger import/install for missing modules
32
62
  modules_to_import.each do |m_module|
33
- module_name = "#{m_module['namespace']}/#{m_module['name']}"
34
- module_name += "-#{m_module['version']}" if m_module['version']
63
+ module_name = full_module_name(m_module)
35
64
  module_type = m_module['type']
65
+
36
66
  print "Importing #{module_type.gsub('_',' ')} '#{module_name}' ... "
37
67
  new_context_params = ::DTK::Shell::ContextParams.new([module_name])
38
68
  new_context_params.override_method_argument!('option_2', m_module['version'])
@@ -110,5 +140,11 @@ module DTK::Client
110
140
  (version ? "#{display_name}-#{version.strip}" : "#{display_name}")
111
141
  end
112
142
 
143
+ private
144
+
145
+ def full_module_name(module_hash)
146
+ ::DTK::Client::ModuleUtil.join_name(module_hash['name'], module_hash['namespace'])
147
+ end
148
+
113
149
  end
114
150
  end
@@ -63,7 +63,7 @@ module DTK::Client
63
63
  if service_module_name_x =~ /(^[^:]+):([^:]+$)/
64
64
  namespace,service_module_name = [$1,$2]
65
65
  end
66
- post_body.merge!(:service_module_name => service_module_name)
66
+ post_body.merge!(:service_module_name => service_module_name)
67
67
  end
68
68
 
69
69
  namespace ||= opts[:default_namespace]
@@ -503,7 +503,7 @@ module DTK::Client
503
503
 
504
504
  def info_aux(context_params)
505
505
  assembly_or_workspace_id, node_id, component_id, attribute_id = context_params.retrieve_arguments([REQ_ASSEMBLY_OR_WS_ID, :node_id, :component_id, :attribute_id],method_argument_names)
506
- is_json_return = context_params.get_forwarded_option(:json_return) || false
506
+ is_json_return = context_params.get_forwarded_options[:json_return] || false
507
507
 
508
508
  post_body = {
509
509
  :assembly_id => assembly_or_workspace_id,
@@ -645,7 +645,7 @@ module DTK::Client
645
645
  return unless Console.confirmation_prompt("Are you sure you want to delete and destroy all nodes in the workspace"+'?')
646
646
  end
647
647
 
648
- unsaved_modules = check_if_unsaved_changes(assembly_or_workspace_id)
648
+ unsaved_modules = check_if_unsaved_cmp_module_changes(assembly_or_workspace_id)
649
649
  unless unsaved_modules.empty?
650
650
  return unless Console.confirmation_prompt("Purging the workspace will cause unsaved changes in component module(s) '#{unsaved_modules.join(',')}' to be lost. Do you still want to proceed"+'?')
651
651
  end
@@ -354,7 +354,7 @@ module DTK::Client
354
354
  opts = {:do_not_raise=>true}
355
355
  module_opts = ignore_component_error ? opts.merge(:ignore_component_error => true) : opts.merge(:additional_message=>true)
356
356
 
357
- continue = trigger_module_component_import(missing_components, required_components, module_opts)
357
+ continue = trigger_module_auto_import(missing_components, required_components, module_opts)
358
358
  return unless continue
359
359
 
360
360
  puts "Resuming DTK Network import for #{module_type} '#{remote_module_name}' ..."
@@ -426,6 +426,7 @@ module DTK::Client
426
426
  catalog = 'dtkn'
427
427
  version = options["version"]
428
428
  module_type = get_module_type(context_params)
429
+ skip_recursive_pull = context_params.get_forwarded_options()[:skip_recursive_pull]
429
430
 
430
431
  raise DtkValidationError, "You have to provide valid catalog to pull changes from! Valid catalogs: #{PULL_CATALOGS}" unless catalog
431
432
 
@@ -433,15 +434,14 @@ module DTK::Client
433
434
 
434
435
  if catalog.to_s.eql?("dtkn")
435
436
  clone_aux(module_type.to_sym, module_id, version, true, true) unless File.directory?(module_location)
436
- opts = {:version => version, :remote_namespace => options.namespace}
437
+ opts = {:version => version, :remote_namespace => options.namespace, :skip_recursive_pull => skip_recursive_pull}
437
438
 
438
439
  response = pull_from_remote_aux(module_type.to_sym, module_id, opts)
439
440
  return response unless response.ok?
440
441
 
441
442
  push_clone_changes_aux(module_type.to_sym, module_id, version, nil, true) if File.directory?(module_location)
442
- Response::Ok.new()
443
- #elsif catalog.to_s.eql?("origin")
444
- #needs to be implemented
443
+ response.skip_render = true
444
+ response
445
445
  else
446
446
  raise DtkValidationError, "You have to provide valid catalog to pull changes from! Valid catalogs: #{PULL_CATALOGS}"
447
447
  end
@@ -23,9 +23,10 @@ module DTK::Client
23
23
  remote_params.merge!(:version => version) if version
24
24
 
25
25
  # check and import component module dependencies before importing service itself
26
- if (module_type == :service_module)
27
- import_module_component_dependencies(module_id,remote_namespace)
26
+ unless opts[:skip_recursive_pull]
27
+ import_module_component_dependencies(module_type, module_id,remote_namespace)
28
28
  end
29
+
29
30
  # check whether a local module exists to determine whether pull from local clone or try to pull from server
30
31
  if Helper(:git_repo).local_clone_dir_exists?(module_type,module_name,:full_module_name=>full_module_name,:version=>version)
31
32
  unless rsa_pub_key
@@ -44,40 +45,52 @@ module DTK::Client
44
45
  ##
45
46
  #
46
47
  # module_type: will be :component_module or :service_module
47
- def import_module_component_dependencies(module_id,remote_namespace=nil)
48
- post_body = PostBody.new(
49
- :service_module_id => module_id,
50
- :remote_namespace? => remote_namespace,
51
- :rsa_pub_key => SSHUtil.rsa_pub_key_content()
52
- )
53
- response = post(rest_url("service_module/resolve_pull_from_remote"),post_body)
48
+ def import_module_component_dependencies(module_type, module_id, remote_namespace=nil)
49
+ response = resolve_pull_from_remote_on_server(module_type, module_id, remote_namespace)
54
50
 
55
51
  print "Resolving dependencies please wait ... "
56
52
 
53
+ # install them all!
57
54
  if (response.ok? && !(missing_components = response.data(:missing_modules)).empty?)
58
55
  required_modules = response.data(:required_modules)
59
56
  puts " New dependencies found, Installing."
60
57
 
61
- module_opts = {:module_type => 'component-module'}
62
- trigger_module_component_import(missing_components, required_modules, module_opts)
58
+ trigger_module_auto_import(missing_components, required_modules, { :include_pull_action => true })
63
59
 
64
60
  puts "Resuming pull from remote ..."
65
61
  else
66
62
  puts 'Done.'
67
63
  end
68
64
 
65
+ # pull them all!
66
+ if (response.ok? && !(required_modules = response.data(:required_modules)).empty?)
67
+ trigger_module_auto_pull(required_modules)
68
+ end
69
+
69
70
  RemoteDependencyUtil.print_dependency_warnings(response)
70
71
  nil
71
72
  end
72
73
 
74
+ private
75
+
76
+ def resolve_pull_from_remote_on_server(module_type, module_id, remote_namespace=nil)
77
+ post_body = PostBody.new(
78
+ :module_id => module_id,
79
+ :remote_namespace? => remote_namespace,
80
+ :rsa_pub_key => SSHUtil.rsa_pub_key_content()
81
+ )
82
+ post(rest_url("#{module_type}/resolve_pull_from_remote"),post_body)
83
+ end
84
+
73
85
  module PullFromRemote
74
86
  extend CommandBase
75
87
  def self.perform_locally(cmd_obj,module_type,module_id,module_name,remote_params)
76
88
  opts = remote_params
77
89
  response = cmd_obj.Helper(:git_repo).pull_changes(module_type,module_name,opts)
90
+
78
91
  # return response unless response.ok?
79
92
  if response.data[:diffs].empty?
80
- raise DtkError, "No changes to pull from remote"
93
+ puts "No changes to pull from remote."
81
94
  end
82
95
 
83
96
  return response
@@ -23,7 +23,7 @@ module DTK::Client
23
23
  response
24
24
  end
25
25
 
26
- def check_if_unsaved_changes(assembly_or_workspace_id, opts={})
26
+ def check_if_unsaved_cmp_module_changes(assembly_or_workspace_id, opts={})
27
27
  unsaved_modules = []
28
28
  post_body = {
29
29
  :assembly_id => assembly_or_workspace_id,
@@ -40,5 +40,42 @@ module DTK::Client
40
40
  unsaved_modules
41
41
  end
42
42
 
43
+ def check_if_unsaved_assembly_changes(assembly_or_workspace_id, assembly_name, opts={})
44
+ post_body = {
45
+ :assembly_id => assembly_or_workspace_id,
46
+ :module_type => 'service_module',
47
+ :modification_type => 'workflow'
48
+ }
49
+ response = post rest_url("assembly/prepare_for_edit_module"), post_body
50
+ return unless response.ok?
51
+ assembly_name,service_module_id,service_module_name,version,repo_url,branch,branch_head_sha,edit_file = response.data(:assembly_name,:module_id,:full_module_name,:version,:repo_url,:workspace_branch,:branch_head_sha,:edit_file)
52
+
53
+ edit_opts = {
54
+ :automatically_clone => true,
55
+ :assembly_module => {
56
+ :assembly_name => assembly_name,
57
+ :version => version
58
+ },
59
+ :workspace_branch_info => {
60
+ :repo_url => repo_url,
61
+ :branch => branch,
62
+ :module_name => service_module_name
63
+ },
64
+ :commit_sha => branch_head_sha,
65
+ :pull_if_needed => true,
66
+ :modification_type => :workflow,
67
+ :edit_file => edit_file
68
+ }
69
+
70
+ version = nil #TODO: version associated with assembly is passed in edit_opts, which is a little confusing
71
+ module_location = OsUtil.module_location(:service_module,service_module_name,version,edit_opts)
72
+ return unless File.directory?(module_location)
73
+
74
+ grit_adapter = Helper(:git_repo).create(module_location)
75
+ return unless grit_adapter.repo_exists?
76
+
77
+ grit_adapter.changed?
78
+ end
79
+
43
80
  end
44
81
  end
@@ -127,7 +127,11 @@ module DTK::Client
127
127
  DTK::Client::Configurator.add_current_user_to_direct_access() if response.ok?
128
128
  end
129
129
 
130
- nil
130
+ if response.ok? && !response.data(:registered_with_repoman)
131
+ OsUtil.print("Warning: We were not able to register your key with remote catalog!", :yellow)
132
+ end
133
+
134
+ response.ok? ? nil : response
131
135
  end
132
136
 
133
137
  desc "delete-ssh-key KEYPAIR-NAME ","Deletes the named ssh key from your user account"
@@ -537,11 +537,16 @@ TODO: will put in dot release and will rename to 'extend'
537
537
  return unless Console.confirmation_prompt("Are you sure you want to delete and destroy service '#{assembly_name}' and its nodes"+'?')
538
538
  end
539
539
 
540
- unsaved_modules = check_if_unsaved_changes(assembly_id)
540
+ unsaved_modules = check_if_unsaved_cmp_module_changes(assembly_id)
541
541
  unless unsaved_modules.empty?
542
542
  return unless Console.confirmation_prompt("Deleting this service will cause unsaved changes in component module(s) '#{unsaved_modules.join(',')}' to be lost. Do you still want to proceed"+'?')
543
543
  end
544
544
 
545
+ assembly_changed = check_if_unsaved_assembly_changes(assembly_id, assembly_name)
546
+ if assembly_changed == true
547
+ return unless Console.confirmation_prompt("You made some changes in assembly or it's workflow that will be lost if you delete this service. Do you still want to proceed"+'?')
548
+ end
549
+
545
550
  # purge local clone
546
551
  response = purge_clone_aux(:all,:assembly_module => {:assembly_name => assembly_name})
547
552
  return response unless response.ok?
@@ -1,3 +1,3 @@
1
1
  module DtkClient
2
- VERSION="0.6.4"
2
+ VERSION="0.6.6"
3
3
  end
data/lib/shell/domain.rb CHANGED
@@ -9,11 +9,15 @@ module DTK
9
9
  def initialize(override_method_arguments = [])
10
10
  @current_context = ActiveContext.new
11
11
  @method_arguments = override_method_arguments
12
- @thor_options = nil
12
+ @thor_options = Hash.new
13
13
  end
14
14
 
15
15
  def add_context_to_params(context_name, entity_name, context_value = nil)
16
- @current_context.push_new_context(context_name, entity_name, context_value)
16
+ @current_context.push_new_context(context_name, stand_name(entity_name), context_value)
17
+ end
18
+
19
+ def add_context_name_to_params(context_name, entity_name, context_value = nil)
20
+ @current_context.push_new_name_context(context_name, stand_name(entity_name), context_value)
17
21
  end
18
22
 
19
23
  def forward_options(options)
@@ -24,10 +28,6 @@ module DTK
24
28
  @thor_options
25
29
  end
26
30
 
27
- def get_forwarded_option(key)
28
- @thor_options ? @thor_options[key] : nil
29
- end
30
-
31
31
  def get_forwarded_thor_option(option_key)
32
32
  return @thor_options ? @thor_options[option_key] : nil
33
33
  end
@@ -112,10 +112,10 @@ module DTK
112
112
  break if element
113
113
  if context_name
114
114
  if alternative_key.to_s.include?(context_name.downcase)
115
- required = alternative_key.to_s.match(/.+!$/)
115
+ required = alternative_key.to_s.match(/.+!$/)
116
116
  selected_key = alternative_key
117
117
  end
118
- end
118
+ end
119
119
  end
120
120
  end
121
121
 
@@ -165,7 +165,7 @@ module DTK
165
165
  (matched ? matched[1].to_i - 1 : nil)
166
166
  end
167
167
 
168
- # based on map key binding e.g. assembly_id, assembly_name we will extrace value
168
+ # based on map key binding e.g. assembly_id, assembly_name we will extrace value
169
169
  # from our ActiveContext
170
170
  def check_context_for_element(key_mapping)
171
171
  split_info = split_info(key_mapping)
@@ -184,6 +184,15 @@ module DTK
184
184
  split_info[0].gsub(/_/,'-') # makes sure we are using entity names with '_'
185
185
  end
186
186
 
187
+ #
188
+ # Standardize context name since we are in domain treating :component_module as :'component-module'
189
+ # and need to be careful about these changes
190
+ #
191
+
192
+ def stand_name(name)
193
+ name.to_s.gsub('_','-').to_sym
194
+ end
195
+
187
196
  def split_info(key_mapping)
188
197
  key_mapping.to_s.split(/_([a-z]+!?$)/)
189
198
  end
@@ -198,9 +207,13 @@ module DTK
198
207
 
199
208
  SHELL_SEPARATOR = '/'
200
209
 
201
- def self.create_context(context_name, entity_name, context_value=nil)
210
+ def self.create_context(context_name, entity_name, context_value=nil, type_id=:id)
202
211
  if context_value
203
- return ContextEntity.create_identifier(context_name, entity_name, context_value)
212
+ if :id.eql?(type_id)
213
+ return ContextEntity.create_identifier(context_name, entity_name, context_value)
214
+ else
215
+ return ContextEntity.create_name_identifier(context_name, entity_name, context_value)
216
+ end
204
217
  else
205
218
  return ContextEntity.create_command(context_name, entity_name)
206
219
  end
@@ -235,6 +248,14 @@ module DTK
235
248
  return instance
236
249
  end
237
250
 
251
+ def self.create_name_identifier(name, entity_name, value)
252
+ instance = self.create_command(name,entity_name)
253
+ instance.name = value
254
+ instance.identifier = value
255
+ instance.alt_identifier = value
256
+ return instance
257
+ end
258
+
238
259
  def self.create_identifier(name, entity_name, value)
239
260
  instance = self.create_command(name,entity_name)
240
261
  instance.identifier = value
@@ -246,7 +267,7 @@ module DTK
246
267
 
247
268
  class ActiveContext
248
269
 
249
- # special case when we are not able to provide valid identifier but we are
270
+ # special case when we are not able to provide valid identifier but we are
250
271
  # using it as such
251
272
  NO_IDENTIFIER_PROVIDED = -1
252
273
 
@@ -266,6 +287,9 @@ module DTK
266
287
  def push_new_context(context_name, entity_name, context_value=nil)
267
288
  @context_list << ContextEntity.create_context(context_name, entity_name, context_value)
268
289
  end
290
+ def push_new_name_context(context_name, entity_name, context_value=nil)
291
+ @context_list << ContextEntity.create_context(context_name, entity_name, context_value, :name)
292
+ end
269
293
 
270
294
  def pop_context(n)
271
295
  return @context_list.pop(n)
@@ -301,7 +325,7 @@ module DTK
301
325
  return filtered_entities.collect { |e| e.entity.to_s }
302
326
  end
303
327
 
304
- # returns id to be used to retrive task list form the cache based on
328
+ # returns id to be used to retrive task list form the cache based on
305
329
  # current active context
306
330
  def get_task_cache_id()
307
331
  identifier = command_list().join('_')
@@ -447,7 +471,7 @@ module DTK
447
471
 
448
472
  # returns 2 arrays one for commands and next one for identifiers
449
473
  def get_all_tasks(child_name)
450
- command_o_tasks, identifier_o_tasks = [], []
474
+ command_o_tasks, identifier_o_tasks = [], []
451
475
  command_o_tasks = (self[:all][child_name]||[]) + (self[:command_only][child_name]||[])
452
476
  identifier_o_tasks = (self[:all][child_name]||[]) + (self[:identifier_only][child_name]||[])
453
477
  return command_o_tasks, identifier_o_tasks
@@ -463,6 +487,6 @@ module DTK
463
487
  @completed_tasks << child_name
464
488
  end
465
489
  end
466
-
490
+
467
491
  end
468
492
  end
data/lib/util/console.rb CHANGED
@@ -14,7 +14,9 @@ module DTK::Client
14
14
  include CommandBase
15
15
  include CommandHelperMixin
16
16
 
17
+ #
17
18
  # Display confirmation prompt and repeat message until expected answer is given
19
+ #
18
20
  def confirmation_prompt(message, add_options=true)
19
21
  # used to disable skip with ctrl+c
20
22
  trap("INT", "SIG_IGN")
@@ -58,7 +60,7 @@ module DTK::Client
58
60
  # remove loading animation
59
61
  print "\b\b\b\b\b\b\bRefreshing..."
60
62
  STDOUT.flush
61
- puts
63
+ puts
62
64
  end
63
65
 
64
66
 
@@ -67,7 +69,7 @@ module DTK::Client
67
69
  # path to desire directory from where unix shell can execute normaly.
68
70
  #
69
71
  def unix_shell(path,module_id,module_type,version=nil)
70
-
72
+
71
73
  dtk_shell_ac_proc = Readline.completion_proc
72
74
  dtk_shell_ac_append_char = Readline.completion_append_character
73
75
 
@@ -75,7 +77,7 @@ module DTK::Client
75
77
  puts "[NOTICE] Shell interaction is currenly not supported on Windows."
76
78
  return
77
79
  end
78
-
80
+
79
81
  begin
80
82
  # we need to change path like this since system call 'cd' is not supported
81
83
  initial_dir = Dir.pwd
@@ -102,7 +104,7 @@ module DTK::Client
102
104
  path = line.match(/^\//) ? line : "#{Dir.getwd()}/#{line}"
103
105
  # If filepat* with '*' at the end, match first directory and go in it, else try to change original input
104
106
  if path.match(/\*$/)
105
- dirs = Dir[path].select{|file| File.directory?(file)}
107
+ dirs = Dir[path].select{|file| File.directory?(file)}
106
108
  unless dirs.empty?
107
109
  Dir.chdir(dirs.first)
108
110
  next
@@ -16,7 +16,7 @@ module DTK
16
16
  warnings = response.data['dependency_warnings']
17
17
  if warnings && !warnings.empty?
18
18
  print_out "Following warnings have been detected for current module by Repo Manager:\n"
19
- warnings.each { |w| print_out(" - #{w}") }
19
+ warnings.each { |w| print_out(" - #{w['message']}") }
20
20
  puts
21
21
  are_there_warnings = true
22
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dtk-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rich PELAVIN
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-27 00:00:00.000000000 Z
11
+ date: 2014-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler