Program: 63937
Project: 63937
Buggy source:
public Cluster buildAmbariCluster(Stack stack){
  Cluster cluster=stack.getCluster();
  try {
    cluster.setCreationStarted(new Date().getTime());
    cluster=clusterRepository.save(cluster);
    TLSClientConfig clientConfig=tlsSecurityService.buildTLSClientConfig(stack.getId(),cluster.getAmbariIp());
    AmbariClient ambariClient=ambariClientProvider.getAmbariClient(clientConfig,cluster.getUserName(),cluster.getPassword());
    setBaseRepoURL(cluster,ambariClient);
    addBlueprint(stack,ambariClient,cluster.getBlueprint());
    int nodeCount=stack.getFullNodeCountWithoutDecommissionedNodes() - stack.getGateWayNodeCount();
    Set<HostMetadata> hostsInCluster=hostMetadataRepository.findHostsInCluster(cluster.getId());
    PollingResult waitForHostsResult=waitForHosts(stack,ambariClient,nodeCount,hostsInCluster);
    checkPollingResult(waitForHostsResult,"String_Node_Str" + waitForHostsResult.name());
    Set<HostGroup> hostGroups=hostGroupRepository.findHostGroupsInCluster(cluster.getId());
    Map<String,List<String>> hostGroupMappings=buildHostGroupAssociations(hostGroups);
    hostGroups=saveHostMetadata(cluster,hostGroupMappings);
    boolean recipesFound=recipesFound(hostGroups);
    if (recipesFound) {
      recipeEngine.setupRecipes(stack,hostGroups);
      recipeEngine.executePreInstall(stack);
    }
    ambariClient.createCluster(cluster.getName(),cluster.getBlueprint().getBlueprintName(),hostGroupMappings);
    PollingResult pollingResult=waitForClusterInstall(stack,ambariClient);
    checkPollingResult(pollingResult,"String_Node_Str" + pollingResult.name());
    pollingResult=runSmokeTest(stack,ambariClient);
    checkPollingResult(pollingResult,"String_Node_Str" + pollingResult.name());
    cluster=handleClusterCreationSuccess(stack,cluster);
    if (recipesFound) {
      recipeEngine.executePostInstall(stack);
    }
    return cluster;
  }
 catch (  FlowCancelledException flowCancelledException) {
    throw flowCancelledException;
  }
catch (  Exception e) {
    LOGGER.error("String_Node_Str",e.getMessage(),e);
    throw new AmbariOperationFailedException(e.getMessage(),e);
  }
}

Fixed version (ground truth):
public Cluster buildAmbariCluster(Stack stack){
  Cluster cluster=stack.getCluster();
  try {
    cluster.setCreationStarted(new Date().getTime());
    cluster=clusterRepository.save(cluster);
    TLSClientConfig clientConfig=tlsSecurityService.buildTLSClientConfig(stack.getId(),cluster.getAmbariIp());
    AmbariClient ambariClient=ambariClientProvider.getAmbariClient(clientConfig,cluster.getUserName(),cluster.getPassword());
    setBaseRepoURL(cluster,ambariClient);
    addBlueprint(stack,ambariClient,cluster.getBlueprint());
    int nodeCount=stack.getFullNodeCountWithoutDecommissionedNodes() - stack.getGateWayNodeCount();
    Set<HostGroup> hostGroups=hostGroupRepository.findHostGroupsInCluster(cluster.getId());
    Map<String,List<String>> hostGroupMappings=buildHostGroupAssociations(hostGroups);
    hostGroups=saveHostMetadata(cluster,hostGroupMappings);
    Set<HostMetadata> hostsInCluster=hostMetadataRepository.findHostsInCluster(cluster.getId());
    PollingResult waitForHostsResult=waitForHosts(stack,ambariClient,nodeCount,hostsInCluster);
    checkPollingResult(waitForHostsResult,"String_Node_Str" + waitForHostsResult.name());
    boolean recipesFound=recipesFound(hostGroups);
    if (recipesFound) {
      recipeEngine.setupRecipes(stack,hostGroups);
      recipeEngine.executePreInstall(stack);
    }
    ambariClient.createCluster(cluster.getName(),cluster.getBlueprint().getBlueprintName(),hostGroupMappings);
    PollingResult pollingResult=waitForClusterInstall(stack,ambariClient);
    checkPollingResult(pollingResult,"String_Node_Str" + pollingResult.name());
    pollingResult=runSmokeTest(stack,ambariClient);
    checkPollingResult(pollingResult,"String_Node_Str" + pollingResult.name());
    cluster=handleClusterCreationSuccess(stack,cluster);
    if (recipesFound) {
      recipeEngine.executePostInstall(stack);
    }
    return cluster;
  }
 catch (  FlowCancelledException flowCancelledException) {
    throw flowCancelledException;
  }
catch (  Exception e) {
    LOGGER.error("String_Node_Str",e.getMessage(),e);
    throw new AmbariOperationFailedException(e.getMessage(),e);
  }
}