From 0618de54e48145fe43ba8395b17632a7fa6a9a55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Constantino=20V=C3=A1zquez=20Blanco?= Date: Tue, 14 Jul 2009 15:56:02 +0000 Subject: [PATCH] Migrate VMWare VMs working. Debug optional in IM VMWare drivers. git-svn-id: http://svn.opennebula.org/one/trunk@688 3034c82b-c49b-4eb3-8279-a7acafdc01c0 --- src/im_mad/vmware/OneImVmware.java | 26 +++- src/im_mad/vmware/one_im_vmware | 4 +- src/vmm_mad/vmware/OneVmmVmware.java | 147 +++++------------------ src/vmm_mad/vmware/OperationsOverVM.java | 4 +- 4 files changed, 55 insertions(+), 126 deletions(-) diff --git a/src/im_mad/vmware/OneImVmware.java b/src/im_mad/vmware/OneImVmware.java index c4a17fcbd4..49f253302d 100644 --- a/src/im_mad/vmware/OneImVmware.java +++ b/src/im_mad/vmware/OneImVmware.java @@ -30,10 +30,15 @@ class OneImVmware extends Thread private String[] arguments; + boolean debug; + + // Entry point - main procedure public static void main(String[] args) { + boolean debug_flag; + // first, make redirection PrintStream stdout = System.out; @@ -41,13 +46,25 @@ class OneImVmware extends Thread System.setOut(stderr); System.setErr(stdout); - OneImVmware oiv = new OneImVmware(args); + + if (System.getProperty("debug").equals("1")) + { + debug_flag=true; + } + else + { + debug_flag=false; + } + + OneImVmware oiv = new OneImVmware(args,debug_flag); oiv.loop(); } // Constructor - OneImVmware(String[] args) + OneImVmware(String[] args,boolean _debug) { + debug = _debug; + arguments = args; } @@ -192,7 +209,10 @@ class OneImVmware extends Thread catch(Exception e) { System.out.println("Failed monitoring host " + hostToMonitor); - e.printStackTrace(); + if(debug) + { + e.printStackTrace(); + } System.err.println("MONITOR FAILURE " + hid_str + " Failed monitoring host " + hostToMonitor + ". Please check the VM log."); diff --git a/src/im_mad/vmware/one_im_vmware b/src/im_mad/vmware/one_im_vmware index 1a5f672a1e..7b6d0c2ff9 100755 --- a/src/im_mad/vmware/one_im_vmware +++ b/src/im_mad/vmware/one_im_vmware @@ -47,9 +47,9 @@ fi # Execute the actual MAD if [ -n "${ONE_MAD_DEBUG}" ]; then - exec nice -n $PRIORITY java -cp $ONE_LOCATION/lib/mads:$CLASSPATH -Ddatastore=$VMWARE_DATASTORE -Ddatacenter=$VMWARE_DATACENTER -Djavax.net.ssl.trustStore=$VMWARE_TRUSTORE -Xmx1024M $MAD_FILE $* 2>> $MAD_LOG_PATH + exec nice -n $PRIORITY java -cp $ONE_LOCATION/lib/mads:$CLASSPATH -Ddebug=$ONE_MAD_DEBUG -Ddatastore=$VMWARE_DATASTORE -Ddatacenter=$VMWARE_DATACENTER -Djavax.net.ssl.trustStore=$VMWARE_TRUSTORE -Xmx1024M $MAD_FILE $* 2>> $MAD_LOG_PATH else - exec nice -n $PRIORITY java -cp $ONE_LOCATION/lib/mads:$CLASSPATH -Ddatastore=$VMWARE_DATASTORE -Ddatacenter=$VMWARE_DATACENTER -Djavax.net.ssl.trustStore=$VMWARE_TRUSTORE -Xmx1024M $MAD_FILE $* 2> /dev/null + exec nice -n $PRIORITY java -cp $ONE_LOCATION/lib/mads:$CLASSPATH -Ddebug=$ONE_MAD_DEBUG -Ddatastore=$VMWARE_DATASTORE -Ddatacenter=$VMWARE_DATACENTER -Djavax.net.ssl.trustStore=$VMWARE_TRUSTORE -Xmx1024M $MAD_FILE $* 2> /dev/null fi diff --git a/src/vmm_mad/vmware/OneVmmVmware.java b/src/vmm_mad/vmware/OneVmmVmware.java index 3524e69652..ba3ec79f0e 100644 --- a/src/vmm_mad/vmware/OneVmmVmware.java +++ b/src/vmm_mad/vmware/OneVmmVmware.java @@ -27,7 +27,8 @@ class OneVmmVmware extends Thread { private String[] arguments; OperationsOverVM oVM; - + DeployVM dVM; + boolean debug; // Helpers from VI samples @@ -147,7 +148,7 @@ class OneVmmVmware extends Thread ParseXML pXML = new ParseXML(fileName); // First, register the VM - DeployVM dVM = new DeployVM(arguments, + dVM = new DeployVM(arguments, hostName, vid_str, pXML, @@ -334,6 +335,17 @@ class OneVmmVmware extends Thread System.err.println(action + " FAILURE " + vid_str + " Failed suspending VM in host " + hostName); } + continue; + } + + if(!oVM.deregisterVM(vmName)) + { + synchronized (System.err) + { + System.err.println(action + " FAILURE " + vid_str + " Failed deregistering of " +vmName + + " in host " + hostName +"."); + } + continue; } else { @@ -422,6 +434,17 @@ class OneVmmVmware extends Thread try { oVM = new OperationsOverVM(arguments,hostName); + + dVM = new DeployVM(arguments, + hostName, + vmName, + System.getProperty("datastore"), + System.getProperty("datacenter")); + + if(!dVM.registerVirtualMachine()) + { + // We will skip this error, it may be pre-registered + } } catch(Exception e) { @@ -476,125 +499,11 @@ class OneVmmVmware extends Thread if (action.equals("MIGRATE")) { - if (str_split.length < 4) + synchronized (System.err) { - System.out.println("FAILURE Wrong number of arguments for MIGRATE " + - "action. Number args = [" + str_split.length + "]."); - synchronized (System.err) - { - System.err.println(action + " FAILURE " + vid_str); - continue; - } - } - else - { - vid_str = str_split[1]; - String sourceHostName = str_split[2]; - String vmName = str_split[3]; - String destHostName = str_split[4]; - - // First, create the checkpoint - - try - { - oVM = new OperationsOverVM(arguments,sourceHostName); - } - catch(Exception e) - { - synchronized (System.err) - { - System.err.println(action + " FAILURE " + vid_str + " Failed connection to host " + - sourceHostName +". Reason: " + e.getMessage()); - if(debug) - { - e.printStackTrace(); - } - } - continue; - } - - // First, checkpoint the running virtual machine - - if(!oVM.save(vmName)) - { - synchronized (System.err) - { - System.err.println(action + " FAILURE " + vid_str + " Failed saving VM in host " + - sourceHostName); - continue; - } - } - - // Now, we stop it - - if(!oVM.powerOff(vmName)) - { - synchronized (System.err) - { - System.err.println(action + " FAILURE " + vid_str + " Failed shutdown VM in host " + - sourceHostName); - } - } - - // Now, register machine in new host - - DeployVM dVM; - try - { - oVM = new OperationsOverVM(arguments,destHostName); - dVM = new DeployVM(arguments, - destHostName, - vmName, - System.getProperty("datastore"), - System.getProperty("datacenter")); - - if(!dVM.registerVirtualMachine()) - { - // We will skip this error, it may be pre-registered - } - - // Power it On - - if(!oVM.powerOn(vmName)) - { - throw new Exception(); - } - } - catch(Exception e) - { - synchronized (System.err) - { - System.err.println(action + " FAILURE " + vid_str + " Failed registering VM [" - + vmName + "] in host " + destHostName); - if(debug) - { - e.printStackTrace(); - } - } - continue; - } - - - // Restore the virtual machine checkpoint - - if(!oVM.restoreCheckpoint(vmName)) - { - synchronized (System.err) - { - System.err.println(action + " FAILURE " + vid_str + " Failed restoring VM [" + - vmName + "] in host " + destHostName); - } - } - else - { - synchronized (System.err) - { - System.err.println(action + " SUCCESS " + vid_str); - } - } - + System.err.println(action + " FAILURE " + vid_str + " Action not implemented."); continue; - } + } } // if (action.equals("MIGRATE")) if (action.equals("POLL")) diff --git a/src/vmm_mad/vmware/OperationsOverVM.java b/src/vmm_mad/vmware/OperationsOverVM.java index a9ced9848b..6ec5a9f5bc 100644 --- a/src/vmm_mad/vmware/OperationsOverVM.java +++ b/src/vmm_mad/vmware/OperationsOverVM.java @@ -183,7 +183,7 @@ public class OperationsOverVM } catch(Exception e) { - System.out.println("Error checkpointing VirtualMachine [" + vmName + "]. Reason:" + e.getMessage()); + System.out.println("Error checkpointing VirtualMachine " + vmName + ". Reason:" + e.getMessage()); return false; } } @@ -245,7 +245,7 @@ public class OperationsOverVM } catch(Exception e) { - System.out.println("Error checkpointing VirtualMachine [" + vmName + "]. Reason:" + e.getMessage()); + System.out.println("Error restoring checkpoint of VirtualMachine " + vmName + ". Reason:" + e.getMessage()); return false; } }