Skip to content

Commit 01582fc

Browse files
bug 10848: Introducing an api - ListCapacityByType.
1 parent 0165f91 commit 01582fc

4 files changed

Lines changed: 114 additions & 0 deletions

File tree

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/**
2+
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
3+
*
4+
* This software is licensed under the GNU General Public License v3 or later.
5+
*
6+
* It is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or any later version.
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
*/
18+
19+
package com.cloud.api.commands;
20+
21+
import java.text.DecimalFormat;
22+
import java.util.List;
23+
24+
import org.apache.log4j.Logger;
25+
26+
import com.cloud.api.ApiConstants;
27+
import com.cloud.api.BaseListCmd;
28+
import com.cloud.api.Implementation;
29+
import com.cloud.api.Parameter;
30+
import com.cloud.api.response.CapacityResponse;
31+
import com.cloud.api.response.ListResponse;
32+
import com.cloud.capacity.Capacity;
33+
34+
@Implementation(description="Lists capacity By Type.", responseObject=CapacityResponse.class)
35+
public class ListCapacityByTypeCmd extends BaseListCmd {
36+
37+
public static final Logger s_logger = Logger.getLogger(ListCapacityCmd.class.getName());
38+
private static final DecimalFormat s_percentFormat = new DecimalFormat("##.##");
39+
40+
private static final String s_name = "listcapacityresponse";
41+
42+
/////////////////////////////////////////////////////
43+
//////////////// API parameters /////////////////////
44+
/////////////////////////////////////////////////////
45+
46+
@Parameter(name=ApiConstants.TYPE, type=CommandType.INTEGER, required=true, description="lists capacity by type")
47+
private Integer type;
48+
49+
@Parameter(name=ApiConstants.CLUSTER_ID, type=CommandType.LONG, description="lists capacity by the Cluster ID")
50+
private Long clusterId;
51+
52+
@Parameter(name=ApiConstants.POD_ID, type=CommandType.LONG, description="lists capacity by the Pod ID")
53+
private Long podId;
54+
55+
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, description="lists capacity by the Zone ID")
56+
private Long zoneId;
57+
58+
59+
/////////////////////////////////////////////////////
60+
/////////////////// Accessors ///////////////////////
61+
/////////////////////////////////////////////////////
62+
63+
public Integer getType() {
64+
return type;
65+
}
66+
67+
public Long getClusterId() {
68+
return clusterId;
69+
}
70+
71+
public Long getPodId() {
72+
return podId;
73+
}
74+
75+
public Long getZoneId() {
76+
return zoneId;
77+
}
78+
79+
/////////////////////////////////////////////////////
80+
/////////////// API Implementation///////////////////
81+
/////////////////////////////////////////////////////
82+
83+
@Override
84+
public String getCommandName() {
85+
return s_name;
86+
}
87+
88+
@Override
89+
public void execute(){
90+
List<? extends Capacity> result = _mgr.listCapacityByType(this);
91+
ListResponse<CapacityResponse> response = new ListResponse<CapacityResponse>();
92+
List<CapacityResponse> capacityResponses = _responseGenerator.createCapacityResponse(result, s_percentFormat);
93+
response.setResponses(capacityResponses);
94+
response.setResponseName(getCommandName());
95+
this.setResponseObject(response);
96+
}
97+
}

‎api/src/com/cloud/server/ManagementService.java‎

100644100755
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import com.cloud.api.commands.ListAlertsCmd;
3838
import com.cloud.api.commands.ListAsyncJobsCmd;
3939
import com.cloud.api.commands.ListCapabilitiesCmd;
40+
import com.cloud.api.commands.ListCapacityByTypeCmd;
4041
import com.cloud.api.commands.ListCapacityCmd;
4142
import com.cloud.api.commands.ListCfgsByCmd;
4243
import com.cloud.api.commands.ListClustersCmd;
@@ -299,6 +300,14 @@ public interface ManagementService {
299300
*/
300301
List<? extends Capacity> listCapacities(ListCapacityCmd cmd);
301302

303+
/**
304+
* lists the capacity rows in capacity operations table
305+
*
306+
* @param cmd
307+
* @return List of capacities
308+
*/
309+
List<? extends Capacity> listCapacityByType(ListCapacityByTypeCmd cmd);
310+
302311
/**
303312
* List the permissions on a template. This will return a list of account names that have been granted permission to launch
304313
* instances from the template.

‎client/tomcatconf/commands.properties.in‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ listAlerts=com.cloud.api.commands.ListAlertsCmd;3
170170

171171
#### system capacity commands
172172
listCapacity=com.cloud.api.commands.ListCapacityCmd;3
173+
listCapacityByType=com.cloud.api.commands.ListCapacityByTypeCmd;3
173174

174175
#### host commands
175176
addHost=com.cloud.api.commands.AddHostCmd;3

‎server/src/com/cloud/server/ManagementServerImpl.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
import com.cloud.api.commands.ListAlertsCmd;
7676
import com.cloud.api.commands.ListAsyncJobsCmd;
7777
import com.cloud.api.commands.ListCapabilitiesCmd;
78+
import com.cloud.api.commands.ListCapacityByTypeCmd;
7879
import com.cloud.api.commands.ListCapacityCmd;
7980
import com.cloud.api.commands.ListCfgsByCmd;
8081
import com.cloud.api.commands.ListClustersCmd;
@@ -3218,6 +3219,12 @@ public List<? extends Alert> searchForAlerts(ListAlertsCmd cmd) {
32183219
return _alertDao.search(sc, searchFilter);
32193220
}
32203221

3222+
@Override
3223+
public List<CapacityVO> listCapacityByType(ListCapacityByTypeCmd cmd) {
3224+
return null;
3225+
3226+
}
3227+
32213228
@Override
32223229
public List<CapacityVO> listCapacities(ListCapacityCmd cmd) {
32233230

0 commit comments

Comments
 (0)