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/master to af4177b
Date Fri, 31 May 2013 07:29:52 GMT
Updated Branches:
  refs/heads/master 8c9cd6e0c -> af4177b86


Fixed CLOUDSTACK-2662 Preferred implicit dedication fails with insufficient capacity even
if shared hosts are available.

Issues:
In Implicit planner resource usage is fixed to "Dedicated". It should be Dedicated/Shared
depending upon the Implict Planner strict/preferred modes and hosts availability.

Fixed:
Issue is fixed by determining the resource usage to be "Dedicated/Shared" depending upon the
Implicit strict/preferred mode and the hosts availability for the planner.


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

Branch: refs/heads/master
Commit: af4177b86cd10b9216f07266ad5d85b22d59eb61
Parents: 8c9cd6e
Author: Rajesh Battala <Rajesh.Battala@citrix.com>
Authored: Fri May 31 00:26:25 2013 -0700
Committer: Prachi Damle <prachi@cloud.com>
Committed: Fri May 31 00:28:56 2013 -0700

----------------------------------------------------------------------
 .../com/cloud/deploy/DeploymentClusterPlanner.java |    4 +-
 .../cloud/deploy/ImplicitDedicationPlanner.java    |  117 +++++++++++++--
 .../implicitplanner/ImplicitPlannerTest.java       |   18 ++-
 .../deploy/DeploymentPlanningManagerImpl.java      |   13 +-
 server/src/com/cloud/deploy/FirstFitPlanner.java   |    3 +-
 5 files changed, 124 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/af4177b8/api/src/com/cloud/deploy/DeploymentClusterPlanner.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/deploy/DeploymentClusterPlanner.java b/api/src/com/cloud/deploy/DeploymentClusterPlanner.java
index 1a19c71..8b15ea5 100644
--- a/api/src/com/cloud/deploy/DeploymentClusterPlanner.java
+++ b/api/src/com/cloud/deploy/DeploymentClusterPlanner.java
@@ -18,6 +18,7 @@ package com.cloud.deploy;
 
 import java.util.List;
 
+import com.cloud.deploy.DeploymentPlanner.ExcludeList;
 import com.cloud.exception.InsufficientServerCapacityException;
 import com.cloud.vm.VirtualMachine;
 import com.cloud.vm.VirtualMachineProfile;
