AMBARI-14859. Ranger - Keep all temporary files in the tmp directory defined in the Agent's configuration(gautam)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/472d62a7 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/472d62a7 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/472d62a7 Branch: refs/heads/branch-dev-patch-upgrade Commit: 472d62a7b3c0383ad4d95fe659ac87b4a8da3a1f Parents: 12faf8c Author: Gautam Borad <gau...@apache.org> Authored: Tue Jan 12 18:56:35 2016 +0530 Committer: Gautam Borad <gau...@apache.org> Committed: Tue Feb 9 15:30:01 2016 +0530 ---------------------------------------------------------------------- .../RANGER/0.4.0/package/scripts/params.py | 2 + .../0.4.0/package/scripts/ranger_admin.py | 50 +++++++++++--------- .../0.4.0/package/scripts/service_check.py | 12 ++--- .../0.4.0/package/scripts/status_params.py | 27 +++++++++++ 4 files changed, 61 insertions(+), 30 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/472d62a7/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/params.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/params.py b/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/params.py index b6e5ee9..6b6bf28 100644 --- a/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/params.py +++ b/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/params.py @@ -45,6 +45,8 @@ host_sys_prepped = default("/hostLevelParams/host_sys_prepped", False) stack_version_unformatted = str(config['hostLevelParams']['stack_version']) hdp_stack_version = format_hdp_stack_version(stack_version_unformatted) +upgrade_marker_file = format("{tmp_dir}/rangeradmin_ru.inprogress") + xml_configurations_supported = config['configurations']['ranger-env']['xml_configurations_supported'] create_db_dbuser = config['configurations']['ranger-env']['create_db_dbuser'] http://git-wip-us.apache.org/repos/asf/ambari/blob/472d62a7/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/ranger_admin.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/ranger_admin.py b/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/ranger_admin.py index a0007b3..5bcf6b9 100644 --- a/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/ranger_admin.py +++ b/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/ranger_admin.py @@ -29,8 +29,6 @@ import os, errno class RangerAdmin(Script): - upgrade_marker_file = '/tmp/rangeradmin_ru.inprogress' - def get_stack_to_component(self): return {"HDP": "ranger-admin"} @@ -67,11 +65,14 @@ class RangerAdmin(Script): setup_ranger_db(upgrade_type=upgrade_type) setup_java_patch(upgrade_type=upgrade_type) - self.set_ru_rangeradmin_in_progress() + self.set_ru_rangeradmin_in_progress(params.upgrade_marker_file) def post_upgrade_restart(self,env, upgrade_type=None): - if os.path.isfile(RangerAdmin.upgrade_marker_file): - os.remove(RangerAdmin.upgrade_marker_file) + import params + env.set_params(params) + + if os.path.isfile(params.upgrade_marker_file): + os.remove(params.upgrade_marker_file) def start(self, env, upgrade_type=None): import params @@ -81,15 +82,18 @@ class RangerAdmin(Script): def status(self, env): + import status_params + + env.set_params(status_params) cmd = 'ps -ef | grep proc_rangeradmin | grep -v grep' code, output = shell.call(cmd, timeout=20) if code != 0: - if self.is_ru_rangeradmin_in_progress(): - Logger.info('Ranger admin process not running - skipping as stack upgrade is in progress') + if self.is_ru_rangeradmin_in_progress(status_params.upgrade_marker_file): + Logger.info('Ranger admin process not running - skipping as stack upgrade is in progress') else: - Logger.debug('Ranger admin process not running') - raise ComponentIsNotRunning() + Logger.debug('Ranger admin process not running') + raise ComponentIsNotRunning() pass def configure(self, env): @@ -102,23 +106,23 @@ class RangerAdmin(Script): ranger('ranger_admin') - def set_ru_rangeradmin_in_progress(self): - config_dir = os.path.dirname(RangerAdmin.upgrade_marker_file) + def set_ru_rangeradmin_in_progress(self, upgrade_marker_file): + config_dir = os.path.dirname(upgrade_marker_file) try: - msg = "Starting Upgrade" - if (not os.path.exists(config_dir)): - os.makedirs(config_dir) - ofp = open(RangerAdmin.upgrade_marker_file, 'w') - ofp.write(msg) - ofp.close() + msg = "Starting Upgrade" + if (not os.path.exists(config_dir)): + os.makedirs(config_dir) + ofp = open(upgrade_marker_file, 'w') + ofp.write(msg) + ofp.close() except OSError as exc: - if exc.errno == errno.EEXIST and os.path.isdir(config_dir): - pass - else: - raise + if exc.errno == errno.EEXIST and os.path.isdir(config_dir): + pass + else: + raise - def is_ru_rangeradmin_in_progress(self): - return os.path.isfile(RangerAdmin.upgrade_marker_file) + def is_ru_rangeradmin_in_progress(self, upgrade_marker_file): + return os.path.isfile(upgrade_marker_file) if __name__ == "__main__": RangerAdmin().execute() http://git-wip-us.apache.org/repos/asf/ambari/blob/472d62a7/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/service_check.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/service_check.py b/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/service_check.py index 699e3c4..fb6af95 100644 --- a/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/service_check.py +++ b/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/service_check.py @@ -27,16 +27,14 @@ import os class RangerServiceCheck(Script): - upgrade_marker_file = '/tmp/rangeradmin_ru.inprogress' - def service_check(self, env): import params env.set_params(params) - self.check_ranger_admin_service(params.ranger_external_url) + self.check_ranger_admin_service(params.ranger_external_url, params.upgrade_marker_file) - def check_ranger_admin_service(self, ranger_external_url): - if (self.is_ru_rangeradmin_in_progress()): + def check_ranger_admin_service(self, ranger_external_url, upgrade_marker_file): + if (self.is_ru_rangeradmin_in_progress(upgrade_marker_file)): Logger.info('Ranger admin process not running - skipping as stack upgrade is in progress') else: Execute(format("curl -s -o /dev/null -w'%{{http_code}}' --negotiate -u: -k {ranger_external_url}/login.jsp | grep 200"), @@ -44,8 +42,8 @@ class RangerServiceCheck(Script): try_sleep=3, logoutput=True) - def is_ru_rangeradmin_in_progress(self): - return os.path.isfile(RangerServiceCheck.upgrade_marker_file) + def is_ru_rangeradmin_in_progress(self, upgrade_marker_file): + return os.path.isfile(upgrade_marker_file) if __name__ == "__main__": RangerServiceCheck().execute() http://git-wip-us.apache.org/repos/asf/ambari/blob/472d62a7/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/status_params.py ---------------------------------------------------------------------- diff --git a/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/status_params.py b/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/status_params.py new file mode 100644 index 0000000..b932f88 --- /dev/null +++ b/ambari-server/src/main/resources/common-services/RANGER/0.4.0/package/scripts/status_params.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python +""" +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +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. + +""" + +from resource_management.libraries.script import Script +from resource_management.libraries.functions.format import format + +config = Script.get_config() +tmp_dir = Script.get_tmp_dir() + +upgrade_marker_file = format("{tmp_dir}/rangeradmin_ru.inprogress") \ No newline at end of file