vcap_common 1.0.10 → 2.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/json_message.rb +98 -45
- data/lib/services/api.rb +1 -0
- data/lib/services/api/async_requests.rb +45 -1
- data/lib/services/api/clients/sds_client.rb +84 -0
- data/lib/services/api/clients/service_gateway_client.rb +150 -73
- data/lib/services/api/const.rb +1 -0
- data/lib/services/api/messages.rb +35 -21
- data/lib/services/api/multipart.rb +191 -0
- data/lib/vcap/component.rb +1 -1
- data/lib/vcap/config.rb +3 -4
- data/lib/vcap/sorted_set_utils.rb +42 -0
- data/lib/vcap/spec/forked_component/base.rb +8 -3
- metadata +118 -37
- data/lib/json_schema.rb +0 -84
- data/lib/vcap/json_schema.rb +0 -202
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vcap_common
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,56 +9,56 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-09-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: eventmachine
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0
|
21
|
+
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0
|
29
|
+
version: '0'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: thin
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
|
-
- -
|
35
|
+
- - ! '>='
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
37
|
+
version: '0'
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
|
-
- -
|
43
|
+
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
45
|
+
version: '0'
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: yajl-ruby
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
51
|
-
- -
|
51
|
+
- - ! '>='
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: 0
|
53
|
+
version: '0'
|
54
54
|
type: :runtime
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
none: false
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0
|
61
|
+
version: '0'
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
63
|
name: nats
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
requirements:
|
67
67
|
- - ~>
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: 0.4.
|
69
|
+
version: 0.4.24
|
70
70
|
type: :runtime
|
71
71
|
prerelease: false
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -74,7 +74,7 @@ dependencies:
|
|
74
74
|
requirements:
|
75
75
|
- - ~>
|
76
76
|
- !ruby/object:Gem::Version
|
77
|
-
version: 0.4.
|
77
|
+
version: 0.4.24
|
78
78
|
- !ruby/object:Gem::Dependency
|
79
79
|
name: posix-spawn
|
80
80
|
requirement: !ruby/object:Gem::Requirement
|
@@ -91,6 +91,86 @@ dependencies:
|
|
91
91
|
- - ~>
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: 0.3.6
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: membrane
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 0.0.2
|
102
|
+
type: :runtime
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 0.0.2
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: httpclient
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: em-http-request
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ~>
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: 1.0.0.beta3
|
134
|
+
type: :runtime
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ~>
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: 1.0.0.beta3
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: multipart-post
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ! '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
type: :runtime
|
151
|
+
prerelease: false
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
- !ruby/object:Gem::Dependency
|
159
|
+
name: mime-types
|
160
|
+
requirement: !ruby/object:Gem::Requirement
|
161
|
+
none: false
|
162
|
+
requirements:
|
163
|
+
- - ! '>='
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
type: :runtime
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
none: false
|
170
|
+
requirements:
|
171
|
+
- - ! '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
94
174
|
- !ruby/object:Gem::Dependency
|
95
175
|
name: rake
|
96
176
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,31 +194,32 @@ executables: []
|
|
114
194
|
extensions: []
|
115
195
|
extra_rdoc_files: []
|
116
196
|
files:
|
117
|
-
- lib/json_message.rb
|
118
|
-
- lib/json_schema.rb
|
119
|
-
- lib/services/api/async_requests.rb
|
120
|
-
- lib/services/api/clients/service_gateway_client.rb
|
121
|
-
- lib/services/api/const.rb
|
122
|
-
- lib/services/api/messages.rb
|
123
|
-
- lib/services/api/util.rb
|
124
|
-
- lib/services/api.rb
|
125
|
-
- lib/vcap/common.rb
|
126
197
|
- lib/vcap/component.rb
|
127
|
-
- lib/vcap/
|
128
|
-
- lib/vcap/
|
129
|
-
- lib/vcap/
|
130
|
-
- lib/vcap/priority_queue.rb
|
131
|
-
- lib/vcap/process_utils.rb
|
132
|
-
- lib/vcap/quota.rb
|
133
|
-
- lib/vcap/rolling_metric.rb
|
198
|
+
- lib/vcap/user_pools/user_pool.rb
|
199
|
+
- lib/vcap/user_pools/user_pool_util.rb
|
200
|
+
- lib/vcap/user_pools/user_ops.rb
|
134
201
|
- lib/vcap/spec/em.rb
|
202
|
+
- lib/vcap/spec/forked_component.rb
|
135
203
|
- lib/vcap/spec/forked_component/base.rb
|
136
204
|
- lib/vcap/spec/forked_component/nats_server.rb
|
137
|
-
- lib/vcap/
|
205
|
+
- lib/vcap/priority_queue.rb
|
206
|
+
- lib/vcap/common.rb
|
207
|
+
- lib/vcap/fiber_tracing.rb
|
138
208
|
- lib/vcap/subprocess.rb
|
139
|
-
- lib/vcap/
|
140
|
-
- lib/vcap/
|
141
|
-
- lib/vcap/
|
209
|
+
- lib/vcap/quota.rb
|
210
|
+
- lib/vcap/process_utils.rb
|
211
|
+
- lib/vcap/rolling_metric.rb
|
212
|
+
- lib/vcap/config.rb
|
213
|
+
- lib/vcap/sorted_set_utils.rb
|
214
|
+
- lib/json_message.rb
|
215
|
+
- lib/services/api.rb
|
216
|
+
- lib/services/api/multipart.rb
|
217
|
+
- lib/services/api/util.rb
|
218
|
+
- lib/services/api/const.rb
|
219
|
+
- lib/services/api/async_requests.rb
|
220
|
+
- lib/services/api/messages.rb
|
221
|
+
- lib/services/api/clients/sds_client.rb
|
222
|
+
- lib/services/api/clients/service_gateway_client.rb
|
142
223
|
homepage: http://github.com/vmware-ac/core
|
143
224
|
licenses: []
|
144
225
|
post_install_message:
|
@@ -159,7 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
240
|
version: '0'
|
160
241
|
requirements: []
|
161
242
|
rubyforge_project:
|
162
|
-
rubygems_version: 1.8.
|
243
|
+
rubygems_version: 1.8.24
|
163
244
|
signing_key:
|
164
245
|
specification_version: 3
|
165
246
|
summary: vcap common
|
data/lib/json_schema.rb
DELETED
@@ -1,84 +0,0 @@
|
|
1
|
-
# Copyright (c) 2009-2011 VMware, Inc.
|
2
|
-
# This class provides dead simple declarative validation for decoded json using
|
3
|
-
# a fairly intuitive DSL like syntax.
|
4
|
-
#
|
5
|
-
# For example, the following is a sample schema that exercises all functionality
|
6
|
-
#
|
7
|
-
# {'foo' => [String], # 'foo' must be a list of strings
|
8
|
-
# 'bar' => {'baz' => Fixnum, # 'bar' must be a hash where
|
9
|
-
# 'jaz' => /foo/, # 'baz' is a Fixnum, and
|
10
|
-
# } # 'jaz' matches the regex /foo/
|
11
|
-
# }
|
12
|
-
#
|
13
|
-
class JsonSchema
|
14
|
-
WILDCARD = Object
|
15
|
-
|
16
|
-
# TODO(mjp): validate that schema is syntatically correct
|
17
|
-
|
18
|
-
def initialize(schema)
|
19
|
-
@schema = schema
|
20
|
-
end
|
21
|
-
|
22
|
-
def validate(json)
|
23
|
-
_validate(json, @schema)
|
24
|
-
end
|
25
|
-
|
26
|
-
protected
|
27
|
-
|
28
|
-
def _validate(json, schema)
|
29
|
-
case schema
|
30
|
-
when Class
|
31
|
-
# Terminal case, type check
|
32
|
-
klass = json.class
|
33
|
-
if json.is_a? schema
|
34
|
-
nil
|
35
|
-
else
|
36
|
-
"Type mismatch (expected #{schema}, got #{klass})"
|
37
|
-
end
|
38
|
-
|
39
|
-
when Hash
|
40
|
-
# Recursive case, check for required params, recursively check them against the supplied schema
|
41
|
-
missing_keys = schema.keys.select {|k| !json.has_key?(k)} if json.is_a? Hash
|
42
|
-
|
43
|
-
if !(json.is_a? Hash)
|
44
|
-
"Type mismatch (expected hash, got #{json.class})"
|
45
|
-
elsif missing_keys.length > 0
|
46
|
-
"Missing params: '#{missing_keys.join(', ')}'"
|
47
|
-
else
|
48
|
-
errs = nil
|
49
|
-
schema.each_key do |k|
|
50
|
-
sub_errs = _validate(json[k], schema[k])
|
51
|
-
if sub_errs
|
52
|
-
errs ||= {}
|
53
|
-
errs[k] = sub_errs
|
54
|
-
end
|
55
|
-
end
|
56
|
-
errs
|
57
|
-
end
|
58
|
-
|
59
|
-
when Array
|
60
|
-
# Recursive case, check that array isn't empty, recursively check array against supplied schema
|
61
|
-
if !(json.is_a? Array)
|
62
|
-
"Type mismatch (expected array, got #{json.class}"
|
63
|
-
else
|
64
|
-
errs = nil
|
65
|
-
json.each do |v|
|
66
|
-
errs = _validate(v, schema[0])
|
67
|
-
break if errs
|
68
|
-
end
|
69
|
-
errs
|
70
|
-
end
|
71
|
-
|
72
|
-
when Regexp
|
73
|
-
if schema.match(json)
|
74
|
-
nil
|
75
|
-
else
|
76
|
-
"Invalid value (doesn't match '#{schema.source})"
|
77
|
-
end
|
78
|
-
|
79
|
-
else
|
80
|
-
# Terminal case, value check
|
81
|
-
"Value mismatch (expected '#{schema}', got #{json})" unless json == schema
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
data/lib/vcap/json_schema.rb
DELETED
@@ -1,202 +0,0 @@
|
|
1
|
-
# Copyright (c) 2009-2011 VMware, Inc.
|
2
|
-
|
3
|
-
# This provides very basic support for creating declarative validators
|
4
|
-
# for decoded json. Useful for validating things like configs or
|
5
|
-
# messages that are published via NATS.
|
6
|
-
#
|
7
|
-
# Basic usage:
|
8
|
-
#
|
9
|
-
# schema = VCAP::JsonSchema.build do
|
10
|
-
# { :foo => [String],
|
11
|
-
# :bar => {:baz => Integer},
|
12
|
-
# optional(:jaz) => Float,
|
13
|
-
# }
|
14
|
-
# end
|
15
|
-
#
|
16
|
-
# Fails:
|
17
|
-
#
|
18
|
-
# schema.validate({
|
19
|
-
# 'foo' => ['bar', 5],
|
20
|
-
# 'bar' => {'baz' => 7},
|
21
|
-
# })
|
22
|
-
#
|
23
|
-
# Succeeds:
|
24
|
-
#
|
25
|
-
# schema.validate({
|
26
|
-
# 'foo' => ['bar', 'baz'],
|
27
|
-
# 'bar' => {'baz' => 7},
|
28
|
-
# })
|
29
|
-
#
|
30
|
-
#
|
31
|
-
module VCAP
|
32
|
-
module JsonSchema
|
33
|
-
|
34
|
-
class SyntaxError < StandardError; end
|
35
|
-
class ValidationError < StandardError
|
36
|
-
attr_accessor :message
|
37
|
-
def initialize(msg)
|
38
|
-
@message = msg
|
39
|
-
end
|
40
|
-
|
41
|
-
def to_s
|
42
|
-
@message
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
class ValueError < ValidationError; end
|
47
|
-
class TypeError < ValidationError; end
|
48
|
-
class MissingKeyError < ValidationError; end
|
49
|
-
|
50
|
-
# Defines an interface that all schemas must implement
|
51
|
-
class BaseSchema
|
52
|
-
# Verfies that val conforms to the schema being validated
|
53
|
-
# Throws exceptions derived from ValidationError upon schema violations
|
54
|
-
#
|
55
|
-
# @param Object val An object decoded from json
|
56
|
-
#
|
57
|
-
# @return nil
|
58
|
-
def validate(dec_json)
|
59
|
-
raise NotImplementedError.new("You must implement validate")
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
class BoolSchema < BaseSchema
|
64
|
-
def validate(dec_json)
|
65
|
-
unless dec_json.kind_of?(TrueClass) || dec_json.kind_of?(FalseClass)
|
66
|
-
raise TypeError, "Expected instance of TrueClass or FalseClass, got #{dec_json.class}"
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
# Checks that supplied value is an instance of a given class
|
72
|
-
class TypeSchema < BaseSchema
|
73
|
-
def initialize(klass)
|
74
|
-
raise ArgumentError, "You must supply a class #{klass} given" unless klass.kind_of?(Class)
|
75
|
-
@klass = klass
|
76
|
-
end
|
77
|
-
|
78
|
-
def validate(dec_json)
|
79
|
-
raise TypeError, "Expected instance of #{@klass}, got #{dec_json.class}" unless dec_json.kind_of?(@klass)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
# Checks that supplied value is an array, and each value in the array validates
|
84
|
-
class ArraySchema < BaseSchema
|
85
|
-
attr_accessor :item_schema
|
86
|
-
|
87
|
-
def initialize(schema)
|
88
|
-
raise ArgumentError, "You must supply a schema, #{schema.class} given" unless schema.kind_of?(BaseSchema)
|
89
|
-
@item_schema = schema
|
90
|
-
end
|
91
|
-
|
92
|
-
def validate(dec_json)
|
93
|
-
raise TypeError, "Expected instance of Array, #{dec_json.class} given" unless dec_json.kind_of?(Array)
|
94
|
-
for v in dec_json
|
95
|
-
@item_schema.validate(v)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
# Check that required keys are present, and that they validate
|
101
|
-
class HashSchema < BaseSchema
|
102
|
-
class Field
|
103
|
-
attr_reader :name, :schema
|
104
|
-
attr_accessor :optional
|
105
|
-
|
106
|
-
def initialize(name, schema, optional=false)
|
107
|
-
raise ArgumentError, "Schema must be an instance of a schema, #{schema.class} given #{schema.inspect}" unless schema.kind_of?(BaseSchema)
|
108
|
-
@name = name
|
109
|
-
@schema = schema
|
110
|
-
@optional = optional
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
def initialize(kvs={})
|
115
|
-
raise ArgumentError, "Expected Hash, #{kvs.class} given" unless kvs.is_a?(Hash)
|
116
|
-
# Convert symbols to strings. Validation will be performed against decoded json, which will have
|
117
|
-
# string keys.
|
118
|
-
@fields = {}
|
119
|
-
for k, v in kvs
|
120
|
-
raise ArgumentError, "Expected schema for key #{k}, got #{v.class}" unless v.kind_of?(BaseSchema)
|
121
|
-
k_s = k.to_s
|
122
|
-
@fields[k_s] = Field.new(k_s, v, false)
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
def required(name, schema)
|
127
|
-
name_s = name.to_s
|
128
|
-
@fields[name_s] = Field.new(name_s, schema, false)
|
129
|
-
end
|
130
|
-
|
131
|
-
def optional(name, schema)
|
132
|
-
name_s = name.to_s
|
133
|
-
@fields[name_s] = Field.new(name_s, schema, true)
|
134
|
-
end
|
135
|
-
|
136
|
-
def validate(dec_json)
|
137
|
-
raise TypeError, "Expected instance of Hash, got instance of #{dec_json.class}" unless dec_json.kind_of?(Hash)
|
138
|
-
|
139
|
-
missing_keys = []
|
140
|
-
for k in @fields.keys
|
141
|
-
missing_keys << k unless dec_json.has_key?(k) || @fields[k].optional
|
142
|
-
end
|
143
|
-
raise MissingKeyError, "Missing keys: #{missing_keys.join(', ')}" unless missing_keys.empty?
|
144
|
-
|
145
|
-
for k, f in @fields
|
146
|
-
next if f.optional && !dec_json.has_key?(k)
|
147
|
-
begin
|
148
|
-
f.schema.validate(dec_json[k])
|
149
|
-
rescue ValidationError => ve
|
150
|
-
ve.message = "'#{k}' => " + ve.message
|
151
|
-
raise ve
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
class << self
|
158
|
-
class OptionalKeyMarker
|
159
|
-
attr_reader :name
|
160
|
-
def initialize(name)
|
161
|
-
@name = name
|
162
|
-
end
|
163
|
-
|
164
|
-
def to_s
|
165
|
-
@name.to_s
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
def optional(key)
|
170
|
-
OptionalKeyMarker.new(key)
|
171
|
-
end
|
172
|
-
|
173
|
-
def build(&blk)
|
174
|
-
schema_def = instance_eval(&blk)
|
175
|
-
parse(schema_def)
|
176
|
-
end
|
177
|
-
|
178
|
-
def parse(schema_def)
|
179
|
-
case schema_def
|
180
|
-
when VCAP::JsonSchema::BaseSchema
|
181
|
-
schema_def
|
182
|
-
when Hash
|
183
|
-
schema = VCAP::JsonSchema::HashSchema.new
|
184
|
-
for k, v in schema_def
|
185
|
-
sym = k.kind_of?(OptionalKeyMarker) ? :optional : :required
|
186
|
-
schema.send(sym, k, parse(v))
|
187
|
-
end
|
188
|
-
schema
|
189
|
-
when Array
|
190
|
-
raise SyntaxError, "Schema definition for an array must have exactly 1 element" unless schema_def.size == 1
|
191
|
-
item_schema = parse(schema_def[0])
|
192
|
-
VCAP::JsonSchema::ArraySchema.new(item_schema)
|
193
|
-
when Class
|
194
|
-
VCAP::JsonSchema::TypeSchema.new(schema_def)
|
195
|
-
else
|
196
|
-
raise SyntaxError, "Don't know what to do with class #{schema_def.class}"
|
197
|
-
end
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
end # VCAP::JsonSchema
|
202
|
-
end # VCAP
|