dtk-shell 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (191) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +5 -0
  3. data/Gemfile_dev +13 -0
  4. data/README.md +121 -0
  5. data/bin/dtk-execute +32 -0
  6. data/bin/dtk-run +92 -0
  7. data/bin/dtk-shell +31 -0
  8. data/dtk-shell.gemspec +50 -0
  9. data/lib/auxiliary.rb +61 -0
  10. data/lib/bundler_monkey_patch.rb +26 -0
  11. data/lib/client.rb +58 -0
  12. data/lib/command_helper.rb +33 -0
  13. data/lib/command_helpers/git_repo.rb +589 -0
  14. data/lib/command_helpers/git_repo/merge.rb +153 -0
  15. data/lib/command_helpers/jenkins_client.rb +106 -0
  16. data/lib/command_helpers/jenkins_client/config_xml.rb +288 -0
  17. data/lib/command_helpers/service_importer.rb +251 -0
  18. data/lib/command_helpers/service_link.rb +33 -0
  19. data/lib/command_helpers/test_module_creator.rb +69 -0
  20. data/lib/command_helpers/test_module_templates/dtk.model.yaml.eruby +10 -0
  21. data/lib/command_helpers/test_module_templates/spec_helper.rb.eruby +10 -0
  22. data/lib/command_helpers/test_module_templates/temp_component_spec.rb.eruby +5 -0
  23. data/lib/commands.rb +57 -0
  24. data/lib/commands/common/thor/access_control.rb +133 -0
  25. data/lib/commands/common/thor/action_result_handler.rb +74 -0
  26. data/lib/commands/common/thor/assembly_template.rb +92 -0
  27. data/lib/commands/common/thor/assembly_workspace.rb +1801 -0
  28. data/lib/commands/common/thor/base_command_helper.rb +59 -0
  29. data/lib/commands/common/thor/clone.rb +82 -0
  30. data/lib/commands/common/thor/common.rb +88 -0
  31. data/lib/commands/common/thor/common_base.rb +49 -0
  32. data/lib/commands/common/thor/create_target.rb +70 -0
  33. data/lib/commands/common/thor/edit.rb +255 -0
  34. data/lib/commands/common/thor/inventory_parser.rb +98 -0
  35. data/lib/commands/common/thor/list_diffs.rb +128 -0
  36. data/lib/commands/common/thor/module.rb +1011 -0
  37. data/lib/commands/common/thor/module/import.rb +210 -0
  38. data/lib/commands/common/thor/node.rb +53 -0
  39. data/lib/commands/common/thor/poller.rb +65 -0
  40. data/lib/commands/common/thor/pull_clone_changes.rb +28 -0
  41. data/lib/commands/common/thor/pull_from_remote.rb +152 -0
  42. data/lib/commands/common/thor/puppet_forge.rb +72 -0
  43. data/lib/commands/common/thor/purge_clone.rb +101 -0
  44. data/lib/commands/common/thor/push_clone_changes.rb +162 -0
  45. data/lib/commands/common/thor/push_to_remote.rb +94 -0
  46. data/lib/commands/common/thor/remotes.rb +71 -0
  47. data/lib/commands/common/thor/reparse.rb +40 -0
  48. data/lib/commands/common/thor/set_required_attributes.rb +46 -0
  49. data/lib/commands/thor/account.rb +239 -0
  50. data/lib/commands/thor/assembly.rb +356 -0
  51. data/lib/commands/thor/attribute.rb +79 -0
  52. data/lib/commands/thor/component.rb +70 -0
  53. data/lib/commands/thor/component_module.rb +501 -0
  54. data/lib/commands/thor/component_template.rb +174 -0
  55. data/lib/commands/thor/dependency.rb +34 -0
  56. data/lib/commands/thor/developer.rb +144 -0
  57. data/lib/commands/thor/dtk.rb +152 -0
  58. data/lib/commands/thor/library.rb +125 -0
  59. data/lib/commands/thor/node.rb +504 -0
  60. data/lib/commands/thor/node_template.rb +94 -0
  61. data/lib/commands/thor/project.rb +34 -0
  62. data/lib/commands/thor/provider.rb +233 -0
  63. data/lib/commands/thor/remotes.rb +49 -0
  64. data/lib/commands/thor/service.rb +941 -0
  65. data/lib/commands/thor/service_module.rb +914 -0
  66. data/lib/commands/thor/state_change.rb +25 -0
  67. data/lib/commands/thor/target.rb +250 -0
  68. data/lib/commands/thor/task.rb +116 -0
  69. data/lib/commands/thor/test_module.rb +310 -0
  70. data/lib/commands/thor/utils.rb +21 -0
  71. data/lib/commands/thor/workspace.rb +685 -0
  72. data/lib/config/cacert.pem +3785 -0
  73. data/lib/config/client.conf.header +20 -0
  74. data/lib/config/configuration.rb +99 -0
  75. data/lib/config/default.conf +16 -0
  76. data/lib/config/disk_cacher.rb +80 -0
  77. data/lib/configurator.rb +176 -0
  78. data/lib/context_router.rb +44 -0
  79. data/lib/core.rb +497 -0
  80. data/lib/domain/git_adapter.rb +412 -0
  81. data/lib/domain/git_error_handler.rb +64 -0
  82. data/lib/domain/response.rb +285 -0
  83. data/lib/domain/response/error_handler.rb +86 -0
  84. data/lib/dtk-shell/version.rb +20 -0
  85. data/lib/dtk_constants.rb +40 -0
  86. data/lib/dtk_error.rb +114 -0
  87. data/lib/dtk_logger.rb +126 -0
  88. data/lib/dtk_shell.rb +31 -0
  89. data/lib/error.rb +85 -0
  90. data/lib/execute.rb +29 -0
  91. data/lib/execute/cli_pure/cli_rerouter.rb +102 -0
  92. data/lib/execute/command.rb +40 -0
  93. data/lib/execute/command/api_call.rb +60 -0
  94. data/lib/execute/command/api_call/map.rb +60 -0
  95. data/lib/execute/command/api_call/service.rb +91 -0
  96. data/lib/execute/command/api_call/translation_term.rb +119 -0
  97. data/lib/execute/command/rest_call.rb +37 -0
  98. data/lib/execute/command_processor.rb +30 -0
  99. data/lib/execute/command_processor/rest_call.rb +59 -0
  100. data/lib/execute/error_usage.rb +21 -0
  101. data/lib/execute/execute_context.rb +86 -0
  102. data/lib/execute/execute_context/result_store.rb +37 -0
  103. data/lib/execute/script.rb +64 -0
  104. data/lib/execute/script/add_tenant.rb +121 -0
  105. data/lib/git-logs/git.log +0 -0
  106. data/lib/parser/adapters/option_parser.rb +70 -0
  107. data/lib/parser/adapters/thor.rb +555 -0
  108. data/lib/parser/adapters/thor/common_option_defs.rb +40 -0
  109. data/lib/require_first.rb +104 -0
  110. data/lib/search_hash.rb +44 -0
  111. data/lib/shell.rb +261 -0
  112. data/lib/shell/context.rb +1065 -0
  113. data/lib/shell/context_aux.rb +46 -0
  114. data/lib/shell/domain/active_context.rb +186 -0
  115. data/lib/shell/domain/context_entity.rb +89 -0
  116. data/lib/shell/domain/context_params.rb +223 -0
  117. data/lib/shell/domain/override_tasks.rb +88 -0
  118. data/lib/shell/domain/shadow_entity.rb +76 -0
  119. data/lib/shell/header_shell.rb +44 -0
  120. data/lib/shell/help_monkey_patch.rb +283 -0
  121. data/lib/shell/interactive_wizard.rb +225 -0
  122. data/lib/shell/message_queue.rb +63 -0
  123. data/lib/shell/parse_monkey_patch.rb +39 -0
  124. data/lib/shell/status_monitor.rb +124 -0
  125. data/lib/task_status.rb +83 -0
  126. data/lib/task_status/refresh_mode.rb +77 -0
  127. data/lib/task_status/snapshot_mode.rb +28 -0
  128. data/lib/task_status/stream_mode.rb +48 -0
  129. data/lib/task_status/stream_mode/element.rb +101 -0
  130. data/lib/task_status/stream_mode/element/format.rb +101 -0
  131. data/lib/task_status/stream_mode/element/hierarchical_task.rb +100 -0
  132. data/lib/task_status/stream_mode/element/hierarchical_task/result.rb +72 -0
  133. data/lib/task_status/stream_mode/element/hierarchical_task/result/action.rb +93 -0
  134. data/lib/task_status/stream_mode/element/hierarchical_task/result/components.rb +26 -0
  135. data/lib/task_status/stream_mode/element/hierarchical_task/result/node_level.rb +26 -0
  136. data/lib/task_status/stream_mode/element/hierarchical_task/steps.rb +34 -0
  137. data/lib/task_status/stream_mode/element/hierarchical_task/steps/action.rb +53 -0
  138. data/lib/task_status/stream_mode/element/hierarchical_task/steps/components.rb +53 -0
  139. data/lib/task_status/stream_mode/element/hierarchical_task/steps/node_level.rb +42 -0
  140. data/lib/task_status/stream_mode/element/no_results.rb +26 -0
  141. data/lib/task_status/stream_mode/element/render.rb +59 -0
  142. data/lib/task_status/stream_mode/element/stage.rb +84 -0
  143. data/lib/task_status/stream_mode/element/stage/render.rb +76 -0
  144. data/lib/task_status/stream_mode/element/task_end.rb +35 -0
  145. data/lib/task_status/stream_mode/element/task_start.rb +37 -0
  146. data/lib/util/common_util.rb +37 -0
  147. data/lib/util/console.rb +235 -0
  148. data/lib/util/dtk_puppet.rb +65 -0
  149. data/lib/util/module_util.rb +66 -0
  150. data/lib/util/os_util.rb +385 -0
  151. data/lib/util/permission_util.rb +31 -0
  152. data/lib/util/remote_dependency_util.rb +84 -0
  153. data/lib/util/ssh_util.rb +94 -0
  154. data/lib/view_processor.rb +129 -0
  155. data/lib/view_processor/augmented_simple_list.rb +44 -0
  156. data/lib/view_processor/hash_pretty_print.rb +123 -0
  157. data/lib/view_processor/simple_list.rb +156 -0
  158. data/lib/view_processor/table_print.rb +309 -0
  159. data/lib/violation.rb +86 -0
  160. data/lib/violation/attribute.rb +76 -0
  161. data/lib/violation/fix.rb +26 -0
  162. data/lib/violation/fix/result.rb +73 -0
  163. data/lib/violation/fix/result/error.rb +34 -0
  164. data/lib/violation/fix/set_attribute.rb +41 -0
  165. data/lib/violation/sub_classes.rb +60 -0
  166. data/puppet/manifests/init.pp +72 -0
  167. data/puppet/manifests/params.pp +16 -0
  168. data/puppet/r8meta.puppet.yml +35 -0
  169. data/puppet/templates/bash_profile.erb +2 -0
  170. data/puppet/templates/client.conf.erb +1 -0
  171. data/puppet/templates/dtkclient.erb +2 -0
  172. data/spec/component_module_spec.rb +34 -0
  173. data/spec/dependency_spec.rb +6 -0
  174. data/spec/dtk_shell_spec.rb +13 -0
  175. data/spec/dtk_spec.rb +33 -0
  176. data/spec/lib/spec_helper.rb +10 -0
  177. data/spec/lib/spec_thor.rb +108 -0
  178. data/spec/node_template_spec.rb +24 -0
  179. data/spec/project_spec.rb +6 -0
  180. data/spec/repo_spec.rb +7 -0
  181. data/spec/response_spec.rb +52 -0
  182. data/spec/service_module_spec.rb +38 -0
  183. data/spec/service_spec.rb +50 -0
  184. data/spec/state_change_spec.rb +7 -0
  185. data/spec/table_print_spec.rb +48 -0
  186. data/spec/target_spec.rb +57 -0
  187. data/spec/task_spec.rb +28 -0
  188. data/views/assembly/augmented_simple_list.rb +12 -0
  189. data/views/assembly_template/augmented_simple_list.rb +12 -0
  190. data/views/list_task/augmented_simple_list.rb +12 -0
  191. metadata +421 -0
