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,44 +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: test for assembly list/display; want to make assembly specfic stuff datadriven
19
- dtk_require 'simple_list'
20
- module DTK
21
- module Client
22
- class ViewProcAugmentedSimpleList < ViewProcSimpleList
23
- private
24
- def initialize(type,command_class,data_type_index=nil)
25
- super
26
- @meta = get_meta(type,command_class)
27
- end
28
- def failback_meta(ordered_cols)
29
- nil
30
- end
31
- def simple_value_render(ordered_hash,ident_info)
32
- augmented_def?(ordered_hash,ident_info) || super
33
- end
34
- def augmented_def?(ordered_hash,ident_info)
35
- return nil unless @meta
36
- if aug_def = @meta["#{ordered_hash.object_type}_def".to_sym]
37
- ident_str = ident_str(ident_info[:ident]||0)
38
- vals = aug_def[:keys].map{|k|ordered_hash[k.to_s]}
39
- "#{ident_str}#{aug_def[:fn].call(*vals)}\n"
40
- end
41
- end
42
- end
43
- end
44
- end
@@ -1,123 +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 ViewProcHashPrettyPrint < ViewProcessor
21
- include ::DTK::Client::Auxiliary
22
- def render(hash)
23
- object_def = get_top_def()
24
- raise_error() unless object_def
25
- render_object_def(hash,object_def)
26
- end
27
- private
28
- attr_reader :meta
29
- def initialize(type,command_class,data_type_index=nil)
30
- super
31
- @meta = get_meta(type,command_class,data_type_index)
32
- end
33
-
34
- def failback_meta(ordered_cols)
35
- {
36
- :top_type => :top,
37
- :defs => {:top_def => ordered_cols}
38
- }
39
- end
40
-
41
- def get_top_def()
42
- raise_error("No Top def") unless top_object_type = meta[:top_type]
43
- get_object_def(top_object_type)
44
- end
45
-
46
- def get_object_def(object_type)
47
- if defs = meta[:defs] and object_type
48
- {object_type => defs["#{object_type}_def".to_sym]}
49
- end
50
- end
51
- def raise_error(msg=nil)
52
- msg ||= "No hash pretty print view defined"
53
- raise Error.new(msg)
54
- end
55
- def render_object_def(object,object_def,opts={})
56
- #TODO: stub making it only first level
57
- return object unless object.kind_of?(Hash)
58
- hash = object
59
- ret = ViewPrettyPrintHash.new(object_def.keys.first)
60
-
61
- object_def.values.first.each do |item|
62
- if item.kind_of?(Hash)
63
- render_object_def__hash_def!(ret,hash,item)
64
- else
65
- key = item.to_s
66
- target_key = replace_with_key_alias?(key)
67
- #TODO: may want to conditionally include nil values
68
- ret[target_key] = hash[key] if hash[key]
69
- end
70
- end
71
- #catch all for keys not defined
72
- unless opts[:only_explicit_cols]
73
- (hash.keys.map{|k|replace_with_key_alias?(k)} - ret.keys).each do |key|
74
- ret[key] = hash[key] if hash[key]
75
- end
76
- end
77
- return ret
78
- end
79
- def replace_with_key_alias?(key)
80
- #TODO: fix
81
- return key
82
- if ret = GlobalKeyAliases[key.to_sym] then ret.to_s
83
- else key
84
- end
85
- end
86
- GlobalKeyAliases = {
87
- :library_library_id => :library_id,
88
- :datacenter_datacenter_id => :target_id
89
- }
90
-
91
- def render_object_def__hash_def!(ret,hash,hash_def_item)
92
- key = hash_def_item.keys.first.to_s
93
- return unless input = hash[key]
94
- hash_def_info = hash_def_item.values.first
95
- nested_object_def = get_object_def(hash_def_info[:type])
96
- raise_error("object def of type (#{hash_def_info[:type]||""}) does not exist") unless nested_object_def
97
-
98
- opts = Hash.new
99
- if hash_def_info[:only_explicit_cols]
100
- opts.merge!(:only_explicit_cols => true)
101
- end
102
- if hash_def_info[:is_array]
103
- raise_error("hash subpart should be an array") unless input.kind_of?(Array)
104
- ret[key] = input.map{|el|render_object_def(el,nested_object_def,opts)}
105
- else
106
- ret[key] = render_object_def(input,nested_object_def,opts)
107
- end
108
- end
109
- end
110
- class ViewPrettyPrintHash < Common::PrettyPrintHash
111
- def initialize(object_type=nil)
112
- super()
113
- @object_type = object_type
114
- end
115
- attr_accessor :object_type
116
- def slice(*keys)
117
- ret = super
118
- ret.object_type = object_type
119
- ret
120
- end
121
- end
122
- end
123
- end
@@ -1,156 +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 'erubis'
19
- module DTK
20
- module Client
21
- class ViewProcSimpleList < ViewProcessor
22
- def render(hash)
23
- pp_adapter = ViewProcessor.get_adapter("hash_pretty_print",@command_class,@data_type_index)
24
- ordered_hash = pp_adapter.render(hash)
25
- if ordered_hash.size == 1
26
- render_simple_assignment(ordered_hash.keys.first,ordered_hash.values.first)
27
- else
28
- render_ordered_hash(ordered_hash)
29
- end
30
- end
31
- private
32
- #TODO Aldin check if assembly or assembly_name
33
- HIDE_FROM_VIEW = ["assembly"]
34
- def render_simple_assignment(key,val)
35
- key + KeyValSeperator + val.to_s + "\n"
36
- end
37
- def render_ordered_hash(ordered_hash,ident_info={},index=1)
38
- #find next value that is type pretty print hash or array
39
- beg,nested,rest = find_first_non_scalar(ordered_hash)
40
- ret = String.new
41
- unless beg.empty?
42
- ret = simple_value_render(beg,ident_info.merge(:index => index))
43
- end
44
- unless nested.empty?
45
- ident_info_nested = {
46
- :ident => (ident_info[:ident]||0) +IdentAdd,
47
- :nested_key => nested.keys.first
48
- }
49
- ident_info_nested[:ident] += IdentAdd
50
- ret << "#{ident_str(ident_info_nested[:ident])}#{nested.keys.first.upcase}\n"
51
- vals = nested.values.first
52
- vals = [vals] unless vals.kind_of?(Array)
53
- vals.each_with_index{|val,i|ret << render_ordered_hash(val,ident_info_nested,i+1)}
54
- end
55
- unless rest.empty?
56
- rest = hide_from_view(rest)
57
- ret << render_ordered_hash(rest,ident_info.merge(:include_first_key => true))
58
- end
59
- ret
60
- end
61
-
62
- def hide_from_view(ordered_hash)
63
- ordered_hash.each do |k,v|
64
- ordered_hash.delete_if{|k,v| HIDE_FROM_VIEW.include?(k)}
65
- end
66
- return ordered_hash
67
- end
68
-
69
- # Exclude = ["op_status","assembly_template"]
70
- IdentAdd = 2
71
- def find_first_non_scalar(ordered_hash)
72
- found = nil
73
- keys = ordered_hash.keys
74
- keys.each_with_index do |k,i|
75
- val = ordered_hash[k]
76
- if val.kind_of?(ViewPrettyPrintHash) or
77
- (val.kind_of?(Array) and val.size > 0 and val.first.kind_of?(ViewPrettyPrintHash))
78
- found = i
79
- break
80
- end
81
- end
82
- if found.nil?
83
- empty_ordered_hash = ordered_hash.class.new
84
- [ordered_hash,empty_ordered_hash,empty_ordered_hash]
85
- else
86
- [keys[0,found],keys[found,1],keys[found+1,keys.size-1]].map{|key_array|ordered_hash.slice(*key_array)}
87
- end
88
- end
89
- def is_scalar_type?(x)
90
- [String,Fixnum,Bignum].find{|t|x.kind_of?(t)}
91
- end
92
-
93
- def convert_to_string_form(val)
94
- if val.kind_of?(Array)
95
- "[#{val.map{|el|convert_to_string_form(el)}.join(",")}]"
96
- elsif is_scalar_type?(val)
97
- val.to_s
98
- else #catchall
99
- pp_form val
100
- end
101
- end
102
- def pp_form(obj)
103
- ret = String.new
104
- PP.pp obj, ret
105
- ret.chomp!
106
- end
107
-
108
- def ident_str(n)
109
- Array.new(n, " ").join
110
- end
111
-
112
- #process elements that are not scalars
113
- def proc_ordered_hash(ordered_hash)
114
- updated_els = Hash.new
115
- ordered_hash.each do |k,v|
116
- unless is_scalar_type?(v)
117
- updated_els[k] = convert_to_string_form(v)
118
- end
119
- end
120
-
121
- ordered_hash.merge(updated_els)
122
- end
123
-
124
- def simple_value_render(ordered_hash,ident_info)
125
-
126
- proc_ordered_hash = proc_ordered_hash(ordered_hash)
127
-
128
- ident = ident_info[:ident]||0
129
- first_prefix = (ident_info[:include_first_key] ?
130
- (ident_str(ident+IdentAdd) + ordered_hash.keys.first + KeyValSeperator) : ident_str(ident))
131
- first_suffix = ((ident_info[:include_first_key] or not ordered_hash.object_type) ? "" : " (#{ordered_hash.object_type})")
132
- rest_prefix = ident_str(ident+IdentAdd)
133
-
134
- template_bindings = {
135
- :ordered_hash => proc_ordered_hash,
136
- :first_prefix => first_prefix,
137
- :first_suffix => first_suffix,
138
- :rest_prefix => rest_prefix,
139
- :sep => KeyValSeperator
140
- }
141
-
142
- SimpleListTemplate.result(template_bindings)
143
- end
144
- KeyValSeperator = ": "
145
- SimpleListTemplate = Erubis::Eruby.new <<eos
146
- <% keys = ordered_hash.keys %>
147
- <% first = keys.shift %>
148
- <%= rest_prefix %><%= first_prefix.strip %><%= ordered_hash[first] %>
149
- <% keys.each do |k| %>
150
- <%= rest_prefix %><%= k %><%= sep %><%= ordered_hash[k] %>
151
- <% end %>
152
- eos
153
-
154
- end
155
- end
156
- end
@@ -1,309 +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 'hirb'
19
- require 'ostruct'
20
- require 'colorize'
21
- require 'rest_client'
22
- require 'json'
23
-
24
- dtk_require("../config/disk_cacher")
25
-
26
- # we override String here to give power to our mutators defined in TableDefintions
27
- class String
28
- def get_date
29
- DateTime.parse(self).strftime('%H:%M:%S %d/%m/%y') unless self.nil?
30
- end
31
- end
32
-
33
- # override OpenStruct to remove defintion for id
34
- class DtkOpenStruct < OpenStruct
35
- if RUBY_VERSION.match(/^1\.8\..*$/)
36
- undef id
37
- undef type
38
- end
39
- end
40
-
41
- # [Haris]
42
- # Elements with action column (taks status) have been removed since they are no longer in use. In case of bug that is relying
43
- # on existance of element and logic, please contact me to resolve it.
44
- #
45
-
46
- module DTK
47
- module Client
48
- class ViewProcTablePrint < ViewProcessor
49
- def render(data, command_clazz, data_type_clazz, forced_metadata=nil, print_error_table=false)
50
- DtkResponse.new(data, data_type_clazz, forced_metadata, print_error_table).print
51
- end
52
- end
53
-
54
- class DtkResponse
55
-
56
- include Hirb::Console
57
- include CommandBase
58
- extend CommandBase
59
- attr_accessor :command_name, :order_defintion, :evaluated_data
60
-
61
- # when adding class to table view you need to define mapping and order to be displayed in table
62
- # this can be fixed with facets, but that is todo for now TODO: use facets with ordered hashes
63
-
64
- def initialize(data, data_type, forced_metadata, print_error_table)
65
- # if there is no custom metadata, then we use metadata predefined in meta-response.json file
66
-
67
- if forced_metadata.nil?
68
- # get all table definitions from json file
69
- @table_defintions = get_metadata()
70
- # e.g. data type ASSEMBLY
71
- @command_name = data_type
72
- # e.g. ASSEMBLY => TableDefintions::ASSEMBLY
73
- table_defintion = get_table_defintion(@command_name)
74
- # e.g. ASSEMBLY => TableDefintions::ASSEMBLY_ORDER
75
- @order_definition = get_table_defintion(@command_name, true)
76
- else
77
- # if there is custom metadata, check if it is in valid format
78
- validate_forced_metadata(forced_metadata)
79
-
80
- table_defintion = forced_metadata['mapping']
81
- @order_definition = forced_metadata['order']
82
- end
83
-
84
- # if one defintion is missing we stop the execution
85
- if table_defintion.nil? || @order_definition.nil?
86
- raise DTK::Client::DtkError,"Missing table definition(s) for data type #{data_type}."
87
- end
88
-
89
- # transforms data to DtkOpenStruct
90
- structured_data = []
91
-
92
- # very important since rest of the code expect array to be used
93
- data = [data] unless data.kind_of?(Array)
94
-
95
- data.each do |data_element|
96
- # special flag to filter out data not needed here
97
- next if data_element['dtk_client_hidden']
98
-
99
- structured_data << to_ostruct(data_element)
100
- end
101
-
102
- # we use array of OpenStruct to hold our evaluated values
103
- @evaluated_data = []
104
- @error_data = []
105
- @action_data = []
106
- structured_data.each do |structured_element|
107
- evaluated_element = DtkOpenStruct.new
108
- error_element = DtkOpenStruct.new
109
-
110
- # based on mapping we set key = eval(value)
111
- table_defintion.each do |k,v|
112
- begin
113
- # due to problems with space we have special way of handling error columns
114
- # in such a way that those error will be specially printed later on
115
-
116
- if print_error_table && k.include?('error')
117
- error_message = value_of(structured_element, v)
118
- server_error = nil
119
-
120
- # here we see if there was an error if not we will skip this
121
- # if so we add it to @error_data
122
-
123
- if error_message.empty?
124
- # no error message just add it as regular element
125
- evaluated_element.send("#{k}=",value_of(structured_element, v))
126
- else
127
- error_index = ""
128
- error_type = value_of(structured_element,'errors.dtk_type') || ""
129
-
130
- val = value_of(structured_element,'dtk_type')||''
131
- # extract e.g. 3.1.1.1 from '3.1.1.1 action' etc.
132
- error_index = "[ #{val.scan( /\d+[,.]?\d?[,.]?\d?[,.]?\d?[,.]?\d?/ ).first} ]"
133
-
134
- # original table takes that index
135
- evaluated_element.send("#{k}=", error_index)
136
- # we set new error element
137
- error_element.id = error_index
138
-
139
- if error_type == "user_error"
140
- error_element.message = "[USER ERROR] " + error_message
141
- elsif error_type == "test_error"
142
- error_element.message = "[TEST ERROR] " + error_message
143
- else
144
- error_element.message = "[SERVER ERROR] " + error_message
145
- end
146
-
147
- # add it with other
148
- @error_data << error_element
149
- end
150
- else
151
- evaluated_element.send("#{k}=", value_of(structured_element, v))
152
- # eval "evaluated_element.#{k}=structured_element.#{v}"
153
- end
154
- rescue NoMethodError => e
155
- unless e.message.include? "nil:NilClass"
156
- # when chaining comands there are situations where more complex strcture
157
- # e.g. external_ref.region will not be there. So we are handling that case
158
- # make sure when in development to disable this TODO: better solution needed
159
- raise DTK::Client::DtkError,"Error with missing metadata occurred. There is a mistake in table metadata or unexpected data presented to table view."
160
- end
161
- end
162
- end
163
-
164
- @order_definition.delete('errors')
165
-
166
- @evaluated_data << evaluated_element
167
- end
168
- end
169
-
170
- def get_metadata
171
- content = DiskCacher.new.fetch("table_metadata", ::DTK::Configuration.get(:meta_table_ttl))
172
- raise DTK::Client::DtkError, "Table metadata is empty, please contact DTK team." if content.empty?
173
- return JSON.parse(content)
174
- end
175
-
176
- def to_ostruct(data)
177
- result = data.inject({}) do |res, (k, v)|
178
- k = safe_name(k)
179
- case v
180
- when Hash
181
- res.store(k, to_ostruct(v))
182
- res
183
- when Array
184
- res.store(k, v.each { |el| Hash === el ? to_ostruct(el) : el })
185
- res
186
- else
187
- res.store(k,v)
188
- res
189
- end
190
- end
191
-
192
- DtkOpenStruct.new(result)
193
- end
194
-
195
- def safe_name(identifier)
196
- (identifier == 'id' || identifier == 'type') ? "dtk_#{identifier}" : identifier
197
- end
198
-
199
- def get_table_defintion(name,is_order=false)
200
- begin
201
- @table_defintions[name.downcase][(is_order ? 'order' : 'mapping')]
202
- rescue NameError => e
203
- return nil
204
- end
205
- end
206
-
207
- # Check if custom metadata is sent in valid format
208
- def validate_forced_metadata(forced_metadata)
209
- # if custom metadata does not contain order(Array) or mapping(Hash),then it's not valid metadata
210
- unless (forced_metadata['order'].nil? || forced_metadata['mapping'].nil?)
211
- return if (forced_metadata['order'].class.eql?(Array) && forced_metadata['mapping'].class.eql?(Hash))
212
- end
213
-
214
- raise DTK::Client::DtkError,"Provided table definition is not valid. Please review your order and mapping for provided definition: \n #{forced_metadata.inspect}"
215
- end
216
-
217
- def filter_remove_underscore(field)
218
-
219
- end
220
-
221
- def print
222
- filter_remove_underscore = Proc.new { |header| header.gsub('_',' ').upcase }
223
- # hirb print out of our evaluated data in order defined
224
- # Available options can be viewed here: http://tagaholic.me/hirb/doc/classes/Hirb/Helpers/Table.html#M000008
225
- table(@evaluated_data,{:fields => @order_definition,:escape_special_chars => true, :resize => false, :vertical => false, :header_filter => filter_remove_underscore })
226
-
227
- # in case there were error we print those errors
228
- unless @error_data.empty?
229
- printf "\nERRORS: \n\n"
230
- #table(@error_data,{:fields => [ :id, :message ]})
231
- @error_data.each do |error_row|
232
- printf "%15s %s\n", error_row.id.colorize(:yellow), error_row.message.colorize(:red)
233
- end
234
- end
235
-
236
- unless @action_data.empty?
237
- printf " \n"
238
- #table(@error_data,{:fields => [ :id, :message ]})
239
- printed = []
240
- @action_data.each do |action_row|
241
- # printf "%15s\n"
242
- # printf(" INFO: #{action_row.message.colorize(:yellow)} \n") #, action_row.id.colorize(:yellow), action_row.message.colorize(:yellow)
243
- message = action_row.message
244
- printf "%15s %s\n", "INFO:".colorize(:yellow), message.colorize(:yellow) unless printed.include?(message)
245
- printed << message
246
- end
247
- end
248
- end
249
-
250
- private
251
-
252
- # based on string sequence in mapped_command we are executing list of commands to follow
253
- # so for value of "foo.bar.split('.').last" we will get 4 commands that will
254
- # sequentaly be executed using values from previus results
255
- def value_of(open_struct_object, mapped_command)
256
- # split string by '.' delimiter keeping in mind to split when words only
257
- commands = mapped_command.split(/\.(?=\w)/)
258
-
259
- value = open_struct_object
260
- commands.each do |command|
261
- value = evaluate_command(value, command)
262
- end
263
- return value
264
- end
265
-
266
-
267
- def evaluate_command(value, command)
268
- case
269
- when command.include?('map{')
270
- matched_data = command.match(/\['(.+)'\]/)
271
-
272
- my_lambda = lambda{|_x| _x.map{|r|r["#{matched_data[1]}"]||[]}}
273
- value = my_lambda.call(value)
274
-
275
- raise DTK::Client::DtkError,"There is a mistake in table metadata: #{command.inspect}" if value.nil?
276
- when command.include?('(')
277
- # matches command and params e.g. split('.') => [1] split, [2] '.'
278
- matched_data = command.match(/(.+)\((.+)\)/)
279
- command, params = matched_data[1], matched_data[2]
280
- value = value.send(command,params)
281
- when command.include?('[')
282
- # matches command such as first['foo']
283
- matched_data = command.match(/(.+)\[(.+)\]/)
284
- command, params = matched_data[1],matched_data[2]
285
-
286
- value = evaluate_command(value,command)
287
- value = value.send('[]',params)
288
- when command.start_with?("list_")
289
- matched_data = command.match(/list_(.+)/)
290
-
291
- my_lambda = lambda{|_x| _x.map{|r|r["#{matched_data[1]}"]||[]}}
292
- value = my_lambda.call(value)
293
-
294
- raise DTK::Client::DtkError,"There is a mistake in table metadata: #{command.inspect}" if value.nil?
295
- when command.start_with?("count_")
296
- matched_data = command.match(/count_(.+)/)
297
-
298
- my_lambda = lambda{|_x| _x.map{|r|r["#{matched_data[1]}"]||[]}.flatten.size}
299
- value = my_lambda.call(value)
300
-
301
- raise DTK::Client::DtkError,"There is a mistake in table metadata: #{command.inspect}" if value.nil?
302
- else
303
- value = value.send(command)
304
- end
305
- return value
306
- end
307
- end
308
- end
309
- end