Program: 106627
Project: 106627
Buggy source:
@Override public List<VirtualRouter> applyDhcpEntry(Network network,NicProfile nic,VirtualMachineProfile<UserVm> profile,DeployDestination dest,ReservationContext context,List<DomainRouterVO> routers) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
  List<VirtualRouter> rets=new ArrayList<VirtualRouter>(routers.size());
  _userVmDao.loadDetails((UserVmVO)profile.getVirtualMachine());
  DataCenter dc=dest.getDataCenter();
  String serviceOffering=_serviceOfferingDao.findByIdIncludingRemoved(profile.getServiceOfferingId()).getDisplayText();
  String zoneName=_dcDao.findById(network.getDataCenterId()).getName();
  boolean isZoneBasic=(dc.getNetworkType() == NetworkType.Basic);
  List<VirtualRouter> connectedRouters=new ArrayList<VirtualRouter>();
  List<VirtualRouter> disconnectedRouters=new ArrayList<VirtualRouter>();
  for (  DomainRouterVO router : routers) {
    boolean sendDnsDhcpData=true;
    if (router.getState() != State.Running) {
      s_logger.warn("String_Node_Str" + profile.getVirtualMachine() + "String_Node_Str"+ router+ "String_Node_Str");
      continue;
    }
    if (router.isStopPending()) {
      if (_hostDao.findById(router.getHostId()).getStatus() == Status.Up) {
        throw new ResourceUnavailableException("String_Node_Str" + router.getInstanceName() + "String_Node_Str",VirtualRouter.class,router.getId());
      }
      s_logger.warn("String_Node_Str" + profile.getVirtualMachine() + "String_Node_Str"+ router+ "String_Node_Str");
      continue;
    }
    Long podId=null;
    if (isZoneBasic) {
      podId=dest.getPod().getId();
      if (router.getPodIdToDeployIn().longValue() != podId.longValue()) {
        if (_dnsBasicZoneUpdates.equalsIgnoreCase("String_Node_Str")) {
          sendDnsDhcpData=false;
        }
      }
    }
    Commands cmds=new Commands(OnError.Stop);
    String routerControlIpAddress=null;
    List<NicVO> nics=_nicDao.listByVmId(router.getId());
    for (    NicVO n : nics) {
      NetworkVO nc=_networkDao.findById(n.getNetworkId());
      if (nc.getTrafficType() == TrafficType.Control) {
        routerControlIpAddress=n.getIp4Address();
      }
    }
    if (sendDnsDhcpData) {
      DhcpEntryCommand dhcpCommand=new DhcpEntryCommand(nic.getMacAddress(),nic.getIp4Address(),profile.getVirtualMachine().getHostName());
      dhcpCommand.setDefaultRouter(_nicDao.findDefaultNicForVM(profile.getVirtualMachine().getId()).getGateway());
      dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_IP,routerControlIpAddress);
      dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP,router.getGuestIpAddress());
      dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_NAME,router.getInstanceName());
      dhcpCommand.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE,dc.getNetworkType().toString());
      cmds.addCommand("String_Node_Str",dhcpCommand);
    }
    if (cmds.size() > 0) {
      boolean podLevelException=false;
      if (isZoneBasic && podId != null && profile.getVirtualMachine().getType() == VirtualMachine.Type.User && network.getTrafficType() == TrafficType.Guest && network.getGuestType() == Network.GuestType.Shared) {
        podLevelException=true;
      }
      try {
        _agentMgr.send(router.getHostId(),cmds);
      }
 catch (      AgentUnavailableException e) {
        s_logger.warn("String_Node_Str" + router.getHostId(),e);
        disconnectedRouters.add(router);
        continue;
      }
catch (      OperationTimedoutException e) {
        s_logger.warn("String_Node_Str" + router.getHostId(),e);
        disconnectedRouters.add(router);
        continue;
      }
      connectedRouters.add(router);
      Answer answer=cmds.getAnswer("String_Node_Str");
      if (!answer.getResult()) {
        s_logger.error("String_Node_Str" + profile + "String_Node_Str"+ router.getHostName()+ "String_Node_Str"+ answer.getDetails());
        if (podLevelException) {
          throw new ResourceUnavailableException("String_Node_Str" + profile + "String_Node_Str"+ answer.getDetails(),Pod.class,podId);
        }
        throw new ResourceUnavailableException("String_Node_Str" + profile + "String_Node_Str"+ answer.getDetails(),DataCenter.class,router.getDataCenterIdToDeployIn());
      }
    }
    rets.add(router);
  }
  String msg="String_Node_Str";
  if (!connectedRouters.isEmpty()) {
    handleSingleWorkingRedundantRouter(connectedRouters,disconnectedRouters,msg);
  }
 else   if (!disconnectedRouters.isEmpty()) {
    for (    VirtualRouter router : disconnectedRouters) {
      if (s_logger.isDebugEnabled()) {
        s_logger.debug(msg + router.getInstanceName() + "String_Node_Str"+ router.getId()+ "String_Node_Str");
      }
    }
    throw new ResourceUnavailableException(msg,VirtualRouter.class,disconnectedRouters.get(0).getId());
  }
  return rets;
}

