Bug 13059: Remove the listTipConsumedResources api and introduced a sortbyusage flag in the listCapacity call.

Reviewed-By: Kishan
This commit is contained in:
Nitin Mehta 2012-02-08 11:50:55 +05:30
parent d0e63bc377
commit 1fc0afe3f2
5 changed files with 13 additions and 129 deletions

View File

@ -172,6 +172,7 @@ public class ApiConstants {
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 START_DATE = "startdate";
public static final String START_IP = "startip";
public static final String START_PORT = "startport";

View File

@ -28,7 +28,6 @@ import com.cloud.api.BaseListCmd;
import com.cloud.api.IdentityMapper;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.BaseCmd.CommandType;
import com.cloud.api.response.CapacityResponse;
import com.cloud.api.response.ListResponse;
import com.cloud.capacity.Capacity;
@ -60,8 +59,8 @@ public class ListCapacityCmd extends BaseListCmd {
@Parameter(name=ApiConstants.FETCH_LATEST, type=CommandType.BOOLEAN, description="recalculate capacities and fetch the latest")
private Boolean fetchLatest;
@Parameter(name=ApiConstants.RESOURCE_STATE, type=CommandType.BOOLEAN, description="list capacities by resource state. Resource state represents current state determined by admin of the resource, value can be one of [Enabled, Disabled, Maintenance]")
private Boolean resourceState;
@Parameter(name=ApiConstants.SORT_BY_USAGE, type=CommandType.BOOLEAN, description="if true then lists the top consumed resources at various hierarchy level")
private Boolean sortByUsage;
@Parameter(name=ApiConstants.TYPE, type=CommandType.INTEGER, description="lists capacity by type" +
"* CAPACITY_TYPE_MEMORY = 0" +
@ -101,6 +100,9 @@ public class ListCapacityCmd extends BaseListCmd {
return type;
}
public Boolean getSortByUsage() {
return sortByUsage;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////

View File

@ -1,122 +0,0 @@
/**
* Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
*
* This software is licensed under the GNU General Public License v3 or later.
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.cloud.api.commands;
import java.text.DecimalFormat;
import java.util.List;
import org.apache.log4j.Logger;
import com.cloud.api.ApiConstants;
import com.cloud.api.BaseListCmd;
import com.cloud.api.IdentityMapper;
import com.cloud.api.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.ServerApiException;
import com.cloud.api.BaseCmd.CommandType;
import com.cloud.api.response.CapacityResponse;
import com.cloud.api.response.ListResponse;
import com.cloud.capacity.Capacity;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
@Implementation(description="Lists all the system wide capacities.", responseObject=CapacityResponse.class)
public class ListTopConsumedResources extends BaseListCmd {
public static final Logger s_logger = Logger.getLogger(ListCapacityCmd.class.getName());
private static final DecimalFormat s_percentFormat = new DecimalFormat("##.##");
private static final String s_name = "listcapacityresponse";
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@IdentityMapper(entityTableName="data_center")
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, description="lists capacity by the Zone ID")
private Long zoneId;
@IdentityMapper(entityTableName="host_pod_ref")
@Parameter(name=ApiConstants.POD_ID, type=CommandType.LONG, description="lists capacity by the Pod ID")
private Long podId;
@IdentityMapper(entityTableName="cluster")
@Parameter(name=ApiConstants.CLUSTER_ID, type=CommandType.LONG, description="lists capacity by the Cluster ID")
private Long clusterId;
@Parameter(name=ApiConstants.TYPE, type=CommandType.INTEGER, description="lists capacity by type" +
"* CAPACITY_TYPE_MEMORY = 0" +
"* CAPACITY_TYPE_CPU = 1" +
"* CAPACITY_TYPE_STORAGE = 2" +
"* CAPACITY_TYPE_STORAGE_ALLOCATED = 3" +
"* CAPACITY_TYPE_VIRTUAL_NETWORK_PUBLIC_IP = 4" +
"* CAPACITY_TYPE_PRIVATE_IP = 5" +
"* CAPACITY_TYPE_SECONDARY_STORAGE = 6" +
"* CAPACITY_TYPE_VLAN = 7" +
"* CAPACITY_TYPE_DIRECT_ATTACHED_PUBLIC_IP = 8" +
"* CAPACITY_TYPE_LOCAL_STORAGE = 9.")
private Integer type;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public Long getZoneId() {
return zoneId;
}
public Long getPodId() {
return podId;
}
public Long getClusterId() {
return clusterId;
}
public Integer getType() {
return type;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public String getCommandName() {
return s_name;
}
@Override
public void execute(){
List<? extends Capacity> result = _mgr.listTopConsumedResources(this);
ListResponse<CapacityResponse> response = new ListResponse<CapacityResponse>();
List<CapacityResponse> capacityResponses = _responseGenerator.createCapacityResponse(result, s_percentFormat);
response.setResponses(capacityResponses);
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
}

View File

@ -50,7 +50,6 @@ import com.cloud.api.commands.ListServiceOfferingsCmd;
import com.cloud.api.commands.ListStoragePoolsCmd;
import com.cloud.api.commands.ListSystemVMsCmd;
import com.cloud.api.commands.ListTemplatesCmd;
import com.cloud.api.commands.ListTopConsumedResources;
import com.cloud.api.commands.ListVMGroupsCmd;
import com.cloud.api.commands.ListVlanIpRangesCmd;
import com.cloud.api.commands.ListZonesByCmd;
@ -441,6 +440,6 @@ public interface ManagementService {
* @param cmd
* @return List of capacities
*/
List<? extends Capacity> listTopConsumedResources(ListTopConsumedResources cmd);
List<? extends Capacity> listTopConsumedResources(ListCapacityCmd cmd);
}

View File

@ -84,7 +84,6 @@ import com.cloud.api.commands.ListServiceOfferingsCmd;
import com.cloud.api.commands.ListStoragePoolsCmd;
import com.cloud.api.commands.ListSystemVMsCmd;
import com.cloud.api.commands.ListTemplatesCmd;
import com.cloud.api.commands.ListTopConsumedResources;
import com.cloud.api.commands.ListVMGroupsCmd;
import com.cloud.api.commands.ListVlanIpRangesCmd;
import com.cloud.api.commands.ListZonesByCmd;
@ -1939,7 +1938,7 @@ public class ManagementServerImpl implements ManagementServer {
}
@Override
public List<CapacityVO> listTopConsumedResources(ListTopConsumedResources cmd) {
public List<CapacityVO> listTopConsumedResources(ListCapacityCmd cmd) {
Integer capacityType = cmd.getType();
Long zoneId = cmd.getZoneId();
@ -2042,11 +2041,16 @@ public class ManagementServerImpl implements ManagementServer {
Long podId = cmd.getPodId();
Long clusterId = cmd.getClusterId();
Boolean fetchLatest = cmd.getFetchLatest();
Boolean sortByUsage = cmd.getSortByUsage();
zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), zoneId);
if (fetchLatest != null && fetchLatest){
_alertMgr.recalculateCapacity();
}
if (sortByUsage != null && sortByUsage){
return listTopConsumedResources(cmd);
}
List<SummedCapacity> summedCapacities = _capacityDao.findCapacityBy(capacityType, zoneId, podId, clusterId);
List<CapacityVO> capacities = new ArrayList<CapacityVO>();