Search in sources :

Example 21 with AccountVO

use of com.cloud.user.AccountVO in project cloudstack by apache.

the class IAMApiServiceImpl method createIAMGroupResponse.

@Override
public IAMGroupResponse createIAMGroupResponse(IAMGroup group) {
    IAMGroupResponse response = new IAMGroupResponse();
    response.setId(group.getUuid());
    response.setName(group.getName());
    response.setDescription(group.getDescription());
    String domainPath = group.getPath();
    if (domainPath != null) {
        DomainVO domain = _domainDao.findDomainByPath(domainPath);
        if (domain != null) {
            response.setDomainId(domain.getUuid());
            response.setDomainName(domain.getName());
        }
    }
    long accountId = group.getAccountId();
    AccountVO owner = _accountDao.findById(accountId);
    if (owner != null) {
        response.setAccountName(owner.getAccountName());
    }
    // find all the members in this group
    List<Long> members = _iamSrv.listAccountsByGroup(group.getId());
    if (members != null && members.size() > 0) {
        for (Long member : members) {
            AccountVO mem = _accountDao.findById(member);
            if (mem != null) {
                response.addMemberAccount(mem.getAccountName());
            }
        }
    }
    // find all the policies attached to this group
    List<IAMPolicy> policies = _iamSrv.listIAMPoliciesByGroup(group.getId());
    if (policies != null && policies.size() > 0) {
        for (IAMPolicy policy : policies) {
            response.addPolicy(policy.getName());
        }
    }
    response.setObjectName("aclgroup");
    return response;
}
Also used : DomainVO(com.cloud.domain.DomainVO) IAMPolicy(org.apache.cloudstack.iam.api.IAMPolicy) IAMGroupResponse(org.apache.cloudstack.api.response.iam.IAMGroupResponse) AccountVO(com.cloud.user.AccountVO)

Example 22 with AccountVO

use of com.cloud.user.AccountVO in project cloudstack by apache.

the class ConfigurationServerImpl method updateResourceCount.

@DB
public void updateResourceCount() {
    ResourceType[] resourceTypes = Resource.ResourceType.values();
    List<AccountVO> accounts = _accountDao.listAll();
    List<DomainVO> domains = _domainDao.listAll();
    List<ResourceCountVO> domainResourceCount = _resourceCountDao.listResourceCountByOwnerType(ResourceOwnerType.Domain);
    List<ResourceCountVO> accountResourceCount = _resourceCountDao.listResourceCountByOwnerType(ResourceOwnerType.Account);
    final List<ResourceType> accountSupportedResourceTypes = new ArrayList<ResourceType>();
    final List<ResourceType> domainSupportedResourceTypes = new ArrayList<ResourceType>();
    for (ResourceType resourceType : resourceTypes) {
        if (resourceType.supportsOwner(ResourceOwnerType.Account)) {
            accountSupportedResourceTypes.add(resourceType);
        }
        if (resourceType.supportsOwner(ResourceOwnerType.Domain)) {
            domainSupportedResourceTypes.add(resourceType);
        }
    }
    final int accountExpectedCount = accountSupportedResourceTypes.size();
    final int domainExpectedCount = domainSupportedResourceTypes.size();
    if ((domainResourceCount.size() < domainExpectedCount * domains.size())) {
        s_logger.debug("resource_count table has records missing for some domains...going to insert them");
        for (final DomainVO domain : domains) {
            // Lock domain
            Transaction.execute(new TransactionCallbackNoReturn() {

                @Override
                public void doInTransactionWithoutResult(TransactionStatus status) {
                    _domainDao.lockRow(domain.getId(), true);
                    List<ResourceCountVO> domainCounts = _resourceCountDao.listByOwnerId(domain.getId(), ResourceOwnerType.Domain);
                    List<String> domainCountStr = new ArrayList<String>();
                    for (ResourceCountVO domainCount : domainCounts) {
                        domainCountStr.add(domainCount.getType().toString());
                    }
                    if (domainCountStr.size() < domainExpectedCount) {
                        for (ResourceType resourceType : domainSupportedResourceTypes) {
                            if (!domainCountStr.contains(resourceType.toString())) {
                                ResourceCountVO resourceCountVO = new ResourceCountVO(resourceType, 0, domain.getId(), ResourceOwnerType.Domain);
                                s_logger.debug("Inserting resource count of type " + resourceType + " for domain id=" + domain.getId());
                                _resourceCountDao.persist(resourceCountVO);
                            }
                        }
                    }
                }
            });
        }
    }
    if ((accountResourceCount.size() < accountExpectedCount * accounts.size())) {
        s_logger.debug("resource_count table has records missing for some accounts...going to insert them");
        for (final AccountVO account : accounts) {
            // lock account
            Transaction.execute(new TransactionCallbackNoReturn() {

                @Override
                public void doInTransactionWithoutResult(TransactionStatus status) {
                    _accountDao.lockRow(account.getId(), true);
                    List<ResourceCountVO> accountCounts = _resourceCountDao.listByOwnerId(account.getId(), ResourceOwnerType.Account);
                    List<String> accountCountStr = new ArrayList<String>();
                    for (ResourceCountVO accountCount : accountCounts) {
                        accountCountStr.add(accountCount.getType().toString());
                    }
                    if (accountCountStr.size() < accountExpectedCount) {
                        for (ResourceType resourceType : accountSupportedResourceTypes) {
                            if (!accountCountStr.contains(resourceType.toString())) {
                                ResourceCountVO resourceCountVO = new ResourceCountVO(resourceType, 0, account.getId(), ResourceOwnerType.Account);
                                s_logger.debug("Inserting resource count of type " + resourceType + " for account id=" + account.getId());
                                _resourceCountDao.persist(resourceCountVO);
                            }
                        }
                    }
                }
            });
        }
    }
}
Also used : ArrayList(java.util.ArrayList) TransactionStatus(com.cloud.utils.db.TransactionStatus) ResourceType(com.cloud.configuration.Resource.ResourceType) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) AccountVO(com.cloud.user.AccountVO) DomainVO(com.cloud.domain.DomainVO) ResourceCountVO(com.cloud.configuration.ResourceCountVO) ArrayList(java.util.ArrayList) List(java.util.List) DB(com.cloud.utils.db.DB)

