Program: 89346
Project: 89346
Buggy source:
@Override public DeployDestination plan(VirtualMachineProfile<? extends VirtualMachine> vmProfile,DeploymentPlan plan,ExcludeList avoid) throws InsufficientServerCapacityException {
  String _allocationAlgorithm=_configDao.getValue(Config.VmAllocationAlgorithm.key());
  VirtualMachine vm=vmProfile.getVirtualMachine();
  ServiceOffering offering=vmProfile.getServiceOffering();
  DataCenter dc=_dcDao.findById(vm.getDataCenterIdToDeployIn());
  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");
    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"));
  }
  if (plan.getHostId() != 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());
    Pair<Map<Volume,List<StoragePool>>,List<Volume>> result=findSuitablePoolsForVolumes(vmProfile,lastPlan,avoid,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) {
    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 (host.getStatus() == Status.Up && host.getHostAllocationState() == Host.HostAllocationState.Enabled) {
        if (isEnabledForAllocation(host.getDataCenterId(),host.getPodId(),host.getClusterId())) {
          if (_capacityMgr.checkIfHostHasCapacity(host.getId(),cpu_requested,ram_requested,true,cpuOverprovisioningFactor)) {
            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());
            Pair<Map<Volume,List<StoragePool>>,List<Volume>> result=findSuitablePoolsForVolumes(vmProfile,lastPlan,avoid,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.getHostAllocationState().name());
      }
    }
    s_logger.debug("String_Node_Str");
  }
  if (!isEnabledForAllocation(plan.getDataCenterId(),plan.getPodId(),plan.getClusterId())) {
    s_logger.debug("String_Node_Str");
    return null;
  }
  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,_allocationAlgorithm);
    }
 else {
      s_logger.debug("String_Node_Str");
      avoid.addPod(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) {
      clusterList=listClustersByCapacity(podIdSpecified,cpu_requested,ram_requested,avoid,false,cpuOverprovisioningFactor);
      if (!clusterList.isEmpty()) {
        if (avoid.getClustersToAvoid() != null) {
          if (s_logger.isDebugEnabled()) {
            s_logger.debug("String_Node_Str" + avoid.getClustersToAvoid());
          }
          clusterList.removeAll(avoid.getClustersToAvoid());
        }
        List<Long> disabledClusters=listDisabledClusters(plan.getDataCenterId(),podIdSpecified);
        if (!disabledClusters.isEmpty()) {
          if (s_logger.isDebugEnabled()) {
            s_logger.debug("String_Node_Str" + disabledClusters);
          }
          clusterList.removeAll(disabledClusters);
        }
        DeployDestination dest=checkClustersforDestination(clusterList,vmProfile,plan,avoid,dc,_allocationAlgorithm);
        if (dest == null) {
          avoid.addPod(plan.getPodId());
        }
        return dest;
      }
 else {
        if (s_logger.isDebugEnabled()) {
          s_logger.debug("String_Node_Str");
        }
        avoid.addPod(plan.getPodId());
        return null;
      }
    }
 else {
      s_logger.debug("String_Node_Str");
      avoid.addPod(plan.getPodId());
      return null;
    }
  }
 else {
    s_logger.debug("String_Node_Str" + plan.getDataCenterId());
    List<Long> prioritizedClusterIds=listClustersByCapacity(plan.getDataCenterId(),cpu_requested,ram_requested,avoid,true,cpuOverprovisioningFactor);
    if (!prioritizedClusterIds.isEmpty()) {
      if (avoid.getClustersToAvoid() != null) {
        if (s_logger.isDebugEnabled()) {
          s_logger.debug("String_Node_Str" + avoid.getClustersToAvoid());
        }
        prioritizedClusterIds.removeAll(avoid.getClustersToAvoid());
      }
      List<Long> disabledClusters=listDisabledClusters(plan.getDataCenterId(),null);
      if (!disabledClusters.isEmpty()) {
        if (s_logger.isDebugEnabled()) {
          s_logger.debug("String_Node_Str" + disabledClusters);
        }
        prioritizedClusterIds.removeAll(disabledClusters);
      }
    }
 else {
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str");
      }
      return null;
    }
    if (!prioritizedClusterIds.isEmpty()) {
      boolean applyUserConcentrationPodHeuristic=Boolean.parseBoolean(_configDao.getValue(Config.UseUserConcentratedPodAllocation.key()));
      if (applyUserConcentrationPodHeuristic && vmProfile.getOwner() != null) {
        long accountId=vmProfile.getOwner().getAccountId();
        List<Long> podIds=listPodsByUserConcentration(plan.getDataCenterId(),accountId);
        if (!podIds.isEmpty()) {
          if (avoid.getPodsToAvoid() != null) {
            if (s_logger.isDebugEnabled()) {
              s_logger.debug("String_Node_Str" + avoid.getPodsToAvoid());
            }
            podIds.removeAll(avoid.getPodsToAvoid());
          }
          clusterList=reorderClustersByPods(prioritizedClusterIds,podIds);
        }
 else {
          clusterList=prioritizedClusterIds;
        }
      }
 else {
        clusterList=prioritizedClusterIds;
      }
      return checkClustersforDestination(clusterList,vmProfile,plan,avoid,dc,_allocationAlgorithm);
    }
 else {
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str");
      }
      return null;
    }
  }
}

