ibm-bluemix-service_discovery 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0fbba1e59deb4c85155c932c5c1bdef09b177e87
|
4
|
+
data.tar.gz: cc598b0b48e1831c25467699aa50377bf2bb0f4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a4f2b919fd8244824f2fec320e1ea2a4b28ca211f7023b9bfb5abfb5f18bcf55ee9f60f9fc3c5de974b901ae6349e3234c2aca0c4b4f8c98617cc2f42b834e9
|
7
|
+
data.tar.gz: d4a73e7ad3c633a361de1bc2cfbcb96c287a9f87c7f12ac2ca4d3f0e6c37424ed10f5b44e16d06dca23bca381d510aa8088ae8c1e698a3233ab83fe5fbc9f3c1
|
@@ -27,6 +27,8 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
28
|
spec.require_paths = ["lib"]
|
29
29
|
|
30
|
+
spec.required_ruby_version = '>= 1.9.3'
|
31
|
+
|
30
32
|
spec.add_dependency "unirest", "~> 1.1"
|
31
33
|
|
32
34
|
spec.add_development_dependency "bundler", "~> 1.11"
|
@@ -18,6 +18,8 @@ module IBM
|
|
18
18
|
# URL for the production Bluemix Service Registry endpoint
|
19
19
|
SERVICE_REGISTRY_ENDPOINT = "https://servicediscovery.ng.bluemix.net/api/v1/instances"
|
20
20
|
|
21
|
+
private_constant :SERVICE_DISCOVERY_ENDPOINT, :SERVICE_REGISTRY_ENDPOINT
|
22
|
+
|
21
23
|
# cache of registered services
|
22
24
|
@@services = {}
|
23
25
|
|
@@ -26,8 +28,14 @@ module IBM
|
|
26
28
|
|
27
29
|
# dummy logger that can be overridden
|
28
30
|
class << self
|
31
|
+
# logger attribute that can be overridden
|
29
32
|
attr_writer :logger
|
30
33
|
|
34
|
+
# Logger function that should be overridden.
|
35
|
+
#
|
36
|
+
# @example
|
37
|
+
# logger.debug 'this is a debug message'
|
38
|
+
#
|
31
39
|
def logger
|
32
40
|
@logger ||= Logger.new($stdout).tap do |log|
|
33
41
|
log.progname = self.name
|
@@ -37,11 +45,11 @@ module IBM
|
|
37
45
|
|
38
46
|
# Create a new ServiceDiscovery instance.
|
39
47
|
#
|
40
|
-
#
|
41
|
-
#
|
48
|
+
# @example
|
49
|
+
# sd = ServiceDiscovery.new('token...')
|
50
|
+
#
|
51
|
+
# @param auth_token [String] Valid `auth_token` from the IBM Bluemix Service Discovery service
|
42
52
|
#
|
43
|
-
# ===Arguments
|
44
|
-
# [auth_token] (String) Valid `auth_token` from the IBM Bluemix Service Discovery service
|
45
53
|
def initialize(auth_token)
|
46
54
|
@auth_token = auth_token
|
47
55
|
|
@@ -55,24 +63,17 @@ module IBM
|
|
55
63
|
|
56
64
|
# Register a service with Service Discovery
|
57
65
|
#
|
58
|
-
#
|
59
|
-
#
|
66
|
+
# @example
|
67
|
+
# sd = ServiceDiscovery.new('token...')
|
60
68
|
# => sd.register('sample_service', '192.168.1.100:8080', { ttl: 60, heartbeat: true }, {})
|
61
69
|
#
|
62
|
-
#
|
63
|
-
# [
|
64
|
-
# [
|
65
|
-
# [
|
66
|
-
# [
|
67
|
-
#
|
68
|
-
#
|
69
|
-
# [heartbeat] (Boolean) Enable or disable automated heartbeat for the service
|
70
|
-
# [ttl] (Integer) Expire the service after this many seconds if a heartbeat has not been received. Hearbeat is automatically set to 30% of this value
|
71
|
-
#
|
72
|
-
# ===Returns
|
73
|
-
# resulting payload from the call to Service Discovery
|
74
|
-
#
|
75
|
-
# ===Raises
|
70
|
+
# @param service_name [String] The name of the microservice
|
71
|
+
# @param host [String] The host and port where the microservice can be reached at
|
72
|
+
# @param options [Hash] Options to customize service discovery instance (see below)
|
73
|
+
# @option options [Boolean] :heartbeat Enable or disable automated heartbeat for the service
|
74
|
+
# @option options [Integer] :ttl Expire the service after this many seconds if a heartbeat has not been received. Hearbeat is automatically set to 30% of this value
|
75
|
+
# @param meta [Hash] Metadata to store with the service registration
|
76
|
+
# @return [Hash] Resulting payload from the call to Service Discovery
|
76
77
|
#
|
77
78
|
def register(service_name, host, options = {}, meta = {})
|
78
79
|
|
@@ -134,16 +135,11 @@ module IBM
|
|
134
135
|
|
135
136
|
# Send a heartbeat request to indicate the service is still alive and well
|
136
137
|
#
|
137
|
-
#
|
138
|
-
#
|
139
|
-
#
|
140
|
-
# ===Arguments
|
141
|
-
# [service_name] (String) The name of the microservice
|
138
|
+
# @example
|
139
|
+
# sd.renew('sample_service')
|
142
140
|
#
|
143
|
-
#
|
144
|
-
#
|
145
|
-
#
|
146
|
-
# ===Raises
|
141
|
+
# @param service_name [String] The name of the microservice
|
142
|
+
# @return [Boolean] `true` if the service was renewed, `false` otherwise
|
147
143
|
#
|
148
144
|
def renew(service_name)
|
149
145
|
|
@@ -175,17 +171,12 @@ module IBM
|
|
175
171
|
# Set-up a separate Thread to send continuous heartbeats (renew) calls to
|
176
172
|
# indicate the service is alive.
|
177
173
|
#
|
178
|
-
#
|
179
|
-
#
|
180
|
-
#
|
181
|
-
# ===Arguments
|
182
|
-
# [service_name] (String) The name of the microservice
|
183
|
-
# [interval] (Integer) The number of seconds between heartbeats
|
184
|
-
#
|
185
|
-
# ===Returns
|
186
|
-
# (Boolean) `true` if the heartbeat thread was started, `false` otherwise
|
174
|
+
# @example
|
175
|
+
# sd.heartbeat('sample_service', 45)
|
187
176
|
#
|
188
|
-
#
|
177
|
+
# @param service_name [String] The name of the microservice
|
178
|
+
# @param interval [Integer] The number of seconds between heartbeats
|
179
|
+
# @return [Boolean] `true` if the heartbeat thread was started, `false` otherwise
|
189
180
|
#
|
190
181
|
def heartbeat(service_name, interval=60)
|
191
182
|
|
@@ -211,16 +202,11 @@ module IBM
|
|
211
202
|
|
212
203
|
# Stops a previously established heartbeat Thread
|
213
204
|
#
|
214
|
-
#
|
215
|
-
#
|
216
|
-
#
|
217
|
-
# ===Arguments
|
218
|
-
# [service_name] (String) The name of the microservice
|
219
|
-
#
|
220
|
-
# ===Returns
|
221
|
-
# (Boolean) `true` if the heartbeat thread was stopped, `false` otherwise
|
205
|
+
# @example
|
206
|
+
# sd.unheartbeat('sample_service')
|
222
207
|
#
|
223
|
-
#
|
208
|
+
# @param service_name [String] The name of the microservice
|
209
|
+
# @return [Boolean] `true` if the heartbeat thread was stopped, `false` otherwise
|
224
210
|
#
|
225
211
|
def unheartbeat(service_name)
|
226
212
|
Thread.kill @@heartbeats[service_name]
|
@@ -228,16 +214,11 @@ module IBM
|
|
228
214
|
|
229
215
|
# Deletes a service entry from Service Discovery
|
230
216
|
#
|
231
|
-
#
|
232
|
-
#
|
217
|
+
# @example
|
218
|
+
# sd.delete('sample_service')
|
233
219
|
#
|
234
|
-
#
|
235
|
-
# [
|
236
|
-
#
|
237
|
-
# ===Returns
|
238
|
-
# (Boolean) `true` if the service was removed, `false` otherwise
|
239
|
-
#
|
240
|
-
# ===Raises
|
220
|
+
# @param service_name [String] The name of the microservice
|
221
|
+
# @return [Boolean] `true` if the service was removed, `false` otherwise
|
241
222
|
#
|
242
223
|
def delete(service_name)
|
243
224
|
|
@@ -265,16 +246,10 @@ module IBM
|
|
265
246
|
# Resets the state of this service. This includes stopping any existing
|
266
247
|
# heartbeat Threads as well as deleting all registered services.
|
267
248
|
#
|
268
|
-
#
|
269
|
-
#
|
270
|
-
#
|
271
|
-
# ===Arguments
|
272
|
-
# +none+
|
249
|
+
# @example
|
250
|
+
# sd.reset
|
273
251
|
#
|
274
|
-
#
|
275
|
-
# (Boolean) `true` if the reset was successful, `false` otherwise
|
276
|
-
#
|
277
|
-
# ===Raises
|
252
|
+
# @return [Boolean] `true` if the reset was successful, `false` otherwise
|
278
253
|
#
|
279
254
|
def reset
|
280
255
|
|
@@ -294,16 +269,10 @@ module IBM
|
|
294
269
|
# Returns information about the current local state of Service Discovery.
|
295
270
|
# This includes information about the services and the heartbeats.
|
296
271
|
#
|
297
|
-
#
|
298
|
-
#
|
299
|
-
#
|
300
|
-
# ===Arguments
|
301
|
-
# +none+
|
272
|
+
# @example
|
273
|
+
# sd.info
|
302
274
|
#
|
303
|
-
#
|
304
|
-
# (Hash) { services: ['s1', 's2'], heartbeats: ['s1'] }
|
305
|
-
#
|
306
|
-
# ===Raises
|
275
|
+
# @return [Hash] { services: ['s1', 's2'], heartbeats: ['s1'] }
|
307
276
|
#
|
308
277
|
def info
|
309
278
|
{ services: @@services.keys, heartbeats: heartbeats.keys }
|
@@ -311,16 +280,10 @@ module IBM
|
|
311
280
|
|
312
281
|
# Get the current list of registered services within Service Discovery
|
313
282
|
#
|
314
|
-
#
|
315
|
-
#
|
316
|
-
#
|
317
|
-
# ===Arguments
|
318
|
-
# +none+
|
319
|
-
#
|
320
|
-
# ===Returns
|
321
|
-
# (Hash) { services: ['s1', 's2'] }
|
283
|
+
# @example
|
284
|
+
# sd.list
|
322
285
|
#
|
323
|
-
#
|
286
|
+
# @return [Hash] { services: ['s1', 's2'] }
|
324
287
|
#
|
325
288
|
def list
|
326
289
|
|
@@ -343,14 +306,11 @@ module IBM
|
|
343
306
|
|
344
307
|
# Discovers the connection information for a given microservice.
|
345
308
|
#
|
346
|
-
#
|
347
|
-
#
|
309
|
+
# @example
|
310
|
+
# sd.discover('sample_service')
|
348
311
|
#
|
349
|
-
#
|
350
|
-
# [
|
351
|
-
#
|
352
|
-
# ===Returns
|
353
|
-
# (Hash)
|
312
|
+
# @param service_name [String] The name of the microservice
|
313
|
+
# @return [Hash]
|
354
314
|
# {
|
355
315
|
# "service_name":"my_service",
|
356
316
|
# "instances":[
|
@@ -366,8 +326,6 @@ module IBM
|
|
366
326
|
# }]
|
367
327
|
# }
|
368
328
|
#
|
369
|
-
# ===Raises
|
370
|
-
#
|
371
329
|
def discover(service_name)
|
372
330
|
# curl -X GET -H "Authorization: bearer 12o191sqk5h***" https://servicediscovery.ng.bluemix.net/api/v1/services/my_service
|
373
331
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ibm-bluemix-service_discovery
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christopher Young
|
@@ -115,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
115
115
|
requirements:
|
116
116
|
- - ">="
|
117
117
|
- !ruby/object:Gem::Version
|
118
|
-
version:
|
118
|
+
version: 1.9.3
|
119
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
120
|
requirements:
|
121
121
|
- - ">="
|