Example 23 with AccountVO

use of com.cloud.user.AccountVO in project cloudstack by apache.

the class NuageVspGuestNetworkGuruTest method testReserve.

@Test
public void testReserve() throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, URISyntaxException {
    final NetworkVO network = mock(NetworkVO.class);
    when(network.getId()).thenReturn(NETWORK_ID);
    when(network.getUuid()).thenReturn("aaaaaa");
    when(network.getDataCenterId()).thenReturn(NETWORK_ID);
    when(network.getNetworkOfferingId()).thenReturn(NETWORK_ID);
    when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    when(network.getDomainId()).thenReturn(NETWORK_ID);
    when(network.getAccountId()).thenReturn(NETWORK_ID);
    when(network.getVpcId()).thenReturn(null);
    when(network.getBroadcastUri()).thenReturn(new URI("vsp://aaaaaa-aavvv/10.1.1.1"));
    final DataCenterVO dataCenter = mock(DataCenterVO.class);
    when(_dataCenterDao.findById(NETWORK_ID)).thenReturn(dataCenter);
    final AccountVO networksAccount = mock(AccountVO.class);
    when(networksAccount.getId()).thenReturn(NETWORK_ID);
    when(networksAccount.getUuid()).thenReturn("aaaa-abbbb");
    when(networksAccount.getType()).thenReturn(Account.ACCOUNT_TYPE_NORMAL);
    when(_accountDao.findById(NETWORK_ID)).thenReturn(networksAccount);
    final DomainVO networksDomain = mock(DomainVO.class);
    when(networksDomain.getId()).thenReturn(NETWORK_ID);
    when(networksDomain.getUuid()).thenReturn("aaaaa-bbbbb");
    when(_domainDao.findById(NETWORK_ID)).thenReturn(networksDomain);
    final NicVO nicvo = mock(NicVO.class);
    when(nicvo.getId()).thenReturn(NETWORK_ID);
    when(nicvo.getMacAddress()).thenReturn("aa-aa-aa-aa-aa-aa");
    when(nicvo.getUuid()).thenReturn("aaaa-fffff");
    when(nicvo.getNetworkId()).thenReturn(NETWORK_ID);
    when(nicvo.getInstanceId()).thenReturn(NETWORK_ID);
    when(_nicDao.findById(NETWORK_ID)).thenReturn(nicvo);
    when(_nicDao.findDefaultNicForVM(NETWORK_ID)).thenReturn(nicvo);
    final VirtualMachine vm = mock(VirtualMachine.class);
    when(vm.getId()).thenReturn(NETWORK_ID);
    when(vm.getType()).thenReturn(VirtualMachine.Type.User);
    final VirtualMachineProfile vmProfile = mock(VirtualMachineProfile.class);
    when(vmProfile.getType()).thenReturn(VirtualMachine.Type.User);
    when(vmProfile.getInstanceName()).thenReturn("");
    when(vmProfile.getUuid()).thenReturn("aaaa-bbbbb");
    when(vmProfile.getVirtualMachine()).thenReturn(vm);
    NicProfile nicProfile = mock(NicProfile.class);
    when(nicProfile.getUuid()).thenReturn("aaa-bbbb");
    when(nicProfile.getId()).thenReturn(NETWORK_ID);
    when(nicProfile.getMacAddress()).thenReturn("aa-aa-aa-aa-aa-aa");
    final NetworkOfferingVO ntwkoffering = mock(NetworkOfferingVO.class);
    when(ntwkoffering.getId()).thenReturn(NETWORK_ID);
    when(_networkOfferingDao.findById(NETWORK_ID)).thenReturn(ntwkoffering);
    when(_networkDao.acquireInLockTable(NETWORK_ID, 1200)).thenReturn(network);
    when(_ipAddressDao.findByVmIdAndNetworkId(NETWORK_ID, NETWORK_ID)).thenReturn(null);
    when(_domainDao.findById(NETWORK_ID)).thenReturn(mock(DomainVO.class));
    final Answer answer = mock(Answer.class);
    when(answer.getResult()).thenReturn(true);
    when(_agentManager.easySend(eq(NETWORK_ID), (Command) any())).thenReturn(answer);
    final ReservationContext reservationContext = mock(ReservationContext.class);
    when(reservationContext.getAccount()).thenReturn(networksAccount);
    when(reservationContext.getDomain()).thenReturn(networksDomain);
    _nuageVspGuestNetworkGuru.reserve(nicProfile, network, vmProfile, mock(DeployDestination.class), reservationContext);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NicProfile(com.cloud.vm.NicProfile) URI(java.net.URI) AccountVO(com.cloud.user.AccountVO) ReservationContext(com.cloud.vm.ReservationContext) DomainVO(com.cloud.domain.DomainVO) Answer(com.cloud.agent.api.Answer) DeployDestination(com.cloud.deploy.DeployDestination) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) NicVO(com.cloud.vm.NicVO) VirtualMachine(com.cloud.vm.VirtualMachine) NuageTest(com.cloud.NuageTest) Test(org.junit.Test)

