This is an automated email from the ASF dual-hosted git repository.
dsen pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git
The following commit(s) were added to refs/heads/trunk by this push:
new 9072284 [AMBARI-23718] Update repoinfo latest with the link from
repository (dsen)
9072284 is described below
commit 9072284052f9906b3f719c4fa669ea32e48c1228
Author: Dmytro Sen <[email protected]>
AuthorDate: Fri Apr 27 16:13:13 2018 +0300
[AMBARI-23718] Update repoinfo latest with the link from repository (dsen)
---
.../src/main/python/ambari_server/serverSetup.py | 13 ++++-
.../src/main/python/ambari_server/serverUpgrade.py | 11 +++-
.../src/main/python/ambari_server/utils.py | 60 ++++++++++++++++++++++
3 files changed, 81 insertions(+), 3 deletions(-)
diff --git a/ambari-server/src/main/python/ambari_server/serverSetup.py
b/ambari-server/src/main/python/ambari_server/serverSetup.py
index c8aef43..d2e7cf0 100644
--- a/ambari-server/src/main/python/ambari_server/serverSetup.py
+++ b/ambari-server/src/main/python/ambari_server/serverSetup.py
@@ -36,7 +36,7 @@ from ambari_commons.os_family_impl import OsFamilyFuncImpl,
OsFamilyImpl
from ambari_commons.os_utils import copy_files, run_os_command, is_root
from ambari_commons.str_utils import compress_backslashes
from ambari_server.dbConfiguration import DBMSConfigFactory,
TAR_GZ_ARCHIVE_TYPE, default_connectors_map, check_jdbc_drivers
-from ambari_server.serverConfiguration import configDefaults, JDKRelease, \
+from ambari_server.serverConfiguration import configDefaults, JDKRelease,
get_stack_location,\
get_ambari_properties, get_is_secure, get_is_persisted, get_java_exe_path,
get_JAVA_HOME, get_missing_properties, \
get_resources_location, get_value_from_properties, read_ambari_user,
update_properties, validate_jdk, write_property, write_gpl_license_accepted,\
JAVA_HOME, JAVA_HOME_PROPERTY, JCE_NAME_PROPERTY, JDBC_RCA_URL_PROPERTY,
JDBC_URL_PROPERTY, \
@@ -46,7 +46,7 @@ from ambari_server.serverConfiguration import configDefaults,
JDKRelease, \
from ambari_server.serverUtils import is_server_runing
from ambari_server.setupSecurity import adjust_directory_permissions
from ambari_server.userInput import get_YN_input, get_validated_string_input
-from ambari_server.utils import locate_file
+from ambari_server.utils import locate_file,
update_latest_in_repoinfos_for_all_stacks, get_json_url_from_repo_file
from ambari_server.serverClassPath import ServerClassPath
from ambari_server.ambariPath import AmbariPath
@@ -1207,6 +1207,15 @@ def setup(options):
err = 'Error while extracting system views. Exiting'
raise FatalException(retcode, err)
+ json_url = get_json_url_from_repo_file()
+ if json_url:
+ print "Ambari repo file contains latest json url {0}, updating stacks
repoinfos with it...".format(json_url)
+ properties = get_ambari_properties()
+ stack_root = get_stack_location(properties)
+ update_latest_in_repoinfos_for_all_stacks(stack_root, json_url)
+ else:
+ print "Ambari repo file doesn't contain latest json url, skipping
repoinfos modification"
+
# we've already done this, but new files were created so run it one time.
adjust_directory_permissions(svc_user)
diff --git a/ambari-server/src/main/python/ambari_server/serverUpgrade.py
b/ambari-server/src/main/python/ambari_server/serverUpgrade.py
index cbc0bc1..4f7d77a 100644
--- a/ambari-server/src/main/python/ambari_server/serverUpgrade.py
+++ b/ambari-server/src/main/python/ambari_server/serverUpgrade.py
@@ -45,7 +45,7 @@ from ambari_server.serverConfiguration import configDefaults,
get_resources_loca
AMBARI_ENV_FILE, JDBC_DATABASE_PROPERTY, get_default_views_dir,
write_gpl_license_accepted, set_property
from ambari_server.setupSecurity import adjust_directory_permissions, \
generate_env, ensure_can_start_under_current_user
-from ambari_server.utils import compare_versions
+from ambari_server.utils import compare_versions, get_json_url_from_repo_file,
update_latest_in_repoinfos_for_all_stacks
from ambari_server.serverUtils import is_server_runing,
get_ambari_server_api_base
from ambari_server.userInput import get_validated_string_input,
get_prompt_default, read_password, get_YN_input
from ambari_server.serverClassPath import ServerClassPath
@@ -316,6 +316,15 @@ def upgrade(args):
# we need that to support new dynamic jdbc names for upgraded ambari
add_jdbc_properties(properties)
+ json_url = get_json_url_from_repo_file()
+ if json_url:
+ print "Ambari repo file contains latest json url {0}, updating stacks
repoinfos with it...".format(json_url)
+ properties = get_ambari_properties()
+ stack_root = get_stack_location(properties)
+ update_latest_in_repoinfos_for_all_stacks(stack_root, json_url)
+ else:
+ print "Ambari repo file doesn't contain latest json url, skipping
repoinfos modification"
+
def add_jdbc_properties(properties):
for db_name in CUSTOM_JDBC_DB_NAMES:
diff --git a/ambari-server/src/main/python/ambari_server/utils.py
b/ambari-server/src/main/python/ambari_server/utils.py
index e5cb828..55e7df7 100644
--- a/ambari-server/src/main/python/ambari_server/utils.py
+++ b/ambari-server/src/main/python/ambari_server/utils.py
@@ -27,9 +27,12 @@ import glob
from ambari_commons import subprocess32
import logging
import platform
+import xml.etree.ElementTree as ET
+
from ambari_commons import OSConst,OSCheck
from ambari_commons.logging_utils import print_error_msg
from ambari_commons.exceptions import FatalException
+from ambari_commons.os_utils import get_ambari_repo_file_full_name
logger = logging.getLogger(__name__)
@@ -339,3 +342,60 @@ def on_powerpc():
""" True if we are running on a Power PC platform."""
return platform.processor() == 'powerpc' or \
platform.machine().startswith('ppc')
+
+
+XML_HEADER = """<?xml version="1.0"?>
+<!--
+ 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.
+-->
+"""
+
+
+# Go though all stacks and update the repoinfo.xml files
+# replace <latest> tag with the passed url
+def update_latest_in_repoinfos_for_all_stacks(stacks_root, json_url_string):
+ for stack_name in os.walk(stacks_root).next()[1]:
+ for stack_version in os.walk(os.path.join(stacks_root,
stack_name)).next()[1]:
+ repoinfo_xml_path = os.path.join(stacks_root, stack_name, stack_version,
"repos", "repoinfo.xml")
+ if os.path.exists(repoinfo_xml_path):
+ replace_latest(repoinfo_xml_path, json_url_string)
+
+
+# replace <latest> tag in the file with the passed url
+def replace_latest(repoinfo_xml_path, json_url_string):
+ tree = ET.parse(repoinfo_xml_path)
+ root = tree.getroot()
+ latest_tag = root.find("latest")
+ if latest_tag is not None:
+ latest_tag.text = json_url_string
+
+ with open(repoinfo_xml_path, "w") as out:
+ out.write(XML_HEADER)
+ tree.write(out)
+
+
+# parse ambari repo file and get the value of '#json.url = http://...'
+def get_json_url_from_repo_file():
+ repo_file_path = get_ambari_repo_file_full_name()
+ if os.path.exists(repo_file_path):
+ with open(repo_file_path, 'r') as repo_file:
+ for line in repo_file:
+ line = line.rstrip()
+ if "json.url" in line:
+ json_url_string = line.split("=", 1)[1].strip()
+ return json_url_string
+
+ return None
--
To stop receiving notification emails like this one, please contact
[email protected].