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:
slavkap 2021-04-22 12:00:18 +03:00 committed by GitHub
parent a5e53dc5c7
commit b4ee4acaf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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.VolumeInfo;
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
import org.apache.cloudstack.storage.command.CopyCmdAnswer;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
@ -42,7 +43,6 @@ import com.cloud.storage.Volume;
import com.cloud.storage.VolumeVO;
import com.cloud.storage.dao.VolumeDao;
import com.cloud.utils.StringUtils;
import com.cloud.utils.exception.CloudRuntimeException;
@Component
@ -57,7 +57,9 @@ public class DataMotionServiceImpl implements DataMotionService {
@Override
public void copyAsync(DataObject srcData, DataObject destData, Host destHost, AsyncCompletionCallback<CopyCommandResult> callback) {
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)) {
@ -73,8 +75,10 @@ public class DataMotionServiceImpl implements DataMotionService {
// OfflineVmware volume migration
// Cleanup volumes from target and reset the state of volume at source
cleanUpVolumesForFailedMigrations(srcData, destData);
throw new CloudRuntimeException("Can't find strategy to move data. " + "Source: " + srcData.getType().name() + " '" + srcData.getUuid() + ", Destination: " +
destData.getType().name() + " '" + destData.getUuid() + "'");
String errMsg = "Can't find strategy to move data. " + "Source: " + srcData.getType().name() + " '" + srcData.getUuid() + ", Destination: " +
destData.getType().name() + " '" + destData.getUuid() + "'";
invokeCallback(errMsg, callback);
return;
}
strategy.copyAsync(srcData, destData, destHost, callback);
@ -112,10 +116,22 @@ public class DataMotionServiceImpl implements DataMotionService {
volumeIds.add(volumeInfo.getUuid());
}
throw new CloudRuntimeException("Can't find strategy to move data. " + "Source Host: " + srcHost.getName() + ", Destination Host: " + destHost.getName() +
", Volume UUIDs: " + StringUtils.join(volumeIds, ","));
String errMsg = "Can't find strategy to move data. " + "Source Host: " + srcHost.getName() + ", Destination Host: " + destHost.getName() +
", Volume UUIDs: " + StringUtils.join(volumeIds, ",");
invokeCallback(errMsg, callback);
return;
}
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);
}
}