You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by jl...@apache.org on 2016/07/08 16:53:03 UTC
ambari git commit: AMBARI-17465: Management packs should be able to
install extensions (Tim Thorpe via jluniya)
Repository: ambari
Updated Branches:
refs/heads/trunk 7df5b8203 -> 587050eac
AMBARI-17465: Management packs should be able to install extensions (Tim Thorpe via jluniya)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/587050ea
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/587050ea
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/587050ea
Branch: refs/heads/trunk
Commit: 587050eacfca697eeecb55be238823f7843eb003
Parents: 7df5b82
Author: Jayush Luniya <jl...@hortonworks.com>
Authored: Fri Jul 8 09:52:54 2016 -0700
Committer: Jayush Luniya <jl...@hortonworks.com>
Committed: Fri Jul 8 09:52:54 2016 -0700
----------------------------------------------------------------------
ambari-server/conf/unix/ambari.properties | 2 +-
.../python/ambari_server/serverConfiguration.py | 13 ++
.../main/python/ambari_server/setupMpacks.py | 133 ++++++++++++++-----
ambari-server/src/test/python/TestMpacks.py | 80 ++++++++++-
.../extensions/MYEXTENSION/1.0/metainfo.xml | 25 ++++
.../extensions/MYEXTENSION/1.1/metainfo.xml | 25 ++++
.../myextension-ambari-mpack-1.0.0.0/mpack.json | 16 +++
.../myservice-ambari-mpack-1.0.0.0/mpack.json | 4 +-
8 files changed, 258 insertions(+), 40 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/587050ea/ambari-server/conf/unix/ambari.properties
----------------------------------------------------------------------
diff --git a/ambari-server/conf/unix/ambari.properties b/ambari-server/conf/unix/ambari.properties
index abd72ad..b8e41b7 100644
--- a/ambari-server/conf/unix/ambari.properties
+++ b/ambari-server/conf/unix/ambari.properties
@@ -43,7 +43,7 @@ jce.download.supported=true
metadata.path=$ROOT/var/lib/ambari-server/resources/stacks
common.services.path=$ROOT/var/lib/ambari-server/resources/common-services
-extensions.path=/var/lib/ambari-server/resources/extensions
+extensions.path=$ROOT/var/lib/ambari-server/resources/extensions
server.version.file=$ROOT/var/lib/ambari-server/resources/version
webapp.dir=$ROOT/usr/lib/ambari-server/web
pid.dir=$ROOT/var/run/ambari-server
http://git-wip-us.apache.org/repos/asf/ambari/blob/587050ea/ambari-server/src/main/python/ambari_server/serverConfiguration.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server/serverConfiguration.py b/ambari-server/src/main/python/ambari_server/serverConfiguration.py
index e868f96..07159c3 100644
--- a/ambari-server/src/main/python/ambari_server/serverConfiguration.py
+++ b/ambari-server/src/main/python/ambari_server/serverConfiguration.py
@@ -184,6 +184,7 @@ SETUP_OR_UPGRADE_MSG = "- If this is a new setup, then run the \"ambari-server s
DEFAULT_DB_NAME = "ambari"
SECURITY_KEYS_DIR = "security.server.keys_dir"
+EXTENSION_PATH_PROPERTY = 'extensions.path'
COMMON_SERVICES_PATH_PROPERTY = 'common.services.path'
MPACKS_STAGING_PATH_PROPERTY = 'mpacks.staging.path'
WEBAPP_DIR_PROPERTY = 'webapp.dir'
@@ -374,6 +375,7 @@ class ServerConfigDefaults(object):
self.DEFAULT_DB_NAME = "ambari"
self.STACK_LOCATION_DEFAULT = ""
+ self.EXTENSION_LOCATION_DEFAULT = ""
self.COMMON_SERVICES_LOCATION_DEFAULT = ""
self.MPACKS_STAGING_LOCATION_DEFAULT = ""
self.SERVER_TMP_DIR_DEFAULT = ""
@@ -444,6 +446,7 @@ class ServerConfigDefaultsWindows(ServerConfigDefaults):
self.SERVER_RESOURCES_DIR = "resources"
self.STACK_LOCATION_DEFAULT = "resources\\stacks"
+ self.EXTENSION_LOCATION_DEFAULT = "resources\\extensions"
self.COMMON_SERVICES_LOCATION_DEFAULT = "resources\\common-services"
self.MPACKS_STAGING_LOCATION_DEFAULT = "resources\\mpacks"
self.SERVER_TMP_DIR_DEFAULT = "data\\tmp"
@@ -529,6 +532,7 @@ class ServerConfigDefaultsLinux(ServerConfigDefaults):
self.SERVER_RESOURCES_DIR = AmbariPath.get("/var/lib/ambari-server/resources")
self.STACK_LOCATION_DEFAULT = AmbariPath.get("/var/lib/ambari-server/resources/stacks")
+ self.EXTENSION_LOCATION_DEFAULT = AmbariPath.get("/var/lib/ambari-server/resources/extensions")
self.COMMON_SERVICES_LOCATION_DEFAULT = AmbariPath.get("/var/lib/ambari-server/resources/common-services")
self.MPACKS_STAGING_LOCATION_DEFAULT = AmbariPath.get("/var/lib/ambari-server/resources/mpacks")
self.SERVER_TMP_DIR_DEFAULT = AmbariPath.get("/var/lib/ambari-server/data/tmp")
@@ -1380,6 +1384,15 @@ def get_stack_location(properties):
return stack_location
#
+# Extension location
+#
+def get_extension_location(properties):
+ extension_location = properties[EXTENSION_PATH_PROPERTY]
+ if not extension_location:
+ extension_location = configDefaults.EXTENSION_LOCATION_DEFAULT
+ return extension_location
+
+#
# Common services location
#
def get_common_services_location(properties):
http://git-wip-us.apache.org/repos/asf/ambari/blob/587050ea/ambari-server/src/main/python/ambari_server/setupMpacks.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/python/ambari_server/setupMpacks.py b/ambari-server/src/main/python/ambari_server/setupMpacks.py
index 98811f5..5acc92c 100644
--- a/ambari-server/src/main/python/ambari_server/setupMpacks.py
+++ b/ambari-server/src/main/python/ambari_server/setupMpacks.py
@@ -28,7 +28,7 @@ from ambari_commons.inet_utils import download_file
from ambari_commons.logging_utils import print_info_msg, print_error_msg
from ambari_commons.os_utils import copy_file
from ambari_server.serverConfiguration import get_ambari_properties, get_ambari_version, get_stack_location, \
- get_common_services_location, get_mpacks_staging_location, get_server_temp_location
+ get_common_services_location, get_mpacks_staging_location, get_server_temp_location, get_extension_location
from resource_management.core import sudo
from resource_management.libraries.functions.tar_archive import extract_archive, get_archive_root_dir
@@ -150,10 +150,11 @@ def get_mpack_properties():
print_error_msg("Error getting ambari properties")
return -1
stack_location = get_stack_location(properties)
+ extension_location = get_extension_location(properties)
service_definitions_location = get_common_services_location(properties)
mpacks_staging_location = get_mpacks_staging_location(properties)
ambari_version = get_ambari_version(properties)
- return stack_location, service_definitions_location, mpacks_staging_location
+ return stack_location, extension_location, service_definitions_location, mpacks_staging_location
def _get_mpack_name_version(mpack_path):
"""
@@ -223,7 +224,7 @@ def purge_stacks_and_mpacks(purge_list, replay_mode=False):
:param replay_mode: Flag to indicate if purging in replay mode
"""
# Get ambari mpacks config properties
- stack_location, service_definitions_location, mpacks_staging_location = get_mpack_properties()
+ stack_location, extension_location, service_definitions_location, mpacks_staging_location = get_mpack_properties()
print_info_msg("Purging existing stack definitions and management packs")
@@ -257,7 +258,7 @@ def process_stack_definitions_artifact(artifact, artifact_source_dir, options):
:param options: Command line options
"""
# Get ambari mpack properties
- stack_location, service_definitions_location, mpacks_staging_location = get_mpack_properties()
+ stack_location, extension_location, service_definitions_location, mpacks_staging_location = get_mpack_properties()
for file in sorted(os.listdir(artifact_source_dir)):
if os.path.isfile(os.path.join(artifact_source_dir, file)):
# Example: /var/lib/ambari-server/resources/stacks/stack_advisor.py
@@ -294,7 +295,7 @@ def process_stack_definition_artifact(artifact, artifact_source_dir, options):
:param options: Command line options
"""
# Get ambari mpack properties
- stack_location, service_definitions_location, mpacks_staging_location = get_mpack_properties()
+ stack_location, extension_location, service_definitions_location, mpacks_staging_location = get_mpack_properties()
stack_name = None
if "stack_name" in artifact:
stack_name = artifact.stack_name
@@ -307,7 +308,71 @@ def process_stack_definition_artifact(artifact, artifact_source_dir, options):
if not stack_version:
print_error_msg("Must provide stack version for stack-definition artifact!")
raise FatalException(-1, 'Must provide stack version for stack-definition artifact!')
- dest_link = os.path.join(stack_location, stack_name, stack_version)
+ stack_dir = os.path.join(stack_location, stack_name)
+ dest_link = os.path.join(stack_dir, stack_version)
+ if (not os.path.exists(stack_dir)):
+ sudo.makedir(stack_dir, 0755)
+ if options.force and os.path.islink(dest_link):
+ sudo.unlink(dest_link)
+ sudo.symlink(artifact_source_dir, dest_link)
+
+def process_extension_definitions_artifact(artifact, artifact_source_dir, options):
+ """
+ Process extension-definitions artifacts
+ Creates references for everything under the artifact_source_dir in the extension_location directory.
+ This links all files, creates the extension name and extension version directories.
+ Under the extension version directory, it creates links for all files and directories other than the
+ services directory. It creates links from the services directory to each service in the extension version.
+ :param artifact: Artifact metadata
+ :param artifact_source_dir: Location of artifact in the management pack
+ :param options: Command line options
+ """
+ # Get ambari mpack properties
+ stack_location, extension_location, service_definitions_location, mpacks_staging_location = get_mpack_properties()
+ if not os.path.exists(extension_location):
+ sudo.makedir(extension_location, 0755)
+ for file in sorted(os.listdir(artifact_source_dir)):
+ if os.path.isfile(os.path.join(artifact_source_dir, file)):
+ # Example: /var/lib/ambari-server/resources/extensions/README.txt
+ create_symlink(artifact_source_dir, extension_location, file, options.force)
+ else:
+ src_extension_dir = os.path.join(artifact_source_dir, file)
+ dest_extension_dir = os.path.join(extension_location, file)
+ if not os.path.exists(dest_extension_dir):
+ sudo.makedir(dest_extension_dir, 0755)
+ for file in sorted(os.listdir(src_extension_dir)):
+ create_symlink(src_extension_dir, dest_extension_dir, file, options.force)
+
+def process_extension_definition_artifact(artifact, artifact_source_dir, options):
+ """
+ Process extension-definition artifact
+ Creates a link from <extension_location>/<extension_name>/<extension_version>
+ to the artifact_source_dir.
+ Ex: resources/extensions/EXT/1.0 -> resources/mpacks/myext/extensions/EXT/1.0
+ :param artifact: Artifact metadata
+ :param artifact_source_dir: Location of artifact in the management pack
+ :param options: Command line options
+ """
+ # Get ambari mpack properties
+ stack_location, extension_location, service_definitions_location, mpacks_staging_location = get_mpack_properties()
+ extension_name = None
+ if "extension_name" in artifact:
+ extension_name = artifact.extension_name
+ if not extension_name:
+ print_error_msg("Must provide extension name for extension-definition artifact!")
+ raise FatalException(-1, 'Must provide extension name for extension-definition artifact!')
+ extension_version = None
+ if "extension_version" in artifact:
+ extension_version = artifact.extension_version
+ if not extension_version:
+ print_error_msg("Must provide extension version for extension-definition artifact!")
+ raise FatalException(-1, 'Must provide extension version for extension-definition artifact!')
+ extension_dir = os.path.join(extension_location, extension_name)
+ dest_link = os.path.join(extension_dir, extension_version)
+ if (not os.path.exists(extension_location)):
+ sudo.makedir(extension_location, 0755)
+ if (not os.path.exists(extension_dir)):
+ sudo.makedir(extension_dir, 0755)
if options.force and os.path.islink(dest_link):
sudo.unlink(dest_link)
sudo.symlink(artifact_source_dir, dest_link)
@@ -320,7 +385,7 @@ def process_service_definitions_artifact(artifact, artifact_source_dir, options)
:param options: Command line options
"""
# Get ambari mpack properties
- stack_location, service_definitions_location, mpacks_staging_location = get_mpack_properties()
+ stack_location, extension_location, service_definitions_location, mpacks_staging_location = get_mpack_properties()
for file in sorted(os.listdir(artifact_source_dir)):
src_service_definitions_dir = os.path.join(artifact_source_dir, file)
dest_service_definitions_dir = os.path.join(service_definitions_location, file)
@@ -337,7 +402,7 @@ def process_service_definition_artifact(artifact, artifact_source_dir, options):
:param options: Command line options
"""
# Get ambari mpack properties
- stack_location, service_definitions_location, mpacks_staging_location = get_mpack_properties()
+ stack_location, extension_location, service_definitions_location, mpacks_staging_location = get_mpack_properties()
service_name = None
if "service_name" in artifact:
service_name = artifact.service_name
@@ -358,21 +423,21 @@ def process_service_definition_artifact(artifact, artifact_source_dir, options):
sudo.unlink(dest_link)
sudo.symlink(artifact_source_dir, dest_link)
-def process_stack_extension_definitions_artifact(artifact, artifact_source_dir, options):
+def process_stack_addon_service_definitions_artifact(artifact, artifact_source_dir, options):
"""
- Process stack-extension-definitions artifact
+ Process stack addon service definitions artifact
:param artifact: Artifact metadata
:param artifact_source_dir: Location of artifact in the management pack
:param options: Command line options
"""
# Get ambari mpack properties
- stack_location, service_definitions_location, mpacks_staging_location = get_mpack_properties()
+ stack_location, extension_location, service_definitions_location, mpacks_staging_location = get_mpack_properties()
service_versions_map = None
if "service_versions_map" in artifact:
service_versions_map = artifact.service_versions_map
if not service_versions_map:
- print_error_msg("Must provide service versions map for stack-extension-definitions artifact!")
- raise FatalException(-1, 'Must provide service versions map for stack-extension-definition artifact!')
+ print_error_msg("Must provide service versions map for stack-addon-service-definitions artifact!")
+ raise FatalException(-1, 'Must provide service versions map for stack-addon-service-definition artifact!')
for service_name in sorted(os.listdir(artifact_source_dir)):
source_service_path = os.path.join(artifact_source_dir, service_name)
for service_version in sorted(os.listdir(source_service_path)):
@@ -394,27 +459,27 @@ def process_stack_extension_definitions_artifact(artifact, artifact_source_dir,
sudo.unlink(dest_link)
sudo.symlink(source_service_version_path, dest_link)
-def process_stack_extension_definition_artifact(artifact, artifact_source_dir, options):
+def process_stack_addon_service_definition_artifact(artifact, artifact_source_dir, options):
"""
- Process stack-extension-definition artifact
+ Process stack addon service definition artifact
:param artifact: Artifact metadata
:param artifact_source_dir: Location of artifact in the management pack
:param options: Command line options
"""
# Get ambari mpack properties
- stack_location, service_definitions_location, mpacks_staging_location = get_mpack_properties()
+ stack_location, extension_location, service_definitions_location, mpacks_staging_location = get_mpack_properties()
service_name = None
if "service_name" in artifact:
service_name = artifact.service_name
if not service_name:
- print_error_msg("Must provide service name for stack-extension-definition artifact!")
- raise FatalException(-1, 'Must provide service name for stack-extension-definition artifact!')
+ print_error_msg("Must provide service name for stack-addon-service-definition artifact!")
+ raise FatalException(-1, 'Must provide service name for stack-addon-service-definition artifact!')
applicable_stacks = None
if "applicable_stacks" in artifact:
applicable_stacks = artifact.applicable_stacks
if not applicable_stacks:
- print_error_msg("Must provide applicable stacks for stack-extension-definition artifact!")
- raise FatalException(-1, 'Must provide applicable stacks for stack-extension-definition artifact!')
+ print_error_msg("Must provide applicable stacks for stack-addon-service-definition artifact!")
+ raise FatalException(-1, 'Must provide applicable stacks for stack-addon-service-definition artifact!')
for applicable_stack in applicable_stacks:
stack_name = applicable_stack.stack_name
stack_version = applicable_stack.stack_version
@@ -438,7 +503,7 @@ def search_mpacks(mpack_name, max_mpack_version=None):
:return: List of management pack
"""
# Get ambari mpack properties
- stack_location, service_definitions_location, mpacks_staging_location = get_mpack_properties()
+ stack_location, extension_location, service_definitions_location, mpacks_staging_location = get_mpack_properties()
results = []
if os.path.exists(mpacks_staging_location) and os.path.isdir(mpacks_staging_location):
staged_mpack_dirs = sorted(os.listdir(mpacks_staging_location))
@@ -477,7 +542,7 @@ def uninstall_mpack(mpack_name, mpack_version):
"""
print_info_msg("Uninstalling management pack {0}-{1}".format(mpack_name, mpack_version))
# Get ambari mpack properties
- stack_location, service_definitions_location, mpacks_staging_location = get_mpack_properties()
+ stack_location, extension_location, service_definitions_location, mpacks_staging_location = get_mpack_properties()
found = False
if os.path.exists(mpacks_staging_location) and os.path.isdir(mpacks_staging_location):
staged_mpack_dirs = sorted(os.listdir(mpacks_staging_location))
@@ -586,11 +651,13 @@ def _install_mpack(options, replay_mode=False):
purge_stacks_and_mpacks(options.purge_list.split(","), replay_mode)
# Get ambari mpack properties
- stack_location, service_definitions_location, mpacks_staging_location = get_mpack_properties()
+ stack_location, extension_location, service_definitions_location, mpacks_staging_location = get_mpack_properties()
mpacks_cache_location = os.path.join(mpacks_staging_location, MPACKS_CACHE_DIRNAME)
# Create directories
if not os.path.exists(stack_location):
sudo.makedir(stack_location, 0755)
+ if not os.path.exists(extension_location):
+ sudo.makedir(extension_location, 0755)
if not os.path.exists(service_definitions_location):
sudo.makedir(service_definitions_location, 0755)
if not os.path.exists(mpacks_staging_location):
@@ -618,12 +685,12 @@ def _install_mpack(options, replay_mode=False):
shutil.move(tmp_root_dir, mpack_staging_dir)
shutil.move(tmp_archive_path, mpack_archive_path)
- # Process setup steps for all artifacts (stack-definitions, service-definitions, stack-extension-definitions)
- # in the management pack
+ # Process setup steps for all artifacts (stack-definitions, extension-definitions,
+ # service-definitions, stack-addon-service-definitions) in the management pack
for artifact in mpack_metadata.artifacts:
# Artifact name (Friendly name)
artifact_name = artifact.name
- # Artifact type (stack-definitions, service-definitions, stack-extension-definitions etc)
+ # Artifact type (stack-definitions, extension-definitions, service-definitions, etc)
artifact_type = artifact.type
# Artifact directory with contents of the artifact
artifact_source_dir = os.path.join(mpack_staging_dir, artifact.source_dir)
@@ -634,14 +701,18 @@ def _install_mpack(options, replay_mode=False):
process_stack_definitions_artifact(artifact, artifact_source_dir, options)
elif artifact.type == "stack-definition":
process_stack_definition_artifact(artifact, artifact_source_dir, options)
+ elif artifact.type == "extension-definitions":
+ process_extension_definitions_artifact(artifact, artifact_source_dir, options)
+ elif artifact.type == "extension-definition":
+ process_extension_definition_artifact(artifact, artifact_source_dir, options)
elif artifact.type == "service-definitions":
process_service_definitions_artifact(artifact, artifact_source_dir, options)
elif artifact.type == "service-definition":
process_service_definition_artifact(artifact, artifact_source_dir, options)
- elif artifact.type == "stack-extension-definitions":
- process_stack_extension_definitions_artifact(artifact, artifact_source_dir, options)
- elif artifact.type == "stack-extension-definition":
- process_stack_extension_definition_artifact(artifact, artifact_source_dir, options)
+ elif artifact.type == "stack-addon-service-definitions":
+ process_stack_addon_service_definitions_artifact(artifact, artifact_source_dir, options)
+ elif artifact.type == "stack-addon-service-definition":
+ process_stack_addon_service_definition_artifact(artifact, artifact_source_dir, options)
else:
print_info_msg("Unknown artifact {0} of type {1}".format(artifact_name, artifact_type))
@@ -653,7 +724,7 @@ def get_replay_log_file():
Helper function to get mpack replay log file path
:return: mpack replay log file path
"""
- stack_location, service_definitions_location, mpacks_staging_location = get_mpack_properties()
+ stack_location, extension_location, service_definitions_location, mpacks_staging_location = get_mpack_properties()
replay_log_file = os.path.join(mpacks_staging_location, MPACKS_REPLAY_LOG_FILENAME)
return replay_log_file
http://git-wip-us.apache.org/repos/asf/ambari/blob/587050ea/ambari-server/src/test/python/TestMpacks.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/TestMpacks.py b/ambari-server/src/test/python/TestMpacks.py
index a7c6092..0995280 100644
--- a/ambari-server/src/test/python/TestMpacks.py
+++ b/ambari-server/src/test/python/TestMpacks.py
@@ -61,6 +61,7 @@ def get_configs():
configs = {
serverConfiguration.STACK_LOCATION_KEY : "/var/lib/ambari-server/resources/stacks",
serverConfiguration.COMMON_SERVICES_PATH_PROPERTY : "/var/lib/ambari-server/resources/common-services",
+ serverConfiguration.EXTENSION_PATH_PROPERTY : "/var/lib/ambari-server/resources/extensions",
serverConfiguration.MPACKS_STAGING_PATH_PROPERTY : mpacks_directory,
serverConfiguration.SERVER_TMP_DIR_PROPERTY : "/tmp"
}
@@ -199,6 +200,7 @@ class TestMpacks(TestCase):
os_path_exists_calls = [call('/tmp/mystack.tar.gz'),
call('mpacks/mystack-ambari-mpack-1.0.0.0/mpack.json'),
call('/var/lib/ambari-server/resources/stacks'),
+ call('/var/lib/ambari-server/resources/extensions'),
call('/var/lib/ambari-server/resources/common-services'),
call(mpacks_directory),
call(mpacks_directory + '/cache'),
@@ -213,7 +215,7 @@ class TestMpacks(TestCase):
call('/var/lib/ambari-server/resources/stacks/MYSTACK/2.0'),
call('/var/lib/ambari-server/resources/stacks/MYSTACK/2.0/services')]
"""
- os_path_exists_mock.side_effect = [True, True, False, False, False, False,
+ os_path_exists_mock.side_effect = [True, True, False, True, False, False, False,
False, False, False, False, False, False,
False, False, False, False]
get_ambari_properties_mock.return_value = configs
@@ -223,6 +225,7 @@ class TestMpacks(TestCase):
stacks_directory = configs[serverConfiguration.STACK_LOCATION_KEY]
common_services_directory = configs[serverConfiguration.COMMON_SERVICES_PATH_PROPERTY]
+ extensions_directory = configs[serverConfiguration.EXTENSION_PATH_PROPERTY]
mpacks_directory = configs[serverConfiguration.MPACKS_STAGING_PATH_PROPERTY]
mpacks_staging_directory = os.path.join(mpacks_directory, "mystack-ambari-mpack-1.0.0.0")
@@ -283,6 +286,67 @@ class TestMpacks(TestCase):
self.assertTrue(add_replay_log_mock.called)
@patch("os.path.exists")
+ @patch("shutil.move")
+ @patch("os.mkdir")
+ @patch("ambari_server.setupMpacks.create_symlink")
+ @patch("ambari_server.setupMpacks.get_ambari_version")
+ @patch("ambari_server.setupMpacks.get_ambari_properties")
+ @patch("ambari_server.setupMpacks.purge_stacks_and_mpacks")
+ @patch("ambari_server.setupMpacks.add_replay_log")
+ @patch("ambari_server.setupMpacks.expand_mpack")
+ @patch("ambari_server.setupMpacks.download_mpack")
+ def test_install_extension_mpack(self, download_mpack_mock, expand_mpack_mock, add_replay_log_mock,
+ purge_stacks_and_mpacks_mock, get_ambari_properties_mock, get_ambari_version_mock,
+ create_symlink_mock, os_mkdir_mock, shutil_move_mock, os_path_exists_mock):
+ options = self._create_empty_options_mock()
+ options.mpack_path = "/path/to/myextension.tar.gz"
+ options.purge = False
+ download_mpack_mock.return_value = "/tmp/myextension.tar.gz"
+ expand_mpack_mock.return_value = "mpacks/myextension-ambari-mpack-1.0.0.0"
+ get_ambari_version_mock.return_value = "2.4.0.0"
+ """
+ os_path_exists_calls = [call('/tmp/myextension.tar.gz'),
+ call('mpacks/myextension-ambari-mpack-1.0.0.0/mpack.json'),
+ call('/var/lib/ambari-server/resources/stacks'),
+ call('/var/lib/ambari-server/resources/extensions'),
+ call('/var/lib/ambari-server/resources/common-services'),
+ call(mpacks_directory),
+ call(mpacks_directory + '/cache'),
+ call(mpacks_directory + '/myextension-ambari-mpack-1.0.0.0'),
+ call('/var/lib/ambari-server/resources/extensions'),
+ call('/var/lib/ambari-server/resources/extensions/MYEXTENSION')]
+ """
+ os_path_exists_mock.side_effect = [True, True, True, False, True, False, False,
+ False, True, False]
+ get_ambari_properties_mock.return_value = configs
+ shutil_move_mock.return_value = True
+
+ install_mpack(options)
+
+ extensions_directory = configs[serverConfiguration.EXTENSION_PATH_PROPERTY]
+ mpacks_directory = configs[serverConfiguration.MPACKS_STAGING_PATH_PROPERTY]
+ mpacks_staging_directory = os.path.join(mpacks_directory, "myextension-ambari-mpack-1.0.0.0")
+ os_mkdir_calls = [
+ call(extensions_directory),
+ call(mpacks_directory),
+ call(mpacks_directory + '/cache'),
+ call(os.path.join(extensions_directory, "MYEXTENSION"))
+ ]
+ create_symlink_calls = [
+ call(os.path.join(mpacks_staging_directory, "extensions/MYEXTENSION"),
+ os.path.join(extensions_directory, "MYEXTENSION"),
+ "1.0", None),
+ call(os.path.join(mpacks_staging_directory, "extensions/MYEXTENSION"),
+ os.path.join(extensions_directory, "MYEXTENSION"),
+ "1.1", None)
+ ]
+
+ self.assertFalse(purge_stacks_and_mpacks_mock.called)
+ os_mkdir_mock.assert_has_calls(os_mkdir_calls)
+ create_symlink_mock.assert_has_calls(create_symlink_calls)
+ self.assertTrue(add_replay_log_mock.called)
+
+ @patch("os.path.exists")
@patch("os.path.isdir")
@patch("os.symlink")
@patch("shutil.move")
@@ -309,6 +373,7 @@ class TestMpacks(TestCase):
call('mpacks/myservice-ambari-mpack-1.0.0.0/mpack.json'),
call('/var/lib/ambari-server/resources/stacks/MYSTACK/1.0'),
call('/var/lib/ambari-server/resources/stacks'),
+ call('/var/lib/ambari-server/resources/extensions'),
call('/var/lib/ambari-server/resources/common-services'),
call(mpacks_directory),
call(mpacks_directory + '/cache'),
@@ -321,7 +386,7 @@ class TestMpacks(TestCase):
call('/var/lib/ambari-server/resources/stacks/MYSTACK/2.0'),
call('/var/lib/ambari-server/resources/stacks/MYSTACK/2.0/services')]
"""
- os_path_exists_mock.side_effect = [True, True, True, True, True,
+ os_path_exists_mock.side_effect = [True, True, True, True, True, True,
True, True, False, False, True,
True, True, True, True, True]
@@ -377,12 +442,14 @@ class TestMpacks(TestCase):
os_path_exists_calls = [call('/tmp/mystack-1.0.0.1.tar.gz'),
call('mpacks/mystack-ambari-mpack-1.0.0.1/mpack.json'),
call(mpacks_directory),
+ call(mpacks_directory + '/myextension-ambari-mpack-1.0.0.0/mpack.json'),
call(mpacks_directory + '/myservice-ambari-mpack-1.0.0.0/mpack.json'),
call(mpacks_directory + '/mystack-ambari-mpack-1.0.0.0/mpack.json'),
call(mpacks_directory + '/mystack-ambari-mpack-1.0.0.1/mpack.json'),
call('/tmp/mystack-1.0.0.1.tar.gz'),
call('mpacks/mystack-ambari-mpack-1.0.0.1/mpack.json'),
call('/var/lib/ambari-server/resources/stacks'),
+ call('/var/lib/ambari-server/resources/extensions'),
call('/var/lib/ambari-server/resources/common-services'),
call(mpacks_directory),
call(mpacks_directory + '/cache'),
@@ -400,15 +467,16 @@ class TestMpacks(TestCase):
call('/var/lib/ambari-server/resources/stacks/MYSTACK/3.0'),
call('/var/lib/ambari-server/resources/stacks/MYSTACK/3.0/services'),
call(mpacks_directory),
+ call(mpacks_directory + '/myextension-ambari-mpack-1.0.0.0/mpack.json'),
call(mpacks_directory + '/myservice-ambari-mpack-1.0.0.0/mpack.json'),
call(mpacks_directory + '/mystack-ambari-mpack-1.0.0.0/mpack.json'),
call(mpacks_directory + '/mystack-ambari-mpack-1.0.0.1/mpack.json')]
"""
- os_path_exists_mock.side_effect = [True, True, True, True, True, True,
- True, True, True, True, True, True,
+ os_path_exists_mock.side_effect = [True, True, True, True, True, True, True,
+ True, True, True, True, True, True, True,
False, True, True, False, True, True, True,
True, True, True, True, False, False,
- True, True, True, True]
+ True, True, True, True, True]
get_ambari_properties_mock.return_value = configs
shutil_move_mock.return_value = True
@@ -525,4 +593,4 @@ class TestMpacks(TestCase):
options.force = None
options.verbose = None
options.replay_mode = False
- return options
\ No newline at end of file
+ return options
http://git-wip-us.apache.org/repos/asf/ambari/blob/587050ea/ambari-server/src/test/python/mpacks/myextension-ambari-mpack-1.0.0.0/extensions/MYEXTENSION/1.0/metainfo.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/mpacks/myextension-ambari-mpack-1.0.0.0/extensions/MYEXTENSION/1.0/metainfo.xml b/ambari-server/src/test/python/mpacks/myextension-ambari-mpack-1.0.0.0/extensions/MYEXTENSION/1.0/metainfo.xml
new file mode 100644
index 0000000..1ded61b
--- /dev/null
+++ b/ambari-server/src/test/python/mpacks/myextension-ambari-mpack-1.0.0.0/extensions/MYEXTENSION/1.0/metainfo.xml
@@ -0,0 +1,25 @@
+<?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.
+-->
+<metainfo>
+ <stacks>
+ <stack>
+ <name>HDP</name>
+ <version>2.4</version>
+ </stack>
+ </stacks>
+</metainfo>
http://git-wip-us.apache.org/repos/asf/ambari/blob/587050ea/ambari-server/src/test/python/mpacks/myextension-ambari-mpack-1.0.0.0/extensions/MYEXTENSION/1.1/metainfo.xml
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/mpacks/myextension-ambari-mpack-1.0.0.0/extensions/MYEXTENSION/1.1/metainfo.xml b/ambari-server/src/test/python/mpacks/myextension-ambari-mpack-1.0.0.0/extensions/MYEXTENSION/1.1/metainfo.xml
new file mode 100644
index 0000000..1ded61b
--- /dev/null
+++ b/ambari-server/src/test/python/mpacks/myextension-ambari-mpack-1.0.0.0/extensions/MYEXTENSION/1.1/metainfo.xml
@@ -0,0 +1,25 @@
+<?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.
+-->
+<metainfo>
+ <stacks>
+ <stack>
+ <name>HDP</name>
+ <version>2.4</version>
+ </stack>
+ </stacks>
+</metainfo>
http://git-wip-us.apache.org/repos/asf/ambari/blob/587050ea/ambari-server/src/test/python/mpacks/myextension-ambari-mpack-1.0.0.0/mpack.json
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/mpacks/myextension-ambari-mpack-1.0.0.0/mpack.json b/ambari-server/src/test/python/mpacks/myextension-ambari-mpack-1.0.0.0/mpack.json
new file mode 100644
index 0000000..7d827f8
--- /dev/null
+++ b/ambari-server/src/test/python/mpacks/myextension-ambari-mpack-1.0.0.0/mpack.json
@@ -0,0 +1,16 @@
+{
+ "type" : "full-release",
+ "name" : "myextension-ambari-mpack",
+ "version": "1.0.0.0",
+ "description" : "MyExtension Management Pack",
+ "prerequisites": {
+ "min_ambari_version" : "2.4.0.0"
+ },
+ "artifacts": [
+ {
+ "name" : "myextension-extension-definitions",
+ "type" : "extension-definitions",
+ "source_dir": "extensions"
+ }
+ ]
+}
http://git-wip-us.apache.org/repos/asf/ambari/blob/587050ea/ambari-server/src/test/python/mpacks/myservice-ambari-mpack-1.0.0.0/mpack.json
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/mpacks/myservice-ambari-mpack-1.0.0.0/mpack.json b/ambari-server/src/test/python/mpacks/myservice-ambari-mpack-1.0.0.0/mpack.json
index faade4a..0af6949 100644
--- a/ambari-server/src/test/python/mpacks/myservice-ambari-mpack-1.0.0.0/mpack.json
+++ b/ambari-server/src/test/python/mpacks/myservice-ambari-mpack-1.0.0.0/mpack.json
@@ -22,7 +22,7 @@
},
{
"name" : "MYSERVICE-1.0.0",
- "type" : "stack-extension-definition",
+ "type" : "stack-addon-service-definition",
"source_dir": "custom-services/MYSERVICE/1.0.0",
"service_name" : "MYSERVICE",
"service_version" : "1.0.0",
@@ -35,7 +35,7 @@
},
{
"name" : "MYSERVICE-2.0.0",
- "type" : "stack-extension-definition",
+ "type" : "stack-addon-service-definition",
"source_dir": "custom-services/MYSERVICE/2.0.0",
"service_name" : "MYSERVICE",
"service_version" : "2.0.0",