<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: Query the Active Name Node from an Oozie Job in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Query-the-Active-Name-Node-from-an-Oozie-Job/m-p/34895#M11566</link>
    <description>&lt;P&gt;You can use a script such as below to grab &lt;STRONG&gt;active&lt;/STRONG&gt;/&lt;STRONG&gt;standby&lt;/STRONG&gt; states:&lt;/P&gt;&lt;PRE&gt;# Grab the IDs from the nameservice key 
NNS=$(hdfs getconf -confKey dfs.ha.namenodes.nameservice1) 
# Convert to a proper bash array, delimiting on comma 
NNSA=(${NNS/,/ }) 
# Lookup state for both 
STATEA=$(sudo -u hdfs hdfs haadmin -getServiceState ${NNSA[0]}) 
STATEB=$(sudo -u hdfs hdfs haadmin -getServiceState ${NNSA[1]}) 
# Test for &lt;SPAN class="lG"&gt;active&lt;/SPAN&gt; state 
if [ "$STATEA" == "&lt;SPAN class="lG"&gt;active&lt;/SPAN&gt;" ] 
then 
ANN=${NNSA[0]} 
else 
ANN=${NNSA[1]} 
fi 
# Print the host and port of NN that is &lt;SPAN class="lG"&gt;active&lt;/SPAN&gt; 
ANNHOSTPORT=$(hdfs getconf -confKey dfs.namenode.rpc-address.nameservice1.$ANN)&lt;BR /&gt;echo $ANNHOSTPORT&lt;/PRE&gt;&lt;P&gt;This (haadmin commands)&amp;nbsp;may&amp;nbsp;however require admin privileges, i.e. the '&lt;STRONG&gt;hdfs&lt;/STRONG&gt;' user or a member of the &lt;EM&gt;configured supergroup&lt;/EM&gt;, to run.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Are you running some non-Java based WebHDFS REST queries that require knowledge of the active NameNode? Just looking to understand why knowing the active seems necessary for your operation.&lt;/P&gt;</description>
    <pubDate>Tue, 08 Dec 2015 06:23:26 GMT</pubDate>
    <dc:creator>Harsh J</dc:creator>
    <dc:date>2015-12-08T06:23:26Z</dc:date>
    <item>
      <title>Query the Active Name Node from an Oozie Job</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Query-the-Active-Name-Node-from-an-Oozie-Job/m-p/34893#M11565</link>
      <description>&lt;P&gt;I am using Cloudera 5.4.1. I have authored an oozie workflow. in one of the tasks, I need to use Oozie EL to generate a string which contains the URL of the "active" name node.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My cloudera cluster has active and secondary name nodes. At any point of time, I need to be able to dynamically query which is the active name node.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been looking around the internet but have found no answer. This is what I have thought&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Use the SSH Oozie task to execute `hdfs getconfig -namenode` but the problem is that this command returns everything and not just the name of the active name node.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. Use Cloudera Manager REST API to query the active name node. I have not seen any documentation or example which would allow me to do this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If possible, please be kind enough to let me know how can I query and dynamically determine the active name node of a hadoop cluster&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2022 09:51:41 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Query-the-Active-Name-Node-from-an-Oozie-Job/m-p/34893#M11565</guid>
      <dc:creator>abhishes</dc:creator>
      <dc:date>2022-09-16T09:51:41Z</dc:date>
    </item>
    <item>
      <title>Re: Query the Active Name Node from an Oozie Job</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Query-the-Active-Name-Node-from-an-Oozie-Job/m-p/34895#M11566</link>
      <description>&lt;P&gt;You can use a script such as below to grab &lt;STRONG&gt;active&lt;/STRONG&gt;/&lt;STRONG&gt;standby&lt;/STRONG&gt; states:&lt;/P&gt;&lt;PRE&gt;# Grab the IDs from the nameservice key 
