cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From prachida...@apache.org
Subject git commit: updated refs/heads/planner_reserve to d45422b
Date Fri, 10 May 2013 00:03:48 GMT
Updated Branches:
  refs/heads/planner_reserve fb1822393 -> d45422b99


Added some unit tests for DeploymentPlanningManagerImpl


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/d45422b9
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/d45422b9
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/d45422b9

Branch: refs/heads/planner_reserve
Commit: d45422b99e2e867a71b0e3da2c9d81adcd19bfc6
Parents: fb18223
Author: Prachi Damle <prachi@cloud.com>
Authored: Thu May 9 16:58:48 2013 -0700
Committer: Prachi Damle <prachi@cloud.com>
Committed: Thu May 9 16:58:48 2013 -0700

----------------------------------------------------------------------
 .../deploy/DeploymentPlanningManagerImpl.java      |   14 +-
 .../vm/DeploymentPlanningManagerImplTest.java      |  343 +++++++++++++++
 2 files changed, 353 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d45422b9/server/src/com/cloud/deploy/DeploymentPlanningManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/deploy/DeploymentPlanningManagerImpl.java b/server/src/com/cloud/deploy/DeploymentPlanningManagerImpl.java
index 5af17d2..b64148d 100644
--- a/server/src/com/cloud/deploy/DeploymentPlanningManagerImpl.java
+++ b/server/src/com/cloud/deploy/DeploymentPlanningManagerImpl.java
@@ -50,6 +50,7 @@ import com.cloud.configuration.Config;
 import com.cloud.configuration.dao.ConfigurationDao;
 import com.cloud.dc.ClusterDetailsDao;
 import com.cloud.dc.ClusterDetailsVO;
+import com.cloud.dc.ClusterVO;
 import com.cloud.dc.DataCenter;
 import com.cloud.dc.DataCenterVO;
 import com.cloud.dc.Pod;
@@ -86,7 +87,6 @@ import com.cloud.user.AccountManager;
 import com.cloud.utils.DateUtil;
 import com.cloud.utils.NumbersUtil;
 import com.cloud.utils.Pair;
-import com.cloud.utils.component.ComponentContext;
 import com.cloud.utils.component.Manager;
 import com.cloud.utils.component.ManagerBase;
 import com.cloud.utils.db.DB;
@@ -225,7 +225,13 @@ public class DeploymentPlanningManagerImpl extends ManagerBase implements
Deploy
         if (plannerName == null) {
             plannerName = _configDao.getValue(Config.VmDeploymentPlanner.key());
         }
-        DeploymentPlanner planner = ComponentContext.getComponent(plannerName);
+        DeploymentPlanner planner = null;
+        for (DeploymentPlanner plannerInList : _planners) {
+            if (plannerName.equals(plannerInList.getName())) {
+                planner = plannerInList;
+                break;
+            }
+        }
 
         int cpu_requested = offering.getCpu() * offering.getSpeed();
         long ram_requested = offering.getRamSize() * 1024L * 1024L;
