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 ;
89 private boolean running ;
92 protected Server() throws RemoteException
100 public Integer register( ServicesClient _stub )
104 synchronized( clients )
108 ip = _stub.getIPHost() ;
109 } catch (RemoteException e) {
110 e.printStackTrace() ;
114 boolean exists = false ;
117 for( i = 0 ; i < clients.size() ; i++ )
119 if( ip.equals( clients.get( i ).getIP() ) )
122 System.out.println( "Client already connected!" ) ;
129 System.out.println( "The client stub will be replaced." ) ;
130 clients.get( i ).setStub( _stub ) ;
131 System.out.println( "(reconnection of " + clients.get( i ).getName() + ")" ) ;
134 System.out.println( "New connection!" ) ;
135 clients.add( new ConnectedClient( _stub ) ) ;
136 System.out.println( "(connection of " + clients.get( clients.size() - 1 ).getName() + ")" ) ;
139 if( clients.size() == 0 )
141 System.out.println( "There is no client connected." ) ;
142 } else if( clients.size() == 1 ) {
143 System.out.println( "There is one client connected." ) ;
145 System.out.println( "There are " + clients.size() + " clients connected." ) ;
157 private void generateVmIP( String _ip )
159 if( _ip != null && ! _ip.equals( "" ) )
161 for( int i = 0 ; i < vmIPs.size() ; i++ )
163 if( vmIPs.get( i ).getHostIP().equalsIgnoreCase( "" ) )
165 vmIPs.get( i ).setHostIP( _ip ) ;
175 public void ping( String _ip )
179 for( int i = 0 ; i < clients.size() ; i++ )
181 if( _ip.equals( clients.get( i ).getIP() ) )
183 clients.get( i ).resetTimeout() ;
192 public void changeStatus( String _ip, String _status )
194 if( _ip != null && _status != null )
196 for( int i = 0 ; i < clients.size() ; i++ )
198 if( _ip.equals( clients.get( i ).getIP() ) )
200 clients.get( i ).setStatus( _status ) ;
201 System.out.println( "Client " + clients.get( i ).getName() + " changed its status to: " + _status ) ;
210 public void init( int _port )
215 clients = new ArrayList<ConnectedClient>() ;
216 computingClients = new ArrayList<ComputingClient>() ;
217 applications = new ArrayList<RunningApplication>() ;
220 startingClients = new OperatingClients() ;
221 deployingClients = new OperatingClients() ;
222 limitThread = new LimitThread() ;
228 working_directory = "/localhome/vmware" ;
230 save_interleave = 30 * 60 * 1000 ;
232 semaSave = new Semaphore( 1 ) ;
236 vmIPs = new ArrayList<IPAssociation>() ;
237 // TODO initialisation of VM IPs
238 for( int i = 2 ; i < 101 ; i++ )
240 vmIPs.add( new IPAssociation() ) ;
241 vmIPs.get( vmIPs.size() - 1 ).setVmIP( "10.11.10." + i ) ;
244 clients = new ArrayList<ConnectedClient>() ;
246 counter = new DiscCount() ;
248 monitor = new ConnectedMonitor() ;
252 // Check if there are running applications ... and restart them :)
258 if( monitor != null ) { monitor.stopMonitor() ; }
260 for( int i = 0 ; i < clients.size() ; i++ )
263 clients.get( i ).getStub().emergencyStop() ;
264 clients.get( i ).getStub().stop() ;
265 } catch (RemoteException e) {
276 private void exportObject()
278 ServicesServer ref = null ;
279 Registry reg = null ;
285 reg = LocateRegistry.getRegistry( port ) ;
287 String tab[] = reg.list() ;
289 System.out.println( "There is an existing RMI Registry on port " +
290 port + " with " + tab.length + " entries!" ) ;
291 for( int i = 0 ; i < tab.length ; i++ )
294 if( UnicastRemoteObject.unexportObject( Naming.lookup(tab[i]), true ) )
296 System.out.println( "Register successfuly deleted!" ) ;
298 System.err.println( "Register undeleted !!!" ) ;
300 } catch( Exception e ) {
301 e.printStackTrace() ;
305 } catch( RemoteException e ) {
309 if ( System.getSecurityManager() == null )
311 System.setSecurityManager( new SecurityManager() ) ;
314 LocateRegistry.createRegistry( port ) ;
315 LocateRegistry.getRegistry( port ).rebind( "Server", this ) ;
316 ref = (ServicesServer) Naming.lookup( "rmi://"
317 + LocalHost.Instance().getIP() + ":" + port
319 } catch ( Exception e ) {
320 System.err.println( "Error in Server.exportObject() when creating local services:" + e ) ;
321 System.err.println( "Exit from Server.exportObject" ) ;
325 LocalHost.Instance().setServerStub( ref ) ;
327 System.out.println( "Server launched on IP " + LocalHost.Instance().getIP() +
328 " on port " + port + "." ) ;
331 /** Fault manager thread **/
332 private class FaultManager extends Thread
336 FaultManager( ConnectedClient _cl )
344 if( cl != null && cl.getStatus().equalsIgnoreCase( "running" ) ||
345 cl.getStatus().equalsIgnoreCase( "saving" ) )
347 ComputingClient cc = cl.getComputingClient() ;
348 // ServicesClient dead = cc.getClient().getStub() ;
349 String ipDead = cc.getClient().getIP() ;
350 SaveNeighbor snDead = null ;
351 for( int i = 0 ; i < computingClients.size() ; i++ )
353 if( computingClients.get( i ).getSaveNeighbor().getIPHost().equalsIgnoreCase( ipDead ) )
355 snDead = computingClients.get( i ).getSaveNeighbor() ;
362 for( int i = 0 ; i < clients.size() ; i++ )
364 if( clients.get( i ).getStatus().equalsIgnoreCase( "connected" ) )
368 // res = clients.get( i ).getStub().startVM() ;
369 // } catch( RemoteException e ) {
370 // e.printStackTrace();
375 //clients.get(i).setStatus( "running" ) ;
377 int pos = computingClients.indexOf( cc ) ;
380 System.err.println( "Dead client not found in the computing clients list!" ) ;
382 System.out.println( "Trying to replace " + cc.getClient().getName() + " with " +
383 clients.get(i).getName() + " ... " ) ;
385 String save_name = computingClients.get( pos ).getLastSave() ;
387 ComputingClient ccl = new ComputingClient( clients.get(i) ) ;
388 clients.get( i ).setComputingClient( ccl ) ;
389 SaveNeighbor sn = computingClients.get( pos ).getSaveNeighbor() ;
390 ccl.setSaveNeighbor( sn ) ;
391 computingClients.set( pos, ccl ) ;
396 res = computingClients.get( pos ).getClient().getStub().
397 retrieveSave( save_name ) ;
398 } catch( RemoteException e ) {
399 System.err.println( "Unable to indicate to client to retrieve last save!" ) ;
400 e.printStackTrace() ;
407 boolean ok_new = false, ok_old = false ;
409 // replace dead client in vmIPs
410 for( int j = 0 ; j < vmIPs.size() ; j++ )
412 if( vmIPs.get( j ).getHostIP().equalsIgnoreCase( computingClients.get( pos ).getClient().getIP() ) )
414 vmIPs.get( j ).setHostIP( "" ) ;
417 if( vmIPs.get( j ).getHostIP().equalsIgnoreCase( ipDead ) )
419 String vmIP = vmIPs.get( j ).getVmIP() ;
420 vmIPs.get( j ).setHostIP( computingClients.get( pos ).getClient().getIP() ) ;
424 computingClients.get( pos ).getClient().getStub().setIPVM( vmIP ) ;
425 } catch( RemoteException e ) {
426 System.err.println( "Unable to set the new VM IP on the replacing client!" ) ;
427 e.printStackTrace() ;
430 if( ok_new && ok_old )
437 // Replacing in RunningApplication
438 applications.get( ind ).replaceComputingClient( cc, ccl ) ;
440 for( int l = 0 ; l < applications.get( ind ).getComputingClients().size() ; l++ )
442 applications.get( ind ).getComputingClients().get( l ).setSaveRequest( false ) ;
446 System.out.println( "Successful redeployment of the VM." ) ;
448 System.err.println( "Unable to deploy the save on the new computing client!" ) ;
454 for( int k = 0 ; k < computingClients.size() ; k++ )
457 computingClients.get( k ).getClient().getStub().
458 replaceSaveNeighbor( snDead, new SaveNeighbor( clients.get( i ).getStub() ) ) ;
459 } catch( RemoteException e ) {
460 System.err.println( "Unable to inform " + computingClients.get( k ).getClient().getName() +
461 " of the replacement of a save neighbor!" ) ;
462 e.printStackTrace() ;
466 System.out.println( "Dead client successfully replaced." ) ;
470 System.err.println( "Dead client not replaced!!" ) ;
477 synchronized( counter ) {
479 counter.notifyAll() ;}
480 } catch( Exception e ) {}
485 /** Monitoring thread **/
486 private class ConnectedMonitor extends Thread
495 protected void stopMonitor() { run = false ; }
505 Iterator<ConnectedClient> it = clients.iterator() ;
506 int nb_disconnections = 0 ;
507 int nb_disconnections_computing = 0 ;
509 while( it.hasNext() )
511 ConnectedClient cl = it.next() ;
514 if( cl.getTimeout() > max_timeout )
516 System.out.println( "Disconnection of " + cl.getName() ) ;
517 if( cl.getStatus().equalsIgnoreCase( "running" ) || cl.getStatus().equalsIgnoreCase( "saving" ) )
519 System.out.println( "A VM was running on it!!" ) ;
520 System.out.println( "I will redeploy a save and restart all VM ..." ) ;
522 // for( int i = 0 ; i < computingClients.size() ; i++ )
524 // if( computingClients.get( i ).getClient().getIP().equals( cl.getIP() ) )
526 // computingClients.remove( i ) ;
530 synchronized( counter ){
534 new Server.FaultManager( cl ).start() ;
535 nb_disconnections_computing++ ;
537 System.out.println( "There was no VM running on it." ) ;
538 System.out.println( "Maybe it will come back later :)" ) ;
541 synchronized( clients )
545 nb_disconnections++ ;
552 synchronized( clients )
554 if( clients.size() == 0 )
556 System.out.println( "There is no client connected." ) ;
557 } else if( clients.size() == 1 ) {
558 System.out.println( "There is one client connected." ) ;
560 System.out.println( "There are " + clients.size() + " clients connected." ) ;
566 if( nb_disconnections_computing > 0 )
568 System.out.println( "Sending emergency stop signal to all computing nodes ... " ) ;
570 for( int i = 0 ; i < clients.size() ; i++ )
572 if( clients.get( i ).getStatus().equalsIgnoreCase( "running" )
573 || clients.get( i ).getStatus().equalsIgnoreCase( "saving" ) )
576 clients.get( i ).getStub().emergencyStop() ;
577 } catch( RemoteException e ) {
578 System.err.println( "Unable to invoke emergency stop signal on " + clients.get( i ).getName() ) ;
579 e.printStackTrace() ;
584 System.out.println( "I will redeploy save and restart VMs ... " ) ;
586 synchronized( counter )
588 if( counter.getNb() > 0 )
590 System.out.println( "... waiting all redeployments done ..." ) ;
593 while( counter.getNb() != 0 )
597 } catch( InterruptedException e ) {
598 e.printStackTrace() ;
603 for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
605 final ServicesClient sc = applications.get( ind ).getComputingClients().get( i ).getClient().getStub() ;
607 applications.get( ind ).getComputingClients().get( i ).setRestartOk( false ) ;
609 new Thread( new Runnable() {
615 sc.restartVMAfterCrash() ;
616 } catch( RemoteException e ) {
617 e.printStackTrace() ;
626 Thread.sleep( 2000 ) ;
627 } catch( InterruptedException e ) {
628 e.printStackTrace() ;
635 public Integer saveOk( String _ip, String _saveName )
638 for( i = 0 ; i < computingClients.size() ; i ++ )
640 if( computingClients.get( i ).getClient().getIP().equalsIgnoreCase( _ip ) )
642 computingClients.get( i ).setLastSave( _saveName ) ;
643 computingClients.get( i ).setSaveStatus( true ) ;
649 boolean all_ok = true ;
652 while( all_ok && i < computingClients.size() )
654 all_ok = all_ok & computingClients.get( i ).getSaveStatus() ;
660 for( i = 0 ; i < computingClients.size() ; i++ )
663 computingClients.get( i ).getClient().getStub().saveOk() ;
664 } catch (RemoteException e) {
667 computingClients.get( i ).setSaveStatus( false ) ;
670 applications.get( ind ).setLastSaveDate( System.currentTimeMillis() ) ;
677 public Integer changeSaveName( String _ip, String _saveName )
679 if( _ip != null && _ip.length() > 0 && _saveName != null && _saveName.length() > 0 )
681 for( int i = 0 ; i < computingClients.size() ; i ++ )
683 if( computingClients.get( i ).getClient().getIP().equalsIgnoreCase( _ip ) )
685 computingClients.get( i ).setLastSave( _saveName ) ;
686 System.out.println( "Save name successfully changed on " + computingClients.get( i ).getClient().getName() ) ;
691 System.err.println( "Unable to found computing client with IP " + _ip + "!" ) ;
695 System.err.println( "Unable to change save name. IP or save name empty ! (IP: " + _ip + " ; save name: " + _saveName +")" ) ;
701 public ArrayList<ServicesClient> startApplication( int _nb )
703 int nb = clients.size() - computingClients.size() ;
705 if( nb > _nb && ! running )
709 final ArrayList<ServicesClient> ac = new ArrayList<ServicesClient>() ;
710 final ArrayList<ComputingClient> tmp = new ArrayList<ComputingClient>() ;
712 RunningApplication app = new RunningApplication( "Test" ) ;
717 while( i < clients.size() && ac.size() < _nb )
720 if( clients.get( i ).getStatus().equalsIgnoreCase( "connected" ) )
722 synchronized( startingClients )
724 while( ac.size() + startingClients.getNb() >= _nb )
726 if( ac.size() == _nb ) break ;
729 startingClients.wait() ;
730 } catch (InterruptedException e) {
735 if( ac.size() < _nb )
737 startingClients.inc() ;
744 synchronized( limitThread )
746 while( limitThread.getNb() >= maxThread )
750 } catch (InterruptedException e) {
758 final int indice = i ;
759 new Thread( new Runnable(){
766 res = clients.get( indice ).getStub().startVM( 0 ) ;
767 } catch( RemoteException e ) {
773 ac.add( clients.get( indice ).getStub() ) ;
774 clients.get( indice ).setStatus( "running" ) ;
775 ComputingClient cl = new ComputingClient( clients.get( indice ) ) ;
776 clients.get( indice ).setComputingClient( cl ) ;
777 computingClients.add( cl ) ;
780 System.err.println( "Problem while launching the VM on "
781 + clients.get( indice ).getName() + "!" ) ;
784 synchronized( limitThread )
787 limitThread.notifyAll() ;
790 synchronized( startingClients )
792 startingClients.dec() ;
793 startingClients.notifyAll() ;
803 if( ac.size() == _nb )
805 app.setComputingClients( tmp ) ;
806 app.setRunning( true ) ;
807 // app.setStartTime( System.currentTimeMillis() ) ;
810 /* Choosing save neighbors */
811 for( i = 0 ; i < tmp.size() ; i++ )
813 if( i == tmp.size() - 1 )
815 index = computingClients.indexOf( tmp.get( i ) ) ;
816 index2 = computingClients.indexOf( tmp.get( 0 ) ) ;
818 if( index == -1 || index2 == -1 )
820 System.err.println( "Problem in ComputingClients list!" ) ;
823 computingClients.get( index ).setSaveNeighbor( new SaveNeighbor( computingClients.get( index2 ).getClient().getStub() )) ;
824 } catch( RemoteException e ) {
825 System.err.println( "Unable to create the save neighbor!" ) ;
826 e.printStackTrace() ;
830 index = computingClients.indexOf( tmp.get( i ) ) ;
831 index2 = computingClients.indexOf( tmp.get( i + 1 ) ) ;
833 if( index == -1 || index2 == -1 )
835 System.err.println( "Problem in ComputingClients list!" ) ;
838 computingClients.get( index ).setSaveNeighbor( new SaveNeighbor( computingClients.get( index2 ).getClient().getStub() ) ) ;
839 } catch( RemoteException e ) {
840 System.err.println( "Unable to create the save neighbor!" ) ;
841 e.printStackTrace() ;
848 applications.add( app ) ;
850 ind = applications.indexOf( app ) ;
860 public void requestSave( String _ip )
864 } catch( InterruptedException e ) {
865 System.err.println( "Unable to obtain the semaphore for semaSave!" ) ;
866 e.printStackTrace() ;
869 final String ip = _ip ;
871 new Thread( new Runnable() {
876 treatRequestSave( ip ) ;
882 public void treatRequestSave( String _ip )
884 if( applications.size() > 0 && _ip != null && _ip.length() > 0 )
886 if( (System.currentTimeMillis() - applications.get( ind ).getLastSaveDate()) > save_interleave )
888 // Mark it as a requester
889 for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
891 if( applications.get( ind ).getComputingClients().get( i ).getClient().getIP().equalsIgnoreCase( _ip ) )
893 applications.get( ind ).getComputingClients().get( i ).setSaveRequest( true ) ;
903 for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
907 ok = applications.get( ind ).getComputingClients().get( i ).getSaveRequest() ;
909 ok = ok & applications.get( ind ).getComputingClients().get( i ).getSaveRequest() ;
921 // Thread.sleep( 5000 ) ;
922 // } catch( InterruptedException e1 ) {
923 // e1.printStackTrace() ;
926 for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
929 applications.get( ind ).getComputingClients().get( i ).getClient().getStub().responseSave( true ) ;
930 applications.get( ind ).getComputingClients().get( i ).setSaveRequest( false ) ;
931 } catch( RemoteException e ) {
932 System.err.println( "Unable to send the save request response to " +
933 applications.get( ind ).getComputingClients().get( i ).getClient().getName() + "!" ) ;
934 e.printStackTrace() ;
938 applications.get( ind ).setLastSaveDate( System.currentTimeMillis() ) ;
944 for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
946 if( applications.get( ind ).getComputingClients().get( i ).getClient().getIP().equalsIgnoreCase( _ip ) )
949 applications.get( ind ).getComputingClients().get( i ).getClient().getStub().responseSave( false ) ;
950 } catch( RemoteException e ) {
951 System.err.println( "Unable to send the save request response to " +
952 applications.get( ind ).getComputingClients().get( i ).getClient().getName() + "!" ) ;
953 e.printStackTrace() ;
961 System.err.println( "!! Serious problem in treatRequestSave method!!" ) ;
967 public void restartOk( String _ip )
969 if( applications.size() > 0 && _ip != null && _ip.length() > 0 )
971 System.out.println( "Client " + _ip + " has finished to restart ("+applications.get( ind ).getComputingClients().size()+") ... " ) ;
972 // if( (System.currentTimeMillis() - applications.get( ind ).getLastSaveDate()) > save_interleave )
974 // Has it already finished?
975 for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
977 if( applications.get( ind ).getComputingClients().get( i ).getClient().getIP().equalsIgnoreCase( _ip ) )
979 applications.get( ind ).getComputingClients().get( i ).setRestartOk( true ) ;
987 for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
991 ok = applications.get( ind ).getComputingClients().get( i ).getRestartOk() ;
993 ok = ok & applications.get( ind ).getComputingClients().get( i ).getRestartOk() ;
1004 applications.get( ind ).setLastSaveDate( System.currentTimeMillis() ) ;
1006 for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
1008 applications.get( ind ).getComputingClients().get( i ).setRestartOk( false ) ;
1018 public void goApplication()
1020 synchronized( applications ) {
1021 if( running && applications.get( ind ).getStartTime() != 0 )
1023 applications.get( ind ).setStartTime( System.currentTimeMillis() ) ;
1024 applications.get( ind ).setLastSaveDate( System.currentTimeMillis() ) ;
1030 public void endApplication()
1032 synchronized( applications )
1036 Iterator<ComputingClient> it = computingClients.iterator() ;
1038 while( it.hasNext() )
1040 ComputingClient cl = it.next() ;
1043 cl.getClient().getStub().emergencyStop() ;
1044 } catch (RemoteException e) {
1045 e.printStackTrace();
1048 cl.getClient().setStatus( "connected" ) ;
1049 cl.getClient().setComputingClient( null ) ;
1054 applications.get( ind ).setEndTime( System.currentTimeMillis() ) ;
1055 applications.get( ind ).setRunning( false ) ;
1056 applications.get( ind ).clear() ;
1057 // applications.remove( ind ) ;
1061 System.out.println( "Application " + applications.get( ind ).getName() + " ends in " +
1062 applications.get( ind ).getExecutionTime() + " seconds." ) ;
1069 public String getAssociatedIP( String _ip )
1073 for( int i = 0 ; i < vmIPs.size() ; i++ )
1075 if( vmIPs.get( i ).getHostIP().equalsIgnoreCase( _ip ) )
1077 ret = vmIPs.get( i ).getVmIP() ;
1086 public Integer deployVM( final String _name, final String _archive, final String _directory )
1088 int nb = 0, pb = 0 ;
1090 if( _name != null && _name.length() > 0 && _archive != null && _name.length() > 0
1091 && _directory != null && _directory.length() > 0 )
1093 System.out.println( "Deploying the VM " + _name + " (" + _archive + ") ... " ) ;
1095 File file = new File( working_directory + "/" + _archive ) ;
1096 if( ! file.exists() )
1098 System.err.println( "There is no archive named " + _archive + " in my working directory!" ) ;
1101 } else if( file.isDirectory() ) {
1102 System.err.println( _archive + " is a directory!" ) ;
1109 // TODO do a better deployment !!
1111 // boolean error, ok, server ;
1112 // ArrayList<ConnectedClient> deployed = new ArrayList<ConnectedClient>() ;
1114 // boolean server = true ;
1117 for( int i = 0 ; i < clients.size() ; i++ )
1123 if( clients.get( i ).getStatus().equalsIgnoreCase( "connected" ) )
1125 synchronized( limitThread )
1127 while( limitThread.getNb() >= maxThread )
1130 limitThread.wait() ;
1131 } catch (InterruptedException e) {
1132 e.printStackTrace();
1139 final int indice = i ;
1140 new Thread( new Runnable() {
1145 boolean error = true ;
1148 ret = clients.get( indice ).getStub().deployVM( _name, _archive, _directory ) ;
1149 } catch( RemoteException e ) {
1150 System.err.println( "Unable to deploy the VM on " + clients.get( indice ).getName() + "!" ) ;
1151 e.printStackTrace() ;
1154 // The client does not have the archive, we have to send it.
1157 // Attention au multi-envois !!!
1158 System.out.print( "Sending VM archive to " + clients.get( indice ).getName() + " ... " ) ;
1165 wd = clients.get( indice ).getStub().getWorkingDirectory() ;
1166 snIP = clients.get( indice ).getStub().getIPHost() ;
1167 } catch (RemoteException e2) {
1168 System.err.println( "Unable to retrieve information on " + clients.get( indice ).getName() + "!" ) ;
1169 e2.printStackTrace() ;
1173 String[] command = new String[]{ "/usr/bin/scp", working_directory + "/" + _archive,
1179 Process proc = Runtime.getRuntime().exec( command ) ;
1182 if( proc.exitValue() == 0 )
1184 System.out.println( "Initial VM archive successfully sent." ) ;
1186 System.err.println( "Initial VM archive not sent!" ) ;
1187 System.err.println( "Error: " + proc.exitValue() ) ;
1188 BufferedReader b = new BufferedReader( new InputStreamReader( proc.getErrorStream() ) ) ;
1192 while( (l = b.readLine()) != null )
1194 System.err.println( l ) ;
1196 } catch( IOException e ) {
1197 e.printStackTrace() ;
1202 } catch( IOException e ) {
1203 System.err.println( "Error during initial VM archive send command: " ) ;
1204 e.printStackTrace() ;
1206 } catch( InterruptedException e ) {
1207 e.printStackTrace() ;
1218 ret = clients.get( indice ).getStub().deployVM( _name, _archive, _directory ) ;
1219 } catch( RemoteException e ) {
1220 System.err.println( "Unable to deploy the VM on " + clients.get( indice ).getName() + "!" ) ;
1221 e.printStackTrace() ;
1228 System.out.println( "Initial VM archive successfully deployed on " + clients.get( indice ).getName() + "." ) ;
1230 synchronized( deployingClients )
1232 deployingClients.inc() ;
1236 synchronized( limitThread )
1239 limitThread.notifyAll() ;
1247 synchronized( limitThread )
1249 while( limitThread.getNb() > 0 )
1252 limitThread.wait() ;
1253 } catch( InterruptedException e ) {
1254 e.printStackTrace() ;
1259 if( nb - deployingClients.getNb() > 0 )
1262 System.err.println( "** " + pb + " machine is not deployed!" ) ;
1264 System.err.println( "** " + pb + " machines are not deployed!" ) ;
1271 public String getWorkingDirectory()
1273 return working_directory ;
1277 private class OperatingClients
1281 OperatingClients() { nb = 0 ; }
1283 protected void inc() { nb++ ; }
1285 protected void dec() { nb-- ; }
1287 protected int getNb() { return nb ; }
1291 private class LimitThread
1295 LimitThread() { nb = 0 ; }
1297 protected void inc() { nb++ ; }
1299 protected void dec() { nb-- ; }
1301 protected int getNb() { return nb ; }
1306 /** La programmation est un art, respectons ceux qui la pratiquent !! **/