mirror of https://github.com/apache/cloudstack.git
Bug 13059: Keeping the param name more intuitive Also adding the ciode for listing used and total capacity as well.
Reviewed-By: Kishan
This commit is contained in:
parent
35ea4b7df1
commit
e6beb08f1b
|
|
@ -115,6 +115,7 @@ public class ApiConstants {
|
|||
public static final String MODE = "mode";
|
||||
public static final String NAME = "name";
|
||||
public static final String METHOD_NAME = "methodname";
|
||||
public static final String LIST_TOP_USED = "listtopused";
|
||||
public static final String NETWORK_DOMAIN = "networkdomain";
|
||||
public static final String NETMASK = "netmask";
|
||||
public static final String NEW_NAME = "newname";
|
||||
|
|
@ -171,8 +172,7 @@ public class ApiConstants {
|
|||
public static final String SNAPSHOT_ID = "snapshotid";
|
||||
public static final String SNAPSHOT_POLICY_ID = "snapshotpolicyid";
|
||||
public static final String SNAPSHOT_TYPE = "snapshottype";
|
||||
public static final String SOURCE_ZONE_ID = "sourcezoneid";
|
||||
public static final String SORT_BY_USAGE = "sortbyusage";
|
||||
public static final String SOURCE_ZONE_ID = "sourcezoneid";
|
||||
public static final String START_DATE = "startdate";
|
||||
public static final String START_IP = "startip";
|
||||
public static final String START_PORT = "startport";
|
||||
|
|
|
|||
|
|
@ -59,8 +59,8 @@ public class ListCapacityCmd extends BaseListCmd {
|
|||
@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, 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.LIST_TOP_USED, type=CommandType.BOOLEAN, since="3.0.0", description="if true then lists the top consumed enabled resources at Zone/Pod/Cluster level ordered by percentage.")
|
||||
private Boolean listTopUsed;
|
||||
|
||||
@Parameter(name=ApiConstants.TYPE, type=CommandType.INTEGER, description="lists capacity by type" +
|
||||
"* CAPACITY_TYPE_MEMORY = 0" +
|
||||
|
|
@ -100,8 +100,8 @@ public class ListCapacityCmd extends BaseListCmd {
|
|||
return type;
|
||||
}
|
||||
|
||||
public Boolean getSortByUsage() {
|
||||
return sortByUsage;
|
||||
public Boolean getlistTopUsed() {
|
||||
return listTopUsed;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -2441,10 +2441,10 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
}
|
||||
capacityResponse.setZoneId(summedCapacity.getDataCenterId());
|
||||
capacityResponse.setZoneName(ApiDBUtils.findZoneById(summedCapacity.getDataCenterId()).getName());
|
||||
if (summedCapacity.getTotalCapacity() != 0) {
|
||||
capacityResponse.setPercentUsed(format.format((float) summedCapacity.getUsedCapacity() / (float) summedCapacity.getTotalCapacity() * 100f));
|
||||
} else if (summedCapacity.getUsedPercentage() != null){
|
||||
if (summedCapacity.getUsedPercentage() != null){
|
||||
capacityResponse.setPercentUsed(format.format(summedCapacity.getUsedPercentage() * 100f));
|
||||
} else if (summedCapacity.getTotalCapacity() != 0) {
|
||||
capacityResponse.setPercentUsed(format.format((float) summedCapacity.getUsedCapacity() / (float) summedCapacity.getTotalCapacity() * 100f));
|
||||
} else {
|
||||
capacityResponse.setPercentUsed(format.format(0L));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,18 +96,21 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
|
|||
"FROM `cloud`.`op_host_capacity` capacity INNER JOIN `cloud`.`host` host ON (host.id = capacity.host_id AND host.removed is NULL)"+
|
||||
"WHERE dc.allocation_state = ? AND pod.allocation_state = ? AND cluster.allocation_state = ? AND host.resource_state = ? AND capacity_type not in (3,4) ";
|
||||
|
||||
private static final String LIST_CAPACITY_GROUP_BY_ZONE_TYPE_PART1 = "SELECT ((sum(capacity.used_capacity) + sum(capacity.reserved_capacity)) / (case capacity_type when 1 then (sum(total_capacity) * (select value from `cloud`.`configuration` where name like 'cpu.overprovisioning.factor')) else sum(total_capacity) end)) percent," +
|
||||
private static final String LIST_CAPACITY_GROUP_BY_ZONE_TYPE_PART1 = "SELECT (sum(capacity.used_capacity) + sum(capacity.reserved_capacity)), (case capacity_type when 1 then (sum(total_capacity) * (select value from `cloud`.`configuration` where name like 'cpu.overprovisioning.factor')) else sum(total_capacity) end), " +
|
||||
"((sum(capacity.used_capacity) + sum(capacity.reserved_capacity)) / (case capacity_type when 1 then (sum(total_capacity) * (select value from `cloud`.`configuration` where name like 'cpu.overprovisioning.factor')) else sum(total_capacity) end)) percent,"+
|
||||
" capacity.capacity_type, capacity.data_center_id "+
|
||||
"FROM `cloud`.`op_host_capacity` capacity "+
|
||||
"WHERE total_capacity > 0 AND data_center_id is not null AND capacity_state='Enabled'";
|
||||
private static final String LIST_CAPACITY_GROUP_BY_ZONE_TYPE_PART2 = " GROUP BY data_center_id, capacity_type order by percent desc limit ";
|
||||
private static final String LIST_CAPACITY_GROUP_BY_POD_TYPE_PART1 = "SELECT ((sum(capacity.used_capacity) + sum(capacity.reserved_capacity)) / (case capacity_type when 1 then (sum(total_capacity) * (select value from `cloud`.`configuration` where name like 'cpu.overprovisioning.factor')) else sum(total_capacity) end)) percent," +
|
||||
private static final String LIST_CAPACITY_GROUP_BY_POD_TYPE_PART1 = "SELECT (sum(capacity.used_capacity) + sum(capacity.reserved_capacity)), (case capacity_type when 1 then (sum(total_capacity) * (select value from `cloud`.`configuration` where name like 'cpu.overprovisioning.factor')) else sum(total_capacity) end), " +
|
||||
"((sum(capacity.used_capacity) + sum(capacity.reserved_capacity)) / (case capacity_type when 1 then (sum(total_capacity) * (select value from `cloud`.`configuration` where name like 'cpu.overprovisioning.factor')) else sum(total_capacity) end)) percent,"+
|
||||
" capacity.capacity_type, capacity.data_center_id, pod_id "+
|
||||
"FROM `cloud`.`op_host_capacity` capacity "+
|
||||
"WHERE total_capacity > 0 AND pod_id is not null AND capacity_state='Enabled'";
|
||||
private static final String LIST_CAPACITY_GROUP_BY_POD_TYPE_PART2 = " GROUP BY pod_id, capacity_type order by percent desc limit ";
|
||||
|
||||
private static final String LIST_CAPACITY_GROUP_BY_CLUSTER_TYPE_PART1 = "SELECT ((sum(capacity.used_capacity) + sum(capacity.reserved_capacity)) / (case capacity_type when 1 then (sum(total_capacity) * (select value from `cloud`.`configuration` where name like 'cpu.overprovisioning.factor')) else sum(total_capacity) end)) percent,"+
|
||||
private static final String LIST_CAPACITY_GROUP_BY_CLUSTER_TYPE_PART1 = "SELECT (sum(capacity.used_capacity) + sum(capacity.reserved_capacity)), (case capacity_type when 1 then (sum(total_capacity) * (select value from `cloud`.`configuration` where name like 'cpu.overprovisioning.factor')) else sum(total_capacity) end), " +
|
||||
"((sum(capacity.used_capacity) + sum(capacity.reserved_capacity)) / (case capacity_type when 1 then (sum(total_capacity) * (select value from `cloud`.`configuration` where name like 'cpu.overprovisioning.factor')) else sum(total_capacity) end)) percent,"+
|
||||
"capacity.capacity_type, capacity.data_center_id, pod_id, cluster_id "+
|
||||
"FROM `cloud`.`op_host_capacity` capacity "+
|
||||
"WHERE total_capacity > 0 AND cluster_id is not null AND capacity_state='Enabled'";
|
||||
|
|
@ -242,10 +245,10 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
|
|||
pstmt = txn.prepareAutoCloseStatement(finalQuery.toString());
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
SummedCapacity summedCapacity = new SummedCapacity( rs.getFloat(1), (short)rs.getLong(2),
|
||||
rs.getLong(3),
|
||||
level == 3 ? rs.getLong(5): null,
|
||||
level != 1 ? rs.getLong(4): null);
|
||||
SummedCapacity summedCapacity = new SummedCapacity( rs.getLong(1), rs.getLong(2), rs.getFloat(3),
|
||||
(short)rs.getLong(4), rs.getLong(5),
|
||||
level == 3 ? rs.getLong(7): null,
|
||||
level != 1 ? rs.getLong(6): null);
|
||||
|
||||
result.add(summedCapacity);
|
||||
}
|
||||
|
|
@ -441,7 +444,7 @@ public class CapacityDaoImpl extends GenericDaoBase<CapacityVO, Long> implements
|
|||
this.dcId = zoneId;
|
||||
}
|
||||
|
||||
public SummedCapacity(float percentUsed, short capacityType, Long zoneId, Long podId, Long clusterId) {
|
||||
public SummedCapacity(long sumUsed, long sumTotal, float percentUsed, short capacityType, Long zoneId, Long podId, Long clusterId) {
|
||||
super();
|
||||
this.percentUsed = percentUsed;
|
||||
this.capacityType = capacityType;
|
||||
|
|
|
|||
|
|
@ -1945,6 +1945,10 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
Long zoneId = cmd.getZoneId();
|
||||
Long podId = cmd.getPodId();
|
||||
Long clusterId = cmd.getClusterId();
|
||||
|
||||
if (clusterId != null){
|
||||
throw new InvalidParameterValueException("Currently clusterId param is not suppoerted");
|
||||
}
|
||||
zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), zoneId);
|
||||
List<SummedCapacity> summedCapacities = new ArrayList<SummedCapacity>();
|
||||
|
||||
|
|
@ -2017,7 +2021,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
}else {
|
||||
capacity.setUsedPercentage(0);
|
||||
}
|
||||
SummedCapacity summedCapacity = new SummedCapacity(capacity.getUsedPercentage(), capacity.getCapacityType(), capacity.getDataCenterId(), capacity.getPodId(), capacity.getClusterId());
|
||||
SummedCapacity summedCapacity = new SummedCapacity(capacity.getUsedCapacity(), capacity.getTotalCapacity(), capacity.getUsedPercentage(), capacity.getCapacityType(), capacity.getDataCenterId(), capacity.getPodId(), capacity.getClusterId());
|
||||
list.add(summedCapacity) ;
|
||||
}else {
|
||||
List<DataCenterVO> dcList = _dcDao.listEnabledZones();
|
||||
|
|
@ -2028,7 +2032,7 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
}else {
|
||||
capacity.setUsedPercentage(0);
|
||||
}
|
||||
SummedCapacity summedCapacity = new SummedCapacity(capacity.getUsedPercentage(), capacity.getCapacityType(), capacity.getDataCenterId(), capacity.getPodId(), capacity.getClusterId());
|
||||
SummedCapacity summedCapacity = new SummedCapacity(capacity.getUsedCapacity(), capacity.getTotalCapacity(), capacity.getUsedPercentage(), capacity.getCapacityType(), capacity.getDataCenterId(), capacity.getPodId(), capacity.getClusterId());
|
||||
list.add(summedCapacity);
|
||||
}//End of for
|
||||
}
|
||||
|
|
@ -2045,14 +2049,14 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
Long podId = cmd.getPodId();
|
||||
Long clusterId = cmd.getClusterId();
|
||||
Boolean fetchLatest = cmd.getFetchLatest();
|
||||
Boolean sortByUsage = cmd.getSortByUsage();
|
||||
Boolean listTopUsed = cmd.getlistTopUsed();
|
||||
|
||||
zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), zoneId);
|
||||
if (fetchLatest != null && fetchLatest){
|
||||
_alertMgr.recalculateCapacity();
|
||||
}
|
||||
|
||||
if (sortByUsage != null && sortByUsage){
|
||||
if (listTopUsed != null && listTopUsed){
|
||||
return listTopConsumedResources(cmd);
|
||||
}
|
||||
List<SummedCapacity> summedCapacities = _capacityDao.findCapacityBy(capacityType, zoneId, podId, clusterId);
|
||||
|
|
|
|||
Loading…
Reference in New Issue