def api_description
return @api_description if @api_description != nil
if @conf["mode"] == "api"
@api_description = JSON.parse "{}"
elsif @conf["retrieve_from"] == "rest"
if conf["branch"] == nil
@branch=""
else
@branch="?branch="+conf["branch"]
end
@node_path = [
conf["retrieve_url"],
"sites", site_uid,
"clusters", cluster_uid,
"nodes", node_uid
].join("/")
begin
@api_description = JSON.parse RestClient.get(@node_path+@branch, :accept => :json)
rescue RestClient::ResourceNotFound
if @conf["fallback_branch"] != nil
begin
@api_description = JSON.parse RestClient.get(@node_path+"?branch="+@conf["fallback_branch"], :accept => :json)
rescue RestClient::ResourceNotFound
raise "Node not find with url #{@node_path+@branch} and #{@node_path+"?branch="+@conf["fallback_branch"]}"
rescue RestClient::ServiceUnavailable => error
@retries ||= 0
if @retries < @max_retries
@retries += 1
sleep 10
retry
else
raise error
end
end
else
raise "Node not find with url #{@node_path+@branch}"
end
rescue RestClient::ServiceUnavailable => error
@retries ||= 0
if @retries < @max_retries
@retries += 1
sleep 10
retry
else
raise error
end
end
elsif @conf["retrieve_from"] == "file"
@node_path = File.join(@conf["retrieve_dir"], @hostname+".json")
@api_description = JSON.parse(File.read(@node_path))
end
return @api_description
end