3333import org .apache .cloudstack .engine .subsystem .api .storage .StorageStrategyFactory ;
3434import org .apache .cloudstack .engine .subsystem .api .storage .VolumeInfo ;
3535import org .apache .cloudstack .framework .async .AsyncCompletionCallback ;
36+ import org .apache .cloudstack .storage .command .CopyCmdAnswer ;
3637import org .apache .log4j .Logger ;
3738import org .springframework .stereotype .Component ;
3839
4243import com .cloud .storage .VolumeVO ;
4344import com .cloud .storage .dao .VolumeDao ;
4445import com .cloud .utils .StringUtils ;
45- import com .cloud .utils .exception .CloudRuntimeException ;
4646
4747
4848@ Component
@@ -57,7 +57,9 @@ public class DataMotionServiceImpl implements DataMotionService {
5757 @ Override
5858 public void copyAsync (DataObject srcData , DataObject destData , Host destHost , AsyncCompletionCallback <CopyCommandResult > callback ) {
5959 if (srcData .getDataStore () == null || destData .getDataStore () == null ) {
60- throw new CloudRuntimeException ("can't find data store" );
60+ String errMsg = "can't find data store" ;
61+ invokeCallback (errMsg , callback );
62+ return ;
6163 }
6264
6365 if (srcData .getDataStore ().getDriver ().canCopy (srcData , destData )) {
@@ -73,8 +75,10 @@ public void copyAsync(DataObject srcData, DataObject destData, Host destHost, As
7375 // OfflineVmware volume migration
7476 // Cleanup volumes from target and reset the state of volume at source
7577 cleanUpVolumesForFailedMigrations (srcData , destData );
76- throw new CloudRuntimeException ("Can't find strategy to move data. " + "Source: " + srcData .getType ().name () + " '" + srcData .getUuid () + ", Destination: " +
77- destData .getType ().name () + " '" + destData .getUuid () + "'" );
78+ String errMsg = "Can't find strategy to move data. " + "Source: " + srcData .getType ().name () + " '" + srcData .getUuid () + ", Destination: " +
79+ destData .getType ().name () + " '" + destData .getUuid () + "'" ;
80+ invokeCallback (errMsg , callback );
81+ return ;
7882 }
7983
8084 strategy .copyAsync (srcData , destData , destHost , callback );
@@ -112,10 +116,22 @@ public void copyAsync(Map<VolumeInfo, DataStore> volumeMap, VirtualMachineTO vmT
112116 volumeIds .add (volumeInfo .getUuid ());
113117 }
114118
115- throw new CloudRuntimeException ("Can't find strategy to move data. " + "Source Host: " + srcHost .getName () + ", Destination Host: " + destHost .getName () +
116- ", Volume UUIDs: " + StringUtils .join (volumeIds , "," ));
119+ String errMsg = "Can't find strategy to move data. " + "Source Host: " + srcHost .getName () + ", Destination Host: " + destHost .getName () +
120+ ", Volume UUIDs: " + StringUtils .join (volumeIds , "," );
121+ invokeCallback (errMsg , callback );
122+ return ;
117123 }
118124
119125 strategy .copyAsync (volumeMap , vmTo , srcHost , destHost , callback );
120126 }
127+
128+ private void invokeCallback (String errMsg , AsyncCompletionCallback <CopyCommandResult > callback ) {
129+ CopyCmdAnswer copyCmdAnswer = new CopyCmdAnswer (errMsg );
130+
131+ CopyCommandResult result = new CopyCommandResult (null , copyCmdAnswer );
132+
133+ result .setResult (errMsg );
134+
135+ callback .complete (result );
136+ }
121137}
0 commit comments