mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
api: rename ListUsageRecords file name to ListUsageRecordsCmd (#3151)
* Rename ListUsageRecords API command file name to ListUsageRecordsCmd * Refactor to use APINAME variable and remove unused s_logger field * Remove unused import
This commit is contained in:
parent
8d3feb100a
commit
0d21f0c1e7
@ -22,28 +22,27 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.utils.Pair;
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.BaseCmd;
|
||||
import org.apache.cloudstack.api.BaseListCmd;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.response.AccountResponse;
|
||||
import org.apache.cloudstack.api.response.DomainResponse;
|
||||
import org.apache.cloudstack.api.response.ListResponse;
|
||||
import org.apache.cloudstack.api.response.ProjectResponse;
|
||||
import org.apache.cloudstack.api.response.UsageRecordResponse;
|
||||
import org.apache.cloudstack.api.response.ResourceTagResponse;
|
||||
import org.apache.cloudstack.api.response.UsageRecordResponse;
|
||||
import org.apache.cloudstack.usage.Usage;
|
||||
|
||||
import com.cloud.utils.Pair;
|
||||
|
||||
@APICommand(name = "listUsageRecords", description = "Lists usage records for accounts", responseObject = UsageRecordResponse.class,
|
||||
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
|
||||
public class GetUsageRecordsCmd extends BaseListCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(GetUsageRecordsCmd.class.getName());
|
||||
|
||||
private static final String s_name = "listusagerecordsresponse";
|
||||
@APICommand(name = ListUsageRecordsCmd.APINAME,
|
||||
description = "Lists usage records for accounts",
|
||||
responseObject = UsageRecordResponse.class,
|
||||
requestHasSensitiveInfo = false,
|
||||
responseHasSensitiveInfo = false)
|
||||
public class ListUsageRecordsCmd extends BaseListCmd {
|
||||
public static final String APINAME = "listUsageRecords";
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//////////////// API parameters /////////////////////
|
||||
@ -56,15 +55,15 @@ public class GetUsageRecordsCmd extends BaseListCmd {
|
||||
private Long domainId;
|
||||
|
||||
@Parameter(name = ApiConstants.END_DATE,
|
||||
type = CommandType.DATE,
|
||||
required = true,
|
||||
description = "End date range for usage record query (use format \"yyyy-MM-dd\" or the new format \"yyyy-MM-dd HH:mm:ss\", e.g. startDate=2015-01-01 or startdate=2015-01-01 10:30:00).")
|
||||
type = CommandType.DATE,
|
||||
required = true,
|
||||
description = "End date range for usage record query (use format \"yyyy-MM-dd\" or the new format \"yyyy-MM-dd HH:mm:ss\", e.g. startDate=2015-01-01 or startdate=2015-01-01 10:30:00).")
|
||||
private Date endDate;
|
||||
|
||||
@Parameter(name = ApiConstants.START_DATE,
|
||||
type = CommandType.DATE,
|
||||
required = true,
|
||||
description = "Start date range for usage record query (use format \"yyyy-MM-dd\" or the new format \"yyyy-MM-dd HH:mm:ss\", e.g. startDate=2015-01-01 or startdate=2015-01-01 11:00:00).")
|
||||
type = CommandType.DATE,
|
||||
required = true,
|
||||
description = "Start date range for usage record query (use format \"yyyy-MM-dd\" or the new format \"yyyy-MM-dd HH:mm:ss\", e.g. startDate=2015-01-01 or startdate=2015-01-01 11:00:00).")
|
||||
private Date startDate;
|
||||
|
||||
@Parameter(name = ApiConstants.ACCOUNT_ID, type = CommandType.UUID, entityType = AccountResponse.class, description = "List usage records for the specified account")
|
||||
@ -117,6 +116,7 @@ public class GetUsageRecordsCmd extends BaseListCmd {
|
||||
public String getUsageId() {
|
||||
return usageId;
|
||||
}
|
||||
|
||||
public void setAccountName(String accountName) {
|
||||
this.accountName = accountName;
|
||||
}
|
||||
@ -152,7 +152,7 @@ public class GetUsageRecordsCmd extends BaseListCmd {
|
||||
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return s_name;
|
||||
return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -163,8 +163,8 @@ public class GetUsageRecordsCmd extends BaseListCmd {
|
||||
Map<String, Set<ResourceTagResponse>> resourceTagResponseMap = null;
|
||||
if (usageRecords != null) {
|
||||
//read the resource tags details for all the resources in usage data and store in Map
|
||||
if(null != includeTags && includeTags) {
|
||||
resourceTagResponseMap = _responseGenerator.getUsageResourceTags();
|
||||
if (null != includeTags && includeTags) {
|
||||
resourceTagResponseMap = _responseGenerator.getUsageResourceTags();
|
||||
}
|
||||
for (Usage usageRecord : usageRecords.first()) {
|
||||
UsageRecordResponse usageResponse = _responseGenerator.createUsageResponse(usageRecord, resourceTagResponseMap);
|
||||
@ -18,7 +18,7 @@ package org.apache.cloudstack.usage;
|
||||
|
||||
import com.cloud.utils.Pair;
|
||||
import org.apache.cloudstack.api.command.admin.usage.GenerateUsageRecordsCmd;
|
||||
import org.apache.cloudstack.api.command.admin.usage.GetUsageRecordsCmd;
|
||||
import org.apache.cloudstack.api.command.admin.usage.ListUsageRecordsCmd;
|
||||
import org.apache.cloudstack.api.command.admin.usage.RemoveRawUsageRecordsCmd;
|
||||
import org.apache.cloudstack.api.response.UsageTypeResponse;
|
||||
|
||||
@ -52,7 +52,7 @@ public interface UsageService {
|
||||
* the appropriate page number)
|
||||
* @return a list of usage records
|
||||
*/
|
||||
Pair<List<? extends Usage>, Integer> getUsageRecords(GetUsageRecordsCmd cmd);
|
||||
Pair<List<? extends Usage>, Integer> getUsageRecords(ListUsageRecordsCmd cmd);
|
||||
|
||||
/**
|
||||
* Retrieves the timezone used for usage aggregation. One day is represented as midnight to 11:59:59pm
|
||||
|
||||
@ -28,7 +28,7 @@ import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.apache.cloudstack.api.command.admin.usage.GetUsageRecordsCmd;
|
||||
import org.apache.cloudstack.api.command.admin.usage.ListUsageRecordsCmd;
|
||||
import org.apache.cloudstack.usage.Usage;
|
||||
import org.apache.cloudstack.usage.UsageService;
|
||||
|
||||
@ -36,7 +36,7 @@ import com.cloud.utils.Pair;
|
||||
|
||||
public class UsageCmdTest extends TestCase {
|
||||
|
||||
private GetUsageRecordsCmd getUsageRecordsCmd;
|
||||
private ListUsageRecordsCmd listUsageRecordsCmd;
|
||||
|
||||
@Rule
|
||||
public ExpectedException expectedException = ExpectedException.none();
|
||||
@ -45,7 +45,7 @@ public class UsageCmdTest extends TestCase {
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
getUsageRecordsCmd = new GetUsageRecordsCmd() {
|
||||
listUsageRecordsCmd = new ListUsageRecordsCmd() {
|
||||
|
||||
};
|
||||
}
|
||||
@ -53,8 +53,8 @@ public class UsageCmdTest extends TestCase {
|
||||
@Test
|
||||
public void testExecuteSuccess() {
|
||||
UsageService usageService = Mockito.mock(UsageService.class);
|
||||
getUsageRecordsCmd._usageService = usageService;
|
||||
getUsageRecordsCmd.execute();
|
||||
listUsageRecordsCmd._usageService = usageService;
|
||||
listUsageRecordsCmd.execute();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -64,29 +64,29 @@ public class UsageCmdTest extends TestCase {
|
||||
|
||||
Pair<List<? extends Usage>, Integer> usageRecords = new Pair<List<? extends Usage>, Integer>(new ArrayList<Usage>(), new Integer(0));
|
||||
|
||||
Mockito.when(usageService.getUsageRecords(getUsageRecordsCmd)).thenReturn(usageRecords);
|
||||
Mockito.when(usageService.getUsageRecords(listUsageRecordsCmd)).thenReturn(usageRecords);
|
||||
|
||||
getUsageRecordsCmd._usageService = usageService;
|
||||
getUsageRecordsCmd.execute();
|
||||
listUsageRecordsCmd._usageService = usageService;
|
||||
listUsageRecordsCmd.execute();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCrud() {
|
||||
getUsageRecordsCmd.setDomainId(1L);
|
||||
assertTrue(getUsageRecordsCmd.getDomainId().equals(1L));
|
||||
listUsageRecordsCmd.setDomainId(1L);
|
||||
assertTrue(listUsageRecordsCmd.getDomainId().equals(1L));
|
||||
|
||||
getUsageRecordsCmd.setAccountName("someAccount");
|
||||
assertTrue(getUsageRecordsCmd.getAccountName().equals("someAccount"));
|
||||
listUsageRecordsCmd.setAccountName("someAccount");
|
||||
assertTrue(listUsageRecordsCmd.getAccountName().equals("someAccount"));
|
||||
|
||||
Date d = new Date();
|
||||
getUsageRecordsCmd.setStartDate(d);
|
||||
getUsageRecordsCmd.setEndDate(d);
|
||||
assertTrue(getUsageRecordsCmd.getStartDate().equals(d));
|
||||
assertTrue(getUsageRecordsCmd.getEndDate().equals(d));
|
||||
listUsageRecordsCmd.setStartDate(d);
|
||||
listUsageRecordsCmd.setEndDate(d);
|
||||
assertTrue(listUsageRecordsCmd.getStartDate().equals(d));
|
||||
assertTrue(listUsageRecordsCmd.getEndDate().equals(d));
|
||||
|
||||
getUsageRecordsCmd.setUsageId("someId");
|
||||
assertTrue(getUsageRecordsCmd.getUsageId().equals("someId"));
|
||||
listUsageRecordsCmd.setUsageId("someId");
|
||||
assertTrue(listUsageRecordsCmd.getUsageId().equals("someId"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -50,7 +50,7 @@ import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.command.admin.resource.ArchiveAlertsCmd;
|
||||
import org.apache.cloudstack.api.command.admin.resource.DeleteAlertsCmd;
|
||||
import org.apache.cloudstack.api.command.admin.usage.GetUsageRecordsCmd;
|
||||
import org.apache.cloudstack.api.command.admin.usage.ListUsageRecordsCmd;
|
||||
import org.apache.cloudstack.api.command.user.event.ArchiveEventsCmd;
|
||||
import org.apache.cloudstack.api.command.user.event.DeleteEventsCmd;
|
||||
import org.apache.cloudstack.api.command.user.event.ListEventsCmd;
|
||||
@ -308,7 +308,7 @@ public class ParamProcessWorker implements DispatchWorker {
|
||||
// This piece of code is for maintaining backward compatibility
|
||||
// and support both the date formats(Bug 9724)
|
||||
if (cmdObj instanceof ListEventsCmd || cmdObj instanceof DeleteEventsCmd || cmdObj instanceof ArchiveEventsCmd ||
|
||||
cmdObj instanceof ArchiveAlertsCmd || cmdObj instanceof DeleteAlertsCmd || cmdObj instanceof GetUsageRecordsCmd) {
|
||||
cmdObj instanceof ArchiveAlertsCmd || cmdObj instanceof DeleteAlertsCmd || cmdObj instanceof ListUsageRecordsCmd) {
|
||||
final boolean isObjInNewDateFormat = isObjInNewDateFormat(paramObj.toString());
|
||||
if (isObjInNewDateFormat) {
|
||||
final DateFormat newFormat = newInputFormat;
|
||||
|
||||
@ -217,7 +217,7 @@ import org.apache.cloudstack.api.command.admin.usage.AddTrafficTypeCmd;
|
||||
import org.apache.cloudstack.api.command.admin.usage.DeleteTrafficMonitorCmd;
|
||||
import org.apache.cloudstack.api.command.admin.usage.DeleteTrafficTypeCmd;
|
||||
import org.apache.cloudstack.api.command.admin.usage.GenerateUsageRecordsCmd;
|
||||
import org.apache.cloudstack.api.command.admin.usage.GetUsageRecordsCmd;
|
||||
import org.apache.cloudstack.api.command.admin.usage.ListUsageRecordsCmd;
|
||||
import org.apache.cloudstack.api.command.admin.usage.ListTrafficMonitorsCmd;
|
||||
import org.apache.cloudstack.api.command.admin.usage.ListTrafficTypeImplementorsCmd;
|
||||
import org.apache.cloudstack.api.command.admin.usage.ListTrafficTypesCmd;
|
||||
@ -2703,7 +2703,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
|
||||
cmdList.add(DeleteTrafficMonitorCmd.class);
|
||||
cmdList.add(DeleteTrafficTypeCmd.class);
|
||||
cmdList.add(GenerateUsageRecordsCmd.class);
|
||||
cmdList.add(GetUsageRecordsCmd.class);
|
||||
cmdList.add(ListUsageRecordsCmd.class);
|
||||
cmdList.add(RemoveRawUsageRecordsCmd.class);
|
||||
cmdList.add(ListTrafficMonitorsCmd.class);
|
||||
cmdList.add(ListTrafficTypeImplementorsCmd.class);
|
||||
|
||||
@ -56,7 +56,7 @@ import com.cloud.utils.db.TransactionLegacy;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
import org.apache.cloudstack.api.command.admin.usage.GenerateUsageRecordsCmd;
|
||||
import org.apache.cloudstack.api.command.admin.usage.GetUsageRecordsCmd;
|
||||
import org.apache.cloudstack.api.command.admin.usage.ListUsageRecordsCmd;
|
||||
import org.apache.cloudstack.api.command.admin.usage.RemoveRawUsageRecordsCmd;
|
||||
import org.apache.cloudstack.api.response.UsageTypeResponse;
|
||||
import org.apache.cloudstack.context.CallContext;
|
||||
@ -159,7 +159,7 @@ public class UsageServiceImpl extends ManagerBase implements UsageService, Manag
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<List<? extends Usage>, Integer> getUsageRecords(GetUsageRecordsCmd cmd) {
|
||||
public Pair<List<? extends Usage>, Integer> getUsageRecords(ListUsageRecordsCmd cmd) {
|
||||
Long accountId = cmd.getAccountId();
|
||||
Long domainId = cmd.getDomainId();
|
||||
String accountName = cmd.getAccountName();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user