Program: 48374
Project: 48374
Buggy source:
@Transactional public ClusterEntity createClusterConfig(ClusterCreate cluster){
  String name=cluster.getName();
  if (name == null || name.isEmpty()) {
    throw ClusterConfigException.CLUSTER_NAME_MISSING();
  }
  List<String> failedMsgList=new ArrayList<String>();
  List<String> warningMsgList=new ArrayList<String>();
  String appManager=cluster.getAppManager();
  if (appManager == null) {
    appManager=Constants.IRONFAN;
  }
  SoftwareManager softwareManager=getSoftwareManager(appManager);
  HadoopStack stack=filterDistroFromAppManager(softwareManager,cluster.getDistro());
  if (cluster.getDistro() == null || stack == null) {
    throw BddException.INVALID_PARAMETER("String_Node_Str",cluster.getDistro());
  }
  ClusterBlueprint blueprint=cluster.toBlueprint();
  try {
    softwareManager.validateBlueprint(cluster.toBlueprint());
    cluster.validateClusterCreate(failedMsgList,warningMsgList);
  }
 catch (  ValidationException e) {
    failedMsgList.addAll(e.getFailedMsgList());
    warningMsgList.addAll(e.getWarningMsgList());
  }
  if (!failedMsgList.isEmpty()) {
    throw ClusterConfigException.INVALID_SPEC(failedMsgList);
  }
  if (!validateRacksInfo(cluster,failedMsgList)) {
    throw ClusterConfigException.INVALID_PLACEMENT_POLICIES(failedMsgList);
  }
  String localRepoURL=cluster.getLocalRepoURL();
  if (!CommonUtil.isBlank(localRepoURL) && !validateLocalRepoURL(localRepoURL)) {
    throw ClusterConfigException.INVALID_LOCAL_REPO_URL(failedMsgList);
  }
  try {
    ClusterEntity entity=clusterEntityMgr.findByName(name);
    if (entity != null) {
      logger.info("String_Node_Str" + name + "String_Node_Str");
      throw BddException.ALREADY_EXISTS("String_Node_Str",name);
    }
    updateInfrastructure(cluster,softwareManager,blueprint);
    logger.debug("String_Node_Str" + name);
    Gson gson=new Gson();
    ClusterEntity clusterEntity=new ClusterEntity(name);
    clusterEntity.setAppManager(cluster.getAppManager());
    clusterEntity.setDistro(cluster.getDistro());
    clusterEntity.setDistroVendor(cluster.getDistroVendor());
    clusterEntity.setDistroVersion(cluster.getDistroVersion());
    clusterEntity.setStartAfterDeploy(true);
    clusterEntity.setPassword(cluster.getPassword());
    clusterEntity.setTemplateId(this.nodeTemplateService.getNodeTemplateIdByName(cluster.getTemplateName()));
    clusterEntity.setVersion(clusterEntityMgr.getServerVersion());
    if (softwareManager.containsComputeOnlyNodeGroups(blueprint)) {
      clusterEntity.setAutomationEnable(automationEnable);
    }
 else {
      clusterEntity.setAutomationEnable(null);
    }
    clusterEntity.setVhmMinNum(-1);
    clusterEntity.setVhmMaxNum(-1);
    if (cluster.getRpNames() != null && cluster.getRpNames().size() > 0) {
      logger.debug("String_Node_Str" + cluster.getRpNames() + "String_Node_Str"+ name);
      clusterEntity.setVcRpNameList(cluster.getRpNames());
    }
 else {
      logger.debug("String_Node_Str");
    }
    if (cluster.getDsNames() != null && !cluster.getDsNames().isEmpty()) {
      logger.debug("String_Node_Str" + cluster.getDsNames() + "String_Node_Str"+ name);
      clusterEntity.setVcDatastoreNameList(cluster.getDsNames());
    }
 else {
      logger.debug("String_Node_Str");
    }
    clusterEntity.setNetworkConfig(validateAndConvertNetNamesToNetConfigs(cluster.getNetworkConfig(),cluster.getDistroVendor().equalsIgnoreCase(Constants.MAPR_VENDOR)));
    clusterEntity.setVhmJobTrackerPort("String_Node_Str");
    if (cluster.getConfiguration() != null && cluster.getConfiguration().size() > 0) {
      clusterEntity.setHadoopConfig((new Gson()).toJson(cluster.getConfiguration()));
      updateVhmJobTrackerPort(cluster,clusterEntity);
    }
    setInfraConfig(cluster,clusterEntity);
    setAdvancedProperties(cluster.getExternalHDFS(),cluster.getExternalMapReduce(),localRepoURL,cluster.getExternalNamenode(),cluster.getExternalSecondaryNamenode(),cluster.getExternalDatanodes(),cluster.getClusterCloneType(),clusterEntity);
    NodeGroupCreate[] groups=cluster.getNodeGroups();
    if (groups != null && groups.length > 0) {
      clusterEntity.setNodeGroups(convertNodeGroupsToEntities(gson,clusterEntity,cluster.getDistro(),groups,cluster.isValidateConfig()));
      validateMemorySize(clusterEntity.getNodeGroups(),failedMsgList);
      if (!failedMsgList.isEmpty()) {
        throw ClusterConfigException.INVALID_SPEC(failedMsgList);
      }
    }
    if (cluster.getTopologyPolicy() == null) {
      clusterEntity.setTopologyPolicy(TopologyType.NONE);
    }
 else {
      clusterEntity.setTopologyPolicy(cluster.getTopologyPolicy());
    }
    if (clusterEntity.getTopologyPolicy() == TopologyType.HVE) {
      boolean hveSupported=false;
      if (clusterEntity.getDistro() != null) {
        HadoopStack hadoopStack=filterDistroFromAppManager(softwareManager,clusterEntity.getDistro());
        if (hadoopStack != null) {
          hveSupported=hadoopStack.isHveSupported();
        }
      }
      if (!hveSupported) {
        throw ClusterConfigException.INVALID_TOPOLOGY_POLICY(clusterEntity.getTopologyPolicy(),"String_Node_Str");
      }
    }
    clusterEntityMgr.insert(clusterEntity);
    logger.debug("String_Node_Str" + name);
    return clusterEntity;
  }
 catch (  UniqueConstraintViolationException ex) {
    logger.info("String_Node_Str" + name + "String_Node_Str");
    throw BddException.ALREADY_EXISTS(ex,"String_Node_Str",name);
  }
}

