Program: 106463
Project: 106463
Buggy source:
@Override public DeployDestination plan(VirtualMachineProfile<? extends VirtualMachine> vmProfile,DeploymentPlan plan,ExcludeList avoid) throws InsufficientServerCapacityException {
  VirtualMachine vm=vmProfile.getVirtualMachine();
  DataCenter dc=_dcDao.findById(vm.getDataCenterIdToDeployIn());
  if (avoid.shouldAvoid(dc)) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + dc.getId() + "String_Node_Str");
    }
    return null;
  }
  ServiceOffering offering=vmProfile.getServiceOffering();
  int cpu_requested=offering.getCpu() * offering.getSpeed();
  long ram_requested=offering.getRamSize() * 1024L * 1024L;
  String opFactor=_configDao.getValue(Config.CPUOverprovisioningFactor.key());
  float cpuOverprovisioningFactor=NumbersUtil.parseFloat(opFactor,1);
  if (s_logger.isDebugEnabled()) {
    s_logger.debug("String_Node_Str" + _allocationAlgorithm);
    s_logger.debug("String_Node_Str" + plan.getDataCenterId() + "String_Node_Str"+ plan.getPodId()+ "String_Node_Str"+ plan.getClusterId()+ "String_Node_Str"+ cpu_requested+ "String_Node_Str"+ ram_requested);
    s_logger.debug("String_Node_Str" + (plan.getPoolId() != null ? "String_Node_Str" : "String_Node_Str"));
  }
  String haVmTag=(String)vmProfile.getParameter(VirtualMachineProfile.Param.HaTag);
  if (plan.getHostId() != null && haVmTag == null) {
    Long hostIdSpecified=plan.getHostId();
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + hostIdSpecified);
    }
    HostVO host=_hostDao.findById(hostIdSpecified);
    if (s_logger.isDebugEnabled()) {
      if (host == null) {
        s_logger.debug("String_Node_Str");
      }
 else {
        s_logger.debug("String_Node_Str" + host.getDataCenterId() + "String_Node_Str"+ host.getPodId()+ "String_Node_Str"+ host.getClusterId());
      }
    }
    DataCenterDeployment lastPlan=new DataCenterDeployment(host.getDataCenterId(),host.getPodId(),host.getClusterId(),hostIdSpecified,plan.getPoolId(),null,plan.getReservationContext());
    Pair<Map<Volume,List<StoragePool>>,List<Volume>> result=findSuitablePoolsForVolumes(vmProfile,lastPlan,avoid,HostAllocator.RETURN_UPTO_ALL);
    Map<Volume,List<StoragePool>> suitableVolumeStoragePools=result.first();
    List<Volume> readyAndReusedVolumes=result.second();
    if (!suitableVolumeStoragePools.isEmpty()) {
      List<Host> suitableHosts=new ArrayList<Host>();
      suitableHosts.add(host);
      Pair<Host,Map<Volume,StoragePool>> potentialResources=findPotentialDeploymentResources(suitableHosts,suitableVolumeStoragePools);
      if (potentialResources != null) {
        Pod pod=_podDao.findById(host.getPodId());
        Cluster cluster=_clusterDao.findById(host.getClusterId());
        Map<Volume,StoragePool> storageVolMap=potentialResources.second();
        for (        Volume vol : readyAndReusedVolumes) {
          storageVolMap.remove(vol);
        }
        DeployDestination dest=new DeployDestination(dc,pod,cluster,host,storageVolMap);
        s_logger.debug("String_Node_Str" + dest);
        return dest;
      }
    }
    s_logger.debug("String_Node_Str");
    return null;
  }
  if (vm.getLastHostId() != null && haVmTag == null) {
    s_logger.debug("String_Node_Str" + vm.getLastHostId());
    HostVO host=_hostDao.findById(vm.getLastHostId());
    if (host == null) {
      s_logger.debug("String_Node_Str");
    }
 else     if (avoid.shouldAvoid(host)) {
      s_logger.debug("String_Node_Str");
    }
 else {
      if (host.getStatus() == Status.Up && host.getResourceState() == ResourceState.Enabled) {
        if (_capacityMgr.checkIfHostHasCapacity(host.getId(),cpu_requested,ram_requested,true,cpuOverprovisioningFactor,true)) {
          s_logger.debug("String_Node_Str");
          s_logger.debug("String_Node_Str" + host.getDataCenterId() + "String_Node_Str"+ host.getPodId()+ "String_Node_Str"+ host.getClusterId());
          DataCenterDeployment lastPlan=new DataCenterDeployment(host.getDataCenterId(),host.getPodId(),host.getClusterId(),host.getId(),plan.getPoolId(),null);
          Pair<Map<Volume,List<StoragePool>>,List<Volume>> result=findSuitablePoolsForVolumes(vmProfile,lastPlan,avoid,HostAllocator.RETURN_UPTO_ALL);
          Map<Volume,List<StoragePool>> suitableVolumeStoragePools=result.first();
          List<Volume> readyAndReusedVolumes=result.second();
          if (!suitableVolumeStoragePools.isEmpty()) {
            List<Host> suitableHosts=new ArrayList<Host>();
            suitableHosts.add(host);
            Pair<Host,Map<Volume,StoragePool>> potentialResources=findPotentialDeploymentResources(suitableHosts,suitableVolumeStoragePools);
            if (potentialResources != null) {
              Pod pod=_podDao.findById(host.getPodId());
              Cluster cluster=_clusterDao.findById(host.getClusterId());
              Map<Volume,StoragePool> storageVolMap=potentialResources.second();
              for (              Volume vol : readyAndReusedVolumes) {
                storageVolMap.remove(vol);
              }
              DeployDestination dest=new DeployDestination(dc,pod,cluster,host,storageVolMap);
              s_logger.debug("String_Node_Str" + dest);
              return dest;
            }
          }
        }
 else {
          s_logger.debug("String_Node_Str");
        }
      }
 else {
        s_logger.debug("String_Node_Str" + host.getStatus().name() + "String_Node_Str"+ host.getResourceState());
      }
    }
    s_logger.debug("String_Node_Str");
  }
  List<Long> clusterList=new ArrayList<Long>();
  if (plan.getClusterId() != null) {
    Long clusterIdSpecified=plan.getClusterId();
    s_logger.debug("String_Node_Str" + clusterIdSpecified);
    ClusterVO cluster=_clusterDao.findById(plan.getClusterId());
    if (cluster != null) {
      clusterList.add(clusterIdSpecified);
      return checkClustersforDestination(clusterList,vmProfile,plan,avoid,dc);
    }
 else {
      s_logger.debug("String_Node_Str");
      avoid.addCluster(plan.getClusterId());
      return null;
    }
  }
 else   if (plan.getPodId() != null) {
    Long podIdSpecified=plan.getPodId();
    s_logger.debug("String_Node_Str" + podIdSpecified);
    HostPodVO pod=_podDao.findById(podIdSpecified);
    if (pod != null) {
      DeployDestination dest=scanClustersForDestinationInZoneOrPod(podIdSpecified,false,vmProfile,plan,avoid);
      if (dest == null) {
        avoid.addPod(plan.getPodId());
      }
      return dest;
    }
 else {
      s_logger.debug("String_Node_Str");
      avoid.addPod(plan.getPodId());
      return null;
    }
  }
 else {
    s_logger.debug("String_Node_Str" + plan.getDataCenterId());
    boolean applyAllocationAtPods=Boolean.parseBoolean(_configDao.getValue(Config.ApplyAllocationAlgorithmToPods.key()));
    if (applyAllocationAtPods) {
      return scanPodsForDestination(vmProfile,plan,avoid);
    }
 else {
      return scanClustersForDestinationInZoneOrPod(plan.getDataCenterId(),true,vmProfile,plan,avoid);
    }
  }
}

