Search in sources :

Example 6 with AccountVO

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

the class QuotaStatementTest method testSendStatement.

@Test
public void testSendStatement() throws UnsupportedEncodingException, MessagingException {
    Calendar date = Calendar.getInstance();
    AccountVO accountVO = new AccountVO();
    accountVO.setId(2L);
    accountVO.setDomainId(1L);
    Mockito.when(accountDao.findById(Mockito.anyLong())).thenReturn(accountVO);
    QuotaAccountVO acc = new QuotaAccountVO(2L);
    acc.setQuotaBalance(new BigDecimal(404));
    acc.setLastStatementDate(null);
    List<QuotaAccountVO> accounts = new ArrayList<>();
    accounts.add(acc);
    Mockito.when(quotaAcc.listAllQuotaAccount()).thenReturn(accounts);
    Mockito.when(quotaUsage.findTotalQuotaUsage(Mockito.anyLong(), Mockito.anyLong(), Mockito.anyInt(), Mockito.any(Date.class), Mockito.any(Date.class))).thenReturn(new BigDecimal(100));
    // call real method on send monthly statement
    quotaStatement.sendStatement();
    Calendar[] period = quotaStatement.statementTime(date, QuotaStatementPeriods.MONTHLY);
    if (period != null) {
        Mockito.verify(alertManager, Mockito.times(1)).sendQuotaAlert(Mockito.any(QuotaAlertManagerImpl.DeferredQuotaEmail.class));
    }
}
Also used : Calendar(java.util.Calendar) QuotaAccountVO(org.apache.cloudstack.quota.vo.QuotaAccountVO) ArrayList(java.util.ArrayList) QuotaAccountVO(org.apache.cloudstack.quota.vo.QuotaAccountVO) AccountVO(com.cloud.user.AccountVO) BigDecimal(java.math.BigDecimal) Date(java.util.Date) Test(org.junit.Test)

Example 7 with AccountVO

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

the class InternalLBVMServiceTest method setUp.

@Override
@Before
public void setUp() {
    //mock system offering creation as it's used by configure() method called by initComponentsLifeCycle
    Mockito.when(_accountMgr.getAccount(1L)).thenReturn(new AccountVO());
    ServiceOfferingVO off = new ServiceOfferingVO("alena", 1, 1, 1, 1, 1, false, "alena", Storage.ProvisioningType.THIN, false, false, null, false, VirtualMachine.Type.InternalLoadBalancerVm, false);
    off = setId(off, 1);
    List<ServiceOfferingVO> list = new ArrayList<ServiceOfferingVO>();
    list.add(off);
    list.add(off);
    Mockito.when(_svcOffDao.createSystemServiceOfferings(Matchers.anyString(), Matchers.anyString(), Matchers.anyInt(), Matchers.anyInt(), Matchers.anyInt(), Matchers.anyInt(), Matchers.anyInt(), Matchers.anyBoolean(), Matchers.anyString(), Matchers.any(ProvisioningType.class), Matchers.anyBoolean(), Matchers.anyString(), Matchers.anyBoolean(), Matchers.any(VirtualMachine.Type.class), Matchers.anyBoolean())).thenReturn(list);
    ComponentContext.initComponentsLifeCycle();
    Mockito.when(_accountMgr.getSystemUser()).thenReturn(new UserVO(1));
    Mockito.when(_accountMgr.getSystemAccount()).thenReturn(new AccountVO(2));
    Mockito.when(_accountDao.findByIdIncludingRemoved(Matchers.anyLong())).thenReturn(new AccountVO(2));
    CallContext.register(_accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
    final DomainRouterVO validVm = new DomainRouterVO(validVmId, off.getId(), 1, "alena", 1, HypervisorType.XenServer, 1, 1, 1, 1, false, null, false, false, VirtualMachine.Type.InternalLoadBalancerVm, null);
    validVm.setRole(Role.INTERNAL_LB_VM);
    final DomainRouterVO nonInternalLbVm = new DomainRouterVO(validVmId, off.getId(), 1, "alena", 1, HypervisorType.XenServer, 1, 1, 1, 1, false, null, false, false, VirtualMachine.Type.DomainRouter, null);
    nonInternalLbVm.setRole(Role.VIRTUAL_ROUTER);
    Mockito.when(_domainRouterDao.findById(validVmId)).thenReturn(validVm);
    Mockito.when(_domainRouterDao.findById(nonExistingVmId)).thenReturn(null);
    Mockito.when(_domainRouterDao.findById(nonInternalLbVmId)).thenReturn(nonInternalLbVm);
}
Also used : ProvisioningType(com.cloud.storage.Storage.ProvisioningType) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) ProvisioningType(com.cloud.storage.Storage.ProvisioningType) UserVO(com.cloud.user.UserVO) ArrayList(java.util.ArrayList) AccountVO(com.cloud.user.AccountVO) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) DomainRouterVO(com.cloud.vm.DomainRouterVO) Before(org.junit.Before)

