use of com.cloud.user.AccountVO in project cloudstack by apache.
the class QuotaManagerImpl method calculateQuotaUsage.
@Override
public boolean calculateQuotaUsage() {
List<AccountVO> accounts = _accountDao.listAll();
for (AccountVO account : accounts) {
Pair<List<? extends UsageVO>, Integer> usageRecords = _usageDao.getUsageRecordsPendingQuotaAggregation(account.getAccountId(), account.getDomainId());
if (s_logger.isDebugEnabled()) {
s_logger.debug("Usage entries size = " + usageRecords.second().intValue() + ", accId" + account.getAccountId() + ", domId" + account.getDomainId());
}
List<QuotaUsageVO> quotaListForAccount = aggregatePendingQuotaRecordsForAccount(account, usageRecords);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Quota entries size = " + quotaListForAccount.size() + ", accId" + account.getAccountId() + ", domId" + account.getDomainId());
}
processQuotaBalanceForAccount(account, quotaListForAccount);
}
return true;
}
use of com.cloud.user.AccountVO in project cloudstack by apache.
the class SolidFireSharedPrimaryDataStoreLifeCycle method createSolidFireVolume.
private SolidFireCreateVolume createSolidFireVolume(SolidFireUtil.SolidFireConnection sfConnection, String volumeName, long volumeSize, long minIops, long maxIops, long burstIops) {
try {
Account csAccount = CallContext.current().getCallingAccount();
long csAccountId = csAccount.getId();
AccountVO accountVo = _accountDao.findById(csAccountId);
String sfAccountName = SolidFireUtil.getSolidFireAccountName(accountVo.getUuid(), csAccountId);
SolidFireUtil.SolidFireAccount sfAccount = SolidFireUtil.getAccount(sfConnection, sfAccountName);
if (sfAccount == null) {
long sfAccountNumber = SolidFireUtil.createAccount(sfConnection, sfAccountName);
sfAccount = SolidFireUtil.getAccountById(sfConnection, sfAccountNumber);
}
long sfVolumeId = SolidFireUtil.createVolume(sfConnection, SolidFireUtil.getSolidFireVolumeName(volumeName), sfAccount.getId(), volumeSize, true, null, minIops, maxIops, burstIops);
SolidFireUtil.SolidFireVolume sfVolume = SolidFireUtil.getVolume(sfConnection, sfVolumeId);
return new SolidFireCreateVolume(sfVolume, sfAccount);
} catch (Throwable e) {
throw new CloudRuntimeException("Failed to create a SolidFire volume: " + e.toString());
}
}
use of com.cloud.user.AccountVO in project cloudstack by apache.
the class UserVmManagerTest method testUpdateVmNicIpFailure1.
// vm is running in network with dhcp support
@Test(expected = InvalidParameterValueException.class)
public void testUpdateVmNicIpFailure1() throws Exception {
UpdateVmNicIpCmd cmd = new UpdateVmNicIpCmd();
Class<?> _class = cmd.getClass();
Field virtualmachineIdField = _class.getDeclaredField("nicId");
virtualmachineIdField.setAccessible(true);
virtualmachineIdField.set(cmd, 1L);
Field accountNameField = _class.getDeclaredField("ipAddr");
accountNameField.setAccessible(true);
accountNameField.set(cmd, "10.10.10.10");
NicVO nic = new NicVO("nic", 1L, 2L, VirtualMachine.Type.User);
when(_nicDao.findById(anyLong())).thenReturn(nic);
when(_vmDao.findById(anyLong())).thenReturn(_vmMock);
when(_networkDao.findById(anyLong())).thenReturn(_networkMock);
when(_networkMock.getState()).thenReturn(Network.State.Implemented);
doReturn(9L).when(_networkMock).getNetworkOfferingId();
when(_networkOfferingDao.findByIdIncludingRemoved(anyLong())).thenReturn(_networkOfferingMock);
doReturn(10L).when(_networkOfferingMock).getId();
List<Service> services = new ArrayList<Service>();
services.add(Service.Dhcp);
when(_networkModel.listNetworkOfferingServices(anyLong())).thenReturn(services);
when(_vmMock.getState()).thenReturn(State.Running);
Account caller = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
CallContext.register(user, caller);
try {
_userVmMgr.updateNicIpForVirtualMachine(cmd);
} finally {
CallContext.unregister();
}
}
use of com.cloud.user.AccountVO in project cloudstack by apache.
the class UserVmManagerTest method testUpdateVmNicIpSuccess1.
@Test
public void testUpdateVmNicIpSuccess1() throws Exception {
UpdateVmNicIpCmd cmd = new UpdateVmNicIpCmd();
Class<?> _class = cmd.getClass();
Field virtualmachineIdField = _class.getDeclaredField("nicId");
virtualmachineIdField.setAccessible(true);
virtualmachineIdField.set(cmd, 1L);
Field accountNameField = _class.getDeclaredField("ipAddr");
accountNameField.setAccessible(true);
accountNameField.set(cmd, "10.10.10.10");
NicVO nic = new NicVO("nic", 1L, 2L, VirtualMachine.Type.User);
when(_nicDao.findById(anyLong())).thenReturn(nic);
when(_vmDao.findById(anyLong())).thenReturn(_vmMock);
when(_networkDao.findById(anyLong())).thenReturn(_networkMock);
doReturn(9L).when(_networkMock).getNetworkOfferingId();
when(_networkOfferingDao.findByIdIncludingRemoved(anyLong())).thenReturn(_networkOfferingMock);
doReturn(10L).when(_networkOfferingMock).getId();
List<Service> services = new ArrayList<Service>();
services.add(Service.Dhcp);
when(_networkModel.listNetworkOfferingServices(anyLong())).thenReturn(services);
when(_vmMock.getState()).thenReturn(State.Stopped);
doNothing().when(_accountMgr).checkAccess(_account, null, true, _vmMock);
when(_accountDao.findByIdIncludingRemoved(anyLong())).thenReturn(_accountMock);
when(_networkMock.getState()).thenReturn(Network.State.Implemented);
when(_networkMock.getDataCenterId()).thenReturn(3L);
when(_networkMock.getGuestType()).thenReturn(GuestType.Isolated);
when(_dcDao.findById(anyLong())).thenReturn(_dcMock);
when(_dcMock.getNetworkType()).thenReturn(NetworkType.Advanced);
when(_ipAddrMgr.allocateGuestIP(Mockito.eq(_networkMock), anyString())).thenReturn("10.10.10.10");
doNothing().when(_networkMgr).implementNetworkElementsAndResources(Mockito.any(DeployDestination.class), Mockito.any(ReservationContext.class), Mockito.eq(_networkMock), Mockito.eq(_networkOfferingMock));
when(_nicDao.persist(any(NicVO.class))).thenReturn(nic);
Account caller = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
CallContext.register(user, caller);
try {
_userVmMgr.updateNicIpForVirtualMachine(cmd);
} finally {
CallContext.unregister();
}
}
use of com.cloud.user.AccountVO in project cloudstack by apache.
the class UserVmManagerTest method testRestoreVMF1.
// Test restoreVm when VM state not in running/stopped case
@Test(expected = CloudRuntimeException.class)
public void testRestoreVMF1() throws ResourceAllocationException, InsufficientCapacityException, ResourceUnavailableException {
when(_vmDao.findById(anyLong())).thenReturn(_vmMock);
when(_templateDao.findById(anyLong())).thenReturn(_templateMock);
doReturn(VirtualMachine.State.Error).when(_vmMock).getState();
Account account = new AccountVO("testaccount", 1L, "networkdomain", (short) 0, "uuid");
UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
CallContext.register(user, account);
try {
_userVmMgr.restoreVMInternal(_account, _vmMock, null);
} finally {
CallContext.unregister();
}
}
Aggregations