schemata-dea 0.0.1.beta14 → 0.0.1.beta15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/lib/schemata/common/componentbase.rb +42 -0
  2. data/lib/schemata/common/msgbase.rb +13 -11
  3. data/lib/schemata/common/msgtypebase.rb +20 -0
  4. data/lib/schemata/common/parsed_msg.rb +1 -1
  5. data/lib/schemata/dea/advertise_message/advertise_message_v1.rb +1 -1
  6. data/lib/schemata/dea/advertise_message.rb +1 -5
  7. data/lib/schemata/dea/dea_status_response/dea_status_response_v1.rb +1 -1
  8. data/lib/schemata/dea/dea_status_response.rb +1 -5
  9. data/lib/schemata/dea/discover_request/discover_request_v1.rb +1 -1
  10. data/lib/schemata/dea/discover_request.rb +1 -5
  11. data/lib/schemata/dea/droplet_status_response/droplet_status_response_v1.rb +1 -1
  12. data/lib/schemata/dea/droplet_status_response.rb +1 -5
  13. data/lib/schemata/dea/exit_message/exit_message_v1.rb +1 -1
  14. data/lib/schemata/dea/exit_message.rb +1 -5
  15. data/lib/schemata/dea/find_droplet_request/find_droplet_request_v1.rb +1 -1
  16. data/lib/schemata/dea/find_droplet_request.rb +1 -5
  17. data/lib/schemata/dea/find_droplet_response/find_droplet_response_v1.rb +1 -1
  18. data/lib/schemata/dea/find_droplet_response.rb +1 -5
  19. data/lib/schemata/dea/heartbeat_response/heartbeat_response_v1.rb +1 -1
  20. data/lib/schemata/dea/heartbeat_response.rb +1 -5
  21. data/lib/schemata/dea/hello_message/hello_message_v1.rb +1 -1
  22. data/lib/schemata/dea/hello_message.rb +1 -5
  23. data/lib/schemata/dea/start_request/start_request_v1.rb +5 -3
  24. data/lib/schemata/dea/start_request.rb +1 -5
  25. data/lib/schemata/dea/stop_request/stop_request_v1.rb +1 -1
  26. data/lib/schemata/dea/stop_request.rb +1 -5
  27. data/lib/schemata/dea/update_request/update_request_v1.rb +1 -1
  28. data/lib/schemata/dea/update_request.rb +1 -5
  29. data/lib/schemata/dea/version.rb +2 -2
  30. data/lib/schemata/dea.rb +3 -60
  31. data/lib/schemata/helpers/decamelize.rb +23 -0
  32. data/lib/schemata/helpers/hash_copy.rb +1 -1
  33. data/lib/schemata/helpers/stringify.rb +1 -1
  34. data/spec/{cloud_controller/cloud_controller_spec.rb → cloud_controller_spec.rb} +0 -0
  35. data/spec/common/helpers_spec.rb +16 -16
  36. data/spec/{dea/dea_spec.rb → dea_spec.rb} +1 -1
  37. data/spec/{health_manager/health_manager_spec.rb → health_manager_spec.rb} +0 -0
  38. data/spec/{router/router_spec.rb → router_spec.rb} +0 -0
  39. data/spec/{staging/staging_spec.rb → staging_spec.rb} +0 -0
  40. data/spec/support/component_helpers.rb +16 -2
  41. data/spec/support/helpers.rb +0 -20
  42. data/spec/support/message_helpers.rb +23 -19
  43. data/spec/support/message_type_helpers.rb +59 -55
  44. metadata +36 -80
  45. data/spec/cloud_controller/droplet_updated_message_spec.rb +0 -10
  46. data/spec/cloud_controller/hm_start_request_spec.rb +0 -11
  47. data/spec/cloud_controller/hm_stop_request_spec.rb +0 -12
  48. data/spec/dea/advertise_message_spec.rb +0 -10
  49. data/spec/dea/dea_status_response_spec.rb +0 -10
  50. data/spec/dea/discover_request_spec.rb +0 -10
  51. data/spec/dea/droplet_status_response_spec.rb +0 -10
  52. data/spec/dea/exit_message_spec.rb +0 -10
  53. data/spec/dea/find_droplet_request_spec.rb +0 -27
  54. data/spec/dea/find_droplet_response_spec.rb +0 -10
  55. data/spec/dea/heartbeat_response_spec.rb +0 -10
  56. data/spec/dea/hello_message_spec.rb +0 -10
  57. data/spec/dea/start_request_spec.rb +0 -10
  58. data/spec/dea/stop_request_spec.rb +0 -10
  59. data/spec/dea/update_request_spec.rb +0 -0
  60. data/spec/health_manager/health_request_spec.rb +0 -12
  61. data/spec/health_manager/health_response_spec.rb +0 -12
  62. data/spec/health_manager/status_crashed_response_spec.rb +0 -12
  63. data/spec/health_manager/status_flapping_response_spec.rb +0 -12
  64. data/spec/health_manager/status_request_spec.rb +0 -12
  65. data/spec/router/register_request_spec.rb +0 -10
  66. data/spec/router/start_message_spec.rb +0 -10
  67. data/spec/staging/staging_message_spec.rb +0 -14
