Repository: ambari
Updated Branches:
  refs/heads/branch-2.5 51408ab69 -> b117a56b1


AMBARI-19293. Component install and after-install should not run in parallel 
(Attila Doroszlai via magyari_sandor)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/b117a56b
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/b117a56b
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/b117a56b

Branch: refs/heads/branch-2.5
Commit: b117a56b1326eaa8db0929aacde21906543d7ec7
Parents: 51408ab
Author: Attila Doroszlai <adorosz...@hortonworks.com>
Authored: Fri Jan 13 13:55:43 2017 +0100
Committer: Sandor Magyari <smagy...@hortonworks.com>
Committed: Fri Jan 13 14:03:02 2017 +0100

----------------------------------------------------------------------
 .../libraries/script/script.py                  | 26 ++++++++++++++++++++
 .../2.0.6/hooks/after-INSTALL/scripts/params.py |  3 ++-
 2 files changed, 28 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/b117a56b/ambari-common/src/main/python/resource_management/libraries/script/script.py
----------------------------------------------------------------------
diff --git 
a/ambari-common/src/main/python/resource_management/libraries/script/script.py 
b/ambari-common/src/main/python/resource_management/libraries/script/script.py
index 9f1bb11..6fb7b2e 100644
--- 
a/ambari-common/src/main/python/resource_management/libraries/script/script.py
+++ 
b/ambari-common/src/main/python/resource_management/libraries/script/script.py
@@ -55,6 +55,7 @@ from contextlib import closing
 from resource_management.libraries.functions.stack_features import 
check_stack_feature
 from resource_management.libraries.functions.constants import StackFeature
 from resource_management.libraries.functions.show_logs import show_logs
+from resource_management.libraries.functions.fcntl_based_process_lock import 
FcntlBasedProcessLock
 
 import ambari_simplejson as json # simplejson is much faster comparing to 
Python 2.6 json module and has the same functions set.
 
@@ -94,7 +95,32 @@ def get_path_from_configuration(name, configuration):
 
   return configuration
 
+def get_config_lock_file():
+  return os.path.join(Script.get_tmp_dir(), "link_configs_lock_file")
+
+class LockedConfigureMeta(type):
+  '''
+  This metaclass ensures that Script.configure() is invoked with a fcntl-based 
process lock
+  if necessary (when Ambari Agent is configured to execute tasks concurrently) 
for all subclasses.
+  '''
+  def __new__(meta, classname, supers, classdict):
+    if 'configure' in classdict:
+      original_configure = classdict['configure']
+
+      def locking_configure(obj, *args, **kw):
+        # local import to avoid circular dependency (default imports Script)
+        from resource_management.libraries.functions.default import default
+        parallel_execution_enabled = 
int(default("/agentConfigParams/agent/parallel_execution", 0)) == 1
+        lock = FcntlBasedProcessLock(get_config_lock_file(), 
skip_fcntl_failures = True, enabled = parallel_execution_enabled)
+        with lock:
+          original_configure(obj, *args, **kw)
+
+      classdict['configure'] = locking_configure
+
+    return type.__new__(meta, classname, supers, classdict)
+
 class Script(object):
+  __metaclass__ = LockedConfigureMeta
 
   instance = None
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/b117a56b/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/after-INSTALL/scripts/params.py
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/after-INSTALL/scripts/params.py
 
b/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/after-INSTALL/scripts/params.py
index ed34217..1782298 100644
--- 
a/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/after-INSTALL/scripts/params.py
+++ 
b/ambari-server/src/main/resources/stacks/HDP/2.0.6/hooks/after-INSTALL/scripts/params.py
@@ -21,6 +21,7 @@ import os
 
 from ambari_commons.constants import AMBARI_SUDO_BINARY
 from resource_management.libraries.script import Script
+from resource_management.libraries.script.script import get_config_lock_file
 from resource_management.libraries.functions import default
 from resource_management.libraries.functions import conf_select
 from resource_management.libraries.functions import stack_select
@@ -96,7 +97,7 @@ has_namenode = not len(namenode_host) == 0
 if has_namenode or dfs_type == 'HCFS':
   hadoop_conf_dir = 
conf_select.get_hadoop_conf_dir(force_latest_on_upgrade=True)
 
-link_configs_lock_file = os.path.join(tmp_dir, "link_configs_lock_file")
+link_configs_lock_file = get_config_lock_file()
 stack_select_lock_file = os.path.join(tmp_dir, "stack_select_lock_file")
 
 upgrade_suspended = default("/roleParams/upgrade_suspended", False)

Reply via email to