From 9c8d8d1dc412983f8cd6a2cf6b474c8f2a617c9b Mon Sep 17 00:00:00 2001 From: abhishek Date: Fri, 10 Dec 2010 15:04:18 -0800 Subject: [PATCH] bug 7474: implementing search for public ip address for a zone, without the filter for vlan db id. status 7474: resolved fixed --- .../src/com/cloud/alert/AlertManagerImpl.java | 12 +++++++--- .../com/cloud/network/dao/IPAddressDao.java | 2 ++ .../cloud/network/dao/IPAddressDaoImpl.java | 24 ++++++++++++++++++- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/server/src/com/cloud/alert/AlertManagerImpl.java b/server/src/com/cloud/alert/AlertManagerImpl.java index 65736c16e06..5efbff1fefa 100644 --- a/server/src/com/cloud/alert/AlertManagerImpl.java +++ b/server/src/com/cloud/alert/AlertManagerImpl.java @@ -50,6 +50,7 @@ import com.cloud.dc.HostPodVO; import com.cloud.dc.dao.DataCenterDao; import com.cloud.dc.dao.DataCenterIpAddressDao; import com.cloud.dc.dao.HostPodDao; +import com.cloud.dc.dao.VlanDao; import com.cloud.host.Host; import com.cloud.host.HostVO; import com.cloud.host.Status; @@ -332,9 +333,14 @@ public class AlertManagerImpl implements AlertManager { List datacenters = _dcDao.listAllIncludingRemoved(); for (DataCenterVO datacenter : datacenters) { long dcId = datacenter.getId(); - - int totalPublicIPs = _publicIPAddressDao.countIPs(dcId, -1, false); - int allocatedPublicIPs = _publicIPAddressDao.countIPs(dcId, -1, true); + + //NOTE + //What happens if we have multiple vlans? Dashboard currently shows stats + //with no filter based on a vlan + //ideal way would be to remove out the vlan param, and filter only on dcId + //implementing the same + int totalPublicIPs = _publicIPAddressDao.countIPsForDashboard(dcId, false); + int allocatedPublicIPs = _publicIPAddressDao.countIPsForDashboard(dcId, true); CapacityVO newPublicIPCapacity = new CapacityVO(null, dcId, null, allocatedPublicIPs, totalPublicIPs, CapacityVO.CAPACITY_TYPE_PUBLIC_IP); newCapacities.add(newPublicIPCapacity); diff --git a/server/src/com/cloud/network/dao/IPAddressDao.java b/server/src/com/cloud/network/dao/IPAddressDao.java index 1d96fe0190e..1c65cf7c52b 100644 --- a/server/src/com/cloud/network/dao/IPAddressDao.java +++ b/server/src/com/cloud/network/dao/IPAddressDao.java @@ -42,4 +42,6 @@ public interface IPAddressDao extends GenericDao { boolean mark(long dcId, String ip); List assignAcccountSpecificIps(long accountId, long longValue, Long vlanDbId, boolean sourceNat); + + int countIPsForDashboard(long dcId, boolean onlyCountAllocated); } diff --git a/server/src/com/cloud/network/dao/IPAddressDaoImpl.java b/server/src/com/cloud/network/dao/IPAddressDaoImpl.java index 9efdeb86c6b..43da2cbedf0 100644 --- a/server/src/com/cloud/network/dao/IPAddressDaoImpl.java +++ b/server/src/com/cloud/network/dao/IPAddressDaoImpl.java @@ -50,7 +50,10 @@ public class IPAddressDaoImpl extends GenericDaoBase implem protected final SearchBuilder VlanDbIdSearchUnallocated; protected final GenericSearchBuilder AllIpCount; protected final GenericSearchBuilder AllocatedIpCount; - + protected final GenericSearchBuilder AllIpCountForDashboard; + protected final GenericSearchBuilder AllocatedIpCountForDashboard; + + // make it public for JUnit test public IPAddressDaoImpl() { AllFieldsSearch = createSearchBuilder(); @@ -79,6 +82,17 @@ public class IPAddressDaoImpl extends GenericDaoBase implem AllocatedIpCount.and("vlan", AllocatedIpCount.entity().getVlanId(), Op.EQ); AllocatedIpCount.and("allocated", AllocatedIpCount.entity().getAllocatedTime(), Op.NNULL); AllocatedIpCount.done(); + + AllIpCountForDashboard = createSearchBuilder(Integer.class); + AllIpCountForDashboard.select(null, Func.COUNT, AllIpCountForDashboard.entity().getAddress()); + AllIpCountForDashboard.and("dc", AllIpCountForDashboard.entity().getDataCenterId(), Op.EQ); + AllIpCountForDashboard.done(); + + AllocatedIpCountForDashboard = createSearchBuilder(Integer.class); + AllocatedIpCountForDashboard.select(null, Func.COUNT, AllocatedIpCountForDashboard.entity().getAddress()); + AllocatedIpCountForDashboard.and("dc", AllocatedIpCountForDashboard.entity().getDataCenterId(), Op.EQ); + AllocatedIpCountForDashboard.and("allocated", AllocatedIpCountForDashboard.entity().getAllocatedTime(), Op.NNULL); + AllocatedIpCountForDashboard.done(); } @Override @@ -204,6 +218,14 @@ public class IPAddressDaoImpl extends GenericDaoBase implem return customSearch(sc, null).get(0); } + @Override + public int countIPsForDashboard(long dcId, boolean onlyCountAllocated) { + SearchCriteria sc = onlyCountAllocated ? AllocatedIpCountForDashboard.create() : AllIpCountForDashboard.create(); + sc.setParameters("dc", dcId); + + return customSearch(sc, null).get(0); + } + @Override @DB public int countIPs(long dcId, Long accountId, String vlanId, String vlanGateway, String vlanNetmask) {