Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Adding mechanism for application execution time retrievement plus bugs correction.
authorSébastien Miquée <sebastien.miquee@univ-fcomte.fr>
Mon, 18 Jul 2011 16:11:50 +0000 (18:11 +0200)
committerSébastien Miquée <sebastien.miquee@univ-fcomte.fr>
Mon, 18 Jul 2011 16:11:50 +0000 (18:11 +0200)
src/and/hpcvm/Client.java
src/and/hpcvm/Server.java
src/and/hpcvm/ServicesServer.java

index 3de9f2a..06bb4e7 100644 (file)
@@ -932,15 +932,6 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                
                if( ! lastSaveOk )
                {
                
                if( ! lastSaveOk )
                {
-//                     String arch1 = "", arch2 = "" ;
-//                     File file = new File( working_directory + "/" + machine.getName() + "_new_" + machine.getComputationId() + ".tar" )  ;
-//                     if( file.exists() )
-//                     {
-//                             arch1 = working_directory + "/" + machine.getName() + "_new_" + machine.getComputationId() + ".tar" ;
-//                     }
-//                     
-//                     file = null ;
-//                     
                        String arch = "" ;
                        File file = new File( working_directory + "/" + machine.getName() + "_new_" + machine.getComputationId() + ".tar.gz" ) ;
                        if( file.exists() )
                        String arch = "" ;
                        File file = new File( working_directory + "/" + machine.getName() + "_new_" + machine.getComputationId() + ".tar.gz" ) ;
                        if( file.exists() )
@@ -1019,42 +1010,6 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                                e.printStackTrace() ;
                                error = true ;
                        }
                                e.printStackTrace() ;
                                error = true ;
                        }
-               
-//                     /** Compression of the archive **/
-//                     if( ! error )
-//                     {
-//                             System.out.print( "Compression of the archive ... " ) ;
-//                             command = new String[]{ "/bin/gzip", 
-//                                             working_directory + "/" + machine.getName() 
-//                                             + "_new_" + machine.getComputationId() + ".tar" } ;
-//                             
-//                             if( emergencyStop )
-//                             {
-//                                     return 1 ;
-//                             }
-//                             
-//                             try {
-//                                     procSave = Runtime.getRuntime().exec( command ) ;
-//                                     procSave.waitFor() ;
-//                     
-//                                     if( procSave.exitValue() == 0 )
-//                                     {
-//                                             System.out.println( "Archive successfully compressed." ) ;
-//                                     } else {
-//                                             System.err.println( "Archive not compressed!" ) ;
-//                                             printProcessError( procSave ) ;
-//                                             
-//                                             error = true ;
-//                                     }
-//                             } catch( IOException e ) {
-//                                     System.err.println( "Error during archive compression command: " ) ;
-//                                     e.printStackTrace() ;
-//                                     error = true ;
-//                             } catch( InterruptedException e ) {
-//                                     e.printStackTrace() ;
-//                                     error = true ;
-//                             }
-//                     }
                        
                        long fin = System.currentTimeMillis() ;
                        
                        
                        long fin = System.currentTimeMillis() ;
                        
