use of com.cloud.usage.UsageVO in project cloudstack by apache.
the class VPNUserUsageParser method createUsageRecord.
private static void createUsageRecord(int type, long runningTime, Date startDate, Date endDate, AccountVO account, long userId, String userName, long zoneId) {
// Our smallest increment is hourly for now
if (s_logger.isDebugEnabled()) {
s_logger.debug("Total running time " + runningTime + "ms");
}
float usage = runningTime / 1000f / 60f / 60f;
DecimalFormat dFormat = new DecimalFormat("#.######");
String usageDisplay = dFormat.format(usage);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Creating VPN user:" + userId + " usage record, usage: " + usageDisplay + ", startDate: " + startDate + ", endDate: " + endDate + ", for account: " + account.getId());
}
// Create the usage record
String usageDesc = "VPN User: " + userName + ", Id: " + userId + " usage time";
UsageVO usageRecord = new UsageVO(zoneId, account.getId(), account.getDomainId(), usageDesc, usageDisplay + " Hrs", type, new Double(usage), null, null, null, null, userId, null, startDate, endDate);
s_usageDao.persist(usageRecord);
}
use of com.cloud.usage.UsageVO in project cloudstack by apache.
the class VolumeUsageParser method createUsageRecord.
private static void createUsageRecord(int type, long runningTime, Date startDate, Date endDate, AccountVO account, long volId, long zoneId, Long doId, Long templateId, long size) {
// Our smallest increment is hourly for now
if (s_logger.isDebugEnabled()) {
s_logger.debug("Total running time " + runningTime + "ms");
}
float usage = runningTime / 1000f / 60f / 60f;
DecimalFormat dFormat = new DecimalFormat("#.######");
String usageDisplay = dFormat.format(usage);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Creating Volume usage record for vol: " + volId + ", usage: " + usageDisplay + ", startDate: " + startDate + ", endDate: " + endDate + ", for account: " + account.getId());
}
// Create the usage record
String usageDesc = "Volume Id: " + volId + " usage time";
if (templateId != null) {
usageDesc += " (Template: " + templateId + ")";
} else if (doId != null) {
usageDesc += " (DiskOffering: " + doId + ")";
}
UsageVO usageRecord = new UsageVO(zoneId, account.getId(), account.getDomainId(), usageDesc, usageDisplay + " Hrs", type, new Double(usage), null, null, doId, templateId, volId, size, startDate, endDate);
s_usageDao.persist(usageRecord);
}
use of com.cloud.usage.UsageVO in project cloudstack by apache.
the class ApiResponseHelperTest method testUsageRecordResponse.
@Test
public void testUsageRecordResponse() {
// Creating the usageVO object to be passed to the createUsageResponse.
Long zoneId = null;
Long accountId = 1L;
Long domainId = 1L;
String Description = "Test Object";
String usageDisplay = " ";
int usageType = -1;
Double rawUsage = null;
Long vmId = null;
String vmName = " ";
Long offeringId = null;
Long templateId = null;
Long usageId = null;
Date startDate = null;
Date endDate = null;
String type = " ";
UsageVO usage = new UsageVO(zoneId, accountId, domainId, Description, usageDisplay, usageType, rawUsage, vmId, vmName, offeringId, templateId, usageId, startDate, endDate, type);
DomainVO domain = new DomainVO();
domain.setName("DomainName");
AccountVO account = new AccountVO();
PowerMockito.mockStatic(ApiDBUtils.class);
when(ApiDBUtils.findAccountById(anyLong())).thenReturn(account);
when(ApiDBUtils.findDomainById(anyLong())).thenReturn(domain);
UsageRecordResponse MockResponse = helper.createUsageResponse(usage);
assertEquals("DomainName", MockResponse.getDomainName());
}
use of com.cloud.usage.UsageVO in project cloudstack by apache.
the class QuotaManagerImpl method aggregatePendingQuotaRecordsForAccount.
public List<QuotaUsageVO> aggregatePendingQuotaRecordsForAccount(final AccountVO account, final Pair<List<? extends UsageVO>, Integer> usageRecords) {
List<QuotaUsageVO> quotaListForAccount = new ArrayList<>();
if (usageRecords == null || usageRecords.first() == null || usageRecords.first().isEmpty()) {
return quotaListForAccount;
}
s_logger.info("Getting pending quota records for account=" + account.getAccountName());
for (UsageVO usageRecord : usageRecords.first()) {
switch(usageRecord.getUsageType()) {
case QuotaTypes.RUNNING_VM:
List<QuotaUsageVO> lq = updateQuotaRunningVMUsage(usageRecord);
if (!lq.isEmpty()) {
quotaListForAccount.addAll(lq);
}
break;
case QuotaTypes.ALLOCATED_VM:
QuotaUsageVO qu = updateQuotaAllocatedVMUsage(usageRecord);
if (qu != null) {
quotaListForAccount.add(qu);
}
break;
case QuotaTypes.SNAPSHOT:
case QuotaTypes.TEMPLATE:
case QuotaTypes.ISO:
case QuotaTypes.VOLUME:
case QuotaTypes.VM_SNAPSHOT:
case QuotaTypes.BACKUP:
qu = updateQuotaDiskUsage(usageRecord, usageRecord.getUsageType());
if (qu != null) {
quotaListForAccount.add(qu);
}
break;
case QuotaTypes.LOAD_BALANCER_POLICY:
case QuotaTypes.PORT_FORWARDING_RULE:
case QuotaTypes.IP_ADDRESS:
case QuotaTypes.NETWORK_OFFERING:
case QuotaTypes.SECURITY_GROUP:
case QuotaTypes.VPN_USERS:
qu = updateQuotaRaw(usageRecord, usageRecord.getUsageType());
if (qu != null) {
quotaListForAccount.add(qu);
}
break;
case QuotaTypes.NETWORK_BYTES_RECEIVED:
case QuotaTypes.NETWORK_BYTES_SENT:
qu = updateQuotaNetwork(usageRecord, usageRecord.getUsageType());
if (qu != null) {
quotaListForAccount.add(qu);
}
break;
case QuotaTypes.VM_DISK_IO_READ:
case QuotaTypes.VM_DISK_IO_WRITE:
case QuotaTypes.VM_DISK_BYTES_READ:
case QuotaTypes.VM_DISK_BYTES_WRITE:
default:
break;
}
}
return quotaListForAccount;
}
use of com.cloud.usage.UsageVO in project cloudstack by apache.
the class QuotaManagerImplTest method testUpdateQuotaRecords.
@Test
public void testUpdateQuotaRecords() {
UsageVO usageVO = new UsageVO();
usageVO.setId(100L);
usageVO.setQuotaCalculated(0);
usageVO.setUsageType(UsageTypes.NETWORK_BYTES_SENT);
usageVO.setRawUsage(9000000000.0);
usageVO.setSize(1010101010L);
QuotaTariffVO tariffVO = new QuotaTariffVO();
tariffVO.setCurrencyValue(new BigDecimal(1));
Mockito.when(quotaTariffDao.findTariffPlanByUsageType(nullable(Integer.class), nullable(Date.class))).thenReturn(tariffVO);
QuotaUsageVO qu = quotaManager.updateQuotaNetwork(usageVO, UsageTypes.NETWORK_BYTES_SENT);
assertTrue(qu.getQuotaUsed().compareTo(BigDecimal.ZERO) > 0);
qu = quotaManager.updateQuotaAllocatedVMUsage(usageVO);
assertTrue(qu.getQuotaUsed().compareTo(BigDecimal.ZERO) > 0);
qu = quotaManager.updateQuotaDiskUsage(usageVO, UsageTypes.VOLUME);
assertTrue(qu.getQuotaUsed().compareTo(BigDecimal.ZERO) > 0);
qu = quotaManager.updateQuotaRaw(usageVO, UsageTypes.VPN_USERS);
assertTrue(qu.getQuotaUsed().compareTo(BigDecimal.ZERO) > 0);
Mockito.verify(quotaUsageDao, Mockito.times(4)).persistQuotaUsage(Mockito.any(QuotaUsageVO.class));
Mockito.verify(usageDao, Mockito.times(4)).persistUsage(Mockito.any(UsageVO.class));
}
Aggregations