private void doNameNodeHAUpdateOnClusterCreation(Configuration clusterConfig,
                                                   Map<String, Map<String, String>> clusterProps,
                                                   Set<String> configTypesUpdated) throws ConfigurationTopologyException {

    final Collection<String> nnHosts = clusterTopology.getHostAssignmentsForComponent("NAMENODE");

    // external namenodes
    if (nnHosts.isEmpty()) {
      LOG.info("NAMENODE HA is enabled but there are no NAMENODE components in the cluster. Assuming external name nodes.");
      // need to redo validation here as required information (explicit hostnames for some host groups) may have been
      // missing by the time the ClusterTopology object was validated
      try {
        new NameNodeHaValidator().validateExternalNamenodeHa(clusterTopology);
      }
      catch (InvalidTopologyException ex) {
        throw new ConfigurationTopologyException(ex.getMessage(), ex);
      }
      return;
    }

    // add "dfs.internal.nameservices" if it's not specified
    Map<String, String> hdfsSiteConfig = clusterConfig.getFullProperties().get("hdfs-site");
    String nameservices = hdfsSiteConfig.get("dfs.nameservices");
    String int_nameservices = hdfsSiteConfig.get("dfs.internal.nameservices");
    if(int_nameservices == null && nameservices != null) {
      clusterConfig.setProperty("hdfs-site", "dfs.internal.nameservices", nameservices);
    }

    // parse out the nameservices value
    String[] parsedNameServices = parseNameServices(hdfsSiteConfig);

    // if a single nameservice is configured (default HDFS HA deployment)
    if (parsedNameServices.length == 1) {
      LOG.info("Processing a single HDFS NameService, which indicates a default HDFS NameNode HA deployment");
      // if the active/standby namenodes are not specified, assign them automatically
      if (! isNameNodeHAInitialActiveNodeSet(clusterProps) && ! isNameNodeHAInitialStandbyNodeSet(clusterProps)) {
        if (nnHosts.size() == 1) { // can't be 0 as in that case was handled above
          throw new ConfigurationTopologyException("NAMENODE HA requires at least two hosts running NAMENODE but there is " +
            "only one: " + nnHosts.iterator().next());
        }

        // set the properties that configure which namenode is active,
        // and which is a standby node in this HA deployment
        Iterator<String> nnHostIterator = nnHosts.iterator();
        clusterConfig.setProperty(HDFS_HA_INITIAL_CONFIG_TYPE, HDFS_ACTIVE_NAMENODE_PROPERTY_NAME, nnHostIterator.next());
        clusterConfig.setProperty(HDFS_HA_INITIAL_CONFIG_TYPE, HDFS_STANDBY_NAMENODE_PROPERTY_NAME, nnHostIterator.next());

        configTypesUpdated.add(HDFS_HA_INITIAL_CONFIG_TYPE);
      }
    } else {
      if (!isPropertySet(clusterProps, HDFS_HA_INITIAL_CONFIG_TYPE, HDFS_ACTIVE_NAMENODE_SET_PROPERTY_NAME) && !isPropertySet(clusterProps, HDFS_HA_INITIAL_CONFIG_TYPE, HDFS_STANDBY_NAMENODE_SET_PROPERTY_NAME)) {        // multiple nameservices indicates an HDFS NameNode Federation install
        // process each nameservice to determine the active/standby nodes
        LOG.info("Processing multiple HDFS NameService instances, which indicates a NameNode Federation deployment");
        if (parsedNameServices.length > 1) {
          Set<String> activeNameNodeHostnames = new HashSet<>();
          Set<String> standbyNameNodeHostnames = new HashSet<>();

          for (String nameService : parsedNameServices) {
            List<String> hostNames = new ArrayList<>();
            String[] nameNodes = parseNameNodes(nameService, hdfsSiteConfig);
            for (String nameNode : nameNodes) {
              // use the HA rpc-address property to obtain the NameNode hostnames
              String propertyName = "dfs.namenode.rpc-address." + nameService + "." + nameNode;
              String propertyValue = hdfsSiteConfig.get(propertyName);
              if (propertyValue == null) {
                throw new ConfigurationTopologyException("NameNode HA property = " + propertyName + " is not found in the cluster config.  This indicates an error in configuration for HA/Federated clusters.  " +
                  "Please recheck the HDFS configuration and try this deployment again");
              }

              String hostName = propertyValue.split(":")[0];
              hostNames.add(hostName);
            }

            if (hostNames.size() < 2) {
              throw new ConfigurationTopologyException("NAMENODE HA for nameservice = " + nameService + " requires at least 2 hosts running NAMENODE but there are: " +
                hostNames.size() + " Hosts: " + hostNames);
            } else {
              // by default, select the active and standby namenodes for this nameservice
              // using the first two hostnames found
              // since HA is assumed, there should only be two NameNodes deployed per NameService
              activeNameNodeHostnames.add(hostNames.get(0));
              standbyNameNodeHostnames.add(hostNames.get(1));
            }
          }

          // set the properties what configure the NameNode Active/Standby status for each nameservice
          if (!activeNameNodeHostnames.isEmpty() && !standbyNameNodeHostnames.isEmpty()) {
            clusterConfig.setProperty(HDFS_HA_INITIAL_CONFIG_TYPE, HDFS_ACTIVE_NAMENODE_SET_PROPERTY_NAME, String.join(",", activeNameNodeHostnames));
            clusterConfig.setProperty(HDFS_HA_INITIAL_CONFIG_TYPE, HDFS_STANDBY_NAMENODE_SET_PROPERTY_NAME, String.join(",", standbyNameNodeHostnames));

            // also set the clusterID property, required for Federation installs of HDFS
            if (!isPropertySet(clusterProps, HDFS_HA_INITIAL_CONFIG_TYPE, HDFS_HA_INITIAL_CLUSTER_ID_PROPERTY_NAME)) {
              clusterConfig.setProperty(HDFS_HA_INITIAL_CONFIG_TYPE, HDFS_HA_INITIAL_CLUSTER_ID_PROPERTY_NAME, getClusterName());
            }

            configTypesUpdated.add(HDFS_HA_INITIAL_CONFIG_TYPE);
          } else {
            LOG.warn("Error in processing the set of active/standby namenodes in this federated cluster, please check hdfs-site configuration");
          }
          // Need to configure ranger-tagsync-site properties, when Ranger-HDFS plugin is enabled
          doTagSyncSiteUpdateForNamenodeNFederationEnabledOnClusterCreation(clusterConfig, clusterProps, configTypesUpdated);
        }
      }
    }
  }
Update Namenode HA properties during cluster creation
@throws ConfigurationTopologyException
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BlueprintConfigurationProcessor.java