dtk-client 0.5.17 → 0.5.18
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 +8 -8
- data/lib/command_helpers/git_repo.rb +82 -48
- data/lib/command_helpers/service_importer.rb +26 -17
- data/lib/command_helpers/test_module_creator.rb +6 -5
- data/lib/commands/common/thor/access_control.rb +5 -4
- data/lib/commands/common/thor/assembly_template.rb +75 -0
- data/lib/commands/common/thor/assembly_workspace.rb +86 -71
- data/lib/commands/common/thor/clone.rb +9 -7
- data/lib/commands/common/thor/common.rb +17 -10
- data/lib/commands/common/thor/edit.rb +65 -6
- data/lib/commands/common/thor/list_diffs.rb +4 -3
- data/lib/commands/common/thor/module.rb +86 -89
- data/lib/commands/common/thor/pull_clone_changes.rb +3 -2
- data/lib/commands/common/thor/pull_from_remote.rb +9 -5
- data/lib/commands/common/thor/purge_clone.rb +2 -2
- data/lib/commands/common/thor/push_clone_changes.rb +39 -16
- data/lib/commands/common/thor/push_to_remote.rb +3 -3
- data/lib/commands/thor/account.rb +16 -4
- data/lib/commands/thor/assembly.rb +66 -89
- data/lib/commands/thor/component_module.rb +40 -24
- data/lib/commands/thor/node.rb +7 -0
- data/lib/commands/thor/provider.rb +45 -23
- data/lib/commands/thor/service.rb +4 -7
- data/lib/commands/thor/service_module.rb +45 -20
- data/lib/commands/thor/test_module.rb +36 -22
- data/lib/commands/thor/workspace.rb +6 -6
- data/lib/core.rb +18 -17
- data/lib/domain/git_adapter.rb +30 -9
- data/lib/dtk-client/version.rb +1 -1
- data/lib/parser/adapters/thor.rb +47 -25
- data/lib/shell/context.rb +10 -2
- data/lib/shell.rb +18 -12
- data/lib/util/module_util.rb +41 -0
- data/lib/util/os_util.rb +25 -7
- metadata +4 -2
@@ -106,12 +106,72 @@ module DTK::Client
|
|
106
106
|
Response::Ok.new()
|
107
107
|
end
|
108
108
|
|
109
|
+
# returns text string with edited yaml content
|
110
|
+
def attributes_editor(yaml_input)
|
111
|
+
dtk_folder = OsUtil.dtk_local_folder
|
112
|
+
file_path = "#{dtk_folder}/temp_attrs.yaml"
|
113
|
+
File.open(file_path, 'w'){|f| f << yaml_input}
|
114
|
+
OsUtil.edit(file_path)
|
115
|
+
OsUtil.print("If you want to use different editor please set environment variable EDITOR and log back into dtk-shell!", :yellow) unless ENV['EDITOR']
|
116
|
+
edited_yaml = File.open(file_path,'r'){|f|f.read}
|
117
|
+
File.unlink(file_path)
|
118
|
+
edited_yaml
|
119
|
+
end
|
120
|
+
private
|
121
|
+
# removes any nil values and returns hash; also modifies any term that does not serialize
|
122
|
+
def post_process(object)
|
123
|
+
ret = Hash.new
|
124
|
+
if object.kind_of?(Hash)
|
125
|
+
post_process__hash(object)
|
126
|
+
elsif object.kind_of?(Array)
|
127
|
+
post_process__array(object)
|
128
|
+
elsif object.kind_of?(FalseClass)
|
129
|
+
Response::Term::Boolean.false
|
130
|
+
else
|
131
|
+
object
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def post_process__hash(hash)
|
136
|
+
ret = Hash.new
|
137
|
+
hash.each_pair do |k,v|
|
138
|
+
processed_val = post_process(v)
|
139
|
+
#processed_val can be false so explicitly checking against nil
|
140
|
+
unless processed_val.nil?
|
141
|
+
ret.merge!(k => processed_val)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
ret
|
145
|
+
end
|
146
|
+
|
147
|
+
def post_process__array(array)
|
148
|
+
ret = Array.new
|
149
|
+
array.each do |a|
|
150
|
+
# explicit nil not removed
|
151
|
+
if a.nil?
|
152
|
+
ret << Response::Term.nil()
|
153
|
+
else
|
154
|
+
processed_val = post_process(a)
|
155
|
+
#processed_val can be false so explicitly checking against nil
|
156
|
+
unless processed_val.nil?
|
157
|
+
ret << processed_val
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
ret
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
|
167
|
+
=begin
|
168
|
+
# TODO: probably deprecate
|
109
169
|
def attribute_header()
|
110
170
|
header_string =
|
111
171
|
"#############################\n#### REQUIRED ATTRIBUTES\n#############################\n#\n"
|
112
172
|
end
|
113
|
-
|
114
|
-
def
|
173
|
+
# TODO: probably deprecate
|
174
|
+
def attributes_editor_old_form(attributes,format)
|
115
175
|
if (format.eql?('yaml'))
|
116
176
|
dtk_folder = OsUtil.dtk_local_folder
|
117
177
|
file_path = "#{dtk_folder}/temp_attrs.yaml"
|
@@ -153,7 +213,7 @@ module DTK::Client
|
|
153
213
|
begin
|
154
214
|
edited = YAML.load_file(file_path)
|
155
215
|
rescue Psych::SyntaxError => e
|
156
|
-
raise
|
216
|
+
raise DSLParsing::YAMLParsing.new("YAML parsing error #{e} in file",file_path)
|
157
217
|
end
|
158
218
|
|
159
219
|
edited.each do |k,v|
|
@@ -169,9 +229,8 @@ module DTK::Client
|
|
169
229
|
raise DtkValidationError, "No attribute changes have been made." if ((first_iteration_keys == second_iteration_keys) && (first_iteration_values == second_iteration_values))
|
170
230
|
edited
|
171
231
|
else
|
172
|
-
raise
|
232
|
+
raise DtkValidationError, "Unsupported format type '#{format.to_s}'!"
|
173
233
|
end
|
174
234
|
end
|
235
|
+
=end
|
175
236
|
|
176
|
-
end
|
177
|
-
end
|
@@ -15,8 +15,9 @@ module DTK::Client
|
|
15
15
|
|
16
16
|
response = post(rest_url("#{module_type}/get_remote_module_info"),post_body)
|
17
17
|
return response unless response.ok?
|
18
|
-
|
19
|
-
module_name = response.data(:
|
18
|
+
|
19
|
+
module_name = response.data(:full_module_name)
|
20
|
+
|
20
21
|
opts = {
|
21
22
|
:remote_repo_url => response.data(:remote_repo_url),
|
22
23
|
:remote_repo => response.data(:remote_repo),
|
@@ -31,7 +32,7 @@ module DTK::Client
|
|
31
32
|
added, deleted, modified = print_diffs(response.data(remote ? :diffs : :status), remote)
|
32
33
|
|
33
34
|
raise DTK::Client::DtkValidationError, "There is no changes in current workspace!" if(added.empty? && deleted.empty? && modified.empty?)
|
34
|
-
|
35
|
+
|
35
36
|
unless added.empty?
|
36
37
|
puts "ADDED:"
|
37
38
|
added.each do |a|
|
@@ -30,11 +30,19 @@ module DTK::Client
|
|
30
30
|
include ServiceImporter
|
31
31
|
include AccessControlMixin
|
32
32
|
|
33
|
-
REQ_MODULE_ID
|
33
|
+
REQ_MODULE_ID = [:service_module_id!, :component_module_id!, :test_module_id!]
|
34
|
+
REQ_MODULE_NAME = [:service_module_name!, :component_module_name!, :test_module_name!]
|
34
35
|
|
35
36
|
def get_module_type(context_params)
|
36
|
-
forwarded_type = context_params.get_forwarded_options() ? context_params.get_forwarded_options()[:module_type] :
|
37
|
-
|
37
|
+
forwarded_type = context_params.get_forwarded_options() ? context_params.get_forwarded_options()[:module_type] : nil
|
38
|
+
|
39
|
+
if context_params.root_command_name || forwarded_type
|
40
|
+
module_type = (context_params.root_command_name||forwarded_type).gsub(/\-/, "_")
|
41
|
+
else
|
42
|
+
module_type = resolve_module_type
|
43
|
+
end
|
44
|
+
|
45
|
+
module_type
|
38
46
|
end
|
39
47
|
|
40
48
|
def module_info_about(context_params, about, data_type)
|
@@ -68,25 +76,26 @@ module DTK::Client
|
|
68
76
|
end
|
69
77
|
end
|
70
78
|
|
71
|
-
def delete_module_aux(context_params,method_opts={})
|
79
|
+
def delete_module_aux(context_params, method_opts={})
|
72
80
|
module_location, modules_path = nil, nil
|
73
81
|
module_id = context_params.retrieve_arguments([:option_1!], method_argument_names)
|
82
|
+
|
83
|
+
delete_module_sub_aux(context_params, module_id, method_opts)
|
84
|
+
end
|
85
|
+
|
86
|
+
def delete_module_sub_aux(context_params, module_id, method_opts={})
|
87
|
+
# ModuleUtil.check_format!(module_id)
|
74
88
|
version = options.version
|
75
89
|
module_name = get_name_from_id_helper(module_id)
|
76
90
|
module_type = get_module_type(context_params)
|
77
91
|
|
78
|
-
# if called from import-git first param will be git_url and second one will be module_id
|
79
|
-
git_import = context_params.get_forwarded_options()[:git_import] if context_params.get_forwarded_options()
|
80
|
-
if git_import
|
81
|
-
module_id = context_params.retrieve_arguments([:option_2!], method_argument_names)
|
82
|
-
end
|
83
|
-
|
84
92
|
unless (options.force? || method_opts[:force_delete])
|
85
|
-
|
93
|
+
is_go = Console.confirmation_prompt("Are you sure you want to delete module '#{module_name}'"+"?")
|
94
|
+
return nil unless is_go
|
86
95
|
end
|
87
96
|
|
88
97
|
response =
|
89
|
-
if options.purge?
|
98
|
+
if options.purge? || method_opts[:purge]
|
90
99
|
opts = {:module_name => module_name}
|
91
100
|
if version then opts.merge!(:version => version)
|
92
101
|
else opts.merge!(:delete_all_versions => true)
|
@@ -142,13 +151,7 @@ module DTK::Client
|
|
142
151
|
module_id, module_name = context_params.retrieve_arguments([REQ_MODULE_ID, "#{module_type}_name".to_sym],method_argument_names)
|
143
152
|
version = options["version"]
|
144
153
|
|
145
|
-
|
146
|
-
module_id = module_name
|
147
|
-
module_name = get_name_from_id_helper(module_id)
|
148
|
-
end
|
149
|
-
|
150
|
-
modules_path = OsUtil.module_clone_location(module_type)
|
151
|
-
module_location = "#{modules_path}/#{module_name}#{version && "-#{version}"}"
|
154
|
+
module_location = OsUtil.module_location(module_type, module_name, version)
|
152
155
|
|
153
156
|
reparse_aux(module_location)
|
154
157
|
push_clone_changes_aux(module_type.to_sym, module_id, version, options["message"]||DEFAULT_COMMIT_MSG, internal_trigger)
|
@@ -162,13 +165,17 @@ module DTK::Client
|
|
162
165
|
return response unless response.ok?
|
163
166
|
|
164
167
|
create_response = import(context_params)
|
168
|
+
|
165
169
|
unless create_response.ok?
|
166
170
|
error_msg = create_response['errors'].select { |er| er['message'].include? "cannot be created since it exists already" }
|
167
171
|
if error_msg.empty?
|
168
172
|
# If server response is not ok and module does not exist on server, delete cloned module, invoke delete method
|
169
|
-
FileUtils.rm_rf("#{response['data']['module_directory']}")
|
170
173
|
delete(context_params,:force_delete => true, :no_error_msg => true)
|
171
174
|
end
|
175
|
+
|
176
|
+
# remove temp directory
|
177
|
+
FileUtils.rm_rf("#{response['data']['module_directory']}")
|
178
|
+
|
172
179
|
return create_response
|
173
180
|
end
|
174
181
|
end
|
@@ -177,8 +184,10 @@ module DTK::Client
|
|
177
184
|
git_repo_url, module_name = context_params.retrieve_arguments([:option_1!, :option_2!],method_argument_names)
|
178
185
|
module_type = get_module_type(context_params)
|
179
186
|
|
187
|
+
namespace, local_module_name = get_namespace_and_name(module_name, ModuleUtil::NAMESPACE_SEPERATOR)
|
188
|
+
|
180
189
|
# Create component module from user's input git repo
|
181
|
-
response = Helper(:git_repo).create_clone_with_branch(module_type.to_sym,
|
190
|
+
response = Helper(:git_repo).create_clone_with_branch(module_type.to_sym, local_module_name, git_repo_url)
|
182
191
|
|
183
192
|
# Raise error if git repository is invalid
|
184
193
|
# raise DtkError,"Git repository URL '#{git_repo_url}' is invalid." unless response.ok?
|
@@ -199,9 +208,7 @@ module DTK::Client
|
|
199
208
|
OsUtil.print("There are some missing dependencies: #{possibly_missing}", :yellow) unless possibly_missing.empty?
|
200
209
|
end
|
201
210
|
else
|
202
|
-
|
203
|
-
FileUtils.rm_rf("#{response['data']['module_directory']}")
|
204
|
-
delete(context_params,:force_delete => true, :no_error_msg => true)
|
211
|
+
delete_module_sub_aux(context_params, local_module_name, :force_delete => true, :no_error_msg => true, :purge => true)
|
205
212
|
return create_response
|
206
213
|
end
|
207
214
|
|
@@ -214,8 +221,9 @@ module DTK::Client
|
|
214
221
|
module_name = context_params.retrieve_arguments([name_option],method_argument_names)
|
215
222
|
module_type = get_module_type(context_params)
|
216
223
|
|
224
|
+
namespace, local_module_name = get_namespace_and_name(module_name, ModuleUtil::NAMESPACE_SEPERATOR)
|
217
225
|
# first check that there is a directory there and it is not already a git repo, and it ha appropriate content
|
218
|
-
response = Helper(:git_repo).check_local_dir_exists_with_content(module_type.to_sym,
|
226
|
+
response = Helper(:git_repo).check_local_dir_exists_with_content(module_type.to_sym, local_module_name, nil, namespace)
|
219
227
|
return response unless response.ok?
|
220
228
|
module_directory = response.data(:module_directory)
|
221
229
|
|
@@ -223,14 +231,14 @@ module DTK::Client
|
|
223
231
|
reparse_aux(module_directory)
|
224
232
|
|
225
233
|
# first make call to server to create an empty repo
|
226
|
-
response = post rest_url("#{module_type}/create"), { :module_name =>
|
234
|
+
response = post rest_url("#{module_type}/create"), { :module_name => local_module_name, :module_namespace => namespace }
|
227
235
|
return response unless response.ok?
|
228
236
|
|
229
|
-
repo_url,repo_id,module_id,branch = response.data(:repo_url,:repo_id,:module_id,:workspace_branch)
|
230
|
-
response = Helper(:git_repo).
|
231
|
-
|
237
|
+
repo_url,repo_id,module_id,branch,new_module_name = response.data(:repo_url,:repo_id,:module_id,:workspace_branch,:full_module_name)
|
238
|
+
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)
|
232
239
|
return response unless response.ok?
|
233
240
|
repo_obj,commit_sha = response.data(:repo_obj, :commit_sha)
|
241
|
+
module_final_dir = repo_obj.repo_dir
|
234
242
|
|
235
243
|
post_body = {
|
236
244
|
:repo_id => repo_id,
|
@@ -239,21 +247,29 @@ module DTK::Client
|
|
239
247
|
:scaffold_if_no_dsl => true
|
240
248
|
}
|
241
249
|
response = post(rest_url("#{module_type}/update_from_initial_create"),post_body)
|
242
|
-
|
250
|
+
|
251
|
+
unless response.ok?
|
252
|
+
response.set_data_hash({ :full_module_name => new_module_name })
|
253
|
+
return response
|
254
|
+
end
|
243
255
|
|
244
256
|
external_dependencies = response.data(:external_dependencies)
|
245
257
|
dsl_created_info = response.data(:dsl_created_info)
|
246
258
|
|
247
259
|
if dsl_created_info and !dsl_created_info.empty?
|
248
|
-
msg = "A #{dsl_created_info["path"]} file has been created for you, located at #{
|
260
|
+
msg = "A #{dsl_created_info["path"]} file has been created for you, located at #{module_final_dir}"
|
261
|
+
DTK::Client::OsUtil.print(msg,:yellow)
|
249
262
|
response = Helper(:git_repo).add_file(repo_obj, dsl_created_info["path"], dsl_created_info["content"], msg)
|
250
|
-
|
251
|
-
response = Response::Ok.new("module_created" => module_name)
|
263
|
+
return response unless response.ok?
|
252
264
|
end
|
253
265
|
|
266
|
+
#TODO: this is never used
|
267
|
+
response = Response::Ok.new("module_created" => module_name)
|
268
|
+
|
269
|
+
# TODO: what is purpose of pushing again
|
254
270
|
# we push clone changes anyway, user can change and push again
|
255
271
|
# context_params.add_context_to_params(module_name, :"component-module", module_id)
|
256
|
-
context_params.add_context_to_params(
|
272
|
+
context_params.add_context_to_params(local_module_name, module_type.to_s.gsub!(/\_/,'-').to_sym, module_id)
|
257
273
|
response = push_module_aux(context_params, true)
|
258
274
|
|
259
275
|
if git_import
|
@@ -261,7 +277,7 @@ module DTK::Client
|
|
261
277
|
response.add_data_value!(:external_dependencies, external_dependencies) if external_dependencies
|
262
278
|
end
|
263
279
|
|
264
|
-
|
280
|
+
response
|
265
281
|
end
|
266
282
|
|
267
283
|
def install_module_aux(context_params)
|
@@ -277,8 +293,9 @@ module DTK::Client
|
|
277
293
|
ignore_component_error = context_params.get_forwarded_options() ? context_params.get_forwarded_options()[:ignore_component_error] : options.ignore?
|
278
294
|
additional_message = context_params.get_forwarded_options()[:additional_message] if context_params.get_forwarded_options()
|
279
295
|
|
280
|
-
remote_namespace, local_module_name = get_namespace_and_name(remote_module_name)
|
281
|
-
|
296
|
+
remote_namespace, local_module_name = get_namespace_and_name(remote_module_name,'/')
|
297
|
+
|
298
|
+
if clone_dir = Helper(:git_repo).local_clone_dir_exists?(module_type.to_sym, local_module_name, :namespace => remote_namespace, :version => version)
|
282
299
|
message = "Module's directory (#{clone_dir}) exists on client. To install this needs to be renamed or removed"
|
283
300
|
message += ". To ignore this conflict and use existing component module please use -i switch (install REMOTE-SERVICE-NAME -i)." if additional_message
|
284
301
|
|
@@ -299,11 +316,12 @@ module DTK::Client
|
|
299
316
|
|
300
317
|
# case when we need to import additional components
|
301
318
|
if (response.ok? && (missing_components = response.data(:missing_module_components)))
|
319
|
+
required_components = response.data(:required_modules)
|
302
320
|
opts = {:do_not_raise=>true}
|
303
321
|
module_opts = ignore_component_error ? opts.merge(:ignore_component_error => true) : opts.merge(:additional_message=>true)
|
304
322
|
module_opts.merge!(:module_type => 'component-module')
|
305
323
|
|
306
|
-
continue = trigger_module_component_import(missing_components,module_opts)
|
324
|
+
continue = trigger_module_component_import(missing_components, required_components, module_opts)
|
307
325
|
return unless continue
|
308
326
|
|
309
327
|
puts "Resuming DTK Network import for #{module_type} '#{remote_module_name}' ..."
|
@@ -315,14 +333,14 @@ module DTK::Client
|
|
315
333
|
return response if(!response.ok? || response.data(:does_not_exist))
|
316
334
|
# module_name,repo_url,branch,version = response.data(:module_name, :repo_url, :workspace_branch, :version)
|
317
335
|
module_id, module_name, namespace, repo_url, branch, version = response.data(:module_id, :module_name, :namespace, :repo_url, :workspace_branch, :version)
|
318
|
-
|
336
|
+
|
319
337
|
if error = response.data(:dsl_parsed_info)
|
320
338
|
dsl_parsed_message = ServiceImporter.error_message(module_name, error)
|
321
339
|
DTK::Client::OsUtil.print(dsl_parsed_message, :red)
|
322
340
|
end
|
323
341
|
|
324
342
|
unless skip_cloning
|
325
|
-
response = Helper(:git_repo).create_clone_with_branch(module_type.to_sym, module_name, repo_url, branch, version)
|
343
|
+
response = Helper(:git_repo).create_clone_with_branch(module_type.to_sym, module_name, repo_url, branch, version, remote_namespace)
|
326
344
|
end
|
327
345
|
|
328
346
|
resolve_missing_components(module_id, module_name, namespace, options.force?) if module_type.to_s.eql?('service_module')
|
@@ -334,7 +352,7 @@ module DTK::Client
|
|
334
352
|
remote_module_name = context_params.retrieve_arguments([:option_1!],method_argument_names)
|
335
353
|
|
336
354
|
# for service_module we are doing this on server side
|
337
|
-
remote_namespace, remote_module_name = get_namespace_and_name(remote_module_name) unless module_type.eql?('service_module')
|
355
|
+
remote_namespace, remote_module_name = get_namespace_and_name(remote_module_name,'/') unless module_type.eql?('service_module')
|
338
356
|
|
339
357
|
unless options.force?
|
340
358
|
return unless Console.confirmation_prompt("Are you sure you want to delete remote #{module_type} '#{remote_namespace.nil? ? '' : remote_namespace+'/'}#{remote_module_name}' and all items contained in it"+'?')
|
@@ -367,20 +385,15 @@ module DTK::Client
|
|
367
385
|
end
|
368
386
|
|
369
387
|
def pull_dtkn_aux(context_params)
|
370
|
-
module_id, module_name = context_params.retrieve_arguments([REQ_MODULE_ID,:
|
388
|
+
module_id, module_name = context_params.retrieve_arguments([REQ_MODULE_ID,REQ_MODULE_NAME,:option_1],method_argument_names)
|
389
|
+
|
371
390
|
catalog = 'dtkn'
|
372
391
|
version = options["version"]
|
373
392
|
module_type = get_module_type(context_params)
|
374
393
|
|
375
394
|
raise DtkValidationError, "You have to provide valid catalog to pull changes from! Valid catalogs: #{PULL_CATALOGS}" unless catalog
|
376
395
|
|
377
|
-
|
378
|
-
module_id = module_name
|
379
|
-
module_name = get_name_from_id_helper(module_id)
|
380
|
-
end
|
381
|
-
|
382
|
-
modules_path = OsUtil.module_clone_location(module_type)
|
383
|
-
module_location = "#{modules_path}/#{module_name}#{version && "-#{version}"}"
|
396
|
+
module_location = OsUtil.module_location(resolve_module_type(), module_name, version)
|
384
397
|
|
385
398
|
if catalog.to_s.eql?("dtkn")
|
386
399
|
clone_aux(module_type.to_sym, module_id, version, true, true) unless File.directory?(module_location)
|
@@ -438,14 +451,7 @@ module DTK::Client
|
|
438
451
|
version = thor_options["version"]
|
439
452
|
internal_trigger = true if thor_options['skip_edit']
|
440
453
|
|
441
|
-
|
442
|
-
if module_name.to_s =~ /^[0-9]+$/
|
443
|
-
module_id = module_name
|
444
|
-
module_name = get_name_from_id_helper(module_id)
|
445
|
-
end
|
446
|
-
|
447
|
-
modules_path = OsUtil.module_clone_location(module_type)
|
448
|
-
module_location = "#{modules_path}/#{module_name}#{version && "-#{version}"}"
|
454
|
+
module_location = OsUtil.module_location(module_type, module_name, version)
|
449
455
|
|
450
456
|
raise DTK::Client::DtkValidationError, "Trying to clone a #{module_type} '#{module_name}#{version && "-#{version}"}' that exists already!" if File.directory?(module_location)
|
451
457
|
clone_aux(module_type.to_sym, module_id, version, internal_trigger, thor_options['omit_output'])
|
@@ -458,12 +464,6 @@ module DTK::Client
|
|
458
464
|
version = options.version||context_params.retrieve_arguments([:option_1], method_argument_names)
|
459
465
|
edit_dsl = context_params.get_forwarded_options()[:edit_dsl] if context_params.get_forwarded_options()
|
460
466
|
|
461
|
-
# if this is not name it will not work, we need module name
|
462
|
-
if module_name.to_s =~ /^[0-9]+$/
|
463
|
-
module_id = module_name
|
464
|
-
module_name = get_name_from_id_helper(module_id)
|
465
|
-
end
|
466
|
-
|
467
467
|
#TODO: cleanup so dont need :base_file_name and get edit_file from server
|
468
468
|
opts = {}
|
469
469
|
base_file_name = "dtk.model"
|
@@ -472,21 +472,15 @@ module DTK::Client
|
|
472
472
|
end
|
473
473
|
|
474
474
|
def push_dtkn_module_aux(context_params, internal_trigger=false)
|
475
|
-
|
476
|
-
module_id, module_name = context_params.retrieve_arguments([REQ_MODULE_ID, :component_module_name],method_argument_names)
|
475
|
+
module_id, module_name = context_params.retrieve_arguments([REQ_MODULE_ID, REQ_MODULE_NAME],method_argument_names)
|
477
476
|
catalog = 'dtkn'
|
478
477
|
version = options["version"]
|
479
478
|
module_type = get_module_type(context_params)
|
480
479
|
|
481
480
|
raise DtkValidationError, "You have to provide valid catalog to push changes to! Valid catalogs: #{PushCatalogs}" unless catalog
|
482
481
|
|
483
|
-
|
484
|
-
module_id = module_name
|
485
|
-
module_name = get_name_from_id_helper(module_id)
|
486
|
-
end
|
482
|
+
module_location = OsUtil.module_location(resolve_module_type(), module_name, version)
|
487
483
|
|
488
|
-
modules_path = OsUtil.module_clone_location(module_type)
|
489
|
-
module_location = "#{modules_path}/#{module_name}#{version && "-#{version}"}"
|
490
484
|
reparse_aux(module_location) unless internal_trigger
|
491
485
|
|
492
486
|
# if catalog.to_s.eql?("origin")
|
@@ -520,14 +514,7 @@ module DTK::Client
|
|
520
514
|
module_name = context_params.retrieve_arguments(["#{module_type}_name".to_sym],method_argument_names)
|
521
515
|
version = options["version"]
|
522
516
|
|
523
|
-
|
524
|
-
if module_name.to_s =~ /^[0-9]+$/
|
525
|
-
module_id = module_name
|
526
|
-
module_name = get_name_from_id_helper(module_id)
|
527
|
-
end
|
528
|
-
|
529
|
-
modules_path = OsUtil.module_clone_location(module_type)
|
530
|
-
module_location = "#{modules_path}/#{module_name}#{version && "-#{version}"}"
|
517
|
+
module_location = OsUtil.module_location(module_type, module_name, version)
|
531
518
|
|
532
519
|
# check if there is repository cloned
|
533
520
|
if File.directory?(module_location)
|
@@ -550,14 +537,10 @@ module DTK::Client
|
|
550
537
|
module_type = get_module_type(context_params)
|
551
538
|
module_id, assembly_template_id = context_params.retrieve_arguments([REQ_MODULE_ID,:option_1!], method_argument_names)
|
552
539
|
module_name = context_params.retrieve_arguments([:service_module_name],method_argument_names)
|
540
|
+
|
553
541
|
assembly_template_name = (assembly_template_id.to_s =~ /^[0-9]+$/) ? DTK::Client::Assembly.get_assembly_template_name_for_service(assembly_template_id, module_name) : assembly_template_id
|
554
542
|
assembly_template_id = DTK::Client::Assembly.get_assembly_template_id_for_service(assembly_template_id, module_name) unless assembly_template_id.to_s =~ /^[0-9]+$/
|
555
543
|
|
556
|
-
if module_name.to_s =~ /^[0-9]+$/
|
557
|
-
module_id = module_name
|
558
|
-
module_name = get_name_from_id_helper(module_id)
|
559
|
-
end
|
560
|
-
|
561
544
|
return unless Console.confirmation_prompt("Are you sure you want to delete assembly '#{assembly_template_name||assembly_template_id}'"+'?') unless options.force?
|
562
545
|
|
563
546
|
post_body = {
|
@@ -566,13 +549,27 @@ module DTK::Client
|
|
566
549
|
:subtype => :template
|
567
550
|
}
|
568
551
|
|
569
|
-
response = post rest_url("module_type/delete_assembly_template"), post_body
|
552
|
+
response = post rest_url("#{module_type}/delete_assembly_template"), post_body
|
570
553
|
return response unless response.ok?
|
571
554
|
|
572
|
-
|
573
|
-
|
574
|
-
|
555
|
+
module_location = OsUtil.module_location(module_type, module_name)
|
556
|
+
|
557
|
+
if (module_location && assembly_template_name)
|
558
|
+
assembly_template_location = "#{module_location}/assemblies/#{assembly_template_name}"
|
559
|
+
base_file = "#{module_location}/assemblies/#{assembly_template_name}.dtk.assembly"
|
560
|
+
|
561
|
+
# Aldin: could not find better solution, leaving as is for now
|
562
|
+
assembly_file_location =
|
563
|
+
if File.exists?("#{base_file}.yaml")
|
564
|
+
"#{base_file}.yaml"
|
565
|
+
elsif File.exists?("#{base_file}.json")
|
566
|
+
"#{base_file}.json"
|
567
|
+
else
|
568
|
+
nil
|
569
|
+
end
|
570
|
+
end
|
575
571
|
|
572
|
+
FileUtils.rm("#{assembly_file_location}") if assembly_file_location
|
576
573
|
if File.directory?(assembly_template_location)
|
577
574
|
unless (assembly_template_location.nil? || ("#{module_location}/assemblies/" == assembly_template_location))
|
578
575
|
FileUtils.rm_rf("#{assembly_template_location}")
|
@@ -600,4 +597,4 @@ module DTK::Client
|
|
600
597
|
end
|
601
598
|
|
602
599
|
end
|
603
|
-
end
|
600
|
+
end
|
@@ -2,9 +2,10 @@ dtk_require_common_commands('thor/common')
|
|
2
2
|
module DTK::Client
|
3
3
|
module PullCloneChangesMixin
|
4
4
|
def pull_clone_changes?(module_type,module_id,version=nil,opts={})
|
5
|
-
module_name,repo_url,branch,not_ok_response = workspace_branch_info(module_type,module_id,version,opts)
|
5
|
+
module_name, module_namespace,repo_url,branch,not_ok_response = workspace_branch_info(module_type,module_id,version,opts)
|
6
6
|
return not_ok_response if not_ok_response
|
7
|
-
|
7
|
+
opts_pull = opts.merge(:local_branch => branch,:namespace => module_namespace)
|
8
|
+
Helper(:git_repo).pull_changes(module_type,module_name,opts_pull)
|
8
9
|
end
|
9
10
|
end
|
10
11
|
end
|
@@ -17,7 +17,8 @@ module DTK::Client
|
|
17
17
|
)
|
18
18
|
response = post(rest_url("#{module_type}/get_remote_module_info"),post_body)
|
19
19
|
return response unless response.ok?
|
20
|
-
|
20
|
+
|
21
|
+
module_name,full_module_name = response.data(:module_name,:full_module_name)
|
21
22
|
remote_params = response.data_hash_form(:remote_repo_url,:remote_repo,:remote_branch)
|
22
23
|
remote_params.merge!(:version => version) if version
|
23
24
|
|
@@ -26,13 +27,15 @@ module DTK::Client
|
|
26
27
|
import_module_component_dependencies(module_id,remote_namespace)
|
27
28
|
end
|
28
29
|
# check whether a local module exists to determine whether pull from local clone or try to pull from server
|
29
|
-
if Helper(:git_repo).
|
30
|
+
if Helper(:git_repo).local_clone_dir_exists?(module_type,module_name,:full_module_name=>full_module_name,:version=>version)
|
30
31
|
unless rsa_pub_key
|
31
32
|
raise DtkError,"No File found at (#{path_to_key}). Path is wrong or it is necessary to generate the public rsa key (e.g., run ssh-keygen -t rsa)"
|
32
33
|
end
|
33
|
-
|
34
|
+
opts_perform_locally = remote_params.merge(:full_module_name => full_module_name)
|
35
|
+
PullFromRemote.perform_locally(self,module_type,module_id,module_name,opts_perform_locally)
|
34
36
|
else
|
35
|
-
|
37
|
+
# TODO: see if this works correctly
|
38
|
+
PullFromRemote.perform_on_server(self,module_type,module_id,full_module_name,remote_params)
|
36
39
|
end
|
37
40
|
end
|
38
41
|
|
@@ -52,10 +55,11 @@ module DTK::Client
|
|
52
55
|
print "Resolving dependencies please wait ... "
|
53
56
|
|
54
57
|
if (response.ok? && !(missing_components = response.data(:missing_modules)).empty?)
|
58
|
+
required_modules = response.data(:required_modules)
|
55
59
|
puts " New dependencies found, Installing."
|
56
60
|
|
57
61
|
module_opts = {:module_type => 'component-module'}
|
58
|
-
trigger_module_component_import(missing_components, module_opts)
|
62
|
+
trigger_module_component_import(missing_components, required_modules, module_opts)
|
59
63
|
|
60
64
|
puts "Resuming pull from remote ..."
|
61
65
|
else
|
@@ -9,12 +9,12 @@ module DTK::Client
|
|
9
9
|
if opts[:delete_all_versions]
|
10
10
|
dirs_to_delete += OsUtil.module_version_locations(module_type,module_name,version,opts)
|
11
11
|
end
|
12
|
-
response = Response::Ok.new()
|
12
|
+
response = Response::Ok.new()
|
13
13
|
pwd = Dir.getwd()
|
14
14
|
dirs_to_delete.each do |dir|
|
15
15
|
if File.directory?(dir)
|
16
16
|
if ((pwd == dir) || (pwd.include?("#{dir}/")))
|
17
|
-
OsUtil.print("Local directory '#{dir}' is not deleted because it is your current working directory.", :yellow)
|
17
|
+
OsUtil.print("Local directory '#{dir}' is not deleted because it is your current working directory.", :yellow)
|
18
18
|
else
|
19
19
|
FileUtils.rm_rf(dir)
|
20
20
|
end
|
@@ -6,13 +6,14 @@ module DTK::Client
|
|
6
6
|
include CommonMixin
|
7
7
|
##
|
8
8
|
#
|
9
|
-
# module_type: will be :component_module or :service_module
|
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,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
|
-
|
15
|
-
|
14
|
+
full_module_name = ModuleUtil.resolve_name(module_name, module_namespace)
|
15
|
+
module_location = OsUtil.module_location(module_type,full_module_name,version,opts)
|
16
|
+
|
16
17
|
unless File.directory?(module_location)
|
17
18
|
if Console.confirmation_prompt("Push not possible, module '#{module_name}#{version && "-#{version}"}' has not been cloned. Would you like to clone module now"+'?')
|
18
19
|
clone_aux(module_type,module_id, version, true, true, opts)
|
@@ -22,7 +23,7 @@ module DTK::Client
|
|
22
23
|
end
|
23
24
|
|
24
25
|
push_opts = opts.merge(:commit_msg => commit_msg, :local_branch => branch)
|
25
|
-
response = Helper(:git_repo).push_changes(module_type,
|
26
|
+
response = Helper(:git_repo).push_changes(module_type,full_module_name,version,push_opts)
|
26
27
|
return response unless response.ok?
|
27
28
|
|
28
29
|
json_diffs = (response.data(:diffs).empty? ? {} : JSON.generate(response.data(:diffs)))
|
@@ -35,21 +36,43 @@ module DTK::Client
|
|
35
36
|
|
36
37
|
response = post(rest_url("#{module_type}/update_model_from_clone"),post_body)
|
37
38
|
return response unless response.ok?
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
|
40
|
+
ret = Response::Ok.new()
|
41
|
+
|
42
|
+
# check if any errors
|
43
|
+
if dsl_parsed_info = response.data(:dsl_parsed_info)
|
44
|
+
if dsl_parsed_message = ServiceImporter.error_message(module_name, dsl_parsed_info)
|
45
|
+
DTK::Client::OsUtil.print(dsl_parsed_message, :red)
|
46
|
+
ret = Response::NoOp.new()
|
47
|
+
end
|
43
48
|
end
|
44
49
|
|
45
|
-
if
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
+
# check if server pushed anything that needs to be pulled
|
51
|
+
dsl_updated_info = response.data(:dsl_updated_info)
|
52
|
+
if dsl_updated_info and !dsl_updated_info.empty?
|
53
|
+
if msg = dsl_updated_info["msg"]
|
54
|
+
DTK::Client::OsUtil.print(msg,:yellow)
|
55
|
+
end
|
56
|
+
new_commit_sha = dsl_updated_info[:commit_sha]
|
57
|
+
unless new_commit_sha and new_commit_sha == commit_sha
|
58
|
+
opts_pull = opts.merge(:local_branch => branch,:namespace => module_namespace)
|
59
|
+
response = Helper(:git_repo).pull_changes(module_type,module_name,opts_pull)
|
60
|
+
return response unless response.ok?
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# check if server sent any file that should be added
|
65
|
+
dsl_created_info = response.data(:dsl_created_info)
|
66
|
+
if dsl_created_info and !dsl_created_info.empty?
|
67
|
+
path = dsl_created_info["path"]
|
68
|
+
content = dsl_created_info["content"]
|
69
|
+
if path and content
|
70
|
+
msg = "A #{path} file has been created for you, located at #{repo_obj.repo_dir}"
|
71
|
+
response = Helper(:git_repo).add_file(path,content,msg)
|
72
|
+
return response unless response.ok?
|
50
73
|
end
|
51
74
|
end
|
52
|
-
|
75
|
+
ret
|
53
76
|
end
|
54
77
|
end
|
55
78
|
end
|