From: Sébastien Miquée Date: Tue, 2 Aug 2011 02:03:09 +0000 (+0200) Subject: Adding missing handler when a restart crash. X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/hpcvm.git/commitdiff_plain/c7a7de23c20d2c7403729e149aeab1f0a832a4fc?ds=sidebyside Adding missing handler when a restart crash. --- diff --git a/src/and/hpcvm/Client.java b/src/and/hpcvm/Client.java index 662944e..232a58c 100644 --- a/src/and/hpcvm/Client.java +++ b/src/and/hpcvm/Client.java @@ -1245,7 +1245,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 ; } @@ -1258,6 +1258,13 @@ public class Client extends UnicastRemoteObject implements ServicesClient return ret ; } + + @Override + public int echo() + { + return 0 ; + } + @Override public int start() @@ -1479,7 +1486,13 @@ public class Client extends UnicastRemoteObject implements ServicesClient saveRequest.setStatus( false ) ; /* Requesting the VM save */ - saveVM() ; + if( saveVM() == 1 ) + { + System.err.println( "Problem while saving. Exiting ..." ) ; + pingServer.stopPing() ; + emergencyStop() ; + System.exit( 1 ) ; + } } else { sendSaveOkVM() ; } diff --git a/src/and/hpcvm/ComputingClient.java b/src/and/hpcvm/ComputingClient.java index b71b748..b9c654c 100644 --- a/src/and/hpcvm/ComputingClient.java +++ b/src/and/hpcvm/ComputingClient.java @@ -17,6 +17,7 @@ public class ComputingClient implements Serializable private String lastSaveName ; private boolean saveRequest ; private boolean restartOk ; + private boolean fail ; ComputingClient( ConnectedClient cl ) { @@ -26,8 +27,13 @@ public class ComputingClient implements Serializable lastSaveName = "none" ; saveRequest = false ; restartOk = false ; + fail = false ; } + protected void setFail( boolean _b ) { fail = _b ; } + + protected boolean getFail() { return fail ; } + protected void setRestartOk( boolean _b ) { restartOk = _b ; } protected boolean getRestartOk() { return restartOk ; } diff --git a/src/and/hpcvm/ConnectedClient.java b/src/and/hpcvm/ConnectedClient.java index a3263dd..969c997 100644 --- a/src/and/hpcvm/ConnectedClient.java +++ b/src/and/hpcvm/ConnectedClient.java @@ -27,7 +27,25 @@ public class ConnectedClient implements Serializable } cl = null ; } + + protected boolean getFail() + { + if( cl != null ) + { + return cl.getFail() ; + } + + return false ; + } + protected void setFail( boolean _b ) + { + if( cl != null ) + { + cl.setFail( _b ) ; + } + } + protected ServicesClient getStub() { return stub ; } protected void setStub( ServicesClient _stub ) { stub = _stub ; } diff --git a/src/and/hpcvm/Server.java b/src/and/hpcvm/Server.java index b703aa7..185b5f3 100644 --- a/src/and/hpcvm/Server.java +++ b/src/and/hpcvm/Server.java @@ -500,7 +500,7 @@ public class Server extends UnicastRemoteObject implements ServicesServer @Override public void run() { - boolean change ; + boolean change, dead ; while( run ) { @@ -513,41 +513,55 @@ 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" ) ) + if( ! cl.getFail() ) { - System.out.println( "A VM was running on it!!" ) ; - System.out.println( "I will redeploy a save and restart all VM ..." ) ; + try { + cl.getStub().echo() ; + cl.resetTimeout() ; + } catch( RemoteException e ) { + dead = true ; + } + } + + if( dead ) + { + 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 ; } } @@ -610,21 +624,32 @@ public class Server extends UnicastRemoteObject implements ServicesServer { applications.get( ind ).getComputingClients().get( i ).setRestartOk( false ) ; - final ServicesClient sc = applications.get( ind ).getComputingClients().get( i ).getClient().getStub() ; + new RestartVM( applications.get( ind ).getComputingClients().get( i ).getClient() ).start() ; - new Thread( new Runnable() { - - @Override - public void run() - { - try { - sc.restartVMAfterCrash() ; - } catch( RemoteException e ) { - e.printStackTrace() ; - yield() ; - } - } - } ).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() ; } } @@ -1041,36 +1066,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() ; - System.out.println( "Application " + applications.get( ind ).getName() + " ends in " + + running = false ; + + System.out.println( "Application " + applications.get( ind ).getName() + " ends in " + applications.get( ind ).getExecutionTime() + " seconds." ) ; - }} + } + } } @@ -1311,6 +1339,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 !! **/ diff --git a/src/and/hpcvm/ServicesClient.java b/src/and/hpcvm/ServicesClient.java index fffec81..438af96 100644 --- a/src/and/hpcvm/ServicesClient.java +++ b/src/and/hpcvm/ServicesClient.java @@ -8,6 +8,8 @@ public interface ServicesClient extends Remote { public void emergencyStop() throws RemoteException ; + public int echo() throws RemoteException ; + public int startVM( int _mode ) throws RemoteException ; public int stopVM() throws RemoteException ;