Fixed version (ground truth):
@Override public DeployDestination plan(VirtualMachineProfile<? extends VirtualMachine> vmProfile,DeploymentPlan plan,ExcludeList avoid) throws InsufficientServerCapacityException {
  VirtualMachine vm=vmProfile.getVirtualMachine();
  DataCenter dc=_dcDao.findById(vm.getDataCenterIdToDeployIn());
  if (avoid.shouldAvoid(dc)) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + dc.getId() + "String_Node_Str");
    }
    return null;
  }
  ServiceOffering offering=vmProfile.getServiceOffering();
  int cpu_requested=offering.getCpu() * offering.getSpeed();
  long ram_requested=offering.getRamSize() * 1024L * 1024L;
  String opFactor=_configDao.getValue(Config.CPUOverprovisioningFactor.key());
  float cpuOverprovisioningFactor=NumbersUtil.parseFloat(opFactor,1);
  if (s_logger.isDebugEnabled()) {
    s_logger.debug("String_Node_Str" + _allocationAlgorithm);
    s_logger.debug("String_Node_Str" + plan.getDataCenterId() + "String_Node_Str"+ plan.getPodId()+ "String_Node_Str"+ plan.getClusterId()+ "String_Node_Str"+ cpu_requested+ "String_Node_Str"+ ram_requested);
    s_logger.debug("String_Node_Str" + (plan.getPoolId() != null ? "String_Node_Str" : "String_Node_Str"));
  }
  String haVmTag=(String)vmProfile.getParameter(VirtualMachineProfile.Param.HaTag);
  if (plan.getHostId() != null && haVmTag == null) {
    Long hostIdSpecified=plan.getHostId();
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + hostIdSpecified);
    }
    HostVO host=_hostDao.findById(hostIdSpecified);
    if (s_logger.isDebugEnabled()) {
      if (host == null) {
        s_logger.debug("String_Node_Str");
      }
 else {
        s_logger.debug("String_Node_Str" + host.getDataCenterId() + "String_Node_Str"+ host.getPodId()+ "String_Node_Str"+ host.getClusterId());
      }
    }
    DataCenterDeployment lastPlan=new DataCenterDeployment(host.getDataCenterId(),host.getPodId(),host.getClusterId(),hostIdSpecified,plan.getPoolId(),null,plan.getReservationContext());
    Pair<Map<Volume,List<StoragePool>>,List<Volume>> result=findSuitablePoolsForVolumes(vmProfile,lastPlan,avoid,HostAllocator.RETURN_UPTO_ALL);
    Map<Volume,List<StoragePool>> suitableVolumeStoragePools=result.first();
    List<Volume> readyAndReusedVolumes=result.second();
    if (!suitableVolumeStoragePools.isEmpty()) {
      List<Host> suitableHosts=new ArrayList<Host>();
      suitableHosts.add(host);
      Pair<Host,Map<Volume,StoragePool>> potentialResources=findPotentialDeploymentResources(suitableHosts,suitableVolumeStoragePools);
      if (potentialResources != null) {
        Pod pod=_podDao.findById(host.getPodId());
        Cluster cluster=_clusterDao.findById(host.getClusterId());
        Map<Volume,StoragePool> storageVolMap=potentialResources.second();
        for (        Volume vol : readyAndReusedVolumes) {
          storageVolMap.remove(vol);
        }
        DeployDestination dest=new DeployDestination(dc,pod,cluster,host,storageVolMap);
        s_logger.debug("String_Node_Str" + dest);
        return dest;
      }
    }
    s_logger.debug("String_Node_Str");
    return null;
  }
  if (vm.getLastHostId() != null && haVmTag == null) {
    s_logger.debug("String_Node_Str" + vm.getLastHostId());
    HostVO host=_hostDao.findById(vm.getLastHostId());
    if (host == null) {
      s_logger.debug("String_Node_Str");
    }
 else     if (avoid.shouldAvoid(host)) {
      s_logger.debug("String_Node_Str");
    }
 else     if (_capacityMgr.checkIfHostReachMaxGuestLimit(host)) {
      s_logger.debug("String_Node_Str" + host.getId() + "String_Node_Str");
    }
 else {
      if (host.getStatus() == Status.Up && host.getResourceState() == ResourceState.Enabled) {
        if (_capacityMgr.checkIfHostHasCapacity(host.getId(),cpu_requested,ram_requested,true,cpuOverprovisioningFactor,true)) {
          s_logger.debug("String_Node_Str");
          s_logger.debug("String_Node_Str" + host.getDataCenterId() + "String_Node_Str"+ host.getPodId()+ "String_Node_Str"+ host.getClusterId());
          DataCenterDeployment lastPlan=new DataCenterDeployment(host.getDataCenterId(),host.getPodId(),host.getClusterId(),host.getId(),plan.getPoolId(),null);
          Pair<Map<Volume,List<StoragePool>>,List<Volume>> result=findSuitablePoolsForVolumes(vmProfile,lastPlan,avoid,HostAllocator.RETURN_UPTO_ALL);
          Map<Volume,List<StoragePool>> suitableVolumeStoragePools=result.first();
          List<Volume> readyAndReusedVolumes=result.second();
          if (!suitableVolumeStoragePools.isEmpty()) {
            List<Host> suitableHosts=new ArrayList<Host>();
            suitableHosts.add(host);
            Pair<Host,Map<Volume,StoragePool>> potentialResources=findPotentialDeploymentResources(suitableHosts,suitableVolumeStoragePools);
            if (potentialResources != null) {
              Pod pod=_podDao.findById(host.getPodId());
              Cluster cluster=_clusterDao.findById(host.getClusterId());
              Map<Volume,StoragePool> storageVolMap=potentialResources.second();
              for (              Volume vol : readyAndReusedVolumes) {
                storageVolMap.remove(vol);
              }
              DeployDestination dest=new DeployDestination(dc,pod,cluster,host,storageVolMap);
              s_logger.debug("String_Node_Str" + dest);
              return dest;
            }
          }
        }
 else {
          s_logger.debug("String_Node_Str");
        }
      }
 else {
        s_logger.debug("String_Node_Str" + host.getStatus().name() + "String_Node_Str"+ host.getResourceState());
      }
    }
    s_logger.debug("String_Node_Str");
  }
  List<Long> clusterList=new ArrayList<Long>();
  if (plan.getClusterId() != null) {
    Long clusterIdSpecified=plan.getClusterId();
    s_logger.debug("String_Node_Str" + clusterIdSpecified);
    ClusterVO cluster=_clusterDao.findById(plan.getClusterId());
    if (cluster != null) {
      clusterList.add(clusterIdSpecified);
      return checkClustersforDestination(clusterList,vmProfile,plan,avoid,dc);
    }
 else {
      s_logger.debug("String_Node_Str");
      avoid.addCluster(plan.getClusterId());
      return null;
    }
  }
 else   if (plan.getPodId() != null) {
    Long podIdSpecified=plan.getPodId();
    s_logger.debug("String_Node_Str" + podIdSpecified);
    HostPodVO pod=_podDao.findById(podIdSpecified);
    if (pod != null) {
      DeployDestination dest=scanClustersForDestinationInZoneOrPod(podIdSpecified,false,vmProfile,plan,avoid);
      if (dest == null) {
        avoid.addPod(plan.getPodId());
      }
      return dest;
    }
 else {
      s_logger.debug("String_Node_Str");
      avoid.addPod(plan.getPodId());
      return null;
    }
  }
 else {
    s_logger.debug("String_Node_Str" + plan.getDataCenterId());
    boolean applyAllocationAtPods=Boolean.parseBoolean(_configDao.getValue(Config.ApplyAllocationAlgorithmToPods.key()));
    if (applyAllocationAtPods) {
      return scanPodsForDestination(vmProfile,plan,avoid);
    }
 else {
      return scanClustersForDestinationInZoneOrPod(plan.getDataCenterId(),true,vmProfile,plan,avoid);
    }
  }
}