Program: 48277
Project: 48277
Buggy source:
@Override public List<BaseNode> getPlacementPlan(ClusterCreate clusterSpec,List<BaseNode> existedNodes){
  logger.info("String_Node_Str");
  logger.info("String_Node_Str");
  Container container=new Container();
  List<VcCluster> clusters=resMgr.getAvailableClusters();
  AuAssert.check(clusters != null && clusters.size() != 0);
  for (  VcCluster cl : clusters) {
    container.addResource(cl);
  }
  logger.info("String_Node_Str" + ContainerToStringHelper.convertToString(container));
  logger.info("String_Node_Str");
  int maxTimeDiffInSec=Constants.MAX_TIME_DIFF_IN_SEC;
  SoftwareManager softMgr=softwareManagerCollector.getSoftwareManager(clusterSpec.getAppManager());
  if (softMgr.hasHbase(clusterSpec.toBlueprint()))   maxTimeDiffInSec=Constants.MAX_TIME_DIFF_IN_SEC_HBASE;
  List<String> outOfSyncHosts=new ArrayList<String>();
  for (  AbstractHost host : container.getAllHosts()) {
    int hostTimeDiffInSec=VcResourceUtils.getHostTimeDiffInSec(host.getName());
    if (Math.abs(hostTimeDiffInSec) > maxTimeDiffInSec) {
      logger.info("String_Node_Str" + host.getName() + "String_Node_Str"+ hostTimeDiffInSec+ "String_Node_Str");
      outOfSyncHosts.add(host.getName());
    }
  }
  for (  String host : outOfSyncHosts) {
    container.removeHost(host);
  }
  logger.info("String_Node_Str");
  List<com.vmware.bdd.spectypes.VcCluster> usedClusters=clusterSpec.getVcClusters();
  List<String> noNetworkHosts=new ArrayList<String>();
  noNetworkHosts=resMgr.filterHostsByNetwork(clusterSpec.getNetworkNames(),usedClusters);
  for (  String host : noNetworkHosts) {
    container.removeHost(host);
  }
  Map<String,List<String>> filteredHosts=new HashMap<String,List<String>>();
  if (!outOfSyncHosts.isEmpty())   filteredHosts.put(PlacementUtil.OUT_OF_SYNC_HOSTS,outOfSyncHosts);
  if (!noNetworkHosts.isEmpty()) {
    filteredHosts.put(PlacementUtil.NO_NETWORKS_HOSTS,noNetworkHosts);
    filteredHosts.put(PlacementUtil.NETWORK_NAMES,clusterSpec.getNetworkNames());
  }
  VcVirtualMachine templateVm=getTemplateVM(clusterSpec.getTemplateName());
  container.setTemplateNode(createBaseNodeFromTemplateVm(templateVm));
  if (clusterSpec.getHostToRackMap() != null && clusterSpec.getHostToRackMap().size() != 0) {
    container.addRackMap(clusterSpec.getHostToRackMap());
  }
  logger.info("String_Node_Str");
  Set<String> validRacks=new HashSet<String>();
  List<AbstractHost> hosts=container.getAllHosts();
  for (  AbstractHost host : hosts) {
    if (container.getRack(host) != null) {
      validRacks.add(container.getRack(host));
    }
  }
  for (  NodeGroupCreate nodeGroup : clusterSpec.getNodeGroups()) {
    if (nodeGroup.getPlacementPolicies() != null && nodeGroup.getPlacementPolicies().getGroupRacks() != null && validRacks.size() == 0) {
      throw PlacementException.INVALID_RACK_INFO(clusterSpec.getName(),nodeGroup.getName());
    }
  }
  if (null == existedNodes) {
    checkAndUpdateClusterCloneType(clusterSpec,container);
  }
  logger.info("String_Node_Str");
  String clusterCloneType=clusterSpec.getClusterCloneType();
  chooseClusterCloneService(clusterCloneType).preCalculatePlacements(container,clusterSpec,existedNodes);
  List<BaseNode> baseNodes=placementService.getPlacementPlan(container,clusterSpec,existedNodes,filteredHosts);
  for (  BaseNode baseNode : baseNodes) {
    baseNode.setNodeAction(Constants.NODE_ACTION_CLONING_VM);
  }
  for (  BaseNode current : baseNodes) {
    Float cpuRatio=current.getNodeGroup().getReservedCpuRatio();
    Float memRatio=current.getNodeGroup().getReservedMemRatio();
    if (cpuRatio != null && cpuRatio > 0 && cpuRatio <= 1) {
      if (current.getTargetHost() != null) {
        VcHost host=VcResourceUtils.findHost(current.getTargetHost());
        long nodeCpuMhz=host.getCpuHz() / (1024 * 1024) * current.getCpu();
        current.getVmSchema().resourceSchema.cpuReservationMHz=(long)Math.ceil(nodeCpuMhz * cpuRatio);
        logger.info("String_Node_Str" + current.getVmSchema().resourceSchema.cpuReservationMHz);
      }
    }
    if (memRatio != null && memRatio > 0 && memRatio <= 1) {
      if (current.getVmSchema().resourceSchema.latencySensitivity == LatencyPriority.HIGH)       current.getVmSchema().resourceSchema.memReservationSize=current.getMem();
 else {
        current.getVmSchema().resourceSchema.memReservationSize=(long)Math.ceil(current.getMem() * memRatio);
      }
      logger.info("String_Node_Str" + current.getVmSchema().resourceSchema.memReservationSize);
    }
  }
  logger.info("String_Node_Str");
  return baseNodes;
}