NNS=$(hdfs getconf -confKey dfs.ha.namenodes.nameservice1) 
# Convert to a proper bash array, delimiting on comma 
NNSA=(${NNS/,/ }) 
# Lookup state for both 
STATEA=$(sudo -u hdfs hdfs haadmin -getServiceState ${NNSA[0]}) 
STATEB=$(sudo -u hdfs hdfs haadmin -getServiceState ${NNSA[1]}) 
# Test for &lt;SPAN class="lG"&gt;active&lt;/SPAN&gt; state 
if [ "$STATEA" == "&lt;SPAN class="lG"&gt;active&lt;/SPAN&gt;" ] 
then 
ANN=${NNSA[0]} 
else 
ANN=${NNSA[1]} 
fi 
# Print the host and port of NN that is &lt;SPAN class="lG"&gt;active&lt;/SPAN&gt; 
ANNHOSTPORT=$(hdfs getconf -confKey dfs.namenode.rpc-address.nameservice1.$ANN)&lt;BR /&gt;echo $ANNHOSTPORT&lt;/PRE&gt;&lt;P&gt;This (haadmin commands)&amp;nbsp;may&amp;nbsp;however require admin privileges, i.e. the '&lt;STRONG&gt;hdfs&lt;/STRONG&gt;' user or a member of the &lt;EM&gt;configured supergroup&lt;/EM&gt;, to run.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Are you running some non-Java based WebHDFS REST queries that require knowledge of the active NameNode? Just looking to understand why knowing the active seems necessary for your operation.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Dec 2015 06:23:26 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Query-the-Active-Name-Node-from-an-Oozie-Job/m-p/34895#M11566</guid>
      <dc:creator>Harsh J</dc:creator>
      <dc:date>2015-12-08T06:23:26Z</dc:date>
    </item>
    <item>
      <title>Re: Query the Active Name Node from an Oozie Job</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Query-the-Active-Name-Node-from-an-Oozie-Job/m-p/34896#M11567</link>
      <description>&lt;P&gt;The reason why this solution will not work for me is because haadmin requires super user (HDFS Admin) permission to run.&lt;BR /&gt;&lt;BR /&gt;This is absolutely impossible for a remote machine to provide.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Dec 2015 06:31:38 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Query-the-Active-Name-Node-from-an-Oozie-Job/m-p/34896#M11567</guid>
      <dc:creator>abhishes</dc:creator>
      <dc:date>2015-12-08T06:31:38Z</dc:date>
    </item>
    <item>
      <title>Re: Query the Active Name Node from an Oozie Job</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Query-the-Active-Name-Node-from-an-Oozie-Job/m-p/34900#M11568</link>
      <description>Yes that is true, and I did note as much.&lt;BR /&gt;&lt;BR /&gt;If you are writing an EL function in Java, you can also rely on the&lt;BR /&gt;StandbyException when connecting to explicit hostnames, to detect the&lt;BR /&gt;active (i.e. one that does not return the exception). This is the way the&lt;BR /&gt;Java client discovers the active NN.&lt;BR /&gt;&lt;BR /&gt;The CM API method can work if you query the role instances directly:&lt;BR /&gt;&lt;A href="http://cloudera.github.io/cm_api/apidocs/v9/path__clusters_-clusterName-_services_-serviceName-_roles_-roleName-.html#GET." target="_blank"&gt;http://cloudera.github.io/cm_api/apidocs/v9/path__clusters_-clusterName-_services_-serviceName-_roles_-roleName-.html#GET.&lt;/A&gt;&lt;BR /&gt;The returned apiRole object, on applicable roles such as NameNode or&lt;BR /&gt;ResourceManager, has a flag for "haStatus" (HA status) as described at&lt;BR /&gt;&lt;A href="http://cloudera.github.io/cm_api/apidocs/v9/ns0_apiRole.html" target="_blank"&gt;http://cloudera.github.io/cm_api/apidocs/v9/ns0_apiRole.html&lt;/A&gt; (and&lt;BR /&gt;&lt;A href="http://cloudera.github.io/cm_api/apidocs/v9/ns0_haStatus.html)" target="_blank"&gt;http://cloudera.github.io/cm_api/apidocs/v9/ns0_haStatus.html)&lt;/A&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 08 Dec 2015 08:28:52 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Query-the-Active-Name-Node-from-an-Oozie-Job/m-p/34900#M11568</guid>
      <dc:creator>Harsh J</dc:creator>
      <dc:date>2015-12-08T08:28:52Z</dc:date>
    </item>
    <item>
      <title>Re: Query the Active Name Node from an Oozie Job</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Query-the-Active-Name-Node-from-an-Oozie-Job/m-p/34973#M11569</link>
      <description>&lt;P&gt;OK. The cloudera manager API solution looks good&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://cloudera.mycompany.com/api/v9/clusters/cluster2/services/hdfs1/roles" target="_blank"&gt;http://cloudera.mycompany.com/api/v9/clusters/cluster2/services/hdfs1/roles&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output is comprehensive... but it doesn't have the machine name anywhere.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;{
    "name" : "hdfs1-NAMENODE-f307e0a1ebd0702da50cbfb68356cadf",
    "type" : "NAMENODE",
    "serviceRef" : {
      "clusterName" : "cluster2",
      "serviceName" : "hdfs1"
    },
    "hostRef" : {
      "hostId" : "01008a9e-8b44-4e73-bc29-510fbe00b632"
    },
    "roleUrl" : "http://clouderamgr01.mycompany.com:7180/cmf/roleRedirect/hdfs1-NAMENODE-f307e0a1ebd0702da50cbfb68356cadf",
    "roleState" : "STARTED",
    "healthSummary" : "GOOD",
    "healthChecks" : [ {
      "name" : "NAME_NODE_DATA_DIRECTORIES_FREE_SPACE",
      "summary" : "GOOD"
    }, {
      "name" : "NAME_NODE_DIRECTORY_FAILURES",
      "summary" : "GOOD"
    }, {
      "name" : "NAME_NODE_FILE_DESCRIPTOR",
      "summary" : "GOOD"
    }, {
      "name" : "NAME_NODE_HA_CHECKPOINT_AGE",
      "summary" : "DISABLED"
    }, {
      "name" : "NAME_NODE_HEAP_DUMP_DIRECTORY_FREE_SPACE",
      "summary" : "DISABLED"
    }, {
      "name" : "NAME_NODE_HOST_HEALTH",
      "summary" : "GOOD"
    }, {
      "name" : "NAME_NODE_JOURNAL_NODE_SYNC_STATUS",
      "summary" : "DISABLED"
    }, {
      "name" : "NAME_NODE_LOG_DIRECTORY_FREE_SPACE",
      "summary" : "GOOD"
    }, {
      "name" : "NAME_NODE_PAUSE_DURATION",
      "summary" : "GOOD"
    }, {
      "name" : "NAME_NODE_ROLLING_UPGRADE_STATUS",
      "summary" : "GOOD"
    }, {
      "name" : "NAME_NODE_RPC_LATENCY",
      "summary" : "DISABLED"
    }, {
      "name" : "NAME_NODE_SAFE_MODE",
      "summary" : "GOOD"
    }, {
      "name" : "NAME_NODE_SCM_HEALTH",
      "summary" : "GOOD"
    }, {
      "name" : "NAME_NODE_SWAP_MEMORY_USAGE",
      "summary" : "GOOD"
    }, {
      "name" : "NAME_NODE_UNEXPECTED_EXITS",
      "summary" : "GOOD"
    }, {
      "name" : "NAME_NODE_UPGRADE_STATUS",
      "summary" : "GOOD"
    }, {
      "name" : "NAME_NODE_WEB_METRIC_COLLECTION",
      "summary" : "GOOD"
    } ],
    "configStalenessStatus" : "FRESH",
    "haStatus" : "STANDBY",
    "maintenanceMode" : false,
    "maintenanceOwners" : [ ],
    "commissionState" : "COMMISSIONED",
    "roleConfigGroupRef" : {
      "roleConfigGroupName" : "hdfs1-NAMENODE-BASE"
    }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;{
    "name" : "hdfs1-NAMENODE-e8e705638eaaa8233bd2729af511f874",
    "type" : "NAMENODE",
    "serviceRef" : {
      "clusterName" : "cluster2",
      "serviceName" : "hdfs1"
    },
    "hostRef" : {
      "hostId" : "4127ba89-71a8-4a27-af75-51900f9f0a2e"
    },
    "roleUrl" : "http://clouderamgr01.mycompany.com:7180/cmf/roleRedirect/hdfs1-NAMENODE-e8e705638eaaa8233bd2729af511f874",
    "roleState" : "STARTED",
    "healthSummary" : "GOOD",
    "healthChecks" : [ {
      "name" : "NAME_NODE_DATA_DIRECTORIES_FREE_SPACE",
      "summary" : "GOOD"
    }, {
      "name" : "NAME_NODE_DIRECTORY_FAILURES",
      "summary" : "GOOD"
    }, {
      "name" : "NAME_NODE_FILE_DESCRIPTOR",
      "summary" : "GOOD"
    }, {
      "name" : "NAME_NODE_HA_CHECKPOINT_AGE",
      "summary" : "GOOD"
    }, {
      "name" : "NAME_NODE_HEAP_DUMP_DIRECTORY_FREE_SPACE",
      "summary" : "DISABLED"
    }, {
      "name" : "NAME_NODE_HOST_HEALTH",
      "summary" : "GOOD"
    }, {
      "name" : "NAME_NODE_JOURNAL_NODE_SYNC_STATUS",
      "summary" : "GOOD"
    }, {
      "name" : "NAME_NODE_LOG_DIRECTORY_FREE_SPACE",
      "summary" : "GOOD"
    }, {
      "name" : "NAME_NODE_PAUSE_DURATION",
      "summary" : "GOOD"
    }, {
      "name" : "NAME_NODE_ROLLING_UPGRADE_STATUS",
      "summary" : "GOOD"
    }, {
      "name" : "NAME_NODE_RPC_LATENCY",
      "summary" : "GOOD"
    }, {
      "name" : "NAME_NODE_SAFE_MODE",
      "summary" : "GOOD"
    }, {
      "name" : "NAME_NODE_SCM_HEALTH",
      "summary" : "GOOD"
    }, {
      "name" : "NAME_NODE_SWAP_MEMORY_USAGE",
      "summary" : "GOOD"
    }, {
      "name" : "NAME_NODE_UNEXPECTED_EXITS",
      "summary" : "GOOD"
    }, {
      "name" : "NAME_NODE_UPGRADE_STATUS",
      "summary" : "GOOD"
    }, {
      "name" : "NAME_NODE_WEB_METRIC_COLLECTION",
      "summary" : "GOOD"
    } ],
    "configStalenessStatus" : "FRESH",
    "haStatus" : "ACTIVE",
    "maintenanceMode" : false,
    "maintenanceOwners" : [ ],
    "commissionState" : "COMMISSIONED",
    "roleConfigGroupRef" : {
      "roleConfigGroupName" : "hdfs1-NAMENODE-BASE"
    }&lt;/PRE&gt;&lt;P&gt;The following is the screenshot from the cloudera manager UI. which clearly shows 02 as standby&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://community.cloudera.com/t5/image/serverpage/image-id/1332i497FFEF814688677/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="Screen Shot 2015-12-09 at 9.23.06 AM.png" title="Screen Shot 2015-12-09 at 9.23.06 AM.png" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I take the hostId provided by the Json above and then do a&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://cloudera.mycompany.com/api/v9/clusters/cluster2/hosts/01008a9e-8b44-4e73-bc29-510fbe00b632" target="_blank"&gt;http://cloudera.mycompany.com/api/v9/clusters/cluster2/hosts/01008a9e-8b44-4e73-bc29-510fbe00b632&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but this only gives me a blank page. So I cannot get machine name.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Dec 2015 15:42:38 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Query-the-Active-Name-Node-from-an-Oozie-Job/m-p/34973#M11569</guid>
      <dc:creator>abhishes</dc:creator>
      <dc:date>2015-12-09T15:42:38Z</dc:date>
    </item>
    <item>
      <title>Re: Query the Active Name Node from an Oozie Job</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Query-the-Active-Name-Node-from-an-Oozie-Job/m-p/34976#M11570</link>
      <description>The role level APIs carry the state, but you're querying the service level.&lt;BR /&gt;Use the role IDs from the service level to then query the roles directly.&lt;BR /&gt;</description>
      <pubDate>Wed, 09 Dec 2015 15:32:52 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Query-the-Active-Name-Node-from-an-Oozie-Job/m-p/34976#M11570</guid>
      <dc:creator>Harsh J</dc:creator>
      <dc:date>2015-12-09T15:32:52Z</dc:date>
    </item>
  </channel>
</rss>