@@ -0,0 +1,42 @@
1
+ require 'schemata/helpers/decamelize'
2
+
3
+ module Schemata
4
+ module ComponentBase
5
+
6
+ def message_types
7
+ self.constants.select { |x| x != :VERSION }
8
+ end
9
+
10
+ def component_name
11
+ self.name.split("::")[1]
12
+ end
13
+
14
+ def eigenclass
15
+ class << self; self; end
16
+ end
17
+
18
+ def register_mock_methods
19
+ message_types.each do |type|
20
+ message_type = self::const_get(type)
21
+ mock_method_name = "mock_#{Schemata::Helpers.decamelize(type.to_s)}"
22
+ eigenclass.send(:define_method, mock_method_name) do |*args|
23
+ version = args[0] || message_type.current_version
24
+ message_type::const_get("V#{version}").mock
25
+ end
26
+ end
27
+ end
28
+
29
+ def require_message_classes
30
+ path = "./lib/schemata/"
31
+ path << Schemata::Helpers.decamelize(component_name)
32
+ path << "/*.rb"
33
+ Dir.glob(path, &method(:require))
34
+ end
35
+
36
+ def self.extended(klass)
37
+ klass.require_message_classes
38
+ klass.register_mock_methods
39
+ end
40
+
41
+ end
42
+ end
@@ -14,7 +14,7 @@ module Schemata
14
14
  @contents = {}
15
15
 
16
16
  data.each do |key, field_value|
17
- key = Schemata::HashCopyHelpers.stringify(key)
17
+ key = Schemata::Helpers.stringify(key)
18
18
  field_schema = @schema.schemas[key]
19
19
  next unless field_schema
20
20
 
@@ -27,7 +27,7 @@ module Schemata
27
27
  # symbols, but on the decoding side, it should expect strings. To allow
28
28
  # for this in the schema definition, Schemata stringifies all symbols during
29
29
  # construction of Schemata objects.
30
- field_value = Schemata::HashCopyHelpers.stringify(field_value)
30
+ field_value = Schemata::Helpers.stringify(field_value)
31
31
 
32
32
  begin
33
33
  field_schema.validate(field_value)
@@ -35,7 +35,7 @@ module Schemata
35
35
  raise Schemata::UpdateAttributeError.new(key, e.message)
36
36
  end
37
37
 
38
- @contents[key] = Schemata::HashCopyHelpers.deep_copy(field_value)
38
+ @contents[key] = Schemata::Helpers.deep_copy(field_value)
39
39
  end
40
40
  end
41
41
 
@@ -45,7 +45,7 @@ module Schemata
45
45
  schema.schemas.each do |key, field_schema|
46
46
  vc_klass.send(:define_method, key) do
47
47
  unless @contents[key].nil?
48
- return Schemata::HashCopyHelpers.deep_copy(@contents[key])
48
+ return Schemata::Helpers.deep_copy(@contents[key])
49
49
  end
50
50
  nil
51
51
  end
@@ -53,13 +53,15 @@ module Schemata
53
53
  # TODO This call to stringify should be removed when cc/dea stops using
