schema_registry 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +24 -0
- data/Makefile +51 -0
- data/Rakefile +8 -0
- data/lib/schema_registry/client.rb +22 -6
- data/lib/schema_registry/version.rb +1 -1
- data/log/.gitignore +2 -0
- data/test/functional/schema_registry_test.rb +4 -6
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58117d0b752d254049962f942bdc029e51d95119
|
4
|
+
data.tar.gz: 7d101a19c3912c71484834b6ff1f02492349baa6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e087a0cd8bb28d9f56c69c02975c5fc20bab199f118ad653c9475438cd4528d83725252d26829eb2f09b9ce6cf1489120a4a5d71d9234775b695f104faf1138
|
7
|
+
data.tar.gz: b2c94029b386207e910fccb5d0759142dc6325be39b3e79ea551ddb7f016e5bd60fefb9aa252a80eeafe5513d5a86fa013223a2bf7299406413b024e7041b419
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
language: ruby
|
2
|
+
sudo: false
|
3
|
+
|
4
|
+
rvm:
|
5
|
+
- "2.0"
|
6
|
+
- "2.1"
|
7
|
+
- "2.2"
|
8
|
+
|
9
|
+
env:
|
10
|
+
global:
|
11
|
+
SCHEMA_REGISTRY_URL: "http://localhost:8081"
|
12
|
+
|
13
|
+
before_script:
|
14
|
+
- make confluent/start
|
15
|
+
|
16
|
+
after_script:
|
17
|
+
- make confluent/stop
|
18
|
+
|
19
|
+
before_cache:
|
20
|
+
- rm -rf confluent/logs
|
21
|
+
|
22
|
+
cache:
|
23
|
+
directories:
|
24
|
+
- confluent
|
data/Makefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
.PHONY: confluent/kafka/* confluent/zookeeper/* confluent/registry/* confluent/start confluent/stop
|
2
|
+
|
3
|
+
# Confluent platform tasks
|
4
|
+
|
5
|
+
confluent/start: confluent/rest/start
|
6
|
+
|
7
|
+
confluent/stop: confluent/rest/stop confluent/registry/stop confluent/kafka/stop confluent/zookeeper/stop
|
8
|
+
|
9
|
+
# Download & extract tasks
|
10
|
+
|
11
|
+
confluent/confluent.tgz:
|
12
|
+
mkdir -p confluent && wget http://packages.confluent.io/archive/1.0/confluent-1.0-2.10.4.tar.gz -O confluent/confluent.tgz
|
13
|
+
|
14
|
+
confluent/EXTRACTED: confluent/confluent.tgz
|
15
|
+
tar xzf confluent/confluent.tgz -C confluent --strip-components 1 && touch confluent/EXTRACTED
|
16
|
+
|
17
|
+
# Zookeeper tasks
|
18
|
+
|
19
|
+
confluent/zookeeper/start: confluent/EXTRACTED
|
20
|
+
nohup confluent/bin/zookeeper-server-start confluent/etc/kafka/zookeeper.properties 2> log/zookeeper.err > log/zookeeper.out < /dev/null &
|
21
|
+
while ! nc localhost 2181 </dev/null; do echo "Waiting for zookeeper..."; sleep 1; done
|
22
|
+
|
23
|
+
confluent/zookeeper/stop: confluent/EXTRACTED
|
24
|
+
confluent/bin/zookeeper-server-stop
|
25
|
+
|
26
|
+
# Kafka tasks
|
27
|
+
|
28
|
+
confluent/kafka/start: confluent/zookeeper/start confluent/EXTRACTED
|
29
|
+
nohup confluent/bin/kafka-server-start confluent/etc/kafka/server.properties 2> log/kafka.err > log/kafka.out < /dev/null &
|
30
|
+
while ! nc localhost 9092 </dev/null; do echo "Waiting for Kafka..."; sleep 1; done
|
31
|
+
|
32
|
+
confluent/kafka/stop: confluent/EXTRACTED
|
33
|
+
confluent/bin/kafka-server-stop
|
34
|
+
|
35
|
+
# schema-registry tasks
|
36
|
+
|
37
|
+
confluent/registry/start: confluent/kafka/start confluent/EXTRACTED
|
38
|
+
nohup confluent/bin/schema-registry-start confluent/etc/schema-registry/schema-registry.properties 2> log/schema-registry.err > log/schema-registry.out < /dev/null &
|
39
|
+
while ! nc localhost 8081 </dev/null; do echo "Waiting for schema registry..."; sleep 1; done
|
40
|
+
|
41
|
+
confluent/registry/stop: confluent/EXTRACTED
|
42
|
+
confluent/bin/kafka-server-stop
|
43
|
+
|
44
|
+
# REST proxy tasks
|
45
|
+
|
46
|
+
confluent/rest/start: confluent/registry/start confluent/EXTRACTED
|
47
|
+
nohup confluent/bin/kafka-rest-start confluent/etc/kafka-rest/kafka-rest.properties 2> log/kafka-rest.err > log/kafka-rest.out < /dev/null &
|
48
|
+
while ! nc localhost 8082 </dev/null; do echo "Waiting for REST proxy..."; sleep 1; done
|
49
|
+
|
50
|
+
confluent/rest/stop: confluent/EXTRACTED
|
51
|
+
confluent/bin/kafka-rest-stop
|
data/Rakefile
CHANGED
@@ -7,10 +7,12 @@ module SchemaRegistry
|
|
7
7
|
|
8
8
|
def initialize(code, message)
|
9
9
|
@code = code
|
10
|
-
super(message)
|
10
|
+
super("#{message} (error code #{code})")
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
+
InvalidResponse = Class.new(SchemaRegistry::Error)
|
15
|
+
|
14
16
|
RESPONSE_ERROR_CODES = {
|
15
17
|
40401 => (SubjectNotFound = Class.new(SchemaRegistry::ResponseError)),
|
16
18
|
40402 => (VersionNotFound = Class.new(SchemaRegistry::ResponseError)),
|
@@ -19,6 +21,7 @@ module SchemaRegistry
|
|
19
21
|
42202 => (InvalidVersion = Class.new(SchemaRegistry::ResponseError)),
|
20
22
|
42203 => (InvalidCompatibilityLevel = Class.new(SchemaRegistry::ResponseError)),
|
21
23
|
409 => (IncompatibleAvroSchema = Class.new(SchemaRegistry::ResponseError)),
|
24
|
+
403 => (UnauthorizedRequest = Class.new(SchemaRegistry::ResponseError)),
|
22
25
|
}
|
23
26
|
|
24
27
|
class Client
|
@@ -69,12 +72,25 @@ module SchemaRegistry
|
|
69
72
|
request.body = JSON.dump(body)
|
70
73
|
end
|
71
74
|
|
72
|
-
response = http.request(request)
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
75
|
+
case response = http.request(request)
|
76
|
+
when Net::HTTPSuccess
|
77
|
+
begin
|
78
|
+
JSON.parse(response.body)
|
79
|
+
rescue JSON::ParserError => e
|
80
|
+
raise SchemaRegistry::InvalidResponse, "Invalid JSON in response: #{e.message}"
|
81
|
+
end
|
82
|
+
|
83
|
+
when Net::HTTPForbidden
|
84
|
+
message = username.nil? ? "Unauthorized" : "User `#{username}` failed to authenticate"
|
85
|
+
raise SchemaRegistry::UnauthorizedRequest.new(response.code.to_i, message)
|
86
|
+
|
77
87
|
else
|
88
|
+
response = begin
|
89
|
+
JSON.parse(response.body)
|
90
|
+
rescue JSON::ParserError => e
|
91
|
+
raise SchemaRegistry::InvalidResponse, "Invalid JSON in response: #{e.message}"
|
92
|
+
end
|
93
|
+
|
78
94
|
error_class = RESPONSE_ERROR_CODES[response_data['error_code']] || SchemaRegistry::ResponseError
|
79
95
|
raise error_class.new(response_data['error_code'], response_data['message'])
|
80
96
|
end
|
data/log/.gitignore
ADDED
@@ -3,16 +3,14 @@ require 'test_helper'
|
|
3
3
|
class SchemaRegistryTest < Minitest::Test
|
4
4
|
|
5
5
|
def setup
|
6
|
-
|
7
|
-
@client = SchemaRegistry::Client.new(
|
6
|
+
registry_url = ENV['SCHEMA_REGISTRY_URL'] || "http://localhost:8081"
|
7
|
+
@client = SchemaRegistry::Client.new(registry_url)
|
8
8
|
end
|
9
9
|
|
10
10
|
def test_global_compatibility_level
|
11
11
|
old_level = @client.default_compatibility_level
|
12
|
-
assert_equal SchemaRegistry::Compatibility::BACKWARD, old_level
|
13
12
|
|
14
13
|
@client.default_compatibility_level = SchemaRegistry::Compatibility::FULL
|
15
|
-
|
16
14
|
current_level = @client.default_compatibility_level
|
17
15
|
assert_equal current_level, SchemaRegistry::Compatibility::FULL
|
18
16
|
ensure
|
@@ -23,14 +21,14 @@ class SchemaRegistryTest < Minitest::Test
|
|
23
21
|
schema = schema_fixture('test', 1)
|
24
22
|
|
25
23
|
subject = @client.subject('test.schema_registry')
|
26
|
-
schema_id = subject.
|
24
|
+
schema_id = subject.register_schema(schema)
|
27
25
|
assert schema_id > 0
|
28
26
|
|
29
27
|
assert_equal ['test.schema_registry'], @client.subjects.map(&:name)
|
30
28
|
|
31
29
|
registered_schema = @client.schema(schema_id)
|
32
30
|
schema_info = subject.verify_schema(schema)
|
33
|
-
assert_equal schema_id, schema_info
|
31
|
+
assert_equal schema_id, schema_info.id
|
34
32
|
|
35
33
|
assert_equal Avro::Schema.parse(schema), Avro::Schema.parse(registered_schema)
|
36
34
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schema_registry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Willem van Bergen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -76,14 +76,17 @@ extensions: []
|
|
76
76
|
extra_rdoc_files: []
|
77
77
|
files:
|
78
78
|
- .gitignore
|
79
|
+
- .travis.yml
|
79
80
|
- Gemfile
|
80
81
|
- LICENSE.txt
|
82
|
+
- Makefile
|
81
83
|
- README.md
|
82
84
|
- Rakefile
|
83
85
|
- lib/schema_registry.rb
|
84
86
|
- lib/schema_registry/client.rb
|
85
87
|
- lib/schema_registry/subject.rb
|
86
88
|
- lib/schema_registry/version.rb
|
89
|
+
- log/.gitignore
|
87
90
|
- schema_registry.gemspec
|
88
91
|
- test/fixtures/schemas/test-v1.avsc
|
89
92
|
- test/functional/schema_registry_test.rb
|