}
private void createDiskImage() throws VMsCreatorException {
+ if (newVM.baseImagePath != null) {
+ checkCustomBaseImage(newVM.baseImagePath);
+ }
+
if (newVM.baseImagePath == null || newVM.baseImagePath.isEmpty()) {
newVM.baseImagePath = FileIO.getInstance().getBaseimgPath();
}
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";
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();
// 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)");
}