54
54
  # symbols. See comment above for a better description.
55
55
  vc_klass.send(:define_method, "#{key}=") do |field_value|
56
- field_value = Schemata::HashCopyHelpers.stringify(field_value)
57
- begin
58
- field_schema.validate(field_value)
59
- rescue Membrane::SchemaValidationError => e
60
- raise Schemata::UpdateAttributeError.new(key, e.message)
56
+ field_value = Schemata::Helpers.stringify(field_value)
57
+ unless schema.optional_keys.include?(key) && field_value == nil
58
+ begin
59
+ field_schema.validate(field_value)
60
+ rescue Membrane::SchemaValidationError => e
61
+ raise Schemata::UpdateAttributeError.new(key, e.message)
62
+ end
61
63
  end
62
- @contents[key] = Schemata::HashCopyHelpers.deep_copy(field_value)
64
+ @contents[key] = Schemata::Helpers.deep_copy(field_value)
63
65
  field_value
64
66
  end
65
67
  end
@@ -67,7 +69,7 @@ module Schemata
67
69
  end
68
70
 
69
71
  def contents
70
- Schemata::HashCopyHelpers.deep_copy(@contents)
72
+ Schemata::Helpers.deep_copy(@contents)
71
73
  end
72
74
 
73
75
  def empty?
@@ -1,5 +1,6 @@
1
1
  require 'schemata/common/msgbase'
2
2
  require 'schemata/common/parsed_msg'
3
+ require 'schemata/helpers/decamelize'
3
4
 
4
5
  module Schemata
5
6
  module MessageTypeBase
@@ -70,8 +71,27 @@ module Schemata
70
71
  Schemata::const_get(component)
71
72
  end
72
73
 
74
+ def component_name
75
+ self.name.split("::")[1]
76
+ end
77
+
78
+ def message_type_name
79
+ self.name.split("::")[2]
80
+ end
81
+
82
+ def require_message_versions
83
+ path = "./lib/schemata/"
84
+ path << Schemata::Helpers.decamelize(component_name)
85
+ path << "/"
86
+ path << Schemata::Helpers.decamelize(message_type_name)
87
+ path << "/*.rb"
88
+
89
+ Dir.glob(path, &method(:require))
90
+ end
91
+
73
92
  def self.extended(o)
74
93
  o.extend Dsl
94
+ o.require_message_versions
75
95
  end
76
96
 
77
97
  module Dsl
@@ -37,7 +37,7 @@ module Schemata
37
37
  end
38
38
 
39
39
  def contents
40
- Schemata::HashCopyHelpers.deep_copy(@contents)
40
+ Schemata::Helpers.deep_copy(@contents)
41
41
  end
42
42
  end
43
43
  end
@@ -2,7 +2,7 @@ require 'schemata/helpers/hash_copy'
2
2
  require 'schemata/common/msgtypebase'
3
3
 
4
4
  module Schemata
5
- module DEA
5
+ module Dea
6
6
  module AdvertiseMessage
7
7
  version 1 do
8
8
  include_preschemata
@@ -1,13 +1,9 @@
1
1
  require 'schemata/common/msgtypebase'
2
2
 
3
3
  module Schemata
4
- module DEA
4
+ module Dea
5
5
  module AdvertiseMessage
6
6
  extend Schemata::MessageTypeBase
7
7
  end
8
8
  end
9
9
  end
10
-
11
- Dir[File.dirname(__FILE__) + '/advertise_message/*.rb'].each do |file|
12
- require file
13
- end
@@ -1,7 +1,7 @@
1
1
  require 'schemata/common/msgtypebase'
2
2
 
3
3
  module Schemata
4
- module DEA
4
+ module Dea
5
5
  module DeaStatusResponse
6
6
  version 1 do
7
7
  include_preschemata
@@ -1,13 +1,9 @@
1
1
  require 'schemata/common/msgtypebase'
2
2
 
3
3
  module Schemata
4
- module DEA
4
+ module Dea
5
5
  module DeaStatusResponse
6
6
  extend Schemata::MessageTypeBase
7
7
  end
8
8
  end
9
9
  end
