Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Refunding the restart mechanism.
authorSébastien Miquée <sebastien.miquee@univ-fcomte.fr>
Fri, 8 Jul 2011 15:02:15 +0000 (17:02 +0200)
committerSébastien Miquée <sebastien.miquee@univ-fcomte.fr>
Fri, 8 Jul 2011 15:02:15 +0000 (17:02 +0200)
  - adding the running application class
  - changing management of time_of_last_save (in running application now)

src/and/hpcvm/Client.java
src/and/hpcvm/ComputingClient.java [new file with mode: 0644]
src/and/hpcvm/ConnectedClient.java [new file with mode: 0644]
src/and/hpcvm/RunningApplication.java [new file with mode: 0644]
src/and/hpcvm/SaveNeighbor.java [new file with mode: 0644]
src/and/hpcvm/Server.java
src/and/hpcvm/ServicesClient.java
src/and/hpcvm/ServicesServer.java
src/and/hpcvm/VirtualMachine.java

index 793d066..7d58da8 100644 (file)
@@ -39,14 +39,15 @@ public class Client extends UnicastRemoteObject implements ServicesClient
        private int wait_start ;
        private int max_start_try ;
        private boolean isRestartedSave ;
        private int wait_start ;
        private int max_start_try ;
        private boolean isRestartedSave ;
-       private long save_interleave ;
-       private long date_last_save ;
+//     private long save_interleave ;
+//     private long date_last_save ;
        private SaveProcess saveProcess;
        private int maxRetryVM ;
        private int timeRetryVM ;
        private Semaphore sema ;
        private boolean emergencyStop ;
        private Process procSave ;
        private SaveProcess saveProcess;
        private int maxRetryVM ;
        private int timeRetryVM ;
        private Semaphore sema ;
        private boolean emergencyStop ;
        private Process procSave ;
+       private SaveRequest saveRequest ;
        private boolean lastSaveOk ;
        
                
        private boolean lastSaveOk ;
        
                
@@ -71,9 +72,19 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                        procSave.destroy() ;
                } catch( Exception e ) {}
                
                        procSave.destroy() ;
                } catch( Exception e ) {}
                
+               // Stopping the save request
+               synchronized( saveRequest )
+               {
+                       saveRequest.setStatus( false ) ;
+                       try {
+                               saveRequest.notifyAll() ;
+                       } catch( Exception e ) {}
+               }
+               
                stopVM() ;
        }
        
                stopVM() ;
        }
        
+       
        @Override
        public int startVM( int _mode ) 
        {               
        @Override
        public int startVM( int _mode ) 
        {               
@@ -86,6 +97,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                                e2.printStackTrace() ;
                        }
 
                                e2.printStackTrace() ;
                        }
 