Example 24 with AccountVO

use of com.cloud.user.AccountVO in project cloudstack by apache.

the class NuageVspGuestNetworkGuruTest method testImplementNetwork.

@Test
public void testImplementNetwork() throws URISyntaxException, InsufficientVirtualNetworkCapacityException {
    final NetworkVO network = mock(NetworkVO.class);
    when(network.getId()).thenReturn(NETWORK_ID);
    when(network.getUuid()).thenReturn("aaaaaa");
    when(network.getDataCenterId()).thenReturn(NETWORK_ID);
    when(network.getNetworkOfferingId()).thenReturn(NETWORK_ID);
    when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    when(network.getDomainId()).thenReturn(NETWORK_ID);
    when(network.getAccountId()).thenReturn(NETWORK_ID);
    when(network.getVpcId()).thenReturn(null);
    when(network.getState()).thenReturn(com.cloud.network.Network.State.Implementing);
    when(network.getTrafficType()).thenReturn(TrafficType.Guest);
    when(network.getMode()).thenReturn(Mode.Static);
    when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Vsp);
    when(network.getBroadcastUri()).thenReturn(new URI("vsp://aaaaaa-aavvv/10.1.1.1"));
    when(network.getGateway()).thenReturn("10.1.1.1");
    when(network.getCidr()).thenReturn("10.1.1.0/24");
    when(network.getName()).thenReturn("iso");
    final NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getTags()).thenReturn("aaaa");
    when(offering.getEgressDefaultPolicy()).thenReturn(true);
    when(_networkModel.findPhysicalNetworkId(NETWORK_ID, "aaa", TrafficType.Guest)).thenReturn(NETWORK_ID);
    final ReservationContext reserveContext = mock(ReservationContext.class);
    final Domain domain = mock(Domain.class);
    when(domain.getId()).thenReturn(NETWORK_ID);
    when(reserveContext.getDomain()).thenReturn(domain);
    when(domain.getName()).thenReturn("aaaaa");
    final Account account = mock(Account.class);
    when(account.getId()).thenReturn(NETWORK_ID);
    when(account.getAccountId()).thenReturn(NETWORK_ID);
    when(reserveContext.getAccount()).thenReturn(account);
    final DomainVO domainVo = mock(DomainVO.class);
    when(_domainDao.findById(NETWORK_ID)).thenReturn(domainVo);
    final AccountVO accountVo = mock(AccountVO.class);
    when(_accountDao.findById(NETWORK_ID)).thenReturn(accountVo);
    when(_networkDao.acquireInLockTable(NETWORK_ID, 1200)).thenReturn(network);
    when(_nuageVspManager.getDnsDetails(network.getDataCenterId())).thenReturn(new ArrayList<String>());
    when(_nuageVspManager.getGatewaySystemIds()).thenReturn(new ArrayList<String>());
    final DataCenter dc = mock(DataCenter.class);
    when(dc.getId()).thenReturn(NETWORK_ID);
    final DeployDestination deployDest = mock(DeployDestination.class);
    when(deployDest.getDataCenter()).thenReturn(dc);
    _nuageVspGuestNetworkGuru.implement(network, offering, deployDest, reserveContext);
}
Also used : Account(com.cloud.user.Account) DomainVO(com.cloud.domain.DomainVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) DataCenter(com.cloud.dc.DataCenter) NetworkOffering(com.cloud.offering.NetworkOffering) DeployDestination(com.cloud.deploy.DeployDestination) Domain(com.cloud.domain.Domain) URI(java.net.URI) AccountVO(com.cloud.user.AccountVO) ReservationContext(com.cloud.vm.ReservationContext) NuageTest(com.cloud.NuageTest) Test(org.junit.Test)

