Repository: ambari Updated Branches: refs/heads/branch-2.5 fa3b473c8 -> a879b8ac4
AMBARI-19927. Some services were not started after adding in Kerberize cluster.(echekanskiy via vbrodetskyi) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/a879b8ac Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/a879b8ac Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/a879b8ac Branch: refs/heads/branch-2.5 Commit: a879b8ac463dbc4e73ebfd5889103ea95bcce442 Parents: fa3b473 Author: Vitaly Brodetskyi <[email protected]> Authored: Thu Feb 9 15:18:39 2017 +0200 Committer: Vitaly Brodetskyi <[email protected]> Committed: Thu Feb 9 15:18:39 2017 +0200 ---------------------------------------------------------------------- .../stacks/HDP/2.0.6/services/stack_advisor.py | 50 ++++++++++++++++++-- 1 file changed, 46 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/a879b8ac/ambari-server/src/main/resources/stacks/HDP/2.0.6/services/stack_advisor.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0.6/services/stack_advisor.py b/ambari-server/src/main/resources/stacks/HDP/2.0.6/services/stack_advisor.py index 7cf4345..1ef7ac3 100644 --- a/ambari-server/src/main/resources/stacks/HDP/2.0.6/services/stack_advisor.py +++ b/ambari-server/src/main/resources/stacks/HDP/2.0.6/services/stack_advisor.py @@ -16,9 +16,10 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ - +import random import re import os +import string import sys import socket @@ -218,12 +219,50 @@ class HDP206StackAdvisor(DefaultStackAdvisor): ambari_user = ambari_user.split('@')[0] return ambari_user + PROXYUSER_SPECIAL_RE = [r"\$\{(?:([\w\-\.]+)/)?([\w\-\.]+)(?:\s*\|\s*(.+?))?\}"] + + @classmethod + def preserve_special_values(cls, value): + """ + Replace matches of PROXYUSER_SPECIAL_RE with random strings. + + :param value: input string + :return: result string and dictionary that contains mapping random string to original value + """ + def gen_random_str(): + return ''.join(random.choice(string.digits + string.ascii_letters) for _ in range(20)) + + result = value + replacements_dict = {} + for regexp in cls.PROXYUSER_SPECIAL_RE: + for match in re.finditer(regexp, value): + matched_string = match.string[match.start():match.end()] + rand_str = gen_random_str() + result = result.replace(matched_string, rand_str) + replacements_dict[rand_str] = matched_string + return result, replacements_dict + + @staticmethod + def restore_special_values(data, replacement_dict): + """ + Replace random strings in data set to their original values using replacement_dict. + + :param data: + :param replacement_dict: + :return: + """ + for replacement, original in replacement_dict.iteritems(): + data.remove(replacement) + data.add(original) + def get_data_for_proxyuser(self, user_name, services, configurations, groups=False): """ Returns values of proxyuser properties for given user. Properties can be hadoop.proxyuser.username.groups or hadoop.proxyuser.username.hosts + :param user_name: :param services: + :param configurations: :param groups: if true, will return values for group property, not hosts :return: tuple (wildcard_value, set[values]), where wildcard_value indicates if property value was * """ @@ -240,11 +279,14 @@ class HDP206StackAdvisor(DefaultStackAdvisor): if property_value == "*": return True, set() else: - result_values = set() + property_value, replacement_map = self.preserve_special_values(property_value) + result_values = set([v.strip() for v in property_value.split(",")]) if "core-site" in configurations: if property_name in configurations["core-site"]['properties']: - result_values = result_values.union(configurations["core-site"]['properties'][property_name].split(",")) - result_values = result_values.union(property_value.split(",")) + additional_value, additional_replacement_map = self.preserve_special_values(configurations["core-site"]['properties'][property_name]) + replacement_map.update(additional_replacement_map) + result_values = result_values.union([v.strip() for v in additional_value.split(",")]) + self.restore_special_values(result_values, replacement_map) return False, result_values return False, set()
