@@ -200,11 +200,20 @@ public UploadVO createEntityDownloadURL(VMTemplateVO template, VMTemplateHostVO
200200
201201 Type type = (template .getFormat () == ImageFormat .ISO ) ? Type .ISO : Type .TEMPLATE ;
202202
203- //Check if ssvm is up
204- HostVO sserver = storageServers .get (0 );
205- if (sserver .getStatus () != com .cloud .host .Status .Up ){
206- throw new CloudRuntimeException ("Couldnt create extract link - Secondary Storage Vm is not up" );
207- }
203+ List <HostVO > storageServerVMs = _serverDao .listByTypeDataCenter (Host .Type .SecondaryStorageVM , dataCenterId );
204+ //Check if one ssvm is up
205+ boolean no_vm_up = true ;
206+ HostVO use_ssvm = null ;
207+ for (HostVO ssvm : storageServerVMs ){
208+ if (ssvm .getStatus () == com .cloud .host .Status .Up ){
209+ no_vm_up = false ;
210+ use_ssvm = ssvm ;
211+ break ;
212+ }
213+ }
214+ if (no_vm_up ){
215+ throw new CloudRuntimeException ("Couldnt create extract link - Secondary Storage Vm is not up" );
216+ }
208217
209218 //Check if it already exists.
210219 List <UploadVO > extractURLList = _uploadDao .listByTypeUploadStatus (template .getId (), type , UploadVO .Status .DOWNLOAD_URL_CREATED );
@@ -213,15 +222,15 @@ public UploadVO createEntityDownloadURL(VMTemplateVO template, VMTemplateHostVO
213222 }
214223
215224 // It doesn't exist so create a DB entry.
216- UploadVO uploadTemplateObj = new UploadVO (sserver .getId (), template .getId (), new Date (),
225+ UploadVO uploadTemplateObj = new UploadVO (use_ssvm .getId (), template .getId (), new Date (),
217226 Status .DOWNLOAD_URL_NOT_CREATED , 0 , type , Mode .HTTP_DOWNLOAD );
218227 uploadTemplateObj .setInstallPath (vmTemplateHost .getInstallPath ());
219228 _uploadDao .persist (uploadTemplateObj );
220229 try {
221230 // Create Symlink at ssvm
222231 String uuid = UUID .randomUUID ().toString () + ".vhd" ;
223232 CreateEntityDownloadURLCommand cmd = new CreateEntityDownloadURLCommand (vmTemplateHost .getInstallPath (), uuid );
224- long result = send (sserver .getId (), cmd , null );
233+ long result = send (use_ssvm .getId (), cmd , null );
225234 if (result == -1 ){
226235 errorString = "Unable to create a link for " +type + " id:" +template .getId ();
227236 s_logger .error (errorString );
@@ -230,7 +239,7 @@ public UploadVO createEntityDownloadURL(VMTemplateVO template, VMTemplateHostVO
230239
231240 //Construct actual URL locally now that the symlink exists at SSVM
232241 List <SecondaryStorageVmVO > ssVms = _secStorageVmDao .getSecStorageVmListInStates (SecondaryStorageVm .Role .templateProcessor , dataCenterId , State .Running );
233- if (ssVms .size () > 0 ) {
242+ if (ssVms .size () > 0 ) {
234243 SecondaryStorageVmVO ssVm = ssVms .get (0 );
235244 if (ssVm .getPublicIpAddress () == null ) {
236245 errorString = "A running secondary storage vm has a null public ip?" ;
0 commit comments