+                       
                        // Checking first start
                        if( machine.checkVmx() == 1 )
                        {
                        // Checking first start
                        if( machine.checkVmx() == 1 )
                        {
@@ -191,7 +203,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                                " -gp " + machine.getVmUserPasswd() + " runScriptInGuest " +
                                working_directory + "/" + machine.getDirectory() 
                                + "/" + machine.getVmx_name() + " " + ushell + 
                                " -gp " + machine.getVmUserPasswd() + " runScriptInGuest " +
                                working_directory + "/" + machine.getDirectory() 
                                + "/" + machine.getVmx_name() + " " + ushell + 
-                               " \"echo ok\"" ;// + " -noWait " ;
+                               " \"echo ok\"" ;
                                
                                try {
                                        FileWriter fw = new FileWriter( new File( working_directory + "/testStarted.sh" ) ) ;
                                
                                try {
                                        FileWriter fw = new FileWriter( new File( working_directory + "/testStarted.sh" ) ) ;
@@ -221,16 +233,9 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                                                if( p.exitValue() == 0 )
                                                {
                                                        started = true ;
                                                if( p.exitValue() == 0 )
                                                {
                                                        started = true ;
-//                                             machine.setStatus( "running" ) ;
-//                                             if( _mode == 0 )
-//                                             {
-//                                                     LocalHost.Instance().getServerStub().changeStatus( 
-//                                                             LocalHost.Instance().getIP(), "running" ) ;
-//                                             } 
                                                        ret = false ;
                                                } else {
                                                        System.err.println( "Error while checking if the VM is started!" ) ;
                                                        ret = false ;
                                                } else {
                                                        System.err.println( "Error while checking if the VM is started!" ) ;
-//                                             printProcessError( p.getErrorStream() ) ;
                                                        ret = printProcessError( p ) ;
                                                
                                                        if( ! ret )
                                                        ret = printProcessError( p ) ;
                                                
                                                        if( ! ret )
@@ -251,7 +256,6 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                                                                System.out.println( "Retrying (" + retry + ") ... " ) ;
                                                                Thread.sleep( timeRetryVM ) ;
                                                        }
                                                                System.out.println( "Retrying (" + retry + ") ... " ) ;
                                                                Thread.sleep( timeRetryVM ) ;
                                                        }
-//                                             wait_start = wait_start / 2 ;
                                                        count++ ;
                                                }
                                        } catch( IOException e ) {
                                                        count++ ;
                                                }
                                        } catch( IOException e ) {
@@ -337,7 +341,6 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                                                ret = false ;
                                        } else {
                                                System.err.println( "VM did not received the host IP!" ) ;
                                                ret = false ;
                                        } else {
                                                System.err.println( "VM did not received the host IP!" ) ;
-//                                     printProcessError( p.getErrorStream() ) ;
                                                ret = printProcessError( p ) ;
                                        
                                                if( ! ret )
                                                ret = printProcessError( p ) ;
                                        
                                                if( ! ret )
@@ -416,12 +419,10 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                                        if( p.exitValue() == 0 )
                                        {
                                                System.out.println( "VM received its assigned IP." ) ;
                                        if( p.exitValue() == 0 )
                                        {
                                                System.out.println( "VM received its assigned IP." ) ;
-//                                     return 0 ;
                                                ret = false ;
                                                machine.setStatus( "running" ) ;
                                        } else {
                                                System.err.println( "VM did not received its assigned IP!" ) ;
                                                ret = false ;
                                                machine.setStatus( "running" ) ;
                                        } else {
                                                System.err.println( "VM did not received its assigned IP!" ) ;
-//                                     printProcessError( p.getErrorStream() ) ;
                                                ret = printProcessError( p ) ;
                                        
                                                if( ! ret )
                                                ret = printProcessError( p ) ;
                                        
                                                if( ! ret )
@@ -479,6 +480,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                return 1 ;
        }
 
                return 1 ;
        }
 
+       
        @Override
        public int stopVM() 
        {               
        @Override
        public int stopVM() 
        {               
@@ -526,7 +528,6 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                                        ret = false ;
                                } else {
                                        System.err.println( "Virtual machine not stopped!" ) ;
                                        ret = false ;
                                } else {
                                        System.err.println( "Virtual machine not stopped!" ) ;
-//                                     printProcessError( p.getErrorStream() ) ;
                                        ret = printProcessError( p ) ;
                                        
                                        if( ! ret )
                                        ret = printProcessError( p ) ;
                                        
                                        if( ! ret )
@@ -567,41 +568,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                                e1.printStackTrace() ;
                        }
                        
                                e1.printStackTrace() ;
                        }
                        
-//                     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 )
                        {
                                sema.release() ;
                        if(     machine.checkVmx() == 0 )
                        {
                                sema.release() ;
@@ -663,7 +630,6 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                                        ret = false ;
                                } else {
                                        System.err.println( "Virtual machine not suspended!" ) ;
                                        ret = false ;
                                } else {
                                        System.err.println( "Virtual machine not suspended!" ) ;
-//                                     printProcessError( p.getErrorStream() ) ;
                                        ret = printProcessError( p ) ;
                                        
                                        if( ! ret )
                                        ret = printProcessError( p ) ;
                                        
                                        if( ! ret )
@@ -753,7 +719,6 @@ public class Client extends UnicastRemoteObject implements ServicesClient
 
                                } else {
                                        System.err.println( "Virtual machine not restarted!" ) ;
 
                                } else {
                                        System.err.println( "Virtual machine not restarted!" ) ;
-//                                     printProcessError( p.getErrorStream() ) ;
                                        ret = printProcessError( p ) ;
                                        
                                        if( ! ret )
                                        ret = printProcessError( p ) ;
                                        
                                        if( ! ret )
@@ -822,32 +787,6 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                                                return 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 ;
                                
                                        /** Retrieving VM assigned IP **/
                                        String vmIP = null ;
@@ -869,8 +808,13 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                                if( startVM( 0 ) == 0 ) 
                                {
                                        if( sendSaveOkVM() == 0 )
                                if( startVM( 0 ) == 0 ) 
                                {
                                        if( sendSaveOkVM() == 0 )
-                                       {
-                                               date_last_save = System.currentTimeMillis() ;
+                                       {                                               
+                                               try {
+                                                       LocalHost.Instance().getServerStub().restartOk( LocalHost.Instance().getIP() ) ;
+                                               } catch( RemoteException e ) {
+                                                       System.err.println( "Unable to inform server about my successful restart!" ) ;
+                                                       e.printStackTrace() ;
+                                               }
                                                
                                                return 0 ;
                                        }
                                                
                                                return 0 ;
                                        }
@@ -921,7 +865,6 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                                return 0 ;
                        } else {
                                System.err.println( "Signal not sent!" ) ;
                                return 0 ;
                        } else {
                                System.err.println( "Signal not sent!" ) ;
-//                             printProcessError( p.getErrorStream() ) ;
                                ret = printProcessError( p ) ;
                                
                                if( ! ret )
                                ret = printProcessError( p ) ;
                                
                                if( ! ret )
@@ -968,6 +911,8 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                System.out.println( "Saving VM ..." ) ;
                saveProcess.setStatus( true ) ;
                
                System.out.println( "Saving VM ..." ) ;
                saveProcess.setStatus( true ) ;
                
+               long deb = System.currentTimeMillis() ;
+               
                machine.setStatus( "saving" ) ;
                try {
                        LocalHost.Instance().getServerStub().changeStatus( 
                machine.setStatus( "saving" ) ;
                try {
                        LocalHost.Instance().getServerStub().changeStatus( 
@@ -980,50 +925,67 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                String[] command ;
                String saveName = "" ;
                boolean error = false ;
                String[] command ;
                String saveName = "" ;
                boolean error = false ;
-               boolean errorVM = false ;
                
                
-               if( suspendVM( 1 ) == 1 ) { error = true ; errorVM = true ; }
+               
+               if( suspendVM( 1 ) == 1 ) { return 1 ; }
+               
                
                if( ! lastSaveOk )
                {
                
                if( ! lastSaveOk )
                {
-                       System.out.println( "Deletion of last nok archive ... " ) ;
+                       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" ) ;
+                       if( file.exists() )
+                       {
+                               arch2 = working_directory + "/" + machine.getName() + "_new_" + machine.getComputationId() + ".tar.gz" ;
+                       }
+                       
+                       file = null ;
+                       
+                       if( arch1.length() > 0 || arch2.length() > 0 )
+                       {                       
+                               System.out.println( "Deletion of last nok archive ... " ) ;
                        
                        
-                       command = new String[]{ "/bin/rm", "-rf", 
-                                       working_directory + "/" + machine.getName() + "_new_" + machine.getComputationId() + ".tar",
-                                       working_directory + "/" + machine.getName() + "_new_" + machine.getComputationId() + ".tar.gz", } ;
+                               command = new String[]{ "/bin/rm", "-rf", 
+                                       arch1, arch2 } ;
                                                        
                                                        
-                       try {
-                               procSave = Runtime.getRuntime().exec( command ) ;
-                               procSave.waitFor() ;
+                               try {
+                                       procSave = Runtime.getRuntime().exec( command ) ;
+                                       procSave.waitFor() ;
                                
                                
-                               if( procSave.exitValue() == 0 )
-                               {
-                                       System.out.println( "Last nok archive successfully deleted." ) ;
-                               } else {
-                                       System.err.println( "Last nok archive not deleted!" ) ;
-//                                     printProcessError( p.getErrorStream() ) ;
-                                       printProcessError( procSave ) ;
+                                       if( procSave.exitValue() == 0 )
+                                       {
+                                               System.out.println( "Last nok archive successfully deleted." ) ;
+                                       } else {
+                                               System.err.println( "Last nok archive not deleted!" ) ;
+                                               printProcessError( procSave ) ;
                                        
                                        
+                                               error = true ;
+                                       }
+                               } catch( IOException e ) {
+                                       System.err.println( "Error during nok archive deletion command: " ) ;
+                                       error = true ;
+                                       e.printStackTrace() ;
+                               } catch( InterruptedException e ) {
+                                       e.printStackTrace() ;
                                        error = true ;
                                }
                                        error = true ;
                                }
-                       } catch( IOException e ) {
-                               System.err.println( "Error during nok archive deletion command: " ) ;
-                               error = true ;
-                               e.printStackTrace() ;
-                       } catch( InterruptedException e ) {
-                               e.printStackTrace() ;
-                               error = true ;
                        }
                }
                
                        }
                }
                
+               
                if( ! error )
                {
                        System.out.print( "Creation of the archive ... " ) ;
                if( ! error )
                {
                        System.out.print( "Creation of the archive ... " ) ;
+                       
                        /** Archive creation **/
                        /** Archive creation **/
-//                     command = new String[]{ "/bin/tar", "-cf", 
-//                             working_directory + "/" + machine.getName() + "_new_" + machine.getComputationId() + ".tar",
-//                             working_directory + "/" + machine.getDirectory() } ;
-//                     
                        command = new String[]{ "/bin/tar", "-cf", 
                                        machine.getName() + "_new_" + machine.getComputationId() + ".tar",
                                        machine.getDirectory(), "-C", working_directory } ;
                        command = new String[]{ "/bin/tar", "-cf", 
                                        machine.getName() + "_new_" + machine.getComputationId() + ".tar",
                                        machine.getDirectory(), "-C", working_directory } ;
@@ -1045,7 +1007,6 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                                        
                                } else {
                                        System.err.println( "Archive not created!" ) ;
                                        
                                } else {
                                        System.err.println( "Archive not created!" ) ;
-//                                     printProcessError( p.getErrorStream() ) ;
                                        printProcessError( procSave ) ;
                                        
                                        error = true ;
                                        printProcessError( procSave ) ;
                                        
                                        error = true ;
@@ -1081,7 +1042,6 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                                                System.out.println( "Archive successfully compressed." ) ;
                                        } else {
                                                System.err.println( "Archive not compressed!" ) ;
                                                System.out.println( "Archive successfully compressed." ) ;
                                        } else {
                                                System.err.println( "Archive not compressed!" ) ;
-//                                             printProcessError( p.getErrorStream() ) ;
                                                printProcessError( procSave ) ;
                                                
                                                error = true ;
                                                printProcessError( procSave ) ;
                                                
                                                error = true ;
@@ -1096,48 +1056,17 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                                }
                        }
                        
                                }
                        }
                        
+                       long fin = System.currentTimeMillis() ;
+                       
+                       System.out.println( "Time to create the save: " + (fin-deb)/1000 + " seconds." ) ;
+                       
                        
                        /** Restarting VM **/
                        
                        /** Restarting VM **/
-                       if( errorVM || startVM( 0 ) == 1 ) { error = true ; }
+                       if( startVM( 0 ) == 1 ) { return 1 ; }
                        
                        
                        /** Sending ok save signal **/
                        
                        
                        /** Sending ok save signal **/
-//                     if( ! error )
-//                     {
-                               if( sendSaveOkVM() == 1 ) { error = true ; }
-                               
-                               
-//                     }               
-                       
-//                     /** Deletion of the tar archive **/
-//                     if( ! error )
-//                     {
-//                             command = new String[]{ "/bin/rm", 
-//                                             working_directory + "/" + machine.getName() 
-//                                             + "_new_" + machine.getComputationId() + ".tar" } ;
-//                             
-//                             try {
-//                                     Process p = Runtime.getRuntime().exec( command ) ;
-//                                     p.waitFor() ;
-//                     
-//                                     if( p.exitValue() == 0 )
-//                                     {
-//                                             System.out.println( "Archive (not compressed) successfully deleted." ) ;
-//                                     } else {
-//                                             System.err.println( "Archive (not compressed) not deleted!" ) ;
-//                                             printProcessError( p.getErrorStream() ) ;
-//                                             
-//                                             error = true ;
-//                                     }
-//                             } catch( IOException e ) {
-//                                     System.err.println( "Error during archive (not compressed) deletion command: " ) ;
-//                                     e.printStackTrace() ;
-//                                     error = true ;
-//                             } catch( InterruptedException e ) {
-//                                     e.printStackTrace() ;
-//                                     error = true ;
-//                             }
-//                     }       
+                       if( sendSaveOkVM() == 1 ) { return 1 ; }
                
                        saveName = machine.getName() + "_new_" + machine.getComputationId() + ".tar.gz" ;       
                
                
                        saveName = machine.getName() + "_new_" + machine.getComputationId() + ".tar.gz" ;       
                
@@ -1149,23 +1078,13 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                                        return 1 ;
                                }
                                
                                        return 1 ;
                                }
                                
-                               ArrayList<ServicesClient> sn = machine.getSaveNeighbors() ;
+                               ArrayList<SaveNeighbor> sn = machine.getSaveNeighbors() ;
                                
                                for( int i = 0 ; i < sn.size() ; i++ )
                                {
                                
                                for( int i = 0 ; i < sn.size() ; i++ )
                                {
-                                       String name ;
-                                       String wd ;
-                                       String snIP ;
-                                       
-                                       try {
-                                               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 ; 
-                                       }
+                                       String name = sn.get( i ).getName() ;
+                                       String wd = sn.get( i ).getWorkingDirectory() ;
+                                       String snIP = sn.get( i ).getIPHost() ;
                                        
                                        System.out.print( "Sending save to " + name + " ... " ) ;
                                        
                                        
                                        System.out.print( "Sending save to " + name + " ... " ) ;
                                        
@@ -1181,7 +1100,6 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                                                        System.out.println( "Archive successfully sent." ) ;
                                                } else {
                                                        System.err.println( "Archive not sent!" ) ;
                                                        System.out.println( "Archive successfully sent." ) ;
                                                } else {
                                                        System.err.println( "Archive not sent!" ) ;
-//                                                     printProcessError( p.getErrorStream() ) ;
                                                        printProcessError( procSave ) ;
                                                
                                                        error = true ;
                                                        printProcessError( procSave ) ;
                                                
                                                        error = true ;
@@ -1248,6 +1166,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                
                serverStub = null ;
                saveProcess = new SaveProcess() ;
                
                serverStub = null ;
                saveProcess = new SaveProcess() ;
+               saveRequest = new SaveRequest() ;
                
                machine = new VirtualMachine() ;
                
                
                machine = new VirtualMachine() ;
                
@@ -1268,8 +1187,8 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                maxRetryVM = 10 ;
                timeRetryVM = 10000 ;
                
                maxRetryVM = 10 ;
                timeRetryVM = 10000 ;
                
-               save_interleave = 30 * 60 * 1000 ;
-               date_last_save = 0 ;
+//             save_interleave = 30 * 60 * 1000 ;
+//             date_last_save = 0 ;
                
                isRestartedSave = false ;
                lastSaveOk = true ;
                
                isRestartedSave = false ;
                lastSaveOk = true ;
@@ -1296,7 +1215,6 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                
                System.out.println( "Connected to server " + server_ip + " on port " + server_port + "." ) ;
                
                
                System.out.println( "Connected to server " + server_ip + " on port " + server_port + "." ) ;
                
-//             LocalHost.Instance().setServerIP( server_ip ) ;
                LocalHost.Instance().setServerStub( serverStub ) ;
                
                
                LocalHost.Instance().setServerStub( serverStub ) ;
                
                
@@ -1309,7 +1227,6 @@ public class Client extends UnicastRemoteObject implements ServicesClient
        
        private void exportObject() 
        {
        
        private void exportObject() 
        {
-//             ServicesClient ref = null ;
                Registry reg = null ;
                
                try 
                Registry reg = null ;
                
                try 
@@ -1453,8 +1370,9 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                        {
                                try {
                                        LocalHost.Instance().getServerStub().ping( LocalHost.Instance().getIP() ) ;
                        {
                                try {
                                        LocalHost.Instance().getServerStub().ping( LocalHost.Instance().getIP() ) ;
-                               } catch (RemoteException e1) {
-                                       e1.printStackTrace();
+                               } catch( RemoteException e1 ) {
+                                       System.err.println( "Unable to ping the server!" ) ;
+                                       e1.printStackTrace() ;
                                }
                                
                                try {
                                }
                                
                                try {
@@ -1486,7 +1404,6 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                        {
                                try {
                                        serverSocket.close() ;
                        {
                                try {
                                        serverSocket.close() ;
-//                                     socket = serverSocket.accept() ;
                                        
                                        for( int i = 0 ; i < dialogs.size() ; i++ )
                                        {
                                        
                                        for( int i = 0 ; i < dialogs.size() ; i++ )
                                        {
@@ -1595,7 +1512,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                                        
                                        /** It's time to do a save **/
                                        if( run && 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 ) {
                                                try {
                                                        machine.setComputationId( Integer.parseInt( reader.readLine() ) ) ;
                                                } catch( Exception e ) {
@@ -1603,20 +1520,34 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                                                        e.printStackTrace() ;
                                                }
                                                
                                                        e.printStackTrace() ;
                                                }
                                                
-                                               if( (System.currentTimeMillis() - date_last_save) > save_interleave )
+                                               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() )
                                                {
                                                {
-                                                       date_last_save = System.currentTimeMillis() ; 
-                                                       
                                                        /* Close streams */
                                                        reader.close() ; reader = null ;
                                                        socket.close() ; socket = null ;
                                                        
                                                        run = false ;
                                                        /* Close streams */
                                                        reader.close() ; reader = null ;
                                                        socket.close() ; socket = null ;
                                                        
                                                        run = false ;
+                                                       
+                                                       saveRequest.setStatus( false ) ;
                                                
                                                
-                                                       /* Starting the VM save */
+                                                       /* Requesting the VM save */
                                                        saveVM() ;
                                                        saveVM() ;
-                                                       
-                                                       date_last_save = System.currentTimeMillis() ; 
                                                } else {
                                                        sendSaveOkVM() ;
                                                }
                                                } else {
                                                        sendSaveOkVM() ;
                                                }
@@ -1699,7 +1630,6 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                        } else {
                                System.err.println( "Last save NOK!" ) ;
                                System.err.println( "Error: " ) ;
                        } else {
                                System.err.println( "Last save NOK!" ) ;
                                System.err.println( "Error: " ) ;
-//                             printProcessError( p.getErrorStream() ) ;
                                printProcessError( p ) ;
                        }
                } catch( IOException e ) {
                                printProcessError( p ) ;
                        }
                } catch( IOException e ) {
@@ -1713,14 +1643,9 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                for( int i = 0 ; i < machine.getSaveNeighbors().size() ; i++ )
                {
                        try {
                for( int i = 0 ; i < machine.getSaveNeighbors().size() ; i++ )
                {
                        try {
-                               machine.getSaveNeighbors().get( i ).changeSaveName( save_new, save_name, machine.getComputationId() ) ;
+                               machine.getSaveNeighbors().get( i ).getStub().changeSaveName( save_new, save_name, machine.getComputationId() ) ;
                        } catch( RemoteException e ) {
                        } catch( RemoteException e ) {
-                               try {
-                                       System.err.println( "Unable to change save name on " + machine.getSaveNeighbors().get( i ).getName() + "!" ) ;
-                               } catch( RemoteException e1 ) {
-                                       System.err.println( "Unable to change save name on an unamed save neighbor!" ) ;
-                                       e1.printStackTrace() ;
-                               }
+                               System.err.println( "Unable to change save name on " + machine.getSaveNeighbors().get( i ).getName() + "!" ) ;
                                e.printStackTrace() ;
                        }
                }
                                e.printStackTrace() ;
                        }
                }
@@ -1766,7 +1691,6 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                                } else {
                                        System.err.println( "Change save name NOK!" ) ;
                                        System.err.println( "Error: " ) ;
                                } else {
                                        System.err.println( "Change save name NOK!" ) ;
                                        System.err.println( "Error: " ) ;
-//                                     printProcessError( p.getErrorStream() ) ;
                                        printProcessError( p ) ;
                                }
                        } catch( IOException e ) {
                                        printProcessError( p ) ;
                                }
                        } catch( IOException e ) {
@@ -1780,19 +1704,14 @@ public class Client extends UnicastRemoteObject implements ServicesClient
 
        
        @Override
 
        
        @Override
-       public void setSavingNeighbor( ServicesClient _sn )
+       public void setSaveNeighbor( SaveNeighbor _sn )
        {
                if( _sn != null )
                {
        {
                if( _sn != null )
                {
-                       ArrayList<ServicesClient> as = new ArrayList<ServicesClient>() ;
+                       ArrayList<SaveNeighbor> as = new ArrayList<SaveNeighbor>() ;
                        as.add( _sn ) ;
                        
                        as.add( _sn ) ;
                        
-                       try {
-                               System.out.println( "Save neighbor: " + _sn.getName() ) ;
-                       } catch( RemoteException e ) {
-                               System.err.println( "Unable to retrieve the name of the save neighbor!" ) ;
-                               e.printStackTrace() ;
-                       }
+                       System.out.println( "Save neighbor: " + _sn.getName() ) ;
                        
                        machine.setSaveNeighbors( as ) ;
                }
                        
                        machine.setSaveNeighbors( as ) ;
                }
@@ -1800,19 +1719,14 @@ public class Client extends UnicastRemoteObject implements ServicesClient
        
        
        @Override
        
        
        @Override
-       public void setSavingNeighbors( ArrayList<ServicesClient> _sn )
+       public void setSaveNeighbors( ArrayList<SaveNeighbor> _sn )
        {
                if( _sn != null && _sn.size() > 0 )
                {
                        System.out.print( "Save neighbors: " ) ;
                        for( int i = 0 ; i < _sn.size() ; i++ )
                        {
        {
                if( _sn != null && _sn.size() > 0 )
                {
                        System.out.print( "Save neighbors: " ) ;
                        for( int i = 0 ; i < _sn.size() ; i++ )
                        {
-                               try {
-                                       System.out.print( _sn.get( i ).getName() ) ;
-                               } catch( RemoteException e ) {
-                                       System.err.println( "Unable to retrieve the name of a save neighbor!" ) ;
-                                       e.printStackTrace() ;
-                               }
+                               System.out.print( _sn.get( i ).getName() ) ;
                                
                                if( i != _sn.size() - 1 )
                                {
                                
                                if( i != _sn.size() - 1 )
                                {
@@ -1828,16 +1742,11 @@ public class Client extends UnicastRemoteObject implements ServicesClient
 
        
        @Override
 
        
        @Override
-       public void addSavingNeighbor( ServicesClient _sn )
+       public void addSaveNeighbor( SaveNeighbor _sn )
        {
                if( _sn != null )
                {
        {
                if( _sn != null )
                {
-                       try {
-                               System.out.println( "Adding save neighbor: " + _sn.getName() ) ;
-                       } catch( RemoteException e ) {
-                               System.err.println( "Unable to retrieve the name of a save neighbor!" ) ;
-                               e.printStackTrace() ;
-                       }
+                       System.out.println( "Adding save neighbor: " + _sn.getName() ) ;
                        
                        machine.getSaveNeighbors().add( _sn ) ;
                }
                        
                        machine.getSaveNeighbors().add( _sn ) ;
                }
@@ -1845,20 +1754,15 @@ public class Client extends UnicastRemoteObject implements ServicesClient
        
        
        @Override
        
        
        @Override
-       public void addSavingNeighbors( ArrayList<ServicesClient> _sn )
+       public void addSaveNeighbors( ArrayList<SaveNeighbor> _sn )
        {
                if( _sn != null && _sn.size() > 0 )
                {
                        System.out.print( "Adding save neighbors: " ) ;
                        for( int i = 0 ; i < _sn.size() ; i++ )
                        {
        {
                if( _sn != null && _sn.size() > 0 )
                {
                        System.out.print( "Adding save neighbors: " ) ;
                        for( int i = 0 ; i < _sn.size() ; i++ )
                        {
-                               try {
-                                       System.out.print( _sn.get( i ).getName() ) ;
-                               } catch( RemoteException e ) {
-                                       System.err.println( "Unable to retrieve the name of a save neighbor!" ) ;
-                                       e.printStackTrace() ;
-                               }
-                               
+                               System.out.print( _sn.get( i ).getName() ) ;
+                                                       
                                if( i != _sn.size() - 1 )
                                {
                                        System.out.print( ", " ) ;
                                if( i != _sn.size() - 1 )
                                {
                                        System.out.print( ", " ) ;
@@ -1873,29 +1777,26 @@ public class Client extends UnicastRemoteObject implements ServicesClient
        
        
        @Override
        
        
        @Override
-       public void replaceSavingNeighbor( String _old, ServicesClient _new )
+       public void replaceSaveNeighbor( SaveNeighbor _old, SaveNeighbor _new )
        {
                System.out.print( "Replacing a save neihgbor ... " ) ;
                if( _old != null && _new != null )
                {
                        int i = 0 ;
        {
                System.out.print( "Replacing a save neihgbor ... " ) ;
                if( _old != null && _new != null )
                {
                        int i = 0 ;
+                       boolean change = false ;
                        
                        for( i = 0 ; i < machine.getSaveNeighbors().size() ; i++ )
                        {
                        
                        for( i = 0 ; i < machine.getSaveNeighbors().size() ; i++ )
                        {
-                               try {
-                                       if( machine.getSaveNeighbors().get( i ).getIPHost().equalsIgnoreCase( _old ) )
-                                       {
-                                               machine.getSaveNeighbors().set( i, _new ) ;
-                                               System.out.println( "Save neighbor successfully changed." ) ;
-                                               break ;
-                                       }
-                               } catch( RemoteException e ) {
-                                       System.err.println( "Unable to retrieve the IP address of a save neighbor!" ) ;
-                                       e.printStackTrace() ;
+                               if( machine.getSaveNeighbors().get( i ).getIPHost().equalsIgnoreCase( _old.getIPHost() ) )
+                               {
+                                       machine.getSaveNeighbors().set( i, _new ) ;
+                                       System.out.println( "Save neighbor successfully changed." ) ;
+                                       change = true ;
+                                       break ;
                                }
                        }
                        
                                }
                        }
                        
-                       if( i == machine.getSaveNeighbors().size() )
+                       if( ! change )
                        {
                                System.out.println( "I am not concerned by the modification." ) ;
                        }
                        {
                                System.out.println( "I am not concerned by the modification." ) ;
                        }
@@ -1917,36 +1818,21 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                        }
                        
                        // TODO NEIGHBORS !!!!
                        }
                        
                        // TODO NEIGHBORS !!!!
-                       //System.out.println( "!!!! NEIGHBORS !!!!!" ) ;
                        boolean ok = false ;
                        boolean ok = false ;
-                       boolean go = true ;
                        int i = 0 ;
                        
                        while( ! ok && i < machine.getSaveNeighbors().size() )
                        {
                        int i = 0 ;
                        
                        while( ! ok && i < machine.getSaveNeighbors().size() )
                        {
-                               try {
-                                       System.out.print( "Retrieving a save on " + machine.getSaveNeighbors().get( 0 ).getName() + " ... " ) ;
-                               } catch( RemoteException e1 ) {
-                                       System.err.println( "Unable to retrieve the name of a save neighbor!" ) ;
-                                       e1.printStackTrace() ;
-                               }
+                               System.out.print( "Retrieving a save on " + machine.getSaveNeighbors().get( 0 ).getName() + " ... " ) ;
                                
                                String command[] = {} ;
                                
                                
                                String command[] = {} ;
                                
-                               try
-                               {
-                                       command = new String[]{ "/usr/bin/scp", 
-                                                       machine.getSaveNeighbors().get( i ).getIPHost() + ":" +
-                                                       machine.getSaveNeighbors().get( i ).getWorkingDirectory() + "/" +
-                                                       machine.getSave_last(),
-                                                       working_directory } ;
-                               } catch( RemoteException e1 ) {
-                                       System.err.println( "Unable to retrieve the name of a save neighbor!" ) ;
-                                       e1.printStackTrace() ;
-                                       go = false ;
-                               }       
+                               command = new String[]{ "/usr/bin/scp", 
+                                               machine.getSaveNeighbors().get( i ).getIPHost() + ":" +
+                                               machine.getSaveNeighbors().get( i ).getWorkingDirectory() + "/" +
+                                               machine.getSave_last(),
+                                               working_directory } ;
                                
                                
-                               if( go )
                                try {
                                        Process p = Runtime.getRuntime().exec( command ) ;
                                        p.waitFor() ;
                                try {
                                        Process p = Runtime.getRuntime().exec( command ) ;
                                        p.waitFor() ;
@@ -1959,17 +1845,14 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                                        } else {
                                                System.err.println( "Archive not retrieved!" ) ;
                                                System.err.println( "Error: " ) ; 
                                        } else {
                                                System.err.println( "Archive not retrieved!" ) ;
                                                System.err.println( "Error: " ) ; 
-//                                             printProcessError( p.getErrorStream() ) ;
+
                                                printProcessError( p ) ;
                                                printProcessError( p ) ;
-//                                             error = true ;
                                        }
                                } catch( IOException e ) {
                                        System.err.println( "Error during archive retrieve command: " ) ;
                                        e.printStackTrace() ;
                                        }
                                } catch( IOException e ) {
                                        System.err.println( "Error during archive retrieve command: " ) ;
                                        e.printStackTrace() ;
-//                                     error = true ;
                                } catch( InterruptedException e ) {
                                        e.printStackTrace() ;
                                } catch( InterruptedException e ) {
                                        e.printStackTrace() ;
-//                                     error = true ;
                                }
                                
                                i++ ;
                                }
                                
                                i++ ;
@@ -1987,6 +1870,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                
        }
 
                
        }
 
+       
        @Override
        public String getIPVM() throws RemoteException 
        {
        @Override
        public String getIPVM() throws RemoteException 
        {
@@ -2050,6 +1934,35 @@ public class Client extends UnicastRemoteObject implements ServicesClient
        }
        
        
        }
        
        
+       @Override
+       public void responseSave( boolean _b )
+       {
+               synchronized( saveRequest )
+               {
+                       saveRequest.setStatus( _b ) ;
+                       try {
+                               saveRequest.notifyAll() ;
+                       } catch( Exception e ) {
+                               e.printStackTrace() ;
+                       }
+               }
+       }
+       
+       
+       private class SaveRequest
+       {
+               boolean status ;
+               
+               SaveRequest()
+               {
+                       status = false ;
+               }
+               
+               protected boolean getStatus() { return status ; }
+               
+               protected void setStatus( boolean _b ) { status = _b ; }
+       }
+       
        private class SaveProcess
        {
                boolean status ;
        private class SaveProcess
        {
                boolean status ;
diff --git a/src/and/hpcvm/ComputingClient.java b/src/and/hpcvm/ComputingClient.java
new file mode 100644 (file)
index 0000000..b71b748
--- /dev/null
@@ -0,0 +1,83 @@
+package and.hpcvm;
+
+import java.io.Serializable;
+import java.rmi.RemoteException;
+import java.util.ArrayList;
+
+
+
+
+public class ComputingClient implements Serializable
+{
+
+       private static final long serialVersionUID = 1L;
+       private ConnectedClient client ;
+       private boolean save_status ;
+       private ArrayList<SaveNeighbor> save_neighbors ;
+       private String lastSaveName ;
+       private boolean saveRequest ;
+       private boolean restartOk ;
+
+       ComputingClient( ConnectedClient cl )
+       {
+               client = cl ;
+               save_status = false ;
+               save_neighbors = new ArrayList<SaveNeighbor>() ;
+               lastSaveName = "none" ;
+               saveRequest = false ;
+               restartOk = false ;
+       }
+       
+       protected void setRestartOk( boolean _b ) { restartOk = _b ; }
+       
+       protected boolean getRestartOk() { return restartOk ; }
+       
+       protected void setSaveRequest( boolean _b ) { saveRequest = _b ; }
+       
+       protected boolean getSaveRequest() { return saveRequest ; }
+
+       protected ConnectedClient getClient() { return client ; }
+
+       protected boolean getSaveStatus(){ return save_status ; }
+
+       protected void setSaveStatus( boolean _status ) { save_status = _status ; }
+
+       protected void setSaveNeighbor( SaveNeighbor _sn ) 
+       { 
+               if( _sn != null )
+               {
+                       if( save_neighbors.size() == 0 )
+                       {
+                               save_neighbors.add( _sn ) ;
+                       } else {
+                               save_neighbors.set( 0, _sn ) ;
+                       }
+
+                       try {
+                               client.getStub().setSaveNeighbor( _sn ) ;
+                       } catch( RemoteException e ) {
+                               System.err.println( "Error while setting save neighbor on " + 
+                                               client.getName() + "(" + client.getIP() + ")!" ) ;
+                               e.printStackTrace() ;
+                       }
+               }
+       }
+
+       protected SaveNeighbor getSaveNeighbor() 
+       {
+               if( save_neighbors.isEmpty() )
+               {
+                       return null ;
+               } else {
+                       return save_neighbors.get( 0 ) ;
+               }
+       }
+
+       public void setLastSave( String _saveName ) 
+       {
+               lastSaveName = _saveName ;                      
+       }
+
+       public String getLastSave() { return lastSaveName ; }
+
+}
\ No newline at end of file
diff --git a/src/and/hpcvm/ConnectedClient.java b/src/and/hpcvm/ConnectedClient.java
new file mode 100644 (file)
index 0000000..a3263dd
--- /dev/null
@@ -0,0 +1,52 @@
+package and.hpcvm;
+
+import java.io.Serializable;
+import java.rmi.RemoteException;
+
+public class ConnectedClient implements Serializable
+{
+       private static final long serialVersionUID = 1L;
+       private ServicesClient stub ;
+       private int timeout ;
+       private Status state ;
+       private String ip ;
+       private String name ;
+       private ComputingClient cl ;
+
+       ConnectedClient( ServicesClient _stub )
+       {
+               stub = _stub ;
+               timeout = 0 ;
+               state = new Status() ;
+               state.setStatus( "connected" ) ;
+               try {
+                       ip = stub.getIPHost() ;
+                       name = stub.getName() ;
+               } catch (RemoteException e) {
+                       e.printStackTrace();
+               }
+               cl = null ;
+       }
+
+       protected ServicesClient getStub() { return stub ; }
+
+       protected void setStub( ServicesClient _stub ) { stub = _stub ; }
+
+       protected int getTimeout() { return timeout ; }
+
+       protected void incTimeout() { timeout++ ; }
+
+       protected void resetTimeout() { timeout = 0 ; }
+
+       protected String getStatus() { return state.getStatus() ; }
+
+       protected void setStatus( String _state ) { state.setStatus( _state ) ; }
+
+       protected String getIP() { return ip ; }
+
+       protected String getName() { return name ; } ;
+
+       protected void setComputingClient( ComputingClient _cl ) { cl = _cl ; }
+
+       protected ComputingClient getComputingClient() { return cl ; } 
+}
diff --git a/src/and/hpcvm/RunningApplication.java b/src/and/hpcvm/RunningApplication.java
new file mode 100644 (file)
index 0000000..5988648
--- /dev/null
@@ -0,0 +1,104 @@
+package and.hpcvm;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+
+
+
+public class RunningApplication implements Serializable
+{
+       private static final long serialVersionUID = 1L;
+       private String name ;
+       private ArrayList<ComputingClient> computingsNodes ;
+       private long lastSaveDate ;
+       private String vmName ;
+       private boolean running ;
+       private long startTime ;
+       private long endTime ;
+       
+       public RunningApplication( String _name )
+       {
+               name = _name ;
+               computingsNodes = new ArrayList<ComputingClient>() ;
+               lastSaveDate = 0 ;
+               running = false ;
+               startTime = 0 ;
+               endTime = 0 ;
+       }
+       
+       
+       public void clear() { computingsNodes.clear() ; }
+       
+       public int getNbComputingClients() { return computingsNodes.size() ; }
+       
+       public long getLastSaveDate() { return lastSaveDate ; }
+       
+       public void setLastSaveDate( long _sd ) { lastSaveDate = _sd ; }
+       
+       public void setName( String _name ) { name = _name ; }
+       
+       public String getName() { return name ; }
+       
+       public void setStartTime( long _t ) { startTime = _t ; }
+       
+       public long getStartTime() { return startTime ; }
+       
+       public void setEndTime( long _t ) { endTime = _t ; }
+       
+       public long getEndTime() { return endTime ; }
+       
+       public long getExecutionTime() { return endTime - startTime ; }
+       
+       
+       public void setComputingClients( ArrayList<ComputingClient> _cc )
+       {
+               if( _cc != null )
+               {
+                       computingsNodes.clear() ;
+                       
+                       System.out.println( "Application " + name + " contains clients:" ) ;
+                       
+                       for( int i = 0 ; i < _cc.size() ; i++ )
+                       {
+                               computingsNodes.add( _cc.get( i ) ) ;
+                               System.out.println( "  " + _cc.get(i).getClient().getName() ) ;
+                       }
+               }
+       }
+
+       
+       public ArrayList<ComputingClient> getComputingClients() { return computingsNodes ; }
+
+       
+       public int replaceComputingClient( ComputingClient _dead, ComputingClient _new )
+       {
+               if( _dead != null && _new != null )
+               {
+                       for( int i = 0 ; i < computingsNodes.size() ; i++ )
+                       {
+                               if( computingsNodes.get( i ).getClient().getIP().equalsIgnoreCase( _dead.getClient().getIP() ) )
+                               {
+                                       System.out.println( "Replacing " + _dead.getClient().getName() + " with " +_new.getClient().getName() ) ;
+                                       computingsNodes.set( i , _new ) ;
+                                       return 0 ;
+                               }
+                               
+                               System.err.println( "Dead computing client not found. Unable to replace it!" ) ;
+                       }
+               }
+               
+               return 1 ;
+       }
+       
+       
+       public void setVmName( String _vmname ) { vmName = _vmname ; }
+       
+       public String getVmName() { return vmName ; }
+               
+       public void setRunning( boolean _b ) { running = _b ; }
+       
+       public boolean getRunning() { return running ; }
+       
+}
+
+/** La programmation est un art, respectons ceux qui la pratiquent !! **/
diff --git a/src/and/hpcvm/SaveNeighbor.java b/src/and/hpcvm/SaveNeighbor.java
new file mode 100644 (file)
index 0000000..a1d668d
--- /dev/null
@@ -0,0 +1,38 @@
+package and.hpcvm ;
+
+import java.io.Serializable;
+import java.rmi.RemoteException;
+
+
+public class SaveNeighbor implements Serializable
+{
+       private static final long serialVersionUID = 1L;
+       private ServicesClient sc ;
+       private String ip ;
+       private String name ;
+       private String wd ;
+       
+       public SaveNeighbor( ServicesClient _sc ) throws RemoteException
+       {
+               super() ;
+               
+               sc = _sc ;
+               try {
+                       ip = sc.getIPHost() ;
+                       name = sc.getName() ;
+                       wd = sc.getWorkingDirectory() ;
+               } catch( RemoteException e ) {
+                       System.err.println( "Unable to retrieve inforation one save neighbor!" ) ;
+                       e.printStackTrace() ;
+               }
+       }
+               
+       protected String getIPHost() { return ip ; }
+       
+       protected String getName() { return name ; }
+       
+       protected String getWorkingDirectory() { return wd ; }
+       
+       protected ServicesClient getStub() { return sc ; }
+               
+}
\ No newline at end of file
index 0c696a4..2bc7ab8 100644 (file)
@@ -11,6 +11,7 @@ import java.rmi.registry.Registry;
 import java.rmi.server.UnicastRemoteObject;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.rmi.server.UnicastRemoteObject;
 import java.util.ArrayList;
 import java.util.Iterator;
+import java.util.concurrent.Semaphore;
 
 
 public class Server extends UnicastRemoteObject implements ServicesServer
 
 
 public class Server extends UnicastRemoteObject implements ServicesServer
@@ -31,119 +32,7 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                }
                
                protected int getNb() { return nb ; }
                }
                
                protected int getNb() { return nb ; }
-       }
-       
-       
-       private class ConnectedClient
-       {
-               private ServicesClient stub ;
-               private int timeout ;
-               private Status state ;
-               private String ip ;
-               private String name ;
-               private ComputingClient cl ;
-               
-               ConnectedClient( ServicesClient _stub )
-               {
-                       stub = _stub ;
-                       timeout = 0 ;
-                       state = new Status() ;
-                       state.setStatus( "connected" ) ;
-                       try {
-                               ip = stub.getIPHost() ;
-                               name = stub.getName() ;
-                       } catch (RemoteException e) {
-                               e.printStackTrace();
-                       }
-                       cl = null ;
-               }
-               
-               protected ServicesClient getStub() { return stub ; }
-               
-               protected void setStub( ServicesClient _stub ) { stub = _stub ; }
-               
-               protected int getTimeout() { return timeout ; }
-               
-               protected void incTimeout() { timeout++ ; }
-               
-               protected void resetTimeout() { timeout = 0 ; }
-               
-               protected String getStatus() { return state.getStatus() ; }
-               
-               protected void setStatus( String _state ) { state.setStatus( _state ) ; }
-               
-               protected String getIP() { return ip ; }
-               
-               protected String getName() { return name ; } ;
-               
-               protected void setComputingClient( ComputingClient _cl ) { cl = _cl ; }
-               
-               protected ComputingClient getComputingClient() { return cl ; } 
-       }
-       
-       
-       private class ComputingClient
-       {
-               private ConnectedClient client ;
-               private boolean save_status ;
-               private ArrayList<ServicesClient> save_neighbor ;
-               private String lastSaveName ;
-               
-               ComputingClient( ConnectedClient cl )
-               {
-                       client = cl ;
-                       save_status = false ;
-                       save_neighbor = new ArrayList<ServicesClient>() ;
-                       lastSaveName = "none" ;
-               }
-               
-               protected ConnectedClient getClient() { return client ; }
-               
-               protected boolean getSaveStatus(){ return save_status ; }
-               
-               protected void setSaveStatus( boolean _status ) { save_status = _status ; }
-               
-               protected void setSaveNeighbor( ServicesClient _sn ) 
-               { 
-                       if( _sn != null )
-                       {
-                               if( save_neighbor.size() == 0 )
-                               {
-                                       save_neighbor.add( _sn ) ;
-                               } else {
-                                       save_neighbor.set( 0, _sn ) ;
-                               }
-                               
-//                             System.out.println( "My save neighbor is " + _sn ) ;
-                       
-                               try {
-                                       client.getStub().setSavingNeighbor( _sn ) ;
-                               } catch( RemoteException e ) {
-                                       System.err.println( "Error while setting save neighbor on " + 
-                                                       client.getName() + "(" + client.getIP() + ")!" ) ;
-                                       e.printStackTrace() ;
-                               }
-                       }
-               }
-               
-               protected ServicesClient getSaveNeighbor() 
-               {
-                       if( save_neighbor.isEmpty() )
-                       {
-                               return null ;
-                       } else {
-                               return save_neighbor.get( 0 ) ;
-                       }
-               }
-
-               public void setLastSave( String _saveName ) 
-               {
-                       lastSaveName = _saveName ;                      
-               }
-               
-               public String getLastSave() { return lastSaveName ; }
-               
-       }
+       }       
        
        
        private class IPAssociation
        
        
        private class IPAssociation
@@ -153,8 +42,8 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                
                IPAssociation()
                {
                
                IPAssociation()
                {
-                       vmIP = null ;
-                       hostIP = null ;
+                       vmIP = "" ;
+                       hostIP = "" ;
                }
                
                protected void setVmIP( String _vmIP )
                }
                
                protected void setVmIP( String _vmIP )
@@ -184,11 +73,14 @@ public class Server extends UnicastRemoteObject implements ServicesServer
        private int port ;
        private ArrayList<ConnectedClient> clients ;
        private ArrayList<ComputingClient> computingClients ;
        private int port ;
        private ArrayList<ConnectedClient> clients ;
        private ArrayList<ComputingClient> computingClients ;
+       private ArrayList<RunningApplication> applications ;
        private int max_timeout ;
        private ConnectedMonitor monitor ;
        private DiscCount counter ;
        private ArrayList<IPAssociation> vmIPs ;
        private String working_directory ;
        private int max_timeout ;
        private ConnectedMonitor monitor ;
        private DiscCount counter ;
        private ArrayList<IPAssociation> vmIPs ;
        private String working_directory ;
+       private long save_interleave ;
+       private Semaphore semaSave ;
        
        
        protected Server() throws RemoteException 
        
        
        protected Server() throws RemoteException 
@@ -259,7 +151,7 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                {       
                        for( int i = 0 ; i < vmIPs.size() ; i++ )
                        {
                {       
                        for( int i = 0 ; i < vmIPs.size() ; i++ )
                        {
-                               if( vmIPs.get( i ).getHostIP() == null )
+                               if( vmIPs.get( i ).getHostIP().equalsIgnoreCase( "" ) )
                                {
                                        vmIPs.get( i ).setHostIP( _ip ) ;
                                        
                                {
                                        vmIPs.get( i ).setHostIP( _ip ) ;
                                        
@@ -310,12 +202,17 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                port = _port ;
                max_timeout = 4 ;
                
                port = _port ;
                max_timeout = 4 ;
                
-               clients = new ArrayList<Server.ConnectedClient>() ;
-               computingClients = new ArrayList<Server.ComputingClient>() ;
+               clients = new ArrayList<ConnectedClient>() ;
+               computingClients = new ArrayList<ComputingClient>() ;
+               applications = new ArrayList<RunningApplication>() ;
                monitor = null ;
                
                working_directory = "/localhome/vmware" ;
                
                monitor = null ;
                
                working_directory = "/localhome/vmware" ;
                
+               save_interleave  = 30 * 60 * 1000 ;
+               
+               semaSave = new Semaphore( 1 ) ;
+               
                exportObject() ;
 
                vmIPs = new ArrayList<IPAssociation>() ;
                exportObject() ;
 
                vmIPs = new ArrayList<IPAssociation>() ;
@@ -326,12 +223,15 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                        vmIPs.get( vmIPs.size() - 1 ).setVmIP( "10.11.10." + i ) ;
                }
                
                        vmIPs.get( vmIPs.size() - 1 ).setVmIP( "10.11.10." + i ) ;
                }
                
-               clients = new ArrayList<Server.ConnectedClient>() ;
+               clients = new ArrayList<ConnectedClient>() ;
                
                counter = new DiscCount() ;
                
                monitor = new ConnectedMonitor() ;
                monitor.start() ;
                
                counter = new DiscCount() ;
                
                monitor = new ConnectedMonitor() ;
                monitor.start() ;
+               
+               // TODO
+               // Check if there are running applications ... and restart them :)
        }
        
        
        }
        
        
@@ -342,6 +242,7 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                for( int i = 0 ; i < clients.size() ; i++ )
                {
                        try {
                for( int i = 0 ; i < clients.size() ; i++ )
                {
                        try {
+                               clients.get( i ).getStub().emergencyStop() ;
                                clients.get( i ).getStub().stop() ;
                        } catch (RemoteException e) {
                                e.printStackTrace();
                                clients.get( i ).getStub().stop() ;
                        } catch (RemoteException e) {
                                e.printStackTrace();
@@ -428,6 +329,15 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                ComputingClient cc = cl.getComputingClient() ;
 //                             ServicesClient dead = cc.getClient().getStub() ;
                                String ipDead = cc.getClient().getIP() ;
                                ComputingClient cc = cl.getComputingClient() ;
 //                             ServicesClient dead = cc.getClient().getStub() ;
                                String ipDead = cc.getClient().getIP() ;
+                               SaveNeighbor snDead = null ;
+                               for( int i = 0 ; i < computingClients.size() ; i++ )
+                               {
+                                       if( computingClients.get( i ).getSaveNeighbor().getIPHost().equalsIgnoreCase( ipDead ) ) 
+                                       {
+                                               snDead = computingClients.get( i ).getSaveNeighbor() ;
+                                               break ;
+                                       }
+                               }
                                                                
                                boolean ok = false ;
                                
                                                                
                                boolean ok = false ;
                                
@@ -458,7 +368,7 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                                        
                                                        ComputingClient ccl = new ComputingClient( clients.get(i) ) ;
                                                        clients.get( i ).setComputingClient( ccl ) ;
                                                        
                                                        ComputingClient ccl = new ComputingClient( clients.get(i) ) ;
                                                        clients.get( i ).setComputingClient( ccl ) ;
-                                                       ServicesClient sn = computingClients.get( pos ).getSaveNeighbor() ;
+                                                       SaveNeighbor sn = computingClients.get( pos ).getSaveNeighbor() ;
                                                        ccl.setSaveNeighbor( sn ) ;
                                                        computingClients.set( pos, ccl ) ;
 
                                                        ccl.setSaveNeighbor( sn ) ;
                                                        computingClients.set( pos, ccl ) ;
 
@@ -475,24 +385,45 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                                        if( res == 0 )
                                                        {
                                                                ok = true ;
                                                        if( res == 0 )
                                                        {
                                                                ok = true ;
+                                                               
+                                                               boolean ok_new = false, ok_old = false ;
                                                                        
                                                                        
-                                                                       // replace dead client in vmIPs
+                                                               // replace dead client in vmIPs
                                                                for( int j = 0 ; j < vmIPs.size() ; j++ )
                                                                {
                                                                for( int j = 0 ; j < vmIPs.size() ; j++ )
                                                                {
+                                                                       if( vmIPs.get( j ).getHostIP().equalsIgnoreCase( computingClients.get( pos ).getClient().getIP() ) )
+                                                                       {
+                                                                               vmIPs.get( j ).setHostIP( "" ) ;
+                                                                               ok_new = true ;
+                                                                       }
                                                                        if( vmIPs.get( j ).getHostIP().equalsIgnoreCase( ipDead ) )
                                                                        {
                                                                                String vmIP = vmIPs.get( j ).getVmIP() ;
                                                                                vmIPs.get( j ).setHostIP( computingClients.get( pos ).getClient().getIP() ) ;
                                                                        if( vmIPs.get( j ).getHostIP().equalsIgnoreCase( ipDead ) )
                                                                        {
                                                                                String vmIP = vmIPs.get( j ).getVmIP() ;
                                                                                vmIPs.get( j ).setHostIP( computingClients.get( pos ).getClient().getIP() ) ;
-                                                                                       
+                                                                               ok_old = true ;
+                                                                               
                                                                                try {
                                                                                        computingClients.get( pos ).getClient().getStub().setIPVM( vmIP ) ;
                                                                                } catch( RemoteException e ) {
                                                                                        System.err.println( "Unable to set the new VM IP on the replacing client!" ) ;
                                                                                        e.printStackTrace() ;
                                                                                }
                                                                                try {
                                                                                        computingClients.get( pos ).getClient().getStub().setIPVM( vmIP ) ;
                                                                                } catch( RemoteException e ) {
                                                                                        System.err.println( "Unable to set the new VM IP on the replacing client!" ) ;
                                                                                        e.printStackTrace() ;
                                                                                }
-                                                                               break ;
+                                                                               
+                                                                               if( ok_new && ok_old )
+                                                                               {
+                                                                                       break ;
+                                                                               }
                                                                        }
                                                                }
                                                                        }
                                                                }
+                                                               
+                                                               // Replacing in RunningApplication
+                                                               applications.get( 0 ).replaceComputingClient( cc, ccl ) ;
+                                                               
+                                                               for( int l = 0 ; l < applications.get(0).getComputingClients().size() ; l++ )
+                                                               {
+                                                                       applications.get(0).getComputingClients().get( l ).setSaveRequest( false ) ;
+                                                               }
+                                                               
                                                                        
                                                                System.out.println( "Successful redeployment of the VM." ) ;
                                                        } else {
                                                                        
                                                                System.out.println( "Successful redeployment of the VM." ) ;
                                                        } else {
@@ -510,7 +441,7 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                                        {
                                                                try {
                                                                        computingClients.get( k ).getClient().getStub().
                                                        {
                                                                try {
                                                                        computingClients.get( k ).getClient().getStub().
-                                                                               replaceSavingNeighbor( ipDead, clients.get( i ).getStub() ) ;
+                                                                               replaceSaveNeighbor( snDead, new SaveNeighbor( clients.get( i ).getStub() ) ) ;
                                                                } catch( RemoteException e ) {
                                                                        System.err.println( "Unable to inform " + computingClients.get( k ).getClient().getName() +
                                                                                        " of the replacement of a save neighbor!" ) ;
                                                                } catch( RemoteException e ) {
                                                                        System.err.println( "Unable to inform " + computingClients.get( k ).getClient().getName() +
                                                                                        " of the replacement of a save neighbor!" ) ;
@@ -649,9 +580,11 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                                }
                                        }
                                        
                                                }
                                        }
                                        
-                                       for( int  i = 0 ; i < computingClients.size() ; i++ )
+                                       for( int  i = 0 ; i < applications.get(0).getComputingClients().size() ; i++ )
                                        {
                                        {
-                                               final ServicesClient sc = computingClients.get( i ).getClient().getStub() ;
+                                               final ServicesClient sc = applications.get(0).getComputingClients().get( i ).getClient().getStub() ;
+                                               
+                                               applications.get( 0 ).getComputingClients().get( i ).setRestartOk( false ) ;
                                                
                                                new Thread( new Runnable() {
                                                        
                                                
                                                new Thread( new Runnable() {
                                                        
@@ -713,6 +646,8 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                }
                                computingClients.get( i ).setSaveStatus( false ) ;
                        }
                                }
                                computingClients.get( i ).setSaveStatus( false ) ;
                        }
+                       
+                       applications.get( 0 ).setLastSaveDate( System.currentTimeMillis() ) ;
                }
                
                return 0 ;
                }
                
                return 0 ;
@@ -745,7 +680,9 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                if( nb > _nb )
                {
                        ArrayList<ServicesClient> ac = new ArrayList<ServicesClient>() ;
                if( nb > _nb )
                {
                        ArrayList<ServicesClient> ac = new ArrayList<ServicesClient>() ;
-                       ArrayList<ComputingClient> tmp = new ArrayList<Server.ComputingClient>() ;
+                       ArrayList<ComputingClient> tmp = new ArrayList<ComputingClient>() ;
+                       
+                       RunningApplication app = new RunningApplication( "Test" ) ;
                        
                        int i = 0 ;
                        
                        
                        int i = 0 ;
                        
@@ -779,6 +716,10 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                        
                        if( ac.size() == _nb )
                        {
                        
                        if( ac.size() == _nb )
                        {
+                               app.setComputingClients( tmp ) ;
+                               app.setRunning( true ) ;
+                               app.setStartTime( System.currentTimeMillis() ) ;
+                               
                                int index, index2 ;
                                /* Choosing save neighbors */
                                for( i = 0 ; i < tmp.size() ; i++ )
                                int index, index2 ;
                                /* Choosing save neighbors */
                                for( i = 0 ; i < tmp.size() ; i++ )
@@ -792,7 +733,12 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                                {
                                                        System.err.println( "Problem in ComputingClients list!" ) ;
                                                } else {
                                                {
                                                        System.err.println( "Problem in ComputingClients list!" ) ;
                                                } else {
-                                                       computingClients.get( index ).setSaveNeighbor( computingClients.get( index2 ).getClient().getStub() ) ;
+                                                       try {
+                                                               computingClients.get( index ).setSaveNeighbor( new SaveNeighbor( computingClients.get( index2 ).getClient().getStub() )) ;
+                                                       } catch( RemoteException e ) {
+                                                               System.err.println( "Unable to create the save neighbor!" ) ;
+                                                               e.printStackTrace() ;
+                                                       }
                                                }
                                        } else {
                                                index = computingClients.indexOf( tmp.get( i ) ) ;
                                                }
                                        } else {
                                                index = computingClients.indexOf( tmp.get( i ) ) ;
@@ -802,23 +748,183 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                                {
                                                        System.err.println( "Problem in ComputingClients list!" ) ;
                                                } else {
                                                {
                                                        System.err.println( "Problem in ComputingClients list!" ) ;
                                                } else {
-                                                       computingClients.get( index ).setSaveNeighbor( computingClients.get( index2 ).getClient().getStub() ) ;
+                                                       try {
+                                                               computingClients.get( index ).setSaveNeighbor( new SaveNeighbor( computingClients.get( index2 ).getClient().getStub() ) ) ;
+                                                       } catch( RemoteException e ) {
+                                                               System.err.println( "Unable to create the save neighbor!" ) ;
+                                                               e.printStackTrace() ;
+                                                       }
                                                }
                                        }
                                }
                        }
                        
                                                }
                                        }
                                }
                        }
                        
-                       /* Cleaning */
-                       tmp.clear() ;
-                       tmp = null ;
+                       applications.add( app ) ;
                        
                        return ac ;
                }
                
                return null ;
        }
                        
                        return ac ;
                }
                
                return null ;
        }
+       
+       
+       @Override
+       public void requestSave( String _ip )
+       {
+               try {
+                       semaSave.acquire() ;
+               } catch( InterruptedException e ) {
+                       System.err.println( "Unable to obtain the semaphore for semaSave!" ) ;
+                       e.printStackTrace() ;
+               }
+               
+               final String ip = _ip ;
+               
+               new Thread( new Runnable() {
+                       
+                       @Override
+                       public void run() 
+                       {
+                               treatRequestSave( ip ) ;
+                       }
+               } ).start() ;
+       }
 
 
-
+       
+       public void treatRequestSave( String _ip )
+       {
+               if( applications.size() > 0 && _ip != null && _ip.length() > 0 )
+               {
+                       if( (System.currentTimeMillis() - applications.get( 0 ).getLastSaveDate()) > save_interleave )
+                       {
+                               // Mark it as a requester
+                               for( int i = 0 ; i < applications.get( 0 ).getComputingClients().size() ; i++ )
+                               {
+                                       if( applications.get( 0 ).getComputingClients().get( i ).getClient().getIP().equalsIgnoreCase( _ip ) )
+                                       {
+                                               applications.get( 0 ).getComputingClients().get( i ).setSaveRequest( true ) ;
+                                                                                               
+                                               break ;
+                                       }
+                               }
+                               
+                               semaSave.release() ;
+                               
+                               // Is every body ok?
+                               boolean ok = false ;
+                               for( int i = 0 ; i < applications.get( 0 ).getComputingClients().size() ; i++ )
+                               {
+                                       if( i == 0 )
+                                       {
+                                               ok = applications.get( 0 ).getComputingClients().get( i ).getSaveRequest() ;
+                                       } else {
+                                               ok = ok & applications.get( 0 ).getComputingClients().get( i ).getSaveRequest() ;       
+                                       }
+                                       
+                                       if( ! ok )
+                                       {
+                                               break ;
+                                       }
+                               }
+                               
+                               if( ok )
+                               {
+//                                     try {
+//                                             Thread.sleep( 5000 ) ;
+//                                     } catch( InterruptedException e1 ) {
+//                                             e1.printStackTrace() ;
+//                                     }
+                                       
+                                       for( int i = 0 ; i < applications.get( 0 ).getComputingClients().size() ; i++ )
+                                       {
+                                               try {
+                                                       applications.get( 0 ).getComputingClients().get( i ).getClient().getStub().responseSave( true ) ;
+                                                       applications.get( 0 ).getComputingClients().get( i ).setSaveRequest( false ) ;                                                  
+                                               } catch( RemoteException e ) {
+                                                       System.err.println( "Unable to send the save request response to " +
+                                                                       applications.get( 0 ).getComputingClients().get( i ).getClient().getName() + "!" ) ;
+                                                       e.printStackTrace() ; 
+                                               }
+                                       }
+                                       
+                                       applications.get( 0 ).setLastSaveDate( System.currentTimeMillis() ) ;
+                               }
+                               
+                       } else {
+                               semaSave.release() ;
+                               
+                               for( int i = 0 ; i < applications.get( 0 ).getComputingClients().size() ; i++ )
+                               {
+                                       if( applications.get( 0 ).getComputingClients().get( i ).getClient().getIP().equalsIgnoreCase( _ip ) )
+                                       {
+                                               try {
+                                                       applications.get( 0 ).getComputingClients().get( i ).getClient().getStub().responseSave( false ) ;
+                                               } catch( RemoteException e ) {
+                                                       System.err.println( "Unable to send the save request response to " +
+                                                                       applications.get( 0 ).getComputingClients().get( i ).getClient().getName() + "!" ) ;
+                                                       e.printStackTrace() ; 
+                                               }
+                                               break ;
+                                       }
+                               }
+                       }
+               } else {
+                       semaSave.release() ;
+                       System.err.println( "!! Serious problem in treatRequestSave method!!" ) ;
+               }
+       }       
+       
+       
+       @Override
+       public void restartOk( String _ip )
+       {
+               if( applications.size() > 0 && _ip != null && _ip.length() > 0 )
+               {
+                       System.out.println( "Client " + _ip + " has finished to restart ("+applications.get(0).getComputingClients().size()+") ... " ) ;
+                       if( (System.currentTimeMillis() - applications.get( 0 ).getLastSaveDate()) > save_interleave )
+                       {
+                               // Has it already finished?
+                               for( int i = 0 ; i < applications.get( 0 ).getComputingClients().size() ; i++ )
+                               {
+                                       if( applications.get( 0 ).getComputingClients().get( i ).getClient().getIP().equalsIgnoreCase( _ip ) )
+                                       {
+                                               applications.get( 0 ).getComputingClients().get( i ).setRestartOk( true ) ;
+                                                                                               
+                                               break ;
+                                       }
+                               }
+                               
+                               // Is every body ok?
+                               boolean ok = false ;
+                               for( int i = 0 ; i < applications.get( 0 ).getComputingClients().size() ; i++ )
+                               {
+                                       if( i == 0 )
+                                       {
+                                               ok = applications.get( 0 ).getComputingClients().get( i ).getRestartOk() ;
+                                       } else {
+                                               ok = ok & applications.get( 0 ).getComputingClients().get( i ).getRestartOk() ; 
+                                       }
+                                       
+                                       if( ! ok )
+                                       {
+                                               break ;
+                                       }
+                               }
+                               
+                               if( ok )
+                               {
+                                       applications.get( 0 ).setLastSaveDate( System.currentTimeMillis() ) ;
+                                       
+                                       for( int i = 0 ; i < applications.get( 0 ).getComputingClients().size() ; i++ )
+                                       {
+                                               applications.get( 0 ).getComputingClients().get( i ).setRestartOk( false ) ;
+                                       }
+                               }
+                               
+                       }
+               }
+       }       
+       
 
        @Override
        public void endApplication() 
 
        @Override
        public void endApplication() 
@@ -830,7 +936,7 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                        ComputingClient cl = it.next() ;
 
                        try {
                        ComputingClient cl = it.next() ;
 
                        try {
-                               cl.getClient().getStub().stopVM() ;
+                               cl.getClient().getStub().emergencyStop() ;
                        } catch (RemoteException e) {
                                e.printStackTrace();
                        }
                        } catch (RemoteException e) {
                                e.printStackTrace();
                        }
@@ -841,6 +947,10 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                        cl = null ;
                }
                
                        cl = null ;
                }
                
+               applications.get( 0 ).setEndTime( System.currentTimeMillis() ) ;
+               applications.get( 0 ).setRunning( false ) ;
+               applications.get( 0 ).clear() ;
+               
        }
 
 
        }
 
 
@@ -897,94 +1007,98 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                        {
                                ret = 1 ;
                                error = false ;
                        {
                                ret = 1 ;
                                error = false ;
-                               try {
-                                       ret = clients.get( i ).getStub().deployVM( _name, _archive, _directory ) ;
-                               } catch( RemoteException e ) {
-                                       System.err.println( "Unable to deploy the VM on " + clients.get( i ).getName() + "!" ) ;
-                                       e.printStackTrace() ;
-                               }
-                               
-                               // The client does not have the archive, we have to send it.
-                               if( ret == 2 )
+                               if( clients.get( i ).getStatus().equalsIgnoreCase( "connected" ) )
                                {
                                {
-                                       System.out.print( "Sending VM archive to " + clients.get( i ).getName() + " ... " ) ;
-                                       
-                                       String wd = "" ;
-                                       String snIP = "" ;
-                                       error = false ;
-                                       
                                        try {
                                        try {
-                                               wd = clients.get( i ).getStub().getWorkingDirectory() ;
-                                               snIP = clients.get( i ).getStub().getIPHost() ;
-                                       } catch (RemoteException e2) {
-                                               System.err.println( "Unable to retrieve information on " + clients.get( i ).getName() + "!" ) ;
-                                               e2.printStackTrace() ;
-                                               error = true ;
-                                               pb++ ;
+                                               ret = clients.get( i ).getStub().deployVM( _name, _archive, _directory ) ;
+                                       } catch( RemoteException e ) {
+                                               System.err.println( "Unable to deploy the VM on " + clients.get( i ).getName() + "!" ) ;
+                                               e.printStackTrace() ;
                                        }
                                        
                                        }
                                        
-                                       String[] command = new String[]{ "/usr/bin/scp", working_directory + "/" + _archive,
+                                       // The client does not have the archive, we have to send it.
+                                       if( ret == 2 )
+                                       {
+                                               System.out.print( "Sending VM archive to " + clients.get( i ).getName() + " ... " ) ;
+                                       
+                                               String wd = "" ;
+                                               String snIP = "" ;
+                                               error = false ;
+                                       
+                                               try {
+                                                       wd = clients.get( i ).getStub().getWorkingDirectory() ;
+                                                       snIP = clients.get( i ).getStub().getIPHost() ;
+                                               } catch (RemoteException e2) {
+                                                       System.err.println( "Unable to retrieve information on " + clients.get( i ).getName() + "!" ) ;
+                                                       e2.printStackTrace() ;
+                                                       error = true ;
+                                                       pb++ ;
+                                               }
+                                       
+                                               String[] command = new String[]{ "/usr/bin/scp", working_directory + "/" + _archive,
                                                                snIP + ":" + wd } ;
                                
                                                                snIP + ":" + wd } ;
                                
-                                       if( ! error )
-                                       try {
-                                               Process proc = Runtime.getRuntime().exec( command ) ;
-                                               proc.waitFor() ;
-                       
-                                               if( proc.exitValue() == 0 )
+                                               if( ! error )
                                                {
                                                {
-                                                       System.out.println( "Initial VM archive successfully sent." ) ;
-                                               } else {
-                                                       System.err.println( "Initial VM archive not sent!" ) ;
-//                                                     printProcessError( p.getErrorStream() ) ;
-                                                       System.err.println( "Error: " + proc.exitValue() ) ;
-                                                       BufferedReader b = new BufferedReader( new InputStreamReader( proc.getErrorStream() ) ) ;
-                                                       
-                                                       String l ;
                                                        try {
                                                        try {
-                                                               while( (l = b.readLine()) != null )
+                                                               Process proc = Runtime.getRuntime().exec( command ) ;
+                                                               proc.waitFor() ;
+                       
+                                                               if( proc.exitValue() == 0 )
                                                                {
                                                                {
-                                                                       System.err.println( l ) ;
+                                                                       System.out.println( "Initial VM archive successfully sent." ) ;
+                                                               } else {
+                                                                       System.err.println( "Initial VM archive not sent!" ) ;
+                                                                       System.err.println( "Error: " + proc.exitValue() ) ;
+                                                                       BufferedReader b = new BufferedReader( new InputStreamReader( proc.getErrorStream() ) ) ;
+                                                       
+                                                                       String l ;
+                                                                       try {
+                                                                               while( (l = b.readLine()) != null )
+                                                                               {
+                                                                                       System.err.println( l ) ;
+                                                                               }
+                                                                       } catch( IOException e ) {
+                                                                               e.printStackTrace() ;
+                                                                       }
+                                                       
+                                                                       error = true ;
+                                                                       pb++ ;
                                                                }
                                                        } catch( IOException e ) {
                                                                }
                                                        } catch( IOException e ) {
-                                                                       e.printStackTrace() ;
+                                                               System.err.println( "Error during initial VM archive send command: " ) ;
+                                                               e.printStackTrace() ;
+                                                               error = true ;
+                                                               pb++ ;
+                                                       } catch( InterruptedException e ) {
+                                                               e.printStackTrace() ;
+                                                               error = true ;
+                                                               pb++ ;
                                                        }
                                                        }
-                                                       
-                                                       error = true ;
-                                                       pb++ ;
                                                }
                                                }
-                                       } catch( IOException e ) {
-                                               System.err.println( "Error during initial VM archive send command: " ) ;
-                                               e.printStackTrace() ;
-                                               error = true ;
-                                               pb++ ;
-                                       } catch( InterruptedException e ) {
-                                               e.printStackTrace() ;
-                                               error = true ;
-                                               pb++ ;
-                                       }
                                
                                
                                
                                
-                                       if( error )
-                                       {
-                                               continue ;
-                                       }
+                                               if( error )
+                                               {
+                                                       continue ;
+                                               }
                                
                                
-                                       // Second try ...
-                                       ret = 1 ;
-                                       try {
-                                               ret = clients.get( i ).getStub().deployVM( _name, _archive, _directory ) ;
-                                       } catch( RemoteException e ) {
-                                               System.err.println( "Unable to deploy the VM on " + clients.get( i ).getName() + "!" ) ;
-                                               e.printStackTrace() ;
-                                               pb++ ;
+                                               // Second try ...
+                                               ret = 1 ;
+                                               try {
+                                                       ret = clients.get( i ).getStub().deployVM( _name, _archive, _directory ) ;
+                                               } catch( RemoteException e ) {
+                                                       System.err.println( "Unable to deploy the VM on " + clients.get( i ).getName() + "!" ) ;
+                                                       e.printStackTrace() ;
+                                                       pb++ ;
+                                               }
                                        }
                                        }
-                               }
                                
                                
-                               if( ret == 0 )
-                               {
-                                       System.out.println( "Initial VM archive successfully deployed on " + clients.get( i ).getName() + "." ) ;
-                                       nb++ ;
+                                       if( ret == 0 )
+                                       {
+                                               System.out.println( "Initial VM archive successfully deployed on " + clients.get( i ).getName() + "." ) ;
+                                               nb++ ;
+                                       }
                                }
                        }
                }
                                }
                        }
                }
@@ -994,7 +1108,7 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                        if( pb == 1 )
                                System.err.println( "** " + pb + " machine is not deployed!" ) ;
                        if( pb > 1 )
                        if( pb == 1 )
                                System.err.println( "** " + pb + " machine is not deployed!" ) ;
                        if( pb > 1 )
-                               System.err.println( "** " + pb + " machine(s) are not deployed!" ) ;
+                               System.err.println( "** " + pb + " machines are not deployed!" ) ;
                }
                
                return nb ;
                }
                
                return nb ;
index 4ea41da..fffec81 100644 (file)
@@ -38,19 +38,21 @@ public interface ServicesClient extends Remote
        
        public void saveOk() throws RemoteException ;
        
        
        public void saveOk() throws RemoteException ;
        
+       public void responseSave( boolean _b ) throws RemoteException ;
+       
        public Integer deployVM( String _name, String _archive, String _directory ) throws RemoteException ;
        
        public void changeSaveName( String _n1, String _n2, int _id ) throws RemoteException ;
        
        public Integer deployVM( String _name, String _archive, String _directory ) throws RemoteException ;
        
        public void changeSaveName( String _n1, String _n2, int _id ) throws RemoteException ;
        
-       public void setSavingNeighbor( ServicesClient _sn ) throws RemoteException ;
+       public void setSaveNeighbor( SaveNeighbor _sn ) throws RemoteException ;
        
        
-       public void setSavingNeighbors( ArrayList<ServicesClient> _sn ) throws RemoteException ;
+       public void setSaveNeighbors( ArrayList<SaveNeighbor> _sn ) throws RemoteException ;
        
        
-       public void addSavingNeighbor( ServicesClient _sn ) throws RemoteException ;
+       public void addSaveNeighbor( SaveNeighbor _sn ) throws RemoteException ;
        
        
-       public void addSavingNeighbors( ArrayList<ServicesClient> _sn ) throws RemoteException ;
+       public void addSaveNeighbors( ArrayList<SaveNeighbor> _sn ) throws RemoteException ;
        
        
-       public void replaceSavingNeighbor( String _old, ServicesClient _new ) throws RemoteException ;
+       public void replaceSaveNeighbor( SaveNeighbor _old, SaveNeighbor _new ) throws RemoteException ;
        
        public int retrieveSave( String _saveName ) throws RemoteException ;
        
        
        public int retrieveSave( String _saveName ) throws RemoteException ;
        
index 60ac97b..ed3acb6 100644 (file)
@@ -24,10 +24,13 @@ public interface ServicesServer extends Remote
        
        public void stop() throws RemoteException ;
        
        
        public void stop() throws RemoteException ;
        
+       public void requestSave( String _ip ) throws RemoteException ;
+       
        public Integer deployVM( String _name, String _archive, String _directory ) throws RemoteException ;
        
        public String getWorkingDirectory() throws RemoteException ;
 
        public Integer deployVM( String _name, String _archive, String _directory ) throws RemoteException ;
        
        public String getWorkingDirectory() throws RemoteException ;
 
+       public void restartOk( String _ip ) throws RemoteException ;
 }
 
 
 }
 
 
index 95a6683..adeab1b 100644 (file)
@@ -10,7 +10,7 @@ import java.io.InputStreamReader;
 import java.util.ArrayList;
 
 public class VirtualMachine 
 import java.util.ArrayList;
 
 public class VirtualMachine 
-{
+{      
        private String name ;
        private String ip ;
        private String initial_archive_name ;
        private String name ;
        private String ip ;
        private String initial_archive_name ;
@@ -25,7 +25,7 @@ public class VirtualMachine
        private Status status ;
        private int computation_id ;
        private String working_directory ;
        private Status status ;
        private int computation_id ;
        private String working_directory ;
-       private ArrayList<ServicesClient> save_neighbors ;
+       private ArrayList<SaveNeighbor> save_neighbors ;
        private String clientInVM ;
        private String vm_user ;
        private String vm_user_passwd ;
        private String clientInVM ;
        private String vm_user ;
        private String vm_user_passwd ;
@@ -50,7 +50,7 @@ public class VirtualMachine
                status = new Status() ;
                status.setStatus( "stopped" ) ;
                computation_id  = -1 ;
                status = new Status() ;
                status.setStatus( "stopped" ) ;
                computation_id  = -1 ;
-               save_neighbors = new ArrayList<ServicesClient>() ;
+               save_neighbors = new ArrayList<SaveNeighbor>() ;
                clientInVM = "/home/mpi/InGuest" ;
                vm_user = "mpi" ;
                vm_user_passwd = "mpi" ;
                clientInVM = "/home/mpi/InGuest" ;
                vm_user = "mpi" ;
                vm_user_passwd = "mpi" ;
@@ -66,18 +66,18 @@ public class VirtualMachine
        }
        
        
        }
        
        
-       public ArrayList<ServicesClient> getSaveNeighbors() { return save_neighbors ; }
+       public ArrayList<SaveNeighbor> getSaveNeighbors() { return save_neighbors ; }
        
        @SuppressWarnings("unchecked")
        
        @SuppressWarnings("unchecked")
-       public void setSaveNeighbors( ArrayList<ServicesClient> _sn )
+       public void setSaveNeighbors( ArrayList<SaveNeighbor> _sn )
        {
                if( _sn != null ) 
                {
        {
                if( _sn != null ) 
                {
-                       save_neighbors = (ArrayList<ServicesClient>) _sn.clone() ;
+                       save_neighbors = (ArrayList<SaveNeighbor>) _sn.clone() ;
                }
        }
        
                }
        }
        
-       public void addSaveNeighbor( ServicesClient _sn )
+       public void addSaveNeighbor( SaveNeighbor _sn )
        {
                if( _sn != null )
                {
        {
                if( _sn != null )
                {
@@ -385,6 +385,10 @@ public class VirtualMachine
 
        public int checkVmx() 
        {
 
        public int checkVmx() 
        {
+               deploy = false ;
+               first = false ;
+               deployFault = false ;
+               
                // Initial deployment
                File file = new File( working_directory + "/" + directory + "/initial.hpcvm" ) ;
                
                // Initial deployment
                File file = new File( working_directory + "/" + directory + "/initial.hpcvm" ) ;
                
@@ -415,6 +419,12 @@ public class VirtualMachine
                
                file = null ;
                
                
                file = null ;
                
+               // If nothing to do
+               if( ! deploy && ! first && ! deployFault )
+               {
+                       return 0 ;
+               }
+               
                // Deployment of the VM
                
                if( deploy )
                // Deployment of the VM
                
                if( deploy )
@@ -531,7 +541,7 @@ public class VirtualMachine
                
                                if( p.exitValue() == 0 )
                                {
                
                                if( p.exitValue() == 0 )
                                {
-                                       System.out.println( "Successfully deletion of the deployment mark." ) ;
+                                       System.out.println( "Successful deletion of the deployment mark." ) ;
                                } else {
                                        System.err.println( "Unsuccessful deletion of the deployment mark!" ) ;
                                        printProcessError( p ) ;
                                } else {
                                        System.err.println( "Unsuccessful deletion of the deployment mark!" ) ;
                                        printProcessError( p ) ;
@@ -661,7 +671,7 @@ public class VirtualMachine
                
                                if( p.exitValue() == 0 )
                                {
                
                                if( p.exitValue() == 0 )
                                {
-                                       System.out.println( "Successfully deletion of the first start mark." ) ;
+                                       System.out.println( "Successful deletion of the first start mark." ) ;
                                } else {
                                        System.err.println( "Unsuccessful deletion of the first start mark!" ) ;
                                        printProcessError( p ) ;
                                } else {
                                        System.err.println( "Unsuccessful deletion of the first start mark!" ) ;
                                        printProcessError( p ) ;
@@ -817,7 +827,7 @@ public class VirtualMachine
                
                                if( p.exitValue() == 0 )
                                {
                
                                if( p.exitValue() == 0 )
                                {
-                                       System.out.println( "Successfully deletion of the fault mark." ) ;
+                                       System.out.println( "Successful deletion of the fault mark." ) ;
                                } else {
                                        System.err.println( "Unsuccessful deletion of the fault mark!" ) ;
                                        printProcessError( p ) ;
                                } else {
                                        System.err.println( "Unsuccessful deletion of the fault mark!" ) ;
                                        printProcessError( p ) ;