cloudbox-server 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (147) hide show
  1. data/.yardopts +3 -0
  2. data/README.md +17 -0
  3. data/bin/cb-cluster-allocate +5 -0
  4. data/bin/cb-cluster-create +5 -0
  5. data/bin/cb-cluster-delete +5 -0
  6. data/bin/cb-cluster-desallocate +5 -0
  7. data/bin/cb-cluster-info +5 -0
  8. data/bin/cb-cluster-ls +5 -0
  9. data/bin/cb-node-destroy +5 -0
  10. data/bin/cb-node-detach +6 -0
  11. data/bin/cb-node-info +5 -0
  12. data/bin/cb-node-install +5 -0
  13. data/bin/cb-node-ls +5 -0
  14. data/bin/cb-service-add +5 -0
  15. data/bin/cb-service-component-add +5 -0
  16. data/bin/cb-service-component-delete +5 -0
  17. data/bin/cb-service-component-detach +5 -0
  18. data/bin/cb-service-conf-apply +5 -0
  19. data/bin/cb-service-conf-create +5 -0
  20. data/bin/cb-service-conf-get +5 -0
  21. data/bin/cb-service-conf-ls +5 -0
  22. data/bin/cb-service-follow-request +5 -0
  23. data/bin/cb-service-info +5 -0
  24. data/bin/cb-service-install +5 -0
  25. data/bin/cb-service-ls +5 -0
  26. data/bin/cb-service-start +5 -0
  27. data/bin/cb-service-stop +5 -0
  28. data/lib/command.rb +61 -0
  29. data/lib/command/ambari_add_host.rb +19 -0
  30. data/lib/command/ambari_cluster_command.rb +26 -0
  31. data/lib/command/ambari_cluster_component_command.rb +26 -0
  32. data/lib/command/ambari_cluster_component_host_command.rb +26 -0
  33. data/lib/command/ambari_cluster_create.rb +19 -0
  34. data/lib/command/ambari_cluster_host_command.rb +27 -0
  35. data/lib/command/ambari_cluster_list.rb +20 -0
  36. data/lib/command/ambari_cluster_service_command.rb +26 -0
  37. data/lib/command/ambari_cluster_service_host_command.rb +26 -0
  38. data/lib/command/ambari_command.rb +21 -0
  39. data/lib/command/ambari_create_cluster_configuration.rb +39 -0
  40. data/lib/command/ambari_get_cluster_configuration.rb +29 -0
  41. data/lib/command/ambari_host_list.rb +19 -0
  42. data/lib/command/ambari_install_cluster.rb +19 -0
  43. data/lib/command/ambari_install_component.rb +19 -0
  44. data/lib/command/ambari_install_host.rb +19 -0
  45. data/lib/command/ambari_install_host_component.rb +19 -0
  46. data/lib/command/ambari_install_host_components.rb +19 -0
  47. data/lib/command/ambari_install_service_components.rb +19 -0
  48. data/lib/command/ambari_service_add.rb +27 -0
  49. data/lib/command/ambari_service_component_add.rb +21 -0
  50. data/lib/command/ambari_service_component_delete.rb +21 -0
  51. data/lib/command/ambari_service_component_detach.rb +21 -0
  52. data/lib/command/ambari_service_component_info.rb +29 -0
  53. data/lib/command/ambari_service_conf_apply.rb +31 -0
  54. data/lib/command/ambari_service_conf_ls.rb +30 -0
  55. data/lib/command/ambari_service_delete.rb +21 -0
  56. data/lib/command/ambari_service_info.rb +20 -0
  57. data/lib/command/ambari_service_list.rb +21 -0
  58. data/lib/command/ambari_start_cluster.rb +19 -0
  59. data/lib/command/ambari_start_component.rb +19 -0
  60. data/lib/command/ambari_start_host.rb +19 -0
  61. data/lib/command/ambari_start_host_component.rb +19 -0
  62. data/lib/command/ambari_start_host_components.rb +19 -0
  63. data/lib/command/ambari_start_service_components.rb +19 -0
  64. data/lib/command/ambari_stop_cluster.rb +19 -0
  65. data/lib/command/ambari_stop_component.rb +19 -0
  66. data/lib/command/ambari_stop_host.rb +19 -0
  67. data/lib/command/ambari_stop_host_component.rb +19 -0
  68. data/lib/command/ambari_stop_host_components.rb +19 -0
  69. data/lib/command/ambari_stop_service_components.rb +19 -0
  70. data/lib/command/basic_command.rb +44 -0
  71. data/lib/command/cluster_create.rb +50 -0
  72. data/lib/command/cluster_delete.rb +30 -0
  73. data/lib/command/cluster_info.rb +30 -0
  74. data/lib/command/cluster_ls.rb +30 -0
  75. data/lib/command/crowbar_cluster_allocate.rb +42 -0
  76. data/lib/command/crowbar_command.rb +30 -0
  77. data/lib/command/crowbar_get_barclamps_list.rb +30 -0
  78. data/lib/command/crowbar_node_command.rb +21 -0
  79. data/lib/command/crowbar_node_list.rb +40 -0
  80. data/lib/command/crowbar_vcluster_command.rb +20 -0
  81. data/lib/command/filter.rb +15 -0
  82. data/lib/command/node_destroy.rb +58 -0
  83. data/lib/command/node_detach.rb +44 -0
  84. data/lib/command/node_info.rb +27 -0
  85. data/lib/command/node_install.rb +46 -0
  86. data/lib/command/node_reinstall.rb +44 -0
  87. data/lib/command/state_filter.rb +16 -0
  88. data/lib/common.rb +11 -0
  89. data/lib/common/cb-lib-node-erase-hard-disk.sh +29 -0
  90. data/lib/common/cloudbox_exceptions.rb +631 -0
  91. data/lib/common/cloudbox_logger.rb +81 -0
  92. data/lib/common/cloudbox_logger_mock.rb +43 -0
  93. data/lib/common/color.rb +267 -0
  94. data/lib/common/config_properties.rb +2027 -0
  95. data/lib/common/services_description.rb +192 -0
  96. data/lib/exec.rb +35 -0
  97. data/lib/exec/check_parameter.rb +208 -0
  98. data/lib/exec/cluster_allocate.rb +163 -0
  99. data/lib/exec/cluster_create.rb +99 -0
  100. data/lib/exec/cluster_delete.rb +38 -0
  101. data/lib/exec/cluster_desallocate.rb +37 -0
  102. data/lib/exec/cluster_info.rb +177 -0
  103. data/lib/exec/cluster_ls.rb +150 -0
  104. data/lib/exec/command_option.rb +222 -0
  105. data/lib/exec/executable_command.rb +194 -0
  106. data/lib/exec/node_destroy.rb +101 -0
  107. data/lib/exec/node_detach.rb +98 -0
  108. data/lib/exec/node_info.rb +280 -0
  109. data/lib/exec/node_install.rb +234 -0
  110. data/lib/exec/node_ls.rb +160 -0
  111. data/lib/exec/service_add.rb +224 -0
  112. data/lib/exec/service_component_add.rb +39 -0
  113. data/lib/exec/service_component_delete.rb +37 -0
  114. data/lib/exec/service_component_detach.rb +37 -0
  115. data/lib/exec/service_conf_apply.rb +57 -0
  116. data/lib/exec/service_conf_create.rb +80 -0
  117. data/lib/exec/service_conf_get.rb +165 -0
  118. data/lib/exec/service_conf_ls.rb +103 -0
  119. data/lib/exec/service_follow_request.rb +49 -0
  120. data/lib/exec/service_info.rb +346 -0
  121. data/lib/exec/service_install.rb +87 -0
  122. data/lib/exec/service_ls.rb +124 -0
  123. data/lib/exec/service_start.rb +110 -0
  124. data/lib/exec/service_stop.rb +112 -0
  125. data/lib/receiver.rb +14 -0
  126. data/lib/receiver/ambari_receiver.rb +812 -0
  127. data/lib/receiver/ambari_rest_api_connector.rb +599 -0
  128. data/lib/receiver/basic_receiver.rb +28 -0
  129. data/lib/receiver/connector.rb +28 -0
  130. data/lib/receiver/crowbar_receiver.rb +588 -0
  131. data/lib/receiver/crowbar_rest_api_connector.rb +518 -0
  132. data/lib/receiver/crowbar_shell_api.rb +643 -0
  133. data/lib/receiver/rest_api_connector.rb +275 -0
  134. data/resources/ambari-configurations/HBASE/default_hbase-site +33 -0
  135. data/resources/ambari-configurations/HDFS/default_hdfs-site +49 -0
  136. data/resources/ambari-configurations/HIVE/default_hive-site +33 -0
  137. data/resources/ambari-configurations/MAPREDUCE/default_mapred-site +72 -0
  138. data/resources/ambari-configurations/OOZIE/default_oozie-site +28 -0
  139. data/resources/ambari-configurations/WEBHCAT/default_webhcat-site +18 -0
  140. data/resources/ambari-configurations/ZOOKEEPER/default_zookeeper-site +8 -0
  141. data/resources/ambari-configurations/default_core-site +22 -0
  142. data/resources/ambari-configurations/default_global +141 -0
  143. data/resources/cloudbox-server.conf +10 -0
  144. data/spec/common/services_description.rb +130 -0
  145. data/spec/exec/check_parameter.rb +152 -0
  146. data/spec/exec/command_option_spec.rb +97 -0
  147. metadata +328 -0
