|
2 | 2 | # Cookbook:: hadoop |
3 | 3 | # Library:: helpers |
4 | 4 | # |
5 | | -# Copyright © 2015-2016 Cask Data, Inc. |
| 5 | +# Copyright © 2015-2018 Cask Data, Inc. |
6 | 6 | # |
7 | 7 | # Licensed under the Apache License, Version 2.0 (the "License"); |
8 | 8 | # you may not use this file except in compliance with the License. |
|
17 | 17 | # limitations under the License. |
18 | 18 | # |
19 | 19 |
|
| 20 | +require 'net/http' |
| 21 | + |
20 | 22 | module Hadoop |
21 | 23 | 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 | + |
22 | 63 | # |
23 | 64 | # Return HDP 2.2 version, including revision, used for building HDP 2.2+ on-disk paths |
24 | 65 | # |
@@ -75,7 +116,9 @@ def hdp_version |
75 | 116 | when '2.6.4.0' |
76 | 117 | '2.6.4.0-91' |
77 | 118 | 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('-') |
79 | 122 | end |
80 | 123 | end |
81 | 124 |
|
|
0 commit comments