Fixed version (ground truth):
@Override public DeployDestination plan(VirtualMachineProfile<? extends VirtualMachine> vmProfile,DeploymentPlan plan,ExcludeList avoid) throws InsufficientServerCapacityException {
  String _allocationAlgorithm=_configDao.getValue(Config.VmAllocationAlgorithm.key());
  VirtualMachine vm=vmProfile.getVirtualMachine();
  ServiceOffering offering=vmProfile.getServiceOffering();
  DataCenter dc=_dcDao.findById(vm.getDataCenterIdToDeployIn());
  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");
    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"));
  }
  if (plan.getHostId() != 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());
    Pair<Map<Volume,List<StoragePool>>,List<Volume>> result=findSuitablePoolsForVolumes(vmProfile,lastPlan,avoid,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) {
    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 (host.getStatus() == Status.Up && host.getHostAllocationState() == Host.HostAllocationState.Enabled) {
        if (isEnabledForAllocation(host.getDataCenterId(),host.getPodId(),host.getClusterId())) {
          if (_capacityMgr.checkIfHostHasCapacity(host.getId(),cpu_requested,ram_requested,true,cpuOverprovisioningFactor)) {
            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());
            Pair<Map<Volume,List<StoragePool>>,List<Volume>> result=findSuitablePoolsForVolumes(vmProfile,lastPlan,avoid,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.getHostAllocationState().name());
      }
    }
    s_logger.debug("String_Node_Str");
  }
  if (!isEnabledForAllocation(plan.getDataCenterId(),plan.getPodId(),plan.getClusterId())) {
    s_logger.debug("String_Node_Str");
    return null;
  }
  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,_allocationAlgorithm);
    }
 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) {
      clusterList=listClustersByCapacity(podIdSpecified,cpu_requested,ram_requested,avoid,false,cpuOverprovisioningFactor);
      if (!clusterList.isEmpty()) {
        if (avoid.getClustersToAvoid() != null) {
          if (s_logger.isDebugEnabled()) {
            s_logger.debug("String_Node_Str" + avoid.getClustersToAvoid());
          }
          clusterList.removeAll(avoid.getClustersToAvoid());
        }
        List<Long> disabledClusters=listDisabledClusters(plan.getDataCenterId(),podIdSpecified);
        if (!disabledClusters.isEmpty()) {
          if (s_logger.isDebugEnabled()) {
            s_logger.debug("String_Node_Str" + disabledClusters);
          }
          clusterList.removeAll(disabledClusters);
        }
        DeployDestination dest=checkClustersforDestination(clusterList,vmProfile,plan,avoid,dc,_allocationAlgorithm);
        if (dest == null) {
          avoid.addPod(plan.getPodId());
        }
        return dest;
      }
 else {
        if (s_logger.isDebugEnabled()) {
          s_logger.debug("String_Node_Str");
        }
        avoid.addPod(plan.getPodId());
        return null;
      }
    }
 else {
      s_logger.debug("String_Node_Str");
      avoid.addPod(plan.getPodId());
      return null;
    }
  }
 else {
    s_logger.debug("String_Node_Str" + plan.getDataCenterId());
    List<Long> prioritizedClusterIds=listClustersByCapacity(plan.getDataCenterId(),cpu_requested,ram_requested,avoid,true,cpuOverprovisioningFactor);
    if (!prioritizedClusterIds.isEmpty()) {
      if (avoid.getClustersToAvoid() != null) {
        if (s_logger.isDebugEnabled()) {
          s_logger.debug("String_Node_Str" + avoid.getClustersToAvoid());
        }
        prioritizedClusterIds.removeAll(avoid.getClustersToAvoid());
      }
      List<Long> disabledClusters=listDisabledClusters(plan.getDataCenterId(),null);
      if (!disabledClusters.isEmpty()) {
        if (s_logger.isDebugEnabled()) {
          s_logger.debug("String_Node_Str" + disabledClusters);
        }
        prioritizedClusterIds.removeAll(disabledClusters);
      }
    }
 else {
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str");
      }
      return null;
    }
    if (!prioritizedClusterIds.isEmpty()) {
      boolean applyUserConcentrationPodHeuristic=Boolean.parseBoolean(_configDao.getValue(Config.UseUserConcentratedPodAllocation.key()));
      if (applyUserConcentrationPodHeuristic && vmProfile.getOwner() != null) {
        long accountId=vmProfile.getOwner().getAccountId();
        List<Long> podIds=listPodsByUserConcentration(plan.getDataCenterId(),accountId);
        if (!podIds.isEmpty()) {
          if (avoid.getPodsToAvoid() != null) {
            if (s_logger.isDebugEnabled()) {
              s_logger.debug("String_Node_Str" + avoid.getPodsToAvoid());
            }
            podIds.removeAll(avoid.getPodsToAvoid());
          }
          clusterList=reorderClustersByPods(prioritizedClusterIds,podIds);
        }
 else {
          clusterList=prioritizedClusterIds;
        }
      }
 else {
        clusterList=prioritizedClusterIds;
      }
      return checkClustersforDestination(clusterList,vmProfile,plan,avoid,dc,_allocationAlgorithm);
    }
 else {
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str");
      }
      return null;
    }
  }
}