3030import javax .naming .ConfigurationException ;
3131
3232import org .apache .cloudstack .engine .subsystem .api .storage .DataStore ;
33+ import org .apache .cloudstack .engine .subsystem .api .storage .DataStoreManager ;
3334import org .apache .cloudstack .engine .subsystem .api .storage .Scope ;
35+ import org .apache .cloudstack .engine .subsystem .api .storage .ZoneScope ;
36+ import org .apache .cloudstack .storage .datastore .db .ImageStoreDao ;
37+ import org .apache .cloudstack .storage .datastore .db .ImageStoreVO ;
3438import org .apache .log4j .Logger ;
3539import org .springframework .context .annotation .Primary ;
3640import org .springframework .stereotype .Component ;
@@ -240,6 +244,10 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
240244
241245 @ Inject
242246 KeystoreManager _keystoreMgr ;
247+ @ Inject
248+ DataStoreManager _dataStoreMgr ;
249+ @ Inject
250+ ImageStoreDao _imageStoreDao ;
243251 private long _capacityScanInterval = DEFAULT_CAPACITY_SCAN_INTERVAL ;
244252 private int _secStorageVmMtuSize ;
245253
@@ -300,33 +308,39 @@ public boolean generateSetupCommand(Long ssHostId) {
300308 return false ;
301309 }
302310
303- List <HostVO > ssHosts = _ssvmMgr . listSecondaryStorageHostsInOneZone ( zoneId );
304- for ( HostVO ssHost : ssHosts ) {
305- String secUrl = ssHost . getStorageUrl ();
311+ List <DataStore > ssStores = this . _dataStoreMgr . getImageStoresByScope ( new ZoneScope ( zoneId ) );
312+ for ( DataStore ssStore : ssStores ) {
313+ String secUrl = ssStore . getUri ();
306314 SecStorageSetupCommand setupCmd = null ;
307315 if (!_useSSlCopy ) {
308- setupCmd = new SecStorageSetupCommand (secUrl , null );
316+ setupCmd = new SecStorageSetupCommand (ssStore . getTO (), secUrl , null );
309317 } else {
310318 Certificates certs = _keystoreMgr .getCertificates (ConsoleProxyManager .CERTIFICATE_NAME );
311- setupCmd = new SecStorageSetupCommand (secUrl , certs );
319+ setupCmd = new SecStorageSetupCommand (ssStore . getTO (), secUrl , certs );
312320 }
313321
314322 Answer answer = _agentMgr .easySend (ssHostId , setupCmd );
315323 if (answer != null && answer .getResult ()) {
316324 SecStorageSetupAnswer an = (SecStorageSetupAnswer ) answer ;
317- ssHost .setParent (an .get_dir ());
318- _hostDao .update (ssHost .getId (), ssHost );
325+ if (an .get_dir () != null ){
326+ // update the parent path in image_store table for this image store
327+ ImageStoreVO svo = this ._imageStoreDao .findById (ssStore .getId ());
328+ svo .setParent (an .get_dir ());
329+ _imageStoreDao .update (ssStore .getId (), svo );
330+ }
319331 if (s_logger .isDebugEnabled ()) {
320- s_logger .debug ("Successfully programmed secondary storage " + ssHost .getName () + " in secondary storage VM " + secStorageVm .getInstanceName ());
332+ s_logger .debug ("Successfully programmed secondary storage " + ssStore .getName () + " in secondary storage VM " + secStorageVm .getInstanceName ());
321333 }
322334 } else {
323335 if (s_logger .isDebugEnabled ()) {
324- s_logger .debug ("Successfully programmed secondary storage " + ssHost .getName () + " in secondary storage VM " + secStorageVm .getInstanceName ());
336+ s_logger .debug ("Successfully programmed secondary storage " + ssStore .getName () + " in secondary storage VM " + secStorageVm .getInstanceName ());
325337 }
326338 return false ;
327339 }
328340 }
329- } else if ( cssHost .getType () == Host .Type .SecondaryStorage ) {
341+ }
342+ /* After removing SecondaryStorage entries from host table, control should never come here!!
343+ else if( cssHost.getType() == Host.Type.SecondaryStorage ) {
330344 List<SecondaryStorageVmVO> alreadyRunning = _secStorageVmDao.getSecStorageVmListInStates(SecondaryStorageVm.Role.templateProcessor, zoneId, State.Running);
331345 String secUrl = cssHost.getStorageUrl();
332346 SecStorageSetupCommand setupCmd = new SecStorageSetupCommand(secUrl, null);
@@ -345,6 +359,7 @@ public boolean generateSetupCommand(Long ssHostId) {
345359 }
346360 }
347361 }
362+ */
348363 return true ;
349364 }
350365
0 commit comments