Search in sources :

Example 41 with AccountVO

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;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) QuotaUsageVO(org.apache.cloudstack.quota.vo.QuotaUsageVO) UsageVO(com.cloud.usage.UsageVO) QuotaAccountVO(org.apache.cloudstack.quota.vo.QuotaAccountVO) AccountVO(com.cloud.user.AccountVO) QuotaUsageVO(org.apache.cloudstack.quota.vo.QuotaUsageVO)

Example 42 with AccountVO

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());
    }
}
Also used : Account(com.cloud.user.Account) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SolidFireUtil(org.apache.cloudstack.storage.datastore.util.SolidFireUtil) AccountVO(com.cloud.user.AccountVO)

Example 43 with AccountVO

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();
    }
}
Also used : Field(java.lang.reflect.Field) Account(com.cloud.user.Account) UserVO(com.cloud.user.UserVO) ArrayList(java.util.ArrayList) AccountService(com.cloud.user.AccountService) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) VolumeOrchestrationService(org.apache.cloudstack.engine.orchestration.service.VolumeOrchestrationService) ResourceLimitService(com.cloud.user.ResourceLimitService) UpdateVmNicIpCmd(org.apache.cloudstack.api.command.user.vm.UpdateVmNicIpCmd) AccountVO(com.cloud.user.AccountVO) Test(org.junit.Test)

Example 44 with AccountVO

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();
    }
}
Also used : Field(java.lang.reflect.Field) Account(com.cloud.user.Account) UserVO(com.cloud.user.UserVO) DeployDestination(com.cloud.deploy.DeployDestination) ArrayList(java.util.ArrayList) AccountService(com.cloud.user.AccountService) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) VolumeOrchestrationService(org.apache.cloudstack.engine.orchestration.service.VolumeOrchestrationService) ResourceLimitService(com.cloud.user.ResourceLimitService) UpdateVmNicIpCmd(org.apache.cloudstack.api.command.user.vm.UpdateVmNicIpCmd) AccountVO(com.cloud.user.AccountVO) Test(org.junit.Test)

Example 45 with AccountVO

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();
    }
}
Also used : Account(com.cloud.user.Account) UserVO(com.cloud.user.UserVO) AccountVO(com.cloud.user.AccountVO) Test(org.junit.Test)

Aggregations

AccountVO (com.cloud.user.AccountVO)139 Account (com.cloud.user.Account)65 Test (org.junit.Test)52 UserVO (com.cloud.user.UserVO)44 Field (java.lang.reflect.Field)41 ArrayList (java.util.ArrayList)40 DomainVO (com.cloud.domain.DomainVO)32 AccountManager (com.cloud.user.AccountManager)27 Before (org.junit.Before)22 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)21 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)21 Date (java.util.Date)16 QuotaAccountVO (org.apache.cloudstack.quota.vo.QuotaAccountVO)16 DomainDao (com.cloud.domain.dao.DomainDao)14 SslCertDao (com.cloud.network.dao.SslCertDao)14 AgentManager (com.cloud.agent.AgentManager)13 IPAddressDao (com.cloud.network.dao.IPAddressDao)13 LoadBalancerDao (com.cloud.network.dao.LoadBalancerDao)13 NetworkDao (com.cloud.network.dao.NetworkDao)13 NetworkVO (com.cloud.network.dao.NetworkVO)13