6767import org .apache .cloudstack .storage .to .SnapshotObjectTO ;
6868import org .apache .cloudstack .storage .to .TemplateObjectTO ;
6969import org .apache .cloudstack .storage .to .VolumeObjectTO ;
70- import org .springframework .context .ApplicationContext ;
7170
7271import com .cloud .agent .api .Answer ;
7372import com .cloud .agent .api .Command ;
9796import com .cloud .hypervisor .vmware .util .VmwareHelper ;
9897import com .cloud .serializer .GsonHelper ;
9998import com .cloud .storage .DataStoreRole ;
100- import com .cloud .storage .ImageStoreDetailsUtil ;
10199import com .cloud .storage .JavaStorageLayer ;
102100import com .cloud .storage .Storage .ImageFormat ;
103101import com .cloud .storage .StorageLayer ;
112110
113111public class VmwareStorageProcessor implements StorageProcessor {
114112
115- private ImageStoreDetailsUtil imageStoreDetailsUtil ;
116-
117113 private static final Logger s_logger = Logger .getLogger (VmwareStorageProcessor .class );
118114 private static final int DEFAULT_NFS_PORT = 2049 ;
119115
@@ -125,18 +121,18 @@ public class VmwareStorageProcessor implements StorageProcessor {
125121 protected Integer _shutdownWaitMs ;
126122 private final Gson _gson ;
127123 private final StorageLayer _storage = new JavaStorageLayer ();
124+ private String _nfsVersion ;
128125
129126 public VmwareStorageProcessor (VmwareHostService hostService , boolean fullCloneFlag , VmwareStorageMount mountService , Integer timeout , VmwareResource resource ,
130- Integer shutdownWaitMs , PremiumSecondaryStorageResource storageResource ) {
127+ Integer shutdownWaitMs , PremiumSecondaryStorageResource storageResource , String nfsVersion ) {
131128 this .hostService = hostService ;
132129 _fullCloneFlag = fullCloneFlag ;
133130 this .mountService = mountService ;
134131 _timeout = timeout ;
135132 this .resource = resource ;
136133 _shutdownWaitMs = shutdownWaitMs ;
137134 _gson = GsonHelper .getGsonLogger ();
138- ApplicationContext applicationContext = com .cloud .utils .component .ComponentContext .getApplicationContext ();
139- imageStoreDetailsUtil = applicationContext .getBean ("imageStoreDetailsUtil" , ImageStoreDetailsUtil .class );
135+ _nfsVersion = nfsVersion ;
140136 }
141137
142138 @ Override
@@ -323,7 +319,7 @@ public Answer copyTemplateToPrimaryStorage(CopyCommand cmd) {
323319
324320 if (managed ) {
325321 VirtualMachineMO vmMo = copyTemplateFromSecondaryToPrimary (hyperHost , dsMo , secondaryStorageUrl , templateInfo .first (), templateInfo .second (),
326- managedStoragePoolRootVolumeName , false , imageStoreDetailsUtil . getNfsVersionByUuid ( destStore . getUuid ()) );
322+ managedStoragePoolRootVolumeName , false , _nfsVersion );
327323
328324 vmMo .unregisterVm ();
329325
@@ -340,7 +336,7 @@ public Answer copyTemplateToPrimaryStorage(CopyCommand cmd) {
340336 }
341337 else {
342338 copyTemplateFromSecondaryToPrimary (hyperHost , dsMo , secondaryStorageUrl , templateInfo .first (), templateInfo .second (),
343- templateUuidName , true , imageStoreDetailsUtil . getNfsVersionByUuid ( destStore . getUuid ()) );
339+ templateUuidName , true , _nfsVersion );
344340 }
345341 } else {
346342 s_logger .info ("Template " + templateInfo .second () + " has already been setup, skip the template setup process in primary storage" );
@@ -585,8 +581,8 @@ public Answer copyVolumeFromImageCacheToPrimary(CopyCommand cmd) {
585581 }
586582 }
587583
588- Pair <String , String > result = copyVolumeFromSecStorage (hyperHost , srcVolume .getPath (), new DatastoreMO (context , morDatastore ), srcStore .getUrl (), (long )cmd .getWait () * 1000 , imageStoreDetailsUtil . getNfsVersionByUuid ( destStore . getUuid ()) );
589- deleteVolumeDirOnSecondaryStorage (result .first (), srcStore .getUrl (), imageStoreDetailsUtil . getNfsVersionByUuid ( uuid ) );
584+ Pair <String , String > result = copyVolumeFromSecStorage (hyperHost , srcVolume .getPath (), new DatastoreMO (context , morDatastore ), srcStore .getUrl (), (long )cmd .getWait () * 1000 , _nfsVersion );
585+ deleteVolumeDirOnSecondaryStorage (result .first (), srcStore .getUrl (), _nfsVersion );
590586 VolumeObjectTO newVolume = new VolumeObjectTO ();
591587 newVolume .setPath (result .second ());
592588 return new CopyCmdAnswer (newVolume );
@@ -643,8 +639,7 @@ private Pair<String, String> copyVolumeToSecStorage(VmwareHostService hostServic
643639
644640 vmMo .createSnapshot (exportName , "Temporary snapshot for copy-volume command" , false , false );
645641
646- exportVolumeToSecondaryStroage (vmMo , volumePath , secStorageUrl , destVolumePath , exportName , hostService .getWorkerName (hyperHost .getContext (), cmd , 1 ),
647- imageStoreDetailsUtil .getNfsVersionByUuid (cmd .getDestTO ().getDataStore ().getUuid ()));
642+ exportVolumeToSecondaryStroage (vmMo , volumePath , secStorageUrl , destVolumePath , exportName , hostService .getWorkerName (hyperHost .getContext (), cmd , 1 ), _nfsVersion );
648643 return new Pair <String , String >(destVolumePath , exportName );
649644
650645 } finally {
@@ -846,7 +841,7 @@ public Answer createTemplateFromVolume(CopyCommand cmd) {
846841
847842 Ternary <String , Long , Long > result =
848843 createTemplateFromVolume (vmMo , template .getPath (), template .getId (), template .getName (), secondaryStoragePoolURL , volumePath ,
849- hostService .getWorkerName (context , cmd , 0 ), imageStoreDetailsUtil . getNfsVersionByUuid ( imageStore . getUuid ()) );
844+ hostService .getWorkerName (context , cmd , 0 ), _nfsVersion );
850845
851846 TemplateObjectTO newTemplate = new TemplateObjectTO ();
852847 newTemplate .setPath (result .first ());
@@ -1037,8 +1032,7 @@ public Answer createTemplateFromSnapshot(CopyCommand cmd) {
10371032 }
10381033
10391034 NfsTO nfsSvr = (NfsTO )imageStore ;
1040- Ternary <String , Long , Long > result = createTemplateFromSnapshot (template .getPath (), uniqeName , nfsSvr .getUrl (), snapshot .getPath (), template .getId (), (long )cmd .getWait () * 1000 ,
1041- imageStoreDetailsUtil .getNfsVersionByUuid (imageStore .getUuid ()));
1035+ Ternary <String , Long , Long > result = createTemplateFromSnapshot (template .getPath (), uniqeName , nfsSvr .getUrl (), snapshot .getPath (), template .getId (), (long )cmd .getWait () * 1000 , _nfsVersion );
10421036
10431037 TemplateObjectTO newTemplate = new TemplateObjectTO ();
10441038 newTemplate .setPath (result .first ());
@@ -1181,10 +1175,9 @@ public Answer backupSnapshot(CopyCommand cmd) {
11811175 throw new Exception ("Failed to take snapshot " + srcSnapshot .getName () + " on vm: " + vmName );
11821176 }
11831177
1184- String nfsVersion = imageStoreDetailsUtil .getNfsVersionByUuid (destStore .getUuid ());
11851178 backupResult =
11861179 backupSnapshotToSecondaryStorage (vmMo , destSnapshot .getPath (), srcSnapshot .getVolume ().getPath (), snapshotUuid , secondaryStorageUrl ,
1187- prevSnapshotUuid , prevBackupUuid , hostService .getWorkerName (context , cmd , 1 ), nfsVersion );
1180+ prevSnapshotUuid , prevBackupUuid , hostService .getWorkerName (context , cmd , 1 ), _nfsVersion );
11881181 snapshotBackupUuid = backupResult .first ();
11891182
11901183 success = (snapshotBackupUuid != null );
@@ -1196,7 +1189,7 @@ public Answer backupSnapshot(CopyCommand cmd) {
11961189
11971190 // Get snapshot physical size
11981191 long physicalSize = 0l ;
1199- String secondaryMountPoint = mountService .getMountPoint (secondaryStorageUrl , nfsVersion );
1192+ String secondaryMountPoint = mountService .getMountPoint (secondaryStorageUrl , _nfsVersion );
12001193 String snapshotDir = destSnapshot .getPath () + "/" + snapshotBackupUuid ;
12011194 File [] files = new File (secondaryMountPoint + "/" + snapshotDir ).listFiles ();
12021195 if (files != null ) {
@@ -2258,7 +2251,7 @@ public Answer createVolumeFromSnapshot(CopyCommand cmd) {
22582251 backedUpSnapshotUuid = backedUpSnapshotUuid .replace (".ovf" , "" );
22592252 }
22602253 DatastoreMO primaryDsMo = new DatastoreMO (hyperHost .getContext (), morPrimaryDs );
2261- restoreVolumeFromSecStorage (hyperHost , primaryDsMo , newVolumeName , secondaryStorageUrl , backupPath , backedUpSnapshotUuid , (long )cmd .getWait () * 1000 , imageStoreDetailsUtil . getNfsVersionByUuid ( imageStore . getUuid ()) );
2254+ restoreVolumeFromSecStorage (hyperHost , primaryDsMo , newVolumeName , secondaryStorageUrl , backupPath , backedUpSnapshotUuid , (long )cmd .getWait () * 1000 , _nfsVersion );
22622255
22632256 VolumeObjectTO newVol = new VolumeObjectTO ();
22642257 newVol .setPath (newVolumeName );
0 commit comments