@@ -1403,13 +1358,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                        if( serverSocket != null )
                        {
                                try {
                        if( serverSocket != null )
                        {
                                try {
-                                       serverSocket.close() ;
-                                       
-//                                     for( int i = 0 ; i < dialogs.size() ; i++ )
-//                                     {
-//                                             dialogs.get( i ).stopDialogVM() ;
-//                                     }
-                                       
+                                       serverSocket.close() ;                                  
                                } catch( IOException e ) {
                                        e.printStackTrace() ;
                                }
                                } catch( IOException e ) {
                                        e.printStackTrace() ;
                                }
@@ -1438,8 +1387,7 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                                        socket = serverSocket.accept() ;
                                        
                                        new DialogVM( socket ).start() ;
                                        socket = serverSocket.accept() ;
                                        
                                        new DialogVM( socket ).start() ;
-//                                     dialogs.add( new DialogVM( socket ) ) ;
-//                                     dialogs.get( dialogs.size() - 1 ).start() ;     
+
                                } catch( IOException e ) {
                                        System.err.println( "Problem with the accept function!" ) ;
                                        e.printStackTrace() ;
                                } catch( IOException e ) {
                                        System.err.println( "Problem with the accept function!" ) ;
                                        e.printStackTrace() ;
@@ -1451,24 +1399,11 @@ public class Client extends UnicastRemoteObject implements ServicesClient
        
        private class DialogVM extends Thread
        {
        
        private class DialogVM extends Thread
        {
-               protected boolean go ;
                private Socket socket ;
                private BufferedReader reader ;
                private String line ;
                
                private Socket socket ;
                private BufferedReader reader ;
                private String line ;
                
-               DialogVM( Socket _socket ) { go = true ; socket = _socket ; }
-       
-               protected void stopDialogVM()
-               {
-                       go = false ;
-
-                       try {
-                               reader.close() ; reader = null ;
-                               socket.close() ; socket = null ;
-                       } catch( IOException e ) {
-                               e.printStackTrace() ;
-                       }
-               }
+               DialogVM( Socket _socket ) { socket = _socket ; }
        
                @Override
                public void run() 
        
                @Override
                public void run() 
@@ -1478,105 +1413,119 @@ public class Client extends UnicastRemoteObject implements ServicesClient
                        } catch( IOException e ) {
                                System.err.println( "Unable to open a dialog socket with the VM!" ) ;
                                e.printStackTrace();
                        } catch( IOException e ) {
                                System.err.println( "Unable to open a dialog socket with the VM!" ) ;
                                e.printStackTrace();
-                               stopDialogVM() ;
                        }
                        }
-                       
-//                     while( go )
-                       {
-                               try {
-                                       line = null ;
-                                       
-                                       if( reader != null )
-                                       {
-                                               line = reader.readLine() ;
-                                       }
-                                       
-                                       /** VM is starting -- retrieving informations **/
-                                       if( go && line != null &&  line.equalsIgnoreCase( "infos" ) )
+
+                       try {
+                               line = null ;
+
+                               if( reader != null )
+                               {
+                                       line = reader.readLine() ;
+                               }
+
+                               /** VM is starting -- retrieving informations **/
+                               if( line != null &&  line.equalsIgnoreCase( "infos" ) )
+                               {
+                                       /* Receiving name */
+                                       machine.setName( reader.readLine() ) ;
+
+                                       /* Receiving IP */
+                                       String ip = reader.readLine() ;
+                                       if( ! ip.equalsIgnoreCase( machine.getIp() ) )
                                        {
                                        {
-                                               /* Receiving name */
-                                               machine.setName( reader.readLine() ) ;
-                                               
-                                               /* Receiving IP */
-                                               String ip = reader.readLine() ;
-                                               if( ! ip.equalsIgnoreCase( machine.getIp() ) )
-                                               {
-                                                       System.err.println( "VM IP not well configured!!" ) ;
-                                               }
-                                               
-                                               /* Close streams */
-                                               reader.close() ; reader = null ;
-                                               socket.close() ; socket = null ;
-                                               
-                                               go = false ;
+                                               System.err.println( "VM IP not well configured!!" ) ;
                                        }
                                        }
-                                       
+
+                                       /* Close streams */
+                                       reader.close() ; reader = null ;
+                                       socket.close() ; socket = null ;
+
+                               } else if( line != null &&  line.equalsIgnoreCase( "save" ) ) {
                                        /** It's time to do a save **/
                                        /** It's time to do a save **/
-                                       if( go && line != null &&  line.equalsIgnoreCase( "save" ) )
-                                       {                                               
+
+                                       try {
+                                               machine.setComputationId( Integer.parseInt( reader.readLine() ) ) ;
+                                       } catch( Exception e ) {
+                                               System.err.println( "Problem while reading the computation id!" ) ;
+                                               e.printStackTrace() ;
+                                       }
+
+                                       synchronized( saveRequest ) 
+                                       {
                                                try {
                                                try {
-                                                       machine.setComputationId( Integer.parseInt( reader.readLine() ) ) ;
-                                               } catch( Exception e ) {
-                                                       System.err.println( "Problem while reading the computation id!" ) ;
+                                                       LocalHost.Instance().getServerStub().requestSave( LocalHost.Instance().getIP() ) ;
+                                               } catch( RemoteException e ) {
+                                                       System.err.println( "Unable to request save to server!" ) ;
                                                        e.printStackTrace() ;
                                                }
                                                        e.printStackTrace() ;
                                                }
-                                               
-                                               synchronized( saveRequest ) 
-                                               {
-                                                       try {
-                                                               LocalHost.Instance().getServerStub().requestSave( LocalHost.Instance().getIP() ) ;
-                                                       } catch( RemoteException e ) {
-                                                               System.err.println( "Unable to request save to server!" ) ;
-                                                               e.printStackTrace() ;
-                                                       }
-                                       
-                                                       try {
-                                                               saveRequest.wait() ;
-                                                       } catch( InterruptedException e ) {
-                                                               e.printStackTrace();
-                                                       }
-                                               }
-                                               
-                                               if( saveRequest.getStatus() )
-                                               {
-                                                       /* Close streams */
-                                                       reader.close() ; reader = null ;
-                                                       socket.close() ; socket = null ;
-                                                       
-                                                       go = false ;
-                                                       
-                                                       saveRequest.setStatus( false ) ;
-                                               
-                                                       /* Requesting the VM save */
-                                                       saveVM() ;
-                                               } else {
-                                                       sendSaveOkVM() ;
-                                               }
-                                       }
-                                       
-                                       
-                                       /** Computation is done, we can shutdown the VM **/
-                                       if( go && line != null &&  line.equalsIgnoreCase( "quit" ) )
-                                       {
+
                                                try {
                                                try {
-                                                       Thread.sleep( 5000 ) ;
+                                                       saveRequest.wait() ;
                                                } catch( InterruptedException e ) {
                                                } catch( InterruptedException e ) {
-                                                       e.printStackTrace() ;
+                                                       e.printStackTrace();
                                                }
                                                }
-                                               
+                                       }
+
+                                       if( saveRequest.getStatus() )
+                                       {
                                                /* Close streams */
                                                reader.close() ; reader = null ;
                                                socket.close() ; socket = null ;
                                                /* Close streams */
                                                reader.close() ; reader = null ;
                                                socket.close() ; socket = null ;
-                                               
-                                               go = false ;
-                                               
-                                               stopVM() ;
+
+                                               saveRequest.setStatus( false ) ;
+
+                                               /* Requesting the VM save */
+                                               saveVM() ;
+                                       } else {
+                                               sendSaveOkVM() ;
+                                       }
+                               } else if( line != null &&  line.equalsIgnoreCase( "quit" ) ) {
+                                       /** Computation is done, we can shutdown the VM **/
+
+                                       try {
+                                               Thread.sleep( 5000 ) ;
+                                       } catch( InterruptedException e ) {
+                                               e.printStackTrace() ;
+                                       }
+
+                                       /* Close streams */
+                                       reader.close() ; reader = null ;
+                                       socket.close() ; socket = null ;
+
+                                       stopVM() ;
+
+                                       machine.setStatus( "connected" ) ;
+                                       try {
+                                               LocalHost.Instance().getServerStub().changeStatus( 
+                                                               LocalHost.Instance().getIP(), "connected" ) ;
+                                       } catch( RemoteException e ) {
+                                               System.err.println( "Unable to inform the server of the VM status!" ) ;
+                                               e.printStackTrace() ;
                                        }
                                        
                                        }
                                        
-                               } catch( IOException e ) {
-                                       go = false ;
-                                       e.printStackTrace() ;
+                                       try {
+                                               LocalHost.Instance().getServerStub().endApplication() ;
+                                       } catch( RemoteException e ) {
+                                               System.err.println( "Unable to inform the server of the end of application!" ) ;
+                                               e.printStackTrace() ;
+                                       }
+                               } else if( line != null &&  line.equalsIgnoreCase( "start" ) ) {
+                                       /** Computation is starting **/
+
+                                       /* Close streams */
+                                       reader.close() ; reader = null ;
+                                       socket.close() ; socket = null ;
+                                       
+                                       try {
+                                               LocalHost.Instance().getServerStub().goApplication() ;
+                                       } catch( RemoteException e ) {
+                                               System.err.println( "Unable to inform the server of the end of application!" ) ;
+                                               e.printStackTrace() ;
+                                       }
                                }
                                }
+
+                       } catch( IOException e ) {
+                               e.printStackTrace() ;
                        }
                }
        }
                        }
                }
        }
