@@ -211,11 +211,33 @@ public UploadVO createEntityDownloadURL(VMTemplateVO template, TemplateDataStore
211211 boolean success = false ;
212212 Type type = (template .getFormat () == ImageFormat .ISO ) ? Type .ISO : Type .TEMPLATE ;
213213
214+ // find an endpoint to send command
215+ DataStore store = this .storeMgr .getDataStore (vmTemplateHost .getDataStoreId (), DataStoreRole .Image );
216+ EndPoint ep = _epSelector .select (store );
214217
215218 //Check if it already exists.
216219 List <UploadVO > extractURLList = _uploadDao .listByTypeUploadStatus (template .getId (), type , UploadVO .Status .DOWNLOAD_URL_CREATED );
217220 if (extractURLList .size () > 0 ) {
218- return extractURLList .get (0 );
221+ // do some check here
222+ UploadVO upload = extractURLList .get (0 );
223+ String uploadUrl = extractURLList .get (0 ).getUploadUrl ();
224+ String [] token = uploadUrl .split ("/" );
225+ // example: uploadUrl = https://10-11-101-112.realhostip.com/userdata/2fdd9a70-9c4a-4a04-b1d5-1e41c221a1f9.iso
226+ // then token[2] = 10-11-101-112.realhostip.com, token[4] = 2fdd9a70-9c4a-4a04-b1d5-1e41c221a1f9.iso
227+ String hostname = ep .getPublicAddr ().replace ("." , "-" ) + "." ;
228+ if ((token != null ) && (token .length == 5 ) && (token [2 ].equals (hostname + _ssvmUrlDomain ))) // ssvm publicip and domain suffix not changed
229+ return extractURLList .get (0 );
230+ else if ((token != null ) && (token .length == 5 ) && (token [2 ].startsWith (hostname ))) { // domain suffix changed
231+ String uuid = token [4 ];
232+ uploadUrl = generateCopyUrl (ep .getPublicAddr (), uuid );
233+ UploadVO vo = _uploadDao .createForUpdate ();
234+ vo .setLastUpdated (new Date ());
235+ vo .setUploadUrl (uploadUrl );
236+ _uploadDao .update (upload .getId (), vo );
237+ return _uploadDao .findById (upload .getId (), true );
238+ } else { // ssvm publicip changed
239+ return null ;
240+ }
219241 }
220242
221243 // It doesn't exist so create a DB entry.
@@ -224,9 +246,6 @@ public UploadVO createEntityDownloadURL(VMTemplateVO template, TemplateDataStore
224246 uploadTemplateObj .setInstallPath (vmTemplateHost .getInstallPath ());
225247 _uploadDao .persist (uploadTemplateObj );
226248
227- // find an endpoint to send command
228- DataStore store = this .storeMgr .getDataStore (vmTemplateHost .getDataStoreId (), DataStoreRole .Image );
229- EndPoint ep = _epSelector .select (store );
230249 try {
231250 // Create Symlink at ssvm
232251 String path = vmTemplateHost .getInstallPath ();
0 commit comments