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 " + _ip ) ;
696 public ArrayList<ServicesClient> startApplication( int _nb )
698 int nb = clients.size() - computingClients.size() ;
700 if( nb > _nb && ! running )
704 final ArrayList<ServicesClient> ac = new ArrayList<ServicesClient>() ;
705 final ArrayList<ComputingClient> tmp = new ArrayList<ComputingClient>() ;
707 RunningApplication app = new RunningApplication( "Test" ) ;
712 while( i < clients.size() && ac.size() < _nb )
715 if( clients.get( i ).getStatus().equalsIgnoreCase( "connected" ) )
717 synchronized( startingClients )
719 while( ac.size() + startingClients.getNb() >= _nb )
721 if( ac.size() == _nb ) break ;
724 startingClients.wait() ;
725 } catch (InterruptedException e) {
730 if( ac.size() < _nb )
732 startingClients.inc() ;
739 synchronized( limitThread )
741 while( limitThread.getNb() >= maxThread )
745 } catch (InterruptedException e) {
753 final int indice = i ;
754 new Thread( new Runnable(){
761 res = clients.get( indice ).getStub().startVM( 0 ) ;
762 } catch( RemoteException e ) {
768 ac.add( clients.get( indice ).getStub() ) ;
769 clients.get( indice ).setStatus( "running" ) ;
770 ComputingClient cl = new ComputingClient( clients.get( indice ) ) ;
771 clients.get( indice ).setComputingClient( cl ) ;
772 computingClients.add( cl ) ;
775 System.err.println( "Problem while launching the VM on "
776 + clients.get( indice ).getName() + "!" ) ;
779 synchronized( limitThread )
782 limitThread.notifyAll() ;
785 synchronized( startingClients )
787 startingClients.dec() ;
788 startingClients.notifyAll() ;
798 if( ac.size() == _nb )
800 app.setComputingClients( tmp ) ;
801 app.setRunning( true ) ;
802 // app.setStartTime( System.currentTimeMillis() ) ;
805 /* Choosing save neighbors */
806 for( i = 0 ; i < tmp.size() ; i++ )
808 if( i == tmp.size() - 1 )
810 index = computingClients.indexOf( tmp.get( i ) ) ;
811 index2 = computingClients.indexOf( tmp.get( 0 ) ) ;
813 if( index == -1 || index2 == -1 )
815 System.err.println( "Problem in ComputingClients list!" ) ;
818 computingClients.get( index ).setSaveNeighbor( new SaveNeighbor( computingClients.get( index2 ).getClient().getStub() )) ;
819 } catch( RemoteException e ) {
820 System.err.println( "Unable to create the save neighbor!" ) ;
821 e.printStackTrace() ;
825 index = computingClients.indexOf( tmp.get( i ) ) ;
826 index2 = computingClients.indexOf( tmp.get( i + 1 ) ) ;
828 if( index == -1 || index2 == -1 )
830 System.err.println( "Problem in ComputingClients list!" ) ;
833 computingClients.get( index ).setSaveNeighbor( new SaveNeighbor( computingClients.get( index2 ).getClient().getStub() ) ) ;
834 } catch( RemoteException e ) {
835 System.err.println( "Unable to create the save neighbor!" ) ;
836 e.printStackTrace() ;
843 applications.add( app ) ;
845 ind = applications.indexOf( app ) ;
855 public void requestSave( String _ip )
859 } catch( InterruptedException e ) {
860 System.err.println( "Unable to obtain the semaphore for semaSave!" ) ;
861 e.printStackTrace() ;
864 final String ip = _ip ;
866 new Thread( new Runnable() {
871 treatRequestSave( ip ) ;
877 public void treatRequestSave( String _ip )
879 if( applications.size() > 0 && _ip != null && _ip.length() > 0 )
881 if( (System.currentTimeMillis() - applications.get( ind ).getLastSaveDate()) > save_interleave )
883 // Mark it as a requester
884 for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
886 if( applications.get( ind ).getComputingClients().get( i ).getClient().getIP().equalsIgnoreCase( _ip ) )
888 applications.get( ind ).getComputingClients().get( i ).setSaveRequest( true ) ;
898 for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
902 ok = applications.get( ind ).getComputingClients().get( i ).getSaveRequest() ;
904 ok = ok & applications.get( ind ).getComputingClients().get( i ).getSaveRequest() ;
916 // Thread.sleep( 5000 ) ;
917 // } catch( InterruptedException e1 ) {
918 // e1.printStackTrace() ;
921 for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
924 applications.get( ind ).getComputingClients().get( i ).getClient().getStub().responseSave( true ) ;
925 applications.get( ind ).getComputingClients().get( i ).setSaveRequest( false ) ;
926 } catch( RemoteException e ) {
927 System.err.println( "Unable to send the save request response to " +
928 applications.get( ind ).getComputingClients().get( i ).getClient().getName() + "!" ) ;
929 e.printStackTrace() ;
933 applications.get( ind ).setLastSaveDate( System.currentTimeMillis() ) ;
939 for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
941 if( applications.get( ind ).getComputingClients().get( i ).getClient().getIP().equalsIgnoreCase( _ip ) )
944 applications.get( ind ).getComputingClients().get( i ).getClient().getStub().responseSave( false ) ;
945 } catch( RemoteException e ) {
946 System.err.println( "Unable to send the save request response to " +
947 applications.get( ind ).getComputingClients().get( i ).getClient().getName() + "!" ) ;
948 e.printStackTrace() ;
956 System.err.println( "!! Serious problem in treatRequestSave method!!" ) ;
962 public void restartOk( String _ip )
964 if( applications.size() > 0 && _ip != null && _ip.length() > 0 )
966 System.out.println( "Client " + _ip + " has finished to restart ("+applications.get( ind ).getComputingClients().size()+") ... " ) ;
967 if( (System.currentTimeMillis() - applications.get( ind ).getLastSaveDate()) > save_interleave )
969 // Has it already finished?
970 for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
972 if( applications.get( ind ).getComputingClients().get( i ).getClient().getIP().equalsIgnoreCase( _ip ) )
974 applications.get( ind ).getComputingClients().get( i ).setRestartOk( true ) ;
982 for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
986 ok = applications.get( ind ).getComputingClients().get( i ).getRestartOk() ;
988 ok = ok & applications.get( ind ).getComputingClients().get( i ).getRestartOk() ;
999 applications.get( ind ).setLastSaveDate( System.currentTimeMillis() ) ;
1001 for( int i = 0 ; i < applications.get( ind ).getComputingClients().size() ; i++ )
1003 applications.get( ind ).getComputingClients().get( i ).setRestartOk( false ) ;
1013 public void goApplication()
1015 synchronized( applications ) {
1016 if( running && applications.get( ind ).getStartTime() != 0 )
1018 applications.get( ind ).setStartTime( System.currentTimeMillis() ) ;
1019 applications.get( ind ).setLastSaveDate( System.currentTimeMillis() ) ;
1025 public void endApplication()
1027 synchronized( applications )
1031 Iterator<ComputingClient> it = computingClients.iterator() ;
1033 while( it.hasNext() )
1035 ComputingClient cl = it.next() ;
1038 cl.getClient().getStub().emergencyStop() ;
1039 } catch (RemoteException e) {
1040 e.printStackTrace();
1043 cl.getClient().setStatus( "connected" ) ;
1044 cl.getClient().setComputingClient( null ) ;
1049 applications.get( ind ).setEndTime( System.currentTimeMillis() ) ;
1050 applications.get( ind ).setRunning( false ) ;
1051 applications.get( ind ).clear() ;
1052 // applications.remove( ind ) ;
1056 System.out.println( "Application " + applications.get( ind ).getName() + " ends in " +
1057 applications.get( ind ).getExecutionTime() + " seconds." ) ;
1064 public String getAssociatedIP( String _ip )
1068 for( int i = 0 ; i < vmIPs.size() ; i++ )
1070 if( vmIPs.get( i ).getHostIP().equalsIgnoreCase( _ip ) )
1072 ret = vmIPs.get( i ).getVmIP() ;
1081 public Integer deployVM( final String _name, final String _archive, final String _directory )
1083 int nb = 0, pb = 0 ;
1085 if( _name != null && _name.length() > 0 && _archive != null && _name.length() > 0
1086 && _directory != null && _directory.length() > 0 )
1088 System.out.println( "Deploying the VM " + _name + " (" + _archive + ") ... " ) ;
1090 File file = new File( working_directory + "/" + _archive ) ;
1091 if( ! file.exists() )
1093 System.err.println( "There is no archive named " + _archive + " in my working directory!" ) ;
1096 } else if( file.isDirectory() ) {
1097 System.err.println( _archive + " is a directory!" ) ;
1104 // TODO do a better deployment !!
1106 // boolean error, ok, server ;
1107 // ArrayList<ConnectedClient> deployed = new ArrayList<ConnectedClient>() ;
1109 // boolean server = true ;
1112 for( int i = 0 ; i < clients.size() ; i++ )
1118 if( clients.get( i ).getStatus().equalsIgnoreCase( "connected" ) )
1120 synchronized( limitThread )
1122 while( limitThread.getNb() >= maxThread )
1125 limitThread.wait() ;
1126 } catch (InterruptedException e) {
1127 e.printStackTrace();
1134 final int indice = i ;
1135 new Thread( new Runnable() {
1140 boolean error = true ;
1143 ret = clients.get( indice ).getStub().deployVM( _name, _archive, _directory ) ;
1144 } catch( RemoteException e ) {
1145 System.err.println( "Unable to deploy the VM on " + clients.get( indice ).getName() + "!" ) ;
1146 e.printStackTrace() ;
1149 // The client does not have the archive, we have to send it.
1152 // Attention au multi-envois !!!
1153 System.out.print( "Sending VM archive to " + clients.get( indice ).getName() + " ... " ) ;
1160 wd = clients.get( indice ).getStub().getWorkingDirectory() ;
1161 snIP = clients.get( indice ).getStub().getIPHost() ;
1162 } catch (RemoteException e2) {
1163 System.err.println( "Unable to retrieve information on " + clients.get( indice ).getName() + "!" ) ;
1164 e2.printStackTrace() ;
1168 String[] command = new String[]{ "/usr/bin/scp", working_directory + "/" + _archive,
1174 Process proc = Runtime.getRuntime().exec( command ) ;
1177 if( proc.exitValue() == 0 )
1179 System.out.println( "Initial VM archive successfully sent." ) ;
1181 System.err.println( "Initial VM archive not sent!" ) ;
1182 System.err.println( "Error: " + proc.exitValue() ) ;
1183 BufferedReader b = new BufferedReader( new InputStreamReader( proc.getErrorStream() ) ) ;
1187 while( (l = b.readLine()) != null )
1189 System.err.println( l ) ;
1191 } catch( IOException e ) {
1192 e.printStackTrace() ;
1197 } catch( IOException e ) {
1198 System.err.println( "Error during initial VM archive send command: " ) ;
1199 e.printStackTrace() ;
1201 } catch( InterruptedException e ) {
1202 e.printStackTrace() ;
1213 ret = clients.get( indice ).getStub().deployVM( _name, _archive, _directory ) ;
1214 } catch( RemoteException e ) {
1215 System.err.println( "Unable to deploy the VM on " + clients.get( indice ).getName() + "!" ) ;
1216 e.printStackTrace() ;
1223 System.out.println( "Initial VM archive successfully deployed on " + clients.get( indice ).getName() + "." ) ;
1225 synchronized( deployingClients )
1227 deployingClients.inc() ;
1231 synchronized( limitThread )
1234 limitThread.notifyAll() ;
1242 synchronized( limitThread )
1244 while( limitThread.getNb() > 0 )
1247 limitThread.wait() ;
1248 } catch( InterruptedException e ) {
1249 e.printStackTrace() ;
1254 if( nb - deployingClients.getNb() > 0 )
1257 System.err.println( "** " + pb + " machine is not deployed!" ) ;
1259 System.err.println( "** " + pb + " machines are not deployed!" ) ;
1266 public String getWorkingDirectory()
1268 return working_directory ;
1272 private class OperatingClients
1276 OperatingClients() { nb = 0 ; }
1278 protected void inc() { nb++ ; }
1280 protected void dec() { nb-- ; }
1282 protected int getNb() { return nb ; }
1286 private class LimitThread
1290 LimitThread() { nb = 0 ; }
1292 protected void inc() { nb++ ; }
1294 protected void dec() { nb-- ; }
1296 protected int getNb() { return nb ; }
1301 /** La programmation est un art, respectons ceux qui la pratiquent !! **/