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,900 +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
- #TODO: putting in version as hidden coption that can be enabled when code ready
19
- #TODO: may be consistent on whether service module id or service module name used as params
20
- dtk_require_common_commands('thor/reparse')
21
- dtk_require_from_base("dtk_logger")
22
- dtk_require_from_base("util/os_util")
23
- dtk_require_from_base("commands/thor/assembly")
24
- dtk_require_from_base('command_helpers/service_importer')
25
- dtk_require_from_base('task_status')
26
- dtk_require_common_commands('thor/common')
27
- dtk_require_common_commands('thor/module')
28
- dtk_require_common_commands('thor/poller')
29
- dtk_require_common_commands('thor/assembly_template')
30
- dtk_require_common_commands('thor/pull_clone_changes')
31
-
32
- module DTK::Client
33
- class ServiceModule < CommandBaseThor
34
-
35
- PULL_CATALOGS = ["dtkn"]
36
-
37
- no_tasks do
38
- include ReparseMixin
39
- include ServiceImporter
40
- include ModuleMixin
41
- include Poller
42
- include AssemblyTemplateMixin
43
- include TaskStatusMixin
44
-
45
- def get_service_module_name(service_module_id)
46
- get_name_from_id_helper(service_module_id)
47
- end
48
-
49
- def get_name_and_version_from_assembly_template(assembly_template_name)
50
- name = assembly_template_name
51
- version = nil
52
-
53
- if assembly_template_name.match(/(.*)(\-v\d{1,2}\.\d{1,2}\.\d{1,2}\Z)/)
54
- name, version = [$1,$2]
55
- end
56
-
57
- if version
58
- version.gsub!('-v','')
59
- else
60
- version = 'base'
61
- end
62
-
63
- return name, version
64
- end
65
-
66
- def stage_aux(context_params)
67
- if context_params.is_there_identifier?(:assembly)
68
- service_module_id, service_module_name, assembly_template_name, name = context_params.retrieve_arguments([:service_module_id!, :service_module_name!, :assembly_name!, :option_2], method_argument_names)
69
- else
70
- service_module_id, service_module_name, assembly_template_name, name = context_params.retrieve_arguments([:service_module_id!, :service_module_name!, :option_1!, :option_2], method_argument_names)
71
- end
72
-
73
- post_body = { :assembly_id => assembly_template_name }
74
-
75
- # special case when we need service module id
76
- context_params.pure_cli_mode = true
77
- post_body[:service_module_id] = service_module_id if context_params.pure_cli_mode
78
-
79
- # using this to make sure cache will be invalidated after new assembly is created from other commands e.g.
80
- # 'assembly-create', 'install' etc.
81
- @@invalidate_map << :assembly
82
-
83
- fwd_options = context_params.get_forwarded_options()
84
- in_target = fwd_options[:in_target]||options["in-target"]
85
- instance_bindings = options["instance-bindings"]
86
- settings = parse_service_settings(options["settings"])
87
- node_size = fwd_options[:node_size]||options.node_size
88
- os_type = fwd_options[:os_type]||options.os_type
89
- version = fwd_options[:version]||options.version
90
- no_auto_complete = fwd_options[:no_auto_complete]||options.no_auto_complete
91
- parent_service = fwd_options[:parent_service]||options.parent_service
92
- is_target = fwd_options[:is_target]||options.is_target?
93
- do_not_encode = fwd_options[:do_not_encode]
94
- assembly_list = Assembly.assembly_list()
95
-
96
- if assembly_template_name.to_s =~ /^[0-9]+$/
97
- assembly_template_name = DTK::Client::Assembly.get_assembly_template_name_for_service(assembly_template_name, service_module_name)
98
- assembly_template_name, version = get_name_and_version_from_assembly_template(assembly_template_name)
99
- else
100
- namespace, module_name = get_namespace_and_name(service_module_name, ':')
101
- assembly_template_name = "#{module_name}/#{assembly_template_name}"
102
- end
103
- assembly_template_name.gsub!(/(::)|(\/)/,'-') if assembly_template_name
104
-
105
- if name
106
- raise DTK::Client::DtkValidationError, "Unable to stage service with name '#{name}'. Service with specified name exists already!" if assembly_list.include?(name)
107
- else
108
- name = get_assembly_stage_name(assembly_list, assembly_template_name)
109
- end
110
-
111
- post_body.merge!(:target_id => in_target) if in_target
112
- post_body.merge!(:name => name) if name
113
- post_body.merge!(:instance_bindings => instance_bindings) if instance_bindings
114
- post_body.merge!(:settings_json_form => JSON.generate(settings)) if settings
115
- post_body.merge!(:node_size => node_size) if node_size
116
- post_body.merge!(:os_type => os_type) if os_type
117
- post_body.merge!(:version => version) if version
118
- post_body.merge!(:service_module_name => service_module_name) if service_module_name
119
- post_body.merge!(:no_auto_complete => no_auto_complete) if no_auto_complete
120
- post_body.merge!(:parent_service => parent_service) if parent_service
121
- post_body.merge!(:is_target => is_target) if is_target
122
- post_body.merge!(:do_not_encode => do_not_encode) if do_not_encode
123
-
124
- response = post rest_url("assembly/stage"), post_body
125
- end
126
-
127
- def deploy_aux(context_params)
128
- forwarded_options = context_params.get_forwarded_options()
129
- context_params.forward_options(forwarded_options.merge!(:do_not_encode => true))
130
- stage_response = stage_aux(context_params)
131
- return stage_response unless stage_response.ok?
132
-
133
- if service_instance = stage_response.data['new_service_instance']
134
- instance_name = service_instance['name']
135
-
136
- DTK::Client::OsUtil.print("Service instance '/service/#{instance_name}' has been created!",:yellow)
137
-
138
- new_context_params = DTK::Shell::ContextParams.new
139
- new_context_params.add_context_to_params("service", "service")
140
- new_context_params.add_context_name_to_params("service", "service", instance_name)
141
- new_context_params.forward_options(:instance_name => instance_name)
142
-
143
- response = ContextRouter.routeTask("service", "set_required_attributes_and_converge", new_context_params, @conn)
144
-
145
- # change context to newly created service instance
146
- MainContext.get_context.change_context(["/service/#{instance_name}"])
147
-
148
- return response unless response.ok?
149
-
150
- if forwarded_options['stream-results'] || options['stream-results']
151
- forwarded_options = new_context_params.get_forwarded_options()
152
- task_status_stream(instance_name) unless forwarded_options[:violations]
153
- end
154
-
155
- response
156
- else
157
- fail DtkError.new('Service instance is not staged properly, please try again!')
158
- end
159
- end
160
- end
161
-
162
- def self.extended_context()
163
- {
164
- :command => {
165
- :stage => {
166
- :endpoint => "service_module",
167
- :url => "service_module/list_assemblies",
168
- :opts => {}
169
- },
170
- :stage_target => {
171
- :endpoint => "service_module",
172
- :url => "service_module/list_assemblies",
173
- :opts => {}
174
- },
175
- :deploy_target => {
176
- :endpoint => "service_module",
177
- :url => "service_module/list_assemblies",
178
- :opts => {}
179
- },
180
- :deploy => {
181
- :endpoint => "service_module",
182
- :url => "service_module/list_assemblies",
183
- :opts => {}
184
- }
185
- }
186
- }
187
- end
188
-
189
- def self.valid_children()
190
- [:assembly, :remotes]
191
- end
192
-
193
- def self.all_children()
194
- [:assembly]
195
- end
196
-
197
- def self.multi_context_children()
198
- [[:assembly], [:remotes], [:assembly, :remotes]]
199
- end
200
-
201
- def self.valid_child?(name_of_sub_context)
202
- return ServiceModule.valid_children().include?(name_of_sub_context.to_sym)
203
- end
204
-
205
- def self.pretty_print_cols()
206
- PPColumns.get(:service_module)
207
- end
208
-
209
- def self.validation_list(context_params)
210
- get_cached_response(:service_module, "service_module/list", {})
211
- end
212
-
213
- def self.whoami()
214
- return :service_module, "service_module/list", nil
215
- end
216
-
217
- def self.override_allowed_methods()
218
- return DTK::Shell::OverrideTasks.new({
219
- :command_only => {
220
- :self => [
221
- ["list"," list [--remote] [--diff] [-n NAMESPACE]","# List service modules (local/remote). Use --diff to compare loaded and remote modules."]
222
- ],
223
- :assembly => [
224
- ["list","list","# List assemblies for given service module."]
225
- ],
226
- :remotes => [
227
- ["push-remote", "push-remote [REMOTE-NAME] [--force]", "# Push local changes to remote git repository"],
228
- ["list-remotes", "list-remotes", "# List git remotes for given module"],
229
- ["add-remote", "add-remote REMOTE-NAME REMOTE-URL", "# Add git remote for given module"],
230
- ["remove-remote", "remove-remote REPO-NAME [-y]", "# Remove git remote for given module"]
231
- ]
232
- },
233
- :identifier_only => {
234
- :self => [
235
- ["list-assemblies","list-assemblies","# List assemblies associated with service module."],
236
- ["list-modules","list-modules","# List modules associated with service module."]
237
- ],
238
- :assembly => [
239
- ["info","info","# Info for given assembly in current service module."],
240
- # ["stage", "stage [INSTANCE-NAME] [-t TARGET-NAME/ID] [--node-size NODE-SIZE-SPEC] [--os-type OS-TYPE] [-v VERSION]", "# Stage assembly in target."],
241
- # ["deploy","deploy [-v VERSION] [INSTANCE-NAME] [-t TARGET-NAME/ID] [-m COMMIT-MSG]", "# Stage and deploy assembly in target."],
242
- # ["deploy","deploy [INSTANCE-NAME] [-t TARGET-NAME/ID] [-m COMMIT-MSG]", "# Stage and deploy assembly in target."],
243
- # ["deploy","deploy [INSTANCE-NAME] [-m COMMIT-MSG]", "# Stage and deploy assembly in target."],
244
- ["stage-target","stage-target [INSTANCE-NAME] [-t PARENT-SERVICE-INSTANCE-NAME/ID] [-v VERSION] [--no-auto-complete]", "# Stage assembly as target instance."],
245
- ["stage","stage [INSTANCE-NAME] [-t PARENT-SERVICE-INSTANCE-NAME/ID] [-v VERSION] [--no-auto-complete]", "# Stage assembly in target."],
246
- ["deploy-target","deploy-target [INSTANCE-NAME] [-v VERSION] [--no-auto-complete]", "# Deploy assembly as target instance."],
247
- ["deploy","deploy [INSTANCE-NAME] [-t PARENT-SERVICE-INSTANCE-NAME/ID] [-v VERSION] [--no-auto-complete]", "# Deploy assembly in target."],
248
- ["list-nodes","list-nodes", "# List all nodes for given assembly."],
249
- ["list-components","list-components", "# List all components for given assembly."],
250
- ["list-settings","list-settings", "# List all settings for given assembly."]
251
- ]
252
- }
253
-
254
- })
255
- end
256
-
257
- ##MERGE-QUESTION: need to add options of what info is about
258
- desc "SERVICE-MODULE-NAME/ID info", "Provides information about specified service module"
259
- def info(context_params)
260
- module_info_aux(context_params)
261
- end
262
-
263
- desc "SERVICE-MODULE-NAME/ID list-assemblies [-v VERSION]","List assemblies associated with service module."
264
- version_method_option
265
- method_option :remote, :type => :boolean, :default => false
266
- def list_assemblies(context_params)
267
- context_params.method_arguments = ["assembly"]
268
- list(context_params)
269
- end
270
-
271
- desc "SERVICE-MODULE-NAME/ID list-component-modules","List component modules associated with service module."
272
- method_option :remote, :type => :boolean, :default => false
273
- def list_component_modules(context_params)
274
- context_params.method_arguments = ["modules"]
275
- list(context_params)
276
- end
277
-
278
- desc "list [--remote] [--diffs] [-n NAMESPACE]","List service modules (local/remote). Use --diff to compare loaded and remote modules."
279
- method_option :remote, :type => :boolean, :default => false
280
- method_option :diffs, :type => :boolean, :default => false, :aliases => "--diff"
281
- method_option :namespace, :aliases => "-n" ,
282
- :type => :string,
283
- :banner => "NAMESPACE",
284
- :desc => "List modules only in specific namespace."
285
- # method_option :with_versions, :type => :boolean, :default => false, :aliases => "with-versions"
286
- def list(context_params)
287
- service_module_id, about, service_module_name = context_params.retrieve_arguments([:service_module_id, :option_1, :option_2],method_argument_names)
288
- datatype = nil
289
-
290
- if context_params.is_there_command?(:"assembly")
291
- about = "assembly"
292
- end
293
-
294
- if service_module_id.nil? && !service_module_name.nil?
295
- service_module_id = service_module_name
296
- end
297
-
298
- # If user is on service level, list task can't have about value set
299
- if (context_params.last_entity_name == :"service-module") and about.nil?
300
- action = options.remote? ? "list_remote" : "list"
301
- post_body = (options.remote? ? { :rsa_pub_key => SSHUtil.rsa_pub_key_content() } : {:detail_to_include => ["remotes"]})
302
- post_body[:diff] = options.diffs? ? options.diffs : {}
303
- post_body.merge!(:module_namespace => options.namespace) if options.namespace
304
-
305
- if post_body[:detail_to_include]
306
- post_body[:detail_to_include] << 'versions' # if options.with_versions?
307
- else
308
- post_body[:detail_to_include]
309
- end
310
-
311
- response = post rest_url("service_module/#{action}"), post_body
312
- # If user is on service identifier level, list task can't have '--remote' option.
313
- else
314
- # TODO: this is temp; will shortly support this
315
- raise DTK::Client::DtkValidationError.new("Not supported '--remote' option when listing service module assemblies, component templates or modules", true) if options.remote?
316
- raise DTK::Client::DtkValidationError.new("Not supported type '#{about}' for list for current context level. Possible type options: 'assembly'", true) unless(about == "assembly" || about == "modules")
317
- post_body = { :service_module_id => service_module_id }
318
- if about
319
- case about
320
- when "assembly"
321
- version = options.version
322
- data_type = :assembly_template_description
323
- action = "list_assemblies"
324
- post_body.merge!(:version => version) if version
325
- when "modules"
326
- data_type = options.remote? ? :component_remote : :component_module
327
- action = "list_component_modules"
328
- else
329
- raise_validation_error_method_usage('list')
330
- end
331
- end
332
- response = post rest_url("service_module/#{action}"), post_body
333
- end
334
-
335
- unless response.nil?
336
- if options.with_versions?
337
- response.render_table(:module_with_versions, true)
338
- else
339
- response.render_table(data_type)
340
- end
341
- end
342
-
343
- response
344
- end
345
-
346
- desc "SERVICE-MODULE-NAME/ID list-instances","List all instances associated with this service module."
347
- def list_instances(context_params)
348
- list_instances_aux(context_params)
349
- end
350
-
351
- desc "SERVICE-MODULE-NAME/ID list-versions","List all versions associated with this service module."
352
- def list_versions(context_params)
353
- response = list_versions_aux(context_params)
354
- return response unless response.ok?
355
- response.render_table(:list_versions, true)
356
- end
357
-
358
- desc "SERVICE-MODULE-NAME/ID list-remote-versions","List all remote versions associated with this service module."
359
- def list_remote_versions(context_params)
360
- response = list_remote_versions_aux(context_params)
361
- return response unless response.ok?
362
- response.render_table(:list_versions, true)
363
- end
364
-
365
- # version_method_option
366
- desc "install NAMESPACE/REMOTE-SERVICE-MODULE-NAME [-y] [-v VERSION]", "Install remote service module into local environment. -y will automatically clone component modules."
367
- method_option :force, :aliases => '-y', :type => :boolean, :default => false
368
- # method_option :ignore, :aliases => '-i', :type => :boolean, :default => false
369
- method_option :update_none, :type => :boolean, :default => false
370
- version_method_option
371
- def install(context_params)
372
- response = install_module_aux(context_params)
373
- @@invalidate_map << :service_module if response && response.ok?
374
-
375
- response
376
- end
377
-
378
- =begin
379
- # desc "SERVICE-MODULE-NAME/ID validate-model [-v VERSION]", "Check the DSL Model for Errors"
380
- # version_method_option
381
- desc "SERVICE-MODULE-NAME/ID validate-model", "Check the DSL Model for Errors"
382
- def validate_model(context_params)
383
- service_module_id, service_module_name = context_params.retrieve_arguments([:service_module_id!, :service_module_name],method_argument_names)
384
- version = options["version"]
385
-
386
- if service_module_name.to_s =~ /^[0-9]+$/
387
- service_module_id = service_module_name
388
- service_module_name = get_service_module_name(service_module_id)
389
- end
390
-
391
- modules_path = OsUtil.service_clone_location()
392
- module_location = "#{modules_path}/#{service_module_name}#{version && "-#{version}"}"
393
-
394
- raise DTK::Client::DtkValidationError, "Unable to parse service '#{service_module_name}#{version && "-#{version}"}' that doesn't exist on your local machine!" unless File.directory?(module_location)
395
-
396
- reparse_aux(module_location)
397
- end
398
- =end
399
-
400
- # desc "SERVICE-MODULE-NAME/ID import-version VERSION", "Import a specific version from a linked service module"
401
- # def import_version(context_params)
402
- # service_module_id,version = context_params.retrieve_arguments([:service_module_id!,:option_1!],method_argument_names)
403
- # post_body = {
404
- # :service_module_id => service_module_id,
405
- # :version => version
406
- # }
407
- # response = post rest_url("service_module/import_version"), post_body
408
- # @@invalidate_map << :module_service
409
-
410
- # return response unless response.ok?
411
- # module_name,repo_url,branch,version = response.data(:module_name,:repo_url,:workspace_branch,:version)
412
-
413
- # if error = response.data(:dsl_parse_error)
414
- # dsl_parsed_message = ServiceImporter.error_message("#{module_name}-#{version}", error)
415
- # DTK::Client::OsUtil.print(dsl_parsed_message, :red)
416
- # end
417
-
418
- # #TODO: need to check if local clone directory exists
419
- # Helper(:git_repo).create_clone_with_branch(:service_module,module_name,repo_url,branch,version)
420
- # end
421
-
422
- # desc "SERVICE-MODULE-NAME/ID create-on-dtkn [[NAMESPACE/]REMOTE-MODULE-NAME]","Export service module to remote repository"
423
- # def create_on_dtkn(context_params)
424
- # service_module_id, input_remote_name = context_params.retrieve_arguments([:service_module_id!, :option_1],method_argument_names)
425
-
426
- # post_body = {
427
- # :service_module_id => service_module_id,
428
- # :remote_component_name => input_remote_name,
429
- # :rsa_pub_key => SSHUtil.rsa_pub_key_content()
430
- # }
431
-
432
- # post rest_url("service_module/export"), post_body
433
- # end
434
-
435
- desc "SERVICE-MODULE-NAME/ID publish [[NAMESPACE/]REMOTE-SERVICE-MODULE-NAME] -v VERSION [--force]","Publish service module to remote repository"
436
- version_method_option
437
- method_option :force, :type => :boolean, :default => false, :aliases => '-f'
438
- def publish(context_params)
439
- publish_module_aux(context_params)
440
- end
441
-
442
- # desc "SERVICE-MODULE-NAME/ID push-to-dtkn [-n NAMESPACE] [-v VERSION]", "Push local copy of service module to remote repository."
443
- # version_method_option
444
- # desc "SERVICE-MODULE-NAME/ID push-to-dtkn [-n NAMESPACE]", "Push local copy of service module to remote repository."
445
- # method_option "namespace",:aliases => "-n",
446
- # :type => :string,
447
- # :banner => "NAMESPACE",
448
- # :desc => "Remote namespace"
449
- # def push_to_dtkn(context_params)
450
- # service_module_id, service_module_name = context_params.retrieve_arguments([:service_module_id!, :service_module_name],method_argument_names)
451
- # version = options["version"]
452
-
453
- # if service_module_name.to_s =~ /^[0-9]+$/
454
- # service_id = service_module_name
455
- # service_module_name = get_service_module_name(service_id)
456
- # end
457
-
458
- # modules_path = OsUtil.service_clone_location()
459
- # module_location = "#{modules_path}/#{service_module_name}#{version && "-#{version}"}"
460
-
461
- # unless File.directory?(module_location)
462
- # if Console.confirmation_prompt("Unable to push to remote because module '#{service_module_name}#{version && "-#{version}"}' has not been cloned. Would you like to clone module now"+'?')
463
- # response = clone_aux(:service_module,service_module_id,version,false)
464
-
465
- # if(response.nil? || response.ok?)
466
- # reparse_aux(module_location)
467
- # push_to_remote_aux(:service_module, service_module_id, service_module_name, options["namespace"], version) if Console.confirmation_prompt("Would you like to push changes to remote"+'?')
468
- # end
469
-
470
- # return response
471
- # else
472
- # # user choose not to clone needed module
473
- # return
474
- # end
475
- # end
476
-
477
- # reparse_aux(module_location)
478
- # push_to_remote_aux(:service_module, service_module_id, service_module_name, options["namespace"], options["version"])
479
- # end
480
-
481
- desc "SERVICE-MODULE-NAME/ID pull-dtkn [-n NAMESPACE] [--force]", "Update local service module from remote repository."
482
- method_option :namespace,:aliases => '-n',
483
- :type => :string,
484
- :banner => "NAMESPACE",
485
- :desc => "Remote namespace"
486
- method_option :force,:aliases => '-f',
487
- :type => :boolean,
488
- :desc => "Force pull",
489
- :default => false
490
- def pull_dtkn(context_params)
491
- pull_dtkn_aux(context_params)
492
- end
493
-
494
- desc "SERVICE-MODULE-NAME/ID chmod PERMISSION-SELECTOR", "Update remote permissions e.g. ug+rw , user and group get RW permissions"
495
- method_option "namespace", :aliases => "-n", :type => :string, :banner => "NAMESPACE", :desc => "Remote namespace"
496
- def chmod(context_params)
497
- chmod_module_aux(context_params)
498
- end
499
-
500
- desc "SERVICE-MODULE-NAME/ID make-public", "Make this module public"
501
- method_option "namespace", :aliases => "-n", :type => :string, :banner => "NAMESPACE", :desc => "Remote namespace"
502
- def make_public(context_params)
503
- make_public_module_aux(context_params)
504
- end
505
-
506
- desc "SERVICE-MODULE-NAME/ID make-private", "Make this module private"
507
- method_option "namespace", :aliases => "-n", :type => :string, :banner => "NAMESPACE", :desc => "Remote namespace"
508
- def make_private(context_params)
509
- make_private_module_aux(context_params)
510
- end
511
-
512
- desc "SERVICE-MODULE-NAME/ID add-collaborators", "Add collabrators users or groups comma seperated (--users or --groups)"
513
- method_option "namespace", :aliases => "-n", :type => :string, :banner => "NAMESPACE", :desc => "Remote namespace"
514
- method_option "users",:aliases => "-u", :type => :string, :banner => "USERS", :desc => "User collabrators"
515
- method_option "groups",:aliases => "-g", :type => :string, :banner => "GROUPS", :desc => "Group collabrators"
516
- def add_collaborators(context_params)
517
- add_collaborators_module_aux(context_params)
518
- end
519
-
520
- desc "SERVICE-MODULE-NAME/ID remove-collaborators", "Remove collabrators users or groups comma seperated (--users or --groups)"
521
- method_option "namespace",:aliases => "-n",:type => :string, :banner => "NAMESPACE", :desc => "Remote namespace"
522
- method_option "users",:aliases => "-u", :type => :string, :banner => "USERS", :desc => "User collabrators"
523
- method_option "groups",:aliases => "-g", :type => :string, :banner => "GROUPS", :desc => "Group collabrators"
524
- def remove_collaborators(context_params)
525
- remove_collaborators_module_aux(context_params)
526
- end
527
-
528
- desc "SERVICE-MODULE-NAME/ID list-collaborators", "List collaborators for given module"
529
- method_option "namespace",:aliases => "-n",:type => :string, :banner => "NAMESPACE", :desc => "Remote namespace"
530
- def list_collaborators(context_params)
531
- list_collaborators_module_aux(context_params)
532
- end
533
-
534
- ##
535
- #
536
- # internal_trigger: this flag means that other method (internal) has trigger this.
537
- # This will change behaviour of method
538
- #
539
- # desc "SERVICE-MODULE-NAME/ID clone [-v VERSION] [-n]", "Locally clone the service module files. Use -n to skip edit prompt"
540
- # version_method_option
541
- desc "SERVICE-MODULE-NAME/ID clone [-n] [-v VERSION]", "Locally clone the service module files. Use -n to skip edit prompt"
542
- method_option :skip_edit, :aliases => '-n', :type => :boolean, :default => false
543
- version_method_option
544
- def clone(context_params, internal_trigger=false)
545
- clone_module_aux(context_params, internal_trigger)
546
- end
547
-
548
- # desc "SERVICE-MODULE-NAME/ID edit [-v VERSION]","Switch to unix editing for given service module."
549
- # version_method_option
550
- desc "SERVICE-MODULE-NAME/ID edit","Switch to unix editing for given service module."
551
- def edit(context_params)
552
- edit_module_aux(context_params)
553
- end
554
-
555
- # TODO: put in two versions, one that creates empty and anotehr taht creates from local dir; use --empty flag
556
- desc "import [NAMESPACE:]SERVICE-MODULE-NAME", "Create new service module from local clone"
557
- def import(context_params)
558
- module_name = context_params.retrieve_arguments([:option_1!],method_argument_names)
559
- namespace, local_module_name = get_namespace_and_name(module_name, ':')
560
-
561
- # first check that there is a directory there and it is not already a git repo, and it ha appropriate content
562
- response = Helper(:git_repo).check_local_dir_exists_with_content(:service_module, local_module_name, nil, namespace)
563
- return response unless response.ok?
564
- service_directory = response.data(:module_directory)
565
-
566
- #check for yaml/json parsing errors before import
567
- reparse_aux(service_directory)
568
-
569
- # first call to create empty module
570
- response = post rest_url("service_module/create"), { :module_name => local_module_name, :module_namespace => namespace }
571
- return response unless response.ok?
572
- @@invalidate_map << :service_module
573
-
574
- # initial commit for given service module
575
- service_module_id, repo_info = response.data(:service_module_id, :repo_info)
576
- repo_url,repo_id,module_id,branch,new_module_name = [:repo_url,:repo_id,:module_id,:workspace_branch,:full_module_name].map { |k| repo_info[k.to_s] }
577
-
578
- response = Helper(:git_repo).rename_and_initialize_clone_and_push(:service_module, local_module_name, new_module_name,branch,repo_url,service_directory)
579
- return response unless (response && response.ok?)
580
-
581
- repo_obj,commit_sha = response.data(:repo_obj,:commit_sha)
582
- module_final_dir = repo_obj.repo_dir
583
- old_dir = response.data[:old_dir]
584
-
585
- context_params.add_context_to_params(local_module_name, :"service-module", module_id)
586
- response = push(context_params,true)
587
-
588
- unless response.ok?
589
- # remove new directory and leave the old one if import without namespace failed
590
- if old_dir and (old_dir != module_final_dir)
591
- FileUtils.rm_rf(module_final_dir) unless namespace
592
- end
593
- return response
594
- end
595
-
596
- # remove the old one if no errors while importing
597
- # DTK-1768: removed below; and replaced by removing old dir if unequal to final dir
598
- # was not sure why clause namespace was in so kept this condition
599
- #FileUtils.rm_rf(old_dir) unless namespace
600
- if old_dir and (old_dir != module_final_dir)
601
- FileUtils.rm_rf(old_dir) unless namespace
602
- end
603
-
604
- DTK::Client::OsUtil.print("Module '#{new_module_name}' has been created and module directory moved to #{repo_obj.repo_dir}",:yellow) unless namespace
605
-
606
- response
607
- end
608
-
609
- desc "SERVICE-MODULE-NAME/ID stage-target ASSEMBLY-NAME [INSTANCE-NAME] [-v VERSION] [--no-auto-complete]", "Stage assembly as target instance."
610
- method_option :settings, :type => :string, :aliases => '-s'
611
- method_option :no_auto_complete, :type => :boolean, :default => false, :aliases => '--no-ac'
612
- # method_option :parent_service, :type => :string, :aliases => '-t'
613
- version_method_option
614
- #hidden options
615
- method_option "instance-bindings", :type => :string
616
- method_option :is_target, :type => :boolean, :default => true
617
- def stage_target(context_params)
618
- response = stage_aux(context_params)
619
- return response unless response.ok?
620
-
621
- # when changing context send request for getting latest assemblies instead of getting from cache
622
- @@invalidate_map << :service
623
- @@invalidate_map << :assembly
624
-
625
- return response
626
- end
627
-
628
- desc "SERVICE-MODULE-NAME/ID stage ASSEMBLY-NAME [INSTANCE-NAME] [-t PARENT-SERVICE-INSTANCE-NAME/ID] [-v VERSION] [--no-auto-complete]", "Stage assembly in target."
629
- method_option "in-target", :aliases => "-t", :type => :string, :banner => "TARGET-NAME/ID", :desc => "Target (id) to create assembly in"
630
- method_option :settings, :type => :string, :aliases => '-s'
631
- method_option :no_auto_complete, :type => :boolean, :default => false, :aliases => '--no-ac'
632
- method_option :parent_service, :type => :string, :aliases => '-t'
633
- version_method_option
634
- #hidden option
635
- method_option "instance-bindings", :type => :string
636
- def stage(context_params)
637
- response = stage_aux(context_params)
638
- return response unless response.ok?
639
-
640
- # when changing context send request for getting latest assemblies instead of getting from cache
641
- @@invalidate_map << :service
642
- @@invalidate_map << :assembly
643
-
644
- return response
645
- end
646
-
647
-
648
- # desc "SERVICE-MODULE-NAME/ID push [-v VERSION] [-m COMMIT-MSG]", "Push changes from local copy of service module to server"
649
- # version_method_option
650
- =begin
651
- desc "SERVICE-MODULE-NAME/ID push origin|dtkn [-n NAMESPACE] [-m COMMIT-MSG]", "Push changes from local copy of service module to server (origin) or to remote repository (dtkn)."
652
- method_option "message",:aliases => "-m" ,
653
- :type => :string,
654
- :banner => "COMMIT-MSG",
655
- :desc => "Commit message"
656
- method_option "namespace",:aliases => "-n",
657
- :type => :string,
658
- :banner => "NAMESPACE",
659
- :desc => "Remote namespace"
660
- #hidden option for dev
661
- method_option 'force-parse', :aliases => '-f', :type => :boolean, :default => false
662
- def push(context_params, internal_trigger=false)
663
- service_module_id, service_module_name, catalog = context_params.retrieve_arguments([:service_module_id!, :service_module_name, :option_1],method_argument_names)
664
- version = options["version"]
665
-
666
- raise DtkValidationError, "You have to provide valid catalog to push changes to! Valid catalogs: #{PushCatalogs}" unless catalog
667
-
668
- if service_module_name.to_s =~ /^[0-9]+$/
669
- service_module_id = service_module_name
670
- service_module_name = get_service_module_name(service_module_id)
671
- end
672
-
673
- modules_path = OsUtil.service_clone_location()
674
- module_location = "#{modules_path}/#{service_module_name}#{version && "-#{version}"}"
675
- reparse_aux(module_location) unless internal_trigger
676
-
677
- if catalog.to_s.eql?("origin")
678
- push_clone_changes_aux(:service_module,service_module_id,version,nil,internal_trigger)
679
- elsif catalog.to_s.eql?("dtkn")
680
- unless File.directory?(module_location)
681
- if Console.confirmation_prompt("Unable to push to remote because module '#{service_module_name}#{version && "-#{version}"}' has not been cloned. Would you like to clone module now"+'?')
682
- response = clone_aux(:service_module,service_module_id,version,false)
683
-
684
- if(response.nil? || response.ok?)
685
- reparse_aux(module_location)
686
- push_to_remote_aux(:service_module, service_module_id, service_module_name, options["namespace"], version) if Console.confirmation_prompt("Would you like to push changes to remote"+'?')
687
- end
688
-
689
- return response
690
- else
691
- # user choose not to clone needed module
692
- return
693
- end
694
- end
695
-
696
- push_to_remote_aux(:service_module, service_module_id, service_module_name, options["namespace"], options["version"])
697
- else
698
- raise DtkValidationError, "You have to provide valid catalog to push changes to! Valid catalogs: #{PushCatalogs}"
699
- end
700
- end
701
- PushCatalogs = ["origin", "dtkn"]
702
- =end
703
-
704
- # desc "SERVICE-MODULE-NAME/ID push [-m COMMIT-MSG]", "Push changes from local copy to server (origin)."
705
- desc "SERVICE-MODULE-NAME/ID push [--force] [--docs]", "Push changes from local copy to server."
706
- method_option "message",:aliases => "-m" ,
707
- :type => :string,
708
- :banner => "COMMIT-MSG",
709
- :desc => "Commit message"
710
- method_option :force, :type => :boolean, :default => false, :aliases => '-f'
711
- method_option :docs, :type => :boolean, :default => false, :aliases => '-d'
712
- def push(context_params, internal_trigger=false)
713
- push_module_aux(context_params, internal_trigger)
714
- end
715
-
716
- # desc "SERVICE-MODULE-NAME/ID push-dtkn [-n NAMESPACE] [-m COMMIT-MSG]", "Push changes from local copy of service module to remote repository (dtkn)."
717
- desc "SERVICE-MODULE-NAME/ID push-dtkn [-n NAMESPACE] [--force]", "Push changes from local copy of service module to remote repository (dtkn)."
718
- method_option "message",:aliases => "-m" ,
719
- :type => :string,
720
- :banner => "COMMIT-MSG",
721
- :desc => "Commit message"
722
- method_option "namespace",:aliases => "-n",
723
- :type => :string,
724
- :banner => "NAMESPACE",
725
- :desc => "Remote namespace"
726
- method_option :force, :type => :boolean, :default => false, :aliases => '-f'
727
- def push_dtkn(context_params, internal_trigger=false)
728
- push_dtkn_module_aux(context_params, internal_trigger)
729
- end
730
-
731
- desc "SERVICE-MODULE-NAME/ID list-diffs", "List diffs between module on server and remote repo"
732
- method_option :remote, :type => :boolean, :default => false
733
- def list_diffs(context_params)
734
- list_remote_module_diffs(context_params)
735
- # list_diffs_module_aux(context_params)
736
- end
737
-
738
- desc "delete-version SERVICE-MODULE-NAME [-y] [-p] [-v VERSION]", "Delete service module version and all items contained in it. Optional parameter [-p] is to delete local directory."
739
- method_option :force, :aliases => '-y', :type => :boolean, :default => false
740
- method_option :purge, :aliases => '-p', :type => :boolean, :default => false
741
- version_method_option
742
- def delete_version(context_params, method_opts = {})
743
- response = delete_module_aux(context_params, method_opts)
744
- @@invalidate_map << :service_module if response && response.ok?
745
-
746
- response
747
- end
748
-
749
- desc "delete SERVICE-MODULE-NAME [-y] [-p]", "Delete service module and all items contained in it. Optional parameter [-p] is to delete local directory."
750
- method_option :force, :aliases => '-y', :type => :boolean, :default => false
751
- method_option :purge, :aliases => '-p', :type => :boolean, :default => false
752
- def delete(context_params)
753
- response = delete_module_aux(context_params, :delete_all => true)
754
- @@invalidate_map << :service_module if response && response.ok?
755
-
756
- response
757
- end
758
-
759
- desc "delete-from-catalog NAMESPACE/REMOTE-SERVICE-MODULE-NAME [-y] [--force] [-v VERSION]", "Delete the service module from the DTK Network catalog"
760
- method_option :confirmed, :aliases => '-y', :type => :boolean, :default => false
761
- method_option :force, :type => :boolean, :default => false
762
- version_method_option
763
- def delete_from_catalog(context_params)
764
- delete_from_catalog_aux(context_params)
765
- end
766
-
767
- desc "SERVICE-MODULE-NAME/ID delete-assembly ASSEMBLY-NAME [-y]", "Delete assembly from service module."
768
- method_option :force, :aliases => '-y', :type => :boolean, :default => false
769
- def delete_assembly(context_params)
770
- response = delete_assembly_aux(context_params)
771
- @@invalidate_map << :assembly if response && response.ok?
772
-
773
- response
774
- end
775
-
776
-
777
- # REMOTE INTERACTION
778
-
779
- desc "HIDE_FROM_BASE push-remote [REMOTE-NAME] [--force]", "Push local changes to remote git repository"
780
- method_option :force, :type => :boolean, :default => false
781
- def push_remote(context_params)
782
- push_remote_module_aux(context_params)
783
- end
784
-
785
- desc "HIDE_FROM_BASE list-remotes", "List git remotes for given module"
786
- def list_remotes(context_params)
787
- remote_list_aux(context_params)
788
- end
789
-
790
- desc "HIDE_FROM_BASE add-remote REMOTE-NAME REMOTE-URL", "Add git remote for given module"
791
- def add_remote(context_params)
792
- remote_add_aux(context_params)
793
- end
794
-
795
- desc "HIDE_FROM_BASE remove-remote REPO-NAME [-y]", "Remove git remote for given module"
796
- method_option :force, :aliases => '-y', :type => :boolean, :default => false
797
- def remove_remote(context_params)
798
- remote_remove_aux(context_params)
799
- end
800
-
801
- desc "SERVICE-MODULE-NAME/ID fork NAMESPACE", "Fork service module to new namespace"
802
- def fork(context_params)
803
- fork_aux(context_params)
804
- end
805
-
806
- desc "SERVICE-MODULE-NAME/ID create-new-version VERSION", "Create new service module version"
807
- def create_new_version(context_params)
808
- create_new_version_aux(context_params)
809
- end
810
-
811
- desc "SERVICE-MODULE-NAME/ID deploy-target ASSEMBLY-NAME [INSTANCE-NAME] [-v VERSION] [--no-auto-complete] [--stream-results]", "Deploy assembly as target instance."
812
- method_option :no_auto_complete, :type => :boolean, :default => false, :aliases => '--no-ac'
813
- method_option 'stream-results', :aliases => '-s', :type => :boolean, :default => false, :desc => "Stream results"
814
- version_method_option
815
- #hidden options
816
- method_option "instance-bindings", :type => :string
817
- method_option :is_target, :type => :boolean, :default => true
818
- # method_option :settings, :type => :string, :aliases => '-s'
819
- def deploy_target(context_params)
820
- response = deploy_aux(context_params)
821
- return response unless response.ok?
822
-
823
- @@invalidate_map << :service
824
- @@invalidate_map << :assembly
825
-
826
- response
827
- end
828
-
829
- desc "SERVICE-MODULE-NAME/ID deploy ASSEMBLY-NAME [INSTANCE-NAME] [-t PARENT-SERVICE-INSTANCE-NAME/ID] [-v VERSION] [--no-auto-complete] [--stream-results]", "Deploy assembly in target."
830
- method_option :no_auto_complete, :type => :boolean, :default => false, :aliases => '--no-ac'
831
- method_option :parent_service, :type => :string, :aliases => '-t'
832
- method_option 'stream-results', :aliases => '-s', :type => :boolean, :default => false, :desc => "Stream results"
833
- version_method_option
834
- #hidden options
835
- method_option "instance-bindings", :type => :string
836
- # method_option :settings, :type => :string, :aliases => '-s'
837
- def deploy(context_params)
838
- response = deploy_aux(context_params)
839
- return response unless response.ok?
840
-
841
- @@invalidate_map << :service
842
- @@invalidate_map << :assembly
843
-
844
- response
845
- end
846
-
847
- #
848
- # DEVELOPMENT MODE METHODS
849
- #
850
- if DTK::Configuration.get(:development_mode)
851
-
852
- desc "delete-all","Delete all service modules"
853
- def delete_all(context_params)
854
- return unless Console.confirmation_prompt("This will DELETE ALL service modules, are you sure"+'?')
855
- response = list(context_params)
856
-
857
- response.data().each do |e|
858
- run_shell_command("delete #{e['display_name']} -y -p")
859
- end
860
- end
861
-
862
- end
863
- =begin
864
- desc "SERVICE-NAME/ID assembly-templates list", "List assembly templates optionally filtered by service ID/NAME."
865
- def assembly_template(context_params)
866
-
867
- service_id, method_name = context_params.retrieve_arguments([:service_name!, :option_1!],method_argument_names)
868
-
869
- options_args = ["-s", service_id]
870
-
871
- entity_name = "assembly_template"
872
- load_command(entity_name)
873
- entity_class = DTK::Client.const_get "#{cap_form(entity_name)}"
874
-
875
- response = entity_class.execute_from_cli(@conn, method_name, DTK::Shell::ContextParams.new, options_args, false)
876
-
877
- end
878
- =end
879
- =begin
880
- TODO: needs to be rewritten
881
- desc "create-jenkins-project SERVICE-ID", "Create Jenkins project for service module"
882
- def create_jenkins_project(context_params)
883
- service_module_id = context_params.retrieve_arguments([:service_id],method_argument_names)
884
- #require put here so dont necessarily have to install jenkins client gems
885
-
886
- dtk_require_from_base('command_helpers/jenkins_client')
887
- response = get rest_url("service_module/workspace_branch_info/#{service_module_id.to_s}")
888
- unless response.ok?
889
- errors_message = ''
890
- response['errors'].each { |error| errors_message += ", reason='#{error['code']}' message='#{error['message']}'" }
891
- raise DTK::Client::DtkError, "Invalid jenkins response#{errors_message}"
892
- end
893
- module_name,repo_url,branch = response.data_ret_and_remove!(:module_name,:repo_url,:workspace_branch)
894
- JenkinsClient.create_service_module_project?(service_module_id,module_name,repo_url,branch)
895
- #TODO: right now JenkinsClient wil throw error if problem; better to create an error resonse
896
- response
897
- end
898
- =end
899
- end
900
- end