dtk-client 0.10.0.1 → 0.10.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 27c7da3e73bf4e15f1588363817bf3d31cce7eaa
4
- data.tar.gz: 9b67c4994a0f8e4e4a2646fa18658f48d3c8a4f6
3
+ metadata.gz: f28cd5b72fe1b22b5ed1c1acf5d7994c70e147d5
4
+ data.tar.gz: 3ed5a5af32baa1a5d22e5a493bd4907b7636eef2
5
5
  SHA512:
6
- metadata.gz: ed1c406eec37ae5326c0ec53e022168b380f2cf0e95c91c49017726883a1a0058d1e86f14da84f707b375fec1a8a78fb9cc430c0e71bf43314e7ae321b286420
7
- data.tar.gz: d00b0993f3c444c435f0f1ddd1d4c7f23aeda34761fd689694ea087140902edc607b3390f2079edc396379d4a7f30b72adc8617253a20d570ca50b8ecc3e5df5
6
+ metadata.gz: 609335a109d58bfc74ffa0b0b5580b6474fdadea1d2691d7270420de7f60bb1bd26363c7e55cd77e0f2dbd854bc4c9939d0587360f314b77b45814809f9fae1a
7
+ data.tar.gz: 3f3446bd3d10709e48c19c12886fde17da89e16bf0dcaa866a582a525fe81bb411352da2475100ca54abe75705b02f886805f03546b6a3a6ec846bdad6d7e8ec
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  sftp-config*.json
3
3
  .remote-sync.json
4
4
  .tags
5
+ Gemfile.lock
data/Gemfile CHANGED
@@ -1,3 +1,2 @@
1
1
  source 'https://rubygems.org'
2
2
  gemspec
3
- gem 'dtk-dsl', :github => 'dtk/dtk-dsl'
data/dtk-client.gemspec CHANGED
@@ -24,5 +24,6 @@ Gem::Specification.new do |spec|
24
24
  spec.add_dependency 'git', '1.2.9'
25
25
  spec.add_dependency 'hirb', '0.7.3'
26
26
  spec.add_dependency 'mime-types', '~> 2.99.3'
27
+ spec.add_dependency 'dtk-dsl', '1.0.0'
27
28
 
28
29
  end
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  dsl_version: 1.0.0
3
3
  module: rich/simple
4
- version: 0.0.2
4
+ version: 0.0.1
5
5
  keywords: DTK-2554
6
6
  description: Tests for DTK-2554
7
7
  license: Apache 2.0
@@ -1,6 +1,5 @@
1
1
  ---
2
- dsl_version: 1.0.0
3
- module: rich/spark
2
+ module: test/spark
4
3
  keywords: spark, hdfs, zeppelin
5
4
  description: Spark cluster
6
5
  license: Apache 2.0
@@ -21,9 +21,7 @@ module DTK::Client
21
21
  module Module
22
22
  include Command::Mixin
23
23
 
24
- # TODO: removed push command until fixed by jira: DTK-2667
25
- # ALL_SUBCOMMANDS = ['install', 'list', 'list-assemblies', 'push', 'uninstall', 'clone']
26
- ALL_SUBCOMMANDS = ['install', 'list', 'list-assemblies', 'uninstall', 'clone']
24
+ ALL_SUBCOMMANDS = ['install', 'list', 'list-assemblies', 'push', 'uninstall', 'clone']
27
25
  command_def :desc => 'Subcommands for interacting with DTK modules'
28
26
  ALL_SUBCOMMANDS.each { |subcommand| require_relative("module/#{subcommand.gsub(/-/,'_')}") }
29
27
  end
data/lib/cli/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module DTK
2
2
  module Client
3
3
  module CLI
4
- VERSION = '0.10.0.1'
4
+ VERSION = '0.10.0.2'
5
5
  end
6
6
  end
7
7
  end
@@ -91,8 +91,8 @@ module DTK::Client
91
91
  content_hash = convert_file_content_to_hash(assembly)
92
92
  name = content_hash['name']
93
93
  assembly_content = content_hash['assembly']
94
- workflows = ret_workflows_hash(content_hash['workflow'])
95
-
94
+ workflows = ret_workflows_hash(content_hash)
95
+
96
96
  assembly_content.merge!('workflows' => workflows) if workflows
