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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/commands/register-metadata.rb', line 14
def do (role, solution, test)
plan = JSON.parse("{ \"plan\": [ { \"role\": \"#{role}\", \"solution\": \"#{solution}\" } ] }")
n = Worker.new
n.test ( test )
lines = 1
cmd = "undefined"
begin
plan['plan'].each do |item|
root = "#{@basePath}/roles/#{item['role']}/#{item['solution']}"
if File.exist?(root) == false
log "-- ERROR #{root} does not exist!"
raise "#{root} does not exist!"
end
cmd = "#{@basePath}/roles/#{item['role']}/#{item['solution']}/metadata.json"
if File.exist?(cmd)
md = File.read(cmd)
md = JSON.parse(md)
if (md['services'].size() > 0)
svc = md['services'][0]
adef = {
"listener"=>svc['listener'],
"name" => "#{svc['name']}",
"id" => "#{ENV['HOSTNAME']}-#{svc['name']}",
"tags"=>[ item['role'] ],
"port"=>svc['port']
}
if (svc.has_key? "checks")
adef[:check] = svc['checks'][0]
end
log "-- Registering Service: #{svc['name']}"
log "-- #{adef.to_json}"
h = HelperRun.new
if test
log "-- TEST ONLY"
else
h.run "consul", "register_service", JSON.generate(adef)
end
end
end
end
rescue => exception
@log.error(cmd)
@log.error(exception.to_s)
@log.error(exception.backtrace)
abort()
end
end
|