AMBARI-18262 - When Enabling NameNode HA Via the UI Wizard, the Second NN Fails to Start (jonathanhurley)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/9c0a95de Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/9c0a95de Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/9c0a95de Branch: refs/heads/branch-2.4 Commit: 9c0a95de9b3a29bfc05b5abbf0fa0b41b5fef8a2 Parents: 69e5920 Author: Jonathan Hurley <[email protected]> Authored: Thu Aug 25 12:18:45 2016 -0400 Committer: Sumit Mohanty <[email protected]> Committed: Mon Aug 29 18:33:24 2016 -0700 ---------------------------------------------------------------------- .../2.1.0.2.0/package/scripts/hdfs_namenode.py | 21 ++++++----- .../python/stacks/2.0.6/HDFS/test_namenode.py | 38 ++++++++++++++++++++ 2 files changed, 51 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/9c0a95de/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 63d72aa..db52ee1 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 @@ -525,23 +525,28 @@ def is_this_namenode_active(): # returns ([('nn1', 'c6401.ambari.apache.org:50070')], [('nn2', 'c6402.ambari.apache.org:50070')], []) # 0 1 2 + # or + # returns ([], [('nn1', 'c6401.ambari.apache.org:50070')], [('nn2', 'c6402.ambari.apache.org:50070')], []) + # 0 1 2 # namenode_states = namenode_ha_utils.get_namenode_states(params.hdfs_site, params.security_enabled, params.hdfs_user, times=5, sleep_time=5, backoff_factor=2) - # unwraps ('nn1', 'c6401.ambari.apache.org:50070') - active_namenodes = [] if len(namenode_states[0]) < 1 else namenode_states[0][0] + # unwraps [('nn1', 'c6401.ambari.apache.org:50070')] + active_namenodes = [] if len(namenode_states[0]) < 1 else namenode_states[0] - # unwraps ('nn2', 'c6402.ambari.apache.org:50070') - standby_namenodes = [] if len(namenode_states[1]) < 1 else namenode_states[1][0] + # unwraps [('nn2', 'c6402.ambari.apache.org:50070')] + standby_namenodes = [] if len(namenode_states[1]) < 1 else namenode_states[1] # check to see if this is the active NameNode - if params.namenode_id in active_namenodes: - return True + for entry in active_namenodes: + if params.namenode_id in entry: + return True # if this is not the active NameNode, then we must wait for it to register as standby - if params.namenode_id in standby_namenodes: - return False + for entry in standby_namenodes: + if params.namenode_id in entry: + return False # this this point, this NameNode is neither active nor standby - we must wait to ensure it # enters at least one of these roles before returning a verdict - the annotation will catch http://git-wip-us.apache.org/repos/asf/ambari/blob/9c0a95de/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 dae5329..4cfa2b2 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 @@ -1786,6 +1786,44 @@ class TestNamenode(RMFTestCase): self.assertNoMoreResources() + @patch.object(time, "sleep") + @patch("resource_management.libraries.functions.namenode_ha_utils.get_namenode_states") + def test_namenode_active_detection_works_with_tuples(self, get_namenode_states_mock, sleep_mock): + """ + Checks to ensure that when detecting the NN state, we take into account that both NNs could + be returned with the same state forcing us to iterate over the tuple to find the right one + """ + import params + from hdfs_namenode import is_this_namenode_active + + # mock out the NN ID + params.namenode_id = "nn1" + + # first test the singular case + active_namenodes = [('nn1', 'c6401.ambari.apache.org:50070')] + standby_namenodes = [('nn2', 'c6402.ambari.apache.org:50070')] + unknown_namenodes = [] + + get_namenode_states_mock.return_value = active_namenodes, standby_namenodes, unknown_namenodes + self.assertTrue(is_this_namenode_active()) + + # now test the harder tuple + active_namenodes = [('nn1', 'c6401.ambari.apache.org:50070'), ('nn2', 'c6402.ambari.apache.org:50070')] + standby_namenodes = [] + unknown_namenodes = [] + + get_namenode_states_mock.return_value = active_namenodes, standby_namenodes, unknown_namenodes + self.assertTrue(is_this_namenode_active()) + + # and the negative for good measure + active_namenodes = [] + standby_namenodes = [('nn1', 'c6401.ambari.apache.org:50070'), ('nn2', 'c6402.ambari.apache.org:50070')] + unknown_namenodes = [] + + get_namenode_states_mock.return_value = active_namenodes, standby_namenodes, unknown_namenodes + self.assertFalse(is_this_namenode_active()) + + class Popen_Mock: return_value = 1 lines = ['Time Stamp Iteration# Bytes Already Moved Bytes Left To Move Bytes Being Moved\n',
