Program: 105260
Project: 105260
Buggy source:
protected void updateComputeHost(final HostVO host,final StartupCommand startup,final Host.Type type) throws AgentAuthnException {
  String zoneToken=startup.getDataCenter();
  if (zoneToken == null) {
    s_logger.warn("String_Node_Str");
    throw new AgentAuthnException("String_Node_Str");
  }
  DataCenterVO zone=_zoneDao.findByToken(zoneToken);
  if (zone == null) {
    zone=_zoneDao.findByName(zoneToken);
    if (zone == null) {
      try {
        long zoneId=Long.parseLong(zoneToken);
        zone=_zoneDao.findById(zoneId);
        if (zone == null) {
          throw new AgentAuthnException("String_Node_Str" + zoneToken);
        }
      }
 catch (      NumberFormatException nfe) {
        throw new AgentAuthnException("String_Node_Str" + zoneToken);
      }
    }
  }
  if (s_logger.isDebugEnabled()) {
    s_logger.debug("String_Node_Str");
  }
  long zoneId=zone.getId();
  ResourceDetail maxHostsInZone=_zoneDetailsDao.findDetail(zoneId,ZoneConfig.MaxHosts.key());
  if (maxHostsInZone != null) {
    long maxHosts=new Long(maxHostsInZone.getValue()).longValue();
    long currentCountOfHosts=_hostDao.countRoutingHostsByDataCenter(zoneId);
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + currentCountOfHosts + "String_Node_Str"+ maxHosts);
    }
    if (currentCountOfHosts >= maxHosts) {
      throw new AgentAuthnException("String_Node_Str" + zone.getName() + "String_Node_Str"+ maxHosts+ "String_Node_Str");
    }
  }
  HostPodVO pod=null;
  if (startup.getPrivateIpAddress() == null) {
    s_logger.warn("String_Node_Str");
    throw new AgentAuthnException("String_Node_Str");
  }
  if (startup.getPrivateNetmask() == null) {
    s_logger.warn("String_Node_Str");
    throw new AgentAuthnException("String_Node_Str");
  }
  if (host.getPodId() != null) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str");
    }
    pod=_podDao.findById(host.getPodId());
    if (!checkCIDR(type,pod,startup.getPrivateIpAddress(),startup.getPrivateNetmask())) {
      pod=null;
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str" + host.getPodId());
      }
    }
 else {
      updatePodNetmaskIfNeeded(pod,startup.getPrivateNetmask());
    }
  }
  if (pod == null) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str");
    }
    boolean podFound=false;
    List<HostPodVO> podsInZone=_podDao.listByDataCenterId(zoneId);
    for (    HostPodVO hostPod : podsInZone) {
      if (checkCIDR(type,hostPod,startup.getPrivateIpAddress(),startup.getPrivateNetmask())) {
        pod=hostPod;
        updatePodNetmaskIfNeeded(pod,startup.getPrivateNetmask());
        podFound=true;
        break;
      }
    }
    if (!podFound) {
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str");
      }
      if (startup.getGatewayIpAddress() == null) {
        s_logger.warn("String_Node_Str");
        throw new AgentAuthnException("String_Node_Str");
      }
      String podName="String_Node_Str" + (podsInZone.size() + 1);
      try {
        String gateway=startup.getGatewayIpAddress();
        String cidr=NetUtils.getCidrFromGatewayAndNetmask(gateway,startup.getPrivateNetmask());
        String[] cidrPair=cidr.split("String_Node_Str");
        String cidrAddress=cidrPair[0];
        long cidrSize=Long.parseLong(cidrPair[1]);
        String startIp=NetUtils.getIpRangeStartIpFromCidr(cidrAddress,cidrSize);
        String endIp=NetUtils.getIpRangeEndIpFromCidr(cidrAddress,cidrSize);
        pod=_configurationManager.createPod(-1,podName,zoneId,gateway,cidr,startIp,endIp,null,true);
      }
 catch (      Exception e) {
        throw new CloudRuntimeException("String_Node_Str" + podName + "String_Node_Str"+ zoneId,e);
      }
    }
  }
  final StartupRoutingCommand scc=(StartupRoutingCommand)startup;
  ClusterVO cluster=null;
  if (host.getClusterId() != null) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str");
    }
    cluster=_clusterDao.findById(host.getClusterId());
  }
  if (cluster == null) {
    String clusterName="String_Node_Str" + startup.getPrivateIpAddress();
    ClusterVO existingCluster=_clusterDao.findBy(clusterName,pod.getId());
    if (existingCluster != null) {
      cluster=existingCluster;
    }
 else {
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str" + clusterName + "String_Node_Str"+ pod.getId()+ "String_Node_Str"+ zoneId);
      }
      cluster=new ClusterVO(zoneId,pod.getId(),clusterName);
      cluster.setHypervisorType(scc.getHypervisorType().toString());
      try {
        cluster=_clusterDao.persist(cluster);
      }
 catch (      Exception e) {
        throw new CloudRuntimeException("String_Node_Str" + clusterName + "String_Node_Str"+ pod.getId()+ "String_Node_Str"+ zoneId,e);
      }
    }
  }
  if (s_logger.isDebugEnabled()) {
    s_logger.debug("String_Node_Str" + zoneId + "String_Node_Str"+ pod.getId()+ "String_Node_Str"+ cluster.getId());
  }
  host.setDataCenterId(zone.getId());
  host.setPodId(pod.getId());
  host.setClusterId(cluster.getId());
  host.setPrivateIpAddress(startup.getPrivateIpAddress());
  host.setPrivateNetmask(startup.getPrivateNetmask());
  host.setPrivateMacAddress(startup.getPrivateMacAddress());
  host.setPublicIpAddress(startup.getPublicIpAddress());
  host.setPublicMacAddress(startup.getPublicMacAddress());
  host.setPublicNetmask(startup.getPublicNetmask());
  host.setStorageIpAddress(startup.getStorageIpAddress());
  host.setStorageMacAddress(startup.getStorageMacAddress());
  host.setStorageNetmask(startup.getStorageNetmask());
  host.setVersion(startup.getVersion());
  host.setName(startup.getName());
  host.setType(type);
  host.setStorageUrl(startup.getIqn());
  host.setLastPinged(System.currentTimeMillis() >> 10);
  host.setCaps(scc.getCapabilities());
  host.setCpus(scc.getCpus());
  host.setTotalMemory(scc.getMemory());
  host.setSpeed(scc.getSpeed());
  HypervisorType hyType=scc.getHypervisorType();
  host.setHypervisorType(hyType);
  host.setHypervisorVersion(scc.getHypervisorVersion());
}