Example 25 with AccountVO

use of com.cloud.user.AccountVO in project cloudstack by apache.

the class VolumeApiServiceImplTest method setup.

@Before
public void setup() throws Exception {
    MockitoAnnotations.initMocks(this);
    _svc._volsDao = _volumeDao;
    _svc._accountMgr = _accountMgr;
    _svc._userVmDao = _userVmDao;
    _svc._storagePoolDao = _storagePoolDao;
    _svc._vmSnapshotDao = _vmSnapshotDao;
    _svc._vmInstanceDao = _vmInstanceDao;
    _svc._jobMgr = _jobMgr;
    _svc.volFactory = _volFactory;
    _svc.volService = volService;
    _svc._userVmMgr = _userVmMgr;
    _svc._dcDao = _dcDao;
    _svc._resourceLimitMgr = _resourceLimitMgr;
    _svc._accountDao = _accountDao;
    _svc._hostDao = _hostDao;
    _svc._gson = GsonHelper.getGsonLogger();
    // mock caller context
    AccountVO account = new AccountVO("admin", 1L, "networkDomain", Account.ACCOUNT_TYPE_NORMAL, "uuid");
    AccountVO account2 = new AccountVO("Account2", 2L, "networkDomain", Account.ACCOUNT_TYPE_NORMAL, "uuid");
    UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
    CallContext.register(user, account);
    // mock async context
    AsyncJobExecutionContext context = new AsyncJobExecutionContext();
    AsyncJobExecutionContext.init(_svc._jobMgr, _joinMapDao);
    AsyncJobVO job = new AsyncJobVO();
    context.setJob(job);
    AsyncJobExecutionContext.setCurrentExecutionContext(context);
    TransactionLegacy txn = TransactionLegacy.open("runVolumeDaoImplTest");
    try {
        // volume of running vm id=1
        VolumeVO volumeOfRunningVm = new VolumeVO("root", 1L, 1L, 1L, 1L, 1L, "root", "root", Storage.ProvisioningType.THIN, 1, null, null, "root", Volume.Type.ROOT);
        when(_svc._volsDao.findById(1L)).thenReturn(volumeOfRunningVm);
        UserVmVO runningVm = new UserVmVO(1L, "vm", "vm", 1, HypervisorType.XenServer, 1L, false, false, 1L, 1L, 1, 1L, null, "vm", null);
        runningVm.setState(State.Running);
        runningVm.setDataCenterId(1L);
        when(_svc._userVmDao.findById(1L)).thenReturn(runningVm);
        // volume of stopped vm id=2
        VolumeVO volumeOfStoppedVm = new VolumeVO("root", 1L, 1L, 1L, 1L, 2L, "root", "root", Storage.ProvisioningType.THIN, 1, null, null, "root", Volume.Type.ROOT);
        volumeOfStoppedVm.setPoolId(1L);
        when(_svc._volsDao.findById(2L)).thenReturn(volumeOfStoppedVm);
        UserVmVO stoppedVm = new UserVmVO(2L, "vm", "vm", 1, HypervisorType.XenServer, 1L, false, false, 1L, 1L, 1, 1L, null, "vm", null);
        stoppedVm.setState(State.Stopped);
        stoppedVm.setDataCenterId(1L);
        when(_svc._userVmDao.findById(2L)).thenReturn(stoppedVm);
        // volume of hyperV vm id=3
        UserVmVO hyperVVm = new UserVmVO(3L, "vm", "vm", 1, HypervisorType.Hyperv, 1L, false, false, 1L, 1L, 1, 1L, null, "vm", null);
        hyperVVm.setState(State.Stopped);
        hyperVVm.setDataCenterId(1L);
        when(_svc._userVmDao.findById(3L)).thenReturn(hyperVVm);
        VolumeVO volumeOfStoppeHyperVVm = new VolumeVO("root", 1L, 1L, 1L, 1L, 3L, "root", "root", Storage.ProvisioningType.THIN, 1, null, null, "root", Volume.Type.ROOT);
        volumeOfStoppeHyperVVm.setPoolId(1L);
        when(_svc._volsDao.findById(3L)).thenReturn(volumeOfStoppeHyperVVm);
        StoragePoolVO unmanagedPool = new StoragePoolVO();
        when(_svc._storagePoolDao.findById(1L)).thenReturn(unmanagedPool);
        // volume of managed pool id=4
        StoragePoolVO managedPool = new StoragePoolVO();
        managedPool.setManaged(true);
        when(_svc._storagePoolDao.findById(2L)).thenReturn(managedPool);
        VolumeVO managedPoolVolume = new VolumeVO("root", 1L, 1L, 1L, 1L, 2L, "root", "root", Storage.ProvisioningType.THIN, 1, null, null, "root", Volume.Type.ROOT);
        managedPoolVolume.setPoolId(2L);
        when(_svc._volsDao.findById(4L)).thenReturn(managedPoolVolume);
        // non-root non-datadisk volume
        VolumeInfo volumeWithIncorrectVolumeType = Mockito.mock(VolumeInfo.class);
        when(volumeWithIncorrectVolumeType.getId()).thenReturn(5L);
        when(volumeWithIncorrectVolumeType.getVolumeType()).thenReturn(Volume.Type.ISO);
        when(_svc.volFactory.getVolume(5L)).thenReturn(volumeWithIncorrectVolumeType);
        // correct root volume
        VolumeInfo correctRootVolume = Mockito.mock(VolumeInfo.class);
        when(correctRootVolume.getId()).thenReturn(6L);
        when(correctRootVolume.getDataCenterId()).thenReturn(1L);
        when(correctRootVolume.getVolumeType()).thenReturn(Volume.Type.ROOT);
        when(correctRootVolume.getInstanceId()).thenReturn(null);
        when(correctRootVolume.getState()).thenReturn(Volume.State.Ready);
        when(correctRootVolume.getTemplateId()).thenReturn(null);
        when(correctRootVolume.getPoolId()).thenReturn(1L);
        when(_svc.volFactory.getVolume(6L)).thenReturn(correctRootVolume);
        VolumeVO correctRootVolumeVO = new VolumeVO("root", 1L, 1L, 1L, 1L, 2L, "root", "root", Storage.ProvisioningType.THIN, 1, null, null, "root", Volume.Type.ROOT);
        when(_svc._volsDao.findById(6L)).thenReturn(correctRootVolumeVO);
        // managed root volume
        VolumeInfo managedVolume = Mockito.mock(VolumeInfo.class);
        when(managedVolume.getId()).thenReturn(7L);
        when(managedVolume.getDataCenterId()).thenReturn(1L);
        when(managedVolume.getVolumeType()).thenReturn(Volume.Type.ROOT);
        when(managedVolume.getInstanceId()).thenReturn(null);
        when(managedVolume.getPoolId()).thenReturn(2L);
        when(_svc.volFactory.getVolume(7L)).thenReturn(managedVolume);
        VolumeVO managedVolume1 = new VolumeVO("root", 1L, 1L, 1L, 1L, 2L, "root", "root", Storage.ProvisioningType.THIN, 1, null, null, "root", Volume.Type.ROOT);
        managedVolume1.setPoolId(2L);
        managedVolume1.setDataCenterId(1L);
        when(_svc._volsDao.findById(7L)).thenReturn(managedVolume1);
        // vm having root volume
        UserVmVO vmHavingRootVolume = new UserVmVO(4L, "vm", "vm", 1, HypervisorType.XenServer, 1L, false, false, 1L, 1L, 1, 1L, null, "vm", null);
        vmHavingRootVolume.setState(State.Stopped);
        vmHavingRootVolume.setDataCenterId(1L);
        when(_svc._userVmDao.findById(4L)).thenReturn(vmHavingRootVolume);
        List<VolumeVO> vols = new ArrayList<VolumeVO>();
        vols.add(new VolumeVO());
        when(_svc._volsDao.findByInstanceAndDeviceId(4L, 0L)).thenReturn(vols);
        // volume in uploaded state
        VolumeInfo uploadedVolume = Mockito.mock(VolumeInfo.class);
        when(uploadedVolume.getId()).thenReturn(8L);
        when(uploadedVolume.getDataCenterId()).thenReturn(1L);
        when(uploadedVolume.getVolumeType()).thenReturn(Volume.Type.ROOT);
        when(uploadedVolume.getInstanceId()).thenReturn(null);
        when(uploadedVolume.getPoolId()).thenReturn(1L);
        when(uploadedVolume.getState()).thenReturn(Volume.State.Uploaded);
        when(_svc.volFactory.getVolume(8L)).thenReturn(uploadedVolume);
        VolumeVO upVolume = new VolumeVO("root", 1L, 1L, 1L, 1L, 2L, "root", "root", Storage.ProvisioningType.THIN, 1, null, null, "root", Volume.Type.ROOT);
        upVolume.setPoolId(1L);
        upVolume.setDataCenterId(1L);
        upVolume.setState(Volume.State.Uploaded);
        when(_svc._volsDao.findById(8L)).thenReturn(upVolume);
        // helper dao methods mock
        when(_svc._vmSnapshotDao.findByVm(any(Long.class))).thenReturn(new ArrayList<VMSnapshotVO>());
        when(_svc._vmInstanceDao.findById(any(Long.class))).thenReturn(stoppedVm);
        DataCenterVO enabledZone = Mockito.mock(DataCenterVO.class);
        when(enabledZone.getAllocationState()).thenReturn(Grouping.AllocationState.Enabled);
        when(_svc._dcDao.findById(anyLong())).thenReturn(enabledZone);
    } finally {
        txn.close("runVolumeDaoImplTest");
    }
    // helper methods mock
    doNothing().when(_svc._accountMgr).checkAccess(any(Account.class), any(AccessType.class), any(Boolean.class), any(ControlledEntity.class));
    doNothing().when(_svc._jobMgr).updateAsyncJobAttachment(any(Long.class), any(String.class), any(Long.class));
    when(_svc._jobMgr.submitAsyncJob(any(AsyncJobVO.class), any(String.class), any(Long.class))).thenReturn(1L);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Account(com.cloud.user.Account) UserVmVO(com.cloud.vm.UserVmVO) AsyncJobExecutionContext(org.apache.cloudstack.framework.jobs.AsyncJobExecutionContext) ArrayList(java.util.ArrayList) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) Matchers.anyString(org.mockito.Matchers.anyString) AccountVO(com.cloud.user.AccountVO) AsyncJobVO(org.apache.cloudstack.framework.jobs.impl.AsyncJobVO) TransactionLegacy(com.cloud.utils.db.TransactionLegacy) VMSnapshotVO(com.cloud.vm.snapshot.VMSnapshotVO) UserVO(com.cloud.user.UserVO) ControlledEntity(org.apache.cloudstack.acl.ControlledEntity) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) Matchers.anyLong(org.mockito.Matchers.anyLong) AccessType(org.apache.cloudstack.acl.SecurityChecker.AccessType) Before(org.junit.Before)

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