mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
kvm: remove unnecessary new String (#4870)
Thanks @rubieHess to point it out. see #4800 (comment)
This commit is contained in:
parent
2cdde8774b
commit
09428380f7
@ -4264,8 +4264,8 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
|
||||
QemuImg qemu = new QemuImg(timeout);
|
||||
try{
|
||||
Map<String, String> info = qemu.info(file);
|
||||
String backingFilePath = info.get(new String("backing_file"));
|
||||
String backingFileFormat = info.get(new String("backing_file_format"));
|
||||
String backingFilePath = info.get(QemuImg.BACKING_FILE);
|
||||
String backingFileFormat = info.get(QemuImg.BACKING_FILE_FORMAT);
|
||||
if (org.apache.commons.lang.StringUtils.isNotBlank(backingFilePath)
|
||||
&& org.apache.commons.lang.StringUtils.isBlank(backingFileFormat)) {
|
||||
// VMs which are created in CloudStack 4.14 and before cannot be started or migrated
|
||||
@ -4274,7 +4274,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
|
||||
s_logger.info("Setting backing file format of " + volPath);
|
||||
QemuImgFile backingFile = new QemuImgFile(backingFilePath);
|
||||
Map<String, String> backingFileinfo = qemu.info(backingFile);
|
||||
String backingFileFmt = backingFileinfo.get(new String("file_format"));
|
||||
String backingFileFmt = backingFileinfo.get(QemuImg.FILE_FORMAT);
|
||||
qemu.rebase(file, backingFile, backingFileFmt, false);
|
||||
}
|
||||
} catch (QemuImgException e) {
|
||||
|
||||
@ -809,7 +809,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
|
||||
try{
|
||||
qemu.create(destFile, options);
|
||||
Map<String, String> info = qemu.info(destFile);
|
||||
virtualSize = Long.parseLong(info.get(new String("virtual_size")));
|
||||
virtualSize = Long.parseLong(info.get(QemuImg.VIRTUAL_SIZE));
|
||||
actualSize = new File(destFile.getFileName()).length();
|
||||
} catch (QemuImgException e) {
|
||||
s_logger.error("Failed to create " + volPath +
|
||||
@ -1287,7 +1287,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
|
||||
srcFile = new QemuImgFile(sourcePath, sourceFormat);
|
||||
try {
|
||||
Map<String, String> info = qemu.info(srcFile);
|
||||
String backingFile = info.get(new String("backing_file"));
|
||||
String backingFile = info.get(QemuImg.BACKING_FILE);
|
||||
// qcow2 templates can just be copied into place
|
||||
if (sourceFormat.equals(destFormat) && backingFile == null && sourcePath.endsWith(".qcow2")) {
|
||||
String result = Script.runSimpleBashScript("cp -f " + sourcePath + " " + destPath, timeout);
|
||||
@ -1299,7 +1299,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
|
||||
try {
|
||||
qemu.convert(srcFile, destFile);
|
||||
Map<String, String> destInfo = qemu.info(destFile);
|
||||
Long virtualSize = Long.parseLong(destInfo.get(new String("virtual_size")));
|
||||
Long virtualSize = Long.parseLong(destInfo.get(QemuImg.VIRTUAL_SIZE));
|
||||
newDisk.setVirtualSize(virtualSize);
|
||||
newDisk.setSize(virtualSize);
|
||||
} catch (QemuImgException e) {
|
||||
|
||||
@ -28,6 +28,12 @@ import com.cloud.utils.script.OutputInterpreter;
|
||||
import com.cloud.utils.script.Script;
|
||||
|
||||
public class QemuImg {
|
||||
public final static String BACKING_FILE = "backing_file";
|
||||
public final static String BACKING_FILE_FORMAT = "backing_file_format";
|
||||
public final static String CLUSTER_SIZE = "cluster_size";
|
||||
public final static String FILE_FORMAT = "file_format";
|
||||
public final static String IMAGE = "image";
|
||||
public final static String VIRTUAL_SIZE = "virtual_size";
|
||||
|
||||
/* The qemu-img binary. We expect this to be in $PATH */
|
||||
public String _qemuImgPath = "qemu-img";
|
||||
|
||||
@ -51,10 +51,10 @@ public class QemuImgTest {
|
||||
fail("We didn't get any information back from qemu-img");
|
||||
}
|
||||
|
||||
Long infoSize = Long.parseLong(info.get(new String("virtual_size")));
|
||||
Long infoSize = Long.parseLong(info.get(QemuImg.VIRTUAL_SIZE));
|
||||
assertEquals(Long.valueOf(size), Long.valueOf(infoSize));
|
||||
|
||||
String infoPath = info.get(new String("image"));
|
||||
String infoPath = info.get(QemuImg.IMAGE);
|
||||
assertEquals(filename, infoPath);
|
||||
|
||||
File f = new File(filename);
|
||||
@ -78,13 +78,13 @@ public class QemuImgTest {
|
||||
qemu.create(file, options);
|
||||
Map<String, String> info = qemu.info(file);
|
||||
|
||||
Long infoSize = Long.parseLong(info.get(new String("virtual_size")));
|
||||
Long infoSize = Long.parseLong(info.get(QemuImg.VIRTUAL_SIZE));
|
||||
assertEquals(Long.valueOf(size), Long.valueOf(infoSize));
|
||||
|
||||
String infoPath = info.get(new String("image"));
|
||||
String infoPath = info.get(QemuImg.IMAGE);
|
||||
assertEquals(filename, infoPath);
|
||||
|
||||
String infoClusterSize = info.get(new String("cluster_size"));
|
||||
String infoClusterSize = info.get(QemuImg.CLUSTER_SIZE);
|
||||
assertEquals(clusterSize, infoClusterSize);
|
||||
|
||||
File f = new File(filename);
|
||||
@ -135,7 +135,7 @@ public class QemuImgTest {
|
||||
fail("We didn't get any information back from qemu-img");
|
||||
}
|
||||
|
||||
Long infoSize = Long.parseLong(info.get(new String("virtual_size")));
|
||||
Long infoSize = Long.parseLong(info.get(QemuImg.VIRTUAL_SIZE));
|
||||
assertEquals(Long.valueOf(endSize), Long.valueOf(infoSize));
|
||||
} catch (QemuImgException e) {
|
||||
fail(e.getMessage());
|
||||
@ -164,7 +164,7 @@ public class QemuImgTest {
|
||||
fail("We didn't get any information back from qemu-img");
|
||||
}
|
||||
|
||||
Long infoSize = Long.parseLong(info.get(new String("virtual_size")));
|
||||
Long infoSize = Long.parseLong(info.get(QemuImg.VIRTUAL_SIZE));
|
||||
assertEquals(Long.valueOf(startSize + increment), Long.valueOf(infoSize));
|
||||
} catch (QemuImgException e) {
|
||||
fail(e.getMessage());
|
||||
@ -192,7 +192,7 @@ public class QemuImgTest {
|
||||
fail("We didn't get any information back from qemu-img");
|
||||
}
|
||||
|
||||
Long infoSize = Long.parseLong(info.get(new String("virtual_size")));
|
||||
Long infoSize = Long.parseLong(info.get(QemuImg.VIRTUAL_SIZE));
|
||||
assertEquals(Long.valueOf(startSize + increment), Long.valueOf(infoSize));
|
||||
} catch (QemuImgException e) {
|
||||
fail(e.getMessage());
|
||||
@ -255,7 +255,7 @@ public class QemuImgTest {
|
||||
fail("We didn't get any information back from qemu-img");
|
||||
}
|
||||
|
||||
String backingFile = info.get(new String("backing_file"));
|
||||
String backingFile = info.get(QemuImg.BACKING_FILE);
|
||||
if (backingFile == null) {
|
||||
fail("The second file does not have a property backing_file! Create failed?");
|
||||
}
|
||||
@ -303,10 +303,10 @@ public class QemuImgTest {
|
||||
|
||||
Map<String, String> info = qemu.info(destFile);
|
||||
|
||||
PhysicalDiskFormat infoFormat = PhysicalDiskFormat.valueOf(info.get(new String("format")).toUpperCase());
|
||||
PhysicalDiskFormat infoFormat = PhysicalDiskFormat.valueOf(info.get(QemuImg.FILE_FORMAT).toUpperCase());
|
||||
assertEquals(destFormat, infoFormat);
|
||||
|
||||
Long infoSize = Long.parseLong(info.get(new String("virtual_size")));
|
||||
Long infoSize = Long.parseLong(info.get(QemuImg.VIRTUAL_SIZE));
|
||||
assertEquals(Long.valueOf(srcSize), Long.valueOf(infoSize));
|
||||
|
||||
File sf = new File(srcFileName);
|
||||
@ -316,4 +316,4 @@ public class QemuImgTest {
|
||||
df.delete();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user