This is an automated email from the ASF dual-hosted git repository.

rohit pushed a commit to branch 4.15
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/4.15 by this push:
     new 0942838  kvm: remove unnecessary new String (#4870)
0942838 is described below

commit 09428380f720e6c7f20b1b04ca905dd449c2e380
Author: Wei Zhou <[email protected]>
AuthorDate: Sun Apr 4 09:38:29 2021 +0200

    kvm: remove unnecessary new String (#4870)
    
    Thanks @rubieHess to point it out.
    see #4800 (comment)
---
 .../kvm/resource/LibvirtComputingResource.java     |  6 +++---
 .../kvm/storage/LibvirtStorageAdaptor.java         |  6 +++---
 .../org/apache/cloudstack/utils/qemu/QemuImg.java  |  6 ++++++
 .../apache/cloudstack/utils/qemu/QemuImgTest.java  | 24 +++++++++++-----------
 4 files changed, 24 insertions(+), 18 deletions(-)

diff --git 
a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
 
b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
index 275d395..7b4872b 100644
--- 
a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
+++ 
b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java
@@ -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) {
diff --git 
a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java
 
b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java
index f9c627b..c9f806d 100644
--- 
a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java
+++ 
b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java
@@ -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) {
diff --git 
a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/qemu/QemuImg.java
 
b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/qemu/QemuImg.java
index 3006d25..0e5da48 100644
--- 
a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/qemu/QemuImg.java
+++ 
b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/qemu/QemuImg.java
@@ -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";
diff --git 
a/plugins/hypervisors/kvm/src/test/java/org/apache/cloudstack/utils/qemu/QemuImgTest.java
 
b/plugins/hypervisors/kvm/src/test/java/org/apache/cloudstack/utils/qemu/QemuImgTest.java
index e81890a..5f24f93 100644
--- 
a/plugins/hypervisors/kvm/src/test/java/org/apache/cloudstack/utils/qemu/QemuImgTest.java
+++ 
b/plugins/hypervisors/kvm/src/test/java/org/apache/cloudstack/utils/qemu/QemuImgTest.java
@@ -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();
 
     }
-}
\ No newline at end of file
+}

Reply via email to