10
-
11
- Dir[File.dirname(__FILE__) + '/dea_status_response/*.rb'].each do |file|
12
- require file
13
- end
@@ -1,7 +1,7 @@
1
1
  require 'vcap/common'
2
2
 
3
3
  module Schemata
4
- module DEA
4
+ module Dea
5
5
  module DiscoverRequest
6
6
  version 1 do
7
7
  include_preschemata
@@ -1,13 +1,9 @@
1
1
  require 'schemata/common/msgtypebase'
2
2
 
3
3
  module Schemata
4
- module DEA
4
+ module Dea
5
5
  module DiscoverRequest
6
6
  extend Schemata::MessageTypeBase
7
7
  end
8
8
  end
9
9
  end
10
-
11
- Dir[File.dirname(__FILE__) + '/discover_request/*.rb'].each do |file|
12
- require file
13
- end
@@ -4,7 +4,7 @@ require 'schemata/common/msgtypebase'
4
4
  require 'vcap/common'
5
5
 
6
6
  module Schemata
7
- module DEA
7
+ module Dea
8
8
  module DropletStatusResponse
9
9
  version 1 do
10
10
  include_preschemata
@@ -1,13 +1,9 @@
1
1
  require 'schemata/common/msgtypebase'
2
2
 
3
3
  module Schemata
4
- module DEA
4
+ module Dea
5
5
  module DropletStatusResponse
6
6
  extend Schemata::MessageTypeBase
7
7
  end
8
8
  end
9
9
  end
10
-
11
- Dir[File.dirname(__FILE__) + '/droplet_status_response/*.rb'].each do |file|
12
- require file
13
- end
@@ -2,7 +2,7 @@ require 'schemata/common/msgtypebase'
2
2
  require 'vcap/common'
3
3
 
4
4
  module Schemata
5
- module DEA
5
+ module Dea
6
6
  module ExitMessage
7
7
  version 1 do
8
8
  include_preschemata
@@ -1,13 +1,9 @@
1
1
  require 'schemata/common/msgtypebase'
2
2
 
3
3
  module Schemata
4
- module DEA
4
+ module Dea
5
5
  module ExitMessage
6
6
  extend Schemata::MessageTypeBase
7
7
  end
8
8
  end
9
9
  end
10
-
11
- Dir[File.dirname(__FILE__) + '/exit_message/*.rb'].each do |file|
12
- require file
13
- end
@@ -2,7 +2,7 @@ require 'schemata/common/msgtypebase'
2
2
  require 'vcap/common'
3
3
 
4
4
  module Schemata
5
- module DEA
5
+ module Dea
6
6
  module FindDropletRequest
7
7
  version 1 do
8
8
  include_preschemata
@@ -1,13 +1,9 @@
1
1
  require 'schemata/common/msgtypebase'
2
2
 
3
3
  module Schemata
4
- module DEA
4
+ module Dea
5
5
  module FindDropletRequest
6
6
  extend Schemata::MessageTypeBase
7
7
  end
8
8
  end
9
9
  end
10
-
11
- Dir[File.dirname(__FILE__) + '/find_droplet_request/*.rb'].each do |file|
12
- require file
13
- end
@@ -4,7 +4,7 @@ require 'schemata/common/msgtypebase'
4
4
  require 'vcap/common'
5
5
 
6
6
  module Schemata
7
- module DEA
7
+ module Dea
8
8
  module FindDropletResponse
9
9
  version 1 do
10
10
  include_preschemata
@@ -1,13 +1,9 @@
1
1
  require "schemata/common/msgtypebase"
2
2
 
3
3
  module Schemata
4
- module DEA
4
+ module Dea
5
5
  module FindDropletResponse
6
6
  extend Schemata::MessageTypeBase
7
7
  end
8
8
  end
9
9
  end
10
-
11
- Dir[File.dirname(__FILE__) + '/find_droplet_response/*.rb'].each do |file|
12
- require file
13
- end
@@ -4,7 +4,7 @@ require 'schemata/common/msgtypebase'
4
4
  require 'vcap/common'
5
5
 
6
6
  module Schemata
7
- module DEA
7
+ module Dea
8
8
  module HeartbeatResponse
