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,555 +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
- require 'thor'
19
- require 'thor/group'
20
- require 'readline'
21
- require 'colorize'
22
- require 'digest/sha1'
23
-
24
- dtk_require("../../shell/interactive_wizard")
25
- dtk_require("../../util/os_util")
26
- dtk_require("../../util/console")
27
- dtk_require_from_base('task_status')
28
- dtk_require_from_base("command_helper")
29
- dtk_require("../../context_router")
30
- dtk_require_common_commands('thor/poller')
31
-
32
- module DTK
33
- module Client
34
- class CommandBaseThor < Thor
35
- dtk_nested_require('thor','common_option_defs')
36
-
37
- include CommandBase
38
- include CommandHelperMixin
39
- include Poller
40
-
41
- extend CommandBase
42
- extend TaskStatusMixin
43
- extend Console
44
- extend CommonOptionDefs::ClassMixin
45
-
46
- @@cached_response = {}
47
- @@invalidate_map = []
48
- TIME_DIFF = 60 # second(s)
49
- EXTENDED_TIMEOUT = 360 # second(s)
50
- HIDE_FROM_BASE_CONTEXT = "HIDE_FROM_BASE"
51
-
52
- # thor command specific constants
53
- ALT_IDENTIFIER_SEPARATOR = ':::'
54
-
55
- def initialize(args, opts, config)
56
- @conn = config[:conn]
57
- super
58
- end
59
-
60
- def self.execute_from_cli(conn,method_name,context_params,thor_options,shell_execution=false)
61
- @@shell_execution = shell_execution
62
-
63
- if method_name == 'help'
64
- ret = start([method_name] + context_params.method_arguments,:conn => conn)
65
- else
66
- ret = start([method_name, context_params] + (thor_options||[]),:conn => conn)
67
- end
68
-
69
- # special case where we have validation reply
70
- if ret.kind_of?(Response)
71
- if ret.validation_response?
72
- ret = action_on_revalidation_response(ret, conn, method_name, context_params, thor_options, shell_execution)
73
- end
74
- end
75
-
76
- ret.kind_of?(Response) ? ret : Response::NoOp.new
77
- end
78
-
79
- # TODO: Make sure that server responds with new format of ARGVS
80
- def self.action_on_revalidation_response(validation_response, conn, method_name, context_params, thor_options, shell_execution)
81
- puts "[NOTICE] #{validation_response.validation_message}"
82
- actions = validation_response.validation_actions
83
-
84
- actions.each_with_index do |action, i|
85
- if Console.confirmation_prompt("Pre-action '#{action['action']}' needed, execute"+"?")
86
- # we have hash map with values { :assembly_id => 2123123123, :option_1 => true }
87
- # we translate to array of values, with action as first element
88
-
89
- # def self.execute_from_cli(conn,method_name,context_params,options_args,shell_execution=false)
90
- response = self.execute_from_cli(conn, action['action'], create_context_arguments(action['params']),[],shell_execution)
91
- # we abort if error happens
92
- ResponseErrorHandler.check(response)
93
-
94
- if action['wait_for_complete']
95
- entity_id, entity_type = action['wait_for_complete']['id'].to_s, action['wait_for_complete']['type']
96
- puts "Waiting for task to complete ..."
97
- task_status_aux(entity_id,entity_type,:wait => true)
98
- end
99
- else
100
- # validation action are being skipped
101
- return ""
102
- end
103
- end
104
-
105
- puts "Executing original action: '#{method_name}' ..."
106
- # if all executed correctly we run original action
107
- return self.execute_from_cli(conn,method_name, context_params,thor_options,shell_execution)
108
- end
109
-
110
- def self.invalidate_entities(*array_of_entites)
111
- # we handle to cases here
112
- # n-context invalidation, whole structure
113
- @@invalidate_map << array_of_entites.join('_').to_sym
114
-
115
- # last entity
116
- @@invalidate_map << array_of_entites.last.to_sym
117
- end
118
-
119
- # we take current timestamp and compare it to timestamp stored in @@cached_response
120
- # if difference is greater than TIME_DIFF we send request again, if not we use
121
- # response from cache
122
- def self.get_cached_response(entity_name, url, subtype={})
123
- subtype ||= {}
124
- current_ts = Time.now.to_i
125
- cache_id = (subtype.empty? ? :response : generate_cached_id(subtype))
126
-
127
- # if @@cache_response is empty return true if not than return time difference between
128
- # current_ts and ts stored in cache
129
- time_difference = @@cached_response[entity_name].nil? ? true : ((current_ts - @@cached_response[entity_name][:ts]) > TIME_DIFF)
130
-
131
- if (@@cached_response[entity_name])
132
- time_difference = true if @@cached_response[entity_name][cache_id].nil?
133
- end
134
-
135
- if (time_difference || @@invalidate_map.include?(entity_name))
136
- response = post rest_url(url), subtype
137
-
138
- # we do not want to catch is if it is not valid
139
- if response.nil? || response.empty?
140
- DtkLogger.instance.debug("Response was nil or empty for that reason we did not cache it.")
141
- return response
142
- end
143
-
144
- if response.ok?
145
- response_hash = {cache_id => response, :ts => current_ts}
146
-
147
- @@invalidate_map.delete(entity_name) if @@invalidate_map.include?(entity_name)
148
-
149
- if @@cached_response[entity_name]
150
- @@cached_response[entity_name].merge!(response_hash)
151
- else
152
- @@cached_response.store(entity_name, response_hash)
153
- end
154
- end
155
- end
156
-
157
- if @@cached_response[entity_name]
158
- return @@cached_response[entity_name][cache_id]
159
- else
160
- return nil
161
- end
162
- end
163
-
164
- def self.generate_cached_id(subtype)
165
- values = ''
166
- # subtype.sort.map do |key,value|
167
- # removed sort since subtype is hash where keys are symbols,
168
- # sort method uses the <=> comparison operator to put things into order but
169
- # symbols don't have a <=> comparison operator in ruby 1.8.7
170
- subtype.map do |key,value|
171
- values += value.to_s
172
- end
173
-
174
- Digest::SHA1.hexdigest(values)
175
- end
176
-
177
- def self.create_context_arguments(params)
178
- context_params = DTK::Shell::ContextParams.new
179
- params.each do |k,v|
180
- context_params.add_context_to_params(k,k,v)
181
- end
182
- return context_params
183
- end
184
-
185
- def self.list_method_supported?
186
- return (respond_to?(:validation_list) || respond_to?(:whoami))
187
- end
188
-
189
- # returns all task names for given thor class with use friendly names (with '-' instead '_')
190
- def self.task_names
191
- all_tasks().map(&:first).collect { |item| item.gsub('_','-')}
192
- end
193
-
194
- def self.get_usage_info(entity_name, method)
195
- # no need for nil checks since task will be found
196
- # [0] element contains desire usage description
197
- # [2] element contains method name with '_'
198
- result = printable_tasks().select { |help_item| help_item[2].gsub('_','-') == method }.flatten[0]
199
- # we add entity name with dashes
200
- return result.gsub('dtk', "dtk #{entity_name.gsub('_','-')}")
201
- end
202
-
203
- # caches all the taks names for each possible tier and each thor class
204
- # returnes it, executes only once and only on dtk-shell start
205
- def self.tiered_task_names
206
- # cached data
207
- cached_tasks = {}
208
-
209
- # get command name from namespace (which is derived by thor from file name)
210
- command = namespace.split(':').last.gsub('_','-').upcase
211
-
212
- # first elvel identifier
213
- command_sym = command.downcase.to_sym
214
- command_id_sym = (command.downcase + '_wid').to_sym
215
-
216
- cached_tasks.store(command_sym, [])
217
- cached_tasks.store(command_id_sym, [])
218
-
219
- # n-context children
220
- all_children = []
221
- children = self.respond_to?(:all_children) ? self.all_children() : nil
222
- all_children << children unless children.nil?
223
-
224
- # some commands have multiple n-level contexts
225
- # e.g. workspace_node_component, workspace_utils and workspace_node_utils
226
- # we go through all of them and load them to 'all_children'
227
- multi_context_children = self.respond_to?(:multi_context_children) ? self.multi_context_children() : nil
228
- if multi_context_children
229
- multi_context_children.each do |mc|
230
- all_children << (mc.is_a?(Array) ? mc : multi_context_children)
231
- end
232
- end
233
-
234
- # n-context-override task, special case which
235
- override_task_obj = self.respond_to?(:override_allowed_methods) ? self.override_allowed_methods.dup : nil
236
-
237
- # we seperate tier 1 and tier 2 tasks
238
- all_tasks().each do |task|
239
- # noralize task name with '-' since it will be displayed to user that way
240
- task_name = task[0].gsub('_','-')
241
- usage = task[1].usage
242
- # we will match those commands that require identifiers (NAME/ID)
243
- # e.g. ASSEMBLY-NAME/ID list ... => MATCH
244
- # e.g. [ASSEMBLY-NAME/ID] list ... => MATCH
245
- matched_data = task[1].usage.match(/\[?#{command}.?(NAME\/ID|ID\/NAME)\]?/)
246
- matched_alt_identifiers_data = nil
247
-
248
- # we chance alternate providers
249
- if respond_to?(:alternate_identifiers)
250
- alternate_identifiers = self.alternate_identifiers()
251
-
252
- alternate_identifiers.each do |a_provider|
253
- if matched_alt_identifiers_data = task[1].usage.match(/\[?#{a_provider}.?(NAME\/ID|ID\/NAME)\]?/)
254
- command_alt_sym = "#{command}_#{a_provider}".downcase.to_sym
255
- cached_tasks[command_alt_sym] = cached_tasks.fetch(command_alt_sym,[])
256
- cached_tasks[command_alt_sym] << task_name
257
- # when found break
258
- break
259
- end
260
- end
261
- end
262
-
263
- # only if not matched alt data found continue with caching of task
264
- unless matched_alt_identifiers_data
265
- if matched_data.nil?
266
- # no match it means it is tier 1 task, tier 1 => dtk:\assembly>
267
- # using HIDE_FROM_BASE_CONTEXT to hide command from base context (e.g from dtk:/assembly>) ...
268
- # ... but to be able to use that command in other context
269
- # (e.g get-netstats removed from dtk:/assembly> but used in dtk:/assembly/assembly_id/utils)
270
- cached_tasks[command_sym] << task_name unless usage.include?(HIDE_FROM_BASE_CONTEXT)
271
- else
272
- # match means it is tier 2 taks, tier 2 => dtk:\assembly\231312345>
273
- cached_tasks[command_id_sym] << task_name
274
- # if there are '[' it means it is optinal identifiers so it is tier 1 and tier 2 task
275
- cached_tasks[command_sym] << task_name if matched_data[0].include?('[')
276
- end
277
-
278
- # n-level matching
279
- all_children.each do |child|
280
- current_children = []
281
-
282
- child.each do |c|
283
- current_children << c.to_s
284
-
285
- # create entry e.g. assembly_node_id
286
- child_id_sym = (command.downcase + '_' + current_children.join('_') + '_wid').to_sym
287
-
288
- # n-context matching
289
- matched_data = task[1].usage.match(/^\[?#{c.to_s.upcase}.?(NAME\/ID|ID\/NAME|ID|NAME)(\-?PATTERN)?\]?/)
290
- if matched_data
291
- cached_tasks[child_id_sym] = cached_tasks.fetch(child_id_sym,[]) << task_name
292
- end
293
-
294
- # override method list, we add these methods only once
295
- if override_task_obj && !override_task_obj.is_completed?(c)
296
- command_o_tasks, identifier_o_tasks = override_task_obj.get_all_tasks(c)
297
- child_sym = (command.downcase + '_' + current_children.join('_')).to_sym
298
-
299
- command_o_tasks.each do |o_task|
300
- cached_tasks[child_sym] = cached_tasks.fetch(child_sym,[]) << o_task[0]
301
- end
302
-
303
- identifier_o_tasks.each do |o_task|
304
- cached_tasks[child_id_sym] = cached_tasks.fetch(child_id_sym,[]) << o_task[0]
305
- end
306
-
307
- override_task_obj.add_to_completed(c)
308
- end
309
- end
310
- end
311
- end
312
- end
313
-
314
- # there is always help, and in all cases this is exception to the rule
315
- cached_tasks[command_id_sym] << 'help'
316
-
317
- return cached_tasks
318
- end
319
-
320
- # we make valid methods to make sure that when context changing
321
- # we allow change only for valid ID/NAME
322
- def self.valid_id?(value, conn, context_params)
323
-
324
- context_list = self.get_identifiers(conn, context_params)
325
- results = context_list.select { |e| e[:name].eql?(value) || e[:identifier].eql?(value.to_i)}
326
-
327
- return results.empty? ? nil : results.first
328
- end
329
-
330
- def self.get_identifiers(conn, context_params)
331
- @conn = conn if @conn.nil?
332
-
333
- # we force raw output
334
- # options = Thor::CoreExt::HashWithIndifferentAccess.new({'list' => true})
335
-
336
- 3.downto(1) do
337
- # get list data from one of the methods
338
- if respond_to?(:validation_list)
339
- response = validation_list(context_params)
340
- else
341
- clazz, endpoint, opts = whoami()
342
- response = get_cached_response(clazz, endpoint, opts)
343
- end
344
-
345
- unless (response.nil? || response.empty?)
346
- unless response['data'].nil?
347
- identifiers = []
348
- response['data'].each do |element|
349
- # special flag to filter out data not needed here
350
- next if element['dtk_context_hidden']
351
-
352
- identifiers << { :name => element['display_name'], :identifier => element['id'], :shadow_entity => element['dtk_client_type'] }
353
- end
354
- return identifiers
355
- end
356
- end
357
- unless response.nil?
358
- break if response["status"].eql?('ok')
359
- end
360
- sleep(1)
361
- end
362
-
363
- DtkLogger.instance.warn("[WARNING] We were not able to check cached context, possible errors may occur.")
364
- return []
365
- end
366
-
367
- no_tasks do
368
-
369
- include CommonOptionDefs::Mixin
370
-
371
- #
372
- # Run shell command directly from main, use with CAUTION
373
- #
374
-
375
- def run_shell_command(line)
376
- TOPLEVEL_BINDING.eval('self').execute_shell_command_internal(line)
377
- end
378
-
379
- ##
380
- # Block that allows users to specify part of the code which is expected to run for longer duration
381
- #
382
- def extended_timeout
383
- puts "Please wait, this could take a few minutes ..."
384
- old_timeout = ::DTK::Client::Conn.get_timeout()
385
- ::DTK::Client::Conn.set_timeout(EXTENDED_TIMEOUT)
386
- result = yield
387
- ::DTK::Client::Conn.set_timeout(old_timeout)
388
- result
389
- end
390
-
391
- # Method not implemented error
392
- def not_implemented
393
- raise DTK::Client::DtkError, "Method NOT IMPLEMENTED!"
394
- end
395
-
396
- def raise_validation_error_method_usage(method_name)
397
- usage_text = self.class.all_tasks[method_name][:usage]
398
- raise DTK::Client::DtkValidationError, "Invalid method usage, use: #{usage_text}"
399
- end
400
-
401
- # returns method name and usage
402
- def current_method_info
403
- unless @_initializer[2][:current_task]
404
- raise DTK::Client::DtkError, "You are using development mode, and you have newer version of Thor gem than specified by dtk-client"
405
- end
406
-
407
- return @_initializer[2][:current_task].name, @_initializer[2][:current_task].usage
408
- end
409
-
410
- # returns names of the arguments, after the method name
411
- def method_argument_names
412
- name, usage = current_method_info
413
- results = usage.split(name.gsub(/_/,'-')).last || ""
414
- return results.split(' ')
415
- end
416
-
417
- #TODO: can make more efficient by having rest call that returns name from id, rather than using 'list path'
418
- #entity_id can be a name as well as an id
419
- def get_name_from_id_helper(entity_id, entity_type=nil,list_command_path=nil, subtype=nil)
420
- return entity_id unless is_numeric_id?(entity_id)
421
-
422
- entity_id = entity_id.to_i
423
- if entity_type.nil?
424
- entity_type,list_command_path,subtype = self.class.whoami()
425
- end
426
-
427
- match = nil
428
- response = self.class.get_cached_response(entity_type,list_command_path,subtype)
429
- if response and response.ok? and response['data']
430
- match = response['data'].find{|entity|entity_id == entity['id']}
431
- end
432
- unless match
433
- raise DTK::Client::DtkError, "Not able to resolve entity name, please provide #{entity_type} name."
434
- end
435
- match['display_name']
436
- end
437
-
438
- def is_numeric_id?(possible_id)
439
- !possible_id.to_s.match(/^[0-9]+$/).nil?
440
- end
441
-
442
- # helper for error messages; prints singular or plural version
443
- # tem will be of form singural/plural or simple term in which case plural formed by adding 's'
444
- def plural?(is_plural,term)
445
- singular_plural = term.split('/')
446
- if singular_plural.size == 1
447
- singular_plural << "#{singular_plural[0]}s"
448
- end
449
- singular_plural[is_plural ? 1 : 0]
450
- end
451
-
452
- # removes nil values
453
- def post_body(hash)
454
- hash.inject(Hash.new){|h,(k,v)|v.nil? ? h : h.merge(k => v)}
455
- end
456
-
457
- # User input prompt
458
- def user_input(message)
459
- trap("INT", "SIG_IGN")
460
- while line = Readline.readline("#{message}: ",true)
461
- unless line.chomp.empty?
462
- trap("INT", false)
463
- return line
464
- end
465
- end
466
- end
467
-
468
- def get_type_and_raise_error_if_invalid(about, default_about, type_options)
469
- about ||= default_about
470
- raise DTK::Client::DtkError, "Not supported type '#{about}' for list for current context level. Possible type options: #{type_options.join(', ')}" unless type_options.include?(about)
471
- return about, about[0..-2].to_sym
472
- end
473
-
474
- # check for delimiter, if present returns namespace and name for module/service
475
- # returns: namespace, name
476
- def get_namespace_and_name(input_remote_name, delimiter)
477
- if (input_remote_name||'').include?(delimiter)
478
- input_remote_name.split(delimiter)
479
- # support ns/name as well as ns:name
480
- elsif (input_remote_name||'').include?('/')
481
- input_remote_name.split('/')
482
- else
483
- [nil, input_remote_name]
484
- end
485
- end
486
-
487
- def get_namespace_and_name_for_component(component_full_name)
488
- namespace, name = nil, ''
489
-
490
- if (component_full_name||'').include?(':')
491
- match = component_full_name.match(/(^[^:]+):{1}(.*$)/)
492
- namespace, name = [$1,$2]
493
-
494
- return [nil, component_full_name] if (name.include?(':') && !name.include?('::'))
495
-
496
- # to be robust to user putting in ns::x::y which splits to ns=ns name=:x::y
497
- name.gsub!(/^:/,'')
498
-
499
- component_full_name = name
500
- end
501
-
502
- [namespace, component_full_name]
503
- end
504
- end
505
-
506
-
507
- ##
508
- # This is fix where we wanna exclude basename print when using dtk-shell.
509
- # Thor has banner method, representing row when help is invoked. As such banner
510
- # will print out basename first. e.g.
511
- #
512
- # dtk-shell assembly list [library|target] # List asssemblies in library or target
513
- #
514
- # Basename is derived from name of file, as such can be overriden to serve some other
515
- # logic.
516
- #
517
- def self.basename
518
- basename = super
519
- basename = '' if basename == 'dtk-shell'
520
- return basename
521
- end
522
-
523
- #
524
- # Returns list of invisible contexts with sufix provided (if any)
525
- #
526
-
527
- def self.invisible_context_list(sufix = 'identifier')
528
- self.respond_to?(:invisible_context) ? self.invisible_context.collect { |i| "#{i}-#{sufix}" } : []
529
- end
530
-
531
- desc "help [SUBCOMMAND]", "Describes available subcommands or one specific subcommand"
532
- def help(*args)
533
- puts # pretty print
534
- not_dtk_clazz = true
535
-
536
- if defined?(DTK::Client::Dtk)
537
- not_dtk_clazz = !self.class.eql?(DTK::Client::Dtk)
538
- end
539
-
540
- # not_dtk_clazz - we don't use subcommand print in case of root DTK class
541
- # for other classes Assembly, Node, etc. we print subcommand
542
- # this gives us console output: dtk assembly converge ASSEMBLY-ID
543
- #
544
- # @@shell_execution - if we run from shell we don't want subcommand output
545
- #
546
-
547
- super(args.empty? ? nil : args.first, not_dtk_clazz && !@@shell_execution)
548
-
549
- # we will print error in case configuration has reported error
550
- @conn.print_warning if @conn.connection_error?
551
- puts # pretty print
552
- end
553
- end
554
- end
555
- end
data/lib/require_first.rb DELETED
@@ -1,104 +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
- require File.expand_path('../lib/error', File.dirname(__FILE__))
19
-
20
- # we leave possibilites that folders user multiple names
21
- # when somebody takes fresh projects from git it is expected that
22
- # person will use dtk-common name
23
- POSSIBLE_COMMON_CORE_FOLDERS = ['dtk-common-repo','dtk-common-core']
24
-
25
-
26
- def dtk_require(*files_x)
27
- files = (files_x.first.kind_of?(Array) ? files_x.first : files_x)
28
- caller_dir = caller.first.gsub(/\/[^\/]+$/,"")
29
- files.each{|f|require File.expand_path(f,caller_dir)}
30
- end
31
-
32
- def dtk_require_from_base(*files_x)
33
- #different than just calling dtk_require because of change to context give by caller
34
- dtk_require(*files_x)
35
- end
36
-
37
- def dtk_require_common_commands(*files_x)
38
- dtk_require_from_base(*files_x.map{|f|"commands/common/#{f}"})
39
- end
40
-
41
- def dtk_nested_require(dir,*files_x)
42
- files = (files_x.first.kind_of?(Array) ? files_x.first : files_x)
43
- caller_dir = caller.first.gsub(/\/[^\/]+$/,"")
44
-
45
- # invalid command will be send here as such needs to be handled.
46
- # we will throw DtkClient error as invalid command
47
- files.each do |f|
48
- begin
49
- require File.expand_path("#{dir}/#{f}",caller_dir)
50
- rescue LoadError => e
51
- if e.message.include? "#{dir}/#{f}"
52
- raise DTK::Client::DtkError,"Command '#{f}' not found."
53
- else
54
- raise e
55
- end
56
- end
57
- end
58
- end
59
-
60
- # this returns true if there is no common folder e.g. dtk-common in parent folder,
61
- # and gem is installed
62
- def gem_only_available?()
63
- return !determine_common_folder() && is_dtk_common_core_gem_installed?
64
- end
65
-
66
- def dtk_require_dtk_common_core(common_library)
67
- # use common folder else common gem
68
- common_folder = determine_common_folder()
69
-
70
- if common_folder
71
- dtk_require("../../" + common_folder + "/lib/#{common_library}")
72
- elsif is_dtk_common_core_gem_installed?
73
- # already loaded so do not do anything
74
- else
75
- raise DTK::Client::DtkError,"Common directory/gem not found, please make sure that you have cloned dtk-common folder or installed dtk common gem!"
76
- end
77
- end
78
-
79
- private
80
-
81
- ##
82
- # Check if dtk-common gem has been installed if so use common gem. If there is no gem
83
- # logic from dtk_require_dtk_common will try to find commond folder.
84
- # DEVELOPER NOTE: Uninstall dtk-common gem when changing dtk-common to avoid re-building gem.
85
- def is_dtk_common_core_gem_installed?
86
- begin
87
- # if no exception gem is found
88
- gem 'dtk-common-core'
89
- return true
90
- rescue Gem::LoadError
91
- return false
92
- end
93
- end
94
-
95
- ##
96
- # Checks for expected names of dtk-common folder and returns name of existing common folder
97
- def determine_common_folder
98
- POSSIBLE_COMMON_CORE_FOLDERS.each do |folder|
99
- path = File.join(File.dirname(__FILE__),'..','..',folder)
100
- return folder if File.directory?(path)
101
- end
102
-
103
- return nil
104
- end