dtk-shell 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (191) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +5 -0
  3. data/Gemfile_dev +13 -0
  4. data/README.md +121 -0
  5. data/bin/dtk-execute +32 -0
  6. data/bin/dtk-run +92 -0
  7. data/bin/dtk-shell +31 -0
  8. data/dtk-shell.gemspec +50 -0
  9. data/lib/auxiliary.rb +61 -0
  10. data/lib/bundler_monkey_patch.rb +26 -0
  11. data/lib/client.rb +58 -0
  12. data/lib/command_helper.rb +33 -0
  13. data/lib/command_helpers/git_repo.rb +589 -0
  14. data/lib/command_helpers/git_repo/merge.rb +153 -0
  15. data/lib/command_helpers/jenkins_client.rb +106 -0
  16. data/lib/command_helpers/jenkins_client/config_xml.rb +288 -0
  17. data/lib/command_helpers/service_importer.rb +251 -0
  18. data/lib/command_helpers/service_link.rb +33 -0
  19. data/lib/command_helpers/test_module_creator.rb +69 -0
  20. data/lib/command_helpers/test_module_templates/dtk.model.yaml.eruby +10 -0
  21. data/lib/command_helpers/test_module_templates/spec_helper.rb.eruby +10 -0
  22. data/lib/command_helpers/test_module_templates/temp_component_spec.rb.eruby +5 -0
  23. data/lib/commands.rb +57 -0
  24. data/lib/commands/common/thor/access_control.rb +133 -0
  25. data/lib/commands/common/thor/action_result_handler.rb +74 -0
  26. data/lib/commands/common/thor/assembly_template.rb +92 -0
  27. data/lib/commands/common/thor/assembly_workspace.rb +1801 -0
  28. data/lib/commands/common/thor/base_command_helper.rb +59 -0
  29. data/lib/commands/common/thor/clone.rb +82 -0
  30. data/lib/commands/common/thor/common.rb +88 -0
  31. data/lib/commands/common/thor/common_base.rb +49 -0
  32. data/lib/commands/common/thor/create_target.rb +70 -0
  33. data/lib/commands/common/thor/edit.rb +255 -0
  34. data/lib/commands/common/thor/inventory_parser.rb +98 -0
  35. data/lib/commands/common/thor/list_diffs.rb +128 -0
  36. data/lib/commands/common/thor/module.rb +1011 -0
  37. data/lib/commands/common/thor/module/import.rb +210 -0
  38. data/lib/commands/common/thor/node.rb +53 -0
  39. data/lib/commands/common/thor/poller.rb +65 -0
  40. data/lib/commands/common/thor/pull_clone_changes.rb +28 -0
  41. data/lib/commands/common/thor/pull_from_remote.rb +152 -0
  42. data/lib/commands/common/thor/puppet_forge.rb +72 -0
  43. data/lib/commands/common/thor/purge_clone.rb +101 -0
  44. data/lib/commands/common/thor/push_clone_changes.rb +162 -0
  45. data/lib/commands/common/thor/push_to_remote.rb +94 -0
  46. data/lib/commands/common/thor/remotes.rb +71 -0
  47. data/lib/commands/common/thor/reparse.rb +40 -0
  48. data/lib/commands/common/thor/set_required_attributes.rb +46 -0
  49. data/lib/commands/thor/account.rb +239 -0
  50. data/lib/commands/thor/assembly.rb +356 -0
  51. data/lib/commands/thor/attribute.rb +79 -0
  52. data/lib/commands/thor/component.rb +70 -0
  53. data/lib/commands/thor/component_module.rb +501 -0
  54. data/lib/commands/thor/component_template.rb +174 -0
  55. data/lib/commands/thor/dependency.rb +34 -0
  56. data/lib/commands/thor/developer.rb +144 -0
  57. data/lib/commands/thor/dtk.rb +152 -0
  58. data/lib/commands/thor/library.rb +125 -0
  59. data/lib/commands/thor/node.rb +504 -0
  60. data/lib/commands/thor/node_template.rb +94 -0
  61. data/lib/commands/thor/project.rb +34 -0
  62. data/lib/commands/thor/provider.rb +233 -0
  63. data/lib/commands/thor/remotes.rb +49 -0
  64. data/lib/commands/thor/service.rb +941 -0
  65. data/lib/commands/thor/service_module.rb +914 -0
  66. data/lib/commands/thor/state_change.rb +25 -0
  67. data/lib/commands/thor/target.rb +250 -0
  68. data/lib/commands/thor/task.rb +116 -0
  69. data/lib/commands/thor/test_module.rb +310 -0
  70. data/lib/commands/thor/utils.rb +21 -0
  71. data/lib/commands/thor/workspace.rb +685 -0
  72. data/lib/config/cacert.pem +3785 -0
  73. data/lib/config/client.conf.header +20 -0
  74. data/lib/config/configuration.rb +99 -0
  75. data/lib/config/default.conf +16 -0
  76. data/lib/config/disk_cacher.rb +80 -0
  77. data/lib/configurator.rb +176 -0
  78. data/lib/context_router.rb +44 -0
  79. data/lib/core.rb +497 -0
  80. data/lib/domain/git_adapter.rb +412 -0
  81. data/lib/domain/git_error_handler.rb +64 -0
  82. data/lib/domain/response.rb +285 -0
  83. data/lib/domain/response/error_handler.rb +86 -0
  84. data/lib/dtk-shell/version.rb +20 -0
  85. data/lib/dtk_constants.rb +40 -0
  86. data/lib/dtk_error.rb +114 -0
  87. data/lib/dtk_logger.rb +126 -0
  88. data/lib/dtk_shell.rb +31 -0
  89. data/lib/error.rb +85 -0
  90. data/lib/execute.rb +29 -0
  91. data/lib/execute/cli_pure/cli_rerouter.rb +102 -0
  92. data/lib/execute/command.rb +40 -0
  93. data/lib/execute/command/api_call.rb +60 -0
  94. data/lib/execute/command/api_call/map.rb +60 -0
  95. data/lib/execute/command/api_call/service.rb +91 -0
  96. data/lib/execute/command/api_call/translation_term.rb +119 -0
  97. data/lib/execute/command/rest_call.rb +37 -0
  98. data/lib/execute/command_processor.rb +30 -0
  99. data/lib/execute/command_processor/rest_call.rb +59 -0
  100. data/lib/execute/error_usage.rb +21 -0
  101. data/lib/execute/execute_context.rb +86 -0
  102. data/lib/execute/execute_context/result_store.rb +37 -0
  103. data/lib/execute/script.rb +64 -0
  104. data/lib/execute/script/add_tenant.rb +121 -0
  105. data/lib/git-logs/git.log +0 -0
  106. data/lib/parser/adapters/option_parser.rb +70 -0
  107. data/lib/parser/adapters/thor.rb +555 -0
  108. data/lib/parser/adapters/thor/common_option_defs.rb +40 -0
  109. data/lib/require_first.rb +104 -0
  110. data/lib/search_hash.rb +44 -0
  111. data/lib/shell.rb +261 -0
  112. data/lib/shell/context.rb +1065 -0
  113. data/lib/shell/context_aux.rb +46 -0
  114. data/lib/shell/domain/active_context.rb +186 -0
  115. data/lib/shell/domain/context_entity.rb +89 -0
  116. data/lib/shell/domain/context_params.rb +223 -0
  117. data/lib/shell/domain/override_tasks.rb +88 -0
  118. data/lib/shell/domain/shadow_entity.rb +76 -0
  119. data/lib/shell/header_shell.rb +44 -0
  120. data/lib/shell/help_monkey_patch.rb +283 -0
  121. data/lib/shell/interactive_wizard.rb +225 -0
  122. data/lib/shell/message_queue.rb +63 -0
  123. data/lib/shell/parse_monkey_patch.rb +39 -0
  124. data/lib/shell/status_monitor.rb +124 -0
  125. data/lib/task_status.rb +83 -0
  126. data/lib/task_status/refresh_mode.rb +77 -0
  127. data/lib/task_status/snapshot_mode.rb +28 -0
  128. data/lib/task_status/stream_mode.rb +48 -0
  129. data/lib/task_status/stream_mode/element.rb +101 -0
  130. data/lib/task_status/stream_mode/element/format.rb +101 -0
  131. data/lib/task_status/stream_mode/element/hierarchical_task.rb +100 -0
  132. data/lib/task_status/stream_mode/element/hierarchical_task/result.rb +72 -0
  133. data/lib/task_status/stream_mode/element/hierarchical_task/result/action.rb +93 -0
  134. data/lib/task_status/stream_mode/element/hierarchical_task/result/components.rb +26 -0
  135. data/lib/task_status/stream_mode/element/hierarchical_task/result/node_level.rb +26 -0
  136. data/lib/task_status/stream_mode/element/hierarchical_task/steps.rb +34 -0
  137. data/lib/task_status/stream_mode/element/hierarchical_task/steps/action.rb +53 -0
  138. data/lib/task_status/stream_mode/element/hierarchical_task/steps/components.rb +53 -0
  139. data/lib/task_status/stream_mode/element/hierarchical_task/steps/node_level.rb +42 -0
  140. data/lib/task_status/stream_mode/element/no_results.rb +26 -0
  141. data/lib/task_status/stream_mode/element/render.rb +59 -0
  142. data/lib/task_status/stream_mode/element/stage.rb +84 -0
  143. data/lib/task_status/stream_mode/element/stage/render.rb +76 -0
  144. data/lib/task_status/stream_mode/element/task_end.rb +35 -0
  145. data/lib/task_status/stream_mode/element/task_start.rb +37 -0
  146. data/lib/util/common_util.rb +37 -0
  147. data/lib/util/console.rb +235 -0
  148. data/lib/util/dtk_puppet.rb +65 -0
  149. data/lib/util/module_util.rb +66 -0
  150. data/lib/util/os_util.rb +385 -0
  151. data/lib/util/permission_util.rb +31 -0
  152. data/lib/util/remote_dependency_util.rb +84 -0
  153. data/lib/util/ssh_util.rb +94 -0
  154. data/lib/view_processor.rb +129 -0
  155. data/lib/view_processor/augmented_simple_list.rb +44 -0
  156. data/lib/view_processor/hash_pretty_print.rb +123 -0
  157. data/lib/view_processor/simple_list.rb +156 -0
  158. data/lib/view_processor/table_print.rb +309 -0
  159. data/lib/violation.rb +86 -0
  160. data/lib/violation/attribute.rb +76 -0
  161. data/lib/violation/fix.rb +26 -0
  162. data/lib/violation/fix/result.rb +73 -0
  163. data/lib/violation/fix/result/error.rb +34 -0
  164. data/lib/violation/fix/set_attribute.rb +41 -0
  165. data/lib/violation/sub_classes.rb +60 -0
  166. data/puppet/manifests/init.pp +72 -0
  167. data/puppet/manifests/params.pp +16 -0
  168. data/puppet/r8meta.puppet.yml +35 -0
  169. data/puppet/templates/bash_profile.erb +2 -0
  170. data/puppet/templates/client.conf.erb +1 -0
  171. data/puppet/templates/dtkclient.erb +2 -0
  172. data/spec/component_module_spec.rb +34 -0
  173. data/spec/dependency_spec.rb +6 -0
  174. data/spec/dtk_shell_spec.rb +13 -0
  175. data/spec/dtk_spec.rb +33 -0
  176. data/spec/lib/spec_helper.rb +10 -0
  177. data/spec/lib/spec_thor.rb +108 -0
  178. data/spec/node_template_spec.rb +24 -0
  179. data/spec/project_spec.rb +6 -0
  180. data/spec/repo_spec.rb +7 -0
  181. data/spec/response_spec.rb +52 -0
  182. data/spec/service_module_spec.rb +38 -0
  183. data/spec/service_spec.rb +50 -0
  184. data/spec/state_change_spec.rb +7 -0
  185. data/spec/table_print_spec.rb +48 -0
  186. data/spec/target_spec.rb +57 -0
  187. data/spec/task_spec.rb +28 -0
  188. data/views/assembly/augmented_simple_list.rb +12 -0
  189. data/views/assembly_template/augmented_simple_list.rb +12 -0
  190. data/views/list_task/augmented_simple_list.rb +12 -0
  191. metadata +421 -0