@@ -0,0 +1,16 @@
1
+ # This file is part of cloudbox-server project
2
+ # @author tmarmin (INGENSI)
3
+
4
+ # @todo
5
+ # This class is a filter implementation of a Filter.
6
+ # @abstract
7
+ class StateFilter < Filter
8
+
9
+ # @todo
10
+ # Default protected constructor.
11
+ public
12
+ def initialize()
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/ruby
2
+
3
+ # This file is part of cloudbox-service project
4
+ # @author tnoguer (INGENSI)
5
+
6
+ $: << File.dirname(__FILE__)
7
+
8
+ require 'common/cloudbox_exceptions'
9
+ require 'common/cloudbox_logger'
10
+ require 'common/color'
11
+ require 'common/services_description'
@@ -0,0 +1,29 @@
1
+ #!/bin/bash
2
+
3
+ #set -x
4
+
5
+ # This function erase all data into all hard disks on the node and unmount partitions of /dev.
6
+ # Prerequisite:
7
+ # This script must be executed on the node.
8
+ # INPUT:
9
+ # Nothing.
10
+ # OUTPUT:
11
+ # Nothing.
12
+ nuke_everything() {
13
+ # Make sure that the kernel knows about all the partitions
14
+ for bd in /sys/block/sd*; do
15
+ if [ -e $bd ]; then
16
+ [[ -b /dev/${bd##*/} ]] || continue
17
+ dd if=/dev/zero of=/dev/${bd##*/} bs=512 count=1 > /dev/null 2>&1
18
+ fi
19
+ done
20
+
21
+ if [ -d "/data" ]; then
22
+ data_mount=`ls /data | wc -l`
23
+ if [ "$data_mount" != "0" ]; then
24
+ rm -rf /data/* > /dev/null 2>&1
25
+ fi
26
+ fi
27
+ }
28
+
29
+ nuke_everything
@@ -0,0 +1,631 @@
1
+ # This script is a manager for logger
2
+ # Author: Thibaut Marmin<tmamin@cyres.fr>(INGENSI)
3
+
4
+ module Common
5
+ # The class which list all exceptions errors
6
+ class CloudboxError < StandardError
7
+ end
8
+
9
+ # The class which list all parameters errors
10
+ class ParameterError < CloudboxError
11
+
12
+ # Default constructor of the class.
13
+ # @note Overrides default constructor by passing CustomCommandOption to super().
14
+ def initialize(msg, usage)
15
+ @usage = usage
16
+ super(msg)
17
+ end
18
+
19
+ # Return the usage help of the class calling the exception
20
+ # @author mbretaud
21
+ def usage()
22
+ return @usage
23
+ end
24
+
25
+ private
26
+ @usage = ""
27
+ end
28
+
29
+ # This error class represents a CRUD error on an entity
30
+ class EntityError < CloudboxError
31
+ public
32
+ # Type of the entity
33
+ attr_reader :type
34
+
35
+ public
36
+ # Name of the entity
37
+ attr_reader :name
38
+
39
+ public
40
+ def initialize(type, name, msg = nil)
41
+ super(msg)
42
+ @type = type
43
+ @name = name
44
+ end
45
+ end
46
+
47
+ class AlreadyExistsEntity < EntityError
48
+ def to_s
49
+ return "#{name} #{type} already exists".capitalize + "\n#{message}"
50
+ end
51
+ end
52
+
53
+ class DependencyError < CloudboxError
54
+
55
+ end
56
+
57
+ class MissingDependency < DependencyError
58
+
59
+ end
60
+
61
+ ################ ClusterError ################
62
+ # Throws an exception if the check configuration during the allocating of nodes on a cluster is catch.
63
+ class CheckConfigurationClusterAllocateError < CloudboxError
64
+ def initialize(msg)
65
+ super(msg)
66
+ end
67
+ end
68
+
69
+ # Throws an exception if the check configuration during the checking of the name of the cluster.
70
+ class CheckClusterNameError < CloudboxError
71
+ def initialize(msg)
72
+ super(msg)
73
+ end
74
+ end
75
+
76
+ # Throws an exception if the check configuration during the checking of the name of the cluster.
77
+ class CheckNetworkAddressError < CloudboxError
78
+ def initialize(msg)
79
+ super(msg)
80
+ end
81
+ end
82
+
83
+ # Throws an exception if the check configuration during the checking of the vlan id.
84
+ class CheckVlanIdError < CloudboxError
85
+ def initialize(msg)
86
+ super(msg)
87
+ end
88
+ end
89
+
90
+ class AddServiceHbaseError < CloudboxError
91
+ def initialize(msg)
92
+ super(msg)
93
+ end
94
+ end
95
+
96
+ # Throws an exception if an error occurred during the allocating of the node on a cluster.
97
+ class ClusterAllocateError < CloudboxError
98
+ def initialize(msg)
99
+ super(msg)
100
+ end
101
+ end
102
+
103
+ # Throws an exception if an error occurred during the creation of a cluster.
104
+ class ClusterCreateError < CloudboxError
105
+ def initialize(msg)
106
+ super(msg)
107
+ end
108
+ end
109
+
110
+ # Throws an exception if an error occurred during the deleting of a cluster.
111
+ class ClusterDeleteError < CloudboxError
112
+ def initialize(msg)
113
+ super(msg)
114
+ end
115
+ end
116
+
117
+ # Throws an exception if an error occurred during the desallocating of a cluster.
118
+ class ClusterDesallocateError < CloudboxError
119
+ def initialize(msg)
120
+ super(msg)
121
+ end
122
+ end
123
+
124
+ # Throws an exception if an error occurred during the showing of information about a cluster.
125
+ class ClusterInfoError < CloudboxError
126
+ def initialize(msg)
127
+ super(msg)
128
+ end
129
+ end
130
+
131
+ # Throws an exception if an error occurred during the showing of the list of clusters.
132
+ class ClusterLsError < CloudboxError
133
+ def initialize(msg)
134
+ super(msg)
135
+ end
136
+ end
137
+
138
+ # Throws an exception if an error occurred during the configuration of a proposal.
139
+ class ConfigureProposalError < CloudboxError
140
+ def initialize(msg)
141
+ super(msg)
142
+ end
143
+ end
144
+
145
+ # Throws an exception if an error occurred during the creation of a proposal.
146
+ class CreateProposalError < CloudboxError
147
+ def initialize(msg)
148
+ super(msg)
149
+ end
150
+ end
151
+
152
+ # Throws an exception if an error occurred during the creation of a cluster with the framework Crowbar.
153
+ class CrowbarCreateClusterError < CloudboxError
154
+ def initialize(msg)
155
+ super(msg)
156
+ end
157
+ end
158
+
159
+ # Throws an exception if an error occurred during the getting the list of barclamps.
160
+ class GetBarclampsListError < CloudboxError
161
+ def initialize(msg)
162
+ super(msg)
163
+ end
164
+ end
165
+
166
+ # Throws an exception if an error occurred during the setting of machines of a cluster.
167
+ class SetClusterMachineError < CloudboxError
168
+ def initialize(msg)
169
+ super(msg)
170
+ end
171
+ end
172
+
173
+ # Throws an exception if an error occurred during the verification of barclamps.
174
+ class VerifyBarclampError < CloudboxError
175
+ def initialize(msg)
176
+ super(msg)
177
+ end
178
+ end
179
+
180
+ # Throws an exception if an error occurred during the verification of committed barclamps.
181
+ class VerifyCommittedBarclampError < CloudboxError
182
+ def initialize(msg)
183
+ super(msg)
184
+ end
185
+ end
186
+ ##############################################
187
+
188
+ ################ CrowbarError ################
189
+ # Throws an exception if an error occurred during the installation of a barclamp.
190
+ class BarclampInstallError < CloudboxError
191
+ def initialize(msg)
192
+ super(msg)
193
+ end
194
+ end
195
+
196
+ # Throws an exception if an error occurred during the creation of a proposal.
197
+ class CreateProposalError < CloudboxError
198
+ def initialize(msg)
199
+ super(msg)
200
+ end
201
+ end
202
+
203
+ # Throws an exception if an error occurred during the reloading of the service crowbar.
204
+ class ReloadServiceError < CloudboxError
205
+ def initialize(msg)
206
+ super(msg)
207
+ end
208
+ end
209
+ ##############################################
210
+
211
+ ################ DirectoryError ################
212
+ # Throws an exception if a directory is already existing.
213
+ class DirectoryAlreadyExist < CloudboxError
214
+ def initialize(msg)
215
+ super(msg)
216
+ end
217
+ end
218
+
219
+ # Throws an exception if an error occurred during the creation of a directory.
220
+ class DirectoryCreateError < CloudboxError
221
+ def initialize(msg)
222
+ super(msg)
223
+ end
224
+ end
225
+
226
+ # Throws an exception if a directory is not found.
227
+ class DirectoryNotFound < CloudboxError
228
+ def initialize(msg)
229
+ super(msg)
230
+ end
231
+ end
232
+ ################################################
233
+
234
+ ################ NodeError ################
235
+ # Throws an exception if an error occurred during the deleting of nodes in all proposals.
236
+ class DeleteNodeProposalError < CloudboxError
237
+ def initialize(msg)
238
+ super(msg)
239
+ end
240
+ end
241
+
242
+ # Throws an exception if an error occurred during the erasing of nodes.
243
+ class EraseNodeError < CloudboxError
244
+ def initialize(msg)
245
+ super(msg)
246
+ end
247
+ end
248
+
249
+ # Throws an exception if an error occurred during the deleting of a node.
250
+ class NodeDeleteError < CloudboxError
251
+ def initialize(msg)
252
+ super(msg)
253
+ end
254
+ end
255
+
256
+ # Throws an exception if an error occurred during the destroying of a node.
257
+ class NodeDestroyError < CloudboxError
258
+ def initialize(msg)
259
+ super(msg)
260
+ end
261
+ end
262
+
263
+ # Throws an exception if an error occurred during the detaching of a node.
264
+ class NodeDetachError < CloudboxError
265
+ def initialize(msg)
266
+ super(msg)
267
+ end
268
+ end
269
+
270
+ # Throws an exception if an error occurred during the showing of information about a node.
271
+ class NodeInfoError < CloudboxError
272
+ def initialize(msg)
273
+ super(msg)
274
+ end
275
+ end
276
+
277
+ # Throws an exception if an error occurred during the installation of a node.
278
+ class NodeInstallError < CloudboxError
279
+ def initialize(msg)
280
+ super(msg)
281
+ end
282
+ end
283
+
284
+ # Throws an exception if an error occurred during the showing the list of nodes.
285
+ class NodeListError < CloudboxError
286
+ def initialize(msg)
287
+ super(msg)
288
+ end
289
+ end
290
+
291
+ # Throws an exception if a node is not existing.
292
+ class NodeNotExistsError < CloudboxError
293
+ def initialize(msg)
294
+ super(msg)
295
+ end
296
+ end
297
+
298
+ # Throws an exception if an error occurred during the rebooting of a node.
299
+ class NodeRebootError < CloudboxError
300
+ def initialize(msg)
301
+ super(msg)
302
+ end
303
+ end
304
+
305
+ # Throws an exception if an error occurred during the reinstalling of a node.
306
+ class NodeReinstallError < CloudboxError
307
+ def initialize(msg)
308
+ super(msg)
309
+ end
310
+ end
311
+
312
+ # Throws an exception if an error occurred during the setting Bios name on a node.
313
+ class NodeSetBiosError < CloudboxError
314
+ def initialize(msg)
315
+ super(msg)
316
+ end
317
+ end
318
+
319
+ # Throws an exception if an error occurred during the setting Raid name on a node.
320
+ class NodeSetRaidError < CloudboxError
321
+ def initialize(msg)
322
+ super(msg)
323
+ end
324
+ end
325
+
326
+ # Throws an exception if an error occurred during the setting Bios name and Raid name on a node.
327
+ class NodeSetBiosRaidError < CloudboxError
328
+ def initialize(msg)
329
+ super(msg)
330
+ end
331
+ end
332
+
333
+ # Throws an exception if an error occurred during the removing of a node.
334
+ class RemoveNodesError < CloudboxError
335
+ def initialize(msg)
336
+ super(msg)
337
+ end
338
+ end
339
+ ###########################################
340
+
341
+ ################ ShellError ################
342
+ # Throws an exception if an error occurred during the executing a Shell command.
343
+ class ExecuteShellError < CloudboxError
344
+ def initialize(msg)
345
+ super(msg)
346
+ end
347
+ end
348
+
349
+ # Throws an exception if an error occurred during the executing a SSH command.
350
+ class SSHError < CloudboxError
351
+ def initialize(msg)
352
+ super(msg)
353
+ end
354
+ end
355
+
356
+ # Throws an exception if an error occurred during the uploading of a file.
357
+ class UploadError < CloudboxError
358
+ def initialize(msg)
359
+ super(msg)
360
+ end
361
+ end
362
+ ##############################################
363
+ # Throws an exception if something??? is not implemented.
364
+ class NotImplemented < CloudboxError
365
+ def initialize(msg)
366
+ super(msg)
367
+ end
368
+ end
369
+
370
+ # Throws an exception if a parameter is invalid.
371
+ class InvalidParameter < ParameterError
372
+ def initialize(param, usage)
373
+ super("Invalid parameter: " + param, usage)
374
+ end
375
+ end
376
+
377
+ # Throws an exception if a parameter is missing.
378
+ class MissingParameter < ParameterError
379
+ def initialize(param, usage)
380
+ super("Missing parameter: " + param, usage)
381
+ end
382
+ end
383
+
384
+ # Throws an exception if a parameter is inconsistent.
385
+ class InconsistentParameter < ParameterError
386
+ def initialize(msg, usage, *params)
387
+ super("Inconsistent parameters: " + params.join(", ") + ": " + msg, usage)
388
+ end
389
+ end
390
+
391
+ # Throws an exception if a request is invalid.
392
+ class InvalidRequest < CloudboxError
393
+ end
394
+
395
+ # Throws an exception if an entity is unknown.
396
+ class UnknownEntity < InvalidRequest
397
+
398
+ def initialize(entityType, entityName)
399
+ super("Unkown " + entityType + " " + entityName + ".")
400
+ end
401
+ end
402
+
403
+ # Throws an exception if an error occurred about a file.
404
+ class FileError < CloudboxError
405
+ def initialize(msg)
406
+ super(msg)
407
+ end
408
+ end
409
+
410
+ # Get a message if an action is invalid.
411
+ class InvalidActionSequence < InvalidRequest
412
+ @action = ""
413
+ @currentState = ""
414
+ @entityName = ""
415
+ @entityType = ""
416
+ @possibilities = ""
417
+
418
+ # Default constructor of the class.
419
+ # @note Overrides default constructor by passing CustomCommandOption to super().
420
+ def initialize(action, currentState, possibilities, entityName, entityType)
421
+ @action = action
422
+ @currentState = currentState
423
+ @entityName = entityName
424
+ @entityType = entityType
425
+ @possibilities = possibilities
426
+ super(getMsg())
427
+ end
428
+
429
+ # Get an action
430
+ def getAction
431
+ return @action
432
+ end
433
+
434
+ # Get the current state
435
+ def getCurrentState
436
+ return @currentState
437
+ end
438
+
439
+ # Get the entity name
440
+ def getEntityName
441
+ return @entityName
442
+ end
443
+
444
+ # Get the entity type
445
+ def getEntityType
446
+ return @entityType
447
+ end
448
+
449
+ private
450
+ # Get the message of the error
451
+ def getMsg()
452
+ sexyStates = ""
453
+ first = true
454
+ @possibilities[@action]['required_state'].each do |a|
455
+ sexyStates += "|" unless first
456
+ first = false
457
+ sexyStates += a
458
+ end
459
+ msg = "To #{@action} the #{@entityType} #{@entityName}, it has to be in state #{sexyStates} (current: '#{@currentState}')."
460
+ end
461
+ end
462
+
463
+ # Throws a error if an error occurred with a HTTP request.
464
+ class HTTPError< CloudboxError
465
+
466
+ # Get the consistent error message of the request
467
+ def self.getConsistentError(message, code, body)
468
+ code = code.to_i
469
+ if code > 399 && code < 500
470
+ return ClientError.new(message, code, body)
471
+ elsif code > 499 && code < 600
472
+ return ServerError.new(message, code, body)
473
+ else
474
+ return HTTPError.new(message, code, body)
475
+ end
476
+ end
477
+
478
+ # Default constructor of the class.
479
+ # @note Overrides default constructor by passing CustomCommandOption to super().
480
+ def initialize(message, code, body=nil)
481
+ super(message)
482
+ @code = code
483
+ @body = body
484
+ end
485
+
486
+ # Get the code status of the request
487
+ def code()
488
+ return @code
489
+ end
490
+
491
+ # Get the body of the request
492
+ def body()
493
+ return @body
494
+ end
495
+
496
+ # Get the short HTTP message of the request
497
+ def shortHttpMessage()
498
+ return "" if @@codes[@code].nil?
499
+ return @@codes[@code][:short]
500
+ end
501
+
502
+ # Get the long HTTP message of the request
503
+ def longHttpMessage()
504
+ return "" if @@codes[@code].nil?
505
+ return @@codes[@code][:long]
506
+ end
507
+
508
+ private
509
+ @code=0
510
+ @body=""
511
+ @@codes={
512
+ 400 =>
513
+ {:short => "Bad Request", :long => "The request cannot be fulfilled due to bad syntax."},
514
+ 401 =>
515
+ {:short => "Unauthorized", :long => "Similar to 403 Forbidden, but specifically for use when authentication is required and has failed or has not yet been provided.[] The response must include a WWW-Authenticate header field containing a challenge applicable to the requested resource. See Basic access authentication and Digest access authentication."},
516
+ 402 =>
517
+ {:short => "Payment Required", :long => " Reserved for future use.[] The original intention was that this code might be used as part of some form of digital cash or micropayment scheme, but that has not happened, and this code is not usually used. As an example of its use, however, Apple's defunct MobileMe service generated a 40 error if the MobileMe account was delinquent.[citation needed] In addition, YouTube uses this status if a particular IP address has made excessive requests, and requires the person to enter a CAPTCHA."},
518
+ 403 =>
519
+ {:short => "Forbidden", :long => "The request was a valid request, but the server is refusing to respond to it.[] Unlike a 401 Unauthorized response, authenticating will make no difference.[] On servers where authentication is required, this commonly means that the provided credentials were successfully authenticated but that the credentials still do not grant the client permission to access the resource (e.g. a recognized user attempting to access restricted content)."},
520
+ 404 =>
521
+ {:short => "Not Found", :long => "The requested resource could not be found but may be available again in the future.[] Subsequent requests by the client are permissible."},
522
+ 405 =>
523
+ {:short => "Method Not Allowed", :long => "A request was made of a resource using a request method not supported by that resource;[] for example, using GET on a form which requires data to be presented via POST, or using PUT on a read-only resource."},
524
+ 406 =>
525
+ {:host => "Not Acceptable", :long => "The requested resource is only capable of generating content not acceptable according to the Accept headers sent in the request."},
526
+ 407 =>
527
+ {:short => "Proxy Authentication Required", :long => "The client must first authenticate itself with the proxy."},
528
+ 408 =>
529
+ {:short => "Request Timeout", :long => "The server timed out waiting for the request. According to W3 HTTP specifications: \"The client did not produce a request within the time that the server was prepared to wait. The client MAY repeat the request without modifications at any later time.\""},
530
+ 409 =>
531
+ {:short => "Conflict", :long => "Indicates that the request could not be processed because of conflict in the request, such as an edit conflict."},
532
+ 410 =>
533
+ {:short => "Gone", :long => "Indicates that the resource requested is no longer available and will not be available again. This should be used when a resource has been intentionally removed and the resource should be purged. Upon receiving a 410 status code, the client should not request the resource again in the future. Clients such as search engines should remove the resource from their indices. Most use cases do not require clients and search engines to purge the resource, and a \"404 Not Found\" may be used instead."},
534
+ 411 =>
535
+ {:short => "Length Required", :long => "The request did not specify the length of its content, which is required by the requested resource."},
536
+ 41 =>
537
+ {:short => "Precondition Failed", :long => "The server does not meet one of the preconditions that the requester put on the request."},
538
+ 413 =>
539
+ {:short => "Request Entity Too Large", :long => "The request is larger than the server is willing or able to process."},
540
+ 414 =>
541
+ {:short => "Request-URI Too Long", :long => "The URI provided was too long for the server to process."},
542
+ 415 =>
543
+ {:short => "Unsupported Media Type", :long => "The request entity has a media type which the server or resource does not support. For example, the client uploads an image as image/svg+xml, but the server requires that images use a different format."},
544
+ 416 =>
545
+ {:short => "Requested Range Not Satisfiable", :long => "The client has asked for a portion of the file, but the server cannot supply that portion.[] For example, if the client asked for a part of the file that lies beyond the end of the file."},
546
+ 417 =>
547
+ {:short => "Expectation Failed", :long => "The server cannot meet the requirements of the Expect request-header field."},
548
+ 418 =>
549
+ {:short => "I'm a teapot (RFC 34)", :long => "This code was defined in 1998 as one of the traditional IETF April Fools' jokes, in RFC 34, Hyper Text Coffee Pot Control Protocol, and is not expected to be implemented by actual HTTP servers."},
550
+ 419 =>
551
+ {:short => "Authentication Timeout", :long => "Not a part of the HTTP standard, 419 Authentication Timeout denotes that previously valid authentication has expired. It is used as an alternative to 401 Unauthorized in order to differentiate from otherwise authenticated clients being denied access to specific server resources."},
552
+ 40 =>
553
+ {:short => "Enhance Your Calm (Twitter)", :long => "Not part of the HTTP standard, but returned by the Twitter Search and Trends API when the client is being rate limited.[13] Other services may wish to implement the 49 Too Many Requests response code instead."},
554
+ 4 =>
555
+ {:short => "Unprocessable Entity (WebDAV; RFC 4918)", :long => "The request was well-formed but was unable to be followed due to semantic errors."},
556
+ 43 =>
557
+ {:short => "Locked (WebDAV; RFC 4918)", :long => "The resource that is being accessed is locked."},
558
+ 44 =>
559
+ {:short => "Failed Dependency (WebDAV; RFC 4918)", :long => "The request failed due to failure of a previous request (e.g. a PROPPATCH)."},
560
+ 44 =>
561
+ {:short => "Method Failure (WebDAV)", :long => "Indicates the method was not executed on a particular resource within its scope because some part of the method's execution failed causing the entire method to be aborted."},
562
+ 45 =>
563
+ {:short => "Unordered Collection (Internet draft)", :long => "Defined in drafts of \"WebDAV Advanced Collections Protocol\", but not present in \"Web Distributed Authoring and Versioning (WebDAV) Ordered Collections Protocol\"."},
564
+ 46 =>
565
+ {:short => "Upgrade Required (RFC 817)", :long => "The client should switch to a different protocol such as TLS/1.0."},
566
+ 48 =>
567
+ {:short => "Precondition Required (RFC 6585)", :long => "The origin server requires the request to be conditional. Intended to prevent \"the 'lost update' problem, where a client GETs a resource's state, modifies it, and PUTs it back to the server, when meanwhile a third party has modified the state on the server, leading to a conflict.\""},
568
+ 49 =>
569
+ {:short => "Too Many Requests (RFC 6585)", :long => "The user has sent too many requests in a given amount of time. Intended for use with rate limiting schemes."},
570
+ 431 =>
571
+ {:short => "Request Header Fields Too Large (RFC 6585)", :long => "The server is unwilling to process the request because either an individual header field, or all the header fields collectively, are too large."},
572
+ 444 =>
573
+ {:short => "No Response (Nginx)", :long => "Used in Nginx logs to indicate that the server has returned no information to the client and closed the connection (useful as a deterrent for malware)."},
574
+ 449 =>
575
+ {:short => "Retry With (Microsoft)", :long => "A Microsoft extension. The request should be retried after performing the appropriate action."},
576
+ 450 =>
577
+ {:short => "Blocked by Windows Parental Controls (Microsoft)", :long => "A Microsoft extension. This error is given when Windows Parental Controls are turned on and are blocking access to the given webpage."},
578
+ 451 =>
579
+ {:short => "Unavailable For Legal Reasons (Internet draft)", :long => "Defined in the internet draft \"A New HTTP Status Code for Legally-restricted Resources\". Intended to be used when resource access is denied for legal reasons, e.g. censorship or government-mandated blocked access. A reference to the 1953 dystopian novel Fahrenheit 451, where books are outlawed."},
580
+ 451 =>
581
+ {:short => "Redirect (Microsoft)", :long => "Used in Exchange ActiveSync if there either is a more efficient server to use or the server can't access the users' mailbox."},
582
+ 494 =>
583
+ {:short => "Request Header Too Large (Nginx)", :long => "Nginx internal code similar to 413 but it was introduced earlier."},
584
+ 495 =>
585
+ {:short => "Cert Error (Nginx)", :long => "Nginx internal code used when SSL client certificate error occurred to distinguish it from 4XX in a log and an error page redirection."},
586
+ 496 =>
587
+ {:short => "No Cert (Nginx)", :long => "Nginx internal code used when client didn't provide certificate to distinguish it from 4XX in a log and an error page redirection."},
588
+ 497 =>
589
+ {:short => "HTTP to HTTPS (Nginx)", :long => "Nginx internal code used for the plain HTTP requests that are sent to HTTPS port to distinguish it from 4XX in a log and an error page redirection."},
590
+ 499 =>
591
+ {:short => "Client Closed Request (Nginx)", :long => "Used in Nginx logs to indicate when the connection has been closed by client while the server is still processing its request, making server unable to send a status code back."},
592
+ 500 =>
593
+ {:short => "Internal Server Error", :long => "A generic error message, given when no more specific message is suitable."},
594
+ 501 =>
595
+ {:short => "Not Implemented", :long => "The server either does not recognize the request method, or it lacks the ability to fulfill the request."},
596
+ 502 =>
597
+ {:short => "Bad Gateway", :long => "The server was acting as a gateway or proxy and received an invalid response from the upstream server."},
598
+ 503 =>
599
+ {:short => "Service Unavailable", :long => "The server is currently unavailable (because it is overloaded or down for maintenance).[2] Generally, this is a temporary state."},
600
+ 504 =>
601
+ {:short => "Gateway Timeout", :long => "The server was acting as a gateway or proxy and did not receive a timely response from the upstream server."},
602
+ 505 =>
603
+ {:short => "HTTP Version Not Supported", :long => "The server does not support the HTTP protocol version used in the request."},
604
+ 506 =>
605
+ {:short => "Variant Also Negotiates (RFC 2295)", :long => "Transparent content negotiation for the request results in a circular reference."},
606
+ 507 =>
607
+ {:short => "Insufficient Storage (WebDAV; RFC 4918)", :long => "The server is unable to store the representation needed to complete the request."},
608
+ 508 =>
609
+ {:short => "Loop Detected (WebDAV; RFC 5842)", :long => "The server detected an infinite loop while processing the request (sent in lieu of 208)."},
610
+ 509 =>
611
+ {:short => "Bandwidth Limit Exceeded (Apache bw/limited extension)", :long => "This status code, while used by many servers, is not specified in any RFCs."},
612
+ 510 =>
613
+ {:short => "Not Extended (RFC 2774)", :long => "Further extensions to the request are required for the server to fulfil it."},
614
+ 511 =>
615
+ {:short => "Network Authentication Required (RFC 6585)", :long => "The client needs to authenticate to gain network access. Intended for use by intercepting proxies used to control access to the network (e.g. \"captive portals\" used to require agreement to Terms of Service before granting full Internet access via a Wi-Fi hotspot)."},
616
+ 598 =>
617
+ {:short => "Network read timeout error (Unknown)", :long => "This status code is not specified in any RFCs, but is used by Microsoft HTTP proxies to signal a network read timeout behind the proxy to a client in front of the proxy.[citation needed]"},
618
+ 599 =>
619
+ {:short => "Network connect timeout error (Unknown)", :long => "This status code is not specified in any RFCs, but is used by Microsoft HTTP proxies to signal a network connect timeout behind the proxy to a client in front of the proxy.[citation needed]"}
620
+ }
621
+ end
622
+
623
+ # Throws an exception if an error occurred on a client request.
624
+ class ClientError < HTTPError
625
+ end
626
+
627
+ # Throws an exception if an error occurred on a server request.
628
+ class ServerError < HTTPError
629
+ end
630
+
631
+ end