X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/hpcvm.git/blobdiff_plain/a5033b66e150c1f5a03008abb71408b1700337aa..d83793da6e881ebab006a50a47fbba914e65f9cf:/src/and/hpcvm/Client.java diff --git a/src/and/hpcvm/Client.java b/src/and/hpcvm/Client.java index 66a43c3..793d066 100644 --- a/src/and/hpcvm/Client.java +++ b/src/and/hpcvm/Client.java @@ -85,6 +85,12 @@ public class Client extends UnicastRemoteObject implements ServicesClient System.err.println( "Problem with semaphore acquiring!" ) ; e2.printStackTrace() ; } + + // Checking first start + if( machine.checkVmx() == 1 ) + { + return 1 ; + } boolean ret = true ; int retry = 0 ; @@ -561,41 +567,43 @@ public class Client extends UnicastRemoteObject implements ServicesClient e1.printStackTrace() ; } - if( ! isRestartedSave ) +// if( ! isRestartedSave ) +// { +// /** Restoring the original vmx file (necessary after a crash) **/ +// command = new String[]{ "/bin/cp", +// working_directory + "/" + machine.getDirectory() + "/" + machine.getVmx_name_normal(), +// working_directory + "/" + machine.getDirectory() + "/" + machine.getVmx_name() } ; +// +// try { +// Process p = Runtime.getRuntime().exec( command ) ; +// p.waitFor() ; +// +// if( p.exitValue() == 0 ) +// { +// System.out.println( "Successfully replaced the VMX file." ) ; +// sema.release() ; +// emergencyStop = false ; +// return 0 ; +// } else { +// System.err.println( "Unsuccessful replacement of the VMX file!" ) ; +//// printProcessError( p.getErrorStream() ) ; +// printProcessError( p ) ; +// sema.release() ; +// return 1 ; +// } +// } catch( IOException e ) { +// System.err.println( "Error during VMX file replacement: " ) ; +// e.printStackTrace() ; +// sema.release() ; +// return 1 ; +// } catch( InterruptedException e ) { +// e.printStackTrace() ; +// sema.release() ; +// return 1 ; +// } +// } else { + if( machine.checkVmx() == 0 ) { - /** Restoring the original vmx file (necessary after a crash) **/ - command = new String[]{ "/bin/cp", - working_directory + "/" + machine.getDirectory() + "/" + machine.getVmx_name_normal(), - working_directory + "/" + machine.getDirectory() + "/" + machine.getVmx_name() } ; - - try { - Process p = Runtime.getRuntime().exec( command ) ; - p.waitFor() ; - - if( p.exitValue() == 0 ) - { - System.out.println( "Successfully replaced the VMX file." ) ; - sema.release() ; - emergencyStop = false ; - return 0 ; - } else { - System.err.println( "Unsuccessful replacement of the VMX file!" ) ; -// printProcessError( p.getErrorStream() ) ; - printProcessError( p ) ; - sema.release() ; - return 1 ; - } - } catch( IOException e ) { - System.err.println( "Error during VMX file replacement: " ) ; - e.printStackTrace() ; - sema.release() ; - return 1 ; - } catch( InterruptedException e ) { - e.printStackTrace() ; - sema.release() ; - return 1 ; - } - } else { sema.release() ; emergencyStop = false ; return 0 ; @@ -795,60 +803,51 @@ public class Client extends UnicastRemoteObject implements ServicesClient if( isRestartedSave ) { // Using the specific vmx file - System.out.print( "Changing VMX file after crash ... " ) ; - - String[] command = new String[]{ "/bin/cp", - working_directory + "/" + machine.getDirectory() + "/" + machine.getVmx_name_crash(), - working_directory + "/" + machine.getDirectory() + "/" + machine.getVmx_name() } ; + machine.setDeployFault( true ) ; + // Writing the restarted save mark try { - Process p = Runtime.getRuntime().exec( command ) ; - p.waitFor() ; - - if( p.exitValue() == 0 ) - { - System.out.println( "Successfully replaced the VMX file." ) ; - } else { - System.err.println( "Unsuccessful replacement of the VMX file!" ) ; -// printProcessError( p.getErrorStream() ) ; - printProcessError( p ) ; - - return 1 ; - } - } catch( IOException e ) { - System.err.println( "Error during VMX file replacement: " ) ; - e.printStackTrace() ; - } catch( InterruptedException e ) { - e.printStackTrace() ; - } - - // Removing lock files - System.out.print( "Removing lock files ... " ) ; - - command = new String[]{ "/bin/rm", "-rf", - working_directory + "/" + machine.getDirectory() - + "/" + machine.getVmx_name() + ".lck" } ; + FileWriter fw = new FileWriter( new File( working_directory + "/" + machine.getDirectory() + "/fault.hpcvm" ) ) ; + fw.write( "fault!" ) ; + fw.flush() ; + fw.close() ; + fw = null ; + } catch( IOException e1 ) { + e1.printStackTrace() ; + System.err.println( "Unable to mark the fault!" ) ; + } - try { - Process p = Runtime.getRuntime().exec( command ) ; - p.waitFor() ; - - if( p.exitValue() == 0 ) - { - System.out.println( "Successfully deleted lock files." ) ; - } else { - System.err.println( "Unsuccessful deletion of lock files!" ) ; -// printProcessError( p.getErrorStream() ) ; - printProcessError( p ) ; - - return 1 ; - } - } catch( IOException e ) { - System.err.println( "Error during lock files deletion: " ) ; - e.printStackTrace() ; - } catch( InterruptedException e ) { - e.printStackTrace() ; + if( machine.checkVmx() == 1 ) + { + return 1 ; } + +// System.out.print( "Changing VMX file after crash ... " ) ; +// +// String[] command = new String[]{ "/bin/cp", +// working_directory + "/" + machine.getDirectory() + "/" + machine.getVmx_name_crash(), +// working_directory + "/" + machine.getDirectory() + "/" + machine.getVmx_name() } ; +// +// try { +// Process p = Runtime.getRuntime().exec( command ) ; +// p.waitFor() ; +// +// if( p.exitValue() == 0 ) +// { +// System.out.println( "Successfully replaced the VMX file." ) ; +// } else { +// System.err.println( "Unsuccessful replacement of the VMX file!" ) ; +//// printProcessError( p.getErrorStream() ) ; +// printProcessError( p ) ; +// +// return 1 ; +// } +// } catch( IOException e ) { +// System.err.println( "Error during VMX file replacement: " ) ; +// e.printStackTrace() ; +// } catch( InterruptedException e ) { +// e.printStackTrace() ; +// } /** Retrieving VM assigned IP **/ String vmIP = null ; @@ -871,6 +870,8 @@ public class Client extends UnicastRemoteObject implements ServicesClient { if( sendSaveOkVM() == 0 ) { + date_last_save = System.currentTimeMillis() ; + return 0 ; } } else { @@ -1104,6 +1105,8 @@ public class Client extends UnicastRemoteObject implements ServicesClient // if( ! error ) // { if( sendSaveOkVM() == 1 ) { error = true ; } + + // } // /** Deletion of the tar archive **/ @@ -1146,24 +1149,29 @@ public class Client extends UnicastRemoteObject implements ServicesClient return 1 ; } - boolean ok = true ; - ArrayList sn = machine.getSaveNeighbors() ; for( int i = 0 ; i < sn.size() ; i++ ) { - System.out.print( "Sending save to " + sn.get( i ) + " ... " ) ; + String name ; + String wd ; + String snIP ; + try { - command = new String[]{ "/usr/bin/scp", working_directory + "/" + saveName, - sn.get( i ).getIPHost() + ":" - + sn.get( i ).getWorkingDirectory() } ; - } catch( RemoteException e1 ) { - System.err.println( "Unable to retrieve save neighbor information!" ) ; - e1.printStackTrace() ; - ok = false ; + name = sn.get( i ).getName() ; + wd = sn.get( i ).getWorkingDirectory() ; + snIP = sn.get( i ).getIPHost() ; + } catch (RemoteException e2) { + System.err.println( "Unable to retrieve information on one save neighbor!" ) ; + e2.printStackTrace() ; + continue ; } + + System.out.print( "Sending save to " + name + " ... " ) ; + + command = new String[]{ "/usr/bin/scp", working_directory + "/" + saveName, + snIP + ":" + wd } ; - if( ok ) try { procSave = Runtime.getRuntime().exec( command ) ; procSave.waitFor() ; @@ -1607,6 +1615,8 @@ public class Client extends UnicastRemoteObject implements ServicesClient /* Starting the VM save */ saveVM() ; + + date_last_save = System.currentTimeMillis() ; } else { sendSaveOkVM() ; } @@ -1668,8 +1678,8 @@ public class Client extends UnicastRemoteObject implements ServicesClient @Override public void saveOk() { - String save_name = machine.getName() + "_" + machine.getComputationId() + - "_last.tar.gz" ; + String save_name = machine.getName() + "_last_" + machine.getComputationId() + + ".tar.gz" ; String save_new = machine.getName() + "_new_" + machine.getComputationId() + ".tar.gz" ; @@ -1715,6 +1725,22 @@ public class Client extends UnicastRemoteObject implements ServicesClient } } + // Informing the server + int ret = 1 ; + try { + ret = LocalHost.Instance().getServerStub().changeSaveName( LocalHost.Instance().getIP(), save_name ) ; + } catch( RemoteException e ) { + System.err.println( "Unable to inform the server about the new save name!" ) ; + e.printStackTrace() ; + } + + if( ret == 0 ) + { + System.out.println( "Successfully informing the server about the new save name." ) ; + } else { + System.err.println( "Problem on the server while informing it about the new save name!" ) ; + } + // Ok here lastSaveOk = true ; } @@ -1847,7 +1873,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient @Override - public void replaceSavingNeighbor( ServicesClient _old, ServicesClient _new ) + public void replaceSavingNeighbor( String _old, ServicesClient _new ) { System.out.print( "Replacing a save neihgbor ... " ) ; if( _old != null && _new != null ) @@ -1857,7 +1883,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient for( i = 0 ; i < machine.getSaveNeighbors().size() ; i++ ) { try { - if( machine.getSaveNeighbors().get( i ).getIPHost().equalsIgnoreCase( _old.getIPVM() ) ) + if( machine.getSaveNeighbors().get( i ).getIPHost().equalsIgnoreCase( _old ) ) { machine.getSaveNeighbors().set( i, _new ) ; System.out.println( "Save neighbor successfully changed." ) ; @@ -1990,6 +2016,40 @@ public class Client extends UnicastRemoteObject implements ServicesClient } + public Integer deployVM( String _name, String _archive, String _directory ) + { + if( _name != null && _name.length() > 0 && _archive != null && _name.length() > 0 ) + { + File file = new File( working_directory + "/" + _archive ) ; + if( ! file.exists() ) + { + System.err.println( "There is no archive named " + _archive + " in my working directory!" ) ; + file = null ; + return 2 ; + } else if( file.isDirectory() ) { + System.err.println( _archive + " is a directory!" ) ; + file = null ; + return 1 ; + } + + file = null ; + + machine.setName( _name ) ; + machine.setInitial_archive_name( _archive ) ; + machine.setDirectory( _directory ) ; + + if( machine.deployInitialVM() == 1 ) + { + System.err.println( "Unable to deploy the initial VM archive!" ) ; + } else { + return 0 ; + } + } + + return 1 ; + } + + private class SaveProcess { boolean status ;