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 2015/03/13 00:51:48 UTC

ambari git commit: AMBARI-10054: Standby namenode bootstrapped on every restart in HA Blueprint deployment (jluniya)

Repository: ambari
Updated Branches:
  refs/heads/trunk ad8536b95 -> 7b1500ef5


AMBARI-10054: Standby namenode bootstrapped on every restart in HA Blueprint deployment (jluniya)


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

Branch: refs/heads/trunk
Commit: 7b1500ef568ee8de0187d65901360344294a3ec3
Parents: ad8536b
Author: Jayush Luniya <jl...@hortonworks.com>
Authored: Thu Mar 12 16:51:43 2015 -0700
Committer: Jayush Luniya <jl...@hortonworks.com>
Committed: Thu Mar 12 16:51:43 2015 -0700

----------------------------------------------------------------------
 .../2.1.0.2.0/package/scripts/hdfs_namenode.py  | 50 +++++++++++++++-----
 .../python/stacks/2.0.6/HDFS/test_namenode.py   |  9 ++--
 2 files changed, 43 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/7b1500ef/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/scripts/hdfs_namenode.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/scripts/hdfs_namenode.py b/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/scripts/hdfs_namenode.py
index 32240a1..c89eeba 100644
--- a/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/scripts/hdfs_namenode.py
+++ b/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/scripts/hdfs_namenode.py
@@ -19,6 +19,7 @@ limitations under the License.
 import os.path
 
 from resource_management import *
+from resource_management.core.logger import Logger
 from resource_management.core.exceptions import ComponentIsNotRunning
 
 from utils import service, safe_zkfc_op
@@ -54,8 +55,9 @@ def namenode(action=None, do_format=True, rolling_restart=False, env=None):
         # run the bootstrap command, to start the NameNode in standby mode
         # this requires that the active NameNode is already up and running,
         # so this execute should be re-tried upon failure, up to a timeout
-        Execute("hdfs namenode -bootstrapStandby",
-          user = params.hdfs_user, tries=50)
+        success = bootstrap_standby_namenode(params)
+        if not success:
+          raise Fail("Could not bootstrap standby namenode")
 
     options = "-rollingUpgrade started" if rolling_restart else ""
 
@@ -180,15 +182,21 @@ def format_namenode(force=None):
       if params.hostname == params.dfs_ha_namenode_active:
         # check and run the format command in the HA deployment scenario
         # only format the "active" namenode in an HA deployment
-        Execute(format("yes Y | hdfs --config {hadoop_conf_dir} namenode -format"),
-                user = params.hdfs_user,
-                path = [params.hadoop_bin_dir]
-        )
-        for m_dir in mark_dir:
-          Directory(m_dir,
-            recursive = True
-        )
-
+        if force:
+          ExecuteHadoop('namenode -format',
+                        kinit_override=True,
+                        bin_dir=params.hadoop_bin_dir,
+                        conf_dir=hadoop_conf_dir)
+        else:
+          if not is_namenode_formatted(params):
+            Execute(format("yes Y | hdfs --config {hadoop_conf_dir} namenode -format"),
+                    user = params.hdfs_user,
+                    path = [params.hadoop_bin_dir]
+            )
+            for m_dir in mark_dir:
+              Directory(m_dir,
+                recursive = True
+              )
 
 def is_namenode_formatted(params):
   old_mark_dirs = params.namenode_formatted_old_mark_dirs
@@ -273,3 +281,23 @@ def decommission():
                   conf_dir=conf_dir,
                   kinit_override=True,
                   bin_dir=params.hadoop_bin_dir)
+
+def bootstrap_standby_namenode(params):
+  try:
+    iterations = 50
+    bootstrap_cmd = "hdfs namenode -bootstrapStandby -nonInteractive"
+    Logger.info("Boostrapping standby namenode: %s" % (bootstrap_cmd))
+    for i in range(iterations):
+      Logger.info('Try %d out of %d' % (i+1, iterations))
+      code, out = shell.call(bootstrap_cmd, logoutput=True, user=params.hdfs_user)
+      if code == 0:
+        Logger.info("Standby namenode bootstrapped successfully")
+        return True
+      elif code == 5:
+        Logger.info("Standby namenode already bootstrapped")
+        return True
+      else:
+        Logger.warning('Bootstrap standby namenode failed with %d error code. Will retry' % (code))
+  except Exception as ex:
+    Logger.error('Bootstrap standby namenode threw an exception. Reason %s' %(str(ex)))
+  return False
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/7b1500ef/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_namenode.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_namenode.py b/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_namenode.py
index a8ab797..8f9a576 100644
--- a/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_namenode.py
+++ b/ambari-server/src/test/python/stacks/2.0.6/HDFS/test_namenode.py
@@ -27,7 +27,7 @@ from resource_management.core import shell
 from resource_management.core.exceptions import Fail
 
 
-@patch.object(shell, "call", new=MagicMock(return_value=(1,"")))
+@patch.object(shell, "call", new=MagicMock(return_value=(5,"")))
 class TestNamenode(RMFTestCase):
   COMMON_SERVICES_PACKAGE_DIR = "HDFS/2.1.0.2.0/package"
   STACK_VERSION = "2.0.6"
@@ -443,6 +443,7 @@ class TestNamenode(RMFTestCase):
     self.assert_configure_default()
 
     # verify that active namenode was formatted
+    self.assertResourceCalled('Execute', 'ls /hadoop/hdfs/namenode | wc -l  | grep -q ^0$',)
     self.assertResourceCalled('Execute', 'yes Y | hdfs --config /etc/hadoop/conf namenode -format',
         path = ['/usr/bin'],
         user = 'hdfs',
@@ -541,11 +542,9 @@ class TestNamenode(RMFTestCase):
                               mode = 0755
     )
 
-    # verify that the standby case is detected, and that the bootstrap
+    # TODO: Using shell.call() to bootstrap standby which is patched to return status code '5' (i.e. already bootstrapped)
+    # Need to update the test case to verify that the standby case is detected, and that the bootstrap
     # command is run before the namenode launches
-    self.assertResourceCalled('Execute', 'hdfs namenode -bootstrapStandby',
-                              user = 'hdfs', tries=50)
-
     self.assertResourceCalled('Directory', '/var/run/hadoop/hdfs',
                               owner = 'hdfs',
                               recursive = True,