CLOUDSTACK-8833: Fixed Generating url and migrate volume to another storage , resulting two entry in UI and listvolume is not working for that volume

Update the volume id in volume_store_ref table to newly created volume for migration
This commit is contained in:
Anshul Gangwar 2015-06-10 15:33:42 +05:30 committed by Anshul Gangwar
parent 61ce75e901
commit 42b89278e9
3 changed files with 20 additions and 0 deletions

View File

@ -51,4 +51,6 @@ public interface VolumeDataStoreDao extends GenericDao<VolumeDataStoreVO, Long>,
List<VolumeDataStoreVO> listUploadedVolumesByStoreId(long id);
List<VolumeDataStoreVO> listByVolumeState(Volume.State... states);
boolean updateVolumeId(long srcVolId, long destVolId);
}

View File

@ -25,6 +25,7 @@ import java.util.Map;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import com.cloud.utils.exception.CloudRuntimeException;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
@ -350,4 +351,20 @@ public class VolumeDataStoreDaoImpl extends GenericDaoBase<VolumeDataStoreVO, Lo
return listIncludingRemovedBy(sc);
}
@Override
public boolean updateVolumeId(long srcVolId, long destVolId) {
TransactionLegacy txn = TransactionLegacy.currentTxn();
try {
VolumeDataStoreVO volumeDataStoreVO = findByVolume(srcVolId);
if(volumeDataStoreVO != null) {
txn.start();
volumeDataStoreVO.setVolumeId(destVolId);
update(volumeDataStoreVO.getId(), volumeDataStoreVO);
txn.commit();
}
} catch (Exception e) {
throw new CloudRuntimeException("Unable to update the volume id for volume store ref", e);
}
return true;
}
}

View File

@ -1428,6 +1428,7 @@ public class VolumeServiceImpl implements VolumeService {
srcVolume.processEvent(Event.OperationSuccessed);
destVolume.processEvent(Event.MigrationCopySucceeded, result.getAnswer());
volDao.updateUuid(srcVolume.getId(), destVolume.getId());
_volumeStoreDao.updateVolumeId(srcVolume.getId(), destVolume.getId());
try {
destroyVolume(srcVolume.getId());
srcVolume = volFactory.getVolume(srcVolume.getId());