Fixed version (ground truth):
protected void updateComputeHost(final HostVO host,final StartupCommand startup,final Host.Type type) throws AgentAuthnException {
  String zoneToken=startup.getDataCenter();
  if (zoneToken == null) {
    s_logger.warn("String_Node_Str");
    throw new AgentAuthnException("String_Node_Str");
  }
  DataCenterVO zone=_zoneDao.findByToken(zoneToken);
  if (zone == null) {
    zone=_zoneDao.findByName(zoneToken);
    if (zone == null) {
      try {
        long zoneId=Long.parseLong(zoneToken);
        zone=_zoneDao.findById(zoneId);
        if (zone == null) {
          throw new AgentAuthnException("String_Node_Str" + zoneToken);
        }
      }
 catch (      NumberFormatException nfe) {
        throw new AgentAuthnException("String_Node_Str" + zoneToken);
      }
    }
  }
  if (s_logger.isDebugEnabled()) {
    s_logger.debug("String_Node_Str");
  }
  long zoneId=zone.getId();
  ResourceDetail maxHostsInZone=_zoneDetailsDao.findDetail(zoneId,ZoneConfig.MaxHosts.key());
  if (maxHostsInZone != null) {
    long maxHosts=Long.parseLong(maxHostsInZone.getValue());
    long currentCountOfHosts=_hostDao.countRoutingHostsByDataCenter(zoneId);
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + currentCountOfHosts + "String_Node_Str"+ maxHosts);
    }
    if (currentCountOfHosts >= maxHosts) {
      throw new AgentAuthnException("String_Node_Str" + zone.getName() + "String_Node_Str"+ maxHosts+ "String_Node_Str");
    }
  }
  HostPodVO pod=null;
  if (startup.getPrivateIpAddress() == null) {
    s_logger.warn("String_Node_Str");
    throw new AgentAuthnException("String_Node_Str");
  }
  if (startup.getPrivateNetmask() == null) {
    s_logger.warn("String_Node_Str");
    throw new AgentAuthnException("String_Node_Str");
  }
  if (host.getPodId() != null) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str");
    }
    pod=_podDao.findById(host.getPodId());
    if (!checkCIDR(type,pod,startup.getPrivateIpAddress(),startup.getPrivateNetmask())) {
      pod=null;
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str" + host.getPodId());
      }
    }
 else {
      updatePodNetmaskIfNeeded(pod,startup.getPrivateNetmask());
    }
  }
  if (pod == null) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str");
    }
    boolean podFound=false;
    List<HostPodVO> podsInZone=_podDao.listByDataCenterId(zoneId);
    for (    HostPodVO hostPod : podsInZone) {
      if (checkCIDR(type,hostPod,startup.getPrivateIpAddress(),startup.getPrivateNetmask())) {
        pod=hostPod;
        updatePodNetmaskIfNeeded(pod,startup.getPrivateNetmask());
        podFound=true;
        break;
      }
    }
    if (!podFound) {
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str");
      }
      if (startup.getGatewayIpAddress() == null) {
        s_logger.warn("String_Node_Str");
        throw new AgentAuthnException("String_Node_Str");
      }
      String podName="String_Node_Str" + (podsInZone.size() + 1);
      try {
        String gateway=startup.getGatewayIpAddress();
        String cidr=NetUtils.getCidrFromGatewayAndNetmask(gateway,startup.getPrivateNetmask());
        String[] cidrPair=cidr.split("String_Node_Str");
        String cidrAddress=cidrPair[0];
        long cidrSize=Long.parseLong(cidrPair[1]);
        String startIp=NetUtils.getIpRangeStartIpFromCidr(cidrAddress,cidrSize);
        String endIp=NetUtils.getIpRangeEndIpFromCidr(cidrAddress,cidrSize);
        pod=_configurationManager.createPod(-1,podName,zoneId,gateway,cidr,startIp,endIp,null,true);
      }
 catch (      Exception e) {
        throw new CloudRuntimeException("String_Node_Str" + podName + "String_Node_Str"+ zoneId,e);
      }
    }
  }
  final StartupRoutingCommand scc=(StartupRoutingCommand)startup;
  ClusterVO cluster=null;
  if (host.getClusterId() != null) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str");
    }
    cluster=_clusterDao.findById(host.getClusterId());
  }
  if (cluster == null) {
    String clusterName="String_Node_Str" + startup.getPrivateIpAddress();
    ClusterVO existingCluster=_clusterDao.findBy(clusterName,pod.getId());
    if (existingCluster != null) {
      cluster=existingCluster;
    }
 else {
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str" + clusterName + "String_Node_Str"+ pod.getId()+ "String_Node_Str"+ zoneId);
      }
      cluster=new ClusterVO(zoneId,pod.getId(),clusterName);
      cluster.setHypervisorType(scc.getHypervisorType().toString());
      try {
        cluster=_clusterDao.persist(cluster);
      }
 catch (      Exception e) {
        throw new CloudRuntimeException("String_Node_Str" + clusterName + "String_Node_Str"+ pod.getId()+ "String_Node_Str"+ zoneId,e);
      }
    }
  }
  if (s_logger.isDebugEnabled()) {
    s_logger.debug("String_Node_Str" + zoneId + "String_Node_Str"+ pod.getId()+ "String_Node_Str"+ cluster.getId());
  }
  host.setDataCenterId(zone.getId());
  host.setPodId(pod.getId());
  host.setClusterId(cluster.getId());
  host.setPrivateIpAddress(startup.getPrivateIpAddress());
  host.setPrivateNetmask(startup.getPrivateNetmask());
  host.setPrivateMacAddress(startup.getPrivateMacAddress());
  host.setPublicIpAddress(startup.getPublicIpAddress());
  host.setPublicMacAddress(startup.getPublicMacAddress());
  host.setPublicNetmask(startup.getPublicNetmask());
  host.setStorageIpAddress(startup.getStorageIpAddress());
  host.setStorageMacAddress(startup.getStorageMacAddress());
  host.setStorageNetmask(startup.getStorageNetmask());
  host.setVersion(startup.getVersion());
  host.setName(startup.getName());
  host.setType(type);
  host.setStorageUrl(startup.getIqn());
  host.setLastPinged(System.currentTimeMillis() >> 10);
  host.setCaps(scc.getCapabilities());
  host.setCpus(scc.getCpus());
  host.setTotalMemory(scc.getMemory());
  host.setSpeed(scc.getSpeed());
  HypervisorType hyType=scc.getHypervisorType();
  host.setHypervisorType(hyType);
  host.setHypervisorVersion(scc.getHypervisorVersion());
}