Search in sources :

Example 61 with ServiceOfferingVO

use of com.cloud.service.ServiceOfferingVO in project cloudstack by apache.

the class FirstFitPlannerTest method initializeForTest.

private void initializeForTest(VirtualMachineProfileImpl vmProfile, DataCenterDeployment plan, ExcludeList avoids) {
    DataCenterVO mockDc = mock(DataCenterVO.class);
    VMInstanceVO vm = mock(VMInstanceVO.class);
    UserVmVO userVm = mock(UserVmVO.class);
    ServiceOfferingVO offering = mock(ServiceOfferingVO.class);
    AccountVO account = mock(AccountVO.class);
    when(account.getId()).thenReturn(accountId);
    when(account.getAccountId()).thenReturn(accountId);
    when(vmProfile.getOwner()).thenReturn(account);
    when(vmProfile.getVirtualMachine()).thenReturn(vm);
    when(vmProfile.getId()).thenReturn(12L);
    when(vmDao.findById(12L)).thenReturn(userVm);
    when(userVm.getAccountId()).thenReturn(accountId);
    when(vm.getDataCenterId()).thenReturn(dataCenterId);
    when(dcDao.findById(1L)).thenReturn(mockDc);
    when(avoids.shouldAvoid(mockDc)).thenReturn(false);
    when(plan.getDataCenterId()).thenReturn(dataCenterId);
    when(plan.getClusterId()).thenReturn(null);
    when(plan.getPodId()).thenReturn(null);
    // Mock offering details.
    when(vmProfile.getServiceOffering()).thenReturn(offering);
    when(offering.getId()).thenReturn(offeringId);
    when(vmProfile.getServiceOfferingId()).thenReturn(offeringId);
    when(offering.getCpu()).thenReturn(noOfCpusInOffering);
    when(offering.getSpeed()).thenReturn(cpuSpeedInOffering);
    when(offering.getRamSize()).thenReturn(ramInOffering);
    List<Long> clustersWithEnoughCapacity = new ArrayList<Long>();
    clustersWithEnoughCapacity.add(1L);
    clustersWithEnoughCapacity.add(2L);
    clustersWithEnoughCapacity.add(3L);
    clustersWithEnoughCapacity.add(4L);
    clustersWithEnoughCapacity.add(5L);
    clustersWithEnoughCapacity.add(6L);
    when(capacityDao.listClustersInZoneOrPodByHostCapacities(dataCenterId, noOfCpusInOffering * cpuSpeedInOffering, ramInOffering * 1024L * 1024L, Capacity.CAPACITY_TYPE_CPU, true)).thenReturn(clustersWithEnoughCapacity);
    Map<Long, Double> clusterCapacityMap = new HashMap<Long, Double>();
    clusterCapacityMap.put(1L, 2048D);
    clusterCapacityMap.put(2L, 2048D);
    clusterCapacityMap.put(3L, 2048D);
    clusterCapacityMap.put(4L, 2048D);
    clusterCapacityMap.put(5L, 2048D);
    clusterCapacityMap.put(6L, 2048D);
    Pair<List<Long>, Map<Long, Double>> clustersOrderedByCapacity = new Pair<List<Long>, Map<Long, Double>>(clustersWithEnoughCapacity, clusterCapacityMap);
    when(capacityDao.orderClustersByAggregateCapacity(dataCenterId, Capacity.CAPACITY_TYPE_CPU, true)).thenReturn(clustersOrderedByCapacity);
    List<Long> disabledClusters = new ArrayList<Long>();
    List<Long> clustersWithDisabledPods = new ArrayList<Long>();
    when(clusterDao.listDisabledClusters(dataCenterId, null)).thenReturn(disabledClusters);
    when(clusterDao.listClustersWithDisabledPods(dataCenterId)).thenReturn(clustersWithDisabledPods);
    List<Long> hostList0 = new ArrayList<Long>();
    List<Long> hostList1 = new ArrayList<Long>();
    List<Long> hostList2 = new ArrayList<Long>();
    List<Long> hostList3 = new ArrayList<Long>();
    List<Long> hostList4 = new ArrayList<Long>();
    List<Long> hostList5 = new ArrayList<Long>();
    List<Long> hostList6 = new ArrayList<Long>();
    hostList0.add(new Long(1));
    hostList1.add(new Long(10));
    hostList2.add(new Long(11));
    hostList3.add(new Long(12));
    hostList4.add(new Long(13));
    hostList5.add(new Long(14));
    hostList6.add(new Long(15));
    String[] implicitHostTags = { "GPU" };
    int ramInBytes = ramInOffering * 1024 * 1024;
    when(serviceOfferingDetailsDao.findDetail(Matchers.anyLong(), anyString())).thenReturn(null);
    when(hostGpuGroupsDao.listHostIds()).thenReturn(hostList0);
    when(capacityDao.listHostsWithEnoughCapacity(noOfCpusInOffering * cpuSpeedInOffering, ramInBytes, new Long(1), Host.Type.Routing.toString())).thenReturn(hostList1);
    when(capacityDao.listHostsWithEnoughCapacity(noOfCpusInOffering * cpuSpeedInOffering, ramInBytes, new Long(2), Host.Type.Routing.toString())).thenReturn(hostList2);
    when(capacityDao.listHostsWithEnoughCapacity(noOfCpusInOffering * cpuSpeedInOffering, ramInBytes, new Long(3), Host.Type.Routing.toString())).thenReturn(hostList3);
    when(capacityDao.listHostsWithEnoughCapacity(noOfCpusInOffering * cpuSpeedInOffering, ramInBytes, new Long(4), Host.Type.Routing.toString())).thenReturn(hostList4);
    when(capacityDao.listHostsWithEnoughCapacity(noOfCpusInOffering * cpuSpeedInOffering, ramInBytes, new Long(5), Host.Type.Routing.toString())).thenReturn(hostList5);
    when(capacityDao.listHostsWithEnoughCapacity(noOfCpusInOffering * cpuSpeedInOffering, ramInBytes, new Long(6), Host.Type.Routing.toString())).thenReturn(hostList6);
    when(hostTagsDao.getDistinctImplicitHostTags(hostList1, implicitHostTags)).thenReturn(Arrays.asList("abc", "pqr", "xyz"));
    when(hostTagsDao.getDistinctImplicitHostTags(hostList2, implicitHostTags)).thenReturn(Arrays.asList("abc", "123", "pqr", "456", "xyz"));
    when(hostTagsDao.getDistinctImplicitHostTags(hostList3, implicitHostTags)).thenReturn(Arrays.asList("abc", "pqr"));
    when(hostTagsDao.getDistinctImplicitHostTags(hostList4, implicitHostTags)).thenReturn(Arrays.asList("abc"));
    when(hostTagsDao.getDistinctImplicitHostTags(hostList5, implicitHostTags)).thenReturn(Arrays.asList("abc", "pqr", "xyz"));
    when(hostTagsDao.getDistinctImplicitHostTags(hostList6, implicitHostTags)).thenReturn(Arrays.asList("abc", "123", "pqr", "xyz"));
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) AccountVO(com.cloud.user.AccountVO) List(java.util.List) ArrayList(java.util.ArrayList) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) Map(java.util.Map) HashMap(java.util.HashMap) Pair(com.cloud.utils.Pair)