Example 8 with AccountVO

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

the class InternalLBVMManagerTest method setUp.

@Override
@Before
public void setUp() {
    //mock system offering creation as it's used by configure() method called by initComponentsLifeCycle
    Mockito.when(_accountMgr.getAccount(1L)).thenReturn(new AccountVO());
    ServiceOfferingVO off = new ServiceOfferingVO("alena", 1, 1, 1, 1, 1, false, "alena", Storage.ProvisioningType.THIN, false, false, null, false, VirtualMachine.Type.InternalLoadBalancerVm, false);
    off = setId(off, 1);
    List<ServiceOfferingVO> list = new ArrayList<ServiceOfferingVO>();
    list.add(off);
    list.add(off);
    Mockito.when(_svcOffDao.createSystemServiceOfferings(Matchers.anyString(), Matchers.anyString(), Matchers.anyInt(), Matchers.anyInt(), Matchers.anyInt(), Matchers.anyInt(), Matchers.anyInt(), Matchers.anyBoolean(), Matchers.anyString(), Matchers.any(ProvisioningType.class), Matchers.anyBoolean(), Matchers.anyString(), Matchers.anyBoolean(), Matchers.any(VirtualMachine.Type.class), Matchers.anyBoolean())).thenReturn(list);
    ComponentContext.initComponentsLifeCycle();
    vm = new DomainRouterVO(1L, off.getId(), 1, "alena", 1, HypervisorType.XenServer, 1, 1, 1, 1, false, null, false, false, VirtualMachine.Type.InternalLoadBalancerVm, null);
    vm.setRole(Role.INTERNAL_LB_VM);
    vm = setId(vm, 1);
    vm.setPrivateIpAddress("10.2.2.2");
    final NicVO nic = new NicVO("somereserver", 1L, 1L, VirtualMachine.Type.InternalLoadBalancerVm);
    nic.setIPv4Address(requestedIp);
    final List<DomainRouterVO> emptyList = new ArrayList<DomainRouterVO>();
    final List<DomainRouterVO> nonEmptyList = new ArrayList<DomainRouterVO>();
    nonEmptyList.add(vm);
    Mockito.when(_domainRouterDao.listByNetworkAndRole(invalidNtwkId, Role.INTERNAL_LB_VM)).thenReturn(emptyList);
    Mockito.when(_domainRouterDao.listByNetworkAndRole(validNtwkId, Role.INTERNAL_LB_VM)).thenReturn(nonEmptyList);
    Mockito.when(_nicDao.findByNtwkIdAndInstanceId(validNtwkId, 1)).thenReturn(nic);
    Mockito.when(_nicDao.findByNtwkIdAndInstanceId(invalidNtwkId, 1)).thenReturn(nic);
    final Answer answer = new Answer(null, true, null);
    final Answer[] answers = new Answer[1];
    answers[0] = answer;
    try {
        Mockito.when(_agentMgr.send(Matchers.anyLong(), Matchers.any(Commands.class))).thenReturn(answers);
    } catch (final AgentUnavailableException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (final OperationTimedoutException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    createNetwork();
    Mockito.when(_ntwkModel.getNetwork(Matchers.anyLong())).thenReturn(ntwk);
    Mockito.when(_itMgr.toNicTO(Matchers.any(NicProfile.class), Matchers.any(HypervisorType.class))).thenReturn(null);
    Mockito.when(_domainRouterDao.findById(Matchers.anyLong())).thenReturn(vm);
    final DataCenterVO dc = new DataCenterVO(1L, null, null, null, null, null, null, null, null, null, NetworkType.Advanced, null, null);
    Mockito.when(_dcDao.findById(Matchers.anyLong())).thenReturn(dc);
    final NetworkOfferingVO networkOfferingVO = new NetworkOfferingVO();
    networkOfferingVO.setConcurrentConnections(500);
    Mockito.when(_offeringDao.findById(Matchers.anyLong())).thenReturn(networkOfferingVO);
    Mockito.when(_domainRouterDao.findById(validVmId)).thenReturn(vm);
    Mockito.when(_domainRouterDao.findById(invalidVmId)).thenReturn(null);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) ArrayList(java.util.ArrayList) NicProfile(com.cloud.vm.NicProfile) AccountVO(com.cloud.user.AccountVO) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) ProvisioningType(com.cloud.storage.Storage.ProvisioningType) Answer(com.cloud.agent.api.Answer) NetworkType(com.cloud.dc.DataCenter.NetworkType) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) ProvisioningType(com.cloud.storage.Storage.ProvisioningType) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) Commands(com.cloud.agent.manager.Commands) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) NicVO(com.cloud.vm.NicVO) DomainRouterVO(com.cloud.vm.DomainRouterVO) Before(org.junit.Before)

Example 9 with AccountVO

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

the class NuageVspEntityBuilder method buildVspNetwork.

