package and.hpcvm ;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
{
if( _sn != null )
{
- save_neighbor.set( 0, _sn ) ;
+ if( save_neighbor.size() == 0 )
+ {
+ save_neighbor.add( _sn ) ;
+ } else {
+ save_neighbor.set( 0, _sn ) ;
+ }
- System.out.println( "My save neighbor is " + _sn ) ;
+// System.out.println( "My save neighbor is " + _sn ) ;
try {
client.getStub().setSavingNeighbor( _sn ) ;
private ConnectedMonitor monitor ;
private DiscCount counter ;
private ArrayList<IPAssociation> vmIPs ;
+ private String working_directory ;
protected Server() throws RemoteException
computingClients = new ArrayList<Server.ComputingClient>() ;
monitor = null ;
+ working_directory = "/localhome/vmware" ;
+
exportObject() ;
vmIPs = new ArrayList<IPAssociation>() ;
cl.getStatus().equalsIgnoreCase( "saving" ) )
{
ComputingClient cc = cl.getComputingClient() ;
- ServicesClient dead = cc.getClient().getStub() ;
+// ServicesClient dead = cc.getClient().getStub() ;
String ipDead = cc.getClient().getIP() ;
boolean ok = false ;
for( int k = 0 ; k < computingClients.size() ; k++ )
{
try {
- computingClients.get( i ).getClient().getStub().
- replaceSavingNeighbor( dead, clients.get( i ).getStub() ) ;
+ computingClients.get( k ).getClient().getStub().
+ replaceSavingNeighbor( ipDead, clients.get( i ).getStub() ) ;
} catch( RemoteException e ) {
System.err.println( "Unable to inform " + computingClients.get( k ).getClient().getName() +
" of the replacement of a save neighbor!" ) ;
}
}
-
System.out.println( "Dead client successfully replaced." ) ;
- // restart vms
+
break ;
} else {
System.err.println( "Dead client not replaced!!" ) ;
while( counter.getNb() != 0 )
{
try {
- System.out.println( "### WAITING counter ###" ) ;
- counter.wait() ; // !!!!! synchro
+ counter.wait() ;
} catch( InterruptedException e ) {
e.printStackTrace() ;
}
return 0 ;
}
-
-
+
+
+ public Integer changeSaveName( String _ip, String _saveName )
+ {
+ if( _ip != null && _ip.length() > 0 && _saveName != null && _saveName.length() > 0 )
+ {
+ for( int i = 0 ; i < computingClients.size() ; i ++ )
+ {
+ if( computingClients.get( i ).getClient().getIP().equalsIgnoreCase( _ip ) )
+ {
+ computingClients.get( i ).setLastSave( _saveName ) ;
+ System.out.println( "Save name successfully change for " + _ip ) ;
+ return 0 ;
+ }
+ }
+ }
+
+ return 1 ;
+ }
@Override
public ArrayList<ServicesClient> startApplication( int _nb )
@Override
- public String getAssociatedIP( String _ip ) throws RemoteException
+ public String getAssociatedIP( String _ip )
{
String ret = null ;
return ret ;
}
+
+ public Integer deployVM( String _name, String _archive, String _directory )
+ {
+ int pb = -1 ;
+ int nb = 0 ;
+
+ if( _name != null && _name.length() > 0 && _archive != null && _name.length() > 0
+ && _directory != null && _directory.length() > 0 )
+ {
+ System.out.println( "Deploying the VM " + _name + " (" + _archive + ") ... " ) ;
+
+ File file = new File( working_directory + "/" + _archive ) ;
+ if( ! file.exists() )
+ {
+ System.err.println( "There is no archive named " + _archive + " in my working directory!" ) ;
+ file = null ;
+ return 1 ;
+ } else if( file.isDirectory() ) {
+ System.err.println( _archive + " is a directory!" ) ;
+ file = null ;
+ return 1 ;
+ }
+
+ file = null ;
+
+ // TODO do a better deployment !!
+ int ret ;
+ boolean error ;
+
+ pb = 0 ;
+
+ for( int i = 0 ; i < clients.size() ; i++ )
+ {
+ ret = 1 ;
+ error = false ;
+ try {
+ ret = clients.get( i ).getStub().deployVM( _name, _archive, _directory ) ;
+ } catch( RemoteException e ) {
+ System.err.println( "Unable to deploy the VM on " + clients.get( i ).getName() + "!" ) ;
+ e.printStackTrace() ;
+ }
+
+ // The client does not have the archive, we have to send it.
+ if( ret == 2 )
+ {
+ System.out.print( "Sending VM archive to " + clients.get( i ).getName() + " ... " ) ;
+
+ String wd = "" ;
+ String snIP = "" ;
+ error = false ;
+
+ try {
+ wd = clients.get( i ).getStub().getWorkingDirectory() ;
+ snIP = clients.get( i ).getStub().getIPHost() ;
+ } catch (RemoteException e2) {
+ System.err.println( "Unable to retrieve information on " + clients.get( i ).getName() + "!" ) ;
+ e2.printStackTrace() ;
+ error = true ;
+ pb++ ;
+ }
+
+ String[] command = new String[]{ "/usr/bin/scp", working_directory + "/" + _archive,
+ snIP + ":" + wd } ;
+
+ if( ! error )
+ try {
+ Process proc = Runtime.getRuntime().exec( command ) ;
+ proc.waitFor() ;
+
+ if( proc.exitValue() == 0 )
+ {
+ System.out.println( "Initial VM archive successfully sent." ) ;
+ } else {
+ System.err.println( "Initial VM archive not sent!" ) ;
+// printProcessError( p.getErrorStream() ) ;
+ System.err.println( "Error: " + proc.exitValue() ) ;
+ BufferedReader b = new BufferedReader( new InputStreamReader( proc.getErrorStream() ) ) ;
+
+ String l ;
+ try {
+ while( (l = b.readLine()) != null )
+ {
+ System.err.println( l ) ;
+ }
+ } catch( IOException e ) {
+ e.printStackTrace() ;
+ }
+
+ error = true ;
+ pb++ ;
+ }
+ } catch( IOException e ) {
+ System.err.println( "Error during initial VM archive send command: " ) ;
+ e.printStackTrace() ;
+ error = true ;
+ pb++ ;
+ } catch( InterruptedException e ) {
+ e.printStackTrace() ;
+ error = true ;
+ pb++ ;
+ }
+
+
+ if( error )
+ {
+ continue ;
+ }
+
+ // Second try ...
+ ret = 1 ;
+ try {
+ ret = clients.get( i ).getStub().deployVM( _name, _archive, _directory ) ;
+ } catch( RemoteException e ) {
+ System.err.println( "Unable to deploy the VM on " + clients.get( i ).getName() + "!" ) ;
+ e.printStackTrace() ;
+ pb++ ;
+ }
+ }
+
+ if( ret == 0 )
+ {
+ System.out.println( "Initial VM archive successfully deployed on " + clients.get( i ).getName() + "." ) ;
+ nb++ ;
+ }
+ }
+ }
+
+ if( pb > 0 )
+ {
+ if( pb == 1 )
+ System.err.println( "** " + pb + " machine is not deployed!" ) ;
+ if( pb > 1 )
+ System.err.println( "** " + pb + " machine(s) are not deployed!" ) ;
+ }
+
+ return nb ;
+ }
+
+
+ public String getWorkingDirectory()
+ {
+ return working_directory ;
+ }
+
}
/** La programmation est un art, respectons ceux qui la pratiquent !! **/