Program: 124648
Project: 124648
Buggy source:
public static void setConnectionParameters(HadoopClusterConnectionItem connectionItem,DistributionBean distribution,String version,IRetrieveConfsService confsService) throws Exception {
  HadoopClusterConnection connection=(HadoopClusterConnection)connectionItem.getConnection();
  connection.setUseCustomConfs(confsService != null);
  final DistributionVersion distributionVersion=distribution.getVersion(version,true);
  connection.setDistribution(distribution.name);
  connection.setDfVersion(distributionVersion.version);
  boolean supportYARN=distributionVersion.hadoopComponent != null && distributionVersion.hadoopComponent.isHadoop2();
  boolean supportMR1=distributionVersion.hadoopComponent != null && distributionVersion.hadoopComponent.isHadoop1();
  connection.setUseYarn(supportYARN && !supportMR1);
  HCRepositoryUtil.fillDefaultValuesOfHadoopCluster(connection);
  if (confsService == null) {
    return;
  }
  String namenodeURI=null;
  String ns=confsService.getConfValue(EHadoopConfs.HDFS.getName(),EHadoopConfProperties.DFS_NAMESERVICES.getName());
  if (StringUtils.isNotEmpty(ns)) {
    namenodeURI="String_Node_Str" + ns;
  }
 else {
    namenodeURI=confsService.getConfValue(EHadoopConfs.HDFS.getName(),EHadoopConfProperties.FS_DEFAULT_URI_NEW.getName());
    if (StringUtils.isEmpty(namenodeURI)) {
      namenodeURI=confsService.getConfValue(EHadoopConfs.HDFS.getName(),EHadoopConfProperties.FS_DEFAULT_URI.getName());
    }
  }
  if (namenodeURI != null) {
    connection.setNameNodeURI(namenodeURI);
  }
  String yarnHostName=confsService.getConfValue(EHadoopConfs.YARN.getName(),EHadoopConfProperties.YARN_RESOURCEMANAGER_HOSTNAME.getName());
  if (StringUtils.isNotEmpty(yarnHostName)) {
    connection.getParameters().put(ConnParameterKeys.CONN_PARA_KEY_YARN_HOSTNAME,yarnHostName);
  }
  String rmOrJt=null;
  if (supportYARN) {
    String useRmHa=confsService.getConfValue(EHadoopConfs.YARN.getName(),EHadoopConfProperties.YARN_RESOURCEMANAGER_HA_ENABLED.getName());
    boolean isUseRmHa=Boolean.valueOf(useRmHa);
    if (isUseRmHa) {
      String rmIdKey=getRmIdKey(confsService,EHadoopConfProperties.YARN_RESOURCEMANAGER_ADDRESS_RM_ID.getName());
      if (StringUtils.isNotEmpty(rmIdKey)) {
        rmOrJt=confsService.getConfValue(EHadoopConfs.YARN.getName(),rmIdKey);
      }
      if (rmOrJt == null) {
        rmIdKey=getRmIdKey(confsService,EHadoopConfProperties.YARN_RESOURCEMANAGER_HOSTNAME_RM_ID.getName());
        if (StringUtils.isNotEmpty(rmIdKey)) {
          rmOrJt=confsService.getConfValue(EHadoopConfs.YARN.getName(),rmIdKey);
        }
      }
    }
 else {
      rmOrJt=confsService.getConfValue(EHadoopConfs.YARN.getName(),EHadoopConfProperties.RESOURCE_MANAGER.getName());
    }
  }
 else {
    rmOrJt=confsService.getConfValue(EHadoopConfs.MAPREDUCE2.getName(),EHadoopConfProperties.JOB_TRACKER_URI.getName());
  }
  if (rmOrJt == null && yarnHostName != null) {
    rmOrJt=replaceHostName(connection.getJobTrackerURI(),yarnHostName);
  }
  connection.setJobTrackerURI(rmOrJt);
  String rms=confsService.getConfValue(EHadoopConfs.YARN.getName(),EHadoopConfProperties.RESOURCEMANAGER_SCHEDULER.getName());
  if (rms == null) {
    String rmIdKey=getRmIdKey(confsService,EHadoopConfProperties.RESOURCEMANAGER_SCHEDULER_ADDRESS_RM_ID.getName());
    if (StringUtils.isNotEmpty(rmIdKey)) {
      rms=confsService.getConfValue(EHadoopConfs.YARN.getName(),rmIdKey);
    }
    if (yarnHostName != null) {
      rms=replaceHostName(connection.getRmScheduler(),yarnHostName);
    }
  }
  connection.setRmScheduler(rms);
  String jh=confsService.getConfValue(EHadoopConfs.MAPREDUCE2.getName(),EHadoopConfProperties.JOBHISTORY.getName());
  if (StringUtils.isEmpty(jh)) {
    jh=confsService.getConfValue(EHadoopConfs.YARN.getName(),EHadoopConfProperties.JOBHISTORY.getName());
  }
  if (StringUtils.isNotEmpty(jh)) {
    connection.setJobHistory(jh);
  }
  String sd=confsService.getConfValue(EHadoopConfs.MAPREDUCE2.getName(),EHadoopConfProperties.STAGING_DIR.getName());
  if (StringUtils.isEmpty(sd)) {
    sd=confsService.getConfValue(EHadoopConfs.YARN.getName(),EHadoopConfProperties.STAGING_DIR.getName());
  }
  if (StringUtils.isNotEmpty(sd)) {
    connection.setStagingDirectory(sd);
  }
  String at=confsService.getConfValue(EHadoopConfs.HDFS.getName(),EHadoopConfProperties.AUTHENTICATION.getName());
  if (StringUtils.isNotEmpty(at)) {
    connection.setEnableKerberos("String_Node_Str".equals(at));
  }
  if (connection.isEnableKerberos()) {
    String nnp=confsService.getConfValue(EHadoopConfs.HDFS.getName(),EHadoopConfProperties.KERBEROS_PRINCIPAL.getName());
    if (StringUtils.isNotEmpty(nnp)) {
      connection.setPrincipal(nnp);
    }
    String rmOrJtPrincipal=null;
    if (supportYARN) {
      rmOrJtPrincipal=confsService.getConfValue(EHadoopConfs.YARN.getName(),EHadoopConfProperties.RM_PRINCIPAL.getName());
    }
 else {
      rmOrJtPrincipal=confsService.getConfValue(EHadoopConfs.MAPREDUCE2.getName(),EHadoopConfProperties.JT_PRINCIPAL.getName());
    }
    if (rmOrJtPrincipal != null) {
      connection.setJtOrRmPrincipal(rmOrJtPrincipal);
    }
    String jhp=confsService.getConfValue(EHadoopConfs.MAPREDUCE2.getName(),EHadoopConfProperties.JH_PRINCIPAL.getName());
    if (StringUtils.isNotEmpty(jhp)) {
      connection.setJobHistoryPrincipal(jhp);
    }
  }
}

