@@ -192,6 +192,7 @@ public List<Host> allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan pla
192192 VMTemplateVO template = (VMTemplateVO )vmProfile .getTemplate ();
193193 Account account = vmProfile .getOwner ();
194194 List <Host > suitableHosts = new ArrayList <Host >();
195+ List <Host > hostsCopy = new ArrayList <Host >(hosts );
195196
196197 if (type == Host .Type .Storage ) {
197198 // FirstFitAllocator should be used for user VMs only since it won't care whether the host is capable of
@@ -206,23 +207,38 @@ public List<Host> allocateTo(VirtualMachineProfile vmProfile, DeploymentPlan pla
206207
207208 String haVmTag = (String )vmProfile .getParameter (VirtualMachineProfile .Param .HaTag );
208209 if (haVmTag != null ) {
209- hosts .retainAll (_hostDao .listByHostTag (type , clusterId , podId , dcId , haVmTag ));
210+ hostsCopy .retainAll (_hostDao .listByHostTag (type , clusterId , podId , dcId , haVmTag ));
210211 } else {
211212 if (hostTagOnOffering == null && hostTagOnTemplate == null ) {
212- hosts .retainAll (_resourceMgr .listAllUpAndEnabledNonHAHosts (type , clusterId , podId , dcId ));
213+ hostsCopy .retainAll (_resourceMgr .listAllUpAndEnabledNonHAHosts (type , clusterId , podId , dcId ));
213214 } else {
214215 if (hasSvcOfferingTag ) {
215- hosts .retainAll (_hostDao .listByHostTag (type , clusterId , podId , dcId , hostTagOnOffering ));
216+ if (s_logger .isDebugEnabled ()) {
217+ s_logger .debug ("Looking for hosts having tag specified on SvcOffering:" + hostTagOnOffering );
218+ }
219+ hostsCopy .retainAll (_hostDao .listByHostTag (type , clusterId , podId , dcId , hostTagOnOffering ));
220+
221+ if (s_logger .isDebugEnabled ()) {
222+ s_logger .debug ("Hosts with tag '" + hostTagOnOffering + "' are:" + hostsCopy );
223+ }
216224 }
217225
218226 if (hasTemplateTag ) {
219- hosts .retainAll (_hostDao .listByHostTag (type , clusterId , podId , dcId , hostTagOnTemplate ));
227+ if (s_logger .isDebugEnabled ()) {
228+ s_logger .debug ("Looking for hosts having tag specified on Template:" + hostTagOnTemplate );
229+ }
230+
231+ hostsCopy .retainAll (_hostDao .listByHostTag (type , clusterId , podId , dcId , hostTagOnTemplate ));
232+
233+ if (s_logger .isDebugEnabled ()) {
234+ s_logger .debug ("Hosts with tag '" + hostTagOnTemplate + "' are:" + hostsCopy );
235+ }
220236 }
221237 }
222238 }
223239
224- if (!hosts .isEmpty ()) {
225- suitableHosts = allocateTo (plan , offering , template , avoid , hosts , returnUpTo , considerReservedCapacity , account );
240+ if (!hostsCopy .isEmpty ()) {
241+ suitableHosts = allocateTo (plan , offering , template , avoid , hostsCopy , returnUpTo , considerReservedCapacity , account );
226242 }
227243
228244 return suitableHosts ;
0 commit comments