9
9
 
10
10
  version 1 do
@@ -1,13 +1,9 @@
1
1
  require "schemata/common/msgtypebase"
2
2
 
3
3
  module Schemata
4
- module DEA
4
+ module Dea
5
5
  module HeartbeatResponse
6
6
  extend Schemata::MessageTypeBase
7
7
  end
8
8
  end
9
9
  end
10
-
11
- Dir[File.dirname(__FILE__) + '/heartbeat_response/*.rb'].each do |file|
12
- require file
13
- end
@@ -2,7 +2,7 @@ require 'schemata/common/msgtypebase'
2
2
  require 'vcap/common'
3
3
 
4
4
  module Schemata
5
- module DEA
5
+ module Dea
6
6
  module HelloMessage
7
7
  version 1 do
8
8
  include_preschemata
@@ -1,13 +1,9 @@
1
1
  require 'schemata/common/msgtypebase'
2
2
 
3
3
  module Schemata
4
- module DEA
4
+ module Dea
5
5
  module HelloMessage
6
6
  extend Schemata::MessageTypeBase
7
7
  end
8
8
  end
9
9
  end
10
-
11
- Dir[File.dirname(__FILE__) + '/hello_message/*.rb'].each do |file|
12
- require file
13
- end
@@ -2,7 +2,7 @@ require 'schemata/common/msgtypebase'
2
2
  require 'vcap/common'
3
3
 
4
4
  module Schemata
5
- module DEA
5
+ module Dea
6
6
  module StartRequest
7
7
  version 1 do
8
8
  include_preschemata
@@ -74,7 +74,8 @@ module Schemata
74
74
  "cc_partition" => String,
75
75
  "debug" => any,
76
76
  "console" => any,
77
- "index" => Integer
77
+ "index" => Integer,
78
+ optional("flapping") => bool,
78
79
  }
79
80
  end
80
81
 
@@ -132,7 +133,8 @@ module Schemata
132
133
  "cc_partition" => "default",
133
134
  "debug" => nil,
134
135
  "console" => nil,
135
- "index" => 0
136
+ "index" => 0,
137
+ "flapping" => false,
136
138
  }
137
139
  end
138
140
  end
@@ -1,13 +1,9 @@
1
1
  require 'schemata/common/msgtypebase'
2
2
 
3
3
  module Schemata
4
- module DEA
4
+ module Dea
5
5
  module StartRequest
6
6
  extend Schemata::MessageTypeBase
7
7
  end
8
8
  end
9
9
  end
10
-
11
- Dir[File.dirname(__FILE__) + '/start_request/*.rb'].each do |file|
12
- require file
13
- end
@@ -1,7 +1,7 @@
1
1
  require 'vcap/common'
2
2
 
3
3
  module Schemata
4
- module DEA
4
+ module Dea
5
5
  module StopRequest
6
6
  version 1 do
7
7
  include_preschemata
@@ -1,13 +1,9 @@
1
1
  require 'schemata/common/msgtypebase'
2
2
 
3
3
  module Schemata
4
- module DEA
4
+ module Dea
5
5
  module StopRequest
6
6
  extend Schemata::MessageTypeBase
7
7
  end
8
8
  end
9
9
  end
10
-
11
- Dir[File.dirname(__FILE__) + '/stop_request/*.rb'].each do |file|
12
- require file
13
- end
@@ -1,5 +1,5 @@
1
1
  module Schemata
2
- module DEA
2
+ module Dea
3
3
  module UpdateRequest
4
4
  version 1 do
5
5
  include_preschemata
@@ -1,13 +1,9 @@
1
1
  require 'schemata/common/msgtypebase'
2
2
 
3
3
  module Schemata
4
- module DEA
4
+ module Dea
5
5
  module UpdateRequest
6
6
  extend Schemata::MessageTypeBase
7
7
  end
8
8
  end
9
9
  end
10
-
11
- Dir[File.dirname(__FILE__) + '/update_request/*.rb'].each do |file|
12
- require file
13
- end
@@ -1,5 +1,5 @@
1
1
  module Schemata