index e865eb2..8f35386 100644 (file)
@@ -84,7 +84,9 @@ public class Server extends UnicastRemoteObject implements ServicesServer
        private OperatingClients startingClients ;
        private OperatingClients deployingClients ;
        private LimitThread limitThread ;
        private OperatingClients startingClients ;
        private OperatingClients deployingClients ;
        private LimitThread limitThread ;
-       private int maxThread;
+       private int maxThread ;
+       private int ind ;
+       private boolean running ;
        
        
        protected Server() throws RemoteException 
        
        
        protected Server() throws RemoteException 
@@ -195,17 +197,8 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                        {
                                if( _ip.equals( clients.get( i ).getIP() ) ) 
                                {                                       
                        {
                                if( _ip.equals( clients.get( i ).getIP() ) ) 
                                {                                       
-                                       if( _status.equalsIgnoreCase( "stopped" ) )
-                                       {
-                                               System.out.println( "Client " + clients.get( i ).getName() + " is stopped." ) ;
-                                               clients.get( i ).setStatus( "connected" ) ;
-                                               ComputingClient cc = clients.get( i ).getComputingClient() ;
-                                               computingClients.remove( cc ) ;
-                                               clients.get( i ).setComputingClient( null ) ;
-                                       } else {
-                                               clients.get( i ).setStatus( _status ) ;
-                                               System.out.println( "Client " + clients.get( i ).getName() + " changed its status to: " + _status ) ;
-                                       }
+                                       clients.get( i ).setStatus( _status ) ;
+                                       System.out.println( "Client " + clients.get( i ).getName() + " changed its status to: " + _status ) ;
                                        
                                        break ;
                                }
                                        
                                        break ;
                                }
@@ -229,6 +222,9 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                limitThread = new LimitThread() ;
                maxThread = 20 ;
                
                limitThread = new LimitThread() ;
                maxThread = 20 ;
                
+               ind = -1 ;
+               running = false ;
+               
                working_directory = "/localhome/vmware" ;
                
                save_interleave  = 30 * 60 * 1000 ;
                working_directory = "/localhome/vmware" ;
                
                save_interleave  = 30 * 60 * 1000 ;
@@ -439,11 +435,11 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                                                }
                                                                
                                                                // Replacing in RunningApplication
                                                                }
                                                                
                                                                // Replacing in RunningApplication
