@@ -260,7 +260,7 @@ public void copyAsync(DataObject srcData, DataObject destData, Host destHost, As
260
260
} else {
261
261
answer = agentMgr .sendTo (sourcePool .getDataCenterId (), HypervisorType .VMware , cmd );
262
262
}
263
- updateVolumeAfterMigration (answer , srcData , destData );
263
+ handleAnswerAndUpdateVolumeAfterMigration (answer , srcData , destData );
264
264
CopyCommandResult result = new CopyCommandResult (null , answer );
265
265
callback .complete (result );
266
266
}
@@ -286,21 +286,19 @@ private Long findSuitableHostIdForWorkerVmPlacement(Long clusterId) {
286
286
return hostId ;
287
287
}
288
288
289
- private void updateVolumeAfterMigration (Answer answer , DataObject srcData , DataObject destData ) {
289
+ private void handleAnswerAndUpdateVolumeAfterMigration (Answer answer , DataObject srcData , DataObject destData ) {
290
290
VolumeVO destinationVO = volDao .findById (destData .getId ());
291
291
if (!(answer instanceof MigrateVolumeAnswer )) {
292
292
// 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 );
301
294
throw new CloudRuntimeException ("unexpected answer from hypervisor agent: " + answer .getDetails ());
302
295
}
303
296
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
+ }
304
302
if (logger .isDebugEnabled ()) {
305
303
String format = "retrieved '%s' as new path for volume(%d)" ;
306
304
logger .debug (String .format (format , ans .getVolumePath (), destData .getId ()));
@@ -311,6 +309,17 @@ private void updateVolumeAfterMigration(Answer answer, DataObject srcData, DataO
311
309
volDao .update (destinationVO .getId (), destinationVO );
312
310
}
313
311
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
+
314
323
@ Override
315
324
public void copyAsync (Map <VolumeInfo , DataStore > volumeMap , VirtualMachineTO vmTo , Host srcHost , Host destHost , AsyncCompletionCallback <CopyCommandResult > callback ) {
316
325
Answer answer = null ;
0 commit comments