@@ -0,0 +1,210 @@
1
+ #
2
+ # Copyright (C) 2010-2016 dtk contributors
3
+ #
4
+ # This file is part of the dtk project.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ dtk_require_from_base("util/os_util")
19
+ dtk_require_from_base('commands')
20
+ dtk_require_from_base("command_helper")
21
+
22
+ module DTK::Client
23
+ class CommonModule
24
+ class Import < BaseCommandHelper
25
+ include CommandBase
26
+ include CommandHelperMixin
27
+ include PushCloneChangesMixin
28
+ include ReparseMixin
29
+
30
+ def from_git(internal_trigger = false)
31
+ OsUtil.print('Retrieving git module data, please wait ...') unless internal_trigger
32
+
33
+ git_repo_url, module_name = retrieve_arguments([:option_1!, :option_2!])
34
+ namespace, local_module_name = get_namespace_and_name(module_name, ModuleUtil::NAMESPACE_SEPERATOR)
35
+
36
+ module_type = @command.get_module_type(@context_params)
37
+ thor_options = { :git_import => true}
38
+
39
+ unless namespace
40
+ namespace_response = post rest_url("namespace/default_namespace_name")
41
+ return namespace_response unless namespace_response.ok?
42
+
43
+ namespace = namespace_response.data
44
+ thor_options[:default_namespace] = namespace
45
+ end
46
+
47
+ opts = {
48
+ :namespace => namespace,
49
+ :branch => @options['branch']
50
+ }
51
+
52
+ response = Helper(:git_repo).create_clone_from_optional_branch(module_type.to_sym, local_module_name, git_repo_url, opts)
53
+ return response unless response.ok?
54
+
55
+ # Remove .git directory to rid of git pointing to user's github
56
+ FileUtils.rm_rf("#{response['data']['module_directory']}/.git")
57
+
58
+ @context_params.forward_options(thor_options)
59
+ create_response = from_git_or_file()
60
+
61
+ unless create_response.ok?
62
+ delete_dir = namespace.nil? ? local_module_name : "#{namespace}/#{local_module_name}"
63
+ full_module_name = create_response.data[:full_module_name]
64
+ local_module_name = full_module_name.nil? ? delete_dir : full_module_name
65
+
66
+ @command.delete_module_sub_aux(@context_params, local_module_name, :force_delete => true, :no_error_msg => true, :purge => true)
67
+ return create_response
68
+ end
69
+
70
+ opts_pull = {
71
+ :local_branch => @branch,
72
+ :namespace => @module_namespace
73
+ }
74
+ pull_response = Helper(:git_repo).pull_changes(module_type, @module_name, opts_pull)
75
+ return pull_response unless pull_response.ok?
76
+
77
+ if external_dependencies = create_response.data(:external_dependencies)
78
+ print_external_dependencies(external_dependencies, 'in the git repo')
79
+ end
80
+
81
+ unless internal_trigger
82
+ OsUtil.print("Successfully installed #{ModuleUtil.module_name(module_type)} '#{ModuleUtil.join_name(@module_name, @module_namespace)}' from git.", :green)
83
+ end
84
+ end
85
+
86
+ def from_file()
87
+ module_type = @command.get_module_type(@context_params)
88
+ module_name = retrieve_arguments([:option_1!])
89
+ opts = {}
90
+ namespace, local_module_name = get_namespace_and_name(module_name, ModuleUtil::NAMESPACE_SEPERATOR)
91
+
92
+ response = from_git_or_file()
93
+ return response unless response.ok?
94
+
95
+ opts_pull = {
96
+ :local_branch => @branch,
97
+ :namespace => @module_namespace
98
+ }
99
+ resp = Helper(:git_repo).pull_changes(module_type, @module_name, opts_pull)
100
+ return resp unless resp.ok?
101
+
102
+ if error = response.data(:dsl_parse_error)
103
+ dsl_parsed_message = ServiceImporter.error_message(module_name, error)
104
+ DTK::Client::OsUtil.print(dsl_parsed_message, :red)
105
+ end
106
+
107
+ # remove source directory if no errors while importing
108
+ module_final_dir = @repo_obj.repo_dir
109
+ if @old_dir and (@old_dir != module_final_dir)
110
+ FileUtils.rm_rf(@old_dir) unless namespace
111
+ end
112
+
113
+ if external_dependencies = response.data(:external_dependencies)
114
+ print_external_dependencies(external_dependencies, 'dtk.model.yaml includes')
115
+ end
116
+
117
+ # if user do import from default directory (e.g. import ntp - without namespace) print message
118
+ DTK::Client::OsUtil.print("Module '#{@new_module_name}' has been created and module directory moved to #{module_final_dir}",:yellow) unless namespace
119
+
120
+ Response::Ok.new()
121
+ end
122
+
123
+
124
+ private
125
+
126
+ def from_git_or_file()
127
+
128
+ default_ns = @context_params.get_forwarded_options()[:default_namespace]
129
+ git_import = @context_params.get_forwarded_options()[:git_import]
130
+
131
+ name_option = git_import ? :option_2! : :option_1!
132
+
133
+ if git_import
134
+ module_git_url, module_name = @context_params.retrieve_arguments([:option_1!, :option_2!])
135
+ else
136
+ module_name, module_git_url = @context_params.retrieve_arguments([:option_1!, :option_2!])
137
+ end
138
+
139
+ module_type = @command.get_module_type(@context_params)
140
+ version = @options["version"]
141
+
142
+ # extract namespace and module_name from full name (r8:maven will result in namespace = r8 & name = maven)
143
+ namespace, local_module_name = get_namespace_and_name(module_name, ModuleUtil::NAMESPACE_SEPERATOR)
144
+ namespace = default_ns if default_ns && namespace.nil?
145
+
146
+ # first check that there is a directory there and it is not already a git repo, and it ha appropriate content
147
+ response = Helper(:git_repo).check_local_dir_exists_with_content(module_type.to_sym, local_module_name, nil, namespace)
148
+ return response unless response.ok?
149
+
150
+ #check for yaml/json parsing errors before import
151
+ module_directory = response.data(:module_directory)
152
+ reparse_aux(module_directory)
153
+
154
+ # first make call to server to create an empty repo
155
+ post_body = {
156
+ :module_name => local_module_name,
157
+ :module_namespace => namespace,
158
+ :module_git_url => module_git_url
159
+ }
160
+
161
+ response = post(rest_url("#{module_type}/create"), post_body)
162
+ return response unless response.ok?
163
+
164
+ repo_url, repo_id, @module_id, branch, @new_module_name = response.data(:repo_url, :repo_id, :module_id, :workspace_branch, :full_module_name)
165
+ 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)
166
+ return response unless (response && response.ok?)
167
+
168
+ @repo_obj, commit_sha = response.data(:repo_obj, :commit_sha)
169
+ module_final_dir = @repo_obj.repo_dir
170
+ @old_dir = response.data[:old_dir]
171
+
172
+ post_body = {
173
+ :repo_id => repo_id,
174
+ :commit_sha => commit_sha,
175
+ :commit_dsl => true,
176
+ :scaffold_if_no_dsl => true,
177
+ "#{module_type}_id".to_sym => @module_id
178
+ }
179
+
180
+ if git_import
181
+ post_body.merge!(:git_import => true)
182
+ else
183
+ post_body.merge!(:update_from_includes => true)
184
+ end
185
+
186
+ response = post(rest_url("#{module_type}/update_from_initial_create"), post_body)
187
+
188
+ unless response.ok?
189
+ response.set_data_hash({ :full_module_name => @new_module_name })
190
+ # remove new directory and leave the old one if import without namespace failed
191
+ if @old_dir and (@old_dir != module_final_dir)
192
+ FileUtils.rm_rf(module_final_dir) unless (namespace && git_import)
193
+ end
194
+ return response
195
+ end
196
+
197
+ dsl_updated_info = response.data(:dsl_updated_info)
198
+ dsl_created_info = response.data(:dsl_created_info)
199
+ 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?
200
+ 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?
201
+
202
+ @module_name, @module_namespace, repo_url, @branch, not_ok_response = workspace_branch_info(module_type, @module_id, version)
203
+ return not_ok_response if not_ok_response
204
+
205
+ response
206
+ end
207
+
208
+ end
209
+ end
210
+ end
@@ -0,0 +1,53 @@
1
+ #
2
+ # Copyright (C) 2010-2016 dtk contributors
3
+ #
4
+ # This file is part of the dtk project.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module DTK::Client
19
+ module NodeMixin
20
+ def get_node_info_for_ssh_login(node_id, context_params)
21
+ context_params.forward_options(:json_return => true)
22
+ response = info_aux(context_params)
23
+ return response unless response.ok?
24
+ # Should only have info about the specfic node_id
25
+
26
+ unless node_info = response.data(:nodes).find{ |node| node_id == (node['node_properties'] || {})['node_id'] }
27
+ raise DtkError, "Cannot find info about node with id '#{node_id}'"
28
+ end
29
+
30
+ data = {}
31
+ node_properties = node_info['node_properties'] || {}
32
+ if public_dns = node_properties['ec2_public_address']
33
+ data.merge!('public_dns' => public_dns)
34
+ end
35
+ if default_login_user = NodeMixin.default_login_user?(node_properties)
36
+ data.merge!('default_login_user' => default_login_user)
37
+ end
38
+
39
+ Response::Ok.new(data)
40
+ end
41
+
42
+ def self.default_login_user?(node_properties)
43
+ if os_type = node_properties['os_type']
44
+ DefaultLoginByOSType[os_type]
45
+ end
46
+ end
47
+
48
+ DefaultLoginByOSType = {
49
+ 'ubuntu' => 'ubuntu',
50
+ 'amazon-linux' => 'ec2-user'
51
+ }
52
+ end
53
+ end
@@ -0,0 +1,65 @@
1
+ #
2
+ # Copyright (C) 2010-2016 dtk contributors
3
+ #
4
+ # This file is part of the dtk project.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module DTK::Client
19
+ module Poller
20
+
21
+ PERIOD_WAIT_TIME = 1
22
+
23
+ def poller_response(wait_time = PERIOD_WAIT_TIME)
24
+ begin
25
+ response = nil
26
+ thread = Thread.new(self) do |main_thread|
27
+ begin
28
+ while true
29
+ messages_response = main_thread.get main_thread.rest_url("messages/retrieve")
30
+ print_response(messages_response.data) if messages_response.ok?
31
+ sleep(wait_time)
32
+ end
33
+ rescue => e
34
+ puts e.message
35
+ pp e.backtrace
36
+ end
37
+ end
38
+
39
+ response = yield
40
+ ensure
41
+ thread.kill
42
+ end
43
+ response
44
+ end
45
+
46
+ def print_response(message_array)
47
+ message_array.each do |msg|
48
+ DTK::Client::OsUtil.print(msg['message'], resolve_type(msg['type']))
49
+ end
50
+ end
51
+
52
+ def resolve_type(message_type)
53
+ case message_type.to_sym
54
+ when :info
55
+ :white
56
+ when :warning
57
+ :yellow
58
+ when :error
59
+ :red
60
+ else
61
+ :white
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,28 @@
1
+ #
2
+ # Copyright (C) 2010-2016 dtk contributors
3
+ #
4
+ # This file is part of the dtk project.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ dtk_require_common_commands('thor/common')
19
+ module DTK::Client
20
+ module PullCloneChangesMixin
21
+ def pull_clone_changes?(module_type,module_id,version=nil,opts={})
22
+ module_name, module_namespace,repo_url,branch,not_ok_response = workspace_branch_info(module_type,module_id,version,opts)
23
+ return not_ok_response if not_ok_response
24
+ opts_pull = opts.merge(:local_branch => branch,:namespace => module_namespace)
25
+ Helper(:git_repo).pull_changes(module_type,module_name,opts_pull)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,152 @@
1
+ #
2
+ # Copyright (C) 2010-2016 dtk contributors
3
+ #
4
+ # This file is part of the dtk project.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module DTK::Client
19
+ module PullFromRemoteMixin
20
+ def pull_from_remote_aux(module_type,module_id,opts={})
21
+ version = opts[:version]
22
+ remote_namespace = opts[:remote_namespace]
23
+ #get remote module info, errors raised if remote is not linked or access errors
24
+ path_to_key = SSHUtil.default_rsa_pub_key_path()
25
+ rsa_pub_key = File.file?(path_to_key) && File.open(path_to_key){|f|f.read}.chomp
26
+
27
+ post_body = PostBody.new(
28
+ PullFromRemote.id_field(module_type) => module_id,
29
+ :access_rights => "r",
30
+ :action => "pull",
31
+ :version? => version,
32
+ :remote_namespace? => remote_namespace,
33
+ :rsa_pub_key? => rsa_pub_key
34
+ )
35
+ response = post(rest_url("#{module_type}/get_remote_module_info"),post_body)
36
+ return response unless response.ok?
37
+
38
+ module_name,full_module_name, frozen = response.data(:module_name, :full_module_name, :frozen)
39
+ raise DtkError, "You are not allowed to update frozen #{module_type} versions!" if frozen
40
+
41
+ remote_params = response.data_hash_form(:remote_repo_url,:remote_repo,:remote_branch)
42
+ remote_params.merge!(:version => version) if version
43
+
44
+ # check and import component module dependencies before importing service itself
45
+ unless opts[:skip_recursive_pull]
46
+ import_module_component_dependencies(module_type, module_id, remote_namespace)
47
+ end
48
+
49
+ # check whether a local module exists to determine whether pull from local clone or try to pull from server
50
+ # TODO: probably remove OsUtil.print("Pulling changes from remote: #{remote_params[:remote_repo]} @ #{remote_params[:remote_repo_url]}")
51
+
52
+ if Helper(:git_repo).local_clone_dir_exists?(module_type, module_name, :full_module_name => full_module_name, :version => version)
53
+ unless rsa_pub_key
54
+ 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)"
55
+ end
56
+ opts_perform_locally = remote_params.merge(
57
+ :full_module_name => full_module_name,
58
+ :force => opts[:force],
59
+ :do_not_raise => opts[:do_not_raise],
60
+ :ignore_dependency_merge_conflict => opts[:ignore_dependency_merge_conflict]
61
+ )
62
+ PullFromRemote.perform_locally(self,module_type,module_id,module_name,opts_perform_locally)
63
+ else
64
+ # TODO: see if this works correctly
65
+ PullFromRemote.perform_on_server(self,module_type,module_id,full_module_name,remote_params)
66
+ end
67
+ end
68
+
69
+ private
70
+
71
+ ##
72
+ #
73
+ # module_type: will be :component_module or :service_module
74
+ def import_module_component_dependencies(module_type, module_id, remote_namespace = nil)
75
+ response = resolve_pull_from_remote_on_server(module_type, module_id, remote_namespace)
76
+
77
+ print "Resolving dependencies please wait ... "
78
+ RemoteDependencyUtil.check_permission_warnings(response)
79
+
80
+ # install them all!
81
+ if (response.ok? && !(missing_components = response.data(:missing_modules)).empty?)
82
+ required_modules = response.data(:required_modules)
83
+ puts " New dependencies found, Installing."
84
+
85
+ trigger_module_auto_import(missing_components, required_modules, { :include_pull_action => true })
86
+
87
+ puts "Resuming pull from remote ..."
88
+ else
89
+ puts 'Done.'
90
+ end
91
+
92
+ # pull them all!
93
+ if (response.ok? && !(required_modules = response.data(:required_modules)).empty?)
94
+ trigger_module_auto_pull(required_modules)
95
+ end
96
+
97
+ RemoteDependencyUtil.print_dependency_warnings(response)
98
+ nil
99
+ end
100
+
101
+ private
102
+
103
+ def resolve_pull_from_remote_on_server(module_type, module_id, remote_namespace=nil)
104
+ post_body = PostBody.new(
105
+ :module_id => module_id,
106
+ :remote_namespace? => remote_namespace,
107
+ :rsa_pub_key => SSHUtil.rsa_pub_key_content()
108
+ )
109
+ post(rest_url("#{module_type}/resolve_pull_from_remote"),post_body)
110
+ end
111
+
112
+ module PullFromRemote
113
+ extend CommandBase
114
+ def self.perform_locally(cmd_obj,module_type,module_id,module_name,remote_params)
115
+ opts = remote_params
116
+ response = cmd_obj.Helper(:git_repo).pull_changes(module_type,module_name,opts)
117
+
118
+ # return response unless response.ok?
119
+ if custom_message = response.data[:custom_message]
120
+ puts custom_message
121
+ elsif (response.data[:diffs].nil? || response.data[:diffs].empty?)
122
+ puts "No changes to pull from remote.".colorize(:yellow) unless response['errors']
123
+ else
124
+ puts "Changes pulled from remote".colorize(:green)
125
+ end
126
+
127
+ response
128
+ end
129
+
130
+ def self.perform_on_server(cmd_obj,module_type,module_id,module_name,remote_params)
131
+ #TODO: this does not handle different namespaces; so suggesting workaround for now
132
+ raise DtkError, "Module must be cloned to perform this operation; execute 'clone' command and then retry."
133
+ post_body = {
134
+ id_field(module_type) => module_id,
135
+ :remote_repo => remote_params[:remote_repo],
136
+ :module_name => module_name
137
+ }
138
+ post_body.merge!(:version => remote_params[:version]) if remote_params[:version]
139
+ response = post rest_url("#{module_type}/pull_from_remote"), post_body
140
+
141
+
142
+ puts "You have successfully pulled code on server instance." if response.ok?
143
+ response
144
+ end
145
+
146
+ def self.id_field(module_type)
147
+ "#{module_type}_id"
148
+ end
149
+
150
+ end
151
+ end
152
+ end