kimchi 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/kimchi/version.rb +1 -1
  3. data/lib/wire.rb +191 -191
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d137d5b80943090bd73ee24bcb918b024d69c7ab
4
- data.tar.gz: 49d4a6f16a6d8770fb8f3f25525d7a31c8b32e0f
3
+ metadata.gz: ed4ce2cd8ae8b41a7ceff5385a3bdcf607fdd7dd
4
+ data.tar.gz: e9c5911977594b1bcd0a779d324c0fb1cf93e493
5
5
  SHA512:
6
- metadata.gz: 8dc89d50f3442960f2980667618a4b875e200195abf41d5e66b1dd1838c20cf3a7496a08f7a557353a791a9340e6d9a2016e16cd6493c9a43ed32714b3fc1525
7
- data.tar.gz: ed60fb60281291ea458c3cc801246c9991f1d1bfe9bdc6e3864a2d3ee2e706475b18e16d206389b1fdb9b2bee66d8afa7ff74ad7a71347141f0ceae4bde2bb10
6
+ metadata.gz: cec7e1d8250f6f6b71486b8f7256cdd1bca8517282b52bdebf25274d4456d85b6c197a7970478e04c3e89729e26950f87ade3c6941917828a23a204839b5bbb2
7
+ data.tar.gz: 8eac9cb81c5bbb88715b053fde52093fd85c5bc1220d84e6b970ff2fa6541d81cfb59c3ac00c158105a1af4cb061930f4e5ce4523d4a0e6779c007a780c40bbc
@@ -1,3 +1,3 @@
1
1
  module Kimchi
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
data/lib/wire.rb CHANGED
@@ -1,192 +1,192 @@
1
- require "rubygems"
2
- require "fiber"
3
- require "uuid"
4
- require "bunny"
5
- require "net/http"
6
-
7
- module Wire
8
-
9
- class Function
10
- def initialize(name, signature = nil, result_type = nil, native_type = nil)
11
- @name = name
12
- @signature = signature
13
- @result_type = result_type
14
- @native_type = native_type
15
- end
16
-
17
- # ignore this for any real service call, the http endpoint is evidently incapable of getting this from a header
18
- def service= service
19
- @service=service
20
- end
21
-
22
- # ignore this for any real service call, the http endpoint is evidently incapable of getting this from a header
23
- def version= version
24
- @version=version
25
- end
26
-
27
- def to_json
28
- "{\"endpoint\": \"#{@name}\"" + ((@signature == nil) ? "" : ", \"signature\": #{@signature}") + ((@result_type == nil) ? "" : ", \"resultType\": \"#{@result_type}\"") + ((@native_type == nil) ? "" : ", \"nativeType\": \"#{@native_type}\"") + ((@service == nil) ? "" : ", \"service\": \"#{@service}\"") + ((@version == nil) ? "" : ", \"version\": \"#{@version}\"") + "}"
29
- end
30
- end
31
-
32
- class InvocationSignal
33
- def initialize(function, arguments, contexts)
34
- @function = function
35
- @arguments = arguments
36
- @contexts = contexts
37
- end
38
-
39
- def function
40
- @function
41
- end
42
-
43
- def contexts= contexts
44
- @contexts=contexts
45
- end
46
-
47
- def contexts
48
- @contexts
49
- end
50
-
51
- def to_json
52
- "{\"address\": #{@function.to_json}, \"body\": #{@arguments.to_json}, \"contexts\": #{@contexts.to_json}}"
53
- end
54
- end
55
-
56
- class MessageCallback
57
- def initialize (message_hash, message_id, callback, timeout_seconds)
58
- @semaphore = Mutex.new
59
- @callback = callback
60
- @result = nil
61
-
62
- Thread.new do
63
- sleep(timeout_seconds)
64
- message_hash.delete(message_id)
65
- @semaphore.synchronize do
66
- if @result.nil?
67
- callback.timeout
68
- end
69
- end
70
- end
71
- end
72
-
73
- def set_result (result)
74
- @semaphore.synchronize do
75
- @result = result
76
- @callback.complete(@result)
77
- end
78
- end
79
- end
80
-
81
- class Message
82
-
83
- @result = nil
84
-
85
- def result
86
- while @result == nil
87
- sleep(0.1)
88
- end
89
-
90
- @result
91
- end
92
-
93
- def complete (result)
94
- @result = result
95
- end
96
-
97
- def timeout ()
98
- raise Timeout::Error.new
99
- end
100
- end
101
-
102
- class RabbitMQTransport
103
- def initialize (host, port)
104
- @connection = Bunny.new("amqp://#{host}:#{port}")
105
- @connection.start
106
-
107
- @semaphore = Mutex.new
108
-
109
- @uuid = UUID.new
110
- @caller_id = @uuid.generate
111
-
112
- @topic_hash = {}
113
- @message_hash = {}
114
- end
115
-
116
- def initialize_service (service_name)
117
- @semaphore.synchronize do
118
- topic = @topic_hash[service_name]
119
-
120
- if topic == nil
121
- request_channel = @connection.create_channel
122
- topic = request_channel.topic("#{service_name}.request")
123
-
124
- response_queue_name = @uuid.generate
125
- response_channel = @connection.create_channel
126
- response_exchange = response_channel.topic("#{service_name}.response")
127
- response_queue = response_channel.queue("#{response_queue_name}", {:durable => false, :exclusive => true, :auto_delete => true})
128
-
129
- response_queue.bind(response_exchange, :routing_key => "#{@caller_id}").subscribe do |delivery_info, metadata, payload|
130
- if (message_callback = @message_hash[metadata[:correlation_id]]) != nil
131
- result_body = JSON.parse(payload)
132
- message_callback.set_result(result_body)
133
- end
134
- end
135
- end
136
-
137
- return topic
138
- end
139
- end
140
-
141
- def transmit_in_only(service_name, version, invocation_signal)
142
- initialize_service(service_name).publish(invocation_signal.to_json, :routing_key => "#{version}.2", :headers => {"x-opt-callerId" => "#{@caller_id}"}, :content_type => "application/json", :message_id => "#{@uuid.generate}", :timestamp => Time.new.to_i)
143
- end
144
-
145
- def transmit(service_name, version, invocation_signal, timeout_seconds)
146
- message_id = "#{@uuid.generate}".freeze
147
- @message_hash[message_id] = MessageCallback.new(@message_hash, message_id, message = Message.new, timeout_seconds)
148
- initialize_service(service_name).publish(invocation_signal.to_json, :routing_key => "#{version}.2", :headers => {"x-opt-callerId" => "#{@caller_id}"}, :content_type => "application/json", :message_id => "#{message_id}", :timestamp => Time.new.to_i)
149
-
150
- message
151
- end
152
- end
153
-
154
- class HttpTransport
155
- def initialize (host, port)
156
- @host = host
157
- @port = port
158
- end
159
-
160
- def transmit (service_name, version, invocation_signal, timeout_seconds)
161
- message = Message.new
162
-
163
- begin
164
- uri = URI("#{@host}:#{@port}/api/message")
165
- headers = {"Content-Type" => "application/json"}
166
- http = Net::HTTP.new(uri.host, uri.port)
167
- http.read_timeout = timeout_seconds
168
-
169
- invocation_signal.function.service = service_name
170
- invocation_signal.function.version = version
171
-
172
- context_hash = {}
173
- invocation_signal.contexts.each { |context| context.each { |key, value| context_hash[key] = value } }
174
- invocation_signal.contexts = context_hash
175
-
176
- res = http.post(uri.path, invocation_signal.to_json, headers)
177
-
178
- case res
179
- when Net::HTTPSuccess
180
- response = JSON.parse res.body
181
- message.complete(response)
182
- else
183
- res.error!
184
- end
185
- rescue Timeout::Error
186
- message.timeout
187
- end
188
-
189
- message
190
- end
191
- end
1
+ require "rubygems"
2
+ require "fiber"
3
+ require "uuid"
4
+ require "bunny"
5
+ require "net/http"
6
+
7
+ module Wire
8
+
9
+ class Function
10
+ def initialize(name, signature = nil, result_type = nil, native_type = nil)
11
+ @name = name
12
+ @signature = signature
13
+ @result_type = result_type
14
+ @native_type = native_type
15
+ end
16
+
17
+ # ignore this for any real service call, the http endpoint is evidently incapable of getting this from a header
18
+ def service= service
19
+ @service=service
20
+ end
21
+
22
+ # ignore this for any real service call, the http endpoint is evidently incapable of getting this from a header
23
+ def version= version
24
+ @version=version
25
+ end
26
+
27
+ def to_json
28
+ "{\"endpoint\": \"#{@name}\"" + ((@signature == nil) ? "" : ", \"signature\": #{@signature}") + ((@result_type == nil) ? "" : ", \"resultType\": \"#{@result_type}\"") + ((@native_type == nil) ? "" : ", \"nativeType\": \"#{@native_type}\"") + ((@service == nil) ? "" : ", \"service\": \"#{@service}\"") + ((@version == nil) ? "" : ", \"version\": \"#{@version}\"") + "}"
29
+ end
30
+ end
31
+
32
+ class InvocationSignal
33
+ def initialize(function, arguments, contexts)
34
+ @function = function
35
+ @arguments = arguments
36
+ @contexts = contexts
37
+ end
38
+
39
+ def function
40
+ @function
41
+ end
42
+
43
+ def contexts= contexts
44
+ @contexts=contexts
45
+ end
46
+
47
+ def contexts
48
+ @contexts
49
+ end
50
+
51
+ def to_json
52
+ "{\"address\": #{@function.to_json}, \"body\": #{@arguments.to_json}, \"contexts\": #{@contexts.to_json}}"
53
+ end
54
+ end
55
+
56
+ class MessageCallback
57
+ def initialize (message_hash, message_id, callback, timeout_seconds)
58
+ @semaphore = Mutex.new
59
+ @callback = callback
60
+ @result = nil
61
+
62
+ Thread.new do
63
+ sleep(timeout_seconds)
64
+ message_hash.delete(message_id)
65
+ @semaphore.synchronize do
66
+ if @result.nil?
67
+ callback.timeout
68
+ end
69
+ end
70
+ end
71
+ end
72
+
73
+ def set_result (result)
74
+ @semaphore.synchronize do
75
+ @result = result
76
+ @callback.complete(@result)
77
+ end
78
+ end
79
+ end
80
+
81
+ class Message
82
+
83
+ @result = nil
84
+
85
+ def result
86
+ while @result == nil
87
+ sleep(0.1)
88
+ end
89
+
90
+ @result
91
+ end
92
+
93
+ def complete (result)
94
+ @result = result
95
+ end
96
+
97
+ def timeout ()
98
+ raise Timeout::Error.new
99
+ end
100
+ end
101
+
102
+ class RabbitMQTransport
103
+ def initialize (host, port)
104
+ @connection = Bunny.new("amqp://#{host}:#{port}")
105
+ @connection.start
106
+
107
+ @semaphore = Mutex.new
108
+
109
+ @uuid = UUID.new
110
+ @caller_id = @uuid.generate
111
+
112
+ @topic_hash = {}
113
+ @message_hash = {}
114
+ end
115
+
116
+ def initialize_service (service_name)
117
+ @semaphore.synchronize do
118
+ topic = @topic_hash[service_name]
119
+
120
+ if topic == nil
121
+ request_channel = @connection.create_channel
122
+ topic = request_channel.topic("#{service_name}.request")
123
+
124
+ response_queue_name = @uuid.generate
125
+ response_channel = @connection.create_channel
126
+ response_exchange = response_channel.topic("#{service_name}.response")
127
+ response_queue = response_channel.queue("#{response_queue_name}", {:durable => false, :exclusive => true, :auto_delete => true})
128
+
129
+ response_queue.bind(response_exchange, :routing_key => "#{@caller_id}").subscribe do |delivery_info, metadata, payload|
130
+ if (message_callback = @message_hash[metadata[:correlation_id]]) != nil
131
+ result_body = JSON.parse(payload)
132
+ message_callback.set_result(result_body)
133
+ end
134
+ end
135
+ end
136
+
137
+ return topic
138
+ end
139
+ end
140
+
141
+ def transmit_in_only(service_name, version, invocation_signal)
142
+ initialize_service(service_name).publish(invocation_signal.to_json, :routing_key => "#{version}.2", :headers => {"x-opt-callerId" => "#{@caller_id}"}, :content_type => "application/json", :message_id => "#{@uuid.generate}", :timestamp => Time.new.to_i)
143
+ end
144
+
145
+ def transmit(service_name, version, invocation_signal, timeout_seconds)
146
+ message_id = "#{@uuid.generate}".freeze
147
+ @message_hash[message_id] = MessageCallback.new(@message_hash, message_id, message = Message.new, timeout_seconds)
148
+ initialize_service(service_name).publish(invocation_signal.to_json, :routing_key => "#{version}.2", :headers => {"x-opt-callerId" => "#{@caller_id}"}, :content_type => "application/json", :message_id => "#{message_id}", :timestamp => Time.new.to_i)
149
+
150
+ message
151
+ end
152
+ end
153
+
154
+ class HttpTransport
155
+ def initialize (host, port)
156
+ @host = host
157
+ @port = port
158
+ end
159
+
160
+ def transmit (service_name, version, invocation_signal, timeout_seconds)
161
+ message = Message.new
162
+
163
+ begin
164
+ uri = URI("#{@host}:#{@port}/api/message")
165
+ headers = {"Content-Type" => "application/json"}
166
+ http = Net::HTTP.new(uri.host, uri.port)
167
+ http.read_timeout = timeout_seconds
168
+
169
+ invocation_signal.function.service = service_name
170
+ invocation_signal.function.version = version
171
+
172
+ context_hash = {}
173
+ invocation_signal.contexts.each { |context| context.each { |key, value| context_hash[key] = value } }
174
+ invocation_signal.contexts = context_hash
175
+
176
+ res = http.post(uri.path, invocation_signal.to_json, headers)
177
+
178
+ case res
179
+ when Net::HTTPSuccess
180
+ response = JSON.parse res.body
181
+ message.complete(response)
182
+ else
183
+ res.error!
184
+ end
185
+ rescue Timeout::Error
186
+ message.timeout
187
+ end
188
+
189
+ message
190
+ end
191
+ end
192
192
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kimchi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taylor Gautier
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-21 00:00:00.000000000 Z
12
+ date: 2013-11-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  version: '0'
104
104
  requirements: []
105
105
  rubyforge_project:
106
- rubygems_version: 2.1.9
106
+ rubygems_version: 2.0.0
107
107
  signing_key:
108
108
  specification_version: 4
109
109
  summary: Various frameworks and utilities to accelerate ICIX bdd tests