Skip to content

Commit fbe7ac6

Browse files
committed
Address review comments
1 parent b27991d commit fbe7ac6

5 files changed

Lines changed: 15 additions & 40 deletions

File tree

core/src/main/java/com/cloud/agent/api/CleanupConvertedInstanceDisksAnswer.java

Lines changed: 0 additions & 23 deletions
This file was deleted.

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtBaseConvertCommandWrapper.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
import java.util.UUID;
5252
import java.util.stream.Collectors;
5353

54-
public abstract class LibvirtBaseConvertCommandWrapper <T extends Command, A extends Answer, R extends ServerResource> extends CommandWrapper<Command, Answer, ServerResource> {
54+
public abstract class LibvirtBaseConvertCommandWrapper <T extends Command, A extends Answer, R extends ServerResource> extends CommandWrapper<T, A, R> {
5555

5656
protected KVMStoragePool getTemporaryStoragePool(DataStoreTO conversionTemporaryLocation, KVMStoragePoolManager storagePoolMgr) {
5757
if (conversionTemporaryLocation instanceof NfsTO) {
@@ -237,8 +237,10 @@ protected LibvirtDomainXMLParser parseMigratedVMXmlDomain(String installPath) th
237237
logger.error(err);
238238
throw new CloudRuntimeException(err);
239239
}
240-
InputStream is = new BufferedInputStream(new FileInputStream(xmlPath));
241-
String xml = IOUtils.toString(is, Charset.defaultCharset());
240+
String xml;
241+
try (InputStream is = new BufferedInputStream(new FileInputStream(xmlPath))) {
242+
xml = IOUtils.toString(is, Charset.defaultCharset());
243+
}
242244
final LibvirtDomainXMLParser parser = new LibvirtDomainXMLParser();
243245
try {
244246
parser.parseDomainXML(xml);

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtCleanupConvertedInstanceDisksCommandWrapper.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,13 @@
2020

2121
import com.cloud.agent.api.Answer;
2222
import com.cloud.agent.api.CleanupConvertedInstanceDisksCommand;
23-
import com.cloud.agent.api.Command;
2423
import com.cloud.agent.api.to.DataStoreTO;
2524
import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource;
2625
import com.cloud.hypervisor.kvm.resource.LibvirtDomainXMLParser;
2726
import com.cloud.hypervisor.kvm.storage.KVMPhysicalDisk;
2827
import com.cloud.hypervisor.kvm.storage.KVMStoragePool;
2928
import com.cloud.hypervisor.kvm.storage.KVMStoragePoolManager;
3029
import com.cloud.resource.ResourceWrapper;
31-
import com.cloud.resource.ServerResource;
3230

3331
import java.io.File;
3432
import java.util.List;
@@ -37,11 +35,9 @@
3735
public class LibvirtCleanupConvertedInstanceDisksCommandWrapper extends LibvirtBaseConvertCommandWrapper<CleanupConvertedInstanceDisksCommand, Answer, LibvirtComputingResource> {
3836

3937
@Override
40-
public Answer execute(Command command, ServerResource resource) {
41-
CleanupConvertedInstanceDisksCommand cmd = (CleanupConvertedInstanceDisksCommand) command;
42-
LibvirtComputingResource serverResource = (LibvirtComputingResource) resource;
43-
DataStoreTO vmVolumesStore = cmd.getVmVolumesStore();
44-
String vmVolumesPrefix = cmd.getVmVolumesPrefix();
38+
public Answer execute(CleanupConvertedInstanceDisksCommand command, LibvirtComputingResource serverResource) {
39+
DataStoreTO vmVolumesStore = command.getVmVolumesStore();
40+
String vmVolumesPrefix = command.getVmVolumesPrefix();
4541

4642
final KVMStoragePoolManager storagePoolMgr = serverResource.getStoragePoolMgr();
4743
KVMStoragePool conversionPool = getTemporaryStoragePool(vmVolumesStore, storagePoolMgr);
@@ -53,7 +49,7 @@ public Answer execute(Command command, ServerResource resource) {
5349
boolean xmlExists = new File(xmlPath).exists();
5450

5551
LibvirtDomainXMLParser xmlParser = xmlExists ? parseMigratedVMXmlDomain(volumesBasePath) : null;
56-
List<KVMPhysicalDisk> temporaryDisks = xmlExists ?
52+
List<KVMPhysicalDisk> temporaryDisks = xmlExists && xmlParser != null ?
5753
getTemporaryDisksFromParsedXml(conversionPool, xmlParser, volumesBasePath) :
5854
getTemporaryDisksWithPrefixFromTemporaryPool(conversionPool, conversionPoolPath, vmVolumesPrefix);
5955

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtImportConvertedInstanceCommandWrapper.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
import java.util.List;
2222

23-
import com.cloud.agent.api.Command;
24-
import com.cloud.resource.ServerResource;
2523
import org.apache.cloudstack.vm.UnmanagedInstanceTO;
2624

2725
import com.cloud.agent.api.Answer;
@@ -42,9 +40,7 @@
4240
public class LibvirtImportConvertedInstanceCommandWrapper extends LibvirtBaseConvertCommandWrapper<ImportConvertedInstanceCommand, Answer, LibvirtComputingResource> {
4341

4442
@Override
45-
public Answer execute(Command command, ServerResource resource) {
46-
ImportConvertedInstanceCommand cmd = (ImportConvertedInstanceCommand) command;
47-
LibvirtComputingResource serverResource = (LibvirtComputingResource) resource;
43+
public Answer execute(ImportConvertedInstanceCommand cmd, LibvirtComputingResource serverResource) {
4844
RemoteInstanceTO sourceInstance = cmd.getSourceInstance();
4945
Hypervisor.HypervisorType sourceHypervisorType = sourceInstance.getHypervisorType();
5046
String sourceInstanceName = sourceInstance.getInstanceName();

server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2248,7 +2248,11 @@ private UnmanagedInstanceTO convertAndImportToKVM(ConvertInstanceCommand convert
22482248
CleanupConvertedInstanceDisksCommand cleanupCommand =
22492249
new CleanupConvertedInstanceDisksCommand(temporaryConvertLocation, convertedDisksPrefix);
22502250
try {
2251-
agentManager.send(convertHost.getId(), cleanupCommand);
2251+
Answer cleanupAnswer = agentManager.send(convertHost.getId(), cleanupCommand);
2252+
if (!cleanupAnswer.getResult()) {
2253+
logger.warn("Failed to cleanup the converted disks for the VM {} through " +
2254+
"the conversion host {}: {}", sourceVM, convertHost.getName(), cleanupAnswer.getDetails());
2255+
}
22522256
} catch (AgentUnavailableException | OperationTimedoutException e) {
22532257
logger.error("Error cleaning up converted disks for VM {} through the conversion host {}",
22542258
sourceVM, convertHost.getName(), e);

0 commit comments

Comments
 (0)