-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathregistrar.coffee
41 lines (31 loc) · 1.29 KB
/
registrar.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
async = require('async')
rest = require('restler')
class Registrar
getEc2InstanceInfo: (configuration, cb) =>
aws = configuration.amazonMetaDataWS
data =
id:async.apply(@getInfo, aws + 'instance-id')
dns:async.apply(@getInfo, aws + 'public-hostname')
async.parallel data, (err, results) =>
# FIXME we should handle the error here
# maybe sending an email
# or setting the values to something
# that explains the problem
@ec2InstanceId = results.id
@ip = results.dns
cb()
getInfo: (endPoint, callback) ->
rest.get(endPoint).on 'complete', (result) =>
callback(null, result)
register: (configuration, cb) =>
path = "/hermes/#{configuration.uuid}"
body =
maxConnections: configuration.maxConnections
ip: @ip
port: configuration.port
machineId: @ec2InstanceId
rest.put(configuration.zeusEndPoint+path, {headers: { 'Content-Type': 'application/json' }, data: JSON.stringify(body)}).on 'complete', (data, response)->
# FIXME should check the response.statusCode
console.log "registered"
cb()
exports.Registrar = Registrar