bug 11051: ListPods - Introduce a flag 'showCapacitites'. When its true it will start displaying all the capacitites (as objects in the response) for the respective cluster.

This commit is contained in:
Nitin 2011-09-20 15:59:45 +05:30
parent 4a5f6faca2
commit 7bcbdeb834
8 changed files with 42 additions and 11 deletions

View File

@ -139,7 +139,7 @@ public interface ResponseGenerator {
LoadBalancerResponse createLoadBalancerResponse(LoadBalancer loadBalancer);
PodResponse createPodResponse(Pod pod);
PodResponse createPodResponse(Pod pod, Boolean showCapacities);
ZoneResponse createZoneResponse(DataCenter dataCenter);

2
api/src/com/cloud/api/commands/CreatePodCmd.java Normal file → Executable file
View File

@ -111,7 +111,7 @@ public class CreatePodCmd extends BaseCmd {
public void execute(){
Pod result = _configService.createPod(this);
if (result != null) {
PodResponse response = _responseGenerator.createPodResponse(result);
PodResponse response = _responseGenerator.createPodResponse(result, false);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {

12
api/src/com/cloud/api/commands/ListPodsByCmd.java Normal file → Executable file
View File

@ -53,8 +53,10 @@ public class ListPodsByCmd extends BaseListCmd {
@Parameter(name=ApiConstants.ALLOCATION_STATE, type=CommandType.STRING, description="list pods by allocation state")
private String allocationState;
@Parameter(name=ApiConstants.SHOW_CAPACITIES, type=CommandType.BOOLEAN, description="flag to display the capacity of the pods")
private Boolean showCapacities;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
@ -75,6 +77,10 @@ public class ListPodsByCmd extends BaseListCmd {
return allocationState;
}
public Boolean getShowCapacities() {
return showCapacities;
}
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@ -90,7 +96,7 @@ public class ListPodsByCmd extends BaseListCmd {
ListResponse<PodResponse> response = new ListResponse<PodResponse>();
List<PodResponse> podResponses = new ArrayList<PodResponse>();
for (Pod pod : result) {
PodResponse podResponse = _responseGenerator.createPodResponse(pod);
PodResponse podResponse = _responseGenerator.createPodResponse(pod, showCapacities);
podResponse.setObjectName("pod");
podResponses.add(podResponse);
}

2
api/src/com/cloud/api/commands/UpdatePodCmd.java Normal file → Executable file
View File

@ -110,7 +110,7 @@ public class UpdatePodCmd extends BaseCmd {
public void execute(){
Pod result = _configService.editPod(this);
if (result != null) {
PodResponse response = _responseGenerator.createPodResponse(result);
PodResponse response = _responseGenerator.createPodResponse(result,false);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {

View File

@ -57,7 +57,7 @@ public class ClusterResponse extends BaseResponse {
@SerializedName("managedstate") @Param(description="whether this cluster is managed by cloudstack")
private String managedState;
@SerializedName("capacity") @Param(description="", responseObject = CapacityResponse.class)
@SerializedName("capacity") @Param(description="the capacity of the Cluster", responseObject = CapacityResponse.class)
private List<CapacityResponse> capacitites;
public Long getId() {

17
api/src/com/cloud/api/response/PodResponse.java Normal file → Executable file
View File

@ -17,6 +17,8 @@
*/
package com.cloud.api.response;
import java.util.List;
import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;
@ -45,9 +47,12 @@ public class PodResponse extends BaseResponse {
@SerializedName("endip") @Param(description="the ending IP for the Pod")
private String endIp;
@SerializedName("allocationstate") @Param(description="the allocation state of the cluster")
@SerializedName("allocationstate") @Param(description="the allocation state of the Pod")
private String allocationState;
@SerializedName("capacity") @Param(description="the capacity of the Pod", responseObject = CapacityResponse.class)
private List<CapacityResponse> capacitites;
public Long getId() {
return id;
}
@ -118,5 +123,13 @@ public class PodResponse extends BaseResponse {
public void setAllocationState(String allocationState) {
this.allocationState = allocationState;
}
}
public List<CapacityResponse> getCapacitites() {
return capacitites;
}
public void setCapacitites(List<CapacityResponse> capacitites) {
this.capacitites = capacitites;
}
}

View File

@ -244,7 +244,7 @@ public class ApiDBUtils {
}
public static List<CapacityVO> getCapacityByClusterPodZone(Long zoneId, Long podId, Long clusterId){
return _capacityDao.findByClusterPodZone(null,null,clusterId);
return _capacityDao.findByClusterPodZone(zoneId,podId,clusterId);
}
public static List<CapacityVO> getCapacityByPod(){

View File

@ -756,7 +756,7 @@ public class ApiResponseHelper implements ResponseGenerator {
}
@Override
public PodResponse createPodResponse(Pod pod) {
public PodResponse createPodResponse(Pod pod, Boolean showCapacities) {
String[] ipRange = new String[2];
if (pod.getDescription() != null && pod.getDescription().length() > 0) {
ipRange = pod.getDescription().split("-");
@ -774,6 +774,18 @@ public class ApiResponseHelper implements ResponseGenerator {
podResponse.setEndIp(((ipRange.length > 1) && (ipRange[1] != null)) ? ipRange[1] : "");
podResponse.setGateway(pod.getGateway());
podResponse.setAllocationState(pod.getAllocationState().toString());
if (showCapacities != null && showCapacities){
List<CapacityVO> capacities = ApiDBUtils.getCapacityByClusterPodZone(null,pod.getId(),null);
Set<CapacityResponse> capacityResponses = new HashSet<CapacityResponse>();
for (CapacityVO capacity : capacities){
CapacityResponse capacityResponse = new CapacityResponse();
capacityResponse.setCapacityType(capacity.getCapacityType());
capacityResponse.setCapacityUsed(capacity.getUsedCapacity());
capacityResponse.setCapacityTotal(capacity.getTotalCapacity());
capacityResponses.add(capacityResponse);
}
podResponse.setCapacitites(new ArrayList<CapacityResponse>(capacityResponses));
}
podResponse.setObjectName("pod");
return podResponse;
}