|
| 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 | +} |
0 commit comments