dtk-client 0.9.1 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (310) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -0
  3. data/Gemfile +1 -3
  4. data/README.md +2 -121
  5. data/Rakefile +44 -0
  6. data/bin/dtk +10 -88
  7. data/dtk-client.gemspec +21 -44
  8. data/examples/simple/dtk.module.yaml +32 -0
  9. data/{lib/git-logs/git.log → examples/simple/test/README.md} +0 -0
  10. data/examples/spark/dtk.module.yaml +120 -0
  11. data/examples/with_repo_content/deploy/puppet/manifests/hostname.pp +54 -0
  12. data/examples/with_repo_content/dtk.module.yaml +49 -0
  13. data/examples/with_repo_content/test/README.txt +0 -0
  14. data/features/dtk.feature +8 -0
  15. data/features/step_definitions/dtk_steps.rb +6 -0
  16. data/features/support/env.rb +15 -0
  17. data/lib/cli/command/mixin.rb +101 -0
  18. data/lib/cli/command/module/clone.rb +42 -0
  19. data/lib/cli/command/module/install.rb +52 -0
  20. data/lib/cli/command/module/list.rb +31 -0
  21. data/lib/cli/command/module/list_assemblies.rb +39 -0
  22. data/lib/cli/command/module/push.rb +34 -0
  23. data/lib/cli/command/module/uninstall.rb +46 -0
  24. data/lib/cli/command/module.rb +33 -0
  25. data/lib/cli/command/options.rb +33 -0
  26. data/lib/cli/command/service/cancel_task.rb +33 -0
  27. data/lib/cli/command/service/converge.rb +37 -0
  28. data/lib/{parser/adapters/thor/common_option_defs.rb → cli/command/service/create_workspace.rb} +13 -17
  29. data/lib/cli/command/service/destroy.rb +47 -0
  30. data/lib/cli/command/service/edit.rb +47 -0
  31. data/lib/cli/command/service/exec.rb +42 -0
  32. data/lib/cli/command/service/exec_sync.rb +53 -0
  33. data/lib/cli/command/service/list.rb +30 -0
  34. data/lib/cli/command/service/list_actions.rb +39 -0
  35. data/lib/cli/command/service/list_attributes.rb +44 -0
  36. data/lib/cli/command/service/list_component_links.rb +33 -0
  37. data/lib/cli/command/service/list_components.rb +39 -0
  38. data/lib/cli/command/service/list_dependent_modules.rb +33 -0
  39. data/lib/cli/command/service/list_nodes.rb +33 -0
  40. data/lib/cli/command/service/list_violations.rb +33 -0
  41. data/lib/cli/command/service/pull.rb +32 -0
  42. data/lib/cli/command/service/push.rb +37 -0
  43. data/lib/{shell/parse_monkey_patch.rb → cli/command/service/set_default_target.rb} +9 -17
  44. data/lib/cli/command/service/set_required_attributes.rb +32 -0
  45. data/lib/cli/command/service/ssh.rb +42 -0
  46. data/lib/cli/command/service/stage.rb +55 -0
  47. data/lib/cli/command/service/start.rb +33 -0
  48. data/lib/{shell/context_aux.rb → cli/command/service/stop.rb} +10 -23
  49. data/lib/cli/command/service/task_status.rb +39 -0
  50. data/lib/cli/command/service.rb +55 -0
  51. data/lib/{commands.rb → cli/command/subcommand.rb} +22 -25
  52. data/lib/{bundler_monkey_patch.rb → cli/command/token/arg.rb} +6 -6
  53. data/lib/cli/command/token/class_mixin.rb +96 -0
  54. data/lib/cli/command/token/flag.rb +42 -0
  55. data/lib/{execute/command/rest_call.rb → cli/command/token/mixin.rb} +23 -14
  56. data/lib/cli/command/token/switch.rb +35 -0
  57. data/lib/cli/command/token.rb +76 -0
  58. data/lib/cli/command.rb +46 -0
  59. data/lib/cli/context/attributes.rb +50 -0
  60. data/lib/cli/context/type/module.rb +34 -0
  61. data/lib/{commands/thor/state_change.rb → cli/context/type/service.rb} +11 -5
  62. data/lib/cli/context/type/top.rb +32 -0
  63. data/lib/cli/context/type.rb +42 -0
  64. data/lib/cli/context.rb +174 -0
  65. data/lib/cli/directory_parser/file_system.rb +105 -0
  66. data/lib/{execute/command.rb → cli/directory_parser.rb} +14 -17
  67. data/lib/{execute.rb → cli/file_obj.rb} +13 -9
  68. data/lib/cli/processor/plugin/gli.rb +70 -0
  69. data/lib/cli/processor.rb +60 -0
  70. data/lib/cli/runner/dtkn_access.rb +75 -0
  71. data/lib/cli/runner.rb +58 -0
  72. data/lib/cli/version.rb +8 -0
  73. data/lib/{config → client/config}/cacert.pem +0 -0
  74. data/lib/client/config/default.conf +20 -0
  75. data/lib/client/config.rb +106 -0
  76. data/lib/client/configurator.rb +182 -0
  77. data/lib/client/conn.rb +197 -0
  78. data/lib/client/content_generator.rb +127 -0
  79. data/lib/client/error/subclasses.rb +105 -0
  80. data/lib/client/error.rb +98 -0
  81. data/lib/client/git_repo/adapter/git_gem/error_handler.rb +70 -0
  82. data/lib/client/git_repo/adapter/git_gem.rb +179 -0
  83. data/lib/client/git_repo.rb +122 -0
  84. data/lib/client/logger.rb +136 -0
  85. data/lib/client/operation/account.rb +66 -0
  86. data/lib/client/operation/client_module_dir/git_repo.rb +286 -0
  87. data/lib/client/operation/client_module_dir.rb +138 -0
  88. data/lib/client/operation/module/clone_module.rb +52 -0
  89. data/lib/client/operation/module/install/common_module.rb +58 -0
  90. data/lib/client/operation/module/install/external_module.rb +122 -0
  91. data/lib/client/operation/module/install.rb +91 -0
  92. data/lib/client/operation/module/install_from_catalog.rb +76 -0
  93. data/lib/client/operation/module/list.rb +34 -0
  94. data/lib/client/operation/module/list_assemblies.rb +35 -0
  95. data/lib/client/operation/module/push.rb +62 -0
  96. data/lib/client/operation/module/uninstall.rb +44 -0
  97. data/lib/client/operation/module.rb +58 -0
  98. data/lib/{commands/common/thor/reparse.rb → client/operation/module_service_common.rb} +27 -16
  99. data/lib/client/operation/service/cancel_task.rb +29 -0
  100. data/lib/client/operation/service/commit_and_push.rb +128 -0
  101. data/lib/client/operation/service/converge.rb +50 -0
  102. data/lib/{util/common_util.rb → client/operation/service/create_workspace.rb} +13 -13
  103. data/lib/client/operation/service/destroy.rb +42 -0
  104. data/lib/client/operation/service/edit.rb +54 -0
  105. data/lib/client/operation/service/exec.rb +73 -0
  106. data/lib/client/operation/service/list.rb +32 -0
  107. data/lib/client/operation/service/list_actions.rb +34 -0
  108. data/lib/{commands/thor/dependency.rb → client/operation/service/list_attributes.rb} +16 -12
  109. data/lib/client/operation/service/list_component_links.rb +29 -0
  110. data/lib/{commands/common/thor/pull_clone_changes.rb → client/operation/service/list_components.rb} +13 -7
  111. data/lib/client/operation/service/list_dependent_modules.rb +29 -0
  112. data/lib/client/operation/service/list_nodes.rb +29 -0
  113. data/lib/{commands/thor/project.rb → client/operation/service/list_violations.rb} +8 -13
  114. data/lib/client/operation/service/pull.rb +37 -0
  115. data/lib/client/operation/service/set_default_target.rb +31 -0
  116. data/lib/client/operation/service/set_required_attributes.rb +41 -0
  117. data/lib/client/operation/service/ssh.rb +118 -0
  118. data/lib/client/operation/service/stage.rb +54 -0
  119. data/lib/client/operation/service/start.rb +29 -0
  120. data/lib/client/operation/service/stop.rb +30 -0
  121. data/lib/{task_status → client/operation/service/task_status}/refresh_mode.rb +15 -25
  122. data/lib/{task_status → client/operation/service/task_status}/snapshot_mode.rb +4 -5
  123. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/format.rb +1 -1
  124. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/result/action.rb +1 -1
  125. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/result/components.rb +1 -1
  126. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/result/node_level.rb +1 -1
  127. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/result.rb +4 -4
  128. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/steps/action.rb +1 -1
  129. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/steps/components.rb +1 -1
  130. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/steps/node_level.rb +1 -1
  131. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task/steps.rb +4 -4
  132. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/hierarchical_task.rb +3 -3
  133. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/no_results.rb +1 -1
  134. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/render.rb +1 -1
  135. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/stage/render.rb +1 -1
  136. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/stage.rb +3 -3
  137. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/task_end.rb +1 -1
  138. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element/task_start.rb +1 -1
  139. data/lib/{task_status → client/operation/service/task_status}/stream_mode/element.rb +13 -13
  140. data/lib/{task_status → client/operation/service/task_status}/stream_mode.rb +5 -9
  141. data/lib/client/operation/service/task_status.rb +77 -0
  142. data/lib/client/operation/service.rb +54 -0
  143. data/lib/client/operation.rb +67 -0
  144. data/lib/client/operation_args.rb +40 -0
  145. data/lib/{execute/execute_context/result_store.rb → client/render/view/simple.rb} +15 -14
  146. data/lib/client/render/view/table/processor.rb +248 -0
  147. data/lib/client/render/view/table.rb +75 -0
  148. data/lib/client/render.rb +113 -0
  149. data/lib/client/response/error_handler.rb +97 -0
  150. data/lib/client/response/render_helper.rb +78 -0
  151. data/lib/client/response/subclasses.rb +62 -0
  152. data/lib/client/response.rb +83 -0
  153. data/lib/client/session.rb +62 -0
  154. data/lib/client/util/auxiliary.rb +34 -0
  155. data/lib/client/util/console.rb +81 -0
  156. data/lib/client/util/disk_cacher.rb +66 -0
  157. data/lib/client/util/dtk_path.rb +28 -0
  158. data/lib/{search_hash.rb → client/util/hash_with_optional_keys.rb} +29 -21
  159. data/lib/client/util/interactive_wizard.rb +84 -0
  160. data/lib/client/util/module_ref.rb +92 -0
  161. data/lib/client/util/os_util/print.rb +121 -0
  162. data/lib/client/util/os_util.rb +122 -0
  163. data/lib/{commands/thor/utils.rb → client/util/post_body.rb} +1 -1
  164. data/lib/{execute/error_usage.rb → client/util/query_string_hash.rb} +2 -2
  165. data/lib/client/util/remote_dependency.rb +67 -0
  166. data/lib/client/util/ssh_util.rb +89 -0
  167. data/lib/client/util/validation.rb +28 -0
  168. data/lib/client/util.rb +18 -0
  169. data/lib/{util/permission_util.rb → dtk_cli.rb} +10 -9
  170. data/lib/dtk_client.rb +18 -14
  171. data/test/default_test.rb +14 -0
  172. data/test/test_helper.rb +9 -0
  173. metadata +196 -307
  174. data/Gemfile_dev +0 -13
  175. data/bin/dtk-execute +0 -32
  176. data/bin/dtk-shell +0 -31
  177. data/lib/auxiliary.rb +0 -61
  178. data/lib/client.rb +0 -58
  179. data/lib/command_helper.rb +0 -33
  180. data/lib/command_helpers/git_repo/merge.rb +0 -153
  181. data/lib/command_helpers/git_repo.rb +0 -589
  182. data/lib/command_helpers/jenkins_client/config_xml.rb +0 -288
  183. data/lib/command_helpers/jenkins_client.rb +0 -106
  184. data/lib/command_helpers/service_importer.rb +0 -251
  185. data/lib/command_helpers/service_link.rb +0 -33
  186. data/lib/command_helpers/test_module_creator.rb +0 -69
  187. data/lib/command_helpers/test_module_templates/dtk.model.yaml.eruby +0 -10
  188. data/lib/command_helpers/test_module_templates/spec_helper.rb.eruby +0 -10
  189. data/lib/command_helpers/test_module_templates/temp_component_spec.rb.eruby +0 -5
  190. data/lib/commands/common/thor/access_control.rb +0 -133
  191. data/lib/commands/common/thor/action_result_handler.rb +0 -74
  192. data/lib/commands/common/thor/assembly_template.rb +0 -92
  193. data/lib/commands/common/thor/assembly_workspace.rb +0 -1638
  194. data/lib/commands/common/thor/base_command_helper.rb +0 -59
  195. data/lib/commands/common/thor/clone.rb +0 -82
  196. data/lib/commands/common/thor/common.rb +0 -88
  197. data/lib/commands/common/thor/common_base.rb +0 -49
  198. data/lib/commands/common/thor/create_target.rb +0 -70
  199. data/lib/commands/common/thor/edit.rb +0 -255
  200. data/lib/commands/common/thor/inventory_parser.rb +0 -98
  201. data/lib/commands/common/thor/list_diffs.rb +0 -128
  202. data/lib/commands/common/thor/module/import.rb +0 -215
  203. data/lib/commands/common/thor/module.rb +0 -1011
  204. data/lib/commands/common/thor/node.rb +0 -53
  205. data/lib/commands/common/thor/poller.rb +0 -65
  206. data/lib/commands/common/thor/pull_from_remote.rb +0 -152
  207. data/lib/commands/common/thor/puppet_forge.rb +0 -72
  208. data/lib/commands/common/thor/purge_clone.rb +0 -101
  209. data/lib/commands/common/thor/push_clone_changes.rb +0 -162
  210. data/lib/commands/common/thor/push_to_remote.rb +0 -94
  211. data/lib/commands/common/thor/remotes.rb +0 -71
  212. data/lib/commands/common/thor/set_required_attributes.rb +0 -46
  213. data/lib/commands/thor/account.rb +0 -239
  214. data/lib/commands/thor/assembly.rb +0 -361
  215. data/lib/commands/thor/attribute.rb +0 -79
  216. data/lib/commands/thor/component.rb +0 -70
  217. data/lib/commands/thor/component_module.rb +0 -501
  218. data/lib/commands/thor/component_template.rb +0 -174
  219. data/lib/commands/thor/developer.rb +0 -144
  220. data/lib/commands/thor/dtk.rb +0 -152
  221. data/lib/commands/thor/library.rb +0 -125
  222. data/lib/commands/thor/node.rb +0 -504
  223. data/lib/commands/thor/node_group.rb +0 -203
  224. data/lib/commands/thor/node_template.rb +0 -94
  225. data/lib/commands/thor/provider.rb +0 -233
  226. data/lib/commands/thor/remotes.rb +0 -49
  227. data/lib/commands/thor/service.rb +0 -932
  228. data/lib/commands/thor/service_module.rb +0 -900
  229. data/lib/commands/thor/target.rb +0 -250
  230. data/lib/commands/thor/task.rb +0 -116
  231. data/lib/commands/thor/test_module.rb +0 -310
  232. data/lib/commands/thor/workspace.rb +0 -698
  233. data/lib/config/client.conf.header +0 -20
  234. data/lib/config/configuration.rb +0 -99
  235. data/lib/config/default.conf +0 -16
  236. data/lib/config/disk_cacher.rb +0 -80
  237. data/lib/configurator.rb +0 -176
  238. data/lib/context_router.rb +0 -44
  239. data/lib/core.rb +0 -489
  240. data/lib/domain/git_adapter.rb +0 -412
  241. data/lib/domain/git_error_handler.rb +0 -64
  242. data/lib/domain/response/error_handler.rb +0 -86
  243. data/lib/domain/response.rb +0 -285
  244. data/lib/dtk-client/version.rb +0 -20
  245. data/lib/dtk_constants.rb +0 -40
  246. data/lib/dtk_error.rb +0 -114
  247. data/lib/dtk_logger.rb +0 -113
  248. data/lib/error.rb +0 -85
  249. data/lib/execute/cli_pure/cli_rerouter.rb +0 -102
  250. data/lib/execute/command/api_call/map.rb +0 -60
  251. data/lib/execute/command/api_call/service.rb +0 -91
  252. data/lib/execute/command/api_call/translation_term.rb +0 -119
  253. data/lib/execute/command/api_call.rb +0 -60
  254. data/lib/execute/command_processor/rest_call.rb +0 -59
  255. data/lib/execute/command_processor.rb +0 -30
  256. data/lib/execute/execute_context.rb +0 -86
  257. data/lib/execute/script/add_tenant.rb +0 -121
  258. data/lib/execute/script.rb +0 -64
  259. data/lib/parser/adapters/option_parser.rb +0 -70
  260. data/lib/parser/adapters/thor.rb +0 -555
  261. data/lib/require_first.rb +0 -104
  262. data/lib/shell/context.rb +0 -1064
  263. data/lib/shell/domain/active_context.rb +0 -186
  264. data/lib/shell/domain/context_entity.rb +0 -89
  265. data/lib/shell/domain/context_params.rb +0 -223
  266. data/lib/shell/domain/override_tasks.rb +0 -88
  267. data/lib/shell/domain/shadow_entity.rb +0 -76
  268. data/lib/shell/header_shell.rb +0 -44
  269. data/lib/shell/help_monkey_patch.rb +0 -283
  270. data/lib/shell/interactive_wizard.rb +0 -256
  271. data/lib/shell/message_queue.rb +0 -63
  272. data/lib/shell/status_monitor.rb +0 -124
  273. data/lib/shell.rb +0 -261
  274. data/lib/task_status.rb +0 -83
  275. data/lib/util/console.rb +0 -235
  276. data/lib/util/dtk_puppet.rb +0 -65
  277. data/lib/util/module_util.rb +0 -66
  278. data/lib/util/os_util.rb +0 -385
  279. data/lib/util/remote_dependency_util.rb +0 -84
  280. data/lib/util/ssh_util.rb +0 -94
  281. data/lib/view_processor/augmented_simple_list.rb +0 -44
  282. data/lib/view_processor/hash_pretty_print.rb +0 -123
  283. data/lib/view_processor/simple_list.rb +0 -156
  284. data/lib/view_processor/table_print.rb +0 -309
  285. data/lib/view_processor.rb +0 -129
  286. data/puppet/manifests/init.pp +0 -72
  287. data/puppet/manifests/params.pp +0 -16
  288. data/puppet/r8meta.puppet.yml +0 -35
  289. data/puppet/templates/bash_profile.erb +0 -2
  290. data/puppet/templates/client.conf.erb +0 -1
  291. data/puppet/templates/dtkclient.erb +0 -2
  292. data/spec/component_module_spec.rb +0 -34
  293. data/spec/dependency_spec.rb +0 -6
  294. data/spec/dtk_shell_spec.rb +0 -13
  295. data/spec/dtk_spec.rb +0 -33
  296. data/spec/lib/spec_helper.rb +0 -10
  297. data/spec/lib/spec_thor.rb +0 -108
  298. data/spec/node_template_spec.rb +0 -24
  299. data/spec/project_spec.rb +0 -6
  300. data/spec/repo_spec.rb +0 -7
  301. data/spec/response_spec.rb +0 -52
  302. data/spec/service_module_spec.rb +0 -38
  303. data/spec/service_spec.rb +0 -50
  304. data/spec/state_change_spec.rb +0 -7
  305. data/spec/table_print_spec.rb +0 -48
  306. data/spec/target_spec.rb +0 -57
  307. data/spec/task_spec.rb +0 -28
  308. data/views/assembly/augmented_simple_list.rb +0 -12
  309. data/views/assembly_template/augmented_simple_list.rb +0 -12
  310. data/views/list_task/augmented_simple_list.rb +0 -12
