bug 10848: Introducing an api - ListCapacityByType.

This commit is contained in:
Nitin 2011-08-06 20:09:07 +05:30
parent 0165f915b6
commit 01582fcd40
4 changed files with 114 additions and 0 deletions

View File

@ -0,0 +1,97 @@
/**
* Copyright (C) 2010 Cloud.com, 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.Implementation;
import com.cloud.api.Parameter;
import com.cloud.api.response.CapacityResponse;
import com.cloud.api.response.ListResponse;
import com.cloud.capacity.Capacity;
@Implementation(description="Lists capacity By Type.", responseObject=CapacityResponse.class)
public class ListCapacityByTypeCmd 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 /////////////////////
/////////////////////////////////////////////////////
@Parameter(name=ApiConstants.TYPE, type=CommandType.INTEGER, required=true, description="lists capacity by type")
private Integer type;
@Parameter(name=ApiConstants.CLUSTER_ID, type=CommandType.LONG, description="lists capacity by the Cluster ID")
private Long clusterId;
@Parameter(name=ApiConstants.POD_ID, type=CommandType.LONG, description="lists capacity by the Pod ID")
private Long podId;
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, description="lists capacity by the Zone ID")
private Long zoneId;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public Integer getType() {
return type;
}
public Long getClusterId() {
return clusterId;
}
public Long getPodId() {
return podId;
}
public Long getZoneId() {
return zoneId;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@Override
public String getCommandName() {
return s_name;
}
@Override
public void execute(){
List<? extends Capacity> result = _mgr.listCapacityByType(this);
ListResponse<CapacityResponse> response = new ListResponse<CapacityResponse>();
List<CapacityResponse> capacityResponses = _responseGenerator.createCapacityResponse(result, s_percentFormat);
response.setResponses(capacityResponses);
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
}

9
api/src/com/cloud/server/ManagementService.java Normal file → Executable file
View File

@ -37,6 +37,7 @@ import com.cloud.api.commands.ListAccountsCmd;
import com.cloud.api.commands.ListAlertsCmd;
import com.cloud.api.commands.ListAsyncJobsCmd;
import com.cloud.api.commands.ListCapabilitiesCmd;
import com.cloud.api.commands.ListCapacityByTypeCmd;
import com.cloud.api.commands.ListCapacityCmd;
import com.cloud.api.commands.ListCfgsByCmd;
import com.cloud.api.commands.ListClustersCmd;
@ -299,6 +300,14 @@ public interface ManagementService {
*/
List<? extends Capacity> listCapacities(ListCapacityCmd cmd);
/**
* lists the capacity rows in capacity operations table
*
* @param cmd
* @return List of capacities
*/
List<? extends Capacity> listCapacityByType(ListCapacityByTypeCmd cmd);
/**
* List the permissions on a template. This will return a list of account names that have been granted permission to launch
* instances from the template.

View File

@ -170,6 +170,7 @@ listAlerts=com.cloud.api.commands.ListAlertsCmd;3
#### system capacity commands
listCapacity=com.cloud.api.commands.ListCapacityCmd;3
listCapacityByType=com.cloud.api.commands.ListCapacityByTypeCmd;3
#### host commands
addHost=com.cloud.api.commands.AddHostCmd;3

View File

@ -75,6 +75,7 @@ import com.cloud.api.commands.ListAccountsCmd;
import com.cloud.api.commands.ListAlertsCmd;
import com.cloud.api.commands.ListAsyncJobsCmd;
import com.cloud.api.commands.ListCapabilitiesCmd;
import com.cloud.api.commands.ListCapacityByTypeCmd;
import com.cloud.api.commands.ListCapacityCmd;
import com.cloud.api.commands.ListCfgsByCmd;
import com.cloud.api.commands.ListClustersCmd;
@ -3218,6 +3219,12 @@ public class ManagementServerImpl implements ManagementServer {
return _alertDao.search(sc, searchFilter);
}
@Override
public List<CapacityVO> listCapacityByType(ListCapacityByTypeCmd cmd) {
return null;
}
@Override
public List<CapacityVO> listCapacities(ListCapacityCmd cmd) {