Program: 63853
Project: 63853
Buggy source:
public void buildAmbariCluster(Stack stack){
  Cluster cluster=stack.getCluster();
  try {
    if (cluster.getCreationStarted() == null) {
      cluster.setCreationStarted(new Date().getTime());
      cluster=clusterRepository.save(cluster);
    }
    Set<HostGroup> hostGroups=hostGroupService.getByCluster(cluster.getId());
    Map<String,List<Map<String,String>>> hostGroupMappings=buildHostGroupAssociations(hostGroups);
    recipeEngine.executePostAmbariStartRecipes(stack,hostGroups);
    String blueprintText=generateBlueprintText(stack,cluster);
    AmbariClient ambariClient=getAmbariClient(stack);
    ambariRepositoryVersionService.setBaseRepoURL(stack.getName(),cluster.getId(),stack.getOrchestrator(),ambariClient);
    addBlueprint(stack,ambariClient,blueprintText,hostGroups);
    Set<HostMetadata> hostsInCluster=hostMetadataRepository.findHostsInCluster(cluster.getId());
    PollingResult waitForHostsResult=waitForHosts(stack,ambariClient,hostsInCluster);
    checkPollingResult(waitForHostsResult,cloudbreakMessagesService.getMessage(Msg.AMBARI_CLUSTER_HOST_JOIN_FAILED.code()));
    ambariClusterTemplateService.addClusterTemplate(cluster,hostGroupMappings,ambariClient);
    Pair<PollingResult,Exception> pollingResult=ambariOperationService.waitForOperationsToStart(stack,ambariClient,singletonMap("String_Node_Str",1),START_OPERATION_STATE);
    String message=pollingResult.getRight() == null ? cloudbreakMessagesService.getMessage(Msg.AMBARI_CLUSTER_INSTALL_FAILED.code()) : pollingResult.getRight().getMessage();
    checkPollingResult(pollingResult.getLeft(),message);
    pollingResult=waitForClusterInstall(stack,ambariClient);
    checkPollingResult(pollingResult.getLeft(),cloudbreakMessagesService.getMessage(Msg.AMBARI_CLUSTER_INSTALL_FAILED.code()));
    recipeEngine.executePostInstall(stack);
    triggerSmartSenseCapture(ambariClient,blueprintText);
    cluster=ambariViewProvider.provideViewInformation(ambariClient,cluster);
    handleClusterCreationSuccess(stack,cluster);
  }
 catch (  CancellationException cancellationException) {
    throw cancellationException;
  }
catch (  HttpResponseException hre) {
    String errorMessage=AmbariClientExceptionUtil.getErrorMessage(hre);
    throw new AmbariOperationFailedException("String_Node_Str" + errorMessage,hre);
  }
catch (  Exception e) {
    LOGGER.error("String_Node_Str",e.getMessage(),e);
    throw new AmbariOperationFailedException(e.getMessage(),e);
  }
}

Fixed version (ground truth):
public void buildAmbariCluster(Stack stack){
  Cluster cluster=stack.getCluster();
  try {
    if (cluster.getCreationStarted() == null) {
      cluster.setCreationStarted(new Date().getTime());
      cluster=clusterRepository.save(cluster);
    }
    Set<HostGroup> hostGroups=hostGroupService.getByCluster(cluster.getId());
    Map<String,List<Map<String,String>>> hostGroupMappings=buildHostGroupAssociations(hostGroups);
    recipeEngine.executePostAmbariStartRecipes(stack,hostGroups);
    String blueprintText=generateBlueprintText(stack,cluster);
    AmbariClient ambariClient=getAmbariClient(stack);
    ambariRepositoryVersionService.setBaseRepoURL(stack.getName(),cluster.getId(),stack.getOrchestrator(),ambariClient);
    addBlueprint(stack,ambariClient,blueprintText,hostGroups);
    Set<HostMetadata> hostsInCluster=hostMetadataRepository.findHostsInCluster(cluster.getId());
    PollingResult waitForHostsResult=waitForHosts(stack,ambariClient,hostsInCluster);
    checkPollingResult(waitForHostsResult,cloudbreakMessagesService.getMessage(Msg.AMBARI_CLUSTER_HOST_JOIN_FAILED.code()));
    ambariClusterTemplateService.addClusterTemplate(cluster,hostGroupMappings,ambariClient);
    Pair<PollingResult,Exception> pollingResult=ambariOperationService.waitForOperationsToStart(stack,ambariClient,singletonMap("String_Node_Str",1),START_OPERATION_STATE);
    String message=pollingResult.getRight() == null ? cloudbreakMessagesService.getMessage(Msg.AMBARI_CLUSTER_INSTALL_FAILED.code()) : pollingResult.getRight().getMessage();
    checkPollingResult(pollingResult.getLeft(),message);
    pollingResult=waitForClusterInstall(stack,ambariClient);
    checkPollingResult(pollingResult.getLeft(),cloudbreakMessagesService.getMessage(Msg.AMBARI_CLUSTER_INSTALL_FAILED.code()));
    recipeEngine.executePostInstallRecipes(stack,hostGroups);
    triggerSmartSenseCapture(ambariClient,blueprintText);
    cluster=ambariViewProvider.provideViewInformation(ambariClient,cluster);
    handleClusterCreationSuccess(stack,cluster);
  }
 catch (  CancellationException cancellationException) {
    throw cancellationException;
  }
catch (  HttpResponseException hre) {
    String errorMessage=AmbariClientExceptionUtil.getErrorMessage(hre);
    throw new AmbariOperationFailedException("String_Node_Str" + errorMessage,hre);
  }
catch (  Exception e) {
    LOGGER.error("String_Node_Str",e.getMessage(),e);
    throw new AmbariOperationFailedException(e.getMessage(),e);
  }
}