-                                                               applications.get( 0 ).replaceComputingClient( cc, ccl ) ;
+                                                               applications.get( ind ).replaceComputingClient( cc, ccl ) ;
                                                                
                                                                
-                                                               for( int l = 0 ; l < applications.get(0).getComputingClients().size() ; l++ )
+                                                               for( int l = 0 ; l < applications.get( ind ).getComputingClients().size() ; l++ )
                                                                {
                                                                {
-                                                                       applications.get(0).getComputingClients().get( l ).setSaveRequest( false ) ;
+                                                                       applications.get( ind ).getComputingClients().get( l ).setSaveRequest( false ) ;
                                                                }
                                                                
                                                                        
                                                                }
                                                                
                                                                        
@@ -452,10 +448,6 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                                                System.err.println( "Unable to deploy the save on the new computing client!" ) ;
                                                        }
                                                }
                                                                System.err.println( "Unable to deploy the save on the new computing client!" ) ;
                                                        }
                                                }
-//                                             } else {
-//                                                     System.err.println( "Problem while launching the VM on " 
-//                                                                     + clients.get(i).getName() + "!" ) ;
-//                                             }
                                                        
                                                if( ok )
                                                {
                                                        
                                                if( ok )
                                                {
@@ -608,11 +600,11 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                                }
                                        }
                                        
                                                }
                                        }
                                        
-                                       for( int  i = 0 ; i < applications.get(0).getComputingClients().size() ; i++ )
+                                       for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
                                        {
                                        {
-                                               final ServicesClient sc = applications.get(0).getComputingClients().get( i ).getClient().getStub() ;
+                                               final ServicesClient sc = applications.get( ind ).getComputingClients().get( i ).getClient().getStub() ;
                                                
                                                
-                                               applications.get( 0 ).getComputingClients().get( i ).setRestartOk( false ) ;
+                                               applications.get( ind ).getComputingClients().get( i ).setRestartOk( false ) ;
                                                
                                                new Thread( new Runnable() {
                                                        
                                                
                                                new Thread( new Runnable() {
                                                        
@@ -675,7 +667,7 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                computingClients.get( i ).setSaveStatus( false ) ;
                        }
                        
                                computingClients.get( i ).setSaveStatus( false ) ;
                        }
                        
-                       applications.get( 0 ).setLastSaveDate( System.currentTimeMillis() ) ;
+                       applications.get( ind ).setLastSaveDate( System.currentTimeMillis() ) ;
                }
                
                return 0 ;
                }
                
                return 0 ;
@@ -691,7 +683,7 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                if( computingClients.get( i ).getClient().getIP().equalsIgnoreCase( _ip ) ) 
                                {
                                        computingClients.get( i ).setLastSave( _saveName ) ;
                                if( computingClients.get( i ).getClient().getIP().equalsIgnoreCase( _ip ) ) 
                                {
                                        computingClients.get( i ).setLastSave( _saveName ) ;
-                                       System.out.println( "Save name successfully changed for " + _ip ) ;
+                                       System.out.println( "Save name successfully changed on " + _ip ) ;
                                        return 0 ;
                                }
                        }
                                        return 0 ;
                                }
                        }
