X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/hpcvm.git/blobdiff_plain/7cb1767605817324506b7500a36cf650bebcd010..HEAD:/src/and/hpcvm/Client.java diff --git a/src/and/hpcvm/Client.java b/src/and/hpcvm/Client.java index 3de9f2a..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,15 +934,6 @@ 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 ; -// String arch = "" ; File file = new File( working_directory + "/" + machine.getName() + "_new_" + machine.getComputationId() + ".tar.gz" ) ; if( file.exists() ) @@ -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() ; @@ -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() @@ -1373,12 +1337,14 @@ public class Client extends UnicastRemoteObject implements ServicesClient } catch( RemoteException e1 ) { System.err.println( "Unable to ping the server!" ) ; e1.printStackTrace() ; + yield() ; } try { sleep( 2000 ) ; } catch( InterruptedException e ) { e.printStackTrace() ; + yield() ; } } } @@ -1403,15 +1369,10 @@ public class Client extends UnicastRemoteObject implements ServicesClient 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,8 +1389,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient } catch( IOException e ) { System.err.println( "Unable to launch the SocketServer on port " + dialog_port + "!" ) ; e.printStackTrace() ; - - go = false ; + System.exit( 1 ) ; } while( go ) @@ -1438,11 +1398,11 @@ public class Client extends UnicastRemoteObject implements ServicesClient socket = serverSocket.accept() ; new DialogVM( socket ).start() ; -// dialogs.add( new DialogVM( socket ) ) ; -// dialogs.get( dialogs.size() - 1 ).start() ; + } catch( IOException e ) { System.err.println( "Problem with the accept function!" ) ; e.printStackTrace() ; + yield() ; } } } @@ -1451,24 +1411,11 @@ public class Client extends UnicastRemoteObject implements ServicesClient private class DialogVM extends Thread { - protected boolean go ; private Socket socket ; private BufferedReader reader ; private String line ; - DialogVM( Socket _socket ) { go = true ; socket = _socket ; } - - protected void stopDialogVM() - { - go = false ; - - try { - reader.close() ; reader = null ; - socket.close() ; socket = null ; - } catch( IOException e ) { - e.printStackTrace() ; - } - } + DialogVM( Socket _socket ) { socket = _socket ; } @Override public void run() @@ -1477,106 +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( go ) - { - 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( go && 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 ; - - go = 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( go && 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 ; - - go = false ; - - saveRequest.setStatus( false ) ; - - /* Requesting the VM save */ - saveVM() ; - } else { - sendSaveOkVM() ; - } - } - - - /** Computation is done, we can shutdown the VM **/ - if( go && 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 ; - - go = 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 ) { - go = false ; - 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() ; } } } @@ -1584,7 +1554,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient @Override public void stop() { - stopVM() ; + stopVM( 0 ) ; pingServer.stopPing() ;