1717package com .cloud .deploy ;
1818
1919import java .util .ArrayList ;
20- import java .util .Collections ;
21- import java .util .Comparator ;
2220import java .util .HashMap ;
2321import java .util .List ;
2422import java .util .Map ;
4644import com .cloud .dc .dao .DataCenterDao ;
4745import com .cloud .dc .dao .HostPodDao ;
4846import com .cloud .exception .InsufficientServerCapacityException ;
49- import com .cloud .gpu .GPU ;
50- import com .cloud .gpu .dao .HostGpuGroupsDao ;
51- import com .cloud .host .Host ;
5247import com .cloud .host .dao .HostDao ;
53- import com .cloud .host .dao .HostTagsDao ;
5448import com .cloud .hypervisor .Hypervisor .HypervisorType ;
5549import com .cloud .offering .ServiceOffering ;
56- import com .cloud .service .dao .ServiceOfferingDetailsDao ;
5750import com .cloud .storage .StorageManager ;
5851import com .cloud .storage .dao .DiskOfferingDao ;
5952import com .cloud .storage .dao .GuestOSCategoryDao ;
@@ -109,16 +102,9 @@ public class FirstFitPlanner extends PlannerBase implements DeploymentClusterPla
109102 DataStoreManager dataStoreMgr ;
110103 @ Inject
111104 protected ClusterDetailsDao _clusterDetailsDao ;
112- @ Inject
113- protected ServiceOfferingDetailsDao _serviceOfferingDetailsDao ;
114- @ Inject
115- protected HostGpuGroupsDao _hostGpuGroupsDao ;
116- @ Inject
117- protected HostTagsDao _hostTagsDao ;
118105
119106 protected String _allocationAlgorithm = "random" ;
120107 protected String _globalDeploymentPlanner = "FirstFitPlanner" ;
121- protected String [] _implicitHostTags ;
122108
123109 @ Override
124110 public List <Long > orderClusters (VirtualMachineProfile vmProfile , DeploymentPlan plan , ExcludeList avoid ) throws InsufficientServerCapacityException {
@@ -145,6 +131,7 @@ public List<Long> orderClusters(VirtualMachineProfile vmProfile, DeploymentPlan
145131 clusterList .add (clusterIdSpecified );
146132 removeClustersCrossingThreshold (clusterList , avoid , vmProfile , plan );
147133 }
134+ return clusterList ;
148135 } else {
149136 s_logger .debug ("The specified cluster cannot be found, returning." );
150137 avoid .addCluster (plan .getClusterId ());
@@ -165,6 +152,7 @@ public List<Long> orderClusters(VirtualMachineProfile vmProfile, DeploymentPlan
165152 avoid .addPod (plan .getPodId ());
166153 }
167154 }
155+ return clusterList ;
168156 } else {
169157 s_logger .debug ("The specified Pod cannot be found, returning." );
170158 avoid .addPod (plan .getPodId ());
@@ -176,39 +164,13 @@ public List<Long> orderClusters(VirtualMachineProfile vmProfile, DeploymentPlan
176164 boolean applyAllocationAtPods = Boolean .parseBoolean (_configDao .getValue (Config .ApplyAllocationAlgorithmToPods .key ()));
177165 if (applyAllocationAtPods ) {
178166 //start scan at all pods under this zone.
179- clusterList = scanPodsForDestination (vmProfile , plan , avoid );
167+ return scanPodsForDestination (vmProfile , plan , avoid );
180168 } else {
181169 //start scan at clusters under this zone.
182- clusterList = scanClustersForDestinationInZoneOrPod (plan .getDataCenterId (), true , vmProfile , plan , avoid );
183- }
184- }
185-
186- if (clusterList != null && !clusterList .isEmpty ()) {
187- ServiceOffering offering = vmProfile .getServiceOffering ();
188- // In case of non-GPU VMs, protect GPU enabled Hosts and prefer VM deployment on non-GPU Hosts.
189- if ((_serviceOfferingDetailsDao .findDetail (offering .getId (), GPU .Keys .vgpuType .toString ()) == null ) && !(_hostGpuGroupsDao .listHostIds ().isEmpty ())) {
190- int requiredCpu = offering .getCpu () * offering .getSpeed ();
191- long requiredRam = offering .getRamSize () * 1024L * 1024L ;
192- reorderClustersBasedOnImplicitTags (clusterList , requiredCpu , requiredRam );
170+ return scanClustersForDestinationInZoneOrPod (plan .getDataCenterId (), true , vmProfile , plan , avoid );
193171 }
194172 }
195- return clusterList ;
196- }
197173
198- private void reorderClustersBasedOnImplicitTags (List <Long > clusterList , int requiredCpu , long requiredRam ) {
199- final HashMap <Long , Long > UniqueTagsInClusterMap = new HashMap <Long , Long >();
200- for (Long clusterId : clusterList ) {
201- List <Long > hostList = _capacityDao .listHostsWithEnoughCapacity (requiredCpu , requiredRam , clusterId , Host .Type .Routing .toString ());
202- UniqueTagsInClusterMap .put (clusterId , new Long (_hostTagsDao .getDistinctImplicitHostTags (hostList , _implicitHostTags ).size ()));
203- }
204- Collections .sort (clusterList , new Comparator <Long >() {
205- @ Override
206- public int compare (Long o1 , Long o2 ) {
207- Long t1 = UniqueTagsInClusterMap .get (o1 );
208- Long t2 = UniqueTagsInClusterMap .get (o2 );
209- return t1 .compareTo (t2 );
210- }
211- });
212174 }
213175
214176 private List <Long > scanPodsForDestination (VirtualMachineProfile vmProfile , DeploymentPlan plan , ExcludeList avoid ) {
@@ -542,10 +504,6 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
542504 super .configure (name , params );
543505 _allocationAlgorithm = _configDao .getValue (Config .VmAllocationAlgorithm .key ());
544506 _globalDeploymentPlanner = _configDao .getValue (Config .VmDeploymentPlanner .key ());
545- String configValue ;
546- if ((configValue = _configDao .getValue (Config .ImplicitHostTags .key ())) != null ) {
547- _implicitHostTags = configValue .trim ().split ("\\ s*,\\ s*" );
548- }
549507 return true ;
550508 }
551509
0 commit comments