@@ -705,8 +697,10 @@ public class Server extends UnicastRemoteObject implements ServicesServer
        {
                int nb = clients.size() - computingClients.size() ;
                
        {
                int nb = clients.size() - computingClients.size() ;
                
-               if( nb > _nb )
+               if( nb > _nb && ! running )
                {
                {
+                       running = true ;
+                       
                        final ArrayList<ServicesClient> ac = new ArrayList<ServicesClient>() ;
                        final ArrayList<ComputingClient> tmp = new ArrayList<ComputingClient>() ;
                        
                        final ArrayList<ServicesClient> ac = new ArrayList<ServicesClient>() ;
                        final ArrayList<ComputingClient> tmp = new ArrayList<ComputingClient>() ;
                        
@@ -756,7 +750,7 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                                        limitThread.inc() ;
                                                }
                                                
                                                        limitThread.inc() ;
                                                }
                                                
-                                               final int ind = i ;
+                                               final int indice = i ;
                                                new Thread( new Runnable(){
                                                        
                                                        @Override
                                                new Thread( new Runnable(){
                                                        
                                                        @Override
@@ -764,22 +758,22 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                                        {
                                                                int res = 1 ;
                                                                try {
                                                        {
                                                                int res = 1 ;
                                                                try {
-                                                                       res = clients.get( ind ).getStub().startVM( 0 ) ;
+                                                                       res = clients.get( indice ).getStub().startVM( 0 ) ;
                                                                } catch( RemoteException e ) {
                                                                        e.printStackTrace();
                                                                }
                                                                
                                                                if( res == 0 )
                                                                {
                                                                } catch( RemoteException e ) {
                                                                        e.printStackTrace();
                                                                }
                                                                
                                                                if( res == 0 )
                                                                {
-                                                                       ac.add( clients.get( ind ).getStub() ) ;
-                                                                       clients.get( ind ).setStatus( "running" ) ;
-                                                                       ComputingClient cl = new ComputingClient( clients.get( ind ) ) ;
-                                                                       clients.get( ind ).setComputingClient( cl ) ;
+                                                                       ac.add( clients.get( indice ).getStub() ) ;
+                                                                       clients.get( indice ).setStatus( "running" ) ;
+                                                                       ComputingClient cl = new ComputingClient( clients.get( indice ) ) ;
+                                                                       clients.get( indice ).setComputingClient( cl ) ;
                                                                        computingClients.add( cl ) ;
                                                                        tmp.add( cl ) ;
                                                                } else {
                                                                        System.err.println( "Problem while launching the VM on " 
                                                                        computingClients.add( cl ) ;
                                                                        tmp.add( cl ) ;
                                                                } else {
                                                                        System.err.println( "Problem while launching the VM on " 
-                                                                                       + clients.get(ind).getName() + "!" ) ;
+                                                                                       + clients.get( indice ).getName() + "!" ) ;
                                                                }
                                                                
                                                                synchronized( limitThread )
                                                                }
                                                                
                                                                synchronized( limitThread )
@@ -805,7 +799,7 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                        {
                                app.setComputingClients( tmp ) ;
                                app.setRunning( true ) ;
                        {
                                app.setComputingClients( tmp ) ;
                                app.setRunning( true ) ;
-                               app.setStartTime( System.currentTimeMillis() ) ;
+//                             app.setStartTime( System.currentTimeMillis() ) ;
                                
                                int index, index2 ;
                                /* Choosing save neighbors */
                                
                                int index, index2 ;
                                /* Choosing save neighbors */
@@ -848,6 +842,8 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                        
                        applications.add( app ) ;
                        
                        
                        applications.add( app ) ;
                        
+                       ind = applications.indexOf( app ) ;
+                       
                        return ac ;
                }
                
                        return ac ;
                }
                
@@ -882,14 +878,14 @@ public class Server extends UnicastRemoteObject implements ServicesServer
        {
                if( applications.size() > 0 && _ip != null && _ip.length() > 0 )
                {
        {
                if( applications.size() > 0 && _ip != null && _ip.length() > 0 )
                {
-                       if( (System.currentTimeMillis() - applications.get( 0 ).getLastSaveDate()) > save_interleave )
+                       if( (System.currentTimeMillis() - applications.get( ind ).getLastSaveDate()) > save_interleave )
                        {
                                // Mark it as a requester
                        {
                                // Mark it as a requester
-                               for( int i = 0 ; i < applications.get( 0 ).getComputingClients().size() ; i++ )
+                               for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
                                {
                                {
-                                       if( applications.get( 0 ).getComputingClients().get( i ).getClient().getIP().equalsIgnoreCase( _ip ) )
+                                       if( applications.get( ind ).getComputingClients().get( i ).getClient().getIP().equalsIgnoreCase( _ip ) )
                                        {
                                        {
-                                               applications.get( 0 ).getComputingClients().get( i ).setSaveRequest( true ) ;
+                                               applications.get( ind ).getComputingClients().get( i ).setSaveRequest( true ) ;
                                                                                                
                                                break ;
                                        }
                                                                                                
                                                break ;
                                        }
@@ -899,13 +895,13 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                
                                // Is every body ok?
                                boolean ok = false ;
                                
                                // Is every body ok?
                                boolean ok = false ;
-                               for( int i = 0 ; i < applications.get( 0 ).getComputingClients().size() ; i++ )
+                               for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
                                {
                                        if( i == 0 )
                                        {
                                {
                                        if( i == 0 )
                                        {
-                                               ok = applications.get( 0 ).getComputingClients().get( i ).getSaveRequest() ;
+                                               ok = applications.get( ind ).getComputingClients().get( i ).getSaveRequest() ;
                                        } else {
                                        } else {
-                                               ok = ok & applications.get( 0 ).getComputingClients().get( i ).getSaveRequest() ;       
+                                               ok = ok & applications.get( ind ).getComputingClients().get( i ).getSaveRequest() ;     
                                        }
                                        
                                        if( ! ok )
                                        }
                                        
                                        if( ! ok )
@@ -922,33 +918,33 @@ public class Server extends UnicastRemoteObject implements ServicesServer
 //                                             e1.printStackTrace() ;
 //                                     }
                                        
 //                                             e1.printStackTrace() ;
 //                                     }
                                        
-                                       for( int i = 0 ; i < applications.get( 0 ).getComputingClients().size() ; i++ )
+                                       for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
                                        {
                                                try {
                                        {
                                                try {
-                                                       applications.get( 0 ).getComputingClients().get( i ).getClient().getStub().responseSave( true ) ;
-                                                       applications.get( 0 ).getComputingClients().get( i ).setSaveRequest( false ) ;                                                  
+                                                       applications.get( ind ).getComputingClients().get( i ).getClient().getStub().responseSave( true ) ;
+                                                       applications.get( ind ).getComputingClients().get( i ).setSaveRequest( false ) ;                                                        
                                                } catch( RemoteException e ) {
                                                        System.err.println( "Unable to send the save request response to " +
                                                } catch( RemoteException e ) {
                                                        System.err.println( "Unable to send the save request response to " +
-                                                                       applications.get( 0 ).getComputingClients().get( i ).getClient().getName() + "!" ) ;
+                                                                       applications.get( ind ).getComputingClients().get( i ).getClient().getName() + "!" ) ;
                                                        e.printStackTrace() ; 
                                                }
                                        }
                                        
                                                        e.printStackTrace() ; 
                                                }
                                        }
                                        
-                                       applications.get( 0 ).setLastSaveDate( System.currentTimeMillis() ) ;
+                                       applications.get( ind ).setLastSaveDate( System.currentTimeMillis() ) ;
                                }
                                
                        } else {
                                semaSave.release() ;
                                
                                }
                                
                        } else {
                                semaSave.release() ;
                                
-                               for( int i = 0 ; i < applications.get( 0 ).getComputingClients().size() ; i++ )
+                               for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
                                {
                                {
-                                       if( applications.get( 0 ).getComputingClients().get( i ).getClient().getIP().equalsIgnoreCase( _ip ) )
+                                       if( applications.get( ind ).getComputingClients().get( i ).getClient().getIP().equalsIgnoreCase( _ip ) )
                                        {
                                                try {
                                        {
                                                try {
-                                                       applications.get( 0 ).getComputingClients().get( i ).getClient().getStub().responseSave( false ) ;
+                                                       applications.get( ind ).getComputingClients().get( i ).getClient().getStub().responseSave( false ) ;
                                                } catch( RemoteException e ) {
                                                        System.err.println( "Unable to send the save request response to " +
                                                } catch( RemoteException e ) {
                                                        System.err.println( "Unable to send the save request response to " +
-                                                                       applications.get( 0 ).getComputingClients().get( i ).getClient().getName() + "!" ) ;
+                                                                       applications.get( ind ).getComputingClients().get( i ).getClient().getName() + "!" ) ;
                                                        e.printStackTrace() ; 
                                                }
                                                break ;
                                                        e.printStackTrace() ; 
                                                }
                                                break ;
@@ -967,15 +963,15 @@ public class Server extends UnicastRemoteObject implements ServicesServer
        {
                if( applications.size() > 0 && _ip != null && _ip.length() > 0 )
                {
        {
                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 )
+                       System.out.println( "Client " + _ip + " has finished to restart ("+applications.get( ind ).getComputingClients().size()+") ... " ) ;
+                       if( (System.currentTimeMillis() - applications.get( ind ).getLastSaveDate()) > save_interleave )
                        {
                                // Has it already finished?
                        {
                                // Has it already finished?
-                               for( int i = 0 ; i < applications.get( 0 ).getComputingClients().size() ; i++ )
+                               for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
                                {
                                {
-                                       if( applications.get( 0 ).getComputingClients().get( i ).getClient().getIP().equalsIgnoreCase( _ip ) )
+                                       if( applications.get( ind ).getComputingClients().get( i ).getClient().getIP().equalsIgnoreCase( _ip ) )
                                        {
                                        {
-                                               applications.get( 0 ).getComputingClients().get( i ).setRestartOk( true ) ;
+                                               applications.get( ind ).getComputingClients().get( i ).setRestartOk( true ) ;
                                                                                                
                                                break ;
                                        }
                                                                                                
                                                break ;
                                        }
@@ -983,13 +979,13 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                
                                // Is every body ok?
                                boolean ok = false ;
                                
                                // Is every body ok?
                                boolean ok = false ;
-                               for( int i = 0 ; i < applications.get( 0 ).getComputingClients().size() ; i++ )
+                               for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
                                {
                                        if( i == 0 )
                                        {
                                {
                                        if( i == 0 )
                                        {
-                                               ok = applications.get( 0 ).getComputingClients().get( i ).getRestartOk() ;
+                                               ok = applications.get( ind ).getComputingClients().get( i ).getRestartOk() ;
                                        } else {
                                        } else {
-                                               ok = ok & applications.get( 0 ).getComputingClients().get( i ).getRestartOk() ; 
+                                               ok = ok & applications.get( ind ).getComputingClients().get( i ).getRestartOk() ;       
                                        }
                                        
                                        if( ! ok )
                                        }
                                        
                                        if( ! ok )
@@ -1000,11 +996,11 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                
                                if( ok )
                                {
                                
                                if( ok )
                                {
-                                       applications.get( 0 ).setLastSaveDate( System.currentTimeMillis() ) ;
+                                       applications.get( ind ).setLastSaveDate( System.currentTimeMillis() ) ;
                                        
                                        
-                                       for( int i = 0 ; i < applications.get( 0 ).getComputingClients().size() ; i++ )
+                                       for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
                                        {
                                        {
-                                               applications.get( 0 ).getComputingClients().get( i ).setRestartOk( false ) ;
+                                               applications.get( ind ).getComputingClients().get( i ).setRestartOk( false ) ;
                                        }
                                }
                                
                                        }
                                }
                                
@@ -1012,32 +1008,54 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                }
        }       
        
                }
        }       
        
+       
+       @Override
+       public void goApplication()
+       {
+               synchronized( applications ) {
+               if( running && applications.get( ind ).getStartTime() != 0 )
+               {
+                       applications.get( ind ).setStartTime( System.currentTimeMillis() ) ;
+                       applications.get( ind ).setLastSaveDate( System.currentTimeMillis() ) ;
+               }}
+       }
+       
 
        @Override
        public void endApplication() 
        {
 
        @Override
        public void endApplication() 
        {
-               Iterator<ComputingClient> it = computingClients.iterator() ;
-               
-               while( it.hasNext() )
+               synchronized( applications )
                {
                {
-                       ComputingClient cl = it.next() ;
+               if( running )
+               {
+                       Iterator<ComputingClient> it = computingClients.iterator() ;
+               
+                       while( it.hasNext() )
+                       {
+                               ComputingClient cl = it.next() ;
 
 
-                       try {
-                               cl.getClient().getStub().emergencyStop() ;
-                       } catch (RemoteException e) {
-                               e.printStackTrace();
-                       }
+                               try {
+                                       cl.getClient().getStub().emergencyStop() ;
+                               } catch (RemoteException e) {
+                                       e.printStackTrace();
+                               }
                        
                        
-                       cl.getClient().setStatus( "connected" ) ;
-                       cl.getClient().setComputingClient( null ) ;
-                       it.remove() ;
-                       cl = null ;
-               }
-               
-               applications.get( 0 ).setEndTime( System.currentTimeMillis() ) ;
-               applications.get( 0 ).setRunning( false ) ;
-               applications.get( 0 ).clear() ;
+                               cl.getClient().setStatus( "connected" ) ;
+                               cl.getClient().setComputingClient( null ) ;
+                               it.remove() ;
+                               cl = null ;
+                       }
                
                
+                       applications.get( ind ).setEndTime( System.currentTimeMillis() ) ;
+                       applications.get( ind ).setRunning( false ) ;
+                       applications.get( ind ).clear() ;
+//                     applications.remove( ind ) ;
+                       
+                       running = false ;
+                       
+                       System.out.println( "Application " + applications.get( ind ).getName() + " ends in " + 
+                                       applications.get( ind ).getExecutionTime() + " seconds." ) ;
+               }}
        }
 
 
        }
 
 
@@ -1088,8 +1106,8 @@ public class Server extends UnicastRemoteObject implements ServicesServer
 //                     boolean error, ok, server ;
 //                     ArrayList<ConnectedClient> deployed = new ArrayList<ConnectedClient>() ;
                        
 //                     boolean error, ok, server ;
 //                     ArrayList<ConnectedClient> deployed = new ArrayList<ConnectedClient>() ;
                        
-                       boolean server = true ;
-                       boolean ok ;
+//                     boolean server = true ;
+//                     boolean ok ;
                        
                        for( int i = 0 ; i < clients.size() ; i++ )
                        {
                        
                        for( int i = 0 ; i < clients.size() ; i++ )
                        {
@@ -1113,7 +1131,7 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                                limitThread.inc() ;
                                        }
                                        
                                                limitThread.inc() ;
                                        }
                                        
-                                       final int ind = i ;
+                                       final int indice = i ;
                                        new Thread( new Runnable() {
 
                                                @Override
                                        new Thread( new Runnable() {
 
                                                @Override
@@ -1122,9 +1140,9 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                                        boolean error = true  ;
                                                        
                                                        try {
                                                        boolean error = true  ;
                                                        
                                                        try {
-                                                               ret = clients.get( ind ).getStub().deployVM( _name, _archive, _directory ) ;
+                                                               ret = clients.get( indice ).getStub().deployVM( _name, _archive, _directory ) ;
                                                        } catch( RemoteException e ) {
                                                        } catch( RemoteException e ) {
-                                                               System.err.println( "Unable to deploy the VM on " + clients.get( ind ).getName() + "!" ) ;
+                                                               System.err.println( "Unable to deploy the VM on " + clients.get( indice ).getName() + "!" ) ;
                                                                e.printStackTrace() ;
                                                        }
                                        
                                                                e.printStackTrace() ;
                                                        }
                                        
@@ -1132,17 +1150,17 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                                        if( ret == 2 )
                                                        {
                                                                // Attention au multi-envois !!!
                                                        if( ret == 2 )
                                                        {
                                                                // Attention au multi-envois !!!
-                                                               System.out.print( "Sending VM archive to " + clients.get( ind ).getName() + " ... " ) ;
+                                                               System.out.print( "Sending VM archive to " + clients.get( indice ).getName() + " ... " ) ;
                                        
                                                                String wd = "" ;
                                                                String snIP = "" ;
                                                                error = false ;
                                        
                                                                try {
                                        
                                                                String wd = "" ;
                                                                String snIP = "" ;
                                                                error = false ;
                                        
                                                                try {
-                                                                       wd = clients.get( ind ).getStub().getWorkingDirectory() ;
-                                                                       snIP = clients.get( ind ).getStub().getIPHost() ;
+                                                                       wd = clients.get( indice ).getStub().getWorkingDirectory() ;
+                                                                       snIP = clients.get( indice ).getStub().getIPHost() ;
                                                                } catch (RemoteException e2) {
                                                                } catch (RemoteException e2) {
-                                                                       System.err.println( "Unable to retrieve information on " + clients.get( ind ).getName() + "!" ) ;
+                                                                       System.err.println( "Unable to retrieve information on " + clients.get( indice ).getName() + "!" ) ;
                                                                        e2.printStackTrace() ;
                                                                        error = true ;
                                                                }
                                                                        e2.printStackTrace() ;
                                                                        error = true ;
                                                                }
@@ -1192,9 +1210,9 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                                                        // Second try ...
                                                                        ret = 1 ;
                                                                        try {
                                                                        // Second try ...
                                                                        ret = 1 ;
                                                                        try {
-                                                                               ret = clients.get( ind ).getStub().deployVM( _name, _archive, _directory ) ;
+                                                                               ret = clients.get( indice ).getStub().deployVM( _name, _archive, _directory ) ;
                                                                        } catch( RemoteException e ) {
                                                                        } catch( RemoteException e ) {
-                                                                               System.err.println( "Unable to deploy the VM on " + clients.get( ind ).getName() + "!" ) ;
+                                                                               System.err.println( "Unable to deploy the VM on " + clients.get( indice ).getName() + "!" ) ;
                                                                                e.printStackTrace() ;
                                                                        }
                                                                }
                                                                                e.printStackTrace() ;
                                                                        }
                                                                }
@@ -1202,7 +1220,7 @@ public class Server extends UnicastRemoteObject implements ServicesServer
                                
                                                        if( ret == 0 )
                                                        {
                                
                                                        if( ret == 0 )
                                                        {
-                                                               System.out.println( "Initial VM archive successfully deployed on " + clients.get( ind ).getName() + "." ) ;
+                                                               System.out.println( "Initial VM archive successfully deployed on " + clients.get( indice ).getName() + "." ) ;
                                                                
                                                                synchronized( deployingClients )
                                                                {
                                                                
                                                                synchronized( deployingClients )
                                                                {
index ed3acb6..863e393 100644 (file)
@@ -22,6 +22,8 @@ public interface ServicesServer extends Remote
        
        public void endApplication() throws RemoteException ;
        
        
        public void endApplication() throws RemoteException ;
        
+       public void goApplication() throws RemoteException ;
+       
        public void stop() throws RemoteException ;
        
        public void requestSave( String _ip ) throws RemoteException ;
        public void stop() throws RemoteException ;
        
        public void requestSave( String _ip ) throws RemoteException ;