Fixed version (ground truth):
@Override public List<BaseNode> getPlacementPlan(ClusterCreate clusterSpec,List<BaseNode> existedNodes){
  try {
    Thread.sleep(Configuration.getInt("String_Node_Str",10) * 1000);
  }
 catch (  InterruptedException e1) {
    logger.error("String_Node_Str",e1);
  }
  List<String> dsNames=vcResourceManager.getDsNamesToBeUsed(clusterSpec.getDsNames());
  if (dsNames.isEmpty()) {
    throw ClusterConfigException.NO_DATASTORE_ADDED();
  }
  VcResourceFilters filters=vcResourceFilterBuilder.build(dsNames,vcResourceManager.getRpNames(clusterSpec.getRpNames()),clusterSpec.getNetworkNames());
  try {
    syncService.refreshInventory(filters);
  }
 catch (  InterruptedException e) {
    logger.error("String_Node_Str",e);
  }
  logger.info("String_Node_Str");
  logger.info("String_Node_Str");
  Container container=new Container();
  List<VcCluster> clusters=resMgr.getAvailableClusters();
  AuAssert.check(clusters != null && clusters.size() != 0);
  for (  VcCluster cl : clusters) {
    container.addResource(cl);
  }
  logger.info("String_Node_Str" + ContainerToStringHelper.convertToString(container));
  logger.info("String_Node_Str");
  int maxTimeDiffInSec=Constants.MAX_TIME_DIFF_IN_SEC;
  SoftwareManager softMgr=softwareManagerCollector.getSoftwareManager(clusterSpec.getAppManager());
  if (softMgr.hasHbase(clusterSpec.toBlueprint()))   maxTimeDiffInSec=Constants.MAX_TIME_DIFF_IN_SEC_HBASE;
  List<String> outOfSyncHosts=new ArrayList<String>();
  for (  AbstractHost host : container.getAllHosts()) {
    int hostTimeDiffInSec=VcResourceUtils.getHostTimeDiffInSec(host.getName());
    if (Math.abs(hostTimeDiffInSec) > maxTimeDiffInSec) {
      logger.info("String_Node_Str" + host.getName() + "String_Node_Str"+ hostTimeDiffInSec+ "String_Node_Str");
      outOfSyncHosts.add(host.getName());
    }
  }
  for (  String host : outOfSyncHosts) {
    container.removeHost(host);
  }
  logger.info("String_Node_Str");
  List<com.vmware.bdd.spectypes.VcCluster> usedClusters=clusterSpec.getVcClusters();
  List<String> noNetworkHosts=new ArrayList<String>();
  noNetworkHosts=resMgr.filterHostsByNetwork(clusterSpec.getNetworkNames(),usedClusters);
  for (  String host : noNetworkHosts) {
    container.removeHost(host);
  }
  Map<String,List<String>> filteredHosts=new HashMap<String,List<String>>();
  if (!outOfSyncHosts.isEmpty())   filteredHosts.put(PlacementUtil.OUT_OF_SYNC_HOSTS,outOfSyncHosts);
  if (!noNetworkHosts.isEmpty()) {
    filteredHosts.put(PlacementUtil.NO_NETWORKS_HOSTS,noNetworkHosts);
    filteredHosts.put(PlacementUtil.NETWORK_NAMES,clusterSpec.getNetworkNames());
  }
  VcVirtualMachine templateVm=getTemplateVM(clusterSpec.getTemplateName());
  container.setTemplateNode(createBaseNodeFromTemplateVm(templateVm));
  if (clusterSpec.getHostToRackMap() != null && clusterSpec.getHostToRackMap().size() != 0) {
    container.addRackMap(clusterSpec.getHostToRackMap());
  }
  logger.info("String_Node_Str");
  Set<String> validRacks=new HashSet<String>();
  List<AbstractHost> hosts=container.getAllHosts();
  for (  AbstractHost host : hosts) {
    if (container.getRack(host) != null) {
      validRacks.add(container.getRack(host));
    }
  }
  for (  NodeGroupCreate nodeGroup : clusterSpec.getNodeGroups()) {
    if (nodeGroup.getPlacementPolicies() != null && nodeGroup.getPlacementPolicies().getGroupRacks() != null && validRacks.size() == 0) {
      throw PlacementException.INVALID_RACK_INFO(clusterSpec.getName(),nodeGroup.getName());
    }
  }
  if (null == existedNodes) {
    checkAndUpdateClusterCloneType(clusterSpec,container);
  }
  logger.info("String_Node_Str");
  String clusterCloneType=clusterSpec.getClusterCloneType();
  chooseClusterCloneService(clusterCloneType).preCalculatePlacements(container,clusterSpec,existedNodes);
  List<BaseNode> baseNodes=placementService.getPlacementPlan(container,clusterSpec,existedNodes,filteredHosts);
  for (  BaseNode baseNode : baseNodes) {
    baseNode.setNodeAction(Constants.NODE_ACTION_CLONING_VM);
  }
  for (  BaseNode current : baseNodes) {
    Float cpuRatio=current.getNodeGroup().getReservedCpuRatio();
    Float memRatio=current.getNodeGroup().getReservedMemRatio();
    if (cpuRatio != null && cpuRatio > 0 && cpuRatio <= 1) {
      if (current.getTargetHost() != null) {
        VcHost host=VcResourceUtils.findHost(current.getTargetHost());
        long nodeCpuMhz=host.getCpuHz() / (1024 * 1024) * current.getCpu();
        current.getVmSchema().resourceSchema.cpuReservationMHz=(long)Math.ceil(nodeCpuMhz * cpuRatio);
        logger.info("String_Node_Str" + current.getVmSchema().resourceSchema.cpuReservationMHz);
      }
    }
    if (memRatio != null && memRatio > 0 && memRatio <= 1) {
      if (current.getVmSchema().resourceSchema.latencySensitivity == LatencyPriority.HIGH)       current.getVmSchema().resourceSchema.memReservationSize=current.getMem();
 else {
        current.getVmSchema().resourceSchema.memReservationSize=(long)Math.ceil(current.getMem() * memRatio);
      }
      logger.info("String_Node_Str" + current.getVmSchema().resourceSchema.memReservationSize);
    }
  }
  logger.info("String_Node_Str");
  return baseNodes;
}