Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@
import org.apache.cloudstack.storage.command.DettachCommand;
import org.apache.cloudstack.storage.command.TemplateOrVolumePostUploadCommand;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO;
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao;
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO;
Expand Down Expand Up @@ -120,6 +118,7 @@
import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.dao.DiskOfferingDao;
import com.cloud.storage.dao.SnapshotDao;
import com.cloud.storage.dao.StoragePoolTagsDao;
import com.cloud.storage.dao.VMTemplateDao;
import com.cloud.storage.dao.VolumeDao;
import com.cloud.storage.snapshot.SnapshotApiService;
Expand Down Expand Up @@ -254,7 +253,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
@Inject
private StorageManager storageMgr;
@Inject
private StoragePoolDetailsDao storagePoolDetailsDao;
private StoragePoolTagsDao storagePoolTagsDao;
@Inject
private StorageUtil storageUtil;

Expand Down Expand Up @@ -2079,11 +2078,12 @@ public Volume migrateVolume(MigrateVolumeCmd cmd) {
// OfflineVmwareMigration: check storage tags on disk(offering)s in comparison to destination storage pool
// OfflineVmwareMigration: if no match return a proper error now
DiskOfferingVO diskOffering = _diskOfferingDao.findById(vol.getDiskOfferingId());
if(diskOffering.equals(null)) {
throw new CloudRuntimeException("volume '" + vol.getUuid() +"', has no diskoffering. Migration target cannot be checked.");
if (diskOffering.equals(null)) {
throw new CloudRuntimeException("volume '" + vol.getUuid() + "', has no diskoffering. Migration target cannot be checked.");
}
if(! doesTargetStorageSupportDiskOffering(destPool, diskOffering)) {
throw new CloudRuntimeException("Migration target has no matching tags for volume '" +vol.getName() + "(" + vol.getUuid() + ")'");
if (!doesTargetStorageSupportDiskOffering(destPool, diskOffering)) {
throw new CloudRuntimeException(String.format("Migration target pool [%s, tags:%s] has no matching tags for volume [%s, uuid:%s, tags:%s]", destPool.getName(),
Copy link
Member Author

@GabrielBrascher GabrielBrascher May 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some details in the log message.

getStoragePoolTags(destPool), vol.getName(), vol.getUuid(), diskOffering.getTags()));
}

if (liveMigrateVolume && destPool.getClusterId() != null && srcClusterId != null) {
Expand Down Expand Up @@ -2273,15 +2273,11 @@ public boolean doesTargetStorageSupportDiskOffering(StoragePool destPool, String
* Retrieves the storage pool tags as a {@link String}. If the storage pool does not have tags we return a null value.
*/
protected String getStoragePoolTags(StoragePool destPool) {
List<StoragePoolDetailVO> storagePoolDetails = storagePoolDetailsDao.listDetails(destPool.getId());
if (CollectionUtils.isEmpty(storagePoolDetails)) {
List<String> destPoolTags = storagePoolTagsDao.getStoragePoolTags(destPool.getId());
if (CollectionUtils.isEmpty(destPoolTags)) {
return null;
}
String storageTags = "";
for (StoragePoolDetailVO storagePoolDetailVO : storagePoolDetails) {
storageTags = storageTags + storagePoolDetailVO.getName() + ",";
}
return storageTags.substring(0, storageTags.length() - 1);
return StringUtils.join(destPoolTags, ",");
}

private Volume orchestrateMigrateVolume(VolumeVO volume, StoragePool destPool, boolean liveMigrateVolume, DiskOfferingVO newDiskOffering) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@
import org.apache.cloudstack.framework.jobs.dao.AsyncJobJoinMapDao;
import org.apache.cloudstack.framework.jobs.impl.AsyncJobVO;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO;
import org.apache.cloudstack.storage.datastore.db.StoragePoolDetailsDao;
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO;
Expand Down Expand Up @@ -79,6 +77,7 @@
import com.cloud.org.Grouping;
import com.cloud.serializer.GsonHelper;
import com.cloud.storage.Volume.Type;
import com.cloud.storage.dao.StoragePoolTagsDao;
import com.cloud.storage.dao.VolumeDao;
import com.cloud.storage.snapshot.SnapshotManager;
import com.cloud.user.Account;
Expand Down Expand Up @@ -146,7 +145,7 @@ public class VolumeApiServiceImplTest {
@Mock
private HostDao _hostDao;
@Mock
private StoragePoolDetailsDao storagePoolDetailsDao;
private StoragePoolTagsDao storagePoolTagsDao;

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

@Test
public void getStoragePoolTagsTestStorageWithoutTags() {
Mockito.when(storagePoolDetailsDao.listDetails(storagePoolMockId)).thenReturn(new ArrayList<>());
Mockito.when(storagePoolTagsDao.getStoragePoolTags(storagePoolMockId)).thenReturn(new ArrayList<>());

String returnedStoragePoolTags = volumeApiServiceImpl.getStoragePoolTags(storagePoolMock);

Assert.assertNull(returnedStoragePoolTags);

}

@Test
public void getStoragePoolTagsTestStorageWithTags() {
ArrayList<StoragePoolDetailVO> tags = new ArrayList<>();
StoragePoolDetailVO tag1 = new StoragePoolDetailVO(1l, "tag1", "value", true);
StoragePoolDetailVO tag2 = new StoragePoolDetailVO(1l, "tag2", "value", true);
StoragePoolDetailVO tag3 = new StoragePoolDetailVO(1l, "tag3", "value", true);
ArrayList<String> tags = new ArrayList<>();
String tag1 = "tag1";
String tag2 = "tag2";
String tag3 = "tag3";

tags.add(tag1);
tags.add(tag2);
tags.add(tag3);

Mockito.when(storagePoolDetailsDao.listDetails(storagePoolMockId)).thenReturn(tags);
Mockito.when(storagePoolTagsDao.getStoragePoolTags(storagePoolMockId)).thenReturn(tags);

String returnedStoragePoolTags = volumeApiServiceImpl.getStoragePoolTags(storagePoolMock);

Expand Down