Skip to content

Commit 845236e

Browse files
nvazquezabhinandanprateek
authored andcommitted
CLOUDSTACK-9252: Remove static dependencies, refactor
1 parent e6b4bdc commit 845236e

File tree

13 files changed

+195
-70
lines changed

13 files changed

+195
-70
lines changed

engine/storage/image/resources/META-INF/cloudstack/core/spring-engine-storage-image-core-context.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
<bean id="templateServiceImpl"
3131
class="org.apache.cloudstack.storage.image.TemplateServiceImpl"
32-
depends-on="dataObjectManagerImpl, dataStoreManagerImpl, dataMotionServiceImpl, objectInDataStoreManagerImpl, defaultEndPointSelector, templateDataFactoryImpl" />
32+
depends-on="dataObjectManagerImpl, dataStoreManagerImpl, dataMotionServiceImpl, objectInDataStoreManagerImpl, defaultEndPointSelector, templateDataFactoryImpl, imageStoreDetailsUtilImpl" />
3333

3434
<bean id="templateDataFactoryImpl"
3535
class="org.apache.cloudstack.storage.image.TemplateDataFactoryImpl" />
@@ -38,6 +38,8 @@
3838
class="org.apache.cloudstack.storage.image.datastore.ImageStoreHelper" />
3939
<bean id="imageFormatHelper"
4040
class="org.apache.cloudstack.storage.image.format.ImageFormatHelper" />
41+
<bean id="imageStoreDetailsUtilImpl"
42+
class="com.cloud.storage.ImageStoreDetailsUtilImpl" />
4143

4244
<bean id="imageStoreProviderMgr"
4345
class="org.apache.cloudstack.storage.image.manager.ImageStoreProviderManagerImpl" />

engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ public class TemplateServiceImpl implements TemplateService {
136136
ConfigurationDao _configDao;
137137
@Inject
138138
StorageCacheManager _cacheMgr;
139+
@Inject
140+
ImageStoreDetailsUtil _imageStoreDetailsUtil;
139141

140142
class TemplateOpContext<T> extends AsyncRpcContext<T> {
141143
final TemplateObject template;
@@ -565,7 +567,7 @@ public void associateCrosszoneTemplatesToZone(long dcId) {
565567
}
566568

567569
private Map<String, TemplateProp> listTemplate(DataStore ssStore) {
568-
ListTemplateCommand cmd = new ListTemplateCommand(ssStore.getTO(), ImageStoreDetailsUtil.getNfsVersion(ssStore.getId()));
570+
ListTemplateCommand cmd = new ListTemplateCommand(ssStore.getTO(), _imageStoreDetailsUtil.getNfsVersion(ssStore.getId()));
569571
EndPoint ep = _epSelector.select(ssStore);
570572
Answer answer = null;
571573
if (ep == null) {

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
4747
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
4848
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
49-
import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao;
5049
import org.apache.cloudstack.utils.identity.ManagementServerNode;
5150

5251
import com.cloud.agent.AgentManager;
@@ -170,7 +169,7 @@ public class VmwareManagerImpl extends ManagerBase implements VmwareManager, Vmw
170169
@Inject
171170
private ClusterManager _clusterMgr;
172171
@Inject
173-
private ImageStoreDetailsDao _imageDetailsStoreDao;
172+
private ImageStoreDetailsUtil _imageStoreDetailsUtil;
174173

175174
private String _mountParent;
176175
private StorageLayer _storage;
@@ -554,7 +553,7 @@ public boolean needRecycle(String workerTag) {
554553

555554
@Override
556555
public void prepareSecondaryStorageStore(String storageUrl, Long storeId) {
557-
String mountPoint = getMountPoint(storageUrl, ImageStoreDetailsUtil.getNfsVersion(storeId));
556+
String mountPoint = getMountPoint(storageUrl, _imageStoreDetailsUtil.getNfsVersion(storeId));
558557

559558
GlobalLock lock = GlobalLock.getInternLock("prepare.systemvm");
560559
try {

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import java.util.Properties;
3030
import java.util.UUID;
3131

32+
import javax.inject.Inject;
33+
3234
import org.apache.log4j.Logger;
3335

3436
import com.vmware.vim25.FileInfo;
@@ -93,6 +95,10 @@
9395
import com.cloud.vm.snapshot.VMSnapshot;
9496

9597
public class VmwareStorageManagerImpl implements VmwareStorageManager {
98+
99+
@Inject
100+
ImageStoreDetailsUtil _imageStoreDetailsUtil;
101+
96102
@Override
97103
public boolean execute(VmwareHostService hostService, CreateEntityDownloadURLCommand cmd) {
98104
DataTO data = cmd.getData();
@@ -157,7 +163,7 @@ public String createOvaForTemplate(TemplateObjectTO template) {
157163
String secStorageUrl = nfsStore.getUrl();
158164
assert (secStorageUrl != null);
159165
String installPath = template.getPath();
160-
String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl, ImageStoreDetailsUtil.getNfsVersionByUuid(storeTO.getUuid()));
166+
String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl, _imageStoreDetailsUtil.getNfsVersionByUuid(storeTO.getUuid()));
161167
String installFullPath = secondaryMountPoint + "/" + installPath;
162168
try {
163169
if (installFullPath.endsWith(".ova")) {
@@ -195,7 +201,7 @@ public String createOvaForVolume(VolumeObjectTO volume) {
195201
String installPath = volume.getPath();
196202
int index = installPath.lastIndexOf(File.separator);
197203
String volumeUuid = installPath.substring(index + 1);
198-
String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl, ImageStoreDetailsUtil.getNfsVersionByUuid(storeTO.getUuid()));
204+
String secondaryMountPoint = _mountService.getMountPoint(secStorageUrl, _imageStoreDetailsUtil.getNfsVersionByUuid(storeTO.getUuid()));
199205
//The real volume path
200206
String volumePath = installPath + File.separator + volumeUuid + ".ova";
201207
String installFullPath = secondaryMountPoint + "/" + installPath;

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import java.util.concurrent.Executors;
3434
import java.util.concurrent.TimeUnit;
3535

36+
import javax.inject.Inject;
37+
3638
import org.apache.commons.lang.StringUtils;
3739
import org.apache.log4j.Logger;
3840

@@ -110,6 +112,10 @@
110112
import com.cloud.vm.VmDetailConstants;
111113

112114
public class VmwareStorageProcessor implements StorageProcessor {
115+
116+
@Inject
117+
ImageStoreDetailsUtil _imageStoreDetailsUtil;
118+
113119
private static final Logger s_logger = Logger.getLogger(VmwareStorageProcessor.class);
114120
private static final int DEFAULT_NFS_PORT = 2049;
115121

@@ -317,7 +323,7 @@ public Answer copyTemplateToPrimaryStorage(CopyCommand cmd) {
317323

318324
if (managed) {
319325
VirtualMachineMO vmMo = copyTemplateFromSecondaryToPrimary(hyperHost, dsMo, secondaryStorageUrl, templateInfo.first(), templateInfo.second(),
320-
managedStoragePoolRootVolumeName, false, ImageStoreDetailsUtil.getNfsVersionByUuid(destStore.getUuid()));
326+
managedStoragePoolRootVolumeName, false, _imageStoreDetailsUtil.getNfsVersionByUuid(destStore.getUuid()));
321327

322328
vmMo.unregisterVm();
323329

@@ -334,7 +340,7 @@ public Answer copyTemplateToPrimaryStorage(CopyCommand cmd) {
334340
}
335341
else {
336342
copyTemplateFromSecondaryToPrimary(hyperHost, dsMo, secondaryStorageUrl, templateInfo.first(), templateInfo.second(),
337-
templateUuidName, true, ImageStoreDetailsUtil.getNfsVersionByUuid(destStore.getUuid()));
343+
templateUuidName, true, _imageStoreDetailsUtil.getNfsVersionByUuid(destStore.getUuid()));
338344
}
339345
} else {
340346
s_logger.info("Template " + templateInfo.second() + " has already been setup, skip the template setup process in primary storage");
@@ -579,8 +585,8 @@ public Answer copyVolumeFromImageCacheToPrimary(CopyCommand cmd) {
579585
}
580586
}
581587

582-
Pair<String, String> result = copyVolumeFromSecStorage(hyperHost, srcVolume.getPath(), new DatastoreMO(context, morDatastore), srcStore.getUrl(), (long)cmd.getWait() * 1000, ImageStoreDetailsUtil.getNfsVersionByUuid(destStore.getUuid()));
583-
deleteVolumeDirOnSecondaryStorage(result.first(), srcStore.getUrl(), ImageStoreDetailsUtil.getNfsVersionByUuid(uuid));
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));
584590
VolumeObjectTO newVolume = new VolumeObjectTO();
585591
newVolume.setPath(result.second());
586592
return new CopyCmdAnswer(newVolume);
@@ -638,7 +644,7 @@ private Pair<String, String> copyVolumeToSecStorage(VmwareHostService hostServic
638644
vmMo.createSnapshot(exportName, "Temporary snapshot for copy-volume command", false, false);
639645

640646
exportVolumeToSecondaryStroage(vmMo, volumePath, secStorageUrl, destVolumePath, exportName, hostService.getWorkerName(hyperHost.getContext(), cmd, 1),
641-
ImageStoreDetailsUtil.getNfsVersionByUuid(cmd.getDestTO().getDataStore().getUuid()));
647+
_imageStoreDetailsUtil.getNfsVersionByUuid(cmd.getDestTO().getDataStore().getUuid()));
642648
return new Pair<String, String>(destVolumePath, exportName);
643649

644650
} finally {
@@ -840,7 +846,7 @@ public Answer createTemplateFromVolume(CopyCommand cmd) {
840846

841847
Ternary<String, Long, Long> result =
842848
createTemplateFromVolume(vmMo, template.getPath(), template.getId(), template.getName(), secondaryStoragePoolURL, volumePath,
843-
hostService.getWorkerName(context, cmd, 0), ImageStoreDetailsUtil.getNfsVersionByUuid(imageStore.getUuid()));
849+
hostService.getWorkerName(context, cmd, 0), _imageStoreDetailsUtil.getNfsVersionByUuid(imageStore.getUuid()));
844850

845851
TemplateObjectTO newTemplate = new TemplateObjectTO();
846852
newTemplate.setPath(result.first());
@@ -1032,7 +1038,7 @@ public Answer createTemplateFromSnapshot(CopyCommand cmd) {
10321038

10331039
NfsTO nfsSvr = (NfsTO)imageStore;
10341040
Ternary<String, Long, Long> result = createTemplateFromSnapshot(template.getPath(), uniqeName, nfsSvr.getUrl(), snapshot.getPath(), template.getId(), (long)cmd.getWait() * 1000,
1035-
ImageStoreDetailsUtil.getNfsVersionByUuid(imageStore.getUuid()));
1041+
_imageStoreDetailsUtil.getNfsVersionByUuid(imageStore.getUuid()));
10361042

10371043
TemplateObjectTO newTemplate = new TemplateObjectTO();
10381044
newTemplate.setPath(result.first());
@@ -1175,7 +1181,7 @@ public Answer backupSnapshot(CopyCommand cmd) {
11751181
throw new Exception("Failed to take snapshot " + srcSnapshot.getName() + " on vm: " + vmName);
11761182
}
11771183

1178-
String nfsVersion = ImageStoreDetailsUtil.getNfsVersionByUuid(destStore.getUuid());
1184+
String nfsVersion = _imageStoreDetailsUtil.getNfsVersionByUuid(destStore.getUuid());
11791185
backupResult =
11801186
backupSnapshotToSecondaryStorage(vmMo, destSnapshot.getPath(), srcSnapshot.getVolume().getPath(), snapshotUuid, secondaryStorageUrl,
11811187
prevSnapshotUuid, prevBackupUuid, hostService.getWorkerName(context, cmd, 1), nfsVersion);
@@ -2252,7 +2258,7 @@ public Answer createVolumeFromSnapshot(CopyCommand cmd) {
22522258
backedUpSnapshotUuid = backedUpSnapshotUuid.replace(".ovf", "");
22532259
}
22542260
DatastoreMO primaryDsMo = new DatastoreMO(hyperHost.getContext(), morPrimaryDs);
2255-
restoreVolumeFromSecStorage(hyperHost, primaryDsMo, newVolumeName, secondaryStorageUrl, backupPath, backedUpSnapshotUuid, (long)cmd.getWait() * 1000, ImageStoreDetailsUtil.getNfsVersionByUuid(imageStore.getUuid()));
2261+
restoreVolumeFromSecStorage(hyperHost, primaryDsMo, newVolumeName, secondaryStorageUrl, backupPath, backedUpSnapshotUuid, (long)cmd.getWait() * 1000, _imageStoreDetailsUtil.getNfsVersionByUuid(imageStore.getUuid()));
22562262

22572263
VolumeObjectTO newVol = new VolumeObjectTO();
22582264
newVol.setPath(newVolumeName);

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
import java.io.File;
2222

23+
import javax.inject.Inject;
24+
2325
import org.apache.log4j.Logger;
2426
import org.apache.cloudstack.storage.command.CopyCmdAnswer;
2527
import org.apache.cloudstack.storage.command.CopyCommand;
@@ -40,6 +42,10 @@
4042
import com.cloud.storage.ImageStoreDetailsUtil;
4143

4244
public class VmwareStorageSubsystemCommandHandler extends StorageSubsystemCommandHandlerBase {
45+
46+
@Inject
47+
ImageStoreDetailsUtil _imageStoreDetailsUtil;
48+
4349
private static final Logger s_logger = Logger.getLogger(VmwareStorageSubsystemCommandHandler.class);
4450
private VmwareStorageManager storageManager;
4551
private PremiumSecondaryStorageResource storageResource;
@@ -78,7 +84,7 @@ protected Answer execute(CopyCommand cmd) {
7884
}
7985
}
8086

81-
String nfsVersion = ImageStoreDetailsUtil.getNfsVersionByUuid(srcDataStore.getUuid());
87+
String nfsVersion = _imageStoreDetailsUtil.getNfsVersionByUuid(srcDataStore.getUuid());
8288
if (srcDataStore.getRole() == DataStoreRole.ImageCache && destDataStore.getRole() == DataStoreRole.Image) {
8389
//need to take extra processing for vmware, such as packing to ova, before sending to S3
8490
if (srcData.getObjectType() == DataObjectType.VOLUME) {

plugins/hypervisors/vmware/test/com/cloud/hypervisor/vmware/VmwareDatacenterApiUnitTest.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import javax.naming.ConfigurationException;
2929

3030
import com.cloud.user.User;
31+
3132
import org.junit.After;
3233
import org.junit.Before;
3334
import org.junit.BeforeClass;
@@ -48,12 +49,12 @@
4849
import org.springframework.test.context.ContextConfiguration;
4950
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
5051
import org.springframework.test.context.support.AnnotationConfigContextLoader;
51-
5252
import org.apache.cloudstack.api.command.admin.zone.AddVmwareDcCmd;
5353
import org.apache.cloudstack.api.command.admin.zone.RemoveVmwareDcCmd;
5454
import org.apache.cloudstack.context.CallContext;
5555
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
5656
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
57+
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
5758
import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao;
5859
import org.apache.cloudstack.test.utils.SpringUtils;
5960

@@ -87,6 +88,7 @@
8788
import com.cloud.org.Managed.ManagedState;
8889
import com.cloud.secstorage.CommandExecLogDao;
8990
import com.cloud.server.ConfigurationServer;
91+
import com.cloud.storage.ImageStoreDetailsUtil;
9092
import com.cloud.user.Account;
9193
import com.cloud.user.AccountManager;
9294
import com.cloud.user.AccountService;
@@ -131,6 +133,9 @@ public class VmwareDatacenterApiUnitTest {
131133
@Inject
132134
AccountManager _acctMgr;
133135

136+
@Inject
137+
ImageStoreDetailsUtil _imageStoreDetailsUtil;
138+
134139
long zoneId;
135140
long podId;
136141
long clusterId;
@@ -225,6 +230,8 @@ public void testSetUp() {
225230
Mockito.when(addCmd.getPassword()).thenReturn(password);
226231
Mockito.when(addCmd.getName()).thenReturn(vmwareDcName);
227232
Mockito.when(removeCmd.getZoneId()).thenReturn(1L);
233+
Mockito.when(_imageStoreDetailsUtil.getNfsVersion(Mockito.anyLong())).thenReturn(null);
234+
Mockito.when(_imageStoreDetailsUtil.getNfsVersionByUuid(Mockito.anyString())).thenReturn(null);
228235
}
229236

230237
@After
@@ -433,7 +440,17 @@ public DataStoreManager dataStoreManager() {
433440
}
434441

435442
@Bean
436-
public ImageStoreDetailsDao imageStoreDetailsDao(){
443+
public ImageStoreDetailsUtil imageStoreDetailsUtil() {
444+
return Mockito.mock(ImageStoreDetailsUtil.class);
445+
}
446+
447+
@Bean
448+
public ImageStoreDao imageStoreDao() {
449+
return Mockito.mock(ImageStoreDao.class);
450+
}
451+
452+
@Bean
453+
public ImageStoreDetailsDao imageStoreDetailsDao() {
437454
return Mockito.mock(ImageStoreDetailsDao.class);
438455
}
439456

server/src/com/cloud/server/StatsCollector.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
4444
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
4545
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
46-
import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao;
4746
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
4847
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
4948
import org.apache.cloudstack.utils.graphite.GraphiteClient;
@@ -200,7 +199,7 @@ public String toString() {
200199
@Inject
201200
private HostGpuGroupsDao _hostGpuGroupsDao;
202201
@Inject
203-
private ImageStoreDetailsDao _imageStoreDetailsDao;
202+
ImageStoreDetailsUtil _imageStoreDetailsUtil;
204203

205204
private ConcurrentHashMap<Long, HostStats> _hostStats = new ConcurrentHashMap<Long, HostStats>();
206205
private final ConcurrentHashMap<Long, VmStats> _VmStats = new ConcurrentHashMap<Long, VmStats>();
@@ -718,7 +717,7 @@ protected void runInContext() {
718717
continue;
719718
}
720719

721-
GetStorageStatsCommand command = new GetStorageStatsCommand(store.getTO(), ImageStoreDetailsUtil.getNfsVersion(store.getId()));
720+
GetStorageStatsCommand command = new GetStorageStatsCommand(store.getTO(), _imageStoreDetailsUtil.getNfsVersion(store.getId()));
722721
EndPoint ssAhost = _epSelector.select(store);
723722
if (ssAhost == null) {
724723
s_logger.debug("There is no secondary storage VM for secondary storage host " + store.getName());

server/src/com/cloud/storage/ImageStoreDetailsUtil.java

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,10 @@
1616
// under the License.
1717
package com.cloud.storage;
1818

19-
import java.util.Map;
19+
import com.cloud.utils.component.Manager;
2020

21-
import javax.inject.Inject;
2221

23-
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
24-
import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao;
25-
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
26-
27-
public class ImageStoreDetailsUtil {
28-
29-
@Inject
30-
private static ImageStoreDao imageStoreDao;
31-
@Inject
32-
private static ImageStoreDetailsDao imageStoreDetailsDao;
22+
public interface ImageStoreDetailsUtil extends Manager {
3323

3424
/**
3525
* Obtain NFS protocol version (if provided) for a store id.<br/>
@@ -38,22 +28,14 @@ public class ImageStoreDetailsUtil {
3828
* @return {@code null} if {@code nfs.version} is not found for storeId <br/>
3929
* {@code X} if {@code nfs.version} is found found for storeId
4030
*/
41-
public static String getNfsVersion(long storeId) {
42-
String nfsVersion = null;
43-
if (imageStoreDetailsDao.getDetails(storeId) != null){
44-
Map<String, String> storeDetails = imageStoreDetailsDao.getDetails(storeId);
45-
if (storeDetails != null && storeDetails.containsKey("nfs.version")){
46-
nfsVersion = storeDetails.get("nfs.version");
47-
}
48-
}
49-
return nfsVersion;
50-
}
31+
public String getNfsVersion(long storeId);
5132

52-
public static String getNfsVersionByUuid(String storeUuid){
53-
ImageStoreVO imageStore = imageStoreDao.findByUuid(storeUuid);
54-
if (imageStore != null){
55-
return getNfsVersion(imageStore.getId());
56-
}
57-
return null;
58-
}
33+
/**
34+
* Obtain NFS protocol version (if provided) for a store uuid.<br/>
35+
* It can be set by adding an entry in {@code image_store_details} table, providing {@code name=nfs.version} and {@code value=X} (e.g. 3)
36+
* @param storeId image store id
37+
* @return {@code null} if {@code nfs.version} is not found for storeUuid <br/>
38+
* {@code X} if {@code nfs.version} is found found for storeUuid
39+
*/
40+
public String getNfsVersionByUuid(String storeUuid);
5941
}

0 commit comments

Comments
 (0)