Fixed version (ground truth):
public static void setConnectionParameters(HadoopClusterConnectionItem connectionItem,DistributionBean distribution,String version,IRetrieveConfsService confsService) throws Exception {
  HadoopClusterConnection connection=(HadoopClusterConnection)connectionItem.getConnection();
  connection.setUseCustomConfs(confsService != null);
  final DistributionVersion distributionVersion=distribution.getVersion(version,true);
  connection.setDistribution(distribution.name);
  connection.setDfVersion(distributionVersion.version);
  boolean supportYARN=distributionVersion.hadoopComponent != null && distributionVersion.hadoopComponent.isHadoop2();
  boolean supportMR1=distributionVersion.hadoopComponent != null && distributionVersion.hadoopComponent.isHadoop1();
  connection.setUseYarn(supportYARN && !supportMR1);
  HCRepositoryUtil.fillDefaultValuesOfHadoopCluster(connection);
  if (confsService == null) {
    return;
  }
  String namenodeURI=null;
  String ns=confsService.getConfValue(EHadoopConfs.HDFS.getName(),EHadoopConfProperties.DFS_NAMESERVICES.getName());
  if (StringUtils.isNotEmpty(ns)) {
    namenodeURI="String_Node_Str" + ns;
  }
 else {
    namenodeURI=confsService.getConfValue(EHadoopConfs.HDFS.getName(),EHadoopConfProperties.FS_DEFAULT_URI_NEW.getName());
    if (StringUtils.isEmpty(namenodeURI)) {
      namenodeURI=confsService.getConfValue(EHadoopConfs.HDFS.getName(),EHadoopConfProperties.FS_DEFAULT_URI.getName());
    }
  }
  if (namenodeURI != null) {
    connection.setNameNodeURI(namenodeURI);
  }
  String yarnHostName=confsService.getConfValue(EHadoopConfs.YARN.getName(),EHadoopConfProperties.YARN_RESOURCEMANAGER_HOSTNAME.getName());
  if (StringUtils.isNotEmpty(yarnHostName)) {
    connection.getParameters().put(ConnParameterKeys.CONN_PARA_KEY_YARN_HOSTNAME,yarnHostName);
  }
  String rmOrJt=null;
  if (supportYARN) {
    String useRmHa=confsService.getConfValue(EHadoopConfs.YARN.getName(),EHadoopConfProperties.YARN_RESOURCEMANAGER_HA_ENABLED.getName());
    boolean isUseRmHa=Boolean.valueOf(useRmHa);
    if (isUseRmHa) {
      String rmIdKey=getRmIdKey(confsService,EHadoopConfProperties.YARN_RESOURCEMANAGER_ADDRESS_RM_ID.getName());
      if (StringUtils.isNotEmpty(rmIdKey)) {
        rmOrJt=confsService.getConfValue(EHadoopConfs.YARN.getName(),rmIdKey);
      }
      if (rmOrJt == null) {
        rmIdKey=getRmIdKey(confsService,EHadoopConfProperties.YARN_RESOURCEMANAGER_HOSTNAME_RM_ID.getName());
        if (StringUtils.isNotEmpty(rmIdKey)) {
          rmOrJt=confsService.getConfValue(EHadoopConfs.YARN.getName(),rmIdKey);
        }
      }
    }
 else {
      rmOrJt=confsService.getConfValue(EHadoopConfs.YARN.getName(),EHadoopConfProperties.RESOURCE_MANAGER.getName());
    }
  }
 else {
    rmOrJt=confsService.getConfValue(EHadoopConfs.MAPREDUCE2.getName(),EHadoopConfProperties.JOB_TRACKER_URI.getName());
  }
  if (rmOrJt == null && yarnHostName != null) {
    rmOrJt=replaceHostName(connection.getJobTrackerURI(),yarnHostName);
  }
  connection.setJobTrackerURI(rmOrJt);
  String rms=confsService.getConfValue(EHadoopConfs.YARN.getName(),EHadoopConfProperties.RESOURCEMANAGER_SCHEDULER.getName());
  if (rms == null) {
    String rmIdKey=getRmIdKey(confsService,EHadoopConfProperties.RESOURCEMANAGER_SCHEDULER_ADDRESS_RM_ID.getName());
    if (StringUtils.isNotEmpty(rmIdKey)) {
      rms=confsService.getConfValue(EHadoopConfs.YARN.getName(),rmIdKey);
    }
    if (yarnHostName != null) {
      rms=replaceHostName(connection.getRmScheduler(),yarnHostName);
    }
  }
  connection.setRmScheduler(rms);
  String jh=confsService.getConfValue(EHadoopConfs.MAPREDUCE2.getName(),EHadoopConfProperties.JOBHISTORY.getName());
  if (StringUtils.isEmpty(jh)) {
    jh=confsService.getConfValue(EHadoopConfs.YARN.getName(),EHadoopConfProperties.JOBHISTORY.getName());
  }
  if (StringUtils.isNotEmpty(jh)) {
    connection.setJobHistory(jh);
  }
  String sd=confsService.getConfValue(EHadoopConfs.MAPREDUCE2.getName(),EHadoopConfProperties.STAGING_DIR.getName());
  if (StringUtils.isEmpty(sd)) {
    sd=confsService.getConfValue(EHadoopConfs.YARN.getName(),EHadoopConfProperties.STAGING_DIR.getName());
  }
  if (StringUtils.isNotEmpty(sd)) {
    connection.setStagingDirectory(sd);
  }
  String at=confsService.getConfValue(EHadoopConfs.HDFS.getName(),EHadoopConfProperties.AUTHENTICATION.getName());
  if (StringUtils.isNotEmpty(at)) {
    connection.setEnableKerberos("String_Node_Str".equals(at));
  }
  if (connection.isEnableKerberos()) {
    String nnp=confsService.getConfValue(EHadoopConfs.HDFS.getName(),EHadoopConfProperties.KERBEROS_PRINCIPAL.getName());
    if (StringUtils.isNotEmpty(nnp)) {
      connection.setPrincipal(nnp);
    }
    String rmOrJtPrincipal=null;
    if (supportYARN) {
      rmOrJtPrincipal=confsService.getConfValue(EHadoopConfs.YARN.getName(),EHadoopConfProperties.RM_PRINCIPAL.getName());
    }
 else {
      rmOrJtPrincipal=confsService.getConfValue(EHadoopConfs.MAPREDUCE2.getName(),EHadoopConfProperties.JT_PRINCIPAL.getName());
    }
    if (rmOrJtPrincipal != null) {
      connection.setJtOrRmPrincipal(rmOrJtPrincipal);
    }
    String jhp=confsService.getConfValue(EHadoopConfs.MAPREDUCE2.getName(),EHadoopConfProperties.JH_PRINCIPAL.getName());
    if (StringUtils.isEmpty(jhp)) {
      jhp=confsService.getConfValue(EHadoopConfs.YARN.getName(),EHadoopConfProperties.JH_PRINCIPAL.getName());
    }
    if (StringUtils.isNotEmpty(jhp)) {
      connection.setJobHistoryPrincipal(jhp);
    }
  }
}