3 import java.io.BufferedReader;
5 import java.io.IOException;
6 import java.io.InputStreamReader;
7 import java.rmi.Naming;
8 import java.rmi.RemoteException;
9 import java.rmi.registry.LocateRegistry;
10 import java.rmi.registry.Registry;
11 import java.rmi.server.UnicastRemoteObject;
12 import java.util.ArrayList;
13 import java.util.Iterator;
14 import java.util.concurrent.Semaphore;
17 public class Server extends UnicastRemoteObject implements ServicesServer
19 private class DiscCount
23 DiscCount() { nb = 0 ; }
25 protected void inc() { nb++ ; }
27 protected void dec() {
34 protected int getNb() { return nb ; }
38 private class IPAssociation
41 private String hostIP ;
49 protected void setVmIP( String _vmIP )
54 protected void setHostIP( String _hostIP )
59 protected String getVmIP()
64 protected String getHostIP()
72 private static final long serialVersionUID = 1L ;
74 private ArrayList<ConnectedClient> clients ;
75 private ArrayList<ComputingClient> computingClients ;
76 private ArrayList<RunningApplication> applications ;
77 private int max_timeout ;
78 private ConnectedMonitor monitor ;
79 private DiscCount counter ;
80 private ArrayList<IPAssociation> vmIPs ;
81 private String working_directory ;
82 private long save_interleave ;
83 private Semaphore semaSave ;
84 private OperatingClients startingClients ;
85 private OperatingClients deployingClients ;
86 private LimitThread limitThread ;
87 private int maxThread;
90 protected Server() throws RemoteException
98 public Integer register( ServicesClient _stub )
102 synchronized( clients )
106 ip = _stub.getIPHost() ;
107 } catch (RemoteException e) {
108 e.printStackTrace() ;
112 boolean exists = false ;
115 for( i = 0 ; i < clients.size() ; i++ )
117 if( ip.equals( clients.get( i ).getIP() ) )
120 System.out.println( "Client already connected!" ) ;
127 System.out.println( "The client stub will be replaced." ) ;
128 clients.get( i ).setStub( _stub ) ;
129 System.out.println( "(reconnection of " + clients.get( i ).getName() + ")" ) ;
132 System.out.println( "New connection!" ) ;
133 clients.add( new ConnectedClient( _stub ) ) ;
134 System.out.println( "(connection of " + clients.get( clients.size() - 1 ).getName() + ")" ) ;
137 if( clients.size() == 0 )
139 System.out.println( "There is no client connected." ) ;
140 } else if( clients.size() == 1 ) {
141 System.out.println( "There is one client connected." ) ;
143 System.out.println( "There are " + clients.size() + " clients connected." ) ;
155 private void generateVmIP( String _ip )
157 if( _ip != null && ! _ip.equals( "" ) )
159 for( int i = 0 ; i < vmIPs.size() ; i++ )
161 if( vmIPs.get( i ).getHostIP().equalsIgnoreCase( "" ) )
163 vmIPs.get( i ).setHostIP( _ip ) ;
173 public void ping( String _ip )
177 for( int i = 0 ; i < clients.size() ; i++ )
179 if( _ip.equals( clients.get( i ).getIP() ) )
181 clients.get( i ).resetTimeout() ;
190 public void changeStatus( String _ip, String _status )
192 if( _ip != null && _status != null )
194 for( int i = 0 ; i < clients.size() ; i++ )
196 if( _ip.equals( clients.get( i ).getIP() ) )
198 if( _status.equalsIgnoreCase( "stopped" ) )
200 System.out.println( "Client " + clients.get( i ).getName() + " is stopped." ) ;
201 clients.get( i ).setStatus( "connected" ) ;
202 ComputingClient cc = clients.get( i ).getComputingClient() ;
203 computingClients.remove( cc ) ;
204 clients.get( i ).setComputingClient( null ) ;
206 clients.get( i ).setStatus( _status ) ;
207 System.out.println( "Client " + clients.get( i ).getName() + " changed its status to: " + _status ) ;
217 public void init( int _port )
222 clients = new ArrayList<ConnectedClient>() ;
223 computingClients = new ArrayList<ComputingClient>() ;
224 applications = new ArrayList<RunningApplication>() ;
227 startingClients = new OperatingClients() ;
228 deployingClients = new OperatingClients() ;
229 limitThread = new LimitThread() ;
232 working_directory = "/localhome/vmware" ;
234 save_interleave = 30 * 60 * 1000 ;
236 semaSave = new Semaphore( 1 ) ;
240 vmIPs = new ArrayList<IPAssociation>() ;
241 // TODO initialisation of VM IPs
242 for( int i = 2 ; i < 101 ; i++ )
244 vmIPs.add( new IPAssociation() ) ;
245 vmIPs.get( vmIPs.size() - 1 ).setVmIP( "10.11.10." + i ) ;
248 clients = new ArrayList<ConnectedClient>() ;
250 counter = new DiscCount() ;
252 monitor = new ConnectedMonitor() ;
256 // Check if there are running applications ... and restart them :)
262 if( monitor != null ) { monitor.stopMonitor() ; }
264 for( int i = 0 ; i < clients.size() ; i++ )
267 clients.get( i ).getStub().emergencyStop() ;
268 clients.get( i ).getStub().stop() ;
269 } catch (RemoteException e) {
280 private void exportObject()
282 ServicesServer ref = null ;
283 Registry reg = null ;
289 reg = LocateRegistry.getRegistry( port ) ;
291 String tab[] = reg.list() ;
293 System.out.println( "There is an existing RMI Registry on port " +
294 port + " with " + tab.length + " entries!" ) ;
295 for( int i = 0 ; i < tab.length ; i++ )
298 if( UnicastRemoteObject.unexportObject( Naming.lookup(tab[i]), true ) )
300 System.out.println( "Register successfuly deleted!" ) ;
302 System.err.println( "Register undeleted !!!" ) ;
304 } catch( Exception e ) {
305 e.printStackTrace() ;
309 } catch( RemoteException e ) {
313 if ( System.getSecurityManager() == null )
315 System.setSecurityManager( new SecurityManager() ) ;
318 LocateRegistry.createRegistry( port ) ;
319 LocateRegistry.getRegistry( port ).rebind( "Server", this ) ;
320 ref = (ServicesServer) Naming.lookup( "rmi://"
321 + LocalHost.Instance().getIP() + ":" + port
323 } catch ( Exception e ) {
324 System.err.println( "Error in Server.exportObject() when creating local services:" + e ) ;
325 System.err.println( "Exit from Server.exportObject" ) ;
329 LocalHost.Instance().setServerStub( ref ) ;
331 System.out.println( "Server launched on IP " + LocalHost.Instance().getIP() +
332 " on port " + port + "." ) ;
335 /** Fault manager thread **/
336 private class FaultManager extends Thread
340 FaultManager( ConnectedClient _cl )
348 if( cl != null && cl.getStatus().equalsIgnoreCase( "running" ) ||
349 cl.getStatus().equalsIgnoreCase( "saving" ) )
351 ComputingClient cc = cl.getComputingClient() ;
352 // ServicesClient dead = cc.getClient().getStub() ;
353 String ipDead = cc.getClient().getIP() ;
354 SaveNeighbor snDead = null ;
355 for( int i = 0 ; i < computingClients.size() ; i++ )
357 if( computingClients.get( i ).getSaveNeighbor().getIPHost().equalsIgnoreCase( ipDead ) )
359 snDead = computingClients.get( i ).getSaveNeighbor() ;
366 for( int i = 0 ; i < clients.size() ; i++ )
368 if( clients.get( i ).getStatus().equalsIgnoreCase( "connected" ) )
372 // res = clients.get( i ).getStub().startVM() ;
373 // } catch( RemoteException e ) {
374 // e.printStackTrace();
379 //clients.get(i).setStatus( "running" ) ;
381 int pos = computingClients.indexOf( cc ) ;
384 System.err.println( "Dead client not found in the computing clients list!" ) ;
386 System.out.println( "Trying to replace " + cc.getClient().getName() + " with " +
387 clients.get(i).getName() + " ... " ) ;
389 String save_name = computingClients.get( pos ).getLastSave() ;
391 ComputingClient ccl = new ComputingClient( clients.get(i) ) ;
392 clients.get( i ).setComputingClient( ccl ) ;
393 SaveNeighbor sn = computingClients.get( pos ).getSaveNeighbor() ;
394 ccl.setSaveNeighbor( sn ) ;
395 computingClients.set( pos, ccl ) ;
400 res = computingClients.get( pos ).getClient().getStub().
401 retrieveSave( save_name ) ;
402 } catch( RemoteException e ) {
403 System.err.println( "Unable to indicate to client to retrieve last save!" ) ;
404 e.printStackTrace() ;
411 boolean ok_new = false, ok_old = false ;
413 // replace dead client in vmIPs
414 for( int j = 0 ; j < vmIPs.size() ; j++ )
416 if( vmIPs.get( j ).getHostIP().equalsIgnoreCase( computingClients.get( pos ).getClient().getIP() ) )
418 vmIPs.get( j ).setHostIP( "" ) ;
421 if( vmIPs.get( j ).getHostIP().equalsIgnoreCase( ipDead ) )
423 String vmIP = vmIPs.get( j ).getVmIP() ;
424 vmIPs.get( j ).setHostIP( computingClients.get( pos ).getClient().getIP() ) ;
428 computingClients.get( pos ).getClient().getStub().setIPVM( vmIP ) ;
429 } catch( RemoteException e ) {
430 System.err.println( "Unable to set the new VM IP on the replacing client!" ) ;
431 e.printStackTrace() ;
434 if( ok_new && ok_old )
441 // Replacing in RunningApplication
442 applications.get( 0 ).replaceComputingClient( cc, ccl ) ;
444 for( int l = 0 ; l < applications.get(0).getComputingClients().size() ; l++ )
446 applications.get(0).getComputingClients().get( l ).setSaveRequest( false ) ;
450 System.out.println( "Successful redeployment of the VM." ) ;
452 System.err.println( "Unable to deploy the save on the new computing client!" ) ;
456 // System.err.println( "Problem while launching the VM on "
457 // + clients.get(i).getName() + "!" ) ;
462 for( int k = 0 ; k < computingClients.size() ; k++ )
465 computingClients.get( k ).getClient().getStub().
466 replaceSaveNeighbor( snDead, new SaveNeighbor( clients.get( i ).getStub() ) ) ;
467 } catch( RemoteException e ) {
468 System.err.println( "Unable to inform " + computingClients.get( k ).getClient().getName() +
469 " of the replacement of a save neighbor!" ) ;
470 e.printStackTrace() ;
474 System.out.println( "Dead client successfully replaced." ) ;
478 System.err.println( "Dead client not replaced!!" ) ;
485 synchronized( counter ) {
487 counter.notifyAll() ;}
488 } catch( Exception e ) {}
493 /** Monitoring thread **/
494 private class ConnectedMonitor extends Thread
503 protected void stopMonitor() { run = false ; }
513 Iterator<ConnectedClient> it = clients.iterator() ;
514 int nb_disconnections = 0 ;
515 int nb_disconnections_computing = 0 ;
517 while( it.hasNext() )
519 ConnectedClient cl = it.next() ;
522 if( cl.getTimeout() > max_timeout )
524 System.out.println( "Disconnection of " + cl.getName() ) ;
525 if( cl.getStatus().equalsIgnoreCase( "running" ) || cl.getStatus().equalsIgnoreCase( "saving" ) )
527 System.out.println( "A VM was running on it!!" ) ;
528 System.out.println( "I will redeploy a save and restart all VM ..." ) ;
530 // for( int i = 0 ; i < computingClients.size() ; i++ )
532 // if( computingClients.get( i ).getClient().getIP().equals( cl.getIP() ) )
534 // computingClients.remove( i ) ;
538 synchronized( counter ){
542 new Server.FaultManager( cl ).start() ;
543 nb_disconnections_computing++ ;
545 System.out.println( "There was no VM running on it." ) ;
546 System.out.println( "Maybe it will come back later :)" ) ;
549 synchronized( clients )
553 nb_disconnections++ ;
560 synchronized( clients )
562 if( clients.size() == 0 )
564 System.out.println( "There is no client connected." ) ;
565 } else if( clients.size() == 1 ) {
566 System.out.println( "There is one client connected." ) ;
568 System.out.println( "There are " + clients.size() + " clients connected." ) ;
574 if( nb_disconnections_computing > 0 )
576 System.out.println( "Sending emergency stop signal to all computing nodes ... " ) ;
578 for( int i = 0 ; i < clients.size() ; i++ )
580 if( clients.get( i ).getStatus().equalsIgnoreCase( "running" )
581 || clients.get( i ).getStatus().equalsIgnoreCase( "saving" ) )
584 clients.get( i ).getStub().emergencyStop() ;
585 } catch( RemoteException e ) {
586 System.err.println( "Unable to invoke emergency stop signal on " + clients.get( i ).getName() ) ;
587 e.printStackTrace() ;
592 System.out.println( "I will redeploy save and restart VMs ... " ) ;
594 synchronized( counter )
596 if( counter.getNb() > 0 )
598 System.out.println( "... waiting all redeployments done ..." ) ;
601 while( counter.getNb() != 0 )
605 } catch( InterruptedException e ) {
606 e.printStackTrace() ;
611 for( int i = 0 ; i < applications.get(0).getComputingClients().size() ; i++ )
613 final ServicesClient sc = applications.get(0).getComputingClients().get( i ).getClient().getStub() ;
615 applications.get( 0 ).getComputingClients().get( i ).setRestartOk( false ) ;
617 new Thread( new Runnable() {
623 sc.restartVMAfterCrash() ;
624 } catch( RemoteException e ) {
625 e.printStackTrace() ;
634 Thread.sleep( 2000 ) ;
635 } catch( InterruptedException e ) {
636 e.printStackTrace() ;
643 public Integer saveOk( String _ip, String _saveName )
646 for( i = 0 ; i < computingClients.size() ; i ++ )
648 if( computingClients.get( i ).getClient().getIP().equalsIgnoreCase( _ip ) )
650 computingClients.get( i ).setLastSave( _saveName ) ;
651 computingClients.get( i ).setSaveStatus( true ) ;
657 boolean all_ok = true ;
660 while( all_ok && i < computingClients.size() )
662 all_ok = all_ok & computingClients.get( i ).getSaveStatus() ;
668 for( i = 0 ; i < computingClients.size() ; i++ )
671 computingClients.get( i ).getClient().getStub().saveOk() ;
672 } catch (RemoteException e) {
675 computingClients.get( i ).setSaveStatus( false ) ;
678 applications.get( 0 ).setLastSaveDate( System.currentTimeMillis() ) ;
685 public Integer changeSaveName( String _ip, String _saveName )
687 if( _ip != null && _ip.length() > 0 && _saveName != null && _saveName.length() > 0 )
689 for( int i = 0 ; i < computingClients.size() ; i ++ )
691 if( computingClients.get( i ).getClient().getIP().equalsIgnoreCase( _ip ) )
693 computingClients.get( i ).setLastSave( _saveName ) ;
694 System.out.println( "Save name successfully changed for " + _ip ) ;
704 public ArrayList<ServicesClient> startApplication( int _nb )
706 int nb = clients.size() - computingClients.size() ;
710 final ArrayList<ServicesClient> ac = new ArrayList<ServicesClient>() ;
711 final ArrayList<ComputingClient> tmp = new ArrayList<ComputingClient>() ;
713 RunningApplication app = new RunningApplication( "Test" ) ;
718 while( i < clients.size() && ac.size() < _nb )
721 if( clients.get( i ).getStatus().equalsIgnoreCase( "connected" ) )
723 synchronized( startingClients )
725 while( ac.size() + startingClients.getNb() >= _nb )
727 if( ac.size() == _nb ) break ;
730 startingClients.wait() ;
731 } catch (InterruptedException e) {
736 if( ac.size() < _nb )
738 startingClients.inc() ;
745 synchronized( limitThread )
747 while( limitThread.getNb() >= maxThread )
751 } catch (InterruptedException e) {
760 new Thread( new Runnable(){
767 res = clients.get( ind ).getStub().startVM( 0 ) ;
768 } catch( RemoteException e ) {
774 ac.add( clients.get( ind ).getStub() ) ;
775 clients.get( ind ).setStatus( "running" ) ;
776 ComputingClient cl = new ComputingClient( clients.get( ind ) ) ;
777 clients.get( ind ).setComputingClient( cl ) ;
778 computingClients.add( cl ) ;
781 System.err.println( "Problem while launching the VM on "
782 + clients.get(ind).getName() + "!" ) ;
785 synchronized( limitThread )
788 limitThread.notifyAll() ;
791 synchronized( startingClients )
793 startingClients.dec() ;
794 startingClients.notifyAll() ;
804 if( ac.size() == _nb )
806 app.setComputingClients( tmp ) ;
807 app.setRunning( true ) ;
808 app.setStartTime( System.currentTimeMillis() ) ;
811 /* Choosing save neighbors */
812 for( i = 0 ; i < tmp.size() ; i++ )
814 if( i == tmp.size() - 1 )
816 index = computingClients.indexOf( tmp.get( i ) ) ;
817 index2 = computingClients.indexOf( tmp.get( 0 ) ) ;
819 if( index == -1 || index2 == -1 )
821 System.err.println( "Problem in ComputingClients list!" ) ;
824 computingClients.get( index ).setSaveNeighbor( new SaveNeighbor( computingClients.get( index2 ).getClient().getStub() )) ;
825 } catch( RemoteException e ) {
826 System.err.println( "Unable to create the save neighbor!" ) ;
827 e.printStackTrace() ;
831 index = computingClients.indexOf( tmp.get( i ) ) ;
832 index2 = computingClients.indexOf( tmp.get( i + 1 ) ) ;
834 if( index == -1 || index2 == -1 )
836 System.err.println( "Problem in ComputingClients list!" ) ;
839 computingClients.get( index ).setSaveNeighbor( new SaveNeighbor( computingClients.get( index2 ).getClient().getStub() ) ) ;
840 } catch( RemoteException e ) {
841 System.err.println( "Unable to create the save neighbor!" ) ;
842 e.printStackTrace() ;
849 applications.add( app ) ;
859 public void requestSave( String _ip )
863 } catch( InterruptedException e ) {
864 System.err.println( "Unable to obtain the semaphore for semaSave!" ) ;
865 e.printStackTrace() ;
868 final String ip = _ip ;
870 new Thread( new Runnable() {
875 treatRequestSave( ip ) ;
881 public void treatRequestSave( String _ip )
883 if( applications.size() > 0 && _ip != null && _ip.length() > 0 )
885 if( (System.currentTimeMillis() - applications.get( 0 ).getLastSaveDate()) > save_interleave )
887 // Mark it as a requester
888 for( int i = 0 ; i < applications.get( 0 ).getComputingClients().size() ; i++ )
890 if( applications.get( 0 ).getComputingClients().get( i ).getClient().getIP().equalsIgnoreCase( _ip ) )
892 applications.get( 0 ).getComputingClients().get( i ).setSaveRequest( true ) ;
902 for( int i = 0 ; i < applications.get( 0 ).getComputingClients().size() ; i++ )
906 ok = applications.get( 0 ).getComputingClients().get( i ).getSaveRequest() ;
908 ok = ok & applications.get( 0 ).getComputingClients().get( i ).getSaveRequest() ;
920 // Thread.sleep( 5000 ) ;
921 // } catch( InterruptedException e1 ) {
922 // e1.printStackTrace() ;
925 for( int i = 0 ; i < applications.get( 0 ).getComputingClients().size() ; i++ )
928 applications.get( 0 ).getComputingClients().get( i ).getClient().getStub().responseSave( true ) ;
929 applications.get( 0 ).getComputingClients().get( i ).setSaveRequest( false ) ;
930 } catch( RemoteException e ) {
931 System.err.println( "Unable to send the save request response to " +
932 applications.get( 0 ).getComputingClients().get( i ).getClient().getName() + "!" ) ;
933 e.printStackTrace() ;
937 applications.get( 0 ).setLastSaveDate( System.currentTimeMillis() ) ;
943 for( int i = 0 ; i < applications.get( 0 ).getComputingClients().size() ; i++ )
945 if( applications.get( 0 ).getComputingClients().get( i ).getClient().getIP().equalsIgnoreCase( _ip ) )
948 applications.get( 0 ).getComputingClients().get( i ).getClient().getStub().responseSave( false ) ;
949 } catch( RemoteException e ) {
950 System.err.println( "Unable to send the save request response to " +
951 applications.get( 0 ).getComputingClients().get( i ).getClient().getName() + "!" ) ;
952 e.printStackTrace() ;
960 System.err.println( "!! Serious problem in treatRequestSave method!!" ) ;
966 public void restartOk( String _ip )
968 if( applications.size() > 0 && _ip != null && _ip.length() > 0 )
970 System.out.println( "Client " + _ip + " has finished to restart ("+applications.get(0).getComputingClients().size()+") ... " ) ;
971 if( (System.currentTimeMillis() - applications.get( 0 ).getLastSaveDate()) > save_interleave )
973 // Has it already finished?
974 for( int i = 0 ; i < applications.get( 0 ).getComputingClients().size() ; i++ )
976 if( applications.get( 0 ).getComputingClients().get( i ).getClient().getIP().equalsIgnoreCase( _ip ) )
978 applications.get( 0 ).getComputingClients().get( i ).setRestartOk( true ) ;
986 for( int i = 0 ; i < applications.get( 0 ).getComputingClients().size() ; i++ )
990 ok = applications.get( 0 ).getComputingClients().get( i ).getRestartOk() ;
992 ok = ok & applications.get( 0 ).getComputingClients().get( i ).getRestartOk() ;
1003 applications.get( 0 ).setLastSaveDate( System.currentTimeMillis() ) ;
1005 for( int i = 0 ; i < applications.get( 0 ).getComputingClients().size() ; i++ )
1007 applications.get( 0 ).getComputingClients().get( i ).setRestartOk( false ) ;
1017 public void endApplication()
1019 Iterator<ComputingClient> it = computingClients.iterator() ;
1021 while( it.hasNext() )
1023 ComputingClient cl = it.next() ;
1026 cl.getClient().getStub().emergencyStop() ;
1027 } catch (RemoteException e) {
1028 e.printStackTrace();
1031 cl.getClient().setStatus( "connected" ) ;
1032 cl.getClient().setComputingClient( null ) ;
1037 applications.get( 0 ).setEndTime( System.currentTimeMillis() ) ;
1038 applications.get( 0 ).setRunning( false ) ;
1039 applications.get( 0 ).clear() ;
1046 public String getAssociatedIP( String _ip )
1050 for( int i = 0 ; i < vmIPs.size() ; i++ )
1052 if( vmIPs.get( i ).getHostIP().equalsIgnoreCase( _ip ) )
1054 ret = vmIPs.get( i ).getVmIP() ;
1063 public Integer deployVM( final String _name, final String _archive, final String _directory )
1065 int nb = 0, pb = 0 ;
1067 if( _name != null && _name.length() > 0 && _archive != null && _name.length() > 0
1068 && _directory != null && _directory.length() > 0 )
1070 System.out.println( "Deploying the VM " + _name + " (" + _archive + ") ... " ) ;
1072 File file = new File( working_directory + "/" + _archive ) ;
1073 if( ! file.exists() )
1075 System.err.println( "There is no archive named " + _archive + " in my working directory!" ) ;
1078 } else if( file.isDirectory() ) {
1079 System.err.println( _archive + " is a directory!" ) ;
1086 // TODO do a better deployment !!
1088 // boolean error, ok, server ;
1089 // ArrayList<ConnectedClient> deployed = new ArrayList<ConnectedClient>() ;
1091 boolean server = true ;
1094 for( int i = 0 ; i < clients.size() ; i++ )
1100 if( clients.get( i ).getStatus().equalsIgnoreCase( "connected" ) )
1102 synchronized( limitThread )
1104 while( limitThread.getNb() >= maxThread )
1107 limitThread.wait() ;
1108 } catch (InterruptedException e) {
1109 e.printStackTrace();
1117 new Thread( new Runnable() {
1122 boolean error = true ;
1125 ret = clients.get( ind ).getStub().deployVM( _name, _archive, _directory ) ;
1126 } catch( RemoteException e ) {
1127 System.err.println( "Unable to deploy the VM on " + clients.get( ind ).getName() + "!" ) ;
1128 e.printStackTrace() ;
1131 // The client does not have the archive, we have to send it.
1134 // Attention au multi-envois !!!
1135 System.out.print( "Sending VM archive to " + clients.get( ind ).getName() + " ... " ) ;
1142 wd = clients.get( ind ).getStub().getWorkingDirectory() ;
1143 snIP = clients.get( ind ).getStub().getIPHost() ;
1144 } catch (RemoteException e2) {
1145 System.err.println( "Unable to retrieve information on " + clients.get( ind ).getName() + "!" ) ;
1146 e2.printStackTrace() ;
1150 String[] command = new String[]{ "/usr/bin/scp", working_directory + "/" + _archive,
1156 Process proc = Runtime.getRuntime().exec( command ) ;
1159 if( proc.exitValue() == 0 )
1161 System.out.println( "Initial VM archive successfully sent." ) ;
1163 System.err.println( "Initial VM archive not sent!" ) ;
1164 System.err.println( "Error: " + proc.exitValue() ) ;
1165 BufferedReader b = new BufferedReader( new InputStreamReader( proc.getErrorStream() ) ) ;
1169 while( (l = b.readLine()) != null )
1171 System.err.println( l ) ;
1173 } catch( IOException e ) {
1174 e.printStackTrace() ;
1179 } catch( IOException e ) {
1180 System.err.println( "Error during initial VM archive send command: " ) ;
1181 e.printStackTrace() ;
1183 } catch( InterruptedException e ) {
1184 e.printStackTrace() ;
1195 ret = clients.get( ind ).getStub().deployVM( _name, _archive, _directory ) ;
1196 } catch( RemoteException e ) {
1197 System.err.println( "Unable to deploy the VM on " + clients.get( ind ).getName() + "!" ) ;
1198 e.printStackTrace() ;
1205 System.out.println( "Initial VM archive successfully deployed on " + clients.get( ind ).getName() + "." ) ;
1207 synchronized( deployingClients )
1209 deployingClients.inc() ;
1213 synchronized( limitThread )
1216 limitThread.notifyAll() ;
1224 synchronized( limitThread )
1226 while( limitThread.getNb() > 0 )
1229 limitThread.wait() ;
1230 } catch( InterruptedException e ) {
1231 e.printStackTrace() ;
1236 if( nb - deployingClients.getNb() > 0 )
1239 System.err.println( "** " + pb + " machine is not deployed!" ) ;
1241 System.err.println( "** " + pb + " machines are not deployed!" ) ;
1248 public String getWorkingDirectory()
1250 return working_directory ;
1254 private class OperatingClients
1258 OperatingClients() { nb = 0 ; }
1260 protected void inc() { nb++ ; }
1262 protected void dec() { nb-- ; }
1264 protected int getNb() { return nb ; }
1268 private class LimitThread
1272 LimitThread() { nb = 0 ; }
1274 protected void inc() { nb++ ; }
1276 protected void dec() { nb-- ; }
1278 protected int getNb() { return nb ; }
1283 /** La programmation est un art, respectons ceux qui la pratiquent !! **/