Fixed version (ground truth):
@Override public List<VirtualRouter> applyDhcpEntry(Network network,NicProfile nic,VirtualMachineProfile<UserVm> profile,DeployDestination dest,ReservationContext context,List<DomainRouterVO> routers) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
  List<VirtualRouter> rets=new ArrayList<VirtualRouter>(routers.size());
  _userVmDao.loadDetails((UserVmVO)profile.getVirtualMachine());
  DataCenter dc=dest.getDataCenter();
  String serviceOffering=_serviceOfferingDao.findByIdIncludingRemoved(profile.getServiceOfferingId()).getDisplayText();
  String zoneName=_dcDao.findById(network.getDataCenterId()).getName();
  boolean isZoneBasic=(dc.getNetworkType() == NetworkType.Basic);
  List<VirtualRouter> connectedRouters=new ArrayList<VirtualRouter>();
  List<VirtualRouter> disconnectedRouters=new ArrayList<VirtualRouter>();
  for (  DomainRouterVO router : routers) {
    boolean sendDnsDhcpData=true;
    if (router.getState() != State.Running) {
      s_logger.warn("String_Node_Str" + profile.getVirtualMachine() + "String_Node_Str"+ router+ "String_Node_Str");
      continue;
    }
    if (router.isStopPending()) {
      if (_hostDao.findById(router.getHostId()).getStatus() == Status.Up) {
        throw new ResourceUnavailableException("String_Node_Str" + router.getInstanceName() + "String_Node_Str",VirtualRouter.class,router.getId());
      }
      s_logger.warn("String_Node_Str" + profile.getVirtualMachine() + "String_Node_Str"+ router+ "String_Node_Str");
      continue;
    }
    Long podId=null;
    if (isZoneBasic) {
      podId=dest.getPod().getId();
      if (router.getPodIdToDeployIn().longValue() != podId.longValue()) {
        if (_dnsBasicZoneUpdates.equalsIgnoreCase("String_Node_Str")) {
          sendDnsDhcpData=false;
        }
      }
    }
    Commands cmds=new Commands(OnError.Stop);
    String routerControlIpAddress=null;
    List<NicVO> nics=_nicDao.listByVmId(router.getId());
    for (    NicVO n : nics) {
      NetworkVO nc=_networkDao.findById(n.getNetworkId());
      if (nc.getTrafficType() == TrafficType.Control) {
        routerControlIpAddress=n.getIp4Address();
      }
    }
    if (sendDnsDhcpData) {
      DhcpEntryCommand dhcpCommand=new DhcpEntryCommand(nic.getMacAddress(),nic.getIp4Address(),profile.getVirtualMachine().getHostName());
      String defaultDhcpIp=findDefaultDhcpIp(profile.getVirtualMachine().getId());
      dhcpCommand.setDefaultRouter(defaultDhcpIp);
      dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_IP,routerControlIpAddress);
      dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP,router.getGuestIpAddress());
      dhcpCommand.setAccessDetail(NetworkElementCommand.ROUTER_NAME,router.getInstanceName());
      dhcpCommand.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE,dc.getNetworkType().toString());
      cmds.addCommand("String_Node_Str",dhcpCommand);
    }
    if (cmds.size() > 0) {
      boolean podLevelException=false;
      if (isZoneBasic && podId != null && profile.getVirtualMachine().getType() == VirtualMachine.Type.User && network.getTrafficType() == TrafficType.Guest && network.getGuestType() == Network.GuestType.Shared) {
        podLevelException=true;
      }
      try {
        _agentMgr.send(router.getHostId(),cmds);
      }
 catch (      AgentUnavailableException e) {
        s_logger.warn("String_Node_Str" + router.getHostId(),e);
        disconnectedRouters.add(router);
        continue;
      }
catch (      OperationTimedoutException e) {
        s_logger.warn("String_Node_Str" + router.getHostId(),e);
        disconnectedRouters.add(router);
        continue;
      }
      connectedRouters.add(router);
      Answer answer=cmds.getAnswer("String_Node_Str");
      if (!answer.getResult()) {
        s_logger.error("String_Node_Str" + profile + "String_Node_Str"+ router.getHostName()+ "String_Node_Str"+ answer.getDetails());
        if (podLevelException) {
          throw new ResourceUnavailableException("String_Node_Str" + profile + "String_Node_Str"+ answer.getDetails(),Pod.class,podId);
        }
        throw new ResourceUnavailableException("String_Node_Str" + profile + "String_Node_Str"+ answer.getDetails(),DataCenter.class,router.getDataCenterIdToDeployIn());
      }
    }
    rets.add(router);
  }
  String msg="String_Node_Str";
  if (!connectedRouters.isEmpty()) {
    handleSingleWorkingRedundantRouter(connectedRouters,disconnectedRouters,msg);
  }
 else   if (!disconnectedRouters.isEmpty()) {
    for (    VirtualRouter router : disconnectedRouters) {
      if (s_logger.isDebugEnabled()) {
        s_logger.debug(msg + router.getInstanceName() + "String_Node_Str"+ router.getId()+ "String_Node_Str");
      }
    }
    throw new ResourceUnavailableException(msg,VirtualRouter.class,disconnectedRouters.get(0).getId());
  }
  return rets;
}