From cbc47b902113a66fecce5ec163822a710232a9c4 Mon Sep 17 00:00:00 2001 From: Nitin Mehta Date: Wed, 8 Feb 2012 15:34:56 +0530 Subject: [PATCH] Bug 13059: For listing top consumed resources only uyse enabled zone for sec storage Also improve the transaction logic. Reviewed-By: Kishan --- api/src/com/cloud/api/commands/ListCapacityCmd.java | 6 +++--- server/src/com/cloud/capacity/dao/CapacityDaoImpl.java | 7 +------ server/src/com/cloud/server/ManagementServerImpl.java | 10 +++++++--- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/api/src/com/cloud/api/commands/ListCapacityCmd.java b/api/src/com/cloud/api/commands/ListCapacityCmd.java index a2551f9bfe1..b11425b9f39 100755 --- a/api/src/com/cloud/api/commands/ListCapacityCmd.java +++ b/api/src/com/cloud/api/commands/ListCapacityCmd.java @@ -53,13 +53,13 @@ public class ListCapacityCmd extends BaseListCmd { private Long podId; @IdentityMapper(entityTableName="cluster") - @Parameter(name=ApiConstants.CLUSTER_ID, type=CommandType.LONG, description="lists capacity by the Cluster ID") + @Parameter(name=ApiConstants.CLUSTER_ID, type=CommandType.LONG, since="3.0.0", description="lists capacity by the Cluster ID") private Long clusterId; - @Parameter(name=ApiConstants.FETCH_LATEST, type=CommandType.BOOLEAN, description="recalculate capacities and fetch the latest") + @Parameter(name=ApiConstants.FETCH_LATEST, type=CommandType.BOOLEAN, since="3.0.0", description="recalculate capacities and fetch the latest") private Boolean fetchLatest; - @Parameter(name=ApiConstants.SORT_BY_USAGE, type=CommandType.BOOLEAN, description="if true then lists the top consumed resources at various hierarchy level") + @Parameter(name=ApiConstants.SORT_BY_USAGE, type=CommandType.BOOLEAN, since="3.0.0", description="if true then lists the top consumed resources at various hierarchy level and in enabled resource state") private Boolean sortByUsage; @Parameter(name=ApiConstants.TYPE, type=CommandType.INTEGER, description="lists capacity by type" + diff --git a/server/src/com/cloud/capacity/dao/CapacityDaoImpl.java b/server/src/com/cloud/capacity/dao/CapacityDaoImpl.java index d7c1ef2816e..a5c0a3d2dc3 100755 --- a/server/src/com/cloud/capacity/dao/CapacityDaoImpl.java +++ b/server/src/com/cloud/capacity/dao/CapacityDaoImpl.java @@ -708,20 +708,15 @@ public class CapacityDaoImpl extends GenericDaoBase implements } PreparedStatement pstmt = null; - try { - txn.start(); + try { pstmt = txn.prepareAutoCloseStatement(sql.toString()); pstmt.setString(1, capacityState); for (int i = 0; i < resourceIdList.size(); i++){ pstmt.setLong( 2+i, resourceIdList.get(i)); } pstmt.executeUpdate(); - txn.commit(); } catch (Exception e) { - txn.rollback(); s_logger.warn("Error updating CapacityVO", e); - } finally { - txn.close(); } } } diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index f9d26482aa5..35978b569da 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -160,6 +160,7 @@ import com.cloud.network.NetworkVO; import com.cloud.network.dao.IPAddressDao; import com.cloud.network.dao.LoadBalancerDao; import com.cloud.network.dao.NetworkDao; +import com.cloud.org.Grouping.AllocationState; import com.cloud.projects.Project; import com.cloud.projects.Project.ListProjectResourcesCriteria; import com.cloud.projects.ProjectManager; @@ -2004,9 +2005,12 @@ public class ManagementServerImpl implements ManagementServer { List getSecStorageUsed(Long zoneId, Integer capacityType){ if (capacityType == null || capacityType == Capacity.CAPACITY_TYPE_SECONDARY_STORAGE){ - List list = new ArrayList(); - + List list = new ArrayList(); if (zoneId != null){ + DataCenterVO zone = ApiDBUtils.findZoneById(zoneId); + if(zone == null || zone.getAllocationState() == AllocationState.Disabled){ + return null; + } CapacityVO capacity = _storageMgr.getSecondaryStorageUsedStats(null, zoneId); if (capacity.getTotalCapacity()!= 0){ capacity.setUsedPercentage( capacity.getUsedCapacity() / capacity.getTotalCapacity() ); @@ -2016,7 +2020,7 @@ public class ManagementServerImpl implements ManagementServer { SummedCapacity summedCapacity = new SummedCapacity(capacity.getUsedPercentage(), capacity.getCapacityType(), capacity.getDataCenterId(), capacity.getPodId(), capacity.getClusterId()); list.add(summedCapacity) ; }else { - List dcList = ApiDBUtils.listZones(); + List dcList = _dcDao.listEnabledZones(); for(DataCenterVO dc : dcList){ CapacityVO capacity = _storageMgr.getSecondaryStorageUsedStats(null, dc.getId()); if (capacity.getTotalCapacity()!= 0){