Example 62 with ServiceOfferingVO

use of com.cloud.service.ServiceOfferingVO in project cloudstack by apache.

the class AccountManagerImplVolumeDeleteEventTest method defineMocksBehavior.

protected void defineMocksBehavior() throws AgentUnavailableException, ConcurrentOperationException, CloudException {
    AccountVO account = new AccountVO();
    account.setId(ACCOUNT_ID);
    when(_accountDao.remove(ACCOUNT_ID)).thenReturn(true);
    when(_accountDao.findById(ACCOUNT_ID)).thenReturn(account);
    DomainVO domain = new DomainVO();
    VirtualMachineEntity vmEntity = mock(VirtualMachineEntity.class);
    when(_orchSrvc.getVirtualMachine(anyString())).thenReturn(vmEntity);
    when(vmEntity.destroy(anyString(), anyBoolean())).thenReturn(true);
    Mockito.doReturn(vm).when(_vmDao).findById(anyLong());
    VolumeVO vol = new VolumeVO(VOLUME_UUID, 1l, 1l, 1l, 1l, 1l, "folder", "path", null, 50, Type.ROOT);
    vol.setDisplayVolume(true);
    List<VolumeVO> volumes = new ArrayList<>();
    volumes.add(vol);
    when(securityChecker.checkAccess(any(Account.class), any(ControlledEntity.class), any(AccessType.class), anyString())).thenReturn(true);
    when(_userVmDao.findById(anyLong())).thenReturn(vm);
    when(_userVmDao.listByAccountId(ACCOUNT_ID)).thenReturn(Arrays.asList(vm));
    when(_userVmDao.findByUuid(any(String.class))).thenReturn(vm);
    when(_volumeDao.findByInstance(anyLong())).thenReturn(volumes);
    ServiceOfferingVO offering = mock(ServiceOfferingVO.class);
    when(offering.getCpu()).thenReturn(500);
    when(offering.getId()).thenReturn(1l);
    when(offering.getCpu()).thenReturn(500);
    when(offering.getRamSize()).thenReturn(500);
    when(_serviceOfferingDao.findByIdIncludingRemoved(anyLong(), anyLong())).thenReturn(offering);
    when(_domainMgr.getDomain(anyLong())).thenReturn(domain);
    Mockito.doReturn(true).when(_vmMgr).expunge(any(UserVmVO.class), anyLong(), any(Account.class));
}
Also used : DomainVO(com.cloud.domain.DomainVO) UserVmVO(com.cloud.vm.UserVmVO) VolumeVO(com.cloud.storage.VolumeVO) ControlledEntity(org.apache.cloudstack.acl.ControlledEntity) VirtualMachineEntity(org.apache.cloudstack.engine.cloud.entity.api.VirtualMachineEntity) ArrayList(java.util.ArrayList) Mockito.anyString(org.mockito.Mockito.anyString) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) AccessType(org.apache.cloudstack.acl.SecurityChecker.AccessType)