@@ -0,0 +1,285 @@
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
@@ -0,0 +1,86 @@
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; module Client
19
+ class Response
20
+ module ErrorHandlerMixin
21
+ # opts can be
22
+ # :default_error_if_nil - Boolean
23
+ def error_info?(opts={})
24
+ ErrorHandler.error_info?(self,opts)
25
+ end
26
+ end
27
+
28
+ module ErrorHandler
29
+ SpecificErrorCodes = [:unauthorized,:session_timeout,:broken,:forbidden,:timeout,:connection_refused,:resource_not_found,:pg_error]
30
+ DefaultErrorCode = :error
31
+ DefaultErrorMsg = 'Internal DTK Client error, please try again'
32
+
33
+ Info = Struct.new(:msg,:code,:backtrace)
34
+ def self.error_info?(response, opts={})
35
+ unless errors = response["errors"]
36
+ return (opts[:default_error_if_nil] && error_info_default())
37
+ end
38
+
39
+ # special rare case
40
+ errors = errors.first["errors"] if errors.is_a?(Array) && errors.first["errors"]
41
+
42
+ error_msg = ""
43
+ error_internal = nil
44
+ error_backtrace = nil
45
+ error_code = nil
46
+ error_on_server = nil
47
+
48
+ #TODO: below just 'captures' first error
49
+ errors.each do |err|
50
+ error_msg += err["message"] unless err["message"].nil?
51
+ error_msg += err["error"] unless err["error"].nil?
52
+ error_msg += OsUtil.remove_html_tags(err["original_exception"].to_s) unless err["original_exception"].nil?
53
+ error_on_server = true unless err["on_client"]
54
+ error_code = err["code"]||(err["errors"] && err["errors"].first["code"])
55
+ error_internal ||= (err["internal"] or error_code == "not_found") #"not_found" code is at Ramaze level; so error_internal not set
56
+ error_backtrace ||= err["backtrace"]
57
+ end
58
+
59
+ # in case we could not parse error lets log error info
60
+ if error_msg.empty?
61
+ DtkLogger.instance.error("Error info could not be extracted from following response: " + response.to_s)
62
+ end
63
+
64
+ # normalize it for display
65
+ error_msg = error_msg.empty? ? DefaultErrorMsg : "#{error_msg}"
66
+
67
+ unless error_code and SpecificErrorCodes.include?(error_code)
68
+ error_code =
69
+ if error_internal
70
+ error_on_server ? :server_error : :client_error
71
+ else
72
+ DefaultErrorCode
73
+ end
74
+ end
75
+
76
+ error_code = error_code.to_sym
77
+ Info.new(error_msg,error_code,error_backtrace)
78
+ end
79
+
80
+ def self.error_info_default()
81
+ Info.new(DefaultErrorMsg,DefaultErrorCode,nil)
82
+ end
83
+
84
+ end
85
+ end
86
+ end; end
@@ -0,0 +1,20 @@
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 DtkShell
19
+ VERSION="0.10.0"
20
+ end
@@ -0,0 +1,40 @@
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
@@ -0,0 +1,114 @@
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