public VspNetwork buildVspNetwork(long domainId, Network network) {
    VspNetwork.Builder vspNetworkBuilder = new VspNetwork.Builder().id(network.getId()).uuid(network.getUuid()).name(network.getName()).cidr(network.getCidr()).gateway(network.getGateway());
    DomainVO domain = _domainDao.findById(domainId);
    VspDomain vspDomain = buildVspDomain(domain);
    vspNetworkBuilder.domain(vspDomain);
    AccountVO account = _accountDao.findById(network.getAccountId());
    if (account != null) {
        vspNetworkBuilder.accountUuid(account.getUuid()).accountName(account.getAccountName());
    }
    NetworkOfferingVO networkOffering = _networkOfferingDao.findById(network.getNetworkOfferingId());
    vspNetworkBuilder.egressDefaultPolicy(networkOffering.getEgressDefaultPolicy()).publicAccess(networkOffering.getSupportsPublicAccess());
    if (network.getVpcId() != null) {
        VpcVO vpc = _vpcDao.findById(network.getVpcId());
        vspNetworkBuilder.vpcUuid(vpc.getUuid()).vpcName(vpc.getName()).networkType(VspNetwork.NetworkType.Vpc);
    } else {
        if (networkOffering.getGuestType() == Network.GuestType.Shared) {
            List<VlanVO> vlans = _vlanDao.listVlansByNetworkIdIncludingRemoved(network.getId());
            List<VspAddressRange> vspAddressRanges = Lists.transform(vlans, new Function<VlanVO, VspAddressRange>() {

                @Nullable
                @Override
                public VspAddressRange apply(VlanVO vlanVO) {
                    return new VspAddressRange.Builder().gateway(vlanVO.getVlanGateway()).netmask(vlanVO.getVlanNetmask()).build();
                }
            });
            vspNetworkBuilder.networkType(VspNetwork.NetworkType.Shared).addressRanges(vspAddressRanges);
        } else if (_networkOfferingServiceMapDao.areServicesSupportedByNetworkOffering(network.getNetworkOfferingId(), Network.Service.SourceNat) || _networkOfferingServiceMapDao.areServicesSupportedByNetworkOffering(network.getNetworkOfferingId(), Network.Service.StaticNat)) {
            vspNetworkBuilder.networkType(VspNetwork.NetworkType.L3);
        } else {
            vspNetworkBuilder.networkType(VspNetwork.NetworkType.L2);
        }
    }
    boolean firewallServiceSupported = _networkModel.areServicesSupportedByNetworkOffering(network.getNetworkOfferingId(), Network.Service.Firewall);
    vspNetworkBuilder.firewallServiceSupported(firewallServiceSupported);
    String preConfiguredDomainTemplateName = NuageVspUtil.getPreConfiguredDomainTemplateName(_configurationDao, _networkDetailsDao, network, networkOffering);
    vspNetworkBuilder.domainTemplateName(preConfiguredDomainTemplateName);
    if (usesVirtualRouter(networkOffering.getId())) {
        try {
            List<Pair<String, String>> ipAddressRanges = networkOffering.getGuestType() == Network.GuestType.Shared ? getSharedIpAddressRanges(network.getId()) : getIpAddressRanges(network);
            String virtualRouterIp = getVirtualRouterIP(network, ipAddressRanges);
            vspNetworkBuilder.virtualRouterIp(virtualRouterIp);
        } catch (InsufficientVirtualNetworkCapacityException ex) {
            s_logger.error("There is an insufficient network capacity in network " + network.getId(), ex);
            throw new CloudRuntimeException("There is an insufficient network capacity in network " + network.getId(), ex);
        }
    }
    return vspNetworkBuilder.build();
}
Also used : VspDomain(net.nuage.vsp.acs.client.api.model.VspDomain) VspAddressRange(net.nuage.vsp.acs.client.api.model.VspAddressRange) AccountVO(com.cloud.user.AccountVO) DomainVO(com.cloud.domain.DomainVO) VpcVO(com.cloud.network.vpc.VpcVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) VspNetwork(net.nuage.vsp.acs.client.api.model.VspNetwork) VlanVO(com.cloud.dc.VlanVO) Nullable(javax.annotation.Nullable) Pair(net.nuage.vsp.acs.client.common.model.Pair)

Example 10 with AccountVO

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

the class GloboDnsElementTest method setUp.

@Before
public void setUp() throws Exception {
    ComponentContext.initComponentsLifeCycle();
    acct = new AccountVO(200L);
    acct.setType(Account.ACCOUNT_TYPE_NORMAL);
    acct.setAccountName("user");
    acct.setDomainId(domainId);
    user = new UserVO();
    user.setUsername("user");
    user.setAccountId(acct.getAccountId());
    CallContext.register(user, acct);
    when(_acctMgr.getSystemAccount()).thenReturn(this.acct);
    when(_acctMgr.getSystemUser()).thenReturn(this.user);
}
Also used : UserVO(com.cloud.user.UserVO) AccountVO(com.cloud.user.AccountVO) 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