Skip to content

Commit 6323aac

Browse files
Gabriel Beims Bräscherrohityadavcloud
authored andcommitted
server: Fix migration target has no matching tags (#3329)
The code prior to this commit was looking into storage tags at the storage_pool_details. However, it gets null (table is empty). It should select from storage_pool_tags, which would result on the storage pool tags. and then reflect on the code that matched the volume tags (e.g. 'aTag') with the storage pool tags (empty). The code prior to this commit was looking for the storage tags at the table storage_pool_details, which is empty. It should select from storage_pool_tags, which contains the tags from each tagged storage.
1 parent 45be4a0 commit 6323aac

File tree

2 files changed

+18
-24
lines changed

2 files changed

+18
-24
lines changed

server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@
7272
import org.apache.cloudstack.storage.command.DettachCommand;
7373
import org.apache.cloudstack.storage.command.TemplateOrVolumePostUploadCommand;
7474
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
75-
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO;
76-
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao;
7775
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
7876
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
7977
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO;
@@ -120,6 +118,7 @@
120118
import com.cloud.storage.Storage.ImageFormat;
121119
import com.cloud.storage.dao.DiskOfferingDao;
122120
import com.cloud.storage.dao.SnapshotDao;
121+
import com.cloud.storage.dao.StoragePoolTagsDao;
123122
import com.cloud.storage.dao.VMTemplateDao;
124123
import com.cloud.storage.dao.VolumeDao;
125124
import com.cloud.storage.snapshot.SnapshotApiService;
@@ -254,7 +253,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
254253
@Inject
255254
private StorageManager storageMgr;
256255
@Inject
257-
private StoragePoolDetailsDao storagePoolDetailsDao;
256+
private StoragePoolTagsDao storagePoolTagsDao;
258257
@Inject
259258
private StorageUtil storageUtil;
260259

@@ -2084,11 +2083,12 @@ public Volume migrateVolume(MigrateVolumeCmd cmd) {
20842083
// OfflineVmwareMigration: check storage tags on disk(offering)s in comparison to destination storage pool
20852084
// OfflineVmwareMigration: if no match return a proper error now
20862085
DiskOfferingVO diskOffering = _diskOfferingDao.findById(vol.getDiskOfferingId());
2087-
if(diskOffering.equals(null)) {
2088-
throw new CloudRuntimeException("volume '" + vol.getUuid() +"', has no diskoffering. Migration target cannot be checked.");
2086+
if (diskOffering.equals(null)) {
2087+
throw new CloudRuntimeException("volume '" + vol.getUuid() + "', has no diskoffering. Migration target cannot be checked.");
20892088
}
2090-
if(! doesTargetStorageSupportDiskOffering(destPool, diskOffering)) {
2091-
throw new CloudRuntimeException("Migration target has no matching tags for volume '" +vol.getName() + "(" + vol.getUuid() + ")'");
2089+
if (!doesTargetStorageSupportDiskOffering(destPool, diskOffering)) {
2090+
throw new CloudRuntimeException(String.format("Migration target pool [%s, tags:%s] has no matching tags for volume [%s, uuid:%s, tags:%s]", destPool.getName(),
2091+
getStoragePoolTags(destPool), vol.getName(), vol.getUuid(), diskOffering.getTags()));
20922092
}
20932093

20942094
if (liveMigrateVolume && destPool.getClusterId() != null && srcClusterId != null) {
@@ -2278,15 +2278,11 @@ public boolean doesTargetStorageSupportDiskOffering(StoragePool destPool, String
22782278
* Retrieves the storage pool tags as a {@link String}. If the storage pool does not have tags we return a null value.
22792279
*/
22802280
protected String getStoragePoolTags(StoragePool destPool) {
2281-
List<StoragePoolDetailVO> storagePoolDetails = storagePoolDetailsDao.listDetails(destPool.getId());
2282-
if (CollectionUtils.isEmpty(storagePoolDetails)) {
2281+
List<String> destPoolTags = storagePoolTagsDao.getStoragePoolTags(destPool.getId());
2282+
if (CollectionUtils.isEmpty(destPoolTags)) {
22832283
return null;
22842284
}
2285-
String storageTags = "";
2286-
for (StoragePoolDetailVO storagePoolDetailVO : storagePoolDetails) {
2287-
storageTags = storageTags + storagePoolDetailVO.getName() + ",";
2288-
}
2289-
return storageTags.substring(0, storageTags.length() - 1);
2285+
return StringUtils.join(destPoolTags, ",");
22902286
}
22912287

22922288
private Volume orchestrateMigrateVolume(VolumeVO volume, StoragePool destPool, boolean liveMigrateVolume, DiskOfferingVO newDiskOffering) {

server/src/test/java/com/cloud/storage/VolumeApiServiceImplTest.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@
4949
import org.apache.cloudstack.framework.jobs.dao.AsyncJobJoinMapDao;
5050
import org.apache.cloudstack.framework.jobs.impl.AsyncJobVO;
5151
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
52-
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO;
53-
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao;
5452
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
5553
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
5654
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO;
@@ -79,6 +77,7 @@
7977
import com.cloud.org.Grouping;
8078
import com.cloud.serializer.GsonHelper;
8179
import com.cloud.storage.Volume.Type;
80+
import com.cloud.storage.dao.StoragePoolTagsDao;
8281
import com.cloud.storage.dao.VolumeDao;
8382
import com.cloud.storage.snapshot.SnapshotManager;
8483
import com.cloud.user.Account;
@@ -146,7 +145,7 @@ public class VolumeApiServiceImplTest {
146145
@Mock
147146
private HostDao _hostDao;
148147
@Mock
149-
private StoragePoolDetailsDao storagePoolDetailsDao;
148+
private StoragePoolTagsDao storagePoolTagsDao;
150149

151150
private DetachVolumeCmd detachCmd = new DetachVolumeCmd();
152151
private Class<?> _detachCmdClass = detachCmd.getClass();
@@ -516,26 +515,25 @@ public void tearDown() {
516515

517516
@Test
518517
public void getStoragePoolTagsTestStorageWithoutTags() {
519-
Mockito.when(storagePoolDetailsDao.listDetails(storagePoolMockId)).thenReturn(new ArrayList<>());
518+
Mockito.when(storagePoolTagsDao.getStoragePoolTags(storagePoolMockId)).thenReturn(new ArrayList<>());
520519

521520
String returnedStoragePoolTags = volumeApiServiceImpl.getStoragePoolTags(storagePoolMock);
522521

523522
Assert.assertNull(returnedStoragePoolTags);
524-
525523
}
526524

527525
@Test
528526
public void getStoragePoolTagsTestStorageWithTags() {
529-
ArrayList<StoragePoolDetailVO> tags = new ArrayList<>();
530-
StoragePoolDetailVO tag1 = new StoragePoolDetailVO(1l, "tag1", "value", true);
531-
StoragePoolDetailVO tag2 = new StoragePoolDetailVO(1l, "tag2", "value", true);
532-
StoragePoolDetailVO tag3 = new StoragePoolDetailVO(1l, "tag3", "value", true);
527+
ArrayList<String> tags = new ArrayList<>();
528+
String tag1 = "tag1";
529+
String tag2 = "tag2";
530+
String tag3 = "tag3";
533531

534532
tags.add(tag1);
535533
tags.add(tag2);
536534
tags.add(tag3);
537535

538-
Mockito.when(storagePoolDetailsDao.listDetails(storagePoolMockId)).thenReturn(tags);
536+
Mockito.when(storagePoolTagsDao.getStoragePoolTags(storagePoolMockId)).thenReturn(tags);
539537

540538
String returnedStoragePoolTags = volumeApiServiceImpl.getStoragePoolTags(storagePoolMock);
541539

0 commit comments

Comments
 (0)