X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/hpcvm.git/blobdiff_plain/21ced9062609ebd01b8937b54a8d5efbb9d4f7ba..7a473b4f506b5264586f090f34b21fe11531bb70:/src/and/hpcvm/Server.java diff --git a/src/and/hpcvm/Server.java b/src/and/hpcvm/Server.java index a822cf7..90a8653 100644 --- a/src/and/hpcvm/Server.java +++ b/src/and/hpcvm/Server.java @@ -94,7 +94,12 @@ public class Server extends UnicastRemoteObject implements ServicesServer super() ; } - + + public void setSaveTime( int _saveTime ) + { + save_interleave = _saveTime * 60 * 1000 ; + } + @Override public Integer register( ServicesClient _stub ) @@ -263,7 +268,8 @@ public class Server extends UnicastRemoteObject implements ServicesServer clients.get( i ).getStub().emergencyStop() ; clients.get( i ).getStub().stop() ; } catch (RemoteException e) { - e.printStackTrace(); + System.err.println( "Unable to send stop signal to " + clients.get( i ).getName() ) ; + e.printStackTrace() ; } } @@ -398,6 +404,7 @@ public class Server extends UnicastRemoteObject implements ServicesServer } catch( RemoteException e ) { System.err.println( "Unable to indicate to client to retrieve last save!" ) ; e.printStackTrace() ; + yield() ; } if( res == 0 ) @@ -425,6 +432,7 @@ public class Server extends UnicastRemoteObject implements ServicesServer } catch( RemoteException e ) { System.err.println( "Unable to set the new VM IP on the replacing client!" ) ; e.printStackTrace() ; + yield() ; } if( ok_new && ok_old ) @@ -497,7 +505,7 @@ public class Server extends UnicastRemoteObject implements ServicesServer @Override public void run() { - boolean change ; + boolean change, dead ; while( run ) { @@ -510,40 +518,57 @@ public class Server extends UnicastRemoteObject implements ServicesServer { ConnectedClient cl = it.next() ; cl.incTimeout() ; + dead = false ; - if( cl.getTimeout() > max_timeout ) + if( cl.getTimeout() > max_timeout || cl.getFail() ) { - System.out.println( "Disconnection of " + cl.getName() ) ; - if( cl.getStatus().equalsIgnoreCase( "running" ) || cl.getStatus().equalsIgnoreCase( "saving" ) ) + dead = true ; + if( ! cl.getFail() ) + { + try { + cl.getStub().echo() ; + cl.resetTimeout() ; + dead = false ; + } catch( RemoteException e ) { + dead = true ; + } + } + + if( dead ) { - System.out.println( "A VM was running on it!!" ) ; - System.out.println( "I will redeploy a save and restart all VM ..." ) ; + System.out.println( "Disconnection of " + cl.getName() ) ; + if( cl.getStatus().equalsIgnoreCase( "running" ) || cl.getStatus().equalsIgnoreCase( "saving" ) ) + { + System.out.println( "A VM was running on it!!" ) ; + System.out.println( "I will redeploy a save and restart all VM ..." ) ; -// for( int i = 0 ; i < computingClients.size() ; i++ ) -// { -// if( computingClients.get( i ).getClient().getIP().equals( cl.getIP() ) ) +// for( int i = 0 ; i < computingClients.size() ; i++ ) // { -// computingClients.remove( i ) ; -// break ; +// if( computingClients.get( i ).getClient().getIP().equals( cl.getIP() ) ) +// { +// computingClients.remove( i ) ; +// break ; +// } // } -// } - synchronized( counter ){ - counter.inc() ;} + synchronized( counter ) + { + counter.inc() ; + } - - new Server.FaultManager( cl ).start() ; - nb_disconnections_computing++ ; - } else { - System.out.println( "There was no VM running on it." ) ; - System.out.println( "Maybe it will come back later :)" ) ; - } + new Server.FaultManager( cl ).start() ; + nb_disconnections_computing++ ; + } else { + System.out.println( "There was no VM running on it." ) ; + System.out.println( "Maybe it will come back later :)" ) ; + } - synchronized( clients ) - { - it.remove() ; + synchronized( clients ) + { + it.remove() ; + } + nb_disconnections++ ; + change = true ; } - nb_disconnections++ ; - change = true ; } } @@ -577,6 +602,7 @@ public class Server extends UnicastRemoteObject implements ServicesServer } catch( RemoteException e ) { System.err.println( "Unable to invoke emergency stop signal on " + clients.get( i ).getName() ) ; e.printStackTrace() ; + yield() ; } } } @@ -596,28 +622,41 @@ public class Server extends UnicastRemoteObject implements ServicesServer counter.wait() ; } catch( InterruptedException e ) { e.printStackTrace() ; + yield() ; } } } for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ ) { - final ServicesClient sc = applications.get( ind ).getComputingClients().get( i ).getClient().getStub() ; - applications.get( ind ).getComputingClients().get( i ).setRestartOk( false ) ; - new Thread( new Runnable() { - - @Override - public void run() - { - try { - sc.restartVMAfterCrash() ; - } catch( RemoteException e ) { - e.printStackTrace() ; - } - } - } ).start() ; + new RestartVM( applications.get( ind ).getComputingClients().get( i ).getClient() ).start() ; + +// final ServicesClient sc = applications.get( ind ).getComputingClients().get( i ).getClient().getStub() ; + +// new Thread( new Runnable() { +// +// @Override +// public void run() +// { +// try { +// if( sc.restartVMAfterCrash() != 0 ) +// { +// System.err.println( "Problem while restarting VM on " +sc.getName() + "!" ) ; +// } +// } catch( RemoteException e ) { +// try { +// System.err.println( "Problem while restarting VM on " + sc.getName() + "!" ) ; +// } catch( RemoteException e1 ) { +// System.err.println( "Problem while restarting a VM!" ) ; +// e1.printStackTrace() ; +// } +// e.printStackTrace() ; +// yield() ; +// } +// } +// } ).start() ; } } @@ -626,6 +665,7 @@ public class Server extends UnicastRemoteObject implements ServicesServer Thread.sleep( 2000 ) ; } catch( InterruptedException e ) { e.printStackTrace() ; + yield() ; } } } @@ -662,7 +702,8 @@ public class Server extends UnicastRemoteObject implements ServicesServer try { computingClients.get( i ).getClient().getStub().saveOk() ; } catch (RemoteException e) { - e.printStackTrace(); + System.err.println( "Unable to invoke the saveOk method on " + computingClients.get( i ).getClient().getName() ) ; + e.printStackTrace() ; } computingClients.get( i ).setSaveStatus( false ) ; } @@ -697,6 +738,7 @@ public class Server extends UnicastRemoteObject implements ServicesServer return 1 ; } + @Override public ArrayList startApplication( int _nb ) { @@ -727,8 +769,8 @@ public class Server extends UnicastRemoteObject implements ServicesServer try { startingClients.wait() ; - } catch (InterruptedException e) { - e.printStackTrace(); + } catch( InterruptedException e ) { + e.printStackTrace() ; } } @@ -756,8 +798,8 @@ public class Server extends UnicastRemoteObject implements ServicesServer } final int indice = i ; - new Thread( new Runnable(){ - + new Thread( new Runnable() + { @Override public void run() { @@ -765,7 +807,7 @@ public class Server extends UnicastRemoteObject implements ServicesServer try { res = clients.get( indice ).getStub().startVM( 0 ) ; } catch( RemoteException e ) { - e.printStackTrace(); + e.printStackTrace() ; } if( res == 0 ) @@ -804,7 +846,7 @@ public class Server extends UnicastRemoteObject implements ServicesServer { app.setComputingClients( tmp ) ; app.setRunning( true ) ; -// app.setStartTime( System.currentTimeMillis() ) ; + app.setStartTime( System.currentTimeMillis() ) ; int index, index2 ; /* Choosing save neighbors */ @@ -1018,11 +1060,14 @@ public class Server extends UnicastRemoteObject implements ServicesServer public void goApplication() { synchronized( applications ) { - if( running && applications.get( ind ).getStartTime() != 0 ) - { - applications.get( ind ).setStartTime( System.currentTimeMillis() ) ; - applications.get( ind ).setLastSaveDate( System.currentTimeMillis() ) ; - }} + if( running && ! applications.get( ind ).getStartMark() ) + { + System.out.println( "Application is starting." ) ; + applications.get( ind ).setStartMark() ; + applications.get( ind ).setStartTime( System.currentTimeMillis() ) ; + applications.get( ind ).setLastSaveDate( System.currentTimeMillis() ) ; + } + } } @@ -1031,36 +1076,39 @@ public class Server extends UnicastRemoteObject implements ServicesServer { synchronized( applications ) { - if( running ) - { - Iterator it = computingClients.iterator() ; - - while( it.hasNext() ) + if( running ) { - ComputingClient cl = it.next() ; + applications.get( ind ).setEndTime( System.currentTimeMillis() ) ; + applications.get( ind ).setRunning( false ) ; + applications.get( ind ).clear() ; + + Iterator it = computingClients.iterator() ; + + while( it.hasNext() ) + { + ComputingClient cl = it.next() ; - try { - cl.getClient().getStub().emergencyStop() ; - } catch (RemoteException e) { - e.printStackTrace(); - } + try { + cl.getClient().getStub().emergencyStop() ; + } catch (RemoteException e) { + e.printStackTrace(); + } - cl.getClient().setStatus( "connected" ) ; - cl.getClient().setComputingClient( null ) ; - it.remove() ; - cl = null ; - } + cl.getClient().setStatus( "connected" ) ; + cl.getClient().setComputingClient( null ) ; + it.remove() ; + cl = null ; + } - applications.get( ind ).setEndTime( System.currentTimeMillis() ) ; - applications.get( ind ).setRunning( false ) ; - applications.get( ind ).clear() ; -// applications.remove( ind ) ; - running = false ; + applications.get( ind ).clear() ; + + running = false ; - System.out.println( "Application " + applications.get( ind ).getName() + " ends in " + + System.out.println( "Application " + applications.get( ind ).getName() + " ends in " + applications.get( ind ).getExecutionTime() + " seconds." ) ; - }} + } + } } @@ -1301,6 +1349,52 @@ public class Server extends UnicastRemoteObject implements ServicesServer protected int getNb() { return nb ; } } + + private class RestartVM extends Thread + { + private ConnectedClient cc ; + + protected RestartVM( ConnectedClient _cc ) + { + cc = _cc ; + } + + public void run() + { + boolean error = false ; + if( cc != null ) + { + try { + if( cc.getStub().restartVMAfterCrash() != 0 ) + { + System.err.println( "Problem while restarting VM on " + cc.getName() + "!" ) ; + error = true ; + } + } catch( RemoteException e ) { + e.printStackTrace() ; + error = true ; + yield() ; + } + } else { + System.err.println( "The client to restart is null!" ) ; + } + + if( error ) + { + cc.setFail( true ) ; + + try { + System.out.print( "Trying to stop the client ... " ) ; + cc.getStub().stop() ; + System.out.println( "successful client stop." ); + } catch( RemoteException e ) { + System.out.println( "unsuccessful client stop!" ) ; + e.printStackTrace() ; + } + } + } + } + } /** La programmation est un art, respectons ceux qui la pratiquent !! **/