dtk-client 0.5.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/Gemfile +5 -0
- data/Gemfile_dev +12 -0
- data/README.md +78 -0
- data/bin/dtk +54 -0
- data/bin/dtk-shell +15 -0
- data/dtk-client.gemspec +49 -0
- data/lib/auxiliary.rb +13 -0
- data/lib/bundler_monkey_patch.rb +9 -0
- data/lib/client.rb +48 -0
- data/lib/command_helper.rb +16 -0
- data/lib/command_helpers/git_repo.rb +391 -0
- data/lib/command_helpers/jenkins_client/config_xml.rb +271 -0
- data/lib/command_helpers/jenkins_client.rb +91 -0
- data/lib/command_helpers/service_importer.rb +99 -0
- data/lib/command_helpers/service_link.rb +18 -0
- data/lib/command_helpers/ssh_processing.rb +43 -0
- data/lib/commands/common/thor/assembly_workspace.rb +1089 -0
- data/lib/commands/common/thor/clone.rb +39 -0
- data/lib/commands/common/thor/common.rb +34 -0
- data/lib/commands/common/thor/edit.rb +168 -0
- data/lib/commands/common/thor/list_diffs.rb +84 -0
- data/lib/commands/common/thor/pull_clone_changes.rb +11 -0
- data/lib/commands/common/thor/pull_from_remote.rb +99 -0
- data/lib/commands/common/thor/purge_clone.rb +26 -0
- data/lib/commands/common/thor/push_clone_changes.rb +45 -0
- data/lib/commands/common/thor/push_to_remote.rb +45 -0
- data/lib/commands/common/thor/reparse.rb +36 -0
- data/lib/commands/common/thor/set_required_params.rb +29 -0
- data/lib/commands/common/thor/task_status.rb +81 -0
- data/lib/commands/thor/account.rb +213 -0
- data/lib/commands/thor/assembly.rb +329 -0
- data/lib/commands/thor/attribute.rb +62 -0
- data/lib/commands/thor/component.rb +52 -0
- data/lib/commands/thor/component_module.rb +829 -0
- data/lib/commands/thor/component_template.rb +153 -0
- data/lib/commands/thor/dependency.rb +18 -0
- data/lib/commands/thor/developer.rb +105 -0
- data/lib/commands/thor/dtk.rb +117 -0
- data/lib/commands/thor/library.rb +107 -0
- data/lib/commands/thor/node.rb +411 -0
- data/lib/commands/thor/node_group.rb +211 -0
- data/lib/commands/thor/node_template.rb +88 -0
- data/lib/commands/thor/project.rb +17 -0
- data/lib/commands/thor/provider.rb +155 -0
- data/lib/commands/thor/repo.rb +35 -0
- data/lib/commands/thor/service.rb +656 -0
- data/lib/commands/thor/service_module.rb +806 -0
- data/lib/commands/thor/state_change.rb +10 -0
- data/lib/commands/thor/target.rb +94 -0
- data/lib/commands/thor/task.rb +100 -0
- data/lib/commands/thor/utils.rb +4 -0
- data/lib/commands/thor/workspace.rb +437 -0
- data/lib/commands.rb +40 -0
- data/lib/config/cacert.pem +3785 -0
- data/lib/config/client.conf.header +18 -0
- data/lib/config/configuration.rb +82 -0
- data/lib/config/default.conf +14 -0
- data/lib/config/disk_cacher.rb +60 -0
- data/lib/configurator.rb +92 -0
- data/lib/context_router.rb +23 -0
- data/lib/core.rb +460 -0
- data/lib/domain/git_adapter.rb +221 -0
- data/lib/domain/response.rb +234 -0
- data/lib/dtk-client/version.rb +3 -0
- data/lib/dtk_constants.rb +23 -0
- data/lib/dtk_logger.rb +96 -0
- data/lib/error.rb +74 -0
- data/lib/git-logs/git.log +0 -0
- data/lib/parser/adapters/option_parser.rb +53 -0
- data/lib/parser/adapters/thor/common_option_defs.rb +12 -0
- data/lib/parser/adapters/thor.rb +509 -0
- data/lib/require_first.rb +87 -0
- data/lib/search_hash.rb +27 -0
- data/lib/shell/context.rb +975 -0
- data/lib/shell/context_aux.rb +29 -0
- data/lib/shell/domain.rb +447 -0
- data/lib/shell/header_shell.rb +27 -0
- data/lib/shell/help_monkey_patch.rb +221 -0
- data/lib/shell/interactive_wizard.rb +233 -0
- data/lib/shell/parse_monkey_patch.rb +22 -0
- data/lib/shell/status_monitor.rb +105 -0
- data/lib/shell.rb +219 -0
- data/lib/util/console.rb +143 -0
- data/lib/util/dtk_puppet.rb +46 -0
- data/lib/util/os_util.rb +265 -0
- data/lib/view_processor/augmented_simple_list.rb +27 -0
- data/lib/view_processor/hash_pretty_print.rb +106 -0
- data/lib/view_processor/simple_list.rb +139 -0
- data/lib/view_processor/table_print.rb +277 -0
- data/lib/view_processor.rb +112 -0
- data/puppet/manifests/init.pp +72 -0
- data/puppet/manifests/params.pp +16 -0
- data/puppet/r8meta.puppet.yml +18 -0
- data/puppet/templates/bash_profile.erb +2 -0
- data/puppet/templates/client.conf.erb +1 -0
- data/puppet/templates/dtkclient.erb +2 -0
- data/spec/assembly_spec.rb +50 -0
- data/spec/assembly_template_spec.rb +51 -0
- data/spec/component_template_spec.rb +40 -0
- data/spec/dependency_spec.rb +6 -0
- data/spec/dtk_shell_spec.rb +13 -0
- data/spec/dtk_spec.rb +33 -0
- data/spec/lib/spec_helper.rb +10 -0
- data/spec/lib/spec_thor.rb +105 -0
- data/spec/module_spec.rb +35 -0
- data/spec/node_spec.rb +43 -0
- data/spec/node_template_spec.rb +25 -0
- data/spec/project_spec.rb +6 -0
- data/spec/repo_spec.rb +7 -0
- data/spec/response_spec.rb +52 -0
- data/spec/service_spec.rb +41 -0
- data/spec/state_change_spec.rb +7 -0
- data/spec/table_print_spec.rb +48 -0
- data/spec/target_spec.rb +57 -0
- data/spec/task_spec.rb +28 -0
- data/views/assembly/augmented_simple_list.rb +12 -0
- data/views/assembly_template/augmented_simple_list.rb +12 -0
- data/views/list_task/augmented_simple_list.rb +12 -0
- metadata +351 -0
@@ -0,0 +1,39 @@
|
|
1
|
+
dtk_require_common_commands('thor/common')
|
2
|
+
module DTK::Client
|
3
|
+
module CloneMixin
|
4
|
+
extend Console
|
5
|
+
include CommonMixin
|
6
|
+
##
|
7
|
+
#
|
8
|
+
# internal_trigger: this flag means that other method (internal) has trigger this.
|
9
|
+
# This will change behaviour of method
|
10
|
+
# module_type: will be :component_module or :service_module
|
11
|
+
|
12
|
+
def clone_aux(module_type,module_id,version,internal_trigger,omit_output=false,opts={})
|
13
|
+
module_name,repo_url,branch,not_ok_response = workspace_branch_info(module_type,module_id,version,opts)
|
14
|
+
return not_ok_response if not_ok_response
|
15
|
+
response = Helper(:git_repo).create_clone_with_branch(module_type,module_name,repo_url,branch,version,opts)
|
16
|
+
|
17
|
+
if response.ok?
|
18
|
+
puts "Module '#{module_name}' has been successfully cloned!" unless omit_output
|
19
|
+
unless internal_trigger
|
20
|
+
if Console.confirmation_prompt("Would you like to edit cloned module now?")
|
21
|
+
if module_type.to_s.start_with?("service")
|
22
|
+
context_params_for_module = create_context_for_module(module_name, :"service-module")
|
23
|
+
else
|
24
|
+
context_params_for_module = create_context_for_module(module_name, :"component-module")
|
25
|
+
end
|
26
|
+
return edit(context_params_for_module)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
response
|
31
|
+
end
|
32
|
+
|
33
|
+
def create_context_for_module(module_name, module_type)
|
34
|
+
context_params_for_module = DTK::Shell::ContextParams.new
|
35
|
+
context_params_for_module.add_context_to_params(module_name, "#{module_type}", module_name)
|
36
|
+
return context_params_for_module
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module DTK::Client
|
2
|
+
module CommonMixin
|
3
|
+
private
|
4
|
+
#returns module_name,repo_url,branch,not_ok_response( only if error)
|
5
|
+
def workspace_branch_info(module_type,module_id,version,opts={})
|
6
|
+
if info = opts[:workspace_branch_info]
|
7
|
+
[info[:module_name],info[:repo_url],info[:branch]]
|
8
|
+
else
|
9
|
+
post_body = get_workspace_branch_info_post_body(module_type,module_id,version,opts)
|
10
|
+
response = post(rest_url("#{module_type}/get_workspace_branch_info"),post_body)
|
11
|
+
unless response.ok?
|
12
|
+
[nil,nil,nil,response]
|
13
|
+
else
|
14
|
+
response.data(:module_name,:repo_url,:workspace_branch)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_workspace_branch_info_post_body(module_type,module_id,version_explicit,opts={})
|
20
|
+
id_field = "#{module_type}_id"
|
21
|
+
post_body = {
|
22
|
+
id_field => module_id
|
23
|
+
}
|
24
|
+
assembly_module = opts[:assembly_module]
|
25
|
+
if version = version_explicit||(assembly_module && assembly_module[:version])
|
26
|
+
post_body.merge!(:version => version)
|
27
|
+
end
|
28
|
+
if assembly_module
|
29
|
+
post_body.merge!(:assembly_module => true,:assembly_name => assembly_module[:assembly_name])
|
30
|
+
end
|
31
|
+
post_body
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,168 @@
|
|
1
|
+
dtk_require_common_commands('thor/clone')
|
2
|
+
dtk_require_common_commands('thor/push_clone_changes')
|
3
|
+
dtk_require_common_commands('thor/pull_clone_changes')
|
4
|
+
dtk_require_common_commands('thor/reparse')
|
5
|
+
require 'yaml'
|
6
|
+
|
7
|
+
module DTK::Client
|
8
|
+
module EditMixin
|
9
|
+
include CloneMixin
|
10
|
+
include PushCloneChangesMixin
|
11
|
+
include PullCloneChangesMixin
|
12
|
+
include ReparseMixin
|
13
|
+
|
14
|
+
##
|
15
|
+
#
|
16
|
+
# module_type: will be one of
|
17
|
+
# :component_module
|
18
|
+
# :service_module
|
19
|
+
def edit_aux(module_type,module_id,module_name,version,opts={})
|
20
|
+
module_location = OsUtil.module_location(module_type,module_name,version,opts)
|
21
|
+
|
22
|
+
pull_if_needed = opts[:pull_if_needed]
|
23
|
+
# check if there is repository cloned
|
24
|
+
unless File.directory?(module_location)
|
25
|
+
if opts[:automatically_clone] or Console.confirmation_prompt("Edit not possible, module '#{module_name}#{version && "-#{version}"}' has not been cloned. Would you like to clone module now"+'?')
|
26
|
+
internal_trigger = true
|
27
|
+
omit_output = true
|
28
|
+
response = clone_aux(module_type,module_id,version,internal_trigger,omit_output,opts)
|
29
|
+
# if error return
|
30
|
+
return response unless response.ok?
|
31
|
+
pull_if_needed = false
|
32
|
+
else
|
33
|
+
# user choose not to clone needed module
|
34
|
+
return
|
35
|
+
end
|
36
|
+
end
|
37
|
+
# here we should have desired module cloned
|
38
|
+
|
39
|
+
if pull_if_needed
|
40
|
+
response = pull_clone_changes?(module_type,module_id,version,opts)
|
41
|
+
return response unless response.ok?
|
42
|
+
end
|
43
|
+
grit_adapter = Helper(:git_repo).create(module_location)
|
44
|
+
if edit_info = opts[:edit_file]
|
45
|
+
#TODO: cleanup so dont need :base_file_name
|
46
|
+
file_to_edit =
|
47
|
+
if edit_info.kind_of?(String)
|
48
|
+
edit_info
|
49
|
+
else #edit_info.kind_of?(Hash) and has key :base_file_name
|
50
|
+
base_file = edit_info[:base_file_name]
|
51
|
+
(File.exists?("#{module_location}/#{base_file}.yaml") ? "#{base_file}.yaml" : "#{base_file}.json")
|
52
|
+
end
|
53
|
+
OsUtil.edit("#{module_location}/#{file_to_edit}")
|
54
|
+
OsUtil.print("If you want to use different editor please set environment variable EDITOR and log back into dtk-shell!", :yellow) unless ENV['EDITOR']
|
55
|
+
else
|
56
|
+
Console.unix_shell(module_location, module_id, module_type, version)
|
57
|
+
end
|
58
|
+
|
59
|
+
unless grit_adapter.changed?
|
60
|
+
puts "No changes to repository"
|
61
|
+
return Response::Ok.new()
|
62
|
+
end
|
63
|
+
|
64
|
+
unless file_to_edit
|
65
|
+
grit_adapter.print_status
|
66
|
+
end
|
67
|
+
|
68
|
+
# check to see if auto commit flag
|
69
|
+
auto_commit = ::DTK::Configuration.get(:auto_commit_changes)
|
70
|
+
confirmed_ok = false
|
71
|
+
|
72
|
+
# if there is no auto commit ask for confirmation
|
73
|
+
unless auto_commit
|
74
|
+
confirm_msg =
|
75
|
+
if file_to_edit
|
76
|
+
"Would you like to commit changes to the file?"
|
77
|
+
else
|
78
|
+
"Would you like to commit and push ALL the changes?"
|
79
|
+
end
|
80
|
+
confirmed_ok = Console.confirmation_prompt(confirm_msg)
|
81
|
+
end
|
82
|
+
|
83
|
+
if (auto_commit || confirmed_ok)
|
84
|
+
if auto_commit
|
85
|
+
puts "[NOTICE] You are using auto-commit option, all changes you have made will be commited."
|
86
|
+
end
|
87
|
+
commit_msg = user_input("Commit message")
|
88
|
+
internal_trigger=true
|
89
|
+
reparse_aux(module_location)
|
90
|
+
response = push_clone_changes_aux(module_type,module_id,version,commit_msg,internal_trigger,opts)
|
91
|
+
# if error return
|
92
|
+
return response unless response.ok?
|
93
|
+
end
|
94
|
+
|
95
|
+
#TODO: temporary took out; wil put back in
|
96
|
+
#puts "DTK SHELL TIP: Adding the client configuration parameter <config param name>=true will have the client automatically commit each time you exit edit mode" unless auto_commit
|
97
|
+
Response::Ok.new()
|
98
|
+
end
|
99
|
+
|
100
|
+
def attribute_header()
|
101
|
+
header_string =
|
102
|
+
"#############################\n#### REQUIRED ATTRIBUTES\n#############################\n#\n"
|
103
|
+
end
|
104
|
+
|
105
|
+
def attributes_editor(attributes,format)
|
106
|
+
if (format.eql?('yaml'))
|
107
|
+
dtk_folder = OsUtil.dtk_local_folder
|
108
|
+
file_path = "#{dtk_folder}/temp_attrs.yaml"
|
109
|
+
|
110
|
+
first_iteration_keys, first_iteration_values = [], []
|
111
|
+
second_iteration_keys, second_iteration_values = [], []
|
112
|
+
required_attributes = []
|
113
|
+
|
114
|
+
attribute_pairs = YAML.load(attributes)
|
115
|
+
|
116
|
+
attribute_pairs.each do |k,v|
|
117
|
+
first_iteration_keys << k
|
118
|
+
|
119
|
+
#prepare required attributes for editor display
|
120
|
+
if v.eql?("*REQUIRED*")
|
121
|
+
required_attributes << k
|
122
|
+
attribute_pairs[k] = nil
|
123
|
+
v = nil
|
124
|
+
end
|
125
|
+
|
126
|
+
first_iteration_values << v
|
127
|
+
end
|
128
|
+
|
129
|
+
File.open(file_path, 'w') do |out|
|
130
|
+
# print out required attributes
|
131
|
+
unless required_attributes.empty?
|
132
|
+
out.write(attribute_header())
|
133
|
+
required_attributes.each do |req_attr|
|
134
|
+
out.write("##{req_attr}\n")
|
135
|
+
end
|
136
|
+
out.write("#\n")
|
137
|
+
end
|
138
|
+
|
139
|
+
YAML.dump(attribute_pairs, out)
|
140
|
+
end
|
141
|
+
|
142
|
+
OsUtil.edit(file_path)
|
143
|
+
OsUtil.print("If you want to use different editor please set environment variable EDITOR and log back into dtk-shell!", :yellow) unless ENV['EDITOR']
|
144
|
+
begin
|
145
|
+
edited = YAML.load_file(file_path)
|
146
|
+
rescue Psych::SyntaxError => e
|
147
|
+
raise DTK::Client::DSLParsing::YAMLParsing.new("YAML parsing error #{e} in file",file_path)
|
148
|
+
end
|
149
|
+
|
150
|
+
edited.each do |k,v|
|
151
|
+
second_iteration_keys << k
|
152
|
+
second_iteration_values << v
|
153
|
+
end
|
154
|
+
|
155
|
+
unless first_iteration_keys == second_iteration_keys
|
156
|
+
edited_keys = second_iteration_keys.select{|k| !first_iteration_keys.include?(k)}
|
157
|
+
raise DtkValidationError, "You have changed key(s) '#{edited_keys}'. We do not support key editing yet!"
|
158
|
+
end
|
159
|
+
|
160
|
+
raise DtkValidationError, "No attribute changes have been made." if ((first_iteration_keys == second_iteration_keys) && (first_iteration_values == second_iteration_values))
|
161
|
+
edited
|
162
|
+
else
|
163
|
+
raise DTK::Client::DtkValidationError, "Unsupported format type '#{format.to_s}'!"
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
168
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module DTK::Client
|
2
|
+
module ListDiffsMixin
|
3
|
+
def list_diffs_aux(module_type,module_id,remote,version=nil)
|
4
|
+
id_field = "#{module_type}_id"
|
5
|
+
path_to_key = SshProcessing.default_rsa_pub_key_path()
|
6
|
+
rsa_pub_key = File.file?(path_to_key) && File.open(path_to_key){|f|f.read}.chomp
|
7
|
+
|
8
|
+
post_body = {
|
9
|
+
id_field => module_id,
|
10
|
+
:access_rights => "r",
|
11
|
+
:action => "pull"
|
12
|
+
}
|
13
|
+
post_body.merge!(:version => version) if version
|
14
|
+
post_body.merge!(:rsa_pub_key => rsa_pub_key) if rsa_pub_key
|
15
|
+
|
16
|
+
response = post(rest_url("#{module_type}/get_remote_module_info"),post_body)
|
17
|
+
return response unless response.ok?
|
18
|
+
|
19
|
+
module_name = response.data(:module_name)
|
20
|
+
opts = {
|
21
|
+
:remote_repo_url => response.data(:remote_repo_url),
|
22
|
+
:remote_repo => response.data(:remote_repo),
|
23
|
+
:remote_branch => response.data(:remote_branch),
|
24
|
+
:local_branch => response.data(:workspace_branch)
|
25
|
+
}
|
26
|
+
version = response.data(:version)
|
27
|
+
|
28
|
+
response = Helper(:git_repo).get_diffs(module_type,module_name,version,opts)
|
29
|
+
return response unless response.ok?
|
30
|
+
|
31
|
+
added, deleted, modified = print_diffs(response.data(remote ? :diffs : :status), remote)
|
32
|
+
|
33
|
+
raise DTK::Client::DtkValidationError, "There is no changes in current workspace!" if(added.empty? && deleted.empty? && modified.empty?)
|
34
|
+
|
35
|
+
unless added.empty?
|
36
|
+
puts "ADDED:"
|
37
|
+
added.each do |a|
|
38
|
+
puts "\t #{a.inspect}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
unless deleted.empty?
|
43
|
+
puts "DELETED:"
|
44
|
+
deleted.each do |d|
|
45
|
+
puts "\t #{d.inspect}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
unless modified.empty?
|
50
|
+
puts "MODIFIED:"
|
51
|
+
modified.each do |m|
|
52
|
+
puts "\t #{m.inspect}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def print_diffs(response, remote)
|
58
|
+
added = []
|
59
|
+
deleted = []
|
60
|
+
modified = []
|
61
|
+
|
62
|
+
unless response[:files_modified].nil?
|
63
|
+
response[:files_modified].each do |file|
|
64
|
+
modified << file[:path]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
unless response[:files_deleted].nil?
|
69
|
+
response[:files_deleted].each do |file|
|
70
|
+
deleted << file[:path]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
unless response[:files_added].nil?
|
75
|
+
response[:files_added].each do |file|
|
76
|
+
added << file[:path]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
return added, deleted, modified
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
dtk_require_common_commands('thor/common')
|
2
|
+
module DTK::Client
|
3
|
+
module PullCloneChangesMixin
|
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)
|
6
|
+
return not_ok_response if not_ok_response
|
7
|
+
Helper(:git_repo).pull_changes(module_type,module_name,opts.merge(:local_branch => branch))
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
@@ -0,0 +1,99 @@
|
|
1
|
+
module DTK::Client
|
2
|
+
module PullFromRemoteMixin
|
3
|
+
|
4
|
+
##
|
5
|
+
#
|
6
|
+
# module_type: will be :component_module or :service_module
|
7
|
+
def import_module_component_dependencies(module_id)
|
8
|
+
post_body = {
|
9
|
+
:service_module_id => module_id
|
10
|
+
}
|
11
|
+
response = post(rest_url("service_module/resolve_pull_from_remote"),post_body)
|
12
|
+
|
13
|
+
print "Resolving dependencies please wait ... "
|
14
|
+
|
15
|
+
if (response.ok? && !(missing_components = response.data(:missing_modules)).empty?)
|
16
|
+
puts " New dependencies found, Installing."
|
17
|
+
|
18
|
+
trigger_module_component_import(missing_components)
|
19
|
+
puts "Resuming pull from remote ..."
|
20
|
+
else
|
21
|
+
puts 'Done.'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def pull_from_remote_aux(module_type,module_id,version=nil)
|
26
|
+
#get remote module info, errors raised if remote is not linked or access errors
|
27
|
+
path_to_key = SshProcessing.default_rsa_pub_key_path()
|
28
|
+
rsa_pub_key = File.file?(path_to_key) && File.open(path_to_key){|f|f.read}.chomp
|
29
|
+
|
30
|
+
post_body = {
|
31
|
+
PullFromRemote.id_field(module_type) => module_id,
|
32
|
+
:access_rights => "r",
|
33
|
+
:action => "pull"
|
34
|
+
}
|
35
|
+
post_body.merge!(:version => version) if version
|
36
|
+
post_body.merge!(:rsa_pub_key => rsa_pub_key) if rsa_pub_key
|
37
|
+
response = post(rest_url("#{module_type}/get_remote_module_info"),post_body)
|
38
|
+
return response unless response.ok?
|
39
|
+
module_name = response.data(:module_name)
|
40
|
+
remote_params = response.data_hash_form(:remote_repo_url,:remote_repo,:remote_branch)
|
41
|
+
remote_params.merge!(:version => version) if version
|
42
|
+
|
43
|
+
#check and import component module dependencies before importing service itself
|
44
|
+
import_module_component_dependencies(module_id) if (module_type == :service_module)
|
45
|
+
|
46
|
+
# check whether a local module exists to determine whether pull from local clone or try to pull from server
|
47
|
+
if Helper(:git_repo).local_clone_exists?(module_type,module_name,version)
|
48
|
+
unless rsa_pub_key
|
49
|
+
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)"
|
50
|
+
end
|
51
|
+
PullFromRemote.perform_locally(self,module_type,module_id,module_name,remote_params)
|
52
|
+
else
|
53
|
+
PullFromRemote.perform_on_server(self,module_type,module_id,module_name,remote_params)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
private
|
57
|
+
module PullFromRemote
|
58
|
+
extend CommandBase
|
59
|
+
def self.perform_locally(cmd_obj,module_type,module_id,module_name,remote_params)
|
60
|
+
opts = remote_params
|
61
|
+
response = cmd_obj.Helper(:git_repo).pull_changes(module_type,module_name,opts)
|
62
|
+
# return response unless response.ok?
|
63
|
+
|
64
|
+
if response.data[:diffs].empty?
|
65
|
+
raise DtkError, "No changes to pull from remote"
|
66
|
+
end
|
67
|
+
|
68
|
+
return response
|
69
|
+
|
70
|
+
# removing this for now, because we will use push-clone-changes as part of pull-from-remote command
|
71
|
+
# post_body = {
|
72
|
+
# id_field(module_type) => module_id,
|
73
|
+
# :commit_sha => response.data[:commit_sha],
|
74
|
+
# :json_diffs => JSON.generate(response.data[:diffs])
|
75
|
+
# }
|
76
|
+
# post rest_url("#{module_type}/update_model_from_clone"), post_body
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.perform_on_server(cmd_obj,module_type,module_id,module_name,remote_params)
|
80
|
+
post_body = {
|
81
|
+
id_field(module_type) => module_id,
|
82
|
+
:remote_repo => remote_params[:remote_repo],
|
83
|
+
:module_name => module_name
|
84
|
+
}
|
85
|
+
post_body.merge!(:version => remote_params[:version]) if remote_params[:version]
|
86
|
+
response = post rest_url("#{module_type}/pull_from_remote"), post_body
|
87
|
+
|
88
|
+
|
89
|
+
puts "You have successfully pulled code on server instance." if response.ok?
|
90
|
+
response
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.id_field(module_type)
|
94
|
+
"#{module_type}_id"
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module DTK::Client
|
2
|
+
module PurgeCloneMixin
|
3
|
+
def purge_clone_aux(module_type,opts={})
|
4
|
+
module_name = opts[:module_name]
|
5
|
+
version = opts[:version]
|
6
|
+
opts_module_loc = (opts[:assembly_module] ? {:assembly_module => opts[:assembly_module]} : Hash.new)
|
7
|
+
module_location = OsUtil.module_location(module_type,module_name,version,opts_module_loc)
|
8
|
+
dirs_to_delete = [module_location]
|
9
|
+
if opts[:delete_all_versions]
|
10
|
+
dirs_to_delete += OsUtil.module_version_locations(module_type,module_name,version,opts)
|
11
|
+
end
|
12
|
+
response = Response::Ok.new()
|
13
|
+
pwd = Dir.getwd()
|
14
|
+
dirs_to_delete.each do |dir|
|
15
|
+
if File.directory?(dir)
|
16
|
+
if ((pwd == dir) || (pwd.include?("#{dir}/")))
|
17
|
+
OsUtil.print("Local directory '#{dir}' is not deleted because it is your current working directory.", :yellow)
|
18
|
+
else
|
19
|
+
FileUtils.rm_rf(dir)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
response
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
dtk_require_common_commands('thor/common')
|
2
|
+
dtk_require_from_base('command_helpers/service_importer')
|
3
|
+
|
4
|
+
module DTK::Client
|
5
|
+
module PushCloneChangesMixin
|
6
|
+
include CommonMixin
|
7
|
+
##
|
8
|
+
#
|
9
|
+
# module_type: will be :component_module or :service_module
|
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)
|
12
|
+
return not_ok_response if not_ok_response
|
13
|
+
|
14
|
+
push_opts = opts.merge(:commit_msg => commit_msg, :local_branch => branch)
|
15
|
+
response = Helper(:git_repo).push_changes(module_type,module_name,version,push_opts)
|
16
|
+
return response unless response.ok?
|
17
|
+
|
18
|
+
json_diffs = (response.data(:diffs).empty? ? {} : JSON.generate(response.data(:diffs)))
|
19
|
+
commit_sha = response.data(:commit_sha)
|
20
|
+
repo_obj = response.data(:repo_obj)
|
21
|
+
json_diffs = JSON.generate(response.data(:diffs))
|
22
|
+
post_body = get_workspace_branch_info_post_body(module_type,module_id,version,opts).merge(:json_diffs => json_diffs, :commit_sha => commit_sha)
|
23
|
+
post_body.merge!(:modification_type => opts[:modification_type]) if opts[:modification_type]
|
24
|
+
post_body.merge!(:force_parse => true) if options['force-parse']
|
25
|
+
|
26
|
+
response = post(rest_url("#{module_type}/update_model_from_clone"),post_body)
|
27
|
+
return response unless response.ok?
|
28
|
+
|
29
|
+
if (!response.data.empty? && response.data(:dsl_parsed_info))
|
30
|
+
dsl_parsed_message = ServiceImporter.error_message(module_name, response.data(:dsl_parsed_info))
|
31
|
+
DTK::Client::OsUtil.print(dsl_parsed_message, :red)
|
32
|
+
return Response::NoOp.new() #NoOp fine because error reported by section above
|
33
|
+
end
|
34
|
+
|
35
|
+
if module_type == :component_module
|
36
|
+
dsl_created_info = response.data(:dsl_created_info)
|
37
|
+
if dsl_created_info and !dsl_created_info.empty?
|
38
|
+
msg = "A #{dsl_created_info["path"]} file has been created for you, located at #{repo_obj.repo_dir}"
|
39
|
+
return Helper(:git_repo).add_file(repo_obj,dsl_created_info["path"],dsl_created_info["content"],msg)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
Response::Ok.new()
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module DTK::Client
|
2
|
+
module PushToRemoteMixin
|
3
|
+
|
4
|
+
##
|
5
|
+
#
|
6
|
+
# module_type: will be :component_module or :service_module
|
7
|
+
|
8
|
+
def push_to_remote_aux(module_type,module_id, module_name,remote_namespace,version=nil)
|
9
|
+
id_field = "#{module_type}_id"
|
10
|
+
|
11
|
+
rsa_pub_value = SshProcessing.rsa_pub_key_content()
|
12
|
+
|
13
|
+
post_body = {
|
14
|
+
id_field => module_id,
|
15
|
+
:rsa_pub_key => rsa_pub_value,
|
16
|
+
:access_rights => "rw",
|
17
|
+
:action => "push"
|
18
|
+
}
|
19
|
+
post_body.merge!(:version => version) if version
|
20
|
+
post_body.merge!(:remote_namespace => remote_namespace) if remote_namespace
|
21
|
+
response = post(rest_url("#{module_type}/get_remote_module_info"),post_body)
|
22
|
+
|
23
|
+
return response unless response.ok?
|
24
|
+
|
25
|
+
returned_module_name = response.data(:module_name)
|
26
|
+
opts = {
|
27
|
+
:remote_repo_url => response.data(:remote_repo_url),
|
28
|
+
:remote_repo => response.data(:remote_repo),
|
29
|
+
:remote_branch => response.data(:remote_branch),
|
30
|
+
:local_branch => response.data(:workspace_branch)
|
31
|
+
}
|
32
|
+
|
33
|
+
version = response.data(:version)
|
34
|
+
|
35
|
+
response = Helper(:git_repo).push_changes(module_type,returned_module_name,version,opts)
|
36
|
+
return response unless response.ok?
|
37
|
+
if response.data(:diffs).empty?
|
38
|
+
raise DtkError, "No changes to push"
|
39
|
+
end
|
40
|
+
|
41
|
+
Response::Ok.new()
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module DTK::Client
|
5
|
+
module ReparseMixin
|
6
|
+
|
7
|
+
##
|
8
|
+
#
|
9
|
+
# module_type: will be :component_module or :service_module
|
10
|
+
def reparse_aux(location)
|
11
|
+
files_json = Dir.glob("#{location}/**/*.json")
|
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
|
+
|
23
|
+
files_yaml.each do |file|
|
24
|
+
file_content = File.open(file).read
|
25
|
+
begin
|
26
|
+
YAML.load(file_content)
|
27
|
+
rescue Exception => e
|
28
|
+
raise DTK::Client::DSLParsing::YAMLParsing.new("YAML parsing error #{e} in file",file)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
Response::Ok.new()
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module DTK::Client
|
2
|
+
module SetRequiredParamsMixin
|
3
|
+
def set_required_params_aux(id,type,subtype=nil)
|
4
|
+
id_field = "#{type}_id".to_sym
|
5
|
+
post_body = {
|
6
|
+
id_field => id,
|
7
|
+
:subtype => 'instance',
|
8
|
+
:filter => 'required_unset_attributes'
|
9
|
+
}
|
10
|
+
post_body.merge!(:subtype => subtype.to_s) if subtype
|
11
|
+
response = post rest_url("#{type}/get_attributes"), post_body
|
12
|
+
return response unless response.ok?
|
13
|
+
missing_params = response.data
|
14
|
+
if missing_params.empty?
|
15
|
+
response.set_data('Message' => "No parameters to set.")
|
16
|
+
response
|
17
|
+
else
|
18
|
+
param_bindings = DTK::Shell::InteractiveWizard.resolve_missing_params(missing_params)
|
19
|
+
post_body = {
|
20
|
+
id_field => id,
|
21
|
+
:av_pairs_hash => param_bindings.inject(Hash.new){|h,r|h.merge(r[:id] => r[:value])}
|
22
|
+
}
|
23
|
+
response = post rest_url("#{type}/set_attributes"), post_body
|
24
|
+
return response unless response.ok?
|
25
|
+
response.data
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|