@@ -439,7 +445,7 @@ public class DeploymentPlanningManagerImpl extends ManagerBase implements
Deploy
     }
 
     private PlannerResourceUsage getPlannerUsage(DeploymentPlanner planner) {
-        if (planner instanceof DeploymentClusterPlanner) {
+        if (planner != null && planner instanceof DeploymentClusterPlanner) {
             return ((DeploymentClusterPlanner) planner).getResourceUsage();
         } else {
             return DeploymentPlanner.PlannerResourceUsage.Shared;
@@ -733,7 +739,7 @@ public class DeploymentPlanningManagerImpl extends ManagerBase implements
Deploy
         }
 
         for (Long clusterId : clusterList) {
-            Cluster clusterVO = _clusterDao.findById(clusterId);
+            ClusterVO clusterVO = _clusterDao.findById(clusterId);
 
             if (clusterVO.getHypervisorType() != vmProfile.getHypervisorType()) {
                 s_logger.debug("Cluster: " + clusterId

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d45422b9/server/test/com/cloud/vm/DeploymentPlanningManagerImplTest.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/vm/DeploymentPlanningManagerImplTest.java b/server/test/com/cloud/vm/DeploymentPlanningManagerImplTest.java
new file mode 100644
index 0000000..2e055c8
--- /dev/null
+++ b/server/test/com/cloud/vm/DeploymentPlanningManagerImplTest.java
@@ -0,0 +1,343 @@
+package com.cloud.vm;
+
+import static org.junit.Assert.*;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import javax.inject.Inject;
+import javax.naming.ConfigurationException;
+
+import com.cloud.service.ServiceOfferingVO;
+import com.cloud.storage.StorageManager;
+import com.cloud.storage.dao.DiskOfferingDao;
+import com.cloud.storage.dao.GuestOSCategoryDao;
+import com.cloud.storage.dao.GuestOSDao;
+import com.cloud.storage.dao.StoragePoolHostDao;
+import com.cloud.storage.dao.VolumeDao;
+import com.cloud.capacity.CapacityManager;
+import com.cloud.capacity.dao.CapacityDao;
+import com.cloud.configuration.dao.ConfigurationDao;
+import com.cloud.deploy.DeploymentPlanner.ExcludeList;
+import com.cloud.agent.AgentManager;
+import com.cloud.dc.ClusterDetailsDao;
+import com.cloud.dc.ClusterVO;
+import com.cloud.dc.DataCenterVO;
+import com.cloud.dc.dao.ClusterDao;
+import com.cloud.dc.dao.DataCenterDao;
+import com.cloud.dc.dao.HostPodDao;
+import com.cloud.deploy.DataCenterDeployment;
+import com.cloud.deploy.DeployDestination;
+import com.cloud.deploy.DeploymentClusterPlanner;
+import com.cloud.deploy.DeploymentPlanner;
+import com.cloud.deploy.DeploymentPlanner.PlannerResourceUsage;
+import com.cloud.deploy.DeploymentPlanningManagerImpl;
+import com.cloud.deploy.FirstFitPlanner;
+import com.cloud.deploy.PlannerHostReservationVO;
+import com.cloud.deploy.dao.PlannerHostReservationDao;
+import org.apache.cloudstack.affinity.AffinityGroupProcessor;
+import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
+import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
+import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
+import org.apache.cloudstack.framework.messagebus.MessageBus;
+import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
+import org.apache.cloudstack.test.utils.SpringUtils;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.FilterType;
+import org.springframework.context.annotation.ComponentScan.Filter;
+import org.springframework.core.type.classreading.MetadataReader;
+import org.springframework.core.type.classreading.MetadataReaderFactory;
+import org.springframework.core.type.filter.TypeFilter;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.support.AnnotationConfigContextLoader;
+
+import com.cloud.exception.AffinityConflictException;
+import com.cloud.exception.InsufficientServerCapacityException;
+import com.cloud.host.dao.HostDao;
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.user.AccountManager;
+import com.cloud.utils.component.ComponentContext;
+import com.cloud.vm.dao.UserVmDao;
+import com.cloud.vm.dao.VMInstanceDao;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(loader = AnnotationConfigContextLoader.class)
+public class DeploymentPlanningManagerImplTest {
+
+    @Inject
+    DeploymentPlanningManagerImpl _dpm;
+
+    @Inject
+    PlannerHostReservationDao _plannerHostReserveDao;
+
+    @Inject VirtualMachineProfileImpl vmProfile;
+
+    @Inject
+    AffinityGroupVMMapDao _affinityGroupVMMapDao;
+
+    @Inject
+    ExcludeList avoids;
+
+    @Inject
+    DataCenterVO dc;
+
+    @Inject
+    DataCenterDao _dcDao;
+
+    @Inject
+    FirstFitPlanner _planner;
+
+    @Inject
+    ClusterDao _clusterDao;
+
+    private static long domainId = 5L;
+
+    private static long dataCenterId = 1L;
+
+
+    @BeforeClass
+    public static void setUp() throws ConfigurationException {
+    }
+
+    @Before
+    public void testSetUp() {
+        ComponentContext.initComponentsLifeCycle();
+
+        PlannerHostReservationVO reservationVO = new PlannerHostReservationVO(200L, 1L, 2L,
3L, PlannerResourceUsage.Shared);
+        Mockito.when(_plannerHostReserveDao.persist(Mockito.any(PlannerHostReservationVO.class))).thenReturn(reservationVO);
+        Mockito.when(_plannerHostReserveDao.findById(Mockito.anyLong())).thenReturn(reservationVO);
+        Mockito.when(_affinityGroupVMMapDao.countAffinityGroupsForVm(Mockito.anyLong())).thenReturn(0L);
+
+        VMInstanceVO vm = new VMInstanceVO();
+        Mockito.when(vmProfile.getVirtualMachine()).thenReturn(vm);
+
+        Mockito.when(_dcDao.findById(Mockito.anyLong())).thenReturn(dc);
+        Mockito.when(dc.getId()).thenReturn(dataCenterId);
+
+        ClusterVO clusterVO = new ClusterVO();
+        clusterVO.setHypervisorType(HypervisorType.XenServer.toString());
+        Mockito.when(_clusterDao.findById(Mockito.anyLong())).thenReturn(clusterVO);
+
+        Mockito.when(_planner.getName()).thenReturn("FirstFitPlanner");
+        List<DeploymentPlanner> planners = new ArrayList<DeploymentPlanner>();
+        planners.add(_planner);
+        _dpm.setPlanners(planners);
+
+    }
+
+    @Test
+    public void dataCenterAvoidTest() throws InsufficientServerCapacityException, AffinityConflictException
{
+        ServiceOfferingVO svcOffering = new ServiceOfferingVO("testOffering", 1, 512, 500,
1, 1, false, false, false,
+                "test dpm", false, false, null, false, VirtualMachine.Type.User, domainId,
null, "FirstFitPlanner");
+        Mockito.when(vmProfile.getServiceOffering()).thenReturn(svcOffering);
+
+        DataCenterDeployment plan = new DataCenterDeployment(dataCenterId);
+
+        Mockito.when(avoids.shouldAvoid((DataCenterVO) Mockito.anyObject())).thenReturn(true);
+        DeployDestination dest = _dpm.planDeployment(vmProfile, plan, avoids);
+        assertNull("DataCenter is in avoid set, destination should be null! ", dest);
+    }
+
+    @Test
+    public void plannerCannotHandleTest() throws InsufficientServerCapacityException, AffinityConflictException
{
+        ServiceOfferingVO svcOffering = new ServiceOfferingVO("testOffering", 1, 512, 500,
1, 1, false, false, false,
+                "test dpm", false, false, null, false, VirtualMachine.Type.User, domainId,
null,
+                "UserDispersingPlanner");
+        Mockito.when(vmProfile.getServiceOffering()).thenReturn(svcOffering);
+
+        DataCenterDeployment plan = new DataCenterDeployment(dataCenterId);
+        Mockito.when(avoids.shouldAvoid((DataCenterVO) Mockito.anyObject())).thenReturn(false);
+
+        Mockito.when(_planner.canHandle(vmProfile, plan, avoids)).thenReturn(false);
+        DeployDestination dest = _dpm.planDeployment(vmProfile, plan, avoids);
+        assertNull("Planner cannot handle, destination should be null! ", dest);
+    }
+
+    @Test
+    public void emptyClusterListTest() throws InsufficientServerCapacityException, AffinityConflictException
{
+        ServiceOfferingVO svcOffering = new ServiceOfferingVO("testOffering", 1, 512, 500,
1, 1, false, false, false,
+                "test dpm", false, false, null, false, VirtualMachine.Type.User, domainId,
null, "FirstFitPlanner");
+        Mockito.when(vmProfile.getServiceOffering()).thenReturn(svcOffering);
+
+        DataCenterDeployment plan = new DataCenterDeployment(dataCenterId);
+        Mockito.when(avoids.shouldAvoid((DataCenterVO) Mockito.anyObject())).thenReturn(false);
+        Mockito.when(_planner.canHandle(vmProfile, plan, avoids)).thenReturn(true);
+
+        Mockito.when(((DeploymentClusterPlanner) _planner).orderClusters(vmProfile, plan,
avoids)).thenReturn(null);
+        DeployDestination dest = _dpm.planDeployment(vmProfile, plan, avoids);
+        assertNull("Planner cannot handle, destination should be null! ", dest);
+    }
+
+
+    @Configuration
+    @ComponentScan(basePackageClasses = { DeploymentPlanningManagerImpl.class }, includeFilters
= { @Filter(value = TestConfiguration.Library.class, type = FilterType.CUSTOM) }, useDefaultFilters
= false)
+    public static class TestConfiguration extends SpringUtils.CloudStackTestConfiguration
{
+
+        @Bean
+        public FirstFitPlanner firstFitPlanner() {
+            return Mockito.mock(FirstFitPlanner.class);
+        }
+
+        @Bean
+        public DeploymentPlanner deploymentPlanner() {
+            return Mockito.mock(DeploymentPlanner.class);
+        }
+
+        @Bean
+        public DataCenterVO dataCenter() {
+            return Mockito.mock(DataCenterVO.class);
+        }
+
+        @Bean
+        public ExcludeList excludeList() {
+            return Mockito.mock(ExcludeList.class);
+        }
+
+        @Bean
+        public VirtualMachineProfileImpl virtualMachineProfileImpl() {
+            return Mockito.mock(VirtualMachineProfileImpl.class);
+        }
+
+        @Bean
+        public ClusterDetailsDao clusterDetailsDao() {
+            return Mockito.mock(ClusterDetailsDao.class);
+        }
+
+        @Bean
+        public DataStoreManager cataStoreManager() {
+            return Mockito.mock(DataStoreManager.class);
+        }
+
+        @Bean
+        public StorageManager storageManager() {
+            return Mockito.mock(StorageManager.class);
+        }
+
+        @Bean
+        public HostDao hostDao() {
+            return Mockito.mock(HostDao.class);
+        }
+
+        @Bean
+        public HostPodDao hostPodDao() {
+            return Mockito.mock(HostPodDao.class);
+        }
+
+        @Bean
+        public ClusterDao clusterDao() {
+            return Mockito.mock(ClusterDao.class);
+        }
+
+        @Bean
+        public GuestOSDao guestOSDao() {
+            return Mockito.mock(GuestOSDao.class);
+        }
+
+        @Bean
+        public GuestOSCategoryDao guestOSCategoryDao() {
+            return Mockito.mock(GuestOSCategoryDao.class);
+        }
+
+        @Bean
+        public CapacityManager capacityManager() {
+            return Mockito.mock(CapacityManager.class);
+        }
+
+        @Bean
+        public StoragePoolHostDao storagePoolHostDao() {
+            return Mockito.mock(StoragePoolHostDao.class);
+        }
+
+        @Bean
+        public VolumeDao volumeDao() {
+            return Mockito.mock(VolumeDao.class);
+        }
+
+        @Bean
+        public ConfigurationDao configurationDao() {
+            return Mockito.mock(ConfigurationDao.class);
+        }
+
+        @Bean
+        public DiskOfferingDao diskOfferingDao() {
+            return Mockito.mock(DiskOfferingDao.class);
+        }
+
+        @Bean
+        public PrimaryDataStoreDao primaryDataStoreDao() {
+            return Mockito.mock(PrimaryDataStoreDao.class);
+        }
+
+        @Bean
+        public CapacityDao capacityDao() {
+            return Mockito.mock(CapacityDao.class);
+        }
+
+        @Bean
+        public PlannerHostReservationDao plannerHostReservationDao() {
+            return Mockito.mock(PlannerHostReservationDao.class);
+        }
+
+        @Bean
+        public AffinityGroupProcessor affinityGroupProcessor() {
+            return Mockito.mock(AffinityGroupProcessor.class);
+        }
+
+        @Bean
+        public AffinityGroupDao affinityGroupDao() {
+            return Mockito.mock(AffinityGroupDao.class);
+        }
+
+        @Bean
+        public AffinityGroupVMMapDao affinityGroupVMMapDao() {
+            return Mockito.mock(AffinityGroupVMMapDao.class);
+        }
+
+        @Bean
+        public AccountManager accountManager() {
+            return Mockito.mock(AccountManager.class);
+        }
+
+        @Bean
+        public AgentManager agentManager() {
+            return Mockito.mock(AgentManager.class);
+        }
+
+        @Bean
+        public MessageBus messageBus() {
+            return Mockito.mock(MessageBus.class);
+        }
+
+
+        @Bean
+        public UserVmDao userVMDao() {
+            return Mockito.mock(UserVmDao.class);
+        }
+
+        @Bean
+        public VMInstanceDao vmInstanceDao() {
+            return Mockito.mock(VMInstanceDao.class);
+        }
+
+        @Bean
+        public DataCenterDao dataCenterDao() {
+            return Mockito.mock(DataCenterDao.class);
+        }
+
+        public static class Library implements TypeFilter {
+
+            @Override
+            public boolean match(MetadataReader mdr, MetadataReaderFactory arg1) throws IOException
{
+                ComponentScan cs = TestConfiguration.class.getAnnotation(ComponentScan.class);
+                return SpringUtils.includedInBasePackageClasses(mdr.getClassMetadata().getClassName(),
cs);
+            }
+        }
+    }
+}


Mime
View raw message