Fixed version (ground truth):
@Transactional public ClusterEntity createClusterConfig(ClusterCreate cluster){
  String name=cluster.getName();
  if (name == null || name.isEmpty()) {
    throw ClusterConfigException.CLUSTER_NAME_MISSING();
  }
  List<String> failedMsgList=new ArrayList<String>();
  List<String> warningMsgList=new ArrayList<String>();
  String appManager=cluster.getAppManager();
  if (appManager == null) {
    appManager=Constants.IRONFAN;
  }
  SoftwareManager softwareManager=getSoftwareManager(appManager);
  HadoopStack stack=filterDistroFromAppManager(softwareManager,cluster.getDistro());
  if (cluster.getDistro() == null || stack == null) {
    throw BddException.INVALID_PARAMETER("String_Node_Str",cluster.getDistro());
  }
  ClusterBlueprint blueprint=cluster.toBlueprint();
  try {
    softwareManager.validateBlueprint(cluster.toBlueprint());
    cluster.validateClusterCreate(failedMsgList,warningMsgList);
  }
 catch (  ValidationException e) {
    failedMsgList.addAll(e.getFailedMsgList());
    warningMsgList.addAll(e.getWarningMsgList());
  }
  if (!failedMsgList.isEmpty()) {
    throw ClusterConfigException.INVALID_SPEC(failedMsgList);
  }
  if (!validateRacksInfo(cluster,failedMsgList)) {
    throw ClusterConfigException.INVALID_PLACEMENT_POLICIES(failedMsgList);
  }
  String localRepoURL=cluster.getLocalRepoURL();
  if (!CommonUtil.isBlank(localRepoURL) && !validateLocalRepoURL(localRepoURL)) {
    throw ClusterConfigException.INVALID_LOCAL_REPO_URL(failedMsgList);
  }
  try {
    ClusterEntity entity=clusterEntityMgr.findByName(name);
    if (entity != null) {
      logger.info("String_Node_Str" + name + "String_Node_Str");
      throw BddException.ALREADY_EXISTS("String_Node_Str",name);
    }
    updateInfrastructure(cluster,softwareManager,blueprint);
    logger.debug("String_Node_Str" + name);
    Gson gson=new Gson();
    ClusterEntity clusterEntity=new ClusterEntity(name);
    clusterEntity.setAppManager(cluster.getAppManager());
    clusterEntity.setDistro(cluster.getDistro());
    clusterEntity.setDistroVendor(cluster.getDistroVendor());
    clusterEntity.setDistroVersion(cluster.getDistroVersion());
    clusterEntity.setStartAfterDeploy(true);
    clusterEntity.setPassword(cluster.getPassword());
    clusterEntity.setTemplateId(this.nodeTemplateService.getNodeTemplateIdByName(cluster.getTemplateName()));
    clusterEntity.setVersion(clusterEntityMgr.getServerVersion());
    if (softwareManager.containsComputeOnlyNodeGroups(blueprint)) {
      clusterEntity.setAutomationEnable(automationEnable);
    }
 else {
      clusterEntity.setAutomationEnable(null);
    }
    clusterEntity.setVhmMinNum(-1);
    clusterEntity.setVhmMaxNum(-1);
    if (cluster.getRpNames() != null && cluster.getRpNames().size() > 0) {
      logger.debug("String_Node_Str" + cluster.getRpNames() + "String_Node_Str"+ name);
      clusterEntity.setVcRpNameList(cluster.getRpNames());
    }
 else {
      logger.debug("String_Node_Str");
    }
    if (cluster.getDsNames() != null && !cluster.getDsNames().isEmpty()) {
      logger.debug("String_Node_Str" + cluster.getDsNames() + "String_Node_Str"+ name);
      clusterEntity.setVcDatastoreNameList(cluster.getDsNames());
    }
 else {
      logger.debug("String_Node_Str");
    }
    clusterEntity.setNetworkConfig(validateAndConvertNetNamesToNetConfigs(cluster.getNetworkConfig(),cluster.getDistroVendor().equalsIgnoreCase(Constants.MAPR_VENDOR)));
    clusterEntity.setVhmJobTrackerPort("String_Node_Str");
    if (cluster.getConfiguration() != null && cluster.getConfiguration().size() > 0) {
      clusterEntity.setHadoopConfig((new Gson()).toJson(cluster.getConfiguration()));
      updateVhmJobTrackerPort(cluster,clusterEntity);
    }
    setInfraConfig(cluster,clusterEntity);
    setAdvancedProperties(cluster.getExternalHDFS(),cluster.getExternalMapReduce(),localRepoURL,cluster.getExternalNamenode(),cluster.getExternalSecondaryNamenode(),cluster.getExternalDatanodes(),cluster.getClusterCloneType(),clusterEntity);
    NodeGroupCreate[] groups=cluster.getNodeGroups();
    if (groups != null && groups.length > 0) {
      clusterEntity.setNodeGroups(convertNodeGroupsToEntities(gson,clusterEntity,cluster.getDistro(),groups,cluster.isValidateConfig()));
      validateMemorySize(clusterEntity.getNodeGroups(),failedMsgList);
      if (!failedMsgList.isEmpty()) {
        throw ClusterConfigException.INVALID_SPEC(failedMsgList);
      }
    }
    if (!CommonUtil.isBlank(cluster.getAppManager()) && Constants.IRONFAN.equals(cluster.getAppManager()))     for (int i=0; i < clusterEntity.getNodeGroups().size(); i++) {
      NodeGroupEntity group=clusterEntity.getNodeGroups().get(i);
      String groupRoles=group.getRoles();
      if ((group.getLatencySensitivity() == LatencyPriority.HIGH) && ((groupRoles.contains(HadoopRole.HBASE_REGIONSERVER_ROLE.toString())))) {
        setHbase_RegionServer_Opts(cluster,group);
        if (cluster.getConfiguration() != null && cluster.getConfiguration().size() > 0) {
          clusterEntity.setHadoopConfig((new Gson()).toJson(cluster.getConfiguration()));
        }
        break;
      }
    }
    if (cluster.getTopologyPolicy() == null) {
      clusterEntity.setTopologyPolicy(TopologyType.NONE);
    }
 else {
      clusterEntity.setTopologyPolicy(cluster.getTopologyPolicy());
    }
    if (clusterEntity.getTopologyPolicy() == TopologyType.HVE) {
      boolean hveSupported=false;
      if (clusterEntity.getDistro() != null) {
        HadoopStack hadoopStack=filterDistroFromAppManager(softwareManager,clusterEntity.getDistro());
        if (hadoopStack != null) {
          hveSupported=hadoopStack.isHveSupported();
        }
      }
      if (!hveSupported) {
        throw ClusterConfigException.INVALID_TOPOLOGY_POLICY(clusterEntity.getTopologyPolicy(),"String_Node_Str");
      }
    }
    clusterEntityMgr.insert(clusterEntity);
    logger.debug("String_Node_Str" + name);
    return clusterEntity;
  }
 catch (  UniqueConstraintViolationException ex) {
    logger.info("String_Node_Str" + name + "String_Node_Str");
    throw BddException.ALREADY_EXISTS(ex,"String_Node_Str",name);
  }
}