X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/hpcvm.git/blobdiff_plain/f74ee61df3fbc8cf8371347069a715270a3e8a72..HEAD:/src/and/hpcvm/Client.java diff --git a/src/and/hpcvm/Client.java b/src/and/hpcvm/Client.java index 7d58da8..3153cb9 100644 --- a/src/and/hpcvm/Client.java +++ b/src/and/hpcvm/Client.java @@ -81,7 +81,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient } catch( Exception e ) {} } - stopVM() ; + stopVM( 1 ) ; } @@ -241,7 +241,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient if( ! ret ) { sema.release() ; - stopVM() ; + stopVM( 1 ) ; return 1 ; } else { retry++ ; @@ -250,7 +250,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient System.err.println( "Unable to check VM!" ) ; sema.release() ; - stopVM() ; + stopVM( 1 ) ; return 1 ; } System.out.println( "Retrying (" + retry + ") ... " ) ; @@ -261,12 +261,12 @@ public class Client extends UnicastRemoteObject implements ServicesClient } catch( IOException e ) { e.printStackTrace() ; sema.release() ; - stopVM() ; + stopVM( 1 ) ; return 1 ; } catch( InterruptedException e ) { e.printStackTrace() ; sema.release() ; - stopVM() ; + stopVM( 1 ) ; return 1 ; } @@ -283,7 +283,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient sema.release() ; - stopVM() ; + stopVM( 1 ) ; return 1 ; } else { @@ -315,7 +315,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient } catch( IOException e1 ) { e1.printStackTrace() ; sema.release() ; - stopVM() ; + stopVM( 1 ) ; return 1 ; } @@ -346,7 +346,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient if( ! ret ) { sema.release() ; - stopVM() ; + stopVM( 1 ) ; return 1 ; } else { retry++ ; @@ -355,7 +355,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient System.err.println( "Unable to send information to VM!" ) ; sema.release() ; - stopVM() ; + stopVM( 1 ) ; return 1 ; } @@ -367,12 +367,12 @@ public class Client extends UnicastRemoteObject implements ServicesClient System.err.println( "Error during execution of runScriptInGuest command: " ) ; e.printStackTrace() ; sema.release() ; - stopVM() ; + stopVM( 1 ) ; return 1 ; } catch( InterruptedException e) { e.printStackTrace() ; sema.release() ; - stopVM() ; + stopVM( 1 ) ; return 1 ; } } @@ -396,7 +396,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient } catch( IOException e1 ) { e1.printStackTrace() ; sema.release() ; - stopVM() ; + stopVM( 1 ) ; return 1 ; } @@ -428,7 +428,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient if( ! ret ) { sema.release() ; - stopVM() ; + stopVM( 1 ) ; return 1 ; } else { retry++ ; @@ -437,7 +437,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient System.err.println( "Unable to send information to VM!" ) ; sema.release() ; - stopVM() ; + stopVM( 1 ) ; return 1 ; } @@ -449,12 +449,12 @@ public class Client extends UnicastRemoteObject implements ServicesClient System.err.println( "Error during execution of runScriptInGuest command: " ) ; e.printStackTrace() ; sema.release() ; - stopVM() ; + stopVM( 1 ) ; return 1 ; } catch( InterruptedException e ) { e.printStackTrace() ; sema.release() ; - stopVM() ; + stopVM( 1 ) ; return 1 ; } } @@ -482,7 +482,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient @Override - public int stopVM() + public int stopVM( int _mode ) { if( machine != null && machine.getStatus().equalsIgnoreCase( "stopped" ) ) { @@ -505,6 +505,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient int retry = 0 ; machine.setStatus( "undefined" ) ; + if( _mode == 0 ) try { LocalHost.Instance().getServerStub().changeStatus( LocalHost.Instance().getIP(), "undefined" ) ; @@ -560,6 +561,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient } machine.setStatus( "stopped" ) ; + if( _mode == 0 ) try { LocalHost.Instance().getServerStub().changeStatus( LocalHost.Instance().getIP(), "stopped" ) ; @@ -761,7 +763,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient e.printStackTrace() ; } - if( stopVM() == 0 ) + if( stopVM( 1 ) == 0 ) { if( machine.deployLastSave() == 0 ) { @@ -819,7 +821,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient return 0 ; } } else { - stopVM() ; + stopVM( 1 ) ; } } } @@ -932,29 +934,20 @@ public class Client extends UnicastRemoteObject implements ServicesClient if( ! lastSaveOk ) { - String arch1 = "", arch2 = "" ; - File file = new File( working_directory + "/" + machine.getName() + "_new_" + machine.getComputationId() + ".tar" ) ; - if( file.exists() ) - { - arch1 = working_directory + "/" + machine.getName() + "_new_" + machine.getComputationId() + ".tar" ; - } - - file = null ; - - file = new File( working_directory + "/" + machine.getName() + "_new_" + machine.getComputationId() + ".tar.gz" ) ; + String arch = "" ; + File file = new File( working_directory + "/" + machine.getName() + "_new_" + machine.getComputationId() + ".tar.gz" ) ; if( file.exists() ) { - arch2 = working_directory + "/" + machine.getName() + "_new_" + machine.getComputationId() + ".tar.gz" ; + arch = working_directory + "/" + machine.getName() + "_new_" + machine.getComputationId() + ".tar.gz" ; } file = null ; - if( arch1.length() > 0 || arch2.length() > 0 ) + if( arch.length() > 0 ) { System.out.println( "Deletion of last nok archive ... " ) ; - command = new String[]{ "/bin/rm", "-rf", - arch1, arch2 } ; + command = new String[]{ "/bin/rm", "-rf", arch } ; try { procSave = Runtime.getRuntime().exec( command ) ; @@ -986,9 +979,9 @@ public class Client extends UnicastRemoteObject implements ServicesClient System.out.print( "Creation of the archive ... " ) ; /** Archive creation **/ - command = new String[]{ "/bin/tar", "-cf", - machine.getName() + "_new_" + machine.getComputationId() + ".tar", - machine.getDirectory(), "-C", working_directory } ; + command = new String[]{ "/bin/tar", "-cz", "-C", working_directory, + "-f", working_directory + "/" + machine.getName() + "_new_" + machine.getComputationId() + ".tar.gz", + machine.getDirectory() } ; if( emergencyStop ) { @@ -1019,42 +1012,6 @@ public class Client extends UnicastRemoteObject implements ServicesClient e.printStackTrace() ; error = true ; } - - /** Compression of the archive **/ - if( ! error ) - { - System.out.print( "Compression of the archive ... " ) ; - command = new String[]{ "/bin/gzip", - working_directory + "/" + machine.getName() - + "_new_" + machine.getComputationId() + ".tar" } ; - - if( emergencyStop ) - { - return 1 ; - } - - try { - procSave = Runtime.getRuntime().exec( command ) ; - procSave.waitFor() ; - - if( procSave.exitValue() == 0 ) - { - System.out.println( "Archive successfully compressed." ) ; - } else { - System.err.println( "Archive not compressed!" ) ; - printProcessError( procSave ) ; - - error = true ; - } - } catch( IOException e ) { - System.err.println( "Error during archive compression command: " ) ; - e.printStackTrace() ; - error = true ; - } catch( InterruptedException e ) { - e.printStackTrace() ; - error = true ; - } - } long fin = System.currentTimeMillis() ; @@ -1191,7 +1148,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient // date_last_save = 0 ; isRestartedSave = false ; - lastSaveOk = true ; + lastSaveOk = false ; /** Connection to server **/ try { @@ -1290,7 +1247,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient while( (line = br.readLine()) != null ) { System.err.println( line ) ; - if( line.contains( "egmentation" ) ) + if( line.contains( "egmentation" ) || _p.exitValue() == 139 ) { ret = true ; } @@ -1303,6 +1260,13 @@ public class Client extends UnicastRemoteObject implements ServicesClient return ret ; } + + @Override + public int echo() + { + return 0 ; + } + @Override public int start() @@ -1354,31 +1318,33 @@ public class Client extends UnicastRemoteObject implements ServicesClient private class PingServer extends Thread { - private boolean run ; + protected boolean go ; PingServer() { - run = true ; + go = true ; } - protected void stopPing() { run = false ; } + protected void stopPing() { go = false ; } @Override public void run() { - while( run ) + while( go ) { try { LocalHost.Instance().getServerStub().ping( LocalHost.Instance().getIP() ) ; } catch( RemoteException e1 ) { System.err.println( "Unable to ping the server!" ) ; e1.printStackTrace() ; + yield() ; } try { - Thread.sleep( 2000 ) ; + sleep( 2000 ) ; } catch( InterruptedException e ) { e.printStackTrace() ; + yield() ; } } } @@ -1387,31 +1353,26 @@ public class Client extends UnicastRemoteObject implements ServicesClient private class DialogVMServer extends Thread { - private boolean run ; + protected boolean go ; private Socket socket ; - private ArrayList dialogs = new ArrayList() ; +// private ArrayList dialogs = new ArrayList() ; DialogVMServer() { - run = true ; + go = true ; } protected void stopDialogVMServer() { - run = false ; + go = false ; if( serverSocket != null ) { try { - serverSocket.close() ; - - for( int i = 0 ; i < dialogs.size() ; i++ ) - { - dialogs.get( i ).stopDialogVM() ; - } - + serverSocket.close() ; } catch( IOException e ) { e.printStackTrace() ; + yield() ; } } } @@ -1428,20 +1389,20 @@ public class Client extends UnicastRemoteObject implements ServicesClient } catch( IOException e ) { System.err.println( "Unable to launch the SocketServer on port " + dialog_port + "!" ) ; e.printStackTrace() ; - - run = false ; + System.exit( 1 ) ; } - while( run ) + while( go ) { try { socket = serverSocket.accept() ; - dialogs.add( new DialogVM( socket ) ) ; - dialogs.get( dialogs.size() - 1 ).start() ; + new DialogVM( socket ).start() ; + } catch( IOException e ) { System.err.println( "Problem with the accept function!" ) ; e.printStackTrace() ; + yield() ; } } } @@ -1450,24 +1411,11 @@ public class Client extends UnicastRemoteObject implements ServicesClient private class DialogVM extends Thread { - private boolean run ; private Socket socket ; private BufferedReader reader ; private String line ; - DialogVM( Socket _socket ) { run = true ; socket = _socket ; } - - protected void stopDialogVM() - { - run = false ; - - try { - reader.close() ; reader = null ; - socket.close() ; socket = null ; - } catch( IOException e ) { - e.printStackTrace() ; - } - } + DialogVM( Socket _socket ) { socket = _socket ; } @Override public void run() @@ -1476,105 +1424,129 @@ public class Client extends UnicastRemoteObject implements ServicesClient reader = new BufferedReader( new InputStreamReader( socket.getInputStream() ) ) ; } catch( IOException e ) { System.err.println( "Unable to open a dialog socket with the VM!" ) ; - e.printStackTrace(); - stopDialogVM() ; + e.printStackTrace() ; + yield() ; } - - while( run ) - { - try { - line = null ; - - if( reader != null ) + + try { + line = null ; + + if( reader != null ) + { + line = reader.readLine() ; + } + + /** VM is starting -- retrieving informations **/ + if( line != null && line.equalsIgnoreCase( "infos" ) ) + { + /* Receiving name */ + machine.setName( reader.readLine() ) ; + + /* Receiving IP */ + String ip = reader.readLine() ; + if( ! ip.equalsIgnoreCase( machine.getIp() ) ) { - line = reader.readLine() ; + System.err.println( "VM IP not well configured!!" ) ; } - - /** VM is starting -- retrieving informations **/ - if( run && line != null && line.equalsIgnoreCase( "infos" ) ) - { - /* Receiving name */ - machine.setName( reader.readLine() ) ; - - /* Receiving IP */ - String ip = reader.readLine() ; - if( ! ip.equalsIgnoreCase( machine.getIp() ) ) - { - System.err.println( "VM IP not well configured!!" ) ; - } - - /* Close streams */ - reader.close() ; reader = null ; - socket.close() ; socket = null ; - - run = false ; - } - + + /* Close streams */ + reader.close() ; reader = null ; + socket.close() ; socket = null ; + + } else if( line != null && line.equalsIgnoreCase( "save" ) ) { /** It's time to do a save **/ - if( run && line != null && line.equalsIgnoreCase( "save" ) ) - { + + try { + machine.setComputationId( Integer.parseInt( reader.readLine() ) ) ; + } catch( Exception e ) { + System.err.println( "Problem while reading the computation id!" ) ; + e.printStackTrace() ; + } + + synchronized( saveRequest ) + { try { - machine.setComputationId( Integer.parseInt( reader.readLine() ) ) ; - } catch( Exception e ) { - System.err.println( "Problem while reading the computation id!" ) ; + LocalHost.Instance().getServerStub().requestSave( LocalHost.Instance().getIP() ) ; + } catch( RemoteException e ) { + System.err.println( "Unable to request save to server!" ) ; e.printStackTrace() ; } - - synchronized( saveRequest ) - { - try { - LocalHost.Instance().getServerStub().requestSave( LocalHost.Instance().getIP() ) ; - } catch( RemoteException e ) { - System.err.println( "Unable to request save to server!" ) ; - e.printStackTrace() ; - } - - try { - saveRequest.wait() ; - } catch( InterruptedException e ) { - e.printStackTrace(); - } - } - - if( saveRequest.getStatus() ) - { - /* Close streams */ - reader.close() ; reader = null ; - socket.close() ; socket = null ; - - run = false ; - - saveRequest.setStatus( false ) ; - - /* Requesting the VM save */ - saveVM() ; - } else { - sendSaveOkVM() ; - } - } - - - /** Computation is done, we can shutdown the VM **/ - if( run && line != null && line.equalsIgnoreCase( "quit" ) ) - { + try { - Thread.sleep( 5000 ) ; + saveRequest.wait() ; } catch( InterruptedException e ) { - e.printStackTrace() ; + e.printStackTrace(); } - + } + + if( saveRequest.getStatus() ) + { /* Close streams */ reader.close() ; reader = null ; socket.close() ; socket = null ; - - run = false ; - - stopVM() ; + + saveRequest.setStatus( false ) ; + + /* Requesting the VM save */ + if( saveVM() == 1 ) + { + System.err.println( "Problem while saving. Exiting ..." ) ; + pingServer.stopPing() ; + emergencyStop() ; + System.exit( 1 ) ; + } + } else { + sendSaveOkVM() ; + } + } else if( line != null && line.equalsIgnoreCase( "quit" ) ) { + /** Computation is done, we can shutdown the VM **/ + + try { + Thread.sleep( 5000 ) ; + } catch( InterruptedException e ) { + e.printStackTrace() ; + } + + /* Close streams */ + reader.close() ; reader = null ; + socket.close() ; socket = null ; + + stopVM( 0 ) ; + + machine.setStatus( "connected" ) ; + try { + LocalHost.Instance().getServerStub().changeStatus( + LocalHost.Instance().getIP(), "connected" ) ; + } catch( RemoteException e ) { + System.err.println( "Unable to inform the server of the VM status!" ) ; + e.printStackTrace() ; } - } catch( IOException e ) { - e.printStackTrace() ; + try { + LocalHost.Instance().getServerStub().endApplication() ; + } catch( RemoteException e ) { + System.err.println( "Unable to inform the server of the end of application!" ) ; + e.printStackTrace() ; + } + } else if( line != null && line.equalsIgnoreCase( "start" ) ) { + /** Computation is starting **/ + + /* Close streams */ + reader.close() ; reader = null ; + socket.close() ; socket = null ; + System.out.println( "Application is starting." ) ; + + try { + LocalHost.Instance().getServerStub().goApplication() ; + } catch( RemoteException e ) { + System.err.println( "Unable to inform the server of the end of application!" ) ; + e.printStackTrace() ; + } } + + } catch( IOException e ) { + e.printStackTrace() ; + yield() ; } } } @@ -1582,7 +1554,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient @Override public void stop() { - stopVM() ; + stopVM( 0 ) ; pingServer.stopPing() ;