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,285 +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
- # This is wrapper for holding rest response information as well as
19
- # passing selection of ViewProcessor from Thor selection to render view
20
- # selection
21
- require 'git'
22
-
23
- module DTK
24
- module Client
25
- #TODO: should make higher level class be above whether it is 'rest'
26
- class Response < Common::Response
27
- require File.expand_path('response/error_handler',File.dirname(__FILE__))
28
- include ErrorHandlerMixin
29
-
30
- # :render_view => symbol specifing type of data to be rendered e.g. :assembly
31
- # :skip_render => flag that specifies that render is not needed (default: false)
32
- # :print_error_table => we use it if we want to print 'error legend' for given tables (default: false)
33
- attr_accessor :render_view, :skip_render, :print_error_table
34
-
35
- # Amar: had to add this in order to get json meta for PP that's not for domain class
36
- def override_command_class(json_top_type)
37
- @command_class = json_top_type
38
- end
39
-
40
- def initialize(command_class=nil,hash={})
41
- super(hash)
42
- @command_class = command_class
43
- @skip_render = false
44
- @print_error_table = false
45
- # default values
46
- @render_view = RenderView::AUG_SIMPLE_LIST
47
- @render_data_type = nil
48
- end
49
-
50
- def clone_me()
51
- return Marshal.load(Marshal.dump(self))
52
- end
53
-
54
- def self.wrap_helper_actions(data={},&block)
55
- begin
56
- results = (block ? yield : data)
57
- Ok.new(results)
58
-
59
- rescue Git::GitExecuteError => e
60
- if e.message.include?('Please make sure you have the correct access rights')
61
- error_msg = "You do not have git access from this client, please add following SSH key in your git account: \n\n"
62
- error_msg += SSHUtil.rsa_pub_key_content() + "\n"
63
- raise DTK::Client::DtkError, error_msg
64
- end
65
- handle_error_in_wrapper(e)
66
- rescue ErrorUsage => e
67
- Error::Usage.new("message"=> e.to_s)
68
- rescue => e
69
- handle_error_in_wrapper(e)
70
- end
71
- end
72
-
73
- def self.handle_error_in_wrapper(exception)
74
- error_hash = {
75
- "message"=> exception.message,
76
- "backtrace" => exception.backtrace,
77
- "on_client" => true
78
- }
79
-
80
- if DTK::Configuration.get(:development_mode)
81
- DtkLogger.instance.error_pp("Error inside wrapper DEV ONLY: #{exception.message}", exception.backtrace)
82
- end
83
-
84
- Error::Internal.new(error_hash)
85
- end
86
-
87
- def get_label_for_column_name(column, type)
88
- if type.eql?('node')
89
- mappings = {
90
- column => column
91
- }
92
- else
93
- mappings = {
94
- "#{type}_id:" => "ID:",
95
- "#{type}_name:" => "NAME:",
96
- "node_type:" => "TYPE:",
97
- "instance_id:" => "INSTANCE ID:",
98
- "size:" => "SIZE:",
99
- "os_type:" => "OS:",
100
- "op_status:" => "OP STATUS:",
101
- "dns_name:" => "DNS NAME:",
102
- "target:" => "TARGET:"
103
- }
104
- end
105
-
106
- mappings[column]
107
- end
108
-
109
- # used just for printing workspace node info
110
- def render_workspace_node_info(type)
111
- info_list = ""
112
- if type.eql?("component")
113
- info_list = ["component_name","component_id","basic_type","description"]
114
- else
115
- info_list = ["type", "node_id", "node_name","os_type", "instance_id", "admin_op_status", "size", "target", "dns_name", "image_id", "ec2_public_address", "privete_dns_name", "keypair", "security_groups", "security_group", "security_group_set"]
116
- end
117
-
118
- columns = []
119
- puts "--- \n"
120
- if data.kind_of?(String)
121
- data.each_line do |l|
122
- print = "#{l.gsub(/\s+\-*\s+/,'')}"
123
- print.gsub!(/-\s+/,"")
124
- info_list.each do |i|
125
- if match = print.to_s.match(/^(#{i}:)(.+)/)
126
- label = get_label_for_column_name(match[1], type)
127
- columns << " #{label}#{match[2]}\n"
128
- end
129
- end
130
- end
131
- end
132
-
133
- if type.eql?('node')
134
- # move target from first place
135
- columns.rotate!
136
- else
137
- columns.sort!()
138
- end
139
-
140
- columns.each do |column|
141
- STDOUT << column
142
- end
143
- puts "\n"
144
- end
145
-
146
- def render_custom_info(type)
147
- puts "--- \n"
148
-
149
- unless data.empty?
150
- data.each do |k,v|
151
- label = get_custom_labels(k, type)
152
- v = array_to_string(v) if v.is_a?(Array)
153
- STDOUT << " #{label} #{v}\n" if label
154
- end
155
- end
156
-
157
- puts "\n"
158
- end
159
-
160
- def get_custom_labels(label, type)
161
- mappings = {}
162
-
163
- mappings["module"] = {
164
- "id" => "ID:",
165
- "display_name" => "NAME:",
166
- "versions" => "VERSION(S):",
167
- "remote_repos" => "LINKED REMOTE(S):",
168
- "dsl_parsed" => "DSL PARSED:"
169
- }
170
-
171
- mappings[type][label] if mappings[type]
172
- end
173
-
174
- def array_to_string(array_data)
175
- info = ""
176
- array_data.each do |a|
177
- info << "#{a.values.first},"
178
- end
179
-
180
- "#{info.gsub!(/,$/,'')}"
181
- end
182
-
183
-
184
- def render_data(print_error_table=false)
185
- unless @skip_render
186
- if ok?()
187
-
188
- @print_error_table ||= print_error_table
189
-
190
- # if response is empty, response status is ok but no data is passed back
191
- if data.empty? or (data.is_a?(Array) ? data.first.nil? : data.nil?)
192
- @render_view = RenderView::SIMPLE_LIST
193
- if data.kind_of?(Array)
194
- set_data('Message' => "List is empty.")
195
- else #data.kind_of?(Hash)
196
- set_data('Status' => 'OK')
197
- end
198
- end
199
-
200
- # sending raw data from response
201
- rendered_data = ViewProcessor.render(@command_class, data, @render_view, @render_data_type, nil, @print_error_table)
202
-
203
- puts "\n" unless rendered_data
204
- return rendered_data
205
- else
206
- hash_part()
207
- end
208
- end
209
- end
210
-
211
- def render_arg_list!
212
- @render_view = RenderView::AUG_SIMPLE_LIST
213
- end
214
-
215
- def set_datatype(data_type)
216
- @render_data_type = symbol_to_data_type_upcase(data_type)
217
- self
218
- end
219
-
220
- def render_table(default_data_type=nil, use_default=false)
221
- unless ok?
222
- return self
223
- end
224
- unless data_type = (use_default ? default_data_type : (response_datatype() || default_data_type))
225
- raise DTK::Client::DtkError, "Server did not return datatype."
226
- end
227
-
228
- @render_data_type = symbol_to_data_type_upcase(data_type)
229
- @render_view = RenderView::TABLE
230
- self
231
- end
232
-
233
- def response_datatype()
234
- self["datatype"] && self["datatype"].to_sym
235
- end
236
-
237
- def hash_part()
238
- keys.inject(Hash.new){|h,k|h.merge(k => self[k])}
239
- end
240
-
241
- def symbol_to_data_type_upcase(data_type)
242
- return data_type.nil? ? nil : data_type.to_s.upcase
243
- end
244
-
245
- private :hash_part
246
-
247
- class Ok < self
248
- def initialize(data={})
249
- super(nil,{"data"=> data, "status" => "ok"})
250
- end
251
- end
252
-
253
- class NotOk < self
254
- def initialize(data={})
255
- super(nil,{"data"=> data, "status" => "notok"})
256
- end
257
- end
258
-
259
- class Error < self
260
- include Common::Response::ErrorMixin
261
- def initialize(hash={})
262
- super(nil,{"errors" => [hash]})
263
- end
264
-
265
- class Usage < self
266
- def initialize(hash_or_string={})
267
- hash = (hash_or_string.kind_of?(String) ? {'message' => hash_or_string} : hash_or_string)
268
- super({"code" => "error"}.merge(hash))
269
- end
270
- end
271
-
272
- class Internal < self
273
- def initialize(hash={})
274
- super({"code" => "error"}.merge(hash).merge("internal" => true))
275
- end
276
- end
277
- end
278
-
279
- class NoOp < self
280
- def render_data
281
- end
282
- end
283
- end
284
- end
285
- end
@@ -1,20 +0,0 @@
1
- #
2
- # Copyright (C) 2010-2016 dtk contributors
3
- #
4
- # This file is part of the dtk project.
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
- module DtkClient
19
- VERSION="0.9.1"
20
- end
data/lib/dtk_constants.rb DELETED
@@ -1,40 +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 'singleton'
19
- dtk_require("config/disk_cacher")
20
-
21
- class PPColumns
22
-
23
- include Singleton
24
-
25
- def initialize
26
- # content = DiskCacher.new.fetch("http://localhost/mockup/get_const_metadata", ::DTK::Configuration.get(:meta_constants_ttl))
27
- content = DiskCacher.new.fetch("const_metadata", ::DTK::Configuration.get(:meta_constants_ttl))
28
- raise DTK::Client::DtkError, "Require constants metadata is empty, please contact DTK team." if content.empty?
29
- @constants = JSON.parse(content)
30
- end
31
-
32
- def self.get(symbol_identifier)
33
- return PPColumns.instance.get(symbol_identifier)
34
- end
35
-
36
- def get(symbol_identifier)
37
- return @constants[symbol_identifier.to_s]
38
- end
39
-
40
- end
data/lib/dtk_error.rb DELETED
@@ -1,114 +0,0 @@
1
- #
2
- # Copyright (C) 2010-2016 dtk contributors
3
- #
4
- # This file is part of the dtk project.
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
- module DTK
19
- module Client
20
- class DtkError < Error
21
- def initialize(msg,opts={})
22
- super(msg)
23
- @backtrace = opts[:backtrace]
24
- end
25
- attr_reader :backtrace
26
-
27
- def self.raise_error(response)
28
- raise_if_error?(response,:default_error_if_nil => true)
29
- end
30
- def self.raise_if_error?(response,opts={})
31
- # check for errors in response
32
- unless error = response.error_info?(opts)
33
- return
34
- end
35
-
36
- # if error_internal.first == true
37
- case error.code
38
- when :unauthorized
39
- raise self, "[UNAUTHORIZED] Your session has been suspended, please log in again."
40
- when :session_timeout
41
- raise self, "[SESSION TIMEOUT] Your session has been suspended, please log in again."
42
- when :broken
43
- raise self, "[BROKEN] Unable to connect to the DTK server at host: #{Config[:server_host]}"
44
- when :forbidden
45
- raise DTK::Client::DtkLoginRequiredError, "[FORBIDDEN] Access not granted, please log in again."
46
- when :timeout
47
- raise self, "[TIMEOUT ERROR] Server is taking too long to respond."
48
- when :connection_refused
49
- raise self, "[CONNECTION REFUSED] Connection refused by server."
50
- when :resource_not_found
51
- raise self, "[RESOURCE NOT FOUND] #{error.msg}"
52
- when :pg_error
53
- raise self, "[PG_ERROR] #{error.msg}"
54
- when :server_error
55
- raise Server.new(error.msg,:backtrace => error.backtrace)
56
- when :client_error
57
- raise Client.new(error.msg,:backtrace => error.backtrace)
58
- else
59
- # if usage error occurred, display message to console and display that same message to log
60
- raise Usage.new(error.msg)
61
- end
62
- end
63
-
64
-
65
- class Usage < self
66
- def initialize(error_msg,opts={})
67
- msg_to_pass_to_super = "[ERROR] #{error_msg}"
68
- super(msg_to_pass_to_super,opts)
69
- end
70
- end
71
-
72
- class InternalError < self
73
- def initialize(error_msg,opts={})
74
- msg_to_pass_to_super = "[#{label(opts[:where])}] #{error_msg}"
75
- super(msg_to_pass_to_super,opts)
76
- end
77
- def self.label(where=nil)
78
- prefix = (where ? "#{where.to_s.upcase} " : '')
79
- "#{prefix}#{InternalErrorLabel}"
80
- end
81
- InternalErrorLabel = 'INTERNAL ERROR'
82
-
83
- private
84
- def label(where=nil)
85
- self.class.label(where)
86
- end
87
- end
88
-
89
- class Client < InternalError
90
- def initialize(error_msg,opts={})
91
- super(error_msg,opts.merge(:where => :client))
92
- end
93
- def self.label(*args)
94
- super(:client)
95
- end
96
- end
97
-
98
- class Server < InternalError
99
- def initialize(error_msg,opts={})
100
- super(error_msg,opts.merge(:where => :server))
101
- end
102
- def self.label(*args)
103
- super(:server)
104
- end
105
- end
106
-
107
- class InteractiveWizardError < self
108
- def initialize(error_msg, opts={})
109
- super(error_msg, opts)
110
- end
111
- end
112
- end
113
- end
114
- end
data/lib/dtk_logger.rb DELETED
@@ -1,113 +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
- ##
19
- # DtkLogger singleton to be used for logging.
20
- #
21
- require 'singleton'
22
- require 'logger'
23
- require 'colorize'
24
- require 'pp'
25
-
26
- require File.expand_path('./util/os_util', File.dirname(__FILE__))
27
-
28
- class DtkLogger
29
-
30
- #
31
- LOG_FILE_NAME = 'client.log'
32
- LOG_MB_SIZE = 2
33
- LOG_NUMBER_OF_OLD_FILES = 10
34
- DEVELOPMENT_MODE = DTK::Configuration.get(:development_mode)
35
-
36
- include Singleton
37
-
38
- def initialize
39
- log_location_dir = DTK::Client::OsUtil.get_log_location()
40
- begin
41
- if File.directory?(log_location_dir)
42
- file = File.open(file_path(), "a")
43
- file.sync = true
44
- @logger = Logger.new(file, LOG_NUMBER_OF_OLD_FILES, LOG_MB_SIZE * 1024000)
45
-
46
- @logger.formatter = proc do |severity, datetime, progname, msg|
47
- "[#{datetime}] #{severity} -- : #{msg}\n"
48
- end
49
- else
50
- no_log_dir(log_location_dir)
51
- end
52
- rescue Errno::EACCES
53
- no_log_permissions(log_location_dir)
54
- end
55
- end
56
-
57
- def file_path()
58
- "#{DTK::Client::OsUtil.get_log_location()}/#{LOG_FILE_NAME}"
59
- end
60
-
61
- def debug(log_text, sttdout_out=false)
62
- puts log_text if sttdout_out || DEVELOPMENT_MODE
63
- @logger.debug(log_text) if log_created?
64
- end
65
-
66
- def info(log_text, sttdout_out=false)
67
- puts log_text if sttdout_out || DEVELOPMENT_MODE
68
- @logger.info(log_text) if log_created?
69
- end
70
-
71
- def warn(log_text, sttdout_out=false)
72
- DTK::Client::OsUtil.print(log_text, :yellow) if sttdout_out || DEVELOPMENT_MODE
73
- @logger.warn(log_text) if log_created?
74
- end
75
-
76
- def error(log_text, sttdout_out=false)
77
- DTK::Client::OsUtil.print(log_text, :red) if sttdout_out || DEVELOPMENT_MODE
78
- @logger.error(log_text) if log_created?
79
- end
80
-
81
- def error_pp(message, backtrace, sttdout_out = true)
82
- error(message, sttdout_out)
83
- # we do not print this to STDOUT (will be overriden with DEVELOPMENT_MODE)s
84
- error("#{message}\n" + PP.pp(backtrace, ""), false) if backtrace
85
- end
86
-
87
- def fatal_pp(message, backtrace, sttdout_out = true)
88
- fatal(message, sttdout_out)
89
- # we do not print this to STDOUT (will be overriden with DEVELOPMENT_MODE)
90
- fatal("#{message}\n" + PP.pp(backtrace, ""), false) if backtrace
91
- end
92
-
93
-
94
- def fatal(log_text, sttdout_out=false)
95
- puts log_text if sttdout_out || DEVELOPMENT_MODE
96
- @logger.fatal(log_text) if log_created?
97
- end
98
-
99
- private
100
-
101
- def log_created?
102
- #no log found if @logger.nil?
103
- return !@logger.nil?
104
- end
105
-
106
- def no_log_dir(dir)
107
- puts "[WARNING] Log directory (#{dir}) does not exist; please add it manually or re-install DTK client."
108
- end
109
-
110
- def no_log_permissions(dir)
111
- puts "[WARNING] User (#{DTK::Common::Aux.running_process_user()}) does not have permissions to create a log file in log directory (#{dir})"
112
- end
113
- end
data/lib/error.rb DELETED
@@ -1,85 +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
- ##
19
- # Application expected errors will be handled trough DtkError. All else will be treaded
20
- # as Internal Server error. Logs will be added to ~/dtk.log for developers to investigate
21
- # issues more closely.
22
-
23
- module DTK
24
- module Client
25
- class Error < NameError
26
- end
27
-
28
- # DtkError is child of Error; so order matters
29
- require File.expand_path('dtk_error', File.dirname(__FILE__))
30
-
31
- class DSLParsing < Error
32
- def initialize(base_json_error,file_path=nil)
33
- super(err_msg(base_json_error,file_path))
34
- end
35
- private
36
- def err_msg(base_json_error,file_path=nil)
37
- "#{base_json_error}: #{file_path}"
38
- end
39
-
40
- class JSONParsing < self
41
- end
42
-
43
- class YAMLParsing < self
44
- end
45
- end
46
-
47
- # class DtkValidationError < Error
48
-
49
- # attr_accessor :skip_usage_info
50
-
51
- # def initialize(msg, skip_usage_info = false)
52
- # @skip_usage_info = skip_usage_info
53
- # super(msg)
54
- # end
55
- # end
56
-
57
- class DtkValidationError < Error
58
-
59
- attr_accessor :display_usage_info
60
-
61
- def initialize(msg, display_usage_info = false)
62
- @display_usage_info = display_usage_info
63
- super(msg)
64
- end
65
- end
66
-
67
- # raise by developers to signal wrong usage of components
68
- class DtkImplementationError < Error
69
- end
70
-
71
- class DtkLoginRequiredError < Error
72
- end
73
-
74
- end
75
- end
76
-
77
- module DTK
78
- module Shell
79
- class Error < DTK::Client::Error
80
- end
81
-
82
- class ExitSignal < DTK::Client::Error
83
- end
84
- end
85
- end