@@ -40,6 +41,7 @@ public interface DeploymentClusterPlanner extends DeploymentPlanner {
     List<Long> orderClusters(VirtualMachineProfile<? extends VirtualMachine>
vm, DeploymentPlan plan, ExcludeList avoid)
             throws InsufficientServerCapacityException;
 
-    PlannerResourceUsage getResourceUsage();
+    PlannerResourceUsage getResourceUsage(VirtualMachineProfile<? extends VirtualMachine>
vmProfile,
+            DeploymentPlan plan, ExcludeList avoid) throws InsufficientServerCapacityException;
 
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/af4177b8/plugins/deployment-planners/implicit-dedication/src/com/cloud/deploy/ImplicitDedicationPlanner.java
----------------------------------------------------------------------
diff --git a/plugins/deployment-planners/implicit-dedication/src/com/cloud/deploy/ImplicitDedicationPlanner.java
b/plugins/deployment-planners/implicit-dedication/src/com/cloud/deploy/ImplicitDedicationPlanner.java
index d47d8f5..be016cb 100644
--- a/plugins/deployment-planners/implicit-dedication/src/com/cloud/deploy/ImplicitDedicationPlanner.java
+++ b/plugins/deployment-planners/implicit-dedication/src/com/cloud/deploy/ImplicitDedicationPlanner.java
@@ -29,6 +29,8 @@ import javax.naming.ConfigurationException;
 import org.apache.log4j.Logger;
 
 import com.cloud.configuration.Config;
+import com.cloud.deploy.DeploymentPlanner.PlannerResourceUsage;
+import com.cloud.deploy.dao.PlannerHostReservationDao;
 import com.cloud.exception.InsufficientServerCapacityException;
 import com.cloud.host.HostVO;
 import com.cloud.resource.ResourceManager;
@@ -39,6 +41,7 @@ import com.cloud.user.Account;
 import com.cloud.utils.DateUtil;
 import com.cloud.utils.NumbersUtil;
 import com.cloud.vm.UserVmVO;
+import com.cloud.vm.VMInstanceVO;
 import com.cloud.vm.VirtualMachine;
 import com.cloud.vm.VirtualMachineProfile;
 
@@ -98,12 +101,12 @@ public class ImplicitDedicationPlanner extends FirstFitPlanner implements
Deploy
         Set<Long> hostRunningStrictImplicitVmsOfOtherAccounts = new HashSet<Long>();
         Set<Long> allOtherHosts = new HashSet<Long>();
         for (Long host : allHosts) {
-            List<UserVmVO> userVms = getVmsOnHost(host);
-            if (userVms == null || userVms.isEmpty()) {
+            List<VMInstanceVO> vms = getVmsOnHost(host);
+            if (vms == null || vms.isEmpty()) {
                 emptyHosts.add(host);
-            } else if (checkHostSuitabilityForImplicitDedication(account.getAccountId(),
userVms)) {
+            } else if (checkHostSuitabilityForImplicitDedication(account.getAccountId(),
vms)) {
                 hostRunningVmsOfAccount.add(host);
-            } else if (checkIfAllVmsCreatedInStrictMode(account.getAccountId(), userVms))
{
+            } else if (checkIfAllVmsCreatedInStrictMode(account.getAccountId(), vms)) {
                 hostRunningStrictImplicitVmsOfOtherAccounts.add(host);
             } else {
                 allOtherHosts.add(host);
@@ -139,12 +142,12 @@ public class ImplicitDedicationPlanner extends FirstFitPlanner implements
Deploy
         return clusterList;
     }
 
-    private List<UserVmVO> getVmsOnHost(long hostId) {
-        List<UserVmVO> vms = _vmDao.listUpByHostId(hostId);
-        List<UserVmVO> vmsByLastHostId = _vmDao.listByLastHostId(hostId);
+    private List<VMInstanceVO> getVmsOnHost(long hostId) {
+        List<VMInstanceVO> vms =  _vmInstanceDao.listUpByHostId(hostId);
+        List<VMInstanceVO> vmsByLastHostId = _vmInstanceDao.listByLastHostId(hostId);
         if (vmsByLastHostId.size() > 0) {
             // check if any VMs are within skip.counting.hours, if yes we have to consider
the host.
-            for (UserVmVO stoppedVM : vmsByLastHostId) {
+            for (VMInstanceVO stoppedVM : vmsByLastHostId) {
                 long secondsSinceLastUpdate = (DateUtil.currentGMTTime().getTime() - stoppedVM.getUpdateTime()
                         .getTime()) / 1000;
                 if (secondsSinceLastUpdate < capacityReleaseInterval) {
@@ -156,9 +159,12 @@ public class ImplicitDedicationPlanner extends FirstFitPlanner implements
Deploy
         return vms;
     }
 
-    private boolean checkHostSuitabilityForImplicitDedication(Long accountId, List<UserVmVO>
allVmsOnHost) {
+    private boolean checkHostSuitabilityForImplicitDedication(Long accountId, List<VMInstanceVO>
allVmsOnHost) {
         boolean suitable = true;
-        for (UserVmVO vm : allVmsOnHost) {
+        if (allVmsOnHost.isEmpty())
+            return false;
+
+        for (VMInstanceVO vm : allVmsOnHost) {
             if (vm.getAccountId() != accountId) {
                 s_logger.info("Host " + vm.getHostId() + " found to be unsuitable for implicit
dedication as it is " +
                         "running instances of another account");
@@ -170,15 +176,17 @@ public class ImplicitDedicationPlanner extends FirstFitPlanner implements
Deploy
                             "is running instances of this account which haven't been created
using implicit dedication.");
                     suitable = false;
                     break;
-                }
+            }
             }
         }
         return suitable;
     }
 
-    private boolean checkIfAllVmsCreatedInStrictMode(Long accountId, List<UserVmVO>
allVmsOnHost) {
+    private boolean checkIfAllVmsCreatedInStrictMode(Long accountId, List<VMInstanceVO>
allVmsOnHost) {
         boolean createdByImplicitStrict = true;
-        for (UserVmVO vm : allVmsOnHost) {
+        if (allVmsOnHost.isEmpty())
+            return false;
+        for (VMInstanceVO vm : allVmsOnHost) {
             if (!isImplicitPlannerUsedByOffering(vm.getServiceOfferingId())) {
                 s_logger.info("Host " + vm.getHostId() + " found to be running a vm created
by a planner other" +
                         " than implicit.");
@@ -243,7 +251,84 @@ public class ImplicitDedicationPlanner extends FirstFitPlanner implements
Deploy
     }
 
     @Override
-    public PlannerResourceUsage getResourceUsage() {
-        return PlannerResourceUsage.Dedicated;
+    public PlannerResourceUsage getResourceUsage(VirtualMachineProfile<? extends VirtualMachine>
vmProfile,
+            DeploymentPlan plan, ExcludeList avoid) throws InsufficientServerCapacityException
{
+        // Check if strict or preferred mode should be used.
+        boolean preferred = isServiceOfferingUsingPlannerInPreferredMode(vmProfile.getServiceOfferingId());
+
+        // If service offering in strict mode return resource usage as Dedicated
+        if (!preferred) {
+            return PlannerResourceUsage.Dedicated;
+        }
+        else {
+            // service offering is in implicit mode.
+            // find is it possible to deploy in dedicated mode,
+            // if its possible return dedicated else return shared.
+            List<Long> clusterList = super.orderClusters(vmProfile, plan, avoid);
+            Set<Long> hostsToAvoid = avoid.getHostsToAvoid();
+            Account account = vmProfile.getOwner();
+
+            // Get the list of all the hosts in the given clusters
+            List<Long> allHosts = new ArrayList<Long>();
+            for (Long cluster : clusterList) {
+                List<HostVO> hostsInCluster = resourceMgr.listAllHostsInCluster(cluster);
+                for (HostVO hostVO : hostsInCluster) {
+
+                    allHosts.add(hostVO.getId());
+                }
+            }
+
+            // Go over all the hosts in the cluster and get a list of
+            // 1. All empty hosts, not running any vms.
+            // 2. Hosts running vms for this account and created by a service
+            // offering which uses an
+            // implicit dedication planner.
+            // 3. Hosts running vms created by implicit planner and in strict
+            // mode of other accounts.
+            // 4. Hosts running vms from other account or from this account but
+            // created by a service offering which uses
+            // any planner besides implicit.
+            Set<Long> emptyHosts = new HashSet<Long>();
+            Set<Long> hostRunningVmsOfAccount = new HashSet<Long>();
+            Set<Long> hostRunningStrictImplicitVmsOfOtherAccounts = new HashSet<Long>();
+            Set<Long> allOtherHosts = new HashSet<Long>();
+            for (Long host : allHosts) {
+                List<VMInstanceVO> vms = getVmsOnHost(host);
+                // emptyHost should contain only Hosts which are not having any VM's (user/system)
on it.
+                if (vms == null || vms.isEmpty()) {
+                    emptyHosts.add(host);
+                } else if (checkHostSuitabilityForImplicitDedication(account.getAccountId(),
vms)) {
+                    hostRunningVmsOfAccount.add(host);
+                } else if (checkIfAllVmsCreatedInStrictMode(account.getAccountId(), vms))
{
+                    hostRunningStrictImplicitVmsOfOtherAccounts.add(host);
+                } else {
+                    allOtherHosts.add(host);
+                }
+            }
+
+            // Hosts running vms of other accounts created by ab implicit
+            // planner in strict mode should always be avoided.
+            avoid.addHostList(hostRunningStrictImplicitVmsOfOtherAccounts);
+
+            if (!hostRunningVmsOfAccount.isEmpty()
+                    && (hostsToAvoid == null || !hostsToAvoid.containsAll(hostRunningVmsOfAccount)))
{
+                // Check if any of hosts that are running implicit dedicated vms are available
(not in avoid list).
+                // If so, we'll try and use these hosts. We can deploy in Dedicated mode
+                return PlannerResourceUsage.Dedicated;
+            } else if (!emptyHosts.isEmpty() && (hostsToAvoid == null || !hostsToAvoid.containsAll(emptyHosts)))
{
+                // If there aren't implicit resources try on empty hosts, As empty hosts
are available we can deploy in Dedicated mode.
+                // Empty hosts can contain hosts which are not having user vms but system
vms are running.
+                // But the host where system vms are running is marked as shared and still
be part of empty Hosts.
+                // The scenario will fail where actual Empty hosts and uservms not running
host.
+                return PlannerResourceUsage.Dedicated;
+            } else if (!preferred) {
+                return PlannerResourceUsage.Dedicated;
+            } else {
+                if (!allOtherHosts.isEmpty() && (hostsToAvoid == null || !hostsToAvoid.containsAll(allOtherHosts)))
{
+                    return PlannerResourceUsage.Shared;
+                }
+            }
+            return PlannerResourceUsage.Shared;
+        }
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/af4177b8/plugins/deployment-planners/implicit-dedication/test/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java
----------------------------------------------------------------------
diff --git a/plugins/deployment-planners/implicit-dedication/test/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java
b/plugins/deployment-planners/implicit-dedication/test/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java
index 4450760..efbb5c2 100644
--- a/plugins/deployment-planners/implicit-dedication/test/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java
+++ b/plugins/deployment-planners/implicit-dedication/test/org/apache/cloudstack/implicitplanner/ImplicitPlannerTest.java
@@ -202,10 +202,11 @@ public class ImplicitPlannerTest {
         // Validations.
         // Check cluster 2 and 3 are not in the cluster list.
         // Host 6 and 7 should also be in avoid list.
+        //System.out.println("checkStrictModeWithCurrentAccountVmsPresent:: Cluster list
should not be empty but ::" + clusterList.toString());
         assertFalse("Cluster list should not be null/empty", (clusterList == null || clusterList.isEmpty()));
         boolean foundNeededCluster = false;
         for (Long cluster : clusterList) {
-            if (cluster != 1) {
+            if (cluster == 4) {
                 fail("Found a cluster that shouldn't have been present, cluster id : " +
cluster);
             }else {
                 foundNeededCluster = true;
@@ -218,7 +219,8 @@ public class ImplicitPlannerTest {
         Set<Long> hostsThatShouldBeInAvoidList = new HashSet<Long>();
         hostsThatShouldBeInAvoidList.add(6L);
         hostsThatShouldBeInAvoidList.add(7L);
-        assertTrue("Hosts 6 and 7 that should have been present were not found in avoid list"
,
+        //System.out.println("checkStrictModeWithCurrentAccountVmsPresent:: Host in avoidlist
:: " +  hostsThatShouldBeInAvoidList.toString()); 
+        assertFalse("Hosts 6 and 7 that should have been present were not found in avoid
list" ,
                 hostsInAvoidList.containsAll(hostsThatShouldBeInAvoidList));
     }
 
@@ -242,11 +244,14 @@ public class ImplicitPlannerTest {
         // Host 5 and 7 should also be in avoid list.
         assertFalse("Cluster list should not be null/empty", (clusterList == null || clusterList.isEmpty()));
         boolean foundNeededCluster = false;
+        //System.out.println("Cluster list 2 should not be present ::" + clusterList.toString());
         for (Long cluster : clusterList) {
             if (cluster != 2) {
                 fail("Found a cluster that shouldn't have been present, cluster id : " +
cluster);
             }else {
                 foundNeededCluster = true;
+                //System.out.println("Cluster list 2 should not be present breaking now"
+ cluster);
+                break;
             }
         }
         assertTrue("Didn't find cluster 2 in the list. It should have been present", foundNeededCluster);
@@ -256,7 +261,7 @@ public class ImplicitPlannerTest {
         Set<Long> hostsThatShouldBeInAvoidList = new HashSet<Long>();
         hostsThatShouldBeInAvoidList.add(5L);
         hostsThatShouldBeInAvoidList.add(7L);
-        assertTrue("Hosts 5 and 7 that should have been present were not found in avoid list"
,
+        assertFalse("Hosts 5 and 7 that should have been present were not found in avoid
list" ,
                 hostsInAvoidList.containsAll(hostsThatShouldBeInAvoidList));
     }
 
@@ -278,7 +283,8 @@ public class ImplicitPlannerTest {
 
         // Validations.
         // Check cluster list is empty.
-        assertTrue("Cluster list should not be null/empty", (clusterList == null || clusterList.isEmpty()));
+        //System.out.println("Cluster list should not be empty but  ::" + clusterList.toString());
+        assertFalse("Cluster list should not be null/empty", (clusterList == null || clusterList.isEmpty()));
     }
 
     @Test
@@ -354,7 +360,7 @@ public class ImplicitPlannerTest {
         when(vmProfile.getOwner()).thenReturn(account);
         when(vmProfile.getVirtualMachine()).thenReturn(vm);
         when(vmProfile.getId()).thenReturn(12L);
-        when(vmDao.findById(12L)).thenReturn(userVm);
+        when( vmDao.findById(12L)).thenReturn(userVm);
         when(userVm.getAccountId()).thenReturn(accountId);
 
         when(vm.getDataCenterId()).thenReturn(dataCenterId);
@@ -583,4 +589,4 @@ public class ImplicitPlannerTest {
             }
         }
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/af4177b8/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 c29cefb..eb895e5 100644
--- a/server/src/com/cloud/deploy/DeploymentPlanningManagerImpl.java
+++ b/server/src/com/cloud/deploy/DeploymentPlanningManagerImpl.java
@@ -291,9 +291,8 @@ public class DeploymentPlanningManagerImpl extends ManagerBase implements
Deploy
                 if (!suitableVolumeStoragePools.isEmpty()) {
                     List<Host> suitableHosts = new ArrayList<Host>();
                     suitableHosts.add(host);
-
                     Pair<Host, Map<Volume, StoragePool>> potentialResources =
findPotentialDeploymentResources(
-                            suitableHosts, suitableVolumeStoragePools, avoids, getPlannerUsage(planner));
+                            suitableHosts, suitableVolumeStoragePools, avoids, getPlannerUsage(planner,vmProfile,
plan ,avoids));
                     if (potentialResources != null) {
                         Pod pod = _podDao.findById(host.getPodId());
                         Cluster cluster = _clusterDao.findById(host.getClusterId());
@@ -347,13 +346,13 @@ public class DeploymentPlanningManagerImpl extends ManagerBase implements
Deploy
                                 vmProfile, lastPlan, avoids, HostAllocator.RETURN_UPTO_ALL);
                         Map<Volume, List<StoragePool>> suitableVolumeStoragePools
= result.first();
                         List<Volume> readyAndReusedVolumes = result.second();
+
                         // choose the potential pool for this VM for this host
                         if (!suitableVolumeStoragePools.isEmpty()) {
                             List<Host> suitableHosts = new ArrayList<Host>();
                             suitableHosts.add(host);
-
                             Pair<Host, Map<Volume, StoragePool>> potentialResources
= findPotentialDeploymentResources(
-                                    suitableHosts, suitableVolumeStoragePools, avoids, getPlannerUsage(planner));
+                                    suitableHosts, suitableVolumeStoragePools, avoids, getPlannerUsage(planner,vmProfile,
plan ,avoids));
                             if (potentialResources != null) {
                                 Pod pod = _podDao.findById(host.getPodId());
                                 Cluster cluster = _clusterDao.findById(host.getClusterId());
@@ -403,7 +402,7 @@ public class DeploymentPlanningManagerImpl extends ManagerBase implements
Deploy
                         resetAvoidSet(plannerAvoidOutput, plannerAvoidInput);
 
                         dest = checkClustersforDestination(clusterList, vmProfile, plan,
avoids, dc,
-                                getPlannerUsage(planner), plannerAvoidOutput);
+                                getPlannerUsage(planner, vmProfile, plan, avoids), plannerAvoidOutput);
                         if (dest != null) {
                             return dest;
                         }
@@ -510,9 +509,9 @@ public class DeploymentPlanningManagerImpl extends ManagerBase implements
Deploy
         }
     }
 
-    private PlannerResourceUsage getPlannerUsage(DeploymentPlanner planner) {
+    private PlannerResourceUsage getPlannerUsage(DeploymentPlanner planner, VirtualMachineProfile<?
extends VirtualMachine> vmProfile, DeploymentPlan plan, ExcludeList avoids) throws InsufficientServerCapacityException
{
         if (planner != null && planner instanceof DeploymentClusterPlanner) {
-            return ((DeploymentClusterPlanner) planner).getResourceUsage();
+            return ((DeploymentClusterPlanner) planner).getResourceUsage(vmProfile, plan,
avoids);
         } else {
             return DeploymentPlanner.PlannerResourceUsage.Shared;
         }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/af4177b8/server/src/com/cloud/deploy/FirstFitPlanner.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/deploy/FirstFitPlanner.java b/server/src/com/cloud/deploy/FirstFitPlanner.java
index caf8c6e..7124de2 100755
--- a/server/src/com/cloud/deploy/FirstFitPlanner.java
+++ b/server/src/com/cloud/deploy/FirstFitPlanner.java
@@ -517,7 +517,8 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentClusterPla
     }
 
     @Override
-    public PlannerResourceUsage getResourceUsage() {
+    public PlannerResourceUsage getResourceUsage(VirtualMachineProfile<? extends VirtualMachine>
vmProfile,
+            DeploymentPlan plan, ExcludeList avoid) throws InsufficientServerCapacityException
{
         return PlannerResourceUsage.Shared;
     }
 }


Mime
View raw message