Skip to content

Commit b4ee4ac

Browse files
authored
server: Fix volume state on migrate with migrateVirtualMachineWithVolume API call (#4934)
When invoking migrateVirtualMachineWithVolume API call and a strategy isn't found the volumes are left in Migrating state This PR puts back the volumes to Ready state.
1 parent a5e53dc commit b4ee4ac

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

engine/storage/datamotion/src/main/java/org/apache/cloudstack/storage/motion/DataMotionServiceImpl.java

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.apache.cloudstack.engine.subsystem.api.storage.StorageStrategyFactory;
3434
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
3535
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
36+
import org.apache.cloudstack.storage.command.CopyCmdAnswer;
3637
import org.apache.log4j.Logger;
3738
import org.springframework.stereotype.Component;
3839

@@ -42,7 +43,6 @@
4243
import com.cloud.storage.VolumeVO;
4344
import com.cloud.storage.dao.VolumeDao;
4445
import 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

Comments
 (0)