dtk-client 0.6.7 → 0.6.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/command_helpers/git_repo.rb +66 -5
- data/lib/commands/common/thor/assembly_workspace.rb +23 -7
- data/lib/commands/common/thor/clone.rb +4 -2
- data/lib/commands/common/thor/edit.rb +16 -15
- data/lib/commands/common/thor/list_diffs.rb +38 -12
- data/lib/commands/common/thor/module/import.rb +249 -0
- data/lib/commands/common/thor/module.rb +198 -60
- data/lib/commands/common/thor/pull_from_remote.rb +1 -1
- data/lib/commands/common/thor/puppet_forge.rb +51 -0
- data/lib/commands/common/thor/push_clone_changes.rb +52 -14
- data/lib/commands/common/thor/reparse.rb +4 -18
- data/lib/commands/common/thor/task_status.rb +8 -4
- data/lib/commands/thor/component_module.rb +12 -17
- data/lib/commands/thor/service.rb +5 -0
- data/lib/commands/thor/service_module.rb +7 -1
- data/lib/commands/thor/test_module.rb +3 -2
- data/lib/config/client.conf.header +1 -0
- data/lib/config/default.conf +1 -0
- data/lib/configurator.rb +1 -0
- data/lib/domain/git_adapter.rb +30 -13
- data/lib/dtk-client/version.rb +1 -1
- data/lib/util/module_util.rb +4 -0
- data/lib/util/os_util.rb +6 -0
- metadata +4 -2
@@ -1,5 +1,6 @@
|
|
1
1
|
dtk_require_common_commands('thor/clone')
|
2
2
|
dtk_require_common_commands('thor/list_diffs')
|
3
|
+
dtk_require_common_commands('thor/puppet_forge')
|
3
4
|
dtk_require_common_commands('thor/push_to_remote')
|
4
5
|
dtk_require_common_commands('thor/pull_from_remote')
|
5
6
|
dtk_require_common_commands('thor/push_clone_changes')
|
@@ -8,6 +9,7 @@ dtk_require_common_commands('thor/edit')
|
|
8
9
|
dtk_require_common_commands('thor/reparse')
|
9
10
|
dtk_require_common_commands('thor/purge_clone')
|
10
11
|
dtk_require_common_commands('thor/common')
|
12
|
+
|
11
13
|
dtk_require_from_base('configurator')
|
12
14
|
dtk_require_from_base('command_helpers/service_importer')
|
13
15
|
dtk_require_from_base('command_helpers/test_module_creator')
|
@@ -18,7 +20,41 @@ DEFAULT_COMMIT_MSG = "Initial commit."
|
|
18
20
|
PULL_CATALOGS = ["dtkn"]
|
19
21
|
|
20
22
|
module DTK::Client
|
23
|
+
class CommonModule
|
24
|
+
# TODO: For Aldin; looking to use nested file structure if helpers just relate to one file in common;
|
25
|
+
# example here is import which is helper for module.rb
|
26
|
+
dtk_require_common_commands('thor/module/import')
|
27
|
+
|
28
|
+
def initialize(command,context_params)
|
29
|
+
@command = command
|
30
|
+
@context_params = context_params
|
31
|
+
@options = command.options
|
32
|
+
end
|
33
|
+
|
34
|
+
def print_external_dependencies(external_dependencies, location)
|
35
|
+
ambiguous = external_dependencies["ambiguous"]||[]
|
36
|
+
amb_sorted = ambiguous.map { |k,v| "#{k.split('/').last} (#{v.join(', ')})" }
|
37
|
+
inconsistent = external_dependencies["inconsistent"]||[]
|
38
|
+
possibly_missing = external_dependencies["possibly_missing"]||[]
|
39
|
+
|
40
|
+
OsUtil.print("There are inconsistent module dependencies mentioned in #{location}: #{inconsistent.join(', ')}", :red) unless inconsistent.empty?
|
41
|
+
OsUtil.print("There are missing module dependencies mentioned in #{location}: #{possibly_missing.join(', ')}", :yellow) unless possibly_missing.empty?
|
42
|
+
OsUtil.print("There are ambiguous module dependencies mentioned in #{location}: '#{amb_sorted.join(', ')}'. One of the namespaces should be selected by editing the module_refs file", :yellow) if ambiguous && !ambiguous.empty?
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
# TODO: when we do this for other areas we can move these things up and use as common classes
|
47
|
+
# helpers
|
48
|
+
def retrieve_arguments(mapping, method_info = nil)
|
49
|
+
@context_params.retrieve_arguments(mapping, method_info||@command.method_argument_names)
|
50
|
+
end
|
51
|
+
def get_namespace_and_name(*args)
|
52
|
+
@command.get_namespace_and_name(*args)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
21
56
|
module ModuleMixin
|
57
|
+
include PuppetForgeMixin
|
22
58
|
include CloneMixin
|
23
59
|
include PushToRemoteMixin
|
24
60
|
include PullFromRemoteMixin
|
@@ -120,7 +156,7 @@ module DTK::Client
|
|
120
156
|
msg = "Module '#{module_name}' "
|
121
157
|
if version then msg << "version #{version} has been deleted"
|
122
158
|
else msg << "has been deleted"; end
|
123
|
-
OsUtil.print(msg
|
159
|
+
OsUtil.print(msg, :yellow)
|
124
160
|
end
|
125
161
|
|
126
162
|
Response::Ok.new()
|
@@ -146,15 +182,18 @@ module DTK::Client
|
|
146
182
|
post rest_url("attribute/set"), post_body
|
147
183
|
end
|
148
184
|
|
149
|
-
def push_module_aux(context_params, internal_trigger=false)
|
185
|
+
def push_module_aux(context_params, internal_trigger=false, opts={})
|
150
186
|
module_type = get_module_type(context_params)
|
151
187
|
module_id, module_name = context_params.retrieve_arguments([REQ_MODULE_ID, "#{module_type}_name".to_sym],method_argument_names)
|
152
188
|
version = options["version"]
|
153
189
|
|
154
190
|
module_location = OsUtil.module_location(module_type, module_name, version)
|
155
191
|
|
192
|
+
git_import = opts[:git_import]
|
193
|
+
opts.merge!(:update_from_includes => true, :force_parse => true) unless git_import
|
194
|
+
|
156
195
|
reparse_aux(module_location)
|
157
|
-
push_clone_changes_aux(module_type.to_sym, module_id, version, options["message"]||DEFAULT_COMMIT_MSG, internal_trigger)
|
196
|
+
push_clone_changes_aux(module_type.to_sym, module_id, version, options["message"]||DEFAULT_COMMIT_MSG, internal_trigger, opts)
|
158
197
|
end
|
159
198
|
|
160
199
|
def create_test_module_aux(context_params)
|
@@ -180,80 +219,114 @@ module DTK::Client
|
|
180
219
|
end
|
181
220
|
end
|
182
221
|
|
183
|
-
|
184
|
-
|
185
|
-
|
222
|
+
def import_git_module_aux(context_params)
|
223
|
+
# For Aldin
|
224
|
+
# This would now be one top level call
|
225
|
+
# uncomment this out to se simple example
|
226
|
+
# CommonModule::Import.new(self,context_params).from_git()
|
186
227
|
|
228
|
+
git_repo_url, module_name = context_params.retrieve_arguments([:option_1!, :option_2!], method_argument_names)
|
187
229
|
namespace, local_module_name = get_namespace_and_name(module_name, ModuleUtil::NAMESPACE_SEPERATOR)
|
188
230
|
|
189
|
-
|
231
|
+
module_type = get_module_type(context_params)
|
232
|
+
thor_options = { :git_import => true}
|
233
|
+
|
234
|
+
unless namespace
|
235
|
+
resp = post rest_url("namespace/default_namespace_name")
|
236
|
+
return resp unless resp.ok?
|
237
|
+
|
238
|
+
namespace = resp.data
|
239
|
+
thor_options[:default_namespace] = namespace
|
240
|
+
end
|
241
|
+
|
190
242
|
opts = {
|
191
243
|
:namespace => namespace,
|
192
|
-
:branch
|
244
|
+
:branch => options['branch']
|
193
245
|
}
|
194
246
|
response = Helper(:git_repo).create_clone_from_optional_branch(module_type.to_sym, local_module_name, git_repo_url, opts)
|
195
|
-
|
196
|
-
# Raise error if git repository is invalid
|
197
|
-
# raise DtkError,"Git repository URL '#{git_repo_url}' is invalid." unless response.ok?
|
198
247
|
return response unless response.ok?
|
199
248
|
|
200
249
|
# Remove .git directory to rid of git pointing to user's github
|
201
250
|
FileUtils.rm_rf("#{response['data']['module_directory']}/.git")
|
202
251
|
|
203
|
-
context_params.forward_options(
|
204
|
-
|
205
|
-
create_response = import(context_params)
|
252
|
+
context_params.forward_options(thor_options)
|
253
|
+
create_response = import_module_aux(context_params)
|
206
254
|
|
207
255
|
if create_response.ok?
|
208
256
|
if external_dependencies = create_response.data(:external_dependencies)
|
209
|
-
inconsistent = external_dependencies["inconsistent"]
|
210
|
-
possibly_missing = external_dependencies["possibly_missing"]
|
211
|
-
|
212
|
-
|
257
|
+
inconsistent = external_dependencies["inconsistent"]||[]
|
258
|
+
possibly_missing = external_dependencies["possibly_missing"]||[]
|
259
|
+
ambiguous = external_dependencies["ambiguous"]||[]
|
260
|
+
amb_sorted = ambiguous.map { |k,v| "#{k.split('/').last} (#{v.join(', ')})" }
|
261
|
+
OsUtil.print("There are inconsistent module dependencies mentioned in the git repo: #{inconsistent.join(', ')}", :red) unless inconsistent.empty?
|
262
|
+
OsUtil.print("There are missing module dependencies mentioned in the git repo: #{possibly_missing.join(', ')}", :yellow) unless possibly_missing.empty?
|
263
|
+
OsUtil.print("There are ambiguous module dependencies mentioned in the git repo: '#{amb_sorted.join(', ')}'. One of the namespaces should be selected by editing the module_refs file", :yellow) if ambiguous && !ambiguous.empty?
|
213
264
|
end
|
214
265
|
else
|
215
|
-
|
266
|
+
delete_dir = namespace.nil? ? local_module_name : "#{namespace}/#{local_module_name}"
|
267
|
+
full_module_name = create_response.data[:full_module_name]
|
268
|
+
local_module_name = full_module_name.nil? ? delete_dir : full_module_name
|
216
269
|
delete_module_sub_aux(context_params, local_module_name, :force_delete => true, :no_error_msg => true, :purge => true)
|
217
270
|
return create_response
|
218
271
|
end
|
219
272
|
|
220
273
|
Response::Ok.new()
|
221
274
|
end
|
222
|
-
|
223
275
|
def import_module_aux(context_params)
|
224
|
-
|
276
|
+
# CommonModule::Import.new(self,context_params).from_file()
|
277
|
+
if context_params.get_forwarded_options()
|
278
|
+
default_ns = context_params.get_forwarded_options()[:default_namespace]
|
279
|
+
git_import = context_params.get_forwarded_options()[:git_import]
|
280
|
+
end
|
281
|
+
|
225
282
|
name_option = git_import ? :option_2! : :option_1!
|
226
283
|
module_name = context_params.retrieve_arguments([name_option],method_argument_names)
|
227
284
|
module_type = get_module_type(context_params)
|
285
|
+
version = options["version"]
|
286
|
+
opts = {}
|
228
287
|
|
288
|
+
# extract namespace and module_name from full name (r8:maven will result in namespace = r8 & name = maven)
|
229
289
|
namespace, local_module_name = get_namespace_and_name(module_name, ModuleUtil::NAMESPACE_SEPERATOR)
|
290
|
+
namespace = default_ns if default_ns && namespace.nil?
|
291
|
+
|
230
292
|
# first check that there is a directory there and it is not already a git repo, and it ha appropriate content
|
231
293
|
response = Helper(:git_repo).check_local_dir_exists_with_content(module_type.to_sym, local_module_name, nil, namespace)
|
232
294
|
return response unless response.ok?
|
233
|
-
module_directory = response.data(:module_directory)
|
234
295
|
|
235
296
|
#check for yaml/json parsing errors before import
|
297
|
+
module_directory = response.data(:module_directory)
|
236
298
|
reparse_aux(module_directory)
|
237
299
|
|
238
300
|
# first make call to server to create an empty repo
|
239
|
-
|
301
|
+
post_body = {
|
302
|
+
:module_name => local_module_name,
|
303
|
+
:module_namespace => namespace
|
304
|
+
}
|
305
|
+
response = post(rest_url("#{module_type}/create"), post_body)
|
240
306
|
return response unless response.ok?
|
241
307
|
|
242
|
-
repo_url,repo_id,module_id,branch,new_module_name = response.data(:repo_url
|
308
|
+
repo_url,repo_id,module_id,branch,new_module_name = response.data(:repo_url, :repo_id, :module_id, :workspace_branch, :full_module_name)
|
243
309
|
response = Helper(:git_repo).rename_and_initialize_clone_and_push(module_type.to_sym, local_module_name, new_module_name, branch, repo_url, module_directory)
|
244
310
|
return response unless (response && response.ok?)
|
245
311
|
|
246
|
-
repo_obj,commit_sha = response.data(:repo_obj, :commit_sha)
|
247
|
-
module_final_dir
|
248
|
-
old_dir
|
312
|
+
repo_obj, commit_sha = response.data(:repo_obj, :commit_sha)
|
313
|
+
module_final_dir = repo_obj.repo_dir
|
314
|
+
old_dir = response.data[:old_dir]
|
249
315
|
|
250
316
|
post_body = {
|
251
|
-
:repo_id
|
252
|
-
"#{module_type}_id".to_sym => module_id,
|
317
|
+
:repo_id => repo_id,
|
253
318
|
:commit_sha => commit_sha,
|
254
|
-
:
|
319
|
+
:commit_dsl => true,
|
320
|
+
:scaffold_if_no_dsl => true,
|
321
|
+
"#{module_type}_id".to_sym => module_id
|
255
322
|
}
|
256
|
-
|
323
|
+
post_body.merge!(:git_import => true) if git_import
|
324
|
+
response = post(rest_url("#{module_type}/update_from_initial_create"), post_body)
|
325
|
+
|
326
|
+
if error = response.data(:dsl_parse_error)
|
327
|
+
dsl_parsed_message = ServiceImporter.error_message(module_name, error)
|
328
|
+
DTK::Client::OsUtil.print(dsl_parsed_message, :red)
|
329
|
+
end
|
257
330
|
|
258
331
|
unless response.ok?
|
259
332
|
response.set_data_hash({ :full_module_name => new_module_name })
|
@@ -264,43 +337,99 @@ module DTK::Client
|
|
264
337
|
return response
|
265
338
|
end
|
266
339
|
|
340
|
+
dsl_updated_info = response.data(:dsl_updated_info)
|
341
|
+
dsl_created_info = response.data(:dsl_created_info)
|
267
342
|
external_dependencies = response.data(:external_dependencies)
|
268
|
-
|
343
|
+
DTK::Client::OsUtil.print("A module_refs.yaml file has been created for you, located at #{module_final_dir}", :yellow) if dsl_updated_info && !dsl_updated_info.empty?
|
344
|
+
DTK::Client::OsUtil.print("A #{dsl_created_info["path"]} file has been created for you, located at #{module_final_dir}", :yellow) if dsl_created_info && !dsl_created_info.empty?
|
269
345
|
|
270
|
-
|
271
|
-
|
272
|
-
DTK::Client::OsUtil.print(msg,:yellow)
|
273
|
-
response = Helper(:git_repo).add_file(repo_obj, dsl_created_info["path"], dsl_created_info["content"], msg)
|
274
|
-
return response unless response.ok?
|
275
|
-
end
|
346
|
+
module_name, module_namespace, repo_url, branch, not_ok_response = workspace_branch_info(module_type, module_id, version)
|
347
|
+
return not_ok_response if not_ok_response
|
276
348
|
|
277
|
-
|
278
|
-
|
349
|
+
opts_pull = {
|
350
|
+
:local_branch => branch,
|
351
|
+
:namespace => module_namespace
|
352
|
+
}
|
279
353
|
|
280
|
-
#
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
354
|
+
# if import-git then always pull changes because files are created on server side
|
355
|
+
if git_import
|
356
|
+
resp = Helper(:git_repo).pull_changes(module_type, module_name, opts_pull)
|
357
|
+
return resp unless resp.ok?
|
358
|
+
response[:module_id] = module_id
|
359
|
+
else
|
360
|
+
# For Aldin; I think all code below this is just for import for file; so think we reorganize to have evrything above this be a common
|
361
|
+
# routine called by both; and then put in new method for 'import from file' that calss common , whcih passes back response
|
362
|
+
# and then calls the rest in the 'import from file' body
|
363
|
+
|
364
|
+
# since we are creating module_refs and dtk,,odel.yaml files on server need to pull
|
365
|
+
dsl_updated_info = response.data(:dsl_updated_info)
|
366
|
+
if dsl_updated_info and !dsl_updated_info.empty?
|
367
|
+
new_commit_sha = dsl_updated_info[:commit_sha]
|
368
|
+
unless new_commit_sha and new_commit_sha == commit_sha
|
369
|
+
resp = Helper(:git_repo).pull_changes(module_type, module_name, opts_pull)
|
370
|
+
return resp unless resp.ok?
|
371
|
+
end
|
372
|
+
end
|
285
373
|
|
286
|
-
|
287
|
-
#
|
374
|
+
# For Aldin; wil update the server side to have dsl_created_info not have content when that is added on server side
|
375
|
+
# so setting acondition wrt to this and casing on this, i.e., whether need to commit file and then do push
|
376
|
+
# after we make sure working we can remove code that commits dsl file on client side
|
377
|
+
push_needed = false
|
378
|
+
if dsl_created_info and !dsl_created_info.empty?
|
379
|
+
path = dsl_created_info["path"]
|
380
|
+
msg = "A #{path} file has been created for you, located at #{module_final_dir}"
|
381
|
+
if content = dsl_created_info["content"]
|
382
|
+
resp = Helper(:git_repo).add_file(repo_obj, path, content, msg)
|
383
|
+
return resp unless resp.ok?
|
384
|
+
push_needed = true
|
385
|
+
end
|
386
|
+
end
|
387
|
+
|
388
|
+
##### code that does push that can be removed once we always do commit of dsl on server side
|
389
|
+
if push_needed
|
390
|
+
if external_dependencies
|
391
|
+
ambiguous = external_dependencies['ambiguous']||[]
|
392
|
+
possibly_missing = external_dependencies["possibly_missing"]||[]
|
393
|
+
opts.merge!(:set_parsed_false => true, :skip_module_ref_update => true) unless ambiguous.empty? && possibly_missing.empty?
|
394
|
+
end
|
395
|
+
|
396
|
+
context_params.add_context_to_params(local_module_name, module_type.to_s.gsub!(/\_/,'-').to_sym, module_id)
|
397
|
+
response = push_module_aux(context_params, true, opts)
|
398
|
+
|
399
|
+
if error = response.data(:dsl_parse_error)
|
400
|
+
dsl_parsed_message = ServiceImporter.error_message(module_name, error)
|
401
|
+
DTK::Client::OsUtil.print(dsl_parsed_message, :red)
|
402
|
+
end
|
403
|
+
|
404
|
+
unless response.ok?
|
405
|
+
# remove new directory and leave the old one if import without namespace failed
|
406
|
+
if old_dir and (old_dir != module_final_dir)
|
407
|
+
FileUtils.rm_rf(module_final_dir) unless namespace
|
408
|
+
end
|
409
|
+
return response
|
410
|
+
end
|
411
|
+
end
|
412
|
+
##### end: code that does push
|
413
|
+
|
414
|
+
response = Response::Ok.new()
|
415
|
+
|
416
|
+
# remove source directory if no errors while importing
|
288
417
|
if old_dir and (old_dir != module_final_dir)
|
289
|
-
FileUtils.rm_rf(
|
418
|
+
FileUtils.rm_rf(old_dir) unless namespace
|
290
419
|
end
|
291
|
-
return response
|
292
|
-
end
|
293
420
|
|
294
|
-
|
295
|
-
|
296
|
-
FileUtils.rm_rf(old_dir) unless (namespace && git_import)
|
297
|
-
end
|
421
|
+
# For Aldin: need to also check to see if any parsing errors by looking at what is now in response under dsl_parse_error
|
422
|
+
# (it was just renamed from dsl_parse_info)
|
298
423
|
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
424
|
+
if external_dependencies
|
425
|
+
ambiguous = external_dependencies["ambiguous"]||[]
|
426
|
+
amb_sorted = ambiguous.map { |k,v| "#{k.split('/').last} (#{v.join(', ')})" }
|
427
|
+
possibly_missing = external_dependencies["possibly_missing"]||[]
|
428
|
+
OsUtil.print("There are missing module dependencies in dtk.model.yaml includes: #{possibly_missing.join(', ')}", :yellow) unless possibly_missing.empty?
|
429
|
+
OsUtil.print("There are ambiguous module dependencies in dtk.model.yaml includes: '#{amb_sorted.join(', ')}'. One of the namespaces should be selected by editing the module_refs file", :yellow) unless ambiguous.empty?
|
430
|
+
end
|
431
|
+
|
432
|
+
# if user do import from default directory (e.g. import ntp - without namespace) print message
|
304
433
|
# module directory moved from (~/dtk/component_module/<module_name>) to (~/dtk/component_module/<default_namespace>/<module_name>)
|
305
434
|
DTK::Client::OsUtil.print("Module '#{new_module_name}' has been created and module directory moved to #{module_final_dir}",:yellow) unless namespace
|
306
435
|
end
|
@@ -370,7 +499,7 @@ module DTK::Client
|
|
370
499
|
# module_name,repo_url,branch,version = response.data(:module_name, :repo_url, :workspace_branch, :version)
|
371
500
|
module_id, module_name, namespace, repo_url, branch, version = response.data(:module_id, :module_name, :namespace, :repo_url, :workspace_branch, :version)
|
372
501
|
|
373
|
-
if error = response.data(:
|
502
|
+
if error = response.data(:dsl_parse_error)
|
374
503
|
dsl_parsed_message = ServiceImporter.error_message(module_name, error)
|
375
504
|
DTK::Client::OsUtil.print(dsl_parsed_message, :red)
|
376
505
|
end
|
@@ -572,6 +701,12 @@ module DTK::Client
|
|
572
701
|
end
|
573
702
|
end
|
574
703
|
|
704
|
+
def list_remote_module_diffs(context_params)
|
705
|
+
module_type = get_module_type(context_params)
|
706
|
+
module_id = context_params.retrieve_arguments([REQ_MODULE_ID],method_argument_names)
|
707
|
+
list_remote_diffs_aux(module_type.to_sym, module_id)
|
708
|
+
end
|
709
|
+
|
575
710
|
def delete_assembly_aux(context_params)
|
576
711
|
module_type = get_module_type(context_params)
|
577
712
|
|
@@ -636,5 +771,8 @@ module DTK::Client
|
|
636
771
|
response.render_table(:assembly)
|
637
772
|
end
|
638
773
|
|
774
|
+
def print_ambiguous(ambiguous)
|
775
|
+
end
|
776
|
+
|
639
777
|
end
|
640
778
|
end
|
@@ -89,7 +89,7 @@ module DTK::Client
|
|
89
89
|
response = cmd_obj.Helper(:git_repo).pull_changes(module_type,module_name,opts)
|
90
90
|
|
91
91
|
# return response unless response.ok?
|
92
|
-
if response.data[:diffs].empty?
|
92
|
+
if (response.data[:diffs].nil? || response.data[:diffs].empty?)
|
93
93
|
puts "No changes to pull from remote."
|
94
94
|
else
|
95
95
|
puts "Changes pulled from remote"
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module DTK::Client
|
2
|
+
module PuppetForgeMixin
|
3
|
+
|
4
|
+
def puppet_forge_install_aux(context_params, pf_module_name, module_name, namespace, version, module_type)
|
5
|
+
post_body_hash = {
|
6
|
+
:puppetf_module_name => pf_module_name,
|
7
|
+
:module_name? => module_name,
|
8
|
+
:module_version? => version,
|
9
|
+
:module_namespace? => namespace
|
10
|
+
}
|
11
|
+
|
12
|
+
response = post rest_url("component_module/install_puppet_forge_modules"),PostBody.new(post_body_hash)
|
13
|
+
|
14
|
+
return response unless response.ok?
|
15
|
+
|
16
|
+
|
17
|
+
installed_modules = response.data(:installed_modules)
|
18
|
+
|
19
|
+
print_modules(response.data(:found_modules), 'using')
|
20
|
+
print_modules(installed_modules, 'installed')
|
21
|
+
|
22
|
+
main_module = response.data(:main_module)
|
23
|
+
|
24
|
+
unless installed_modules.empty?
|
25
|
+
# clone_deps = Console.confirmation_prompt("\nDo you want to clone newly installed dependencies?")
|
26
|
+
# if clone_deps
|
27
|
+
installed_modules.each do |im|
|
28
|
+
clone_aux(im['type'], im['id'], im['version'], true, true, {:backup_if_exist => true})
|
29
|
+
end
|
30
|
+
# end
|
31
|
+
end
|
32
|
+
|
33
|
+
clone_aux(main_module['type'], main_module['id'], main_module['version'], true, true, {:print_imported => true, :backup_if_exist => true})
|
34
|
+
nil
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def print_modules(modules, action_name)
|
40
|
+
modules.each do |target_module|
|
41
|
+
module_name = full_module_name(target_module)
|
42
|
+
module_type = target_module['type']
|
43
|
+
|
44
|
+
print "#{action_name.capitalize} dependency #{module_type.gsub('_',' ')} '#{module_name}'\n"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
|
@@ -8,42 +8,52 @@ module DTK::Client
|
|
8
8
|
#
|
9
9
|
# module_type: will be :component_module or :service_module
|
10
10
|
def push_clone_changes_aux(module_type,module_id,version,commit_msg,internal_trigger=false,opts={})
|
11
|
-
module_name,module_namespace,repo_url,branch,not_ok_response = workspace_branch_info(module_type,module_id,version,opts)
|
11
|
+
module_name, module_namespace, repo_url, branch, not_ok_response = workspace_branch_info(module_type, module_id, version, opts)
|
12
12
|
return not_ok_response if not_ok_response
|
13
13
|
|
14
14
|
full_module_name = ModuleUtil.resolve_name(module_name, module_namespace)
|
15
|
-
module_location = OsUtil.module_location(module_type,full_module_name,version,opts)
|
15
|
+
module_location = OsUtil.module_location(module_type, full_module_name, version, opts)
|
16
16
|
|
17
17
|
unless File.directory?(module_location)
|
18
18
|
return if opts[:skip_cloning]
|
19
19
|
if Console.confirmation_prompt("Push not possible, module '#{module_name}#{version && "-#{version}"}' has not been cloned. Would you like to clone module now"+'?')
|
20
|
-
clone_aux(module_type,module_id, version, true, true, opts)
|
20
|
+
clone_aux(module_type, module_id, version, true, true, opts)
|
21
21
|
else
|
22
22
|
return
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
26
|
push_opts = opts.merge(:commit_msg => commit_msg, :local_branch => branch)
|
27
|
-
response
|
27
|
+
response = Helper(:git_repo).push_changes(module_type, full_module_name, version, push_opts)
|
28
28
|
return response unless response.ok?
|
29
29
|
|
30
30
|
json_diffs = (response.data(:diffs).empty? ? {} : JSON.generate(response.data(:diffs)))
|
31
31
|
commit_sha = response.data(:commit_sha)
|
32
|
-
repo_obj
|
32
|
+
repo_obj = response.data(:repo_obj)
|
33
33
|
json_diffs = JSON.generate(response.data(:diffs))
|
34
|
-
post_body
|
34
|
+
post_body = get_workspace_branch_info_post_body(module_type, module_id, version, opts).merge(:json_diffs => json_diffs, :commit_sha => commit_sha)
|
35
35
|
post_body.merge!(:modification_type => opts[:modification_type]) if opts[:modification_type]
|
36
|
-
post_body.merge!(:force_parse => true) if options['force-parse']
|
36
|
+
post_body.merge!(:force_parse => true) if options['force-parse'] || opts[:force_parse]
|
37
|
+
post_body.merge!(:skip_module_ref_update => true) if opts[:skip_module_ref_update]
|
38
|
+
post_body.merge!(:update_from_includes => true) if opts[:update_from_includes]
|
37
39
|
|
38
|
-
|
40
|
+
if opts[:set_parsed_false]
|
41
|
+
post_body.merge!(:set_parsed_false => true)
|
42
|
+
post_body.merge!(:force_parse => true)
|
43
|
+
end
|
44
|
+
|
45
|
+
response = post(rest_url("#{module_type}/update_model_from_clone"), post_body)
|
39
46
|
return response unless response.ok?
|
40
47
|
|
41
48
|
ret = Response::Ok.new()
|
49
|
+
external_dependencies = response.data('external_dependencies')
|
42
50
|
|
43
51
|
# check if any errors
|
44
|
-
if
|
45
|
-
if
|
46
|
-
|
52
|
+
if dsl_parse_error = response.data(:dsl_parse_error)
|
53
|
+
if parsed_external_dependencies = dsl_parse_error['external_dependencies']
|
54
|
+
external_dependencies = parsed_external_dependencies
|
55
|
+
elsif err_message = ServiceImporter.error_message(module_name, dsl_parse_error)
|
56
|
+
DTK::Client::OsUtil.print(err_message, :red)
|
47
57
|
ret = Response::NoOp.new()
|
48
58
|
end
|
49
59
|
end
|
@@ -57,8 +67,20 @@ module DTK::Client
|
|
57
67
|
new_commit_sha = dsl_updated_info[:commit_sha]
|
58
68
|
unless new_commit_sha and new_commit_sha == commit_sha
|
59
69
|
opts_pull = opts.merge(:local_branch => branch,:namespace => module_namespace)
|
60
|
-
|
61
|
-
return
|
70
|
+
resp = Helper(:git_repo).pull_changes(module_type, module_name, opts_pull)
|
71
|
+
return resp unless resp.ok?
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
if opts[:print_dependencies] || !internal_trigger
|
76
|
+
if external_dependencies
|
77
|
+
ambiguous = external_dependencies["ambiguous"]||[]
|
78
|
+
amb_sorted = ambiguous.map { |k,v| "#{k.split('/').last} (#{v.join(', ')})" }
|
79
|
+
inconsistent = external_dependencies["inconsistent"]||[]
|
80
|
+
possibly_missing = external_dependencies["possibly_missing"]||[]
|
81
|
+
OsUtil.print("There are inconsistent module dependencies: #{inconsistent.join(', ')}", :red) unless inconsistent.empty?
|
82
|
+
OsUtil.print("There are missing module dependencies: #{possibly_missing.join(', ')}", :yellow) unless possibly_missing.empty?
|
83
|
+
OsUtil.print("There are ambiguous module dependencies: '#{amb_sorted.join(', ')}'. One of the namespaces should be selected by editing the module_refs file", :yellow) if ambiguous && !ambiguous.empty?
|
62
84
|
end
|
63
85
|
end
|
64
86
|
|
@@ -68,12 +90,28 @@ module DTK::Client
|
|
68
90
|
path = dsl_created_info["path"]
|
69
91
|
content = dsl_created_info["content"]
|
70
92
|
if path and content
|
71
|
-
msg
|
93
|
+
msg = "A #{path} file has been created for you, located at #{repo_obj.repo_dir}"
|
72
94
|
response = Helper(:git_repo).add_file(repo_obj,path,content,msg)
|
73
95
|
return response unless response.ok?
|
74
96
|
end
|
75
97
|
end
|
98
|
+
|
99
|
+
service_component_refs = response.data['component_module_refs']
|
100
|
+
unless (service_component_refs||{}).empty?
|
101
|
+
print_using_dependencies(service_component_refs)
|
102
|
+
end
|
103
|
+
|
76
104
|
ret
|
77
105
|
end
|
106
|
+
|
107
|
+
private
|
108
|
+
def print_using_dependencies(component_refs)
|
109
|
+
component_refs.each do |k, value|
|
110
|
+
namespace = value['namespace_info']
|
111
|
+
name = value['module_name']
|
112
|
+
puts "Using component module '#{namespace}:#{name}'"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
78
116
|
end
|
79
117
|
end
|
@@ -1,32 +1,18 @@
|
|
1
|
-
require 'json'
|
2
1
|
require 'yaml'
|
3
2
|
|
4
3
|
module DTK::Client
|
5
4
|
module ReparseMixin
|
5
|
+
YamlDTKMetaFiles = ['dtk.model.yaml', 'module_refs.yaml', 'assemblies/*.yaml', 'assemblies/*/assembly.yaml']
|
6
6
|
|
7
|
-
##
|
8
|
-
#
|
9
|
-
# module_type: will be :component_module or :service_module
|
10
7
|
def reparse_aux(location)
|
11
|
-
|
12
|
-
files_yaml = Dir.glob("#{location}/**/*.yaml")
|
13
|
-
|
14
|
-
files_json.each do |file|
|
15
|
-
file_content = File.open(file).read
|
16
|
-
begin
|
17
|
-
JSON.parse(file_content)
|
18
|
-
rescue JSON::ParserError => e
|
19
|
-
raise DTK::Client::DSLParsing::JSONParsing.new("JSON parsing error #{e} in file",file)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
8
|
+
files_yaml = YamlDTKMetaFiles.map{|rel_path|Dir.glob("#{location}/#{rel_path}")}.flatten(1)
|
23
9
|
files_yaml.each do |file|
|
24
10
|
file_content = File.open(file).read
|
25
11
|
begin
|
26
12
|
YAML.load(file_content)
|
27
13
|
rescue Exception => e
|
28
14
|
e.to_s.gsub!(/\(<unknown>\)/,'')
|
29
|
-
raise DTK::Client::DSLParsing::YAMLParsing.new("YAML parsing error #{e} in file",file)
|
15
|
+
raise DTK::Client::DSLParsing::YAMLParsing.new("YAML parsing error #{e} in file", file)
|
30
16
|
end
|
31
17
|
end
|
32
18
|
|
@@ -34,4 +20,4 @@ module DTK::Client
|
|
34
20
|
end
|
35
21
|
|
36
22
|
end
|
37
|
-
end
|
23
|
+
end
|
@@ -22,16 +22,20 @@ module DTK::Client
|
|
22
22
|
#break unless response.data.first["status"].eql? "executing"
|
23
23
|
# TODO: There is bug where we do not see executing status on start so we have to wait until at
|
24
24
|
# least one 'successed' has been found
|
25
|
+
|
26
|
+
top_task_failed = response.data.first['status'].eql?('failed')
|
25
27
|
is_pending = (response.data.select {|r|r["status"].nil? }).size > 0
|
26
28
|
is_executing = (response.data.select {|r|r["status"].eql? "executing"}).size > 0
|
27
29
|
is_failed = (response.data.select {|r|r["status"].eql? "failed"}).size > 0
|
28
30
|
is_cancelled = response.data.first["status"].eql?("cancelled")
|
29
31
|
|
32
|
+
# commented out because of DTK-1804
|
30
33
|
# when some of the converge tasks fail, stop task-status --wait and set task status to '' for remaining tasks which are not executed
|
31
|
-
if is_failed
|
32
|
-
response.data.each {|r| (r["status"] = "") if r["status"].eql?("executing")}
|
33
|
-
is_cancelled = true
|
34
|
-
end
|
34
|
+
# if is_failed
|
35
|
+
# response.data.each {|r| (r["status"] = "") if r["status"].eql?("executing")}
|
36
|
+
# is_cancelled = true
|
37
|
+
# end
|
38
|
+
is_cancelled = true if top_task_failed
|
35
39
|
|
36
40
|
unless (is_executing || is_pending) && !is_cancelled
|
37
41
|
system('clear')
|