Skip to content

Commit aa63cdd

Browse files
nvazquezabhinandanprateek
authored andcommitted
CLOUDSTACK-9252: Last refactor, passing nfs version to ssvm
1 parent a9c1a0a commit aa63cdd

File tree

13 files changed

+78
-101
lines changed

13 files changed

+78
-101
lines changed

plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
4848
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
4949
import org.apache.cloudstack.utils.identity.ManagementServerNode;
50-
import org.springframework.context.ApplicationContext;
5150

5251
import com.cloud.agent.AgentManager;
5352
import com.cloud.agent.Listener;
@@ -112,7 +111,6 @@
112111
import com.cloud.utils.FileUtil;
113112
import com.cloud.utils.NumbersUtil;
114113
import com.cloud.utils.Pair;
115-
import com.cloud.utils.component.ComponentContext;
116114
import com.cloud.utils.component.ManagerBase;
117115
import com.cloud.utils.concurrency.NamedThreadFactory;
118116
import com.cloud.utils.db.DB;
@@ -170,6 +168,7 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
170168
private ManagementServerHostPeerDao _mshostPeerDao;
171169
@Inject
172170
private ClusterManager _clusterMgr;
171+
@Inject
173172
private ImageStoreDetailsUtil imageStoreDetailsUtil;
174173

175174
private String _mountParent;
@@ -202,8 +201,6 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
202201
private final ScheduledExecutorService _hostScanScheduler = Executors.newScheduledThreadPool(1, new NamedThreadFactory("Vmware-Host-Scan"));
203202

204203
public VmwareManagerImpl() {
205-
ApplicationContext applicationContext = ComponentContext.getApplicationContext();
206-
imageStoreDetailsUtil = applicationContext.getBean("imageStoreDetailsUtil", ImageStoreDetailsUtil.class);
207204
_storageMgr = new VmwareStorageManagerImpl(this);
208205
}
209206

plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242

4343
import org.apache.cloudstack.storage.to.TemplateObjectTO;
4444
import org.apache.cloudstack.storage.to.VolumeObjectTO;
45-
import org.springframework.context.ApplicationContext;
4645

4746
import com.cloud.agent.api.Answer;
4847
import com.cloud.agent.api.BackupSnapshotAnswer;
@@ -78,7 +77,6 @@
7877
import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost;
7978
import com.cloud.hypervisor.vmware.util.VmwareContext;
8079
import com.cloud.hypervisor.vmware.util.VmwareHelper;
81-
import com.cloud.storage.ImageStoreDetailsUtil;
8280
import com.cloud.storage.JavaStorageLayer;
8381
import com.cloud.storage.Storage.ImageFormat;
8482
import com.cloud.storage.StorageLayer;
@@ -95,7 +93,7 @@
9593

