Skip to content

Commit aeafdfb

Browse files
authored
Merge pull request #360 from caskdata/feature/hdp-build-id
add helper to fetch hdp build.id
2 parents 8587fd7 + 659b328 commit aeafdfb

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

libraries/helpers.rb

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Cookbook:: hadoop
33
# Library:: helpers
44
#
5-
# Copyright © 2015-2016 Cask Data, Inc.
5+
# Copyright © 2015-2018 Cask Data, Inc.
66
#
77
# Licensed under the Apache License, Version 2.0 (the "License");
88
# you may not use this file except in compliance with the License.
@@ -17,8 +17,49 @@
1717
# limitations under the License.
1818
#
1919

20+
require 'net/http'
21+
2022
module Hadoop
2123
module Helpers
24+
#
25+
# Given an HDP version (2.6.1.0), return its build number (129)
26+
#
27+
def hdp_build_number(version)
28+
repo_path = [
29+
'http://public-repo-1.hortonworks.com/HDP',
30+
hdp_repo_os_path,
31+
'2.x/updates',
32+
version,
33+
'build.id',
34+
]
35+
build_id_url = File.join(repo_path)
36+
37+
uri = URI.parse(build_id_url)
38+
req = Net::HTTP::Get.new(uri.path)
39+
40+
response = Net::HTTP.start(uri.host, uri.port) do |http|
41+
http.request(req)
42+
end
43+
44+
case response.code
45+
when '200'
46+
build_h = Hash[response.body.split("\n").map { |str| str.split(': ') }]
47+
build_h['BUILD_NUMBER'] if build_h.key?('BUILD_NUMBER')
48+
end
49+
rescue StandardError
50+
nil
51+
end
52+
53+
#
54+
# Returns the HDP Repo path component for this OS, ie centos7, ubuntu14
55+
#
56+
def hdp_repo_os_path
57+
value_for_platform_family(
58+
%w(rhel amazon) => "centos#{node['platform_version'].to_i}",
59+
'debian' => "#{node['platform']}#{node['platform_version'].to_i}"
60+
)
61+
end
62+
2263
#
2364
# Return HDP 2.2 version, including revision, used for building HDP 2.2+ on-disk paths
2465
#
@@ -75,7 +116,9 @@ def hdp_version
75116
when '2.6.4.0'
76117
'2.6.4.0-91'
77118
else
78-
node['hadoop']['distribution_version']
119+
# fetch build number from HDP public repository
120+
build_number = hdp_build_number(node['hadoop']['distribution_version'])
121+
[node['hadoop']['distribution_version'], build_number].compact.join('-')
79122
end
80123
end
81124

0 commit comments

Comments
 (0)