You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by dm...@apache.org on 2013/12/13 18:21:39 UTC

git commit: AMBARI-4065. Add to hooks ability to include templates&static files (dlysnichenko)

Updated Branches:
  refs/heads/trunk 65aec6617 -> 34b1cb86a


AMBARI-4065. Add to hooks ability to include templates&static files (dlysnichenko)


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

Branch: refs/heads/trunk
Commit: 34b1cb86a2e81cf882dd459ddb9b0ec4d96b3a35
Parents: 65aec66
Author: Lisnichenko Dmitro <dl...@hortonworks.com>
Authored: Fri Dec 13 19:20:49 2013 +0200
Committer: Lisnichenko Dmitro <dl...@hortonworks.com>
Committed: Fri Dec 13 19:21:27 2013 +0200

----------------------------------------------------------------------
 .../ambari_agent/CustomServiceOrchestrator.py   | 26 +++++++++--------
 .../TestCustomServiceOrchestrator.py            |  7 +++--
 .../1.3._/hooks/before-START/scripts/hook.py    | 30 ++++++++++++++++++++
 .../stacks/HDP/2.0._/hooks/before-START.py      | 30 --------------------
 .../2.0._/hooks/before-START/scripts/hook.py    | 30 ++++++++++++++++++++
 5 files changed, 79 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/34b1cb86/ambari-agent/src/main/python/ambari_agent/CustomServiceOrchestrator.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/CustomServiceOrchestrator.py b/ambari-agent/src/main/python/ambari_agent/CustomServiceOrchestrator.py
index 081673d..932f9ec 100644
--- a/ambari-agent/src/main/python/ambari_agent/CustomServiceOrchestrator.py
+++ b/ambari-agent/src/main/python/ambari_agent/CustomServiceOrchestrator.py
@@ -62,7 +62,7 @@ class CustomServiceOrchestrator():
 
       if command_name == self.CUSTOM_ACTION_COMMAND:
         base_dir = self.config.get('python', 'custom_actions_dir')
-        script_path = os.path.join(base_dir, script)
+        script_tuple = (os.path.join(base_dir, script) , base_dir)
         hook_dir = None
       else:
         stack_name = command['hostLevelParams']['stack_name']
@@ -72,6 +72,7 @@ class CustomServiceOrchestrator():
         base_dir = self.file_cache.get_service_base_dir(
           stack_name, stack_version, metadata_folder, component_name)
         script_path = self.resolve_script_path(base_dir, script, script_type)
+        script_tuple = (script_path, base_dir)
 
       tmpstrucoutfile = os.path.join(self.tmp_dir,
                                     "structured-out-{0}.json".format(task_id))
@@ -81,17 +82,17 @@ class CustomServiceOrchestrator():
         raise AgentException(message)
       # Execute command using proper interpreter
       json_path = self.dump_command_to_json(command)
