106106import com .cloud .storage .dao .VMTemplateZoneDao ;
107107import com .cloud .storage .dao .VolumeDao ;
108108import com .cloud .storage .download .DownloadMonitor ;
109- import com .cloud .storage .snapshot .SnapshotManager ;
110109import com .cloud .storage .upload .UploadMonitor ;
111110import com .cloud .template .TemplateAdapter .TemplateAdapterType ;
112111import com .cloud .user .Account ;
@@ -165,11 +164,11 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe
165164 @ Inject VolumeDao _volumeDao ;
166165 @ Inject SnapshotDao _snapshotDao ;
167166 @ Inject
168- SnapshotManager _snapshotMgr ;
169- @ Inject
170167 SwiftDao _swiftDao ;
171168 @ Inject
172169 VMTemplateSwiftDao _tmpltSwiftDao ;
170+ @ Inject
171+ ConfigurationDao _configDao ;
173172 @ Inject DomainDao _domainDao ;
174173 @ Inject UploadDao _uploadDao ;
175174 long _routerTemplateId = -1 ;
@@ -412,7 +411,7 @@ String downloadTemplateFromSwiftToSecondaryStorage(long dcId, long templateId){
412411 s_logger .warn (errMsg );
413412 return errMsg ;
414413 }
415- SwiftTO swift = _snapshotMgr .getSwiftTO (tmpltSwift .getSwiftId ());
414+ SwiftTO swift = _swiftDao .getSwiftTO (tmpltSwift .getSwiftId ());
416415 if ( swift == null ) {
417416 String errMsg = " Swift " + tmpltSwift .getSwiftId () + " doesn't exit ?" ;
418417 s_logger .warn (errMsg );
@@ -447,7 +446,7 @@ String uploadTemplateToSwiftFromSecondaryStorage(VMTemplateHostVO templateHostRe
447446 return errMsg ;
448447 }
449448
450- SwiftTO swift = _snapshotMgr .getSwiftTO (null );
449+ SwiftTO swift = _swiftDao .getSwiftTO (null );
451450 if (swift == null ) {
452451 String errMsg = " There is no Swift in this setup " ;
453452 s_logger .warn (errMsg );
@@ -808,6 +807,10 @@ public void evictTemplateFromStoragePool(VMTemplateStoragePoolVO templatePoolVO)
808807 }
809808
810809 void swiftTemplateSync () {
810+ Boolean swiftEnable = Boolean .valueOf (_configDao .getValue (Config .SwiftEnable .key ()));
811+ if (!swiftEnable ) {
812+ return ;
813+ }
811814 GlobalLock swiftTemplateSyncLock = GlobalLock .getInternLock ("templatemgr.swiftTemplateSync" );
812815 try {
813816 if (swiftTemplateSyncLock .lock (3 )) {
@@ -863,7 +866,7 @@ public void run() {
863866
864867 @ Override
865868 public boolean start () {
866- _swiftTemplateSyncExecutor .scheduleAtFixedRate (getSwiftTemplateSyncTask (), 120 , 300 , TimeUnit .SECONDS );
869+ _swiftTemplateSyncExecutor .scheduleAtFixedRate (getSwiftTemplateSyncTask (), 60 , 60 , TimeUnit .SECONDS );
867870 return true ;
868871 }
869872
@@ -878,16 +881,11 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
878881 _name = name ;
879882
880883 ComponentLocator locator = ComponentLocator .getCurrentLocator ();
881- ConfigurationDao configDao = locator .getDao (ConfigurationDao .class );
882-
883- if (configDao == null ) {
884- throw new ConfigurationException ("Unable to find ConfigurationDao" );
885- }
886884
887- final Map <String , String > configs = configDao .getConfiguration ("AgentManager" , params );
885+ final Map <String , String > configs = _configDao .getConfiguration ("AgentManager" , params );
888886 _routerTemplateId = NumbersUtil .parseInt (configs .get ("router.template.id" ), 1 );
889887
890- String value = configDao .getValue (Config .PrimaryStorageDownloadWait .toString ());
888+ String value = _configDao .getValue (Config .PrimaryStorageDownloadWait .toString ());
891889 _primaryStorageDownloadWait = NumbersUtil .parseInt (value , Integer .parseInt (Config .PrimaryStorageDownloadWait .getDefaultValue ()));
892890
893891 HostTemplateStatesSearch = _tmpltHostDao .createSearchBuilder ();
@@ -901,7 +899,7 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
901899 HostSearch .done ();
902900 HostTemplateStatesSearch .done ();
903901
904- _storagePoolMaxWaitSeconds = NumbersUtil .parseInt (configDao .getValue (Config .StoragePoolMaxWaitSeconds .key ()), 3600 );
902+ _storagePoolMaxWaitSeconds = NumbersUtil .parseInt (_configDao .getValue (Config .StoragePoolMaxWaitSeconds .key ()), 3600 );
905903 _preloadExecutor = Executors .newFixedThreadPool (8 , new NamedThreadFactory ("Template-Preloader" ));
906904 _swiftTemplateSyncExecutor = Executors .newScheduledThreadPool (1 , new NamedThreadFactory ("swift-template-sync-Executor" ));
907905 return false ;
0 commit comments