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.
- data/lib/schemata/common/componentbase.rb +42 -0
- data/lib/schemata/common/msgbase.rb +13 -11
- data/lib/schemata/common/msgtypebase.rb +20 -0
- data/lib/schemata/common/parsed_msg.rb +1 -1
- data/lib/schemata/dea/advertise_message/advertise_message_v1.rb +1 -1
- data/lib/schemata/dea/advertise_message.rb +1 -5
- data/lib/schemata/dea/dea_status_response/dea_status_response_v1.rb +1 -1
- data/lib/schemata/dea/dea_status_response.rb +1 -5
- data/lib/schemata/dea/discover_request/discover_request_v1.rb +1 -1
- data/lib/schemata/dea/discover_request.rb +1 -5
- data/lib/schemata/dea/droplet_status_response/droplet_status_response_v1.rb +1 -1
- data/lib/schemata/dea/droplet_status_response.rb +1 -5
- data/lib/schemata/dea/exit_message/exit_message_v1.rb +1 -1
- data/lib/schemata/dea/exit_message.rb +1 -5
- data/lib/schemata/dea/find_droplet_request/find_droplet_request_v1.rb +1 -1
- data/lib/schemata/dea/find_droplet_request.rb +1 -5
- data/lib/schemata/dea/find_droplet_response/find_droplet_response_v1.rb +1 -1
- data/lib/schemata/dea/find_droplet_response.rb +1 -5
- data/lib/schemata/dea/heartbeat_response/heartbeat_response_v1.rb +1 -1
- data/lib/schemata/dea/heartbeat_response.rb +1 -5
- data/lib/schemata/dea/hello_message/hello_message_v1.rb +1 -1
- data/lib/schemata/dea/hello_message.rb +1 -5
- data/lib/schemata/dea/start_request/start_request_v1.rb +5 -3
- data/lib/schemata/dea/start_request.rb +1 -5
- data/lib/schemata/dea/stop_request/stop_request_v1.rb +1 -1
- data/lib/schemata/dea/stop_request.rb +1 -5
- data/lib/schemata/dea/update_request/update_request_v1.rb +1 -1
- data/lib/schemata/dea/update_request.rb +1 -5
- data/lib/schemata/dea/version.rb +2 -2
- data/lib/schemata/dea.rb +3 -60
- data/lib/schemata/helpers/decamelize.rb +23 -0
- data/lib/schemata/helpers/hash_copy.rb +1 -1
- data/lib/schemata/helpers/stringify.rb +1 -1
- data/spec/{cloud_controller/cloud_controller_spec.rb → cloud_controller_spec.rb} +0 -0
- data/spec/common/helpers_spec.rb +16 -16
- data/spec/{dea/dea_spec.rb → dea_spec.rb} +1 -1
- data/spec/{health_manager/health_manager_spec.rb → health_manager_spec.rb} +0 -0
- data/spec/{router/router_spec.rb → router_spec.rb} +0 -0
- data/spec/{staging/staging_spec.rb → staging_spec.rb} +0 -0
- data/spec/support/component_helpers.rb +16 -2
- data/spec/support/helpers.rb +0 -20
- data/spec/support/message_helpers.rb +23 -19
- data/spec/support/message_type_helpers.rb +59 -55
- metadata +36 -80
- data/spec/cloud_controller/droplet_updated_message_spec.rb +0 -10
- data/spec/cloud_controller/hm_start_request_spec.rb +0 -11
- data/spec/cloud_controller/hm_stop_request_spec.rb +0 -12
- data/spec/dea/advertise_message_spec.rb +0 -10
- data/spec/dea/dea_status_response_spec.rb +0 -10
- data/spec/dea/discover_request_spec.rb +0 -10
- data/spec/dea/droplet_status_response_spec.rb +0 -10
- data/spec/dea/exit_message_spec.rb +0 -10
- data/spec/dea/find_droplet_request_spec.rb +0 -27
- data/spec/dea/find_droplet_response_spec.rb +0 -10
- data/spec/dea/heartbeat_response_spec.rb +0 -10
- data/spec/dea/hello_message_spec.rb +0 -10
- data/spec/dea/start_request_spec.rb +0 -10
- data/spec/dea/stop_request_spec.rb +0 -10
- data/spec/dea/update_request_spec.rb +0 -0
- data/spec/health_manager/health_request_spec.rb +0 -12
- data/spec/health_manager/health_response_spec.rb +0 -12
- data/spec/health_manager/status_crashed_response_spec.rb +0 -12
- data/spec/health_manager/status_flapping_response_spec.rb +0 -12
- data/spec/health_manager/status_request_spec.rb +0 -12
- data/spec/router/register_request_spec.rb +0 -10
- data/spec/router/start_message_spec.rb +0 -10
- 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::
|
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::
|
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::
|
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::
|
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::
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
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::
|
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::
|
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
|
@@ -1,13 +1,9 @@
|
|
1
1
|
require 'schemata/common/msgtypebase'
|
2
2
|
|
3
3
|
module Schemata
|
4
|
-
module
|
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,13 +1,9 @@
|
|
1
1
|
require 'schemata/common/msgtypebase'
|
2
2
|
|
3
3
|
module Schemata
|
4
|
-
module
|
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,13 +1,9 @@
|
|
1
1
|
require 'schemata/common/msgtypebase'
|
2
2
|
|
3
3
|
module Schemata
|
4
|
-
module
|
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
|
@@ -1,13 +1,9 @@
|
|
1
1
|
require 'schemata/common/msgtypebase'
|
2
2
|
|
3
3
|
module Schemata
|
4
|
-
module
|
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
|
@@ -1,13 +1,9 @@
|
|
1
1
|
require 'schemata/common/msgtypebase'
|
2
2
|
|
3
3
|
module Schemata
|
4
|
-
module
|
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
|
@@ -1,13 +1,9 @@
|
|
1
1
|
require "schemata/common/msgtypebase"
|
2
2
|
|
3
3
|
module Schemata
|
4
|
-
module
|
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
|
@@ -1,13 +1,9 @@
|
|
1
1
|
require "schemata/common/msgtypebase"
|
2
2
|
|
3
3
|
module Schemata
|
4
|
-
module
|
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
|
@@ -1,13 +1,9 @@
|
|
1
1
|
require 'schemata/common/msgtypebase'
|
2
2
|
|
3
3
|
module Schemata
|
4
|
-
module
|
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
|
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
|
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,13 +1,9 @@
|
|
1
1
|
require 'schemata/common/msgtypebase'
|
2
2
|
|
3
3
|
module Schemata
|
4
|
-
module
|
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
|
data/lib/schemata/dea/version.rb
CHANGED
data/lib/schemata/dea.rb
CHANGED
@@ -1,64 +1,7 @@
|
|
1
|
-
require 'schemata/
|
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
|
16
|
-
|
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
|
File without changes
|