@@ -1123,12 +1123,6 @@ private void createManagedVolumeCopyManagedTemplateAsync(VolumeInfo volumeInfo,
11231123 // Refresh the volume info from the DB.
11241124 volumeInfo = volFactory .getVolume (volumeInfo .getId (), destPrimaryDataStore );
11251125
1126- volumeInfo .processEvent (Event .CreateRequested );
1127- CreateVolumeFromBaseImageContext <VolumeApiResult > context = new CreateVolumeFromBaseImageContext <>(null , volumeInfo , destPrimaryDataStore , srcTemplateOnPrimary , future , null , null );
1128- AsyncCallbackDispatcher <VolumeServiceImpl , CopyCommandResult > caller = AsyncCallbackDispatcher .create (this );
1129- caller .setCallback (caller .getTarget ().createVolumeFromBaseManagedImageCallBack (null , null ));
1130- caller .setContext (context );
1131-
11321126 Map <String , String > details = new HashMap <String , String >();
11331127 details .put (PrimaryDataStore .MANAGED , Boolean .TRUE .toString ());
11341128 details .put (PrimaryDataStore .STORAGE_HOST , destPrimaryDataStore .getHostAddress ());
@@ -1141,6 +1135,13 @@ private void createManagedVolumeCopyManagedTemplateAsync(VolumeInfo volumeInfo,
11411135
11421136 grantAccess (volumeInfo , destHost , destPrimaryDataStore );
11431137
1138+ volumeInfo .processEvent (Event .CreateRequested );
1139+
1140+ CreateVolumeFromBaseImageContext <VolumeApiResult > context = new CreateVolumeFromBaseImageContext <>(null , volumeInfo , destPrimaryDataStore , srcTemplateOnPrimary , future , null , null );
1141+ AsyncCallbackDispatcher <VolumeServiceImpl , CopyCommandResult > caller = AsyncCallbackDispatcher .create (this );
1142+ caller .setCallback (caller .getTarget ().createVolumeFromBaseManagedImageCallBack (null , null ));
1143+ caller .setContext (context );
1144+
11441145 try {
11451146 motionSrv .copyAsync (srcTemplateOnPrimary , volumeInfo , destHost , caller );
11461147 } finally {
@@ -1919,6 +1920,11 @@ private AsyncCallFuture<VolumeApiResult> copyManagedVolume(VolumeInfo srcVolume,
19191920 AsyncCallFuture <VolumeApiResult > createVolumeFuture = createVolumeAsync (destVolume , destStore );
19201921 VolumeApiResult createVolumeResult = createVolumeFuture .get ();
19211922 if (createVolumeResult .isFailed ()) {
1923+ s_logger .debug ("Failed to create dest volume " + destVolume .getId () + ", volume can be removed" );
1924+ destroyVolume (destVolume .getId ());
1925+ destVolume .processEvent (Event .ExpungeRequested );
1926+ destVolume .processEvent (Event .OperationSuccessed );
1927+ volDao .remove (destVolume .getId ());
19221928 throw new CloudRuntimeException ("Creation of a dest volume failed: " + createVolumeResult .getResult ());
19231929 }
19241930
0 commit comments