97
97
  assemblies.merge!(name => assembly_content)
98
98
  end
@@ -100,12 +100,15 @@ module DTK::Client
100
100
  assemblies.empty? ? nil : assemblies
101
101
  end
102
102
 
103
- def ret_workflows_hash(workflow)
104
- return if workflow.nil? || workflow.empty?
105
- workflow_name = workflow.delete('assembly_action')
106
- {
107
- workflow_name => workflow
108
- }
103
+ def ret_workflows_hash(content_hash)
104
+ if workflows = content_hash['workflow'] || content_hash['workflows']
105
+ # this is legacy workflow
106
+ if workflow_name = workflows.delete('assembly_action')
107
+ { workflow_name => workflows }
108
+ else
109
+ workflows
110
+ end
111
+ end
109
112
  end
110
113
 
111
114
  def ret_dependencies_hash
@@ -83,11 +83,16 @@ module DTK::Client
83
83
  end
84
84
  end
85
85
 
86
- def self.add_file(args)
86
+ def self.add_service_repo_file(args)
87
87
  wrap_operation(args) do |args|
88
- response_data_hash(:repo => Internal.add_file(args))
88
+ response_data_hash(:repo => Internal.add_service_repo_file(args))
89
+ end
90
+ end
91
+
92
+ def self.get_service_repo_file_content(args)
93
+ wrap_operation(args) do |args|
94
+ response_data_hash(:content => Internal.get_service_repo_file_content(args))
89
95
  end
90
-
91
96
  end
92
97
 
93
98
  def self.pull_from_service_repo(args)
@@ -283,33 +288,61 @@ module DTK::Client
283
288
  repo.pull(Dtkn::GIT_REMOTE, remote_branch)
284
289
  end
285
290
 
286
- def self.add_file(args)
287
- all_backup_file_paths = args.required(:backup_files).keys
288
- final_path = args.required(:final_path)
289
- if File.exists?(file_path = "#{final_path}/.gitignore")
290
- has_backup = false
291
- file = File.open(file_path, "r") do |f|
292
- f.each_line do |line|
293
- unless all_backup_file_paths.include?(line.strip)
294
- write = File.open(file_path, "a")
295
- write << line
296
- end
297
- end
298
- end
299
- else
300
- File.open(".gitignore", "w") do |f|
301
- all_backup_file_paths.each {|el| f.puts("#{el}\n")}
302
- end
291
+ def self.add_service_repo_file(args)
292
+ branch = args.required(:branch)
293
+ service_instance = args.required(:service_instance)
294
+ path = args.required(:path)
295
+ content = args.required(:content)
296
+ checkout_branch(service_instance, branch) do
297
+ File.open(qualified_path(service_instance, path), 'w') { |f| f.write(content) }
303
298
  end
304
- args[:backup_files].each_pair do |file_path, content|
305
- File.open("#{final_path}/#{file_path}", "w") {|f| f.write(content)}
306
- File.open("#{final_path}/dtk.service.yaml", "w") {|f| f.write(content)}
299
+ end
300
+
301
+ # returns content if file exists
302
+ def self.get_service_repo_file_content(args)
303
+ branch = args.required(:branch)
304
+ service_instance = args.required(:service_instance)
305
+ path = args.required(:path)
306
+ checkout_branch(service_instance, branch) do
307
+ qualified_path = qualified_path(service_instance, path)
308
+ if File.exists?(qualified_path)
309
+ File.open(qualified_path, 'r').read
310
+ end
307
311
  end
308
312
  end
309
313
 
310
314
  def self.git_repo
311
315
  ::DTK::Client::GitRepo
312
316
  end
317
+
318
+ private
319
+
320
+ # relative_path is relative to top-leel repo directory
321
+ def self.qualified_path(service_instance, relative_path)
322
+ repo_dir = ret_base_path(:service, service_instance)
323
+ "#{repo_dir}/#{relative_path}"
324
+ end
325
+
326
+ CHECKOUT_LOCK = Mutex.new
327
+ def self.checkout_branch(service_instance, branch, &body)
328
+ ret = nil
329
+ CHECKOUT_LOCK.synchronize do
330
+ repo = git_repo.new(ret_base_path(:service, service_instance), :branch => branch)
331
+ current_branch = repo.current_branch.name
332
+ if current_branch == branch
333
+ ret = yield
334
+ else
335
+ begin
336
+ repo.checkout(branch)
337
+ ret = yield
338
+ ensure
339
+ repo.checkout(current_branch)
340
+ end
341
+ end
342
+ end
343
+ ret
344
+ end
345
+
313
346
  end