@@ -1,53 +0,0 @@
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
@@ -1,65 +0,0 @@
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
@@ -1,152 +0,0 @@
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
@@ -1,72 +0,0 @@
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 PuppetForgeMixin
20
-
21
- NAME_REGEX = /\w*\-\w/
22
-
23
- def puppet_forge_install_aux(context_params, pf_module_name, module_name, namespace, version, module_type)
24
- post_body_hash = {
25
- :puppetf_module_name => pf_module_name,
26
- :module_name? => module_name,
27
- :module_version? => version,
28
- :module_namespace? => namespace
29
- }
30
-
31
- raise DtkError, "Puppet forge module name should be in format NAMESPACE-MODULENAME" unless pf_module_name.match(NAME_REGEX)
32
-
33
- response = poller_response do
34
- post rest_url("component_module/install_puppet_forge_modules"), PostBody.new(post_body_hash)
35
- end
36
-
37
- return response unless response.ok?
38
-
39
-
40
- installed_modules = response.data(:installed_modules)
41
-
42
- print_modules(response.data(:found_modules), 'using')
43
- print_modules(installed_modules, 'installed')
44
-
45
- main_module = response.data(:main_module)
46
-
47
- unless installed_modules.empty?
48
- # clone_deps = Console.confirmation_prompt("\nDo you want to clone newly installed dependencies?")
49
- # if clone_deps
50
- installed_modules.each do |im|
51
- clone_aux(im['type'], im['id'], im['version'], true, true, {:backup_if_exist => true})
52
- end
53
- # end
54
- end
55
-
56
- clone_aux(main_module['type'], main_module['id'], main_module['version'], true, true, {:print_imported => true, :backup_if_exist => true})
57
- nil
58
- end
59
-
60
- private
61
-
62
- def print_modules(modules, action_name)
63
- modules.each do |target_module|
64
- module_name = full_module_name(target_module)
65
- module_type = target_module['type']
66
-
67
- print "#{action_name.capitalize} dependency #{module_type.gsub('_',' ')} '#{module_name}'\n"
68
- end
69
- end
70
-
71
- end
72
- end
@@ -1,101 +0,0 @@
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 PurgeCloneMixin
20
- def purge_clone_aux(module_type, opts = {})
21
- module_name = opts[:module_name]
22
- version = opts[:version]
23
- opts_module_loc = (opts[:assembly_module] ? {:assembly_module => opts[:assembly_module]} : Hash.new)
24
- module_location = OsUtil.module_location(module_type, module_name, version, opts_module_loc)
25
- dirs_to_delete = [module_location]
26
- if opts[:delete_all_versions]
27
- dirs_to_delete += OsUtil.module_version_locations(module_type, module_name, version, opts)
28
- elsif opts[:all_except_base]
29
- dirs_to_delete = OsUtil.module_version_locations(module_type, module_name, version, opts)
30
- end
31
- response = Response::Ok.new()
32
- pwd = Dir.getwd()
33
- dirs_to_delete.each do |dir|
34
- if File.directory?(dir)
35
- if ((pwd == dir) || (pwd.include?("#{dir}/")))
36
- OsUtil.print("Local directory '#{dir}' is not deleted because it is your current working directory.", :yellow)
37
- else
38
- FileUtils.rm_rf(dir)
39
- end
40
- end
41
- end
42
- response
43
- end
44
-
45
- def check_if_unsaved_cmp_module_changes(assembly_or_workspace_id, opts={})
46
- unsaved_modules = []
47
- post_body = {
48
- :assembly_id => assembly_or_workspace_id,
49
- :subtype => 'instance'
50
- }
51
- response = post rest_url("assembly/get_component_modules"), post_body
52
-
53
- if response.ok?
54
- response.data.each do |cmp_mod|
55
- branch_relationship = cmp_mod['branch_relationship']||''
56
- unsaved_modules << "#{cmp_mod['namespace_name']}:#{cmp_mod['display_name']}" if (cmp_mod['local_copy_diff'] && branch_relationship.eql?('local_ahead'))
57
- end
58
- end
59
-
60
- unsaved_modules
61
- end
62
-
63
- def check_if_unsaved_assembly_changes(assembly_or_workspace_id, assembly_name, opts={})
64
- post_body = {
65
- :assembly_id => assembly_or_workspace_id,
66
- :module_type => 'service_module',
67
- :modification_type => 'workflow'
68
- }
69
- response = post rest_url("assembly/prepare_for_edit_module"), post_body
70
- return unless response.ok?
71
- assembly_name,service_module_id,service_module_name,version,repo_url,branch,branch_head_sha,edit_file = response.data(:assembly_name,:module_id,:full_module_name,:version,:repo_url,:workspace_branch,:branch_head_sha,:edit_file)
72
-
73
- edit_opts = {
74
- :automatically_clone => true,
75
- :assembly_module => {
76
- :assembly_name => assembly_name,
77
- :version => version
78
- },
79
- :workspace_branch_info => {
80
- :repo_url => repo_url,
81
- :branch => branch,
82
- :module_name => service_module_name
83
- },
84
- :commit_sha => branch_head_sha,
85
- :pull_if_needed => true,
86
- :modification_type => :workflow,
87
- :edit_file => edit_file
88
- }
89
-
90
- version = nil #TODO: version associated with assembly is passed in edit_opts, which is a little confusing
91
- module_location = OsUtil.module_location(:service_module,service_module_name,version,edit_opts)
92
- return unless File.directory?(module_location)
93
-
94
- grit_adapter = Helper(:git_repo).create(module_location)
95
- return unless grit_adapter.repo_exists?
96
-
97
- grit_adapter.changed?
98
- end
99
-
100
- end
101
- end
@@ -1,162 +0,0 @@
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
- dtk_require_from_base('command_helpers/service_importer')
20
-
21
- module DTK::Client
22
- module PushCloneChangesMixin
23
- include CommonMixin
24
- ##
25
- #
26
- # module_type: will be :component_module or :service_module
27
- def push_clone_changes_aux(module_type, module_id, version, commit_msg, internal_trigger=false, opts={})
28
- module_name, module_namespace, repo_url, branch, not_ok_response = workspace_branch_info(module_type, module_id, version, opts)
29
- return not_ok_response if not_ok_response
30
-
31
- full_module_name = ModuleUtil.resolve_name(module_name, module_namespace)
32
- module_location = OsUtil.module_location(module_type, full_module_name, version, opts)
33
-
34
- unless File.directory?(module_location)
35
- return if opts[:skip_cloning]
36
- if opts[:force_clone] || Console.confirmation_prompt("Push not possible, module '#{module_name}#{version && "-#{version}"}' has not been cloned. Would you like to clone module now"+'?')
37
- clone_aux(module_type, module_id, version, true, true, opts)
38
- else
39
- return
40
- end
41
- end
42
-
43
- push_opts = opts.merge(:commit_msg => commit_msg, :local_branch => branch, :where => 'server')
44
- response = Helper(:git_repo).push_changes(module_type, full_module_name, version, push_opts)
45
- return response unless response.ok?
46
-
47
- json_diffs = (response.data(:diffs).empty? ? {} : JSON.generate(response.data(:diffs)))
48
- commit_sha = response.data(:commit_sha)
49
- repo_obj = response.data(:repo_obj)
50
- json_diffs = JSON.generate(response.data(:diffs))
51
- post_body = get_workspace_branch_info_post_body(module_type, module_id, version, opts).merge(:json_diffs => json_diffs, :commit_sha => commit_sha)
52
-
53
- post_body.merge!(:modification_type => opts[:modification_type]) if opts[:modification_type]
54
- post_body.merge!(:force_parse => true) if options['force-parse'] || opts[:force_parse]
55
- post_body.merge!(:update_from_includes => true) if opts[:update_from_includes]
56
- post_body.merge!(:service_instance_module => true) if opts[:service_instance_module]
57
- post_body.merge!(:current_branch_sha => opts[:current_branch_sha]) if opts[:current_branch_sha]
58
- post_body.merge!(:force => opts[:force]) if opts[:force]
59
- post_body.merge!(:task_action => opts[:task_action]) if opts[:task_action]
60
- post_body.merge!(:generate_docs => true) if opts[:generate_docs]
61
- post_body.merge!(:use_impl_id => opts[:use_impl_id]) if opts[:use_impl_id]
62
-
63
- if opts[:set_parsed_false]
64
- post_body.merge!(:set_parsed_false => true)
65
- post_body.merge!(:force_parse => true)
66
- end
67
-
68
- response = post(rest_url("#{module_type}/update_model_from_clone"), post_body)
69
- return response unless response.ok?
70
-
71
- external_dependencies = response.data(:external_dependencies)
72
- dsl_parse_error = response.data(:dsl_parse_error)
73
- dsl_updated_info = response.data(:dsl_updated_info)
74
- dsl_created_info = response.data(:dsl_created_info)
75
- component_module_refs = response.data(:component_module_refs)
76
-
77
- ret = Response::Ok.new()
78
-
79
- # check if any errors
80
- if dsl_parse_error
81
- if parsed_external_dependencies = dsl_parse_error['external_dependencies']
82
- external_dependencies = parsed_external_dependencies
83
- else
84
- err_msg_opts = { :module_type => module_type }
85
- err_msg_opts.merge!(:command => opts[:command]) if opts[:command]
86
- if err_message = ServiceImporter.error_message(module_name, dsl_parse_error, err_msg_opts)
87
- DTK::Client::OsUtil.print(err_message, :red)
88
- ret = Response::NoOp.new()
89
- end
90
- end
91
- end
92
-
93
- has_code_been_pulled = false
94
-
95
- # check if server pushed anything that needs to be pulled
96
-
97
- # we need to pull latest code in case docs where generated
98
- OsUtil.print("Pulling generated documentation on your local repository ...", :yellow) if opts[:generate_docs]
99
-
100
- if dsl_updated_info and !dsl_updated_info.empty?
101
- if msg = dsl_updated_info["msg"]
102
- DTK::Client::OsUtil.print(msg,:yellow)
103
- end
104
- new_commit_sha = dsl_updated_info[:commit_sha]
105
- unless new_commit_sha and new_commit_sha == commit_sha
106
- opts_pull = opts.merge(:local_branch => branch,:namespace => module_namespace)
107
- resp = Helper(:git_repo).pull_changes(module_type, module_name, opts_pull)
108
- has_code_been_pulled = true
109
- return resp unless resp.ok?
110
- end
111
- end
112
-
113
- # unless DSL was updated we pull latest code due to changes on documentation
114
- if opts[:generate_docs] && !has_code_been_pulled
115
- opts_pull = opts.merge(:local_branch => branch,:namespace => module_namespace)
116
- resp = Helper(:git_repo).pull_changes(module_type, module_name, opts_pull)
117
- return resp unless resp.ok?
118
- end
119
-
120
- if opts[:print_dependencies] || !internal_trigger
121
- if external_dependencies
122
- ambiguous = external_dependencies["ambiguous"]||[]
123
- amb_sorted = ambiguous.map { |k,v| "#{k.split('/').last} (#{v.join(', ')})" }
124
- inconsistent = external_dependencies["inconsistent"]||[]
125
- possibly_missing = external_dependencies["possibly_missing"]||[]
126
- OsUtil.print("There are inconsistent module dependencies: #{inconsistent.join(', ')}", :red) unless inconsistent.empty?
127
- OsUtil.print("There are missing module dependencies: #{possibly_missing.join(', ')}", :yellow) unless possibly_missing.empty?
128
- OsUtil.print("There are ambiguous module dependencies: '#{amb_sorted.join(', ')}'. One of the namespaces should be selected by editing the module_refs file", :yellow) if ambiguous && !ambiguous.empty?
129
- end
130
- end
131
-
132
- # check if server sent any file that should be added
133
- if dsl_created_info and !dsl_created_info.empty?
134
- path = dsl_created_info["path"]
135
- content = dsl_created_info["content"]
136
- if path and content
137
- msg = "A #{path} file has been created for you, located at #{repo_obj.repo_dir}"
138
- response = Helper(:git_repo).add_file(repo_obj,path,content,msg)
139
- return response unless response.ok?
140
- end
141
- end
142
-
143
- unless (component_module_refs||{}).empty?
144
- print_using_dependencies(component_module_refs)
145
- end
146
-
147
- ret
148
- end
149
-
150
- private
151
-
152
- def print_using_dependencies(component_refs)
153
- # TODO: This just prints out dircetly included modules
154
- unless component_refs.empty?
155
- puts 'Using component modules:'
156
- component_refs.values.map { |r| "#{r['namespace_info']}:#{r['module_name']}" }.sort.each do |name|
157
- puts " #{name}"
158
- end
159
- end
160
- end
161
- end
162
- end