-      script_params = [command_name, json_path, base_dir]
-      pre_hook = self.resolve_hook_script_path(hook_dir,
+      pre_hook_tuple = self.resolve_hook_script_path(hook_dir,
           self.PRE_HOOK_PREFIX, command_name, script_type)
-      post_hook = self.resolve_hook_script_path(hook_dir,
+      post_hook_tuple = self.resolve_hook_script_path(hook_dir,
           self.POST_HOOK_PREFIX, command_name, script_type)
-      py_file_list = [pre_hook, script_path, post_hook]
+      py_file_list = [pre_hook_tuple, script_tuple, post_hook_tuple]
       # filter None values
       filtered_py_file_list = [i for i in py_file_list if i]
       # Executing hooks and script
       ret = None
-      for py_file in filtered_py_file_list:
+      for py_file, current_base_dir in filtered_py_file_list:
+        script_params = [command_name, json_path, current_base_dir]
         ret = self.python_executor.run_file(py_file, script_params,
                                tmpoutfile, tmperrfile, timeout, tmpstrucoutfile)
         if ret['exitcode'] != 0:
@@ -125,19 +126,20 @@ class CustomServiceOrchestrator():
     return path
 
 
-  def resolve_hook_script_path(self, hook_base_dir, prefix, command_name, script_type):
+  def resolve_hook_script_path(self, stack_hooks_dir, prefix, command_name, script_type):
     """
-    Returns a path to hook script according to string prefix
+    Returns a tuple(path to hook script, hook base dir) according to string prefix
     and command name. If script does not exist, returns None
     """
-    if not hook_base_dir:
+    if not stack_hooks_dir:
       return None
-    script_file = "{0}-{1}.py".format(prefix, command_name)
-    hook_script_path = os.path.join(hook_base_dir, script_file)
+    hook_dir = "{0}-{1}".format(prefix, command_name)
+    hook_base_dir = os.path.join(stack_hooks_dir, hook_dir)
+    hook_script_path = os.path.join(hook_base_dir, "scripts", "hook.py")
     if not os.path.isfile(hook_script_path):
       logger.debug("Hook script {0} not found, skipping".format(hook_script_path))
       return None
-    return hook_script_path
+    return hook_script_path, hook_base_dir
 
 
   def dump_command_to_json(self, command):

http://git-wip-us.apache.org/repos/asf/ambari/blob/34b1cb86/ambari-agent/src/test/python/ambari_agent/TestCustomServiceOrchestrator.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/test/python/ambari_agent/TestCustomServiceOrchestrator.py b/ambari-agent/src/test/python/ambari_agent/TestCustomServiceOrchestrator.py
index f4bb55a..ec72ffe 100644
--- a/ambari-agent/src/test/python/ambari_agent/TestCustomServiceOrchestrator.py
+++ b/ambari-agent/src/test/python/ambari_agent/TestCustomServiceOrchestrator.py
@@ -126,7 +126,9 @@ class TestCustomServiceOrchestrator(TestCase):
     }
     get_service_base_dir_mock.return_value = "/basedir/"
     resolve_script_path_mock.return_value = "/basedir/scriptpath"
-    resolve_hook_script_path_mock.return_value = "/basedir/hooks/hookpath"
+    resolve_hook_script_path_mock.return_value = \
+      ('/hooks_dir/prefix-command/scripts/hook.py',
+       '/hooks_dir/prefix-command')
     orchestrator = CustomServiceOrchestrator(self.config)
     get_hook_base_dir_mock.return_value = "/hooks/"
     # normal run case
@@ -191,7 +193,8 @@ class TestCustomServiceOrchestrator(TestCase):
     isfile_mock.return_value = True
     res2 = orchestrator.resolve_hook_script_path("/hooks_dir/", "prefix", "command",
                                             "script_type")
-    self.assertEqual(res2, "/hooks_dir/prefix-command.py")
+    self.assertEqual(res2, ('/hooks_dir/prefix-command/scripts/hook.py',
+                            '/hooks_dir/prefix-command'))
     # Testing not existing hook script
     isfile_mock.return_value = False
     res3 = orchestrator.resolve_hook_script_path("/hooks_dir/", "prefix", "command",

http://git-wip-us.apache.org/repos/asf/ambari/blob/34b1cb86/ambari-server/src/main/resources/stacks/HDP/1.3._/hooks/before-START/scripts/hook.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/1.3._/hooks/before-START/scripts/hook.py b/ambari-server/src/main/resources/stacks/HDP/1.3._/hooks/before-START/scripts/hook.py
new file mode 100644
index 0000000..378b2d2
--- /dev/null
+++ b/ambari-server/src/main/resources/stacks/HDP/1.3._/hooks/before-START/scripts/hook.py
@@ -0,0 +1,30 @@
+##!/usr/bin/env python2.6
+"""
+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.
+
+"""
+
+import sys
+from resource_management import *
+
+class BeforeStartHook(Hook):
+
+  def hook(self, env):
+    Execute(("touch", "/tmp/hook-test"))
+
+if __name__ == "__main__":
+  BeforeStartHook().execute()

http://git-wip-us.apache.org/repos/asf/ambari/blob/34b1cb86/ambari-server/src/main/resources/stacks/HDP/2.0._/hooks/before-START.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0._/hooks/before-START.py b/ambari-server/src/main/resources/stacks/HDP/2.0._/hooks/before-START.py
deleted file mode 100644
index 378b2d2..0000000
--- a/ambari-server/src/main/resources/stacks/HDP/2.0._/hooks/before-START.py
+++ /dev/null
@@ -1,30 +0,0 @@
-##!/usr/bin/env python2.6
-"""
-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.
-
-"""
-
-import sys
-from resource_management import *
-
-class BeforeStartHook(Hook):
-
-  def hook(self, env):
-    Execute(("touch", "/tmp/hook-test"))
-
-if __name__ == "__main__":
-  BeforeStartHook().execute()

http://git-wip-us.apache.org/repos/asf/ambari/blob/34b1cb86/ambari-server/src/main/resources/stacks/HDP/2.0._/hooks/before-START/scripts/hook.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/stacks/HDP/2.0._/hooks/before-START/scripts/hook.py b/ambari-server/src/main/resources/stacks/HDP/2.0._/hooks/before-START/scripts/hook.py
new file mode 100644
index 0000000..378b2d2
--- /dev/null
+++ b/ambari-server/src/main/resources/stacks/HDP/2.0._/hooks/before-START/scripts/hook.py
@@ -0,0 +1,30 @@
+##!/usr/bin/env python2.6
+"""
+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.
+
+"""
+
+import sys
+from resource_management import *
+
+class BeforeStartHook(Hook):
+
+  def hook(self, env):
+    Execute(("touch", "/tmp/hook-test"))
+
+if __name__ == "__main__":
+  BeforeStartHook().execute()