314
347
  end
315
348
  end
@@ -23,7 +23,7 @@ module DTK::Client
23
23
  def self.install_dependent_modules(module_refs, opts = {})
24
24
  module_refs.each do |module_ref|
25
25
  if module_exists?(module_ref, { :type => :component_module })
26
- OsUtil.print("Using module '#{module_ref.namespace}:#{module_ref.module_name}'")
26
+ OsUtil.print("Using module '#{module_ref.namespace}:#{module_ref.module_name}'" + (module_ref.version.nil? ? "" : " version: #{module_ref.version} "))
27
27
  # If component module is imported, still check to see if it's dependencies are imported
28
28
  find_and_install_component_module_dependency(module_ref, opts.merge(:skip_if_no_remote => true))
29
29
  else
@@ -44,6 +44,11 @@ module DTK::Client
44
44
  )
45
45
  module_info = rest_get "#{BaseRoute}/remote_module_info", query_string_hash
46
46
 
47
+ # unless version is explicitly provided, use latest version instead of master
48
+ unless @version
49
+ @version = module_info.required(:latest_version)
50
+ end
51
+
47
52
  git_repo_args = {
48
53
  :repo_dir => target_repo_dir,
49
54
  :repo_url => module_info.required(:remote_repo_url),
@@ -31,9 +31,9 @@ module DTK::Client
31
31
  :namespace => module_ref.namespace,
32
32
  :version? => module_ref.version
33
33
  )
34
- ret = rest_post("#{BaseRoute}/delete", post_body)
34
+ rest_post("#{BaseRoute}/delete", post_body)
35
35
  OsUtil.print_info("DTK module '#{module_ref.print_form}' has been deleted successfully.")
36
- ret
36
+ nil
37
37
  end
38
38
  end
39
39
 
@@ -25,18 +25,24 @@ module DTK::Client
25
25
 
26
26
  response = rest_get("#{BaseRoute}/#{service_instance}/repo_info")
27
27
 
28
- push_args = {
28
+ repo_info_args = Args.new(
29
29
  :service_instance => service_instance,
30
30
  :commit_message => args[:commit_message] || default_commit_message(service_instance),
31
31
  :branch => response.required(:branch, :name),
32
32
  :repo_url => response.required(:repo, :url)
33
- }
33
+ )
34
34
 
35
- response = ClientModuleDir::GitRepo.commit_and_push_to_service_repo(push_args)
35
+ response = ClientModuleDir::GitRepo.commit_and_push_to_service_repo(repo_info_args)
36
36
  commit_sha = response.required(:head_sha)
37
37
 
38
38
  response = rest_post("#{BaseRoute}/#{service_instance}/update_from_repo", :commit_sha => commit_sha)
39
- process_response(response, :service_instance => service_instance, :args => push_args)
39
+ print_msgs_of_type(:error_msgs, response)
40
+ print_msgs_of_type(:warning_msgs, response)
41
+ print_msgs_of_type(:info_msgs, response)
42
+
43
+ ClientModuleDir::GitRepo.pull_from_service_repo(repo_info_args) if response.data(:repo_updated)
44
+ process_backup_files(repo_info_args, response.data(:backup_files))
45
+ process_semantic_diffs(response.data(:semantic_diffs))
40
46
  nil
41
47
  end
42
48
  end
@@ -51,36 +57,37 @@ module DTK::Client
51
57
  raise Error, "Need to write"
52
58
  end
53
59
 
54
- def self.process_response(response, opts = {})
55
- print_msgs_of_type(:error_msgs, response)
56
- print_msgs_of_type(:warning_msgs, response)
57
- print_msgs_of_type(:info_msgs, response)
58
60
 
59
- pull_repo_updates?(response, opts)
60
- process_backup_files(response, opts)
61
- process_semantic_diffs(response)
62
- end
61
+ def self.process_backup_files(repo_info_args, backup_files)
62
+ return if (backup_files || {}).empty?
63
+ backup_files.each_pair do |path, content|
64
+ ClientModuleDir::GitRepo.add_service_repo_file(repo_info_args.merge(:path => path, :content => content))
65
+ end
66
+
67
+ backup_file_paths = backup_files.keys
68
+ update_gitignore?(repo_info_args, backup_file_paths)
63
69
 
