Skip to content

Commit 58bc835

Browse files
author
GabrielBrascher
committed
changing some variable names to ease future implementation (developers
can easily guess the name and use autocomplete)
1 parent 2e5de07 commit 58bc835

File tree

4 files changed

+50
-46
lines changed

4 files changed

+50
-46
lines changed

engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132

133133
@Component
134134
public class StorageSystemDataMotionStrategy implements DataMotionStrategy {
135-
protected static final Logger LOGGER = Logger.getLogger(StorageSystemDataMotionStrategy.class);
135+
private static final Logger LOGGER = Logger.getLogger(StorageSystemDataMotionStrategy.class);
136136
private static final Random RANDOM = new Random(System.nanoTime());
137137
private static final int LOCK_TIME_IN_SECONDS = 300;
138138
private static final String OPERATION_NOT_SUPPORTED = "This operation is not supported.";

engine/storage/datamotion/src/test/java/org/apache/cloudstack/storage/motion/KvmNonManagedStorageSystemDataMotionTest.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,17 @@ public class KvmNonManagedStorageSystemDataMotionTest {
6464
private PrimaryDataStoreDao primaryDataStoreDao;
6565

6666
@Mock
67-
private TemplateDataFactory templateFactory;
67+
private TemplateDataFactory templateDataFactory;
6868

6969
@Mock
70-
private AgentManager agentMgr;
70+
private AgentManager agentManager;
7171

7272
@Mock
7373
private DiskOfferingDao diskOfferingDao;
7474

7575
@Spy
7676
@InjectMocks
77-
private KvmNonManagedStorageDataMotionStrategy kvmStorageDataMotionStrategy;
77+
private KvmNonManagedStorageDataMotionStrategy kvmNonManagedStorageDataMotionStrategy;
7878

7979
@Test
8080
public void canHandleTestExpectHypervisorStrategyForKvm() {
@@ -96,11 +96,11 @@ public void canHandleTestExpectCannotHandle() {
9696
private void canHandleExpectCannotHandle(HypervisorType hypervisorType, int times, StrategyPriority expectedStrategyPriority) {
9797
HostVO srcHost = new HostVO("sourceHostUuid");
9898
srcHost.setHypervisorType(hypervisorType);
99-
Mockito.doReturn(StrategyPriority.HYPERVISOR).when(kvmStorageDataMotionStrategy).internalCanHandle(new HashMap<>());
99+
Mockito.doReturn(StrategyPriority.HYPERVISOR).when(kvmNonManagedStorageDataMotionStrategy).internalCanHandle(new HashMap<>());
100100

101-
StrategyPriority strategyPriority = kvmStorageDataMotionStrategy.canHandle(new HashMap<>(), srcHost, new HostVO("destHostUuid"));
101+
StrategyPriority strategyPriority = kvmNonManagedStorageDataMotionStrategy.canHandle(new HashMap<>(), srcHost, new HostVO("destHostUuid"));
102102

103-
Mockito.verify(kvmStorageDataMotionStrategy, Mockito.times(times)).internalCanHandle(new HashMap<>());
103+
Mockito.verify(kvmNonManagedStorageDataMotionStrategy, Mockito.times(times)).internalCanHandle(new HashMap<>());
104104
Assert.assertEquals(expectedStrategyPriority, strategyPriority);
105105
}
106106

@@ -109,7 +109,7 @@ public void internalCanHandleTestNonManaged() {
109109
StoragePoolType[] storagePoolTypeArray = StoragePoolType.values();
110110
for (int i = 0; i < storagePoolTypeArray.length; i++) {
111111
Map<VolumeInfo, DataStore> volumeMap = configureTestInternalCanHandle(false, storagePoolTypeArray[i]);
112-
StrategyPriority strategyPriority = kvmStorageDataMotionStrategy.internalCanHandle(volumeMap);
112+
StrategyPriority strategyPriority = kvmNonManagedStorageDataMotionStrategy.internalCanHandle(volumeMap);
113113
if (storagePoolTypeArray[i] == StoragePoolType.Filesystem || storagePoolTypeArray[i] == StoragePoolType.NetworkFilesystem) {
114114
Assert.assertEquals(StrategyPriority.HYPERVISOR, strategyPriority);
115115
} else {
@@ -123,7 +123,7 @@ public void internalCanHandleTestIsManaged() {
123123
StoragePoolType[] storagePoolTypeArray = StoragePoolType.values();
124124
for (int i = 0; i < storagePoolTypeArray.length; i++) {
125125
Map<VolumeInfo, DataStore> volumeMap = configureTestInternalCanHandle(true, storagePoolTypeArray[i]);
126-
StrategyPriority strategyPriority = kvmStorageDataMotionStrategy.internalCanHandle(volumeMap);
126+
StrategyPriority strategyPriority = kvmNonManagedStorageDataMotionStrategy.internalCanHandle(volumeMap);
127127
Assert.assertEquals(StrategyPriority.CANT_HANDLE, strategyPriority);
128128
}
129129
}
@@ -148,30 +148,30 @@ private Map<VolumeInfo, DataStore> configureTestInternalCanHandle(boolean isMana
148148
@Test
149149
public void getTemplateUuidTestTemplateIdNotNull() {
150150
String expectedTemplateUuid = prepareTestGetTemplateUuid();
151-
String templateUuid = kvmStorageDataMotionStrategy.getTemplateUuid(0l);
151+
String templateUuid = kvmNonManagedStorageDataMotionStrategy.getTemplateUuid(0l);
152152
Assert.assertEquals(expectedTemplateUuid, templateUuid);
153153
}
154154

155155
@Test
156156
public void getTemplateUuidTestTemplateIdNull() {
157157
prepareTestGetTemplateUuid();
158-
String templateUuid = kvmStorageDataMotionStrategy.getTemplateUuid(null);
158+
String templateUuid = kvmNonManagedStorageDataMotionStrategy.getTemplateUuid(null);
159159
Assert.assertEquals(null, templateUuid);
160160
}
161161

162162
private String prepareTestGetTemplateUuid() {
163163
TemplateInfo templateImage = Mockito.mock(TemplateInfo.class);
164164
String expectedTemplateUuid = "template uuid";
165165
Mockito.when(templateImage.getUuid()).thenReturn(expectedTemplateUuid);
166-
Mockito.doReturn(templateImage).when(templateFactory).getTemplate(0l, DataStoreRole.Image);
166+
Mockito.doReturn(templateImage).when(templateDataFactory).getTemplate(0l, DataStoreRole.Image);
167167
return expectedTemplateUuid;
168168
}
169169

170170
@Test
171171
public void configureMigrateDiskInfoTest() {
172172
VolumeObject srcVolumeInfo = Mockito.spy(new VolumeObject());
173173
Mockito.doReturn("volume path").when(srcVolumeInfo).getPath();
174-
MigrateCommand.MigrateDiskInfo migrateDiskInfo = kvmStorageDataMotionStrategy.configureMigrateDiskInfo(srcVolumeInfo, "destPath");
174+
MigrateCommand.MigrateDiskInfo migrateDiskInfo = kvmNonManagedStorageDataMotionStrategy.configureMigrateDiskInfo(srcVolumeInfo, "destPath");
175175
Assert.assertEquals(MigrateCommand.MigrateDiskInfo.DiskType.FILE, migrateDiskInfo.getDiskType());
176176
Assert.assertEquals(MigrateCommand.MigrateDiskInfo.DriverType.QCOW2, migrateDiskInfo.getDriverType());
177177
Assert.assertEquals(MigrateCommand.MigrateDiskInfo.Source.FILE, migrateDiskInfo.getSource());
@@ -217,7 +217,7 @@ private void configureAndVerifygenerateDestPathTest(boolean answerResult, boolea
217217
Mockito.doReturn(diskOffering).when(diskOfferingDao).findById(0l);
218218
DiskProfile diskProfile = Mockito.spy(new DiskProfile(destVolumeInfo, diskOffering, HypervisorType.KVM));
219219

220-
String templateUuid = Mockito.doReturn("templateUuid").when(kvmStorageDataMotionStrategy).getTemplateUuid(0l);
220+
String templateUuid = Mockito.doReturn("templateUuid").when(kvmNonManagedStorageDataMotionStrategy).getTemplateUuid(0l);
221221
CreateCommand rootImageProvisioningCommand = new CreateCommand(diskProfile, templateUuid, destStoragePool, true);
222222
CreateAnswer createAnswer = Mockito.spy(new CreateAnswer(rootImageProvisioningCommand, "details"));
223223
Mockito.doReturn(answerResult).when(createAnswer).getResult();
@@ -227,12 +227,12 @@ private void configureAndVerifygenerateDestPathTest(boolean answerResult, boolea
227227
Mockito.doReturn(volumeTo).when(createAnswer).getVolume();
228228

229229
if (answerIsNull) {
230-
Mockito.doReturn(null).when(agentMgr).easySend(0l, rootImageProvisioningCommand);
230+
Mockito.doReturn(null).when(agentManager).easySend(0l, rootImageProvisioningCommand);
231231
} else {
232-
Mockito.doReturn(createAnswer).when(agentMgr).easySend(0l, rootImageProvisioningCommand);
232+
Mockito.doReturn(createAnswer).when(agentManager).easySend(0l, rootImageProvisioningCommand);
233233
}
234234

235-
String generatedDestPath = kvmStorageDataMotionStrategy.generateDestPath(vmTO, srcVolume, new HostVO("sourceHostUuid"), destStoragePool, destVolumeInfo);
235+
String generatedDestPath = kvmNonManagedStorageDataMotionStrategy.generateDestPath(vmTO, srcVolume, new HostVO("sourceHostUuid"), destStoragePool, destVolumeInfo);
236236

237237
Assert.assertEquals(destPath + uuid, generatedDestPath);
238238
}
@@ -245,7 +245,7 @@ public void shouldMigrateVolumeTest() {
245245
StoragePoolType[] storagePoolTypes = StoragePoolType.values();
246246
for (int i = 0; i < storagePoolTypes.length; i++) {
247247
Mockito.doReturn(storagePoolTypes[i]).when(sourceStoragePool).getPoolType();
248-
boolean result = kvmStorageDataMotionStrategy.shouldMigrateVolume(sourceStoragePool, destHost, destStoragePool);
248+
boolean result = kvmNonManagedStorageDataMotionStrategy.shouldMigrateVolume(sourceStoragePool, destHost, destStoragePool);
249249
if (storagePoolTypes[i] == StoragePoolType.Filesystem) {
250250
Assert.assertTrue(result);
251251
} else {

engine/storage/datamotion/src/test/java/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategyTest.java

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -59,43 +59,43 @@
5959
@RunWith(MockitoJUnitRunner.class)
6060
public class StorageSystemDataMotionStrategyTest {
6161

62+
@Spy
63+
@InjectMocks
64+
private StorageSystemDataMotionStrategy storageSystemDataMotionStrategy;
65+
6266
@Mock
63-
VolumeObject source;
67+
private VolumeObject volumeObjectSource;
6468
@Mock
65-
DataObject destination;
69+
private DataObject dataObjectDestination;
6670
@Mock
67-
PrimaryDataStore sourceStore;
71+
private PrimaryDataStore primaryDataStoreSourceStore;
6872
@Mock
69-
ImageStore destinationStore;
70-
71-
@Spy
72-
@InjectMocks
73-
StorageSystemDataMotionStrategy storageSystemDataMotionStrategy;
74-
73+
private ImageStore destinationStore;
7574
@Mock
76-
PrimaryDataStoreDao storagePoolDao;
75+
private PrimaryDataStoreDao primaryDataStoreDao;
7776

78-
@Before public void setUp() throws Exception {
79-
sourceStore = mock(PrimaryDataStoreImpl.class);
77+
@Before
78+
public void setUp() throws Exception {
79+
primaryDataStoreSourceStore = mock(PrimaryDataStoreImpl.class);
8080
destinationStore = mock(ImageStoreImpl.class);
81-
source = mock(VolumeObject.class);
82-
destination = mock(VolumeObject.class);
81+
volumeObjectSource = mock(VolumeObject.class);
82+
dataObjectDestination = mock(VolumeObject.class);
8383

84-
initMocks(storageSystemDataMotionStrategy);
84+
initMocks(storageSystemDataMotionStrategy);
8585
}
8686

8787
@Test
8888
public void cantHandleSecondary() {
89-
doReturn(sourceStore).when(source).getDataStore();
90-
doReturn(DataStoreRole.Primary).when(sourceStore).getRole();
91-
doReturn(destinationStore).when(destination).getDataStore();
89+
doReturn(primaryDataStoreSourceStore).when(volumeObjectSource).getDataStore();
90+
doReturn(DataStoreRole.Primary).when(primaryDataStoreSourceStore).getRole();
91+
doReturn(destinationStore).when(dataObjectDestination).getDataStore();
9292
doReturn(DataStoreRole.Image).when((DataStore)destinationStore).getRole();
93-
doReturn(sourceStore).when(source).getDataStore();
94-
doReturn(destinationStore).when(destination).getDataStore();
93+
doReturn(primaryDataStoreSourceStore).when(volumeObjectSource).getDataStore();
94+
doReturn(destinationStore).when(dataObjectDestination).getDataStore();
9595
StoragePoolVO storeVO = new StoragePoolVO();
96-
doReturn(storeVO).when(storagePoolDao).findById(0l);
96+
doReturn(storeVO).when(primaryDataStoreDao).findById(0l);
9797

98-
assertTrue(storageSystemDataMotionStrategy.canHandle(source,destination) == StrategyPriority.CANT_HANDLE);
98+
assertTrue(storageSystemDataMotionStrategy.canHandle(volumeObjectSource, dataObjectDestination) == StrategyPriority.CANT_HANDLE);
9999
}
100100

101101
@Test
@@ -133,8 +133,8 @@ private void configureAndTestInternalCanHandle(boolean sPool0IsManaged, boolean
133133
StoragePoolVO storagePool1 = Mockito.spy(new StoragePoolVO());
134134
Mockito.doReturn(sPool1IsManaged).when(storagePool1).isManaged();
135135

136-
Mockito.doReturn(storagePool0).when(storagePoolDao).findById(0l);
137-
Mockito.doReturn(storagePool1).when(storagePoolDao).findById(1l);
136+
Mockito.doReturn(storagePool0).when(primaryDataStoreDao).findById(0l);
137+
Mockito.doReturn(storagePool1).when(primaryDataStoreDao).findById(1l);
138138

139139
StrategyPriority strategyPriority = storageSystemDataMotionStrategy.internalCanHandle(volumeMap);
140140

@@ -164,8 +164,8 @@ public void generateDestPathTest() {
164164
Mockito.doReturn(0l).when(destVolumeInfo).getPoolId();
165165
Mockito.doReturn("expected").when(storageSystemDataMotionStrategy).connectHostToVolume(destHost, 0l, "iScsiName");
166166

167-
String expected = storageSystemDataMotionStrategy.generateDestPath(Mockito.mock(VirtualMachineTO.class), Mockito.mock(VolumeVO.class), destHost, Mockito.mock(StoragePoolVO.class),
168-
destVolumeInfo);
167+
String expected = storageSystemDataMotionStrategy.generateDestPath(Mockito.mock(VirtualMachineTO.class), Mockito.mock(VolumeVO.class), destHost,
168+
Mockito.mock(StoragePoolVO.class), destVolumeInfo);
169169

170170
Assert.assertEquals(expected, "expected");
171171
Mockito.verify(storageSystemDataMotionStrategy).connectHostToVolume(destHost, 0l, "iScsiName");

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/MigrateKVMAsync.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ public class MigrateKVMAsync implements Callable<Domain> {
6161
*/
6262
private static final long VIR_MIGRATE_AUTO_CONVERGE = 8192l;
6363

64+
/**
65+
* Libvirt 1.0.3 supports compression flag for migration.
66+
*/
67+
private static final int LIBVIRT_VERSION_SUPPORTS_MIGRATE_COMPRESSED = 1000003;
68+
6469
public MigrateKVMAsync(final LibvirtComputingResource libvirtComputingResource, final Domain dm, final Connect dconn, final String dxml,
6570
final boolean migrateStorage, final boolean autoConvergence, final String vmName, final String destIp) {
6671
this.libvirtComputingResource = libvirtComputingResource;
@@ -78,8 +83,7 @@ public MigrateKVMAsync(final LibvirtComputingResource libvirtComputingResource,
7883
public Domain call() throws LibvirtException {
7984
long flags = VIR_MIGRATE_LIVE;
8085

81-
// set compression flag for migration, if libvirt version supports it
82-
if (dconn.getLibVirVersion() >= 1000003) {
86+
if (dconn.getLibVirVersion() >= LIBVIRT_VERSION_SUPPORTS_MIGRATE_COMPRESSED) {
8387
flags += VIR_MIGRATE_COMPRESSED;
8488
}
8589

0 commit comments

Comments
 (0)