DaanHoogland commented on code in PR #13151:
URL: https://github.com/apache/cloudstack/pull/13151#discussion_r3434313703
##########
server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java:
##########
@@ -2214,26 +2216,48 @@ private UnmanagedInstanceTO
convertAndImportToKVM(ConvertInstanceCommand convert
throw new CloudRuntimeException(err);
}
+ boolean cleanupConvertedDisks = false;
+ String convertedDisksPrefix = null;
Answer importAnswer;
try {
+ convertedDisksPrefix =
((ConvertInstanceAnswer)convertAnswer).getTemporaryConvertUuid();
ImportConvertedInstanceCommand importCmd = new
ImportConvertedInstanceCommand(
remoteInstanceTO, destinationStoragePools,
temporaryConvertLocation,
-
((ConvertInstanceAnswer)convertAnswer).getTemporaryConvertUuid(),
forceConvertToPool);
+ convertedDisksPrefix, forceConvertToPool);
importAnswer = agentManager.send(importHost.getId(), importCmd);
+
+ if (!importAnswer.getResult()) {
+ cleanupConvertedDisks = true;
+ String err = String.format(
+ "The import process failed for instance %s from VMware
to KVM on host %s: %s",
+ sourceVM, importHost, importAnswer.getDetails());
+ logger.error(err);
+ throw new CloudRuntimeException(err);
+ }
} catch (AgentUnavailableException | OperationTimedoutException e) {
+ cleanupConvertedDisks = true;
String err = String.format(
"Could not send the import converted instance command to
host %s due to: %s",
importHost, e.getMessage());
logger.error(err, e);
throw new CloudRuntimeException(err);
- }
-
- if (!importAnswer.getResult()) {
- String err = String.format(
- "The import process failed for instance %s from VMware to
KVM on host %s: %s",
- sourceVM, importHost, importAnswer.getDetails());
- logger.error(err);
- throw new CloudRuntimeException(err);
+ } finally {
+ if (cleanupConvertedDisks) {
+ logger.debug("Cleaning up the converted disks for the VM {}
through " +
+ "the conversion host {}", sourceVM,
convertHost.getName());
+ CleanupConvertedInstanceDisksCommand cleanupCommand =
+ new
CleanupConvertedInstanceDisksCommand(temporaryConvertLocation,
convertedDisksPrefix);
+ try {
+ Answer cleanupAnswer =
agentManager.send(convertHost.getId(), cleanupCommand);
+ if (!cleanupAnswer.getResult()) {
+ logger.warn("Failed to cleanup the converted disks for
the VM {} through " +
+ "the conversion host {}: {}", sourceVM,
convertHost.getName(), cleanupAnswer.getDetails());
+ }
+ } catch (AgentUnavailableException |
OperationTimedoutException e) {
+ logger.error("Error cleaning up converted disks for VM {}
through the conversion host {}",
+ sourceVM, convertHost.getName(), e);
+ }
+ }
Review Comment:
new method?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]