64
- def self.pull_repo_updates?(response, opts = {})
65
- ClientModuleDir::GitRepo.pull_from_service_repo(opts[:args]) if response.data(:repo_updated)
70
+ ClientModuleDir::GitRepo.commit_and_push_to_service_repo(repo_info_args)
66
71
  end
67
72
 
68
- # TODO: DTK-2663: This is fine for now, but in 0.10.1 want to move logic that writes files to be in
69
- # a new method we write in ClientModuleDir::GitRepo.add_file
70
- def self.process_backup_files(response, opts = {})
71
- backup_files = response.data(:backup_files) || {}
72
- return if backup_files.empty?
73
- service_instance_name = opts[:service_instance]
74
- final_path = "#{OsUtil.dtk_local_folder}/#{service_instance_name}"
75
-
76
- ClientModuleDir::GitRepo.add_file(:backup_files => backup_files, :final_path => final_path)
77
-
78
- response = ClientModuleDir::GitRepo.commit_and_push_to_service_repo(opts[:args])
73
+ GITIGNORE_REL_PATH = '.gitignore'
74
+ def self.update_gitignore?(repo_info_args, backup_file_paths)
75
+ response = ClientModuleDir::GitRepo.get_service_repo_file_content(repo_info_args.merge(:path => GITIGNORE_REL_PATH))
76
+ gitignore_content = response.data(:content) || ''
77
+ gitignore_files = gitignore_content.split("\n")
78
+ to_add = ''
79
+ backup_file_paths.each do |backup_file_path|
80
+ to_add << "#{backup_file_path}\n" unless gitignore_files.include?(backup_file_path)
81
+ end
82
+ unless to_add.empty?
83
+ gitignore_content << "\n" unless gitignore_content.empty? or gitignore_content[-1] == "\n"
84
+ gitignore_content << to_add
85
+ ClientModuleDir::GitRepo.add_service_repo_file(repo_info_args.merge(:path => GITIGNORE_REL_PATH, :content => gitignore_content))
86
+ end
79
87
  end
80
-
81
- def self.process_semantic_diffs(response)
82
- semantic_diffs = response.data(:semantic_diffs) || {}
83
- return if semantic_diffs.empty?
88
+
89
+ def self.process_semantic_diffs(semantic_diffs)
90
+ return if (semantic_diffs || {}).empty?
84
91
  # TODO: DTK-2663; cleanup so pretty printed'
85
92
  OsUtil.print_info("\nDiffs that were pushed:")
86
93
  # TODO: get rid of use of STDOUT
@@ -91,7 +98,7 @@ module DTK::Client
91
98
  PRINT_FN = {
92
99
  :info_msgs => lambda { |msg| OsUtil.print_info(msg) },
93
100
  :warning_msgs => lambda { |msg| OsUtil.print_warning(msg) },
94
- :error_msgs => lambda { |msg| OsUtil.print_error(msg) }
101
+ :error_msgs => lambda { |msg| OsUtil.print_error(msg) }
95
102
  }
96
103
  def self.print_msgs_of_type(msg_type, response)
97
104
  msgs = response.data(msg_type) || []
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.10.0.1
4
+ version: 0.10.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reactor8
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-20 00:00:00.000000000 Z
11
+ date: 2016-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dtk-common-core
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: 2.99.3
111
+ - !ruby/object:Gem::Dependency
112
+ name: dtk-dsl
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '='
116
+ - !ruby/object:Gem::Version
117
+ version: 1.0.0
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '='
123
+ - !ruby/object:Gem::Version
124
+ version: 1.0.0
111
125
  description: Command line tool to interact with a DTK Server and DTK Service Catalog.
112
126
  email: support@reactor8.com
113
127
  executables:
@@ -306,7 +320,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
306
320
  version: '0'
307
321
  requirements: []
308
322
  rubyforge_project:
309
- rubygems_version: 2.4.1
323
+ rubygems_version: 2.4.6
310
324
  signing_key:
311
325
  specification_version: 4
312
326
  summary: DTK CLI client for DTK server interaction.