Example 63 with ServiceOfferingVO

use of com.cloud.service.ServiceOfferingVO in project cloudstack by apache.

the class UserVmManagerTest method getSvcoffering.

private ServiceOfferingVO getSvcoffering(int ramSize) {
    long id = 4L;
    String name = "name";
    String displayText = "displayText";
    int cpu = 1;
    //int ramSize = 256;
    int speed = 128;
    boolean ha = false;
    boolean useLocalStorage = false;
    ServiceOfferingVO serviceOffering = new ServiceOfferingVO(name, cpu, ramSize, speed, null, null, ha, displayText, Storage.ProvisioningType.THIN, useLocalStorage, false, null, false, null, false);
    return serviceOffering;
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO)

Example 64 with ServiceOfferingVO

use of com.cloud.service.ServiceOfferingVO in project cloudstack by apache.

the class RouterDeploymentDefinition method findDefaultServiceOfferingId.

protected void findDefaultServiceOfferingId() {
    ServiceOfferingVO serviceOffering = serviceOfferingDao.findDefaultSystemOffering(ServiceOffering.routerDefaultOffUniqueName, ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dest.getDataCenter().getId()));
    serviceOfferingId = serviceOffering.getId();
}
Also used : ServiceOfferingVO(com.cloud.service.ServiceOfferingVO)

Example 65 with ServiceOfferingVO

use of com.cloud.service.ServiceOfferingVO in project cloudstack by apache.

the class ImplicitPlannerTest method initializeForImplicitPlannerTest.