2
- module DEA
3
- VERSION = "0.0.1.beta14"
2
+ module Dea
3
+ VERSION = "0.0.1.beta15"
4
4
  end
5
5
  end
data/lib/schemata/dea.rb CHANGED
@@ -1,64 +1,7 @@
1
- require 'schemata/dea/heartbeat_response'
2
- require 'schemata/dea/find_droplet_request'
3
- require 'schemata/dea/find_droplet_response'
4
- require 'schemata/dea/droplet_status_response'
5
- require 'schemata/dea/advertise_message'
6
- require 'schemata/dea/hello_message'
7
- require 'schemata/dea/dea_status_response'
8
- require 'schemata/dea/exit_message'
9
- require 'schemata/dea/discover_request'
10
- require 'schemata/dea/start_request'
11
- require 'schemata/dea/stop_request'
12
- require 'schemata/dea/update_request'
1
+ require 'schemata/common/componentbase'
13
2
 
14
3
  module Schemata
15
- module DEA
16
- def self.mock_heartbeat_response(version=HeartbeatResponse.current_version)
17
- HeartbeatResponse::const_get("V#{version}").mock
18
- end
19
-
20
- def self.mock_find_droplet_request(version=FindDropletRequest.current_version)
21
- FindDropletRequest::const_get("V#{version}").mock
22
- end
23
-
24
- def self.mock_find_droplet_response(version=FindDropletResponse.current_version)
25
- FindDropletResponse::const_get("V#{version}").mock
26
- end
27
-
28
- def self.mock_droplet_status_response(version=DropletStatusResponse.current_version)
29
- DropletStatusResponse::const_get("V#{version}").mock
30
- end
31
-
32
- def self.mock_advertise_message(version=AdvertiseMessage.current_version)
33
- AdvertiseMessage::const_get("V#{version}").mock
34
- end
35
-
36
- def self.mock_hello_message(version=HelloMessage.current_version)
37
- HelloMessage::const_get("V#{version}").mock
38
- end
39
-
40
- def self.mock_dea_status_response(version=DeaStatusResponse.current_version)
41
- DeaStatusResponse::const_get("V#{version}").mock
42
- end
43
-
44
- def self.mock_exit_message(version=ExitMessage.current_version)
45
- ExitMessage::const_get("V#{version}").mock
46
- end
47
-
48
- def self.mock_discover_request(version=DiscoverRequest.current_version)
49
- DiscoverRequest::const_get("V#{version}").mock
50
- end
51
-
52
- def self.mock_start_request(version=StartRequest.current_version)
53
- StartRequest::const_get("V#{version}").mock
54
- end
55
-
56
- def self.mock_stop_request(version=StopRequest.current_version)
57
- StopRequest::const_get("V#{version}").mock
58
- end
59
-
60
- def self.mock_update_request(version=UpdateRequest.current_version)
61
- UpdateRequest::const_get("V#{version}").mock
62
- end
4
+ module Dea
5
+ extend Schemata::ComponentBase
63
6
  end
64
7
  end
@@ -0,0 +1,23 @@
1
+ module Schemata
2
+ module Helpers
3
+ def self.decamelize(str)
4
+ words = []
5
+ curr_word = ""
6
+ 0.upto(str.length - 1) do |i|
7
+ ch = str[i]
8
+ if ch =~ /[A-Z]/
9
+ words.push(curr_word)
10
+ curr_word = ""
11
+ end
12
+ curr_word += ch
13
+ end
14
+ words.push(curr_word)
15
+ words.map! { |x| x.downcase }
16
+
17
+ # If the first letter is capitalized, then the first word here is empty
18
+ words.shift if words[0] == ""
19
+
20
+ words.join('_')
21
+ end
22
+ end
23
+ end
@@ -1,5 +1,5 @@
1
1
  module Schemata
2
- module HashCopyHelpers
2
+ module Helpers
3
3
  class CopyError < StandardError; end
4
4
 
5
5
  def self.deep_copy(node)
@@ -1,5 +1,5 @@
1
1
  module Schemata
2
- module HashCopyHelpers
2
+ module Helpers
3
3
 
4
4
  def self.stringify(node)
5
5
  case node