Fix volume migration failure response (#10707)

This commit is contained in:
Harikrishna 2025-04-16 14:28:06 +05:30 committed by GitHub
parent 40d549b075
commit a09354ddf5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 13 deletions

View File

@ -5104,9 +5104,9 @@ public class VmwareResource extends ServerResourceBase implements StoragePoolRes
answer.setVolumeChainInfo(chainInfo);
return answer;
} catch (Exception e) {
String msg = "Catch Exception " + e.getClass().getName() + " due to " + e.toString();
String msg = "Catch Exception " + e.getClass().getName() + " due to " + e.getMessage();
logger.error(msg, e);
return new MigrateVolumeAnswer(cmd, false, msg, null);
return new MigrateVolumeAnswer(cmd, false, e.getMessage(), null);
}
}

View File

@ -260,7 +260,7 @@ public class VmwareStorageMotionStrategy implements DataMotionStrategy {
} else {
answer = agentMgr.sendTo(sourcePool.getDataCenterId(), HypervisorType.VMware, cmd);
}
updateVolumeAfterMigration(answer, srcData, destData);
handleAnswerAndUpdateVolumeAfterMigration(answer, srcData, destData);
CopyCommandResult result = new CopyCommandResult(null, answer);
callback.complete(result);
}
@ -286,21 +286,19 @@ public class VmwareStorageMotionStrategy implements DataMotionStrategy {
return hostId;
}
private void updateVolumeAfterMigration(Answer answer, DataObject srcData, DataObject destData) {
private void handleAnswerAndUpdateVolumeAfterMigration(Answer answer, DataObject srcData, DataObject destData) {
VolumeVO destinationVO = volDao.findById(destData.getId());
if (!(answer instanceof MigrateVolumeAnswer)) {
// OfflineVmwareMigration: reset states and such
VolumeVO sourceVO = volDao.findById(srcData.getId());
sourceVO.setState(Volume.State.Ready);
volDao.update(sourceVO.getId(), sourceVO);
if (destinationVO.getId() != sourceVO.getId()) {
destinationVO.setState(Volume.State.Expunged);
destinationVO.setRemoved(new Date());
volDao.update(destinationVO.getId(), destinationVO);
}
resetVolumeState(srcData, destinationVO);
throw new CloudRuntimeException("unexpected answer from hypervisor agent: " + answer.getDetails());
}
MigrateVolumeAnswer ans = (MigrateVolumeAnswer) answer;
if (!answer.getResult()) {
String msg = "Unable to migrate volume: " + srcData.getName() + " due to " + answer.getDetails();
resetVolumeState(srcData, destinationVO);
throw new CloudRuntimeException(msg);
}
if (logger.isDebugEnabled()) {
String format = "retrieved '%s' as new path for volume(%d)";
logger.debug(String.format(format, ans.getVolumePath(), destData.getId()));
@ -311,6 +309,17 @@ public class VmwareStorageMotionStrategy implements DataMotionStrategy {
volDao.update(destinationVO.getId(), destinationVO);
}
private void resetVolumeState(DataObject srcData, VolumeVO destinationVO) {
VolumeVO sourceVO = volDao.findById(srcData.getId());
sourceVO.setState(Volume.State.Ready);
volDao.update(sourceVO.getId(), sourceVO);
if (destinationVO.getId() != sourceVO.getId()) {
destinationVO.setState(Volume.State.Expunged);
destinationVO.setRemoved(new Date());
volDao.update(destinationVO.getId(), destinationVO);
}
}
@Override
public void copyAsync(Map<VolumeInfo, DataStore> volumeMap, VirtualMachineTO vmTo, Host srcHost, Host destHost, AsyncCompletionCallback<CopyCommandResult> callback) {
Answer answer = null;

View File

@ -3738,7 +3738,7 @@ public class VolumeApiServiceImpl extends ManagerBase implements VolumeApiServic
VolumeApiResult result = future.get();
if (result.isFailed()) {
logger.debug("migrate volume failed:" + result.getResult());
throw new StorageUnavailableException("Migrate volume failed: " + result.getResult(), destPool.getId());
throw new CloudRuntimeException("Migrate volume failed: " + result.getResult());
}
return result.getVolume();
} catch (InterruptedException e) {