9694
public class VmwareStorageManagerImpl implements VmwareStorageManager {
9795

98-
private ImageStoreDetailsUtil imageStoreDetailsUtil;
96+
private String _nfsVersion;
9997

10098
@Override
10199
public boolean execute(VmwareHostService hostService, CreateEntityDownloadURLCommand cmd) {
@@ -141,8 +139,12 @@ public void createOva(String path, String name) {
141139
public VmwareStorageManagerImpl(VmwareStorageMount mountService) {
142140
assert (mountService != null);
143141
_mountService = mountService;
144-
ApplicationContext applicationContext = com.cloud.utils.component.ComponentContext.getApplicationContext();
145-
imageStoreDetailsUtil = applicationContext.getBean("imageStoreDetailsUtil", ImageStoreDetailsUtil.class);
142+
}
143+
144+
public VmwareStorageManagerImpl(VmwareStorageMount mountService, String nfsVersion) {
145+
assert (mountService != null);
146+
_mountService = mountService;
147+
_nfsVersion = nfsVersion;
146148
}
147149

148150
public void configure(Map<String, Object> params) {
@@ -163,7 +165,7 @@ public String createOvaForTemplate(TemplateObjectTO template) {
163165
String secStorageUrl = nfsStore.getUrl();
164166
assert (secStorageUrl != null);
165167
String installPath = template.getPath();
166-
String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl, imageStoreDetailsUtil.getNfsVersionByUuid(storeTO.getUuid()));
168+
String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl, _nfsVersion);
167169
String installFullPath = secondaryMountPoint + "/" + installPath;
168170
try {
169171
if (installFullPath.endsWith(".ova")) {
@@ -201,7 +203,7 @@ public String createOvaForVolume(VolumeObjectTO volume) {
201203
String installPath = volume.getPath();
202204
int index = installPath.lastIndexOf(File.separator);
203205
String volumeUuid = installPath.substring(index + 1);
204-
String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl, imageStoreDetailsUtil.getNfsVersionByUuid(storeTO.getUuid()));
206+
String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl, _nfsVersion);
205207
//The real volume path
206208
String volumePath = installPath + File.separator + volumeUuid + ".ova";
207209
String installFullPath = secondaryMountPoint + "/" + installPath;

plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5273,8 +5273,8 @@ else if (value != null && value.equalsIgnoreCase("ide"))
52735273

52745274
value = (String)params.get("scripts.timeout");
52755275
int timeout = NumbersUtil.parseInt(value, 1440) * 1000;
5276-
_storageProcessor = new VmwareStorageProcessor((VmwareHostService)this, _fullCloneFlag, (VmwareStorageMount)mgr, timeout, this, _shutdownWaitMs, null);
5277-
storageHandler = new VmwareStorageSubsystemCommandHandler(_storageProcessor);
5276+
_storageProcessor = new VmwareStorageProcessor((VmwareHostService)this, _fullCloneFlag, (VmwareStorageMount)mgr, timeout, this, _shutdownWaitMs, null, (String)params.get("nfsVersion"));
5277+
storageHandler = new VmwareStorageSubsystemCommandHandler(_storageProcessor, (String)params.get("nfsVersion"));
52785278

52795279
_vrResource = new VirtualRoutingResource(this);
52805280
if (!_vrResource.configure(name, params)) {

plugins/hypervisors/vmware/src/com/cloud/storage/resource/PremiumSecondaryStorageResource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
102102
VmwareSecondaryStorageContextFactory.initFactoryEnvironment();
103103
}
104104

105-
registerHandler(Hypervisor.HypervisorType.VMware, new VmwareSecondaryStorageResourceHandler(this));
105+
registerHandler(Hypervisor.HypervisorType.VMware, new VmwareSecondaryStorageResourceHandler(this, (String)params.get("nfsVersion")));
106106
return true;
107107
}
108108
}

plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareSecondaryStorageResourceHandler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ public class VmwareSecondaryStorageResourceHandler implements SecondaryStorageRe
6666
* private Map<String, HostMO> _activeHosts = new HashMap<String, HostMO>();
6767
*/
6868

69-
public VmwareSecondaryStorageResourceHandler(PremiumSecondaryStorageResource resource) {
69+
public VmwareSecondaryStorageResourceHandler(PremiumSecondaryStorageResource resource, String nfsVersion) {
7070
_resource = resource;
71-
_storageMgr = new VmwareStorageManagerImpl(this);
71+
_storageMgr = new VmwareStorageManagerImpl(this, nfsVersion);
7272
_gson = GsonHelper.getGsonLogger();
7373

74-
VmwareStorageProcessor storageProcessor = new VmwareStorageProcessor(this, true, this, resource.getTimeout(), null, null, _resource);
75-
VmwareStorageSubsystemCommandHandler vmwareStorageSubsystemCommandHandler = new VmwareStorageSubsystemCommandHandler(storageProcessor);
74+
VmwareStorageProcessor storageProcessor = new VmwareStorageProcessor(this, true, this, resource.getTimeout(), null, null, _resource, nfsVersion);
75+
VmwareStorageSubsystemCommandHandler vmwareStorageSubsystemCommandHandler = new VmwareStorageSubsystemCommandHandler(storageProcessor, nfsVersion);
7676
vmwareStorageSubsystemCommandHandler.setStorageResource(_resource);
7777
vmwareStorageSubsystemCommandHandler.setStorageManager(_storageMgr);
7878
storageSubsystemHandler = vmwareStorageSubsystemCommandHandler;

plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
import org.apache.cloudstack.storage.to.SnapshotObjectTO;
6868
import org.apache.cloudstack.storage.to.TemplateObjectTO;
6969
import org.apache.cloudstack.storage.to.VolumeObjectTO;
70-
import org.springframework.context.ApplicationContext;
7170

7271
import com.cloud.agent.api.Answer;
7372
import com.cloud.agent.api.Command;
@@ -97,7 +96,6 @@
9796
import com.cloud.hypervisor.vmware.util.VmwareHelper;
9897
import com.cloud.serializer.GsonHelper;
9998
import com.cloud.storage.DataStoreRole;
100-
import com.cloud.storage.ImageStoreDetailsUtil;
10199
import com.cloud.storage.JavaStorageLayer;
102100
import com.cloud.storage.Storage.ImageFormat;
103101
import com.cloud.storage.StorageLayer;
@@ -112,8 +110,6 @@
112110

113111
public 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);

plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageSubsystemCommandHandler.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.apache.cloudstack.storage.to.SnapshotObjectTO;
2828
import org.apache.cloudstack.storage.to.TemplateObjectTO;
2929
import org.apache.cloudstack.storage.to.VolumeObjectTO;
30-
import org.springframework.context.ApplicationContext;
3130

3231
import com.cloud.agent.api.Answer;
3332
import com.cloud.agent.api.to.DataObjectType;
@@ -38,15 +37,13 @@
3837
import com.cloud.agent.api.to.SwiftTO;
3938
import com.cloud.hypervisor.vmware.manager.VmwareStorageManager;
4039
import com.cloud.storage.DataStoreRole;
41-
import com.cloud.storage.ImageStoreDetailsUtil;
4240

4341
public class VmwareStorageSubsystemCommandHandler extends StorageSubsystemCommandHandlerBase {
4442

45-
private ImageStoreDetailsUtil imageStoreDetailsUtil;
46-
4743
private static final Logger s_logger = Logger.getLogger(VmwareStorageSubsystemCommandHandler.class);
4844
private VmwareStorageManager storageManager;
4945
private PremiumSecondaryStorageResource storageResource;
46+
private String _nfsVersion;
5047

5148
public PremiumSecondaryStorageResource getStorageResource() {
5249
return storageResource;
@@ -64,10 +61,9 @@ public void setStorageManager(VmwareStorageManager storageManager) {
6461
this.storageManager = storageManager;
6562
}
6663

67-
public VmwareStorageSubsystemCommandHandler(StorageProcessor processor) {
64+
public VmwareStorageSubsystemCommandHandler(StorageProcessor processor, String nfsVersion) {
6865
super(processor);
69-
ApplicationContext applicationContext = com.cloud.utils.component.ComponentContext.getApplicationContext();
70-
imageStoreDetailsUtil = applicationContext.getBean("imageStoreDetailsUtil", ImageStoreDetailsUtil.class);
66+
this._nfsVersion = nfsVersion;
7167
}
7268

7369
@Override
@@ -84,12 +80,11 @@ protected Answer execute(CopyCommand cmd) {
8480
}
8581
}
8682

87-
String nfsVersion = imageStoreDetailsUtil.getNfsVersionByUuid(srcDataStore.getUuid());
8883
if (srcDataStore.getRole() == DataStoreRole.ImageCache && destDataStore.getRole() == DataStoreRole.Image) {
8984
//need to take extra processing for vmware, such as packing to ova, before sending to S3
9085
if (srcData.getObjectType() == DataObjectType.VOLUME) {
9186
NfsTO cacheStore = (NfsTO)srcDataStore;
92-
String parentPath = storageResource.getRootDir(cacheStore.getUrl(), nfsVersion);
87+
String parentPath = storageResource.getRootDir(cacheStore.getUrl(), _nfsVersion);
9388
VolumeObjectTO vol = (VolumeObjectTO)srcData;
9489
String path = vol.getPath();
9590
int index = path.lastIndexOf(File.separator);
@@ -102,7 +97,7 @@ protected Answer execute(CopyCommand cmd) {
10297
} else if (srcData.getObjectType() == DataObjectType.SNAPSHOT) {
10398
// pack ova first
10499
// sync snapshot from NFS cache to S3 in NFS migration to S3 case
105-
String parentPath = storageResource.getRootDir(srcDataStore.getUrl(), nfsVersion);
100+
String parentPath = storageResource.getRootDir(srcDataStore.getUrl(), _nfsVersion);
106101
SnapshotObjectTO snap = (SnapshotObjectTO)srcData;
107102
String path = snap.getPath();
108103
int index = path.lastIndexOf(File.separator);
@@ -145,7 +140,7 @@ protected Answer execute(CopyCommand cmd) {
145140
return answer;
146141
}
147142
NfsTO cacheStore = (NfsTO)cmd.getCacheTO().getDataStore();
148-
String parentPath = storageResource.getRootDir(cacheStore.getUrl(), nfsVersion);
143+
String parentPath = storageResource.getRootDir(cacheStore.getUrl(), _nfsVersion);
149144
SnapshotObjectTO newSnapshot = (SnapshotObjectTO)answer.getNewData();
150145
String path = newSnapshot.getPath();
151146
int index = path.lastIndexOf(File.separator);

0 commit comments

Comments
 (0)