[Title] add checking custom base image routine.
authorjihye kim <jihye1128.kim@samsung.com>
Thu, 28 Jun 2012 07:58:24 +0000 (16:58 +0900)
committerjihye kim <jihye1128.kim@samsung.com>
Thu, 28 Jun 2012 07:58:24 +0000 (16:58 +0900)
[Type] bug fix
[Module] emulator manager
[Priority] major
[Jira#] N_SE-2131
[Redmine#]
[Problem]
[Cause]
[Solution]
[TestCase]

src/org/tizen/emulator/manager/vms/Creator.java

index 583fe01..cc71bce 100644 (file)
@@ -111,6 +111,10 @@ public class Creator {
        }
 
        private void createDiskImage() throws VMsCreatorException {
+               if (newVM.baseImagePath != null) {
+                       checkCustomBaseImage(newVM.baseImagePath);
+               }
+
                if (newVM.baseImagePath == null || newVM.baseImagePath.isEmpty()) {
                        newVM.baseImagePath = FileIO.getInstance().getBaseimgPath();
                }
@@ -124,6 +128,99 @@ public class Creator {
                createInitialVMImageInternal(newVM.baseImagePath, targetPath);
        }
 
+       private boolean isError          = false;
+       private String errorMsg          = null;
+       private void checkCustomBaseImage(final String path) throws VMsCreatorException {
+               String exe_path = FileIO.getInstance().getBinPath() + File.separator + "qemu-img";
+
+               List<String> cmd = new ArrayList<String>();
+               cmd.add(exe_path);
+               cmd.add("info");
+               cmd.add(path);
+
+               ProcessBuilder pb = new ProcessBuilder(cmd);
+               try {
+                       Process process = pb.start();
+                       if (process != null) {
+                               final BufferedReader error = new BufferedReader(new InputStreamReader(process.getErrorStream()));
+                               final BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()));
+                               new Thread(new Runnable() {
+                                       public void run() {
+                                               try {
+                                                       String str = null;
+                                                       do {
+                                                               str = error.readLine();
+                                                               if (str!= null) {
+                                                                       isError  = true;
+                                                                       EMLogger.getLogger().log(Level.WARNING,
+                                                                                       "Failed check base image...(from qemu-img)\n" + str);
+                                                               }
+                                                       } while (str != null);
+                                               } catch (IOException e) {
+                                                       isError  = true;
+                                                       EMLogger.getLogger().log(Level.WARNING,
+                                                                       "Failed check base image...\n" + e.getMessage());
+                                               }
+                                       }
+                               }).start();
+
+                               new Thread(new Runnable() {
+                                       public void run() {
+                                               try {
+                                                       String str = null;
+                                                       do {
+                                                               str = input.readLine();
+                                                               if (str != null) {
+                                                                       if (str.contains("format")) {
+                                                                               if (!str.contains("qcow2")) {
+                                                                                       isError = true;
+                                                                                       errorMsg = "Format of base image is not avaliable.\nBase image path :" + path;
+                                                                                       break;
+                                                                               }
+                                                                       } else if (str != null && str.contains("backing file")) {
+                                                                               isError = true;
+                                                                               errorMsg = "Base image is child image of other base image.\n" +
+                                                                                                       "This image is not using as base image.\n";
+                                                                               break;
+                                                                       }
+                                                               }
+                                                       } while (str != null);
+                                               } catch (IOException e) {
+                                                       isError  = true;
+                                                       EMLogger.getLogger().log(Level.WARNING,
+                                                                       "Failed check base image...\n" + e.getMessage());
+                                               }
+                                       }
+                               }).start();
+
+                               // wait for ending process
+                               try {
+                                       if (process.waitFor() != 0){
+                                               isError = true;
+                                               EMLogger.getLogger().log(Level.WARNING,
+                                                               "Error while running 'qemu-img'. Exit value : " + process.exitValue());
+                                               errorMsg = "Error while running 'qemu-img'. Exit value : " + process.exitValue() +
+                                                               "\nYou can get more information in log file ("
+                                                               + FileIO.getInstance().getTizenVmsArchPath() +  File.separator + "emulator-manager)";
+                                       }
+                               } catch (InterruptedException e) {
+                                       isError  = true;
+                                       EMLogger.getLogger().log(Level.WARNING,
+                                                       "Error while running 'qemu-img'.\n" + e.getMessage());
+                               }
+
+                               if (isError) {
+                                       if (errorMsg == null) {
+                                               errorMsg = "Failed check base image...\nPlease, select base image again.";
+                                       }
+                                       throw new VMsCreatorException(errorMsg);
+                               }
+                       }
+               } catch (IOException e) {
+                       throw new VMsCreatorException("Failed check base image..." + e.getMessage());
+               }
+       }
+
        public void createInitialVMImageInternal(String baseImagePath, String targetImagePath) throws VMsCreatorException {
                String exe_path = FileIO.getInstance().getBinPath() + File.separator + "qemu-img";
 
@@ -151,12 +248,12 @@ public class Creator {
                                                                str = in.readLine();
                                                                if (str!= null) {
                                                                        EMLogger.getLogger().log(Level.WARNING,
-                                                                               "Error while running qemu-img\n" + str);
+                                                                               "Error while running 'qemu-img'\n" + str);
                                                                }
                                                        } while (str != null);
                                                } catch (IOException e) {
                                                        EMLogger.getLogger().log(Level.WARNING,
-                                                                       "Error while running qemu-img\n" + e.getMessage());
+                                                                       "Error while running 'qemu-img'\n" + e.getMessage());
                                                }
                                        }
                                }).start();
@@ -164,7 +261,8 @@ public class Creator {
                                // wait for ending process
                                try {
                                        if (process.waitFor() != 0){
-                                               throw new VMsCreatorException("Failed to create the VM because of failed qemu-img processing.\n"
+                                               throw new VMsCreatorException("Failed to create the VM because of failed qemu-img processing.(Exit vlaue: " +
+                                                               + process.exitValue() +")\n"
                                                                + "You can get more information in log file ("
                                                                + FileIO.getInstance().getTizenVmsArchPath() +  File.separator + "emulator-manager)");
                                        }