mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
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.
This commit is contained in:
parent
a5e53dc5c7
commit
b4ee4acaf3
@ -33,6 +33,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
|||||||
import org.apache.cloudstack.engine.subsystem.api.storage.StorageStrategyFactory;
|
import org.apache.cloudstack.engine.subsystem.api.storage.StorageStrategyFactory;
|
||||||
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
|
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
|
||||||
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
|
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
|
||||||
|
import org.apache.cloudstack.storage.command.CopyCmdAnswer;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@ -42,7 +43,6 @@ import com.cloud.storage.Volume;
|
|||||||
import com.cloud.storage.VolumeVO;
|
import com.cloud.storage.VolumeVO;
|
||||||
import com.cloud.storage.dao.VolumeDao;
|
import com.cloud.storage.dao.VolumeDao;
|
||||||
import com.cloud.utils.StringUtils;
|
import com.cloud.utils.StringUtils;
|
||||||
import com.cloud.utils.exception.CloudRuntimeException;
|
|
||||||
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@ -57,7 +57,9 @@ public class DataMotionServiceImpl implements DataMotionService {
|
|||||||
@Override
|
@Override
|
||||||
public void copyAsync(DataObject srcData, DataObject destData, Host destHost, AsyncCompletionCallback<CopyCommandResult> callback) {
|
public void copyAsync(DataObject srcData, DataObject destData, Host destHost, AsyncCompletionCallback<CopyCommandResult> callback) {
|
||||||
if (srcData.getDataStore() == null || destData.getDataStore() == null) {
|
if (srcData.getDataStore() == null || destData.getDataStore() == null) {
|
||||||
throw new CloudRuntimeException("can't find data store");
|
String errMsg = "can't find data store";
|
||||||
|
invokeCallback(errMsg, callback);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (srcData.getDataStore().getDriver().canCopy(srcData, destData)) {
|
if (srcData.getDataStore().getDriver().canCopy(srcData, destData)) {
|
||||||
@ -73,8 +75,10 @@ public class DataMotionServiceImpl implements DataMotionService {
|
|||||||
// OfflineVmware volume migration
|
// OfflineVmware volume migration
|
||||||
// Cleanup volumes from target and reset the state of volume at source
|
// Cleanup volumes from target and reset the state of volume at source
|
||||||
cleanUpVolumesForFailedMigrations(srcData, destData);
|
cleanUpVolumesForFailedMigrations(srcData, destData);
|
||||||
throw new CloudRuntimeException("Can't find strategy to move data. " + "Source: " + srcData.getType().name() + " '" + srcData.getUuid() + ", Destination: " +
|
String errMsg = "Can't find strategy to move data. " + "Source: " + srcData.getType().name() + " '" + srcData.getUuid() + ", Destination: " +
|
||||||
destData.getType().name() + " '" + destData.getUuid() + "'");
|
destData.getType().name() + " '" + destData.getUuid() + "'";
|
||||||
|
invokeCallback(errMsg, callback);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
strategy.copyAsync(srcData, destData, destHost, callback);
|
strategy.copyAsync(srcData, destData, destHost, callback);
|
||||||
@ -112,10 +116,22 @@ public class DataMotionServiceImpl implements DataMotionService {
|
|||||||
volumeIds.add(volumeInfo.getUuid());
|
volumeIds.add(volumeInfo.getUuid());
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new CloudRuntimeException("Can't find strategy to move data. " + "Source Host: " + srcHost.getName() + ", Destination Host: " + destHost.getName() +
|
String errMsg = "Can't find strategy to move data. " + "Source Host: " + srcHost.getName() + ", Destination Host: " + destHost.getName() +
|
||||||
", Volume UUIDs: " + StringUtils.join(volumeIds, ","));
|
", Volume UUIDs: " + StringUtils.join(volumeIds, ",");
|
||||||
|
invokeCallback(errMsg, callback);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
strategy.copyAsync(volumeMap, vmTo, srcHost, destHost, callback);
|
strategy.copyAsync(volumeMap, vmTo, srcHost, destHost, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void invokeCallback(String errMsg, AsyncCompletionCallback<CopyCommandResult> callback) {
|
||||||
|
CopyCmdAnswer copyCmdAnswer = new CopyCmdAnswer(errMsg);
|
||||||
|
|
||||||
|
CopyCommandResult result = new CopyCommandResult(null, copyCmdAnswer);
|
||||||
|
|
||||||
|
result.setResult(errMsg);
|
||||||
|
|
||||||
|
callback.complete(result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user