private void initializeForImplicitPlannerTest(boolean preferred) {
    String plannerMode = new String("Strict");
    if (preferred) {
        plannerMode = new String("Preferred");
    }
    Map<String, String> details = new HashMap<String, String>();
    details.put("ImplicitDedicationMode", plannerMode);
    when(serviceOfferingDetailsDao.listDetailsKeyPairs(offeringId)).thenReturn(details);
    // Initialize hosts in clusters
    HostVO host1 = mock(HostVO.class);
    when(host1.getId()).thenReturn(5L);
    HostVO host2 = mock(HostVO.class);
    when(host2.getId()).thenReturn(6L);
    HostVO host3 = mock(HostVO.class);
    when(host3.getId()).thenReturn(7L);
    List<HostVO> hostsInCluster1 = new ArrayList<HostVO>();
    List<HostVO> hostsInCluster2 = new ArrayList<HostVO>();
    List<HostVO> hostsInCluster3 = new ArrayList<HostVO>();
    hostsInCluster1.add(host1);
    hostsInCluster2.add(host2);
    hostsInCluster3.add(host3);
    when(resourceMgr.listAllHostsInCluster(1)).thenReturn(hostsInCluster1);
    when(resourceMgr.listAllHostsInCluster(2)).thenReturn(hostsInCluster2);
    when(resourceMgr.listAllHostsInCluster(3)).thenReturn(hostsInCluster3);
    // Mock vms on each host.
    long offeringIdForVmsOfThisAccount = 15L;
    long offeringIdForVmsOfOtherAccount = 16L;
    UserVmVO vm1 = mock(UserVmVO.class);
    when(vm1.getAccountId()).thenReturn(accountId);
    when(vm1.getServiceOfferingId()).thenReturn(offeringIdForVmsOfThisAccount);
    UserVmVO vm2 = mock(UserVmVO.class);
    when(vm2.getAccountId()).thenReturn(accountId);
    when(vm2.getServiceOfferingId()).thenReturn(offeringIdForVmsOfThisAccount);
    // Vm from different account
    UserVmVO vm3 = mock(UserVmVO.class);
    when(vm3.getAccountId()).thenReturn(201L);
    when(vm3.getServiceOfferingId()).thenReturn(offeringIdForVmsOfOtherAccount);
    List<VMInstanceVO> vmsForHost1 = new ArrayList<VMInstanceVO>();
    List<VMInstanceVO> vmsForHost2 = new ArrayList<VMInstanceVO>();
    List<VMInstanceVO> vmsForHost3 = new ArrayList<VMInstanceVO>();
    List<VMInstanceVO> stoppedVmsForHost = new ArrayList<VMInstanceVO>();
    // Host 2 is empty.
    vmsForHost1.add(vm1);
    vmsForHost1.add(vm2);
    vmsForHost3.add(vm3);
    when(vmInstanceDao.listUpByHostId(5L)).thenReturn(vmsForHost1);
    when(vmInstanceDao.listUpByHostId(6L)).thenReturn(vmsForHost2);
    when(vmInstanceDao.listUpByHostId(7L)).thenReturn(vmsForHost3);
    when(vmInstanceDao.listByLastHostId(5L)).thenReturn(stoppedVmsForHost);
    when(vmInstanceDao.listByLastHostId(6L)).thenReturn(stoppedVmsForHost);
    when(vmInstanceDao.listByLastHostId(7L)).thenReturn(stoppedVmsForHost);
    // Mock the offering with which the vm was created.
    ServiceOfferingVO offeringForVmOfThisAccount = mock(ServiceOfferingVO.class);
    when(serviceOfferingDao.findByIdIncludingRemoved(offeringIdForVmsOfThisAccount)).thenReturn(offeringForVmOfThisAccount);
    when(offeringForVmOfThisAccount.getDeploymentPlanner()).thenReturn(planner.getName());
    ServiceOfferingVO offeringForVMOfOtherAccount = mock(ServiceOfferingVO.class);
    when(serviceOfferingDao.findByIdIncludingRemoved(offeringIdForVmsOfOtherAccount)).thenReturn(offeringForVMOfOtherAccount);
    when(offeringForVMOfOtherAccount.getDeploymentPlanner()).thenReturn("FirstFitPlanner");
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) VMInstanceVO(com.cloud.vm.VMInstanceVO) Matchers.anyString(org.mockito.Matchers.anyString) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) HostVO(com.cloud.host.HostVO)

Aggregations

ServiceOfferingVO (com.cloud.service.ServiceOfferingVO)72 ArrayList (java.util.ArrayList)24 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)18 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)18 Account (com.cloud.user.Account)17 List (java.util.List)14 Network (com.cloud.network.Network)10 DB (com.cloud.utils.db.DB)10 VolumeVO (com.cloud.storage.VolumeVO)9 NicProfile (com.cloud.vm.NicProfile)9 VMInstanceVO (com.cloud.vm.VMInstanceVO)9 HashMap (java.util.HashMap)9 LinkedHashMap (java.util.LinkedHashMap)9 ConfigurationException (javax.naming.ConfigurationException)9 DataCenterDeployment (com.cloud.deploy.DataCenterDeployment)8 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)8 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)8 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)8 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)8 DomainRouterVO (com.cloud.vm.DomainRouterVO)8