Skip to content

Commit a09354d

Browse files
Fix volume migration failure response (#10707)
1 parent 40d549b commit a09354d

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -5104,9 +5104,9 @@ private Answer execute(MigrateVolumeCommand cmd) {
51045104
answer.setVolumeChainInfo(chainInfo);
51055105
return answer;
51065106
} catch (Exception e) {
5107-
String msg = "Catch Exception " + e.getClass().getName() + " due to " + e.toString();
5107+
String msg = "Catch Exception " + e.getClass().getName() + " due to " + e.getMessage();
51085108
logger.error(msg, e);
5109-
return new MigrateVolumeAnswer(cmd, false, msg, null);
5109+
return new MigrateVolumeAnswer(cmd, false, e.getMessage(), null);
51105110
}
51115111
}
51125112

plugins/hypervisors/vmware/src/main/java/org/apache/cloudstack/storage/motion/VmwareStorageMotionStrategy.java

+19-10
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ public void copyAsync(DataObject srcData, DataObject destData, Host destHost, As
260260
} else {
261261
answer = agentMgr.sendTo(sourcePool.getDataCenterId(), HypervisorType.VMware, cmd);
262262
}
263-
updateVolumeAfterMigration(answer, srcData, destData);
263+
handleAnswerAndUpdateVolumeAfterMigration(answer, srcData, destData);
264264
CopyCommandResult result = new CopyCommandResult(null, answer);
265265
callback.complete(result);
266266
}
@@ -286,21 +286,19 @@ private Long findSuitableHostIdForWorkerVmPlacement(Long clusterId) {
286286
return hostId;
287287
}
288288

289-
private void updateVolumeAfterMigration(Answer answer, DataObject srcData, DataObject destData) {
289+
private void handleAnswerAndUpdateVolumeAfterMigration(Answer answer, DataObject srcData, DataObject destData) {
290290
VolumeVO destinationVO = volDao.findById(destData.getId());
291291
if (!(answer instanceof MigrateVolumeAnswer)) {
292292
// OfflineVmwareMigration: reset states and such
293-
VolumeVO sourceVO = volDao.findById(srcData.getId());
294-
sourceVO.setState(Volume.State.Ready);
295-
volDao.update(sourceVO.getId(), sourceVO);
296-
if (destinationVO.getId() != sourceVO.getId()) {
297-
destinationVO.setState(Volume.State.Expunged);
298-
destinationVO.setRemoved(new Date());
299-
volDao.update(destinationVO.getId(), destinationVO);
300-
}
293+
resetVolumeState(srcData, destinationVO);
301294
throw new CloudRuntimeException("unexpected answer from hypervisor agent: " + answer.getDetails());
302295
}
303296
MigrateVolumeAnswer ans = (MigrateVolumeAnswer) answer;
297+
if (!answer.getResult()) {
298+
String msg = "Unable to migrate volume: " + srcData.getName() + " due to " + answer.getDetails();
299+
resetVolumeState(srcData, destinationVO);
300+
throw new CloudRuntimeException(msg);
301+
}
304302
if (logger.isDebugEnabled()) {
305303
String format = "retrieved '%s' as new path for volume(%d)";
306304
logger.debug(String.format(format, ans.getVolumePath(), destData.getId()));
@@ -311,6 +309,17 @@ private void updateVolumeAfterMigration(Answer answer, DataObject srcData, DataO
311309
volDao.update(destinationVO.getId(), destinationVO);
312310
}
313311

312+
private void resetVolumeState(DataObject srcData, VolumeVO destinationVO) {
313+
VolumeVO sourceVO = volDao.findById(srcData.getId());
314+
sourceVO.setState(Volume.State.Ready);
315+
volDao.update(sourceVO.getId(), sourceVO);
316+
if (destinationVO.getId() != sourceVO.getId()) {
317+
destinationVO.setState(Volume.State.Expunged);
318+
destinationVO.setRemoved(new Date());
319+
volDao.update(destinationVO.getId(), destinationVO);
320+
}
321+
}
322+
314323
@Override
315324
public void copyAsync(Map<VolumeInfo, DataStore> volumeMap, VirtualMachineTO vmTo, Host srcHost, Host destHost, AsyncCompletionCallback<CopyCommandResult> callback) {
316325
Answer answer = null;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -3738,7 +3738,7 @@ protected Volume liveMigrateVolume(Volume volume, StoragePool destPool) throws S
37383738
VolumeApiResult result = future.get();
37393739
if (result.isFailed()) {
37403740
logger.debug("migrate volume failed:" + result.getResult());
3741-
throw new StorageUnavailableException("Migrate volume failed: " + result.getResult(), destPool.getId());
3741+
throw new CloudRuntimeException("Migrate volume failed: " + result.getResult());
37423742
}
37433743
return result.getVolume();
37443744
} catch (InterruptedException e) {

0 commit comments

Comments
 (0)