private int wait_start ;
private int max_start_try ;
private boolean isRestartedSave ;
- private long save_interleave ;
- private long date_last_save ;
+// private long save_interleave ;
+// private long date_last_save ;
private SaveProcess saveProcess;
private int maxRetryVM ;
private int timeRetryVM ;
private Semaphore sema ;
private boolean emergencyStop ;
private Process procSave ;
+ private SaveRequest saveRequest ;
private boolean lastSaveOk ;
procSave.destroy() ;
} catch( Exception e ) {}
+ // Stopping the save request
+ synchronized( saveRequest )
+ {
+ saveRequest.setStatus( false ) ;
+ try {
+ saveRequest.notifyAll() ;
+ } catch( Exception e ) {}
+ }
+
stopVM() ;
}
+
@Override
public int startVM( int _mode )
{
e2.printStackTrace() ;
}
+
// Checking first start
if( machine.checkVmx() == 1 )
{
" -gp " + machine.getVmUserPasswd() + " runScriptInGuest " +
working_directory + "/" + machine.getDirectory()
+ "/" + machine.getVmx_name() + " " + ushell +
- " \"echo ok\"" ;// + " -noWait " ;
+ " \"echo ok\"" ;
try {
FileWriter fw = new FileWriter( new File( working_directory + "/testStarted.sh" ) ) ;
if( p.exitValue() == 0 )
{
started = true ;
-// machine.setStatus( "running" ) ;
-// if( _mode == 0 )
-// {
-// LocalHost.Instance().getServerStub().changeStatus(
-// LocalHost.Instance().getIP(), "running" ) ;
-// }
ret = false ;
} else {
System.err.println( "Error while checking if the VM is started!" ) ;
-// printProcessError( p.getErrorStream() ) ;
ret = printProcessError( p ) ;
if( ! ret )
System.out.println( "Retrying (" + retry + ") ... " ) ;
Thread.sleep( timeRetryVM ) ;
}
-// wait_start = wait_start / 2 ;
count++ ;
}
} catch( IOException e ) {
ret = false ;
} else {
System.err.println( "VM did not received the host IP!" ) ;
-// printProcessError( p.getErrorStream() ) ;
ret = printProcessError( p ) ;
if( ! ret )
if( p.exitValue() == 0 )
{
System.out.println( "VM received its assigned IP." ) ;
-// return 0 ;
ret = false ;
machine.setStatus( "running" ) ;
} else {
System.err.println( "VM did not received its assigned IP!" ) ;
-// printProcessError( p.getErrorStream() ) ;
ret = printProcessError( p ) ;
if( ! ret )
return 1 ;
}
+
@Override
public int stopVM()
{
ret = false ;
} else {
System.err.println( "Virtual machine not stopped!" ) ;
-// printProcessError( p.getErrorStream() ) ;
ret = printProcessError( p ) ;
if( ! ret )
e1.printStackTrace() ;
}
-// if( ! isRestartedSave )
-// {
-// /** Restoring the original vmx file (necessary after a crash) **/
-// command = new String[]{ "/bin/cp",
-// working_directory + "/" + machine.getDirectory() + "/" + machine.getVmx_name_normal(),
-// working_directory + "/" + machine.getDirectory() + "/" + machine.getVmx_name() } ;
-//
-// try {
-// Process p = Runtime.getRuntime().exec( command ) ;
-// p.waitFor() ;
-//
-// if( p.exitValue() == 0 )
-// {
-// System.out.println( "Successfully replaced the VMX file." ) ;
-// sema.release() ;
-// emergencyStop = false ;
-// return 0 ;
-// } else {
-// System.err.println( "Unsuccessful replacement of the VMX file!" ) ;
-//// printProcessError( p.getErrorStream() ) ;
-// printProcessError( p ) ;
-// sema.release() ;
-// return 1 ;
-// }
-// } catch( IOException e ) {
-// System.err.println( "Error during VMX file replacement: " ) ;
-// e.printStackTrace() ;
-// sema.release() ;
-// return 1 ;
-// } catch( InterruptedException e ) {
-// e.printStackTrace() ;
-// sema.release() ;
-// return 1 ;
-// }
-// } else {
+
if( machine.checkVmx() == 0 )
{
sema.release() ;
ret = false ;
} else {
System.err.println( "Virtual machine not suspended!" ) ;
-// printProcessError( p.getErrorStream() ) ;
ret = printProcessError( p ) ;
if( ! ret )
} else {
System.err.println( "Virtual machine not restarted!" ) ;
-// printProcessError( p.getErrorStream() ) ;
ret = printProcessError( p ) ;
if( ! ret )
return 1 ;
}
-// System.out.print( "Changing VMX file after crash ... " ) ;
-//
-// String[] command = new String[]{ "/bin/cp",
-// working_directory + "/" + machine.getDirectory() + "/" + machine.getVmx_name_crash(),
-// working_directory + "/" + machine.getDirectory() + "/" + machine.getVmx_name() } ;
-//
-// try {
-// Process p = Runtime.getRuntime().exec( command ) ;
-// p.waitFor() ;
-//
-// if( p.exitValue() == 0 )
-// {
-// System.out.println( "Successfully replaced the VMX file." ) ;
-// } else {
-// System.err.println( "Unsuccessful replacement of the VMX file!" ) ;
-//// printProcessError( p.getErrorStream() ) ;
-// printProcessError( p ) ;
-//
-// return 1 ;
-// }
-// } catch( IOException e ) {
-// System.err.println( "Error during VMX file replacement: " ) ;
-// e.printStackTrace() ;
-// } catch( InterruptedException e ) {
-// e.printStackTrace() ;
-// }
/** Retrieving VM assigned IP **/
String vmIP = null ;
if( startVM( 0 ) == 0 )
{
if( sendSaveOkVM() == 0 )
- {
- date_last_save = System.currentTimeMillis() ;
+ {
+ try {
+ LocalHost.Instance().getServerStub().restartOk( LocalHost.Instance().getIP() ) ;
+ } catch( RemoteException e ) {
+ System.err.println( "Unable to inform server about my successful restart!" ) ;
+ e.printStackTrace() ;
+ }
return 0 ;
}
return 0 ;
} else {
System.err.println( "Signal not sent!" ) ;
-// printProcessError( p.getErrorStream() ) ;
ret = printProcessError( p ) ;
if( ! ret )
System.out.println( "Saving VM ..." ) ;
saveProcess.setStatus( true ) ;
+ long deb = System.currentTimeMillis() ;
+
machine.setStatus( "saving" ) ;
try {
LocalHost.Instance().getServerStub().changeStatus(
String[] command ;
String saveName = "" ;
boolean error = false ;
- boolean errorVM = false ;
- if( suspendVM( 1 ) == 1 ) { error = true ; errorVM = true ; }
+
+ if( suspendVM( 1 ) == 1 ) { return 1 ; }
+
if( ! lastSaveOk )
{
- System.out.println( "Deletion of last nok archive ... " ) ;
+ 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 ;
+
+ file = new File( working_directory + "/" + machine.getName() + "_new_" + machine.getComputationId() + ".tar.gz" ) ;
+ if( file.exists() )
+ {
+ arch2 = working_directory + "/" + machine.getName() + "_new_" + machine.getComputationId() + ".tar.gz" ;
+ }
+
+ file = null ;
+
+ if( arch1.length() > 0 || arch2.length() > 0 )
+ {
+ System.out.println( "Deletion of last nok archive ... " ) ;
- command = new String[]{ "/bin/rm", "-rf",
- working_directory + "/" + machine.getName() + "_new_" + machine.getComputationId() + ".tar",
- working_directory + "/" + machine.getName() + "_new_" + machine.getComputationId() + ".tar.gz", } ;
+ command = new String[]{ "/bin/rm", "-rf",
+ arch1, arch2 } ;
- try {
- procSave = Runtime.getRuntime().exec( command ) ;
- procSave.waitFor() ;
+ try {
+ procSave = Runtime.getRuntime().exec( command ) ;
+ procSave.waitFor() ;
- if( procSave.exitValue() == 0 )
- {
- System.out.println( "Last nok archive successfully deleted." ) ;
- } else {
- System.err.println( "Last nok archive not deleted!" ) ;
-// printProcessError( p.getErrorStream() ) ;
- printProcessError( procSave ) ;
+ if( procSave.exitValue() == 0 )
+ {
+ System.out.println( "Last nok archive successfully deleted." ) ;
+ } else {
+ System.err.println( "Last nok archive not deleted!" ) ;
+ printProcessError( procSave ) ;
+ error = true ;
+ }
+ } catch( IOException e ) {
+ System.err.println( "Error during nok archive deletion command: " ) ;
+ error = true ;
+ e.printStackTrace() ;
+ } catch( InterruptedException e ) {
+ e.printStackTrace() ;
error = true ;
}
- } catch( IOException e ) {
- System.err.println( "Error during nok archive deletion command: " ) ;
- error = true ;
- e.printStackTrace() ;
- } catch( InterruptedException e ) {
- e.printStackTrace() ;
- error = true ;
}
}
+
if( ! error )
{
System.out.print( "Creation of the archive ... " ) ;
+
/** Archive creation **/
-// command = new String[]{ "/bin/tar", "-cf",
-// working_directory + "/" + machine.getName() + "_new_" + machine.getComputationId() + ".tar",
-// working_directory + "/" + machine.getDirectory() } ;
-//
command = new String[]{ "/bin/tar", "-cf",
machine.getName() + "_new_" + machine.getComputationId() + ".tar",
machine.getDirectory(), "-C", working_directory } ;
} else {
System.err.println( "Archive not created!" ) ;
-// printProcessError( p.getErrorStream() ) ;
printProcessError( procSave ) ;
error = true ;
System.out.println( "Archive successfully compressed." ) ;
} else {
System.err.println( "Archive not compressed!" ) ;
-// printProcessError( p.getErrorStream() ) ;
printProcessError( procSave ) ;
error = true ;
}
}
+ long fin = System.currentTimeMillis() ;
+
+ System.out.println( "Time to create the save: " + (fin-deb)/1000 + " seconds." ) ;
+
/** Restarting VM **/
- if( errorVM || startVM( 0 ) == 1 ) { error = true ; }
+ if( startVM( 0 ) == 1 ) { return 1 ; }
/** Sending ok save signal **/
-// if( ! error )
-// {
- if( sendSaveOkVM() == 1 ) { error = true ; }
-
-
-// }
-
-// /** Deletion of the tar archive **/
-// if( ! error )
-// {
-// command = new String[]{ "/bin/rm",
-// working_directory + "/" + machine.getName()
-// + "_new_" + machine.getComputationId() + ".tar" } ;
-//
-// try {
-// Process p = Runtime.getRuntime().exec( command ) ;
-// p.waitFor() ;
-//
-// if( p.exitValue() == 0 )
-// {
-// System.out.println( "Archive (not compressed) successfully deleted." ) ;
-// } else {
-// System.err.println( "Archive (not compressed) not deleted!" ) ;
-// printProcessError( p.getErrorStream() ) ;
-//
-// error = true ;
-// }
-// } catch( IOException e ) {
-// System.err.println( "Error during archive (not compressed) deletion command: " ) ;
-// e.printStackTrace() ;
-// error = true ;
-// } catch( InterruptedException e ) {
-// e.printStackTrace() ;
-// error = true ;
-// }
-// }
+ if( sendSaveOkVM() == 1 ) { return 1 ; }
saveName = machine.getName() + "_new_" + machine.getComputationId() + ".tar.gz" ;
return 1 ;
}
- ArrayList<ServicesClient> sn = machine.getSaveNeighbors() ;
+ ArrayList<SaveNeighbor> sn = machine.getSaveNeighbors() ;
for( int i = 0 ; i < sn.size() ; i++ )
{
- String name ;
- String wd ;
- String snIP ;
-
- try {
- name = sn.get( i ).getName() ;
- wd = sn.get( i ).getWorkingDirectory() ;
- snIP = sn.get( i ).getIPHost() ;
- } catch (RemoteException e2) {
- System.err.println( "Unable to retrieve information on one save neighbor!" ) ;
- e2.printStackTrace() ;
- continue ;
- }
+ String name = sn.get( i ).getName() ;
+ String wd = sn.get( i ).getWorkingDirectory() ;
+ String snIP = sn.get( i ).getIPHost() ;
System.out.print( "Sending save to " + name + " ... " ) ;
System.out.println( "Archive successfully sent." ) ;
} else {
System.err.println( "Archive not sent!" ) ;
-// printProcessError( p.getErrorStream() ) ;
printProcessError( procSave ) ;
error = true ;
serverStub = null ;
saveProcess = new SaveProcess() ;
+ saveRequest = new SaveRequest() ;
machine = new VirtualMachine() ;
maxRetryVM = 10 ;
timeRetryVM = 10000 ;
- save_interleave = 30 * 60 * 1000 ;
- date_last_save = 0 ;
+// save_interleave = 30 * 60 * 1000 ;
+// date_last_save = 0 ;
isRestartedSave = false ;
lastSaveOk = true ;
System.out.println( "Connected to server " + server_ip + " on port " + server_port + "." ) ;
-// LocalHost.Instance().setServerIP( server_ip ) ;
LocalHost.Instance().setServerStub( serverStub ) ;
private void exportObject()
{
-// ServicesClient ref = null ;
Registry reg = null ;
try
{
try {
LocalHost.Instance().getServerStub().ping( LocalHost.Instance().getIP() ) ;
- } catch (RemoteException e1) {
- e1.printStackTrace();
+ } catch( RemoteException e1 ) {
+ System.err.println( "Unable to ping the server!" ) ;
+ e1.printStackTrace() ;
}
try {
{
try {
serverSocket.close() ;
-// socket = serverSocket.accept() ;
for( int i = 0 ; i < dialogs.size() ; i++ )
{
/** It's time to do a save **/
if( run && line != null && line.equalsIgnoreCase( "save" ) )
- {
+ {
try {
machine.setComputationId( Integer.parseInt( reader.readLine() ) ) ;
} catch( Exception e ) {
e.printStackTrace() ;
}
- if( (System.currentTimeMillis() - date_last_save) > save_interleave )
+ 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() )
{
- date_last_save = System.currentTimeMillis() ;
-
/* Close streams */
reader.close() ; reader = null ;
socket.close() ; socket = null ;
run = false ;
+
+ saveRequest.setStatus( false ) ;
- /* Starting the VM save */
+ /* Requesting the VM save */
saveVM() ;
-
- date_last_save = System.currentTimeMillis() ;
} else {
sendSaveOkVM() ;
}
} else {
System.err.println( "Last save NOK!" ) ;
System.err.println( "Error: " ) ;
-// printProcessError( p.getErrorStream() ) ;
printProcessError( p ) ;
}
} catch( IOException e ) {
for( int i = 0 ; i < machine.getSaveNeighbors().size() ; i++ )
{
try {
- machine.getSaveNeighbors().get( i ).changeSaveName( save_new, save_name, machine.getComputationId() ) ;
+ machine.getSaveNeighbors().get( i ).getStub().changeSaveName( save_new, save_name, machine.getComputationId() ) ;
} catch( RemoteException e ) {
- try {
- System.err.println( "Unable to change save name on " + machine.getSaveNeighbors().get( i ).getName() + "!" ) ;
- } catch( RemoteException e1 ) {
- System.err.println( "Unable to change save name on an unamed save neighbor!" ) ;
- e1.printStackTrace() ;
- }
+ System.err.println( "Unable to change save name on " + machine.getSaveNeighbors().get( i ).getName() + "!" ) ;
e.printStackTrace() ;
}
}
} else {
System.err.println( "Change save name NOK!" ) ;
System.err.println( "Error: " ) ;
-// printProcessError( p.getErrorStream() ) ;
printProcessError( p ) ;
}
} catch( IOException e ) {
@Override
- public void setSavingNeighbor( ServicesClient _sn )
+ public void setSaveNeighbor( SaveNeighbor _sn )
{
if( _sn != null )
{
- ArrayList<ServicesClient> as = new ArrayList<ServicesClient>() ;
+ ArrayList<SaveNeighbor> as = new ArrayList<SaveNeighbor>() ;
as.add( _sn ) ;
- try {
- System.out.println( "Save neighbor: " + _sn.getName() ) ;
- } catch( RemoteException e ) {
- System.err.println( "Unable to retrieve the name of the save neighbor!" ) ;
- e.printStackTrace() ;
- }
+ System.out.println( "Save neighbor: " + _sn.getName() ) ;
machine.setSaveNeighbors( as ) ;
}
@Override
- public void setSavingNeighbors( ArrayList<ServicesClient> _sn )
+ public void setSaveNeighbors( ArrayList<SaveNeighbor> _sn )
{
if( _sn != null && _sn.size() > 0 )
{
System.out.print( "Save neighbors: " ) ;
for( int i = 0 ; i < _sn.size() ; i++ )
{
- try {
- System.out.print( _sn.get( i ).getName() ) ;
- } catch( RemoteException e ) {
- System.err.println( "Unable to retrieve the name of a save neighbor!" ) ;
- e.printStackTrace() ;
- }
+ System.out.print( _sn.get( i ).getName() ) ;
if( i != _sn.size() - 1 )
{
@Override
- public void addSavingNeighbor( ServicesClient _sn )
+ public void addSaveNeighbor( SaveNeighbor _sn )
{
if( _sn != null )
{
- try {
- System.out.println( "Adding save neighbor: " + _sn.getName() ) ;
- } catch( RemoteException e ) {
- System.err.println( "Unable to retrieve the name of a save neighbor!" ) ;
- e.printStackTrace() ;
- }
+ System.out.println( "Adding save neighbor: " + _sn.getName() ) ;
machine.getSaveNeighbors().add( _sn ) ;
}
@Override
- public void addSavingNeighbors( ArrayList<ServicesClient> _sn )
+ public void addSaveNeighbors( ArrayList<SaveNeighbor> _sn )
{
if( _sn != null && _sn.size() > 0 )
{
System.out.print( "Adding save neighbors: " ) ;
for( int i = 0 ; i < _sn.size() ; i++ )
{
- try {
- System.out.print( _sn.get( i ).getName() ) ;
- } catch( RemoteException e ) {
- System.err.println( "Unable to retrieve the name of a save neighbor!" ) ;
- e.printStackTrace() ;
- }
-
+ System.out.print( _sn.get( i ).getName() ) ;
+
if( i != _sn.size() - 1 )
{
System.out.print( ", " ) ;
@Override
- public void replaceSavingNeighbor( String _old, ServicesClient _new )
+ public void replaceSaveNeighbor( SaveNeighbor _old, SaveNeighbor _new )
{
System.out.print( "Replacing a save neihgbor ... " ) ;
if( _old != null && _new != null )
{
int i = 0 ;
+ boolean change = false ;
for( i = 0 ; i < machine.getSaveNeighbors().size() ; i++ )
{
- try {
- if( machine.getSaveNeighbors().get( i ).getIPHost().equalsIgnoreCase( _old ) )
- {
- machine.getSaveNeighbors().set( i, _new ) ;
- System.out.println( "Save neighbor successfully changed." ) ;
- break ;
- }
- } catch( RemoteException e ) {
- System.err.println( "Unable to retrieve the IP address of a save neighbor!" ) ;
- e.printStackTrace() ;
+ if( machine.getSaveNeighbors().get( i ).getIPHost().equalsIgnoreCase( _old.getIPHost() ) )
+ {
+ machine.getSaveNeighbors().set( i, _new ) ;
+ System.out.println( "Save neighbor successfully changed." ) ;
+ change = true ;
+ break ;
}
}
- if( i == machine.getSaveNeighbors().size() )
+ if( ! change )
{
System.out.println( "I am not concerned by the modification." ) ;
}
}
// TODO NEIGHBORS !!!!
- //System.out.println( "!!!! NEIGHBORS !!!!!" ) ;
boolean ok = false ;
- boolean go = true ;
int i = 0 ;
while( ! ok && i < machine.getSaveNeighbors().size() )
{
- try {
- System.out.print( "Retrieving a save on " + machine.getSaveNeighbors().get( 0 ).getName() + " ... " ) ;
- } catch( RemoteException e1 ) {
- System.err.println( "Unable to retrieve the name of a save neighbor!" ) ;
- e1.printStackTrace() ;
- }
+ System.out.print( "Retrieving a save on " + machine.getSaveNeighbors().get( 0 ).getName() + " ... " ) ;
String command[] = {} ;
- try
- {
- command = new String[]{ "/usr/bin/scp",
- machine.getSaveNeighbors().get( i ).getIPHost() + ":" +
- machine.getSaveNeighbors().get( i ).getWorkingDirectory() + "/" +
- machine.getSave_last(),
- working_directory } ;
- } catch( RemoteException e1 ) {
- System.err.println( "Unable to retrieve the name of a save neighbor!" ) ;
- e1.printStackTrace() ;
- go = false ;
- }
+ command = new String[]{ "/usr/bin/scp",
+ machine.getSaveNeighbors().get( i ).getIPHost() + ":" +
+ machine.getSaveNeighbors().get( i ).getWorkingDirectory() + "/" +
+ machine.getSave_last(),
+ working_directory } ;
- if( go )
try {
Process p = Runtime.getRuntime().exec( command ) ;
p.waitFor() ;
} else {
System.err.println( "Archive not retrieved!" ) ;
System.err.println( "Error: " ) ;
-// printProcessError( p.getErrorStream() ) ;
+
printProcessError( p ) ;
-// error = true ;
}
} catch( IOException e ) {
System.err.println( "Error during archive retrieve command: " ) ;
e.printStackTrace() ;
-// error = true ;
} catch( InterruptedException e ) {
e.printStackTrace() ;
-// error = true ;
}
i++ ;
}
+
@Override
public String getIPVM() throws RemoteException
{
}
+ @Override
+ public void responseSave( boolean _b )
+ {
+ synchronized( saveRequest )
+ {
+ saveRequest.setStatus( _b ) ;
+ try {
+ saveRequest.notifyAll() ;
+ } catch( Exception e ) {
+ e.printStackTrace() ;
+ }
+ }
+ }
+
+
+ private class SaveRequest
+ {
+ boolean status ;
+
+ SaveRequest()
+ {
+ status = false ;
+ }
+
+ protected boolean getStatus() { return status ; }
+
+ protected void setStatus( boolean _b ) { status = _b ; }
+ }
+
private class SaveProcess
{
boolean status ;
--- /dev/null
+package and.hpcvm;
+
+import java.io.Serializable;
+import java.rmi.RemoteException;
+import java.util.ArrayList;
+
+
+
+
+public class ComputingClient implements Serializable
+{
+
+ private static final long serialVersionUID = 1L;
+ private ConnectedClient client ;
+ private boolean save_status ;
+ private ArrayList<SaveNeighbor> save_neighbors ;
+ private String lastSaveName ;
+ private boolean saveRequest ;
+ private boolean restartOk ;
+
+ ComputingClient( ConnectedClient cl )
+ {
+ client = cl ;
+ save_status = false ;
+ save_neighbors = new ArrayList<SaveNeighbor>() ;
+ lastSaveName = "none" ;
+ saveRequest = false ;
+ restartOk = false ;
+ }
+
+ protected void setRestartOk( boolean _b ) { restartOk = _b ; }
+
+ protected boolean getRestartOk() { return restartOk ; }
+
+ protected void setSaveRequest( boolean _b ) { saveRequest = _b ; }
+
+ protected boolean getSaveRequest() { return saveRequest ; }
+
+ protected ConnectedClient getClient() { return client ; }
+
+ protected boolean getSaveStatus(){ return save_status ; }
+
+ protected void setSaveStatus( boolean _status ) { save_status = _status ; }
+
+ protected void setSaveNeighbor( SaveNeighbor _sn )
+ {
+ if( _sn != null )
+ {
+ if( save_neighbors.size() == 0 )
+ {
+ save_neighbors.add( _sn ) ;
+ } else {
+ save_neighbors.set( 0, _sn ) ;
+ }
+
+ try {
+ client.getStub().setSaveNeighbor( _sn ) ;
+ } catch( RemoteException e ) {
+ System.err.println( "Error while setting save neighbor on " +
+ client.getName() + "(" + client.getIP() + ")!" ) ;
+ e.printStackTrace() ;
+ }
+ }
+ }
+
+ protected SaveNeighbor getSaveNeighbor()
+ {
+ if( save_neighbors.isEmpty() )
+ {
+ return null ;
+ } else {
+ return save_neighbors.get( 0 ) ;
+ }
+ }
+
+ public void setLastSave( String _saveName )
+ {
+ lastSaveName = _saveName ;
+ }
+
+ public String getLastSave() { return lastSaveName ; }
+
+}
\ No newline at end of file
--- /dev/null
+package and.hpcvm;
+
+import java.io.Serializable;
+import java.rmi.RemoteException;
+
+public class ConnectedClient implements Serializable
+{
+ private static final long serialVersionUID = 1L;
+ private ServicesClient stub ;
+ private int timeout ;
+ private Status state ;
+ private String ip ;
+ private String name ;
+ private ComputingClient cl ;
+
+ ConnectedClient( ServicesClient _stub )
+ {
+ stub = _stub ;
+ timeout = 0 ;
+ state = new Status() ;
+ state.setStatus( "connected" ) ;
+ try {
+ ip = stub.getIPHost() ;
+ name = stub.getName() ;
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ cl = null ;
+ }
+
+ protected ServicesClient getStub() { return stub ; }
+
+ protected void setStub( ServicesClient _stub ) { stub = _stub ; }
+
+ protected int getTimeout() { return timeout ; }
+
+ protected void incTimeout() { timeout++ ; }
+
+ protected void resetTimeout() { timeout = 0 ; }
+
+ protected String getStatus() { return state.getStatus() ; }
+
+ protected void setStatus( String _state ) { state.setStatus( _state ) ; }
+
+ protected String getIP() { return ip ; }
+
+ protected String getName() { return name ; } ;
+
+ protected void setComputingClient( ComputingClient _cl ) { cl = _cl ; }
+
+ protected ComputingClient getComputingClient() { return cl ; }
+}
--- /dev/null
+package and.hpcvm;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+
+
+
+public class RunningApplication implements Serializable
+{
+ private static final long serialVersionUID = 1L;
+ private String name ;
+ private ArrayList<ComputingClient> computingsNodes ;
+ private long lastSaveDate ;
+ private String vmName ;
+ private boolean running ;
+ private long startTime ;
+ private long endTime ;
+
+ public RunningApplication( String _name )
+ {
+ name = _name ;
+ computingsNodes = new ArrayList<ComputingClient>() ;
+ lastSaveDate = 0 ;
+ running = false ;
+ startTime = 0 ;
+ endTime = 0 ;
+ }
+
+
+ public void clear() { computingsNodes.clear() ; }
+
+ public int getNbComputingClients() { return computingsNodes.size() ; }
+
+ public long getLastSaveDate() { return lastSaveDate ; }
+
+ public void setLastSaveDate( long _sd ) { lastSaveDate = _sd ; }
+
+ public void setName( String _name ) { name = _name ; }
+
+ public String getName() { return name ; }
+
+ public void setStartTime( long _t ) { startTime = _t ; }
+
+ public long getStartTime() { return startTime ; }
+
+ public void setEndTime( long _t ) { endTime = _t ; }
+
+ public long getEndTime() { return endTime ; }
+
+ public long getExecutionTime() { return endTime - startTime ; }
+
+
+ public void setComputingClients( ArrayList<ComputingClient> _cc )
+ {
+ if( _cc != null )
+ {
+ computingsNodes.clear() ;
+
+ System.out.println( "Application " + name + " contains clients:" ) ;
+
+ for( int i = 0 ; i < _cc.size() ; i++ )
+ {
+ computingsNodes.add( _cc.get( i ) ) ;
+ System.out.println( " " + _cc.get(i).getClient().getName() ) ;
+ }
+ }
+ }
+
+
+ public ArrayList<ComputingClient> getComputingClients() { return computingsNodes ; }
+
+
+ public int replaceComputingClient( ComputingClient _dead, ComputingClient _new )
+ {
+ if( _dead != null && _new != null )
+ {
+ for( int i = 0 ; i < computingsNodes.size() ; i++ )
+ {
+ if( computingsNodes.get( i ).getClient().getIP().equalsIgnoreCase( _dead.getClient().getIP() ) )
+ {
+ System.out.println( "Replacing " + _dead.getClient().getName() + " with " +_new.getClient().getName() ) ;
+ computingsNodes.set( i , _new ) ;
+ return 0 ;
+ }
+
+ System.err.println( "Dead computing client not found. Unable to replace it!" ) ;
+ }
+ }
+
+ return 1 ;
+ }
+
+
+ public void setVmName( String _vmname ) { vmName = _vmname ; }
+
+ public String getVmName() { return vmName ; }
+
+ public void setRunning( boolean _b ) { running = _b ; }
+
+ public boolean getRunning() { return running ; }
+
+}
+
+/** La programmation est un art, respectons ceux qui la pratiquent !! **/
--- /dev/null
+package and.hpcvm ;
+
+import java.io.Serializable;
+import java.rmi.RemoteException;
+
+
+public class SaveNeighbor implements Serializable
+{
+ private static final long serialVersionUID = 1L;
+ private ServicesClient sc ;
+ private String ip ;
+ private String name ;
+ private String wd ;
+
+ public SaveNeighbor( ServicesClient _sc ) throws RemoteException
+ {
+ super() ;
+
+ sc = _sc ;
+ try {
+ ip = sc.getIPHost() ;
+ name = sc.getName() ;
+ wd = sc.getWorkingDirectory() ;
+ } catch( RemoteException e ) {
+ System.err.println( "Unable to retrieve inforation one save neighbor!" ) ;
+ e.printStackTrace() ;
+ }
+ }
+
+ protected String getIPHost() { return ip ; }
+
+ protected String getName() { return name ; }
+
+ protected String getWorkingDirectory() { return wd ; }
+
+ protected ServicesClient getStub() { return sc ; }
+
+}
\ No newline at end of file
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import java.util.Iterator;
+import java.util.concurrent.Semaphore;
public class Server extends UnicastRemoteObject implements ServicesServer
}
protected int getNb() { return nb ; }
- }
-
-
- private class ConnectedClient
- {
- private ServicesClient stub ;
- private int timeout ;
- private Status state ;
- private String ip ;
- private String name ;
- private ComputingClient cl ;
-
- ConnectedClient( ServicesClient _stub )
- {
- stub = _stub ;
- timeout = 0 ;
- state = new Status() ;
- state.setStatus( "connected" ) ;
- try {
- ip = stub.getIPHost() ;
- name = stub.getName() ;
- } catch (RemoteException e) {
- e.printStackTrace();
- }
- cl = null ;
- }
-
- protected ServicesClient getStub() { return stub ; }
-
- protected void setStub( ServicesClient _stub ) { stub = _stub ; }
-
- protected int getTimeout() { return timeout ; }
-
- protected void incTimeout() { timeout++ ; }
-
- protected void resetTimeout() { timeout = 0 ; }
-
- protected String getStatus() { return state.getStatus() ; }
-
- protected void setStatus( String _state ) { state.setStatus( _state ) ; }
-
- protected String getIP() { return ip ; }
-
- protected String getName() { return name ; } ;
-
- protected void setComputingClient( ComputingClient _cl ) { cl = _cl ; }
-
- protected ComputingClient getComputingClient() { return cl ; }
- }
-
-
- private class ComputingClient
- {
- private ConnectedClient client ;
- private boolean save_status ;
- private ArrayList<ServicesClient> save_neighbor ;
- private String lastSaveName ;
-
- ComputingClient( ConnectedClient cl )
- {
- client = cl ;
- save_status = false ;
- save_neighbor = new ArrayList<ServicesClient>() ;
- lastSaveName = "none" ;
- }
-
- protected ConnectedClient getClient() { return client ; }
-
- protected boolean getSaveStatus(){ return save_status ; }
-
- protected void setSaveStatus( boolean _status ) { save_status = _status ; }
-
- protected void setSaveNeighbor( ServicesClient _sn )
- {
- if( _sn != null )
- {
- if( save_neighbor.size() == 0 )
- {
- save_neighbor.add( _sn ) ;
- } else {
- save_neighbor.set( 0, _sn ) ;
- }
-
-// System.out.println( "My save neighbor is " + _sn ) ;
-
- try {
- client.getStub().setSavingNeighbor( _sn ) ;
- } catch( RemoteException e ) {
- System.err.println( "Error while setting save neighbor on " +
- client.getName() + "(" + client.getIP() + ")!" ) ;
- e.printStackTrace() ;
- }
- }
- }
-
- protected ServicesClient getSaveNeighbor()
- {
- if( save_neighbor.isEmpty() )
- {
- return null ;
- } else {
- return save_neighbor.get( 0 ) ;
- }
- }
-
- public void setLastSave( String _saveName )
- {
- lastSaveName = _saveName ;
- }
-
- public String getLastSave() { return lastSaveName ; }
-
- }
+ }
private class IPAssociation
IPAssociation()
{
- vmIP = null ;
- hostIP = null ;
+ vmIP = "" ;
+ hostIP = "" ;
}
protected void setVmIP( String _vmIP )
private int port ;
private ArrayList<ConnectedClient> clients ;
private ArrayList<ComputingClient> computingClients ;
+ private ArrayList<RunningApplication> applications ;
private int max_timeout ;
private ConnectedMonitor monitor ;
private DiscCount counter ;
private ArrayList<IPAssociation> vmIPs ;
private String working_directory ;
+ private long save_interleave ;
+ private Semaphore semaSave ;
protected Server() throws RemoteException
{
for( int i = 0 ; i < vmIPs.size() ; i++ )
{
- if( vmIPs.get( i ).getHostIP() == null )
+ if( vmIPs.get( i ).getHostIP().equalsIgnoreCase( "" ) )
{
vmIPs.get( i ).setHostIP( _ip ) ;
port = _port ;
max_timeout = 4 ;
- clients = new ArrayList<Server.ConnectedClient>() ;
- computingClients = new ArrayList<Server.ComputingClient>() ;
+ clients = new ArrayList<ConnectedClient>() ;
+ computingClients = new ArrayList<ComputingClient>() ;
+ applications = new ArrayList<RunningApplication>() ;
monitor = null ;
working_directory = "/localhome/vmware" ;
+ save_interleave = 30 * 60 * 1000 ;
+
+ semaSave = new Semaphore( 1 ) ;
+
exportObject() ;
vmIPs = new ArrayList<IPAssociation>() ;
vmIPs.get( vmIPs.size() - 1 ).setVmIP( "10.11.10." + i ) ;
}
- clients = new ArrayList<Server.ConnectedClient>() ;
+ clients = new ArrayList<ConnectedClient>() ;
counter = new DiscCount() ;
monitor = new ConnectedMonitor() ;
monitor.start() ;
+
+ // TODO
+ // Check if there are running applications ... and restart them :)
}
for( int i = 0 ; i < clients.size() ; i++ )
{
try {
+ clients.get( i ).getStub().emergencyStop() ;
clients.get( i ).getStub().stop() ;
} catch (RemoteException e) {
e.printStackTrace();
ComputingClient cc = cl.getComputingClient() ;
// ServicesClient dead = cc.getClient().getStub() ;
String ipDead = cc.getClient().getIP() ;
+ SaveNeighbor snDead = null ;
+ for( int i = 0 ; i < computingClients.size() ; i++ )
+ {
+ if( computingClients.get( i ).getSaveNeighbor().getIPHost().equalsIgnoreCase( ipDead ) )
+ {
+ snDead = computingClients.get( i ).getSaveNeighbor() ;
+ break ;
+ }
+ }
boolean ok = false ;
ComputingClient ccl = new ComputingClient( clients.get(i) ) ;
clients.get( i ).setComputingClient( ccl ) ;
- ServicesClient sn = computingClients.get( pos ).getSaveNeighbor() ;
+ SaveNeighbor sn = computingClients.get( pos ).getSaveNeighbor() ;
ccl.setSaveNeighbor( sn ) ;
computingClients.set( pos, ccl ) ;
if( res == 0 )
{
ok = true ;
+
+ boolean ok_new = false, ok_old = false ;
- // replace dead client in vmIPs
+ // replace dead client in vmIPs
for( int j = 0 ; j < vmIPs.size() ; j++ )
{
+ if( vmIPs.get( j ).getHostIP().equalsIgnoreCase( computingClients.get( pos ).getClient().getIP() ) )
+ {
+ vmIPs.get( j ).setHostIP( "" ) ;
+ ok_new = true ;
+ }
if( vmIPs.get( j ).getHostIP().equalsIgnoreCase( ipDead ) )
{
String vmIP = vmIPs.get( j ).getVmIP() ;
vmIPs.get( j ).setHostIP( computingClients.get( pos ).getClient().getIP() ) ;
-
+ ok_old = true ;
+
try {
computingClients.get( pos ).getClient().getStub().setIPVM( vmIP ) ;
} catch( RemoteException e ) {
System.err.println( "Unable to set the new VM IP on the replacing client!" ) ;
e.printStackTrace() ;
}
- break ;
+
+ if( ok_new && ok_old )
+ {
+ break ;
+ }
}
}
+
+ // Replacing in RunningApplication
+ applications.get( 0 ).replaceComputingClient( cc, ccl ) ;
+
+ for( int l = 0 ; l < applications.get(0).getComputingClients().size() ; l++ )
+ {
+ applications.get(0).getComputingClients().get( l ).setSaveRequest( false ) ;
+ }
+
System.out.println( "Successful redeployment of the VM." ) ;
} else {
{
try {
computingClients.get( k ).getClient().getStub().
- replaceSavingNeighbor( ipDead, clients.get( i ).getStub() ) ;
+ replaceSaveNeighbor( snDead, new SaveNeighbor( 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!" ) ;
}
}
- for( int i = 0 ; i < computingClients.size() ; i++ )
+ for( int i = 0 ; i < applications.get(0).getComputingClients().size() ; i++ )
{
- final ServicesClient sc = computingClients.get( i ).getClient().getStub() ;
+ final ServicesClient sc = applications.get(0).getComputingClients().get( i ).getClient().getStub() ;
+
+ applications.get( 0 ).getComputingClients().get( i ).setRestartOk( false ) ;
new Thread( new Runnable() {
}
computingClients.get( i ).setSaveStatus( false ) ;
}
+
+ applications.get( 0 ).setLastSaveDate( System.currentTimeMillis() ) ;
}
return 0 ;
if( nb > _nb )
{
ArrayList<ServicesClient> ac = new ArrayList<ServicesClient>() ;
- ArrayList<ComputingClient> tmp = new ArrayList<Server.ComputingClient>() ;
+ ArrayList<ComputingClient> tmp = new ArrayList<ComputingClient>() ;
+
+ RunningApplication app = new RunningApplication( "Test" ) ;
int i = 0 ;
if( ac.size() == _nb )
{
+ app.setComputingClients( tmp ) ;
+ app.setRunning( true ) ;
+ app.setStartTime( System.currentTimeMillis() ) ;
+
int index, index2 ;
/* Choosing save neighbors */
for( i = 0 ; i < tmp.size() ; i++ )
{
System.err.println( "Problem in ComputingClients list!" ) ;
} else {
- computingClients.get( index ).setSaveNeighbor( computingClients.get( index2 ).getClient().getStub() ) ;
+ try {
+ computingClients.get( index ).setSaveNeighbor( new SaveNeighbor( computingClients.get( index2 ).getClient().getStub() )) ;
+ } catch( RemoteException e ) {
+ System.err.println( "Unable to create the save neighbor!" ) ;
+ e.printStackTrace() ;
+ }
}
} else {
index = computingClients.indexOf( tmp.get( i ) ) ;
{
System.err.println( "Problem in ComputingClients list!" ) ;
} else {
- computingClients.get( index ).setSaveNeighbor( computingClients.get( index2 ).getClient().getStub() ) ;
+ try {
+ computingClients.get( index ).setSaveNeighbor( new SaveNeighbor( computingClients.get( index2 ).getClient().getStub() ) ) ;
+ } catch( RemoteException e ) {
+ System.err.println( "Unable to create the save neighbor!" ) ;
+ e.printStackTrace() ;
+ }
}
}
}
}
- /* Cleaning */
- tmp.clear() ;
- tmp = null ;
+ applications.add( app ) ;
return ac ;
}
return null ;
}
+
+
+ @Override
+ public void requestSave( String _ip )
+ {
+ try {
+ semaSave.acquire() ;
+ } catch( InterruptedException e ) {
+ System.err.println( "Unable to obtain the semaphore for semaSave!" ) ;
+ e.printStackTrace() ;
+ }
+
+ final String ip = _ip ;
+
+ new Thread( new Runnable() {
+
+ @Override
+ public void run()
+ {
+ treatRequestSave( ip ) ;
+ }
+ } ).start() ;
+ }
-
+
+ public void treatRequestSave( String _ip )
+ {
+ if( applications.size() > 0 && _ip != null && _ip.length() > 0 )
+ {
+ if( (System.currentTimeMillis() - applications.get( 0 ).getLastSaveDate()) > save_interleave )
+ {
+ // Mark it as a requester
+ for( int i = 0 ; i < applications.get( 0 ).getComputingClients().size() ; i++ )
+ {
+ if( applications.get( 0 ).getComputingClients().get( i ).getClient().getIP().equalsIgnoreCase( _ip ) )
+ {
+ applications.get( 0 ).getComputingClients().get( i ).setSaveRequest( true ) ;
+
+ break ;
+ }
+ }
+
+ semaSave.release() ;
+
+ // Is every body ok?
+ boolean ok = false ;
+ for( int i = 0 ; i < applications.get( 0 ).getComputingClients().size() ; i++ )
+ {
+ if( i == 0 )
+ {
+ ok = applications.get( 0 ).getComputingClients().get( i ).getSaveRequest() ;
+ } else {
+ ok = ok & applications.get( 0 ).getComputingClients().get( i ).getSaveRequest() ;
+ }
+
+ if( ! ok )
+ {
+ break ;
+ }
+ }
+
+ if( ok )
+ {
+// try {
+// Thread.sleep( 5000 ) ;
+// } catch( InterruptedException e1 ) {
+// e1.printStackTrace() ;
+// }
+
+ for( int i = 0 ; i < applications.get( 0 ).getComputingClients().size() ; i++ )
+ {
+ try {
+ applications.get( 0 ).getComputingClients().get( i ).getClient().getStub().responseSave( true ) ;
+ applications.get( 0 ).getComputingClients().get( i ).setSaveRequest( false ) ;
+ } catch( RemoteException e ) {
+ System.err.println( "Unable to send the save request response to " +
+ applications.get( 0 ).getComputingClients().get( i ).getClient().getName() + "!" ) ;
+ e.printStackTrace() ;
+ }
+ }
+
+ applications.get( 0 ).setLastSaveDate( System.currentTimeMillis() ) ;
+ }
+
+ } else {
+ semaSave.release() ;
+
+ for( int i = 0 ; i < applications.get( 0 ).getComputingClients().size() ; i++ )
+ {
+ if( applications.get( 0 ).getComputingClients().get( i ).getClient().getIP().equalsIgnoreCase( _ip ) )
+ {
+ try {
+ applications.get( 0 ).getComputingClients().get( i ).getClient().getStub().responseSave( false ) ;
+ } catch( RemoteException e ) {
+ System.err.println( "Unable to send the save request response to " +
+ applications.get( 0 ).getComputingClients().get( i ).getClient().getName() + "!" ) ;
+ e.printStackTrace() ;
+ }
+ break ;
+ }
+ }
+ }
+ } else {
+ semaSave.release() ;
+ System.err.println( "!! Serious problem in treatRequestSave method!!" ) ;
+ }
+ }
+
+
+ @Override
+ public void restartOk( String _ip )
+ {
+ 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 )
+ {
+ // Has it already finished?
+ for( int i = 0 ; i < applications.get( 0 ).getComputingClients().size() ; i++ )
+ {
+ if( applications.get( 0 ).getComputingClients().get( i ).getClient().getIP().equalsIgnoreCase( _ip ) )
+ {
+ applications.get( 0 ).getComputingClients().get( i ).setRestartOk( true ) ;
+
+ break ;
+ }
+ }
+
+ // Is every body ok?
+ boolean ok = false ;
+ for( int i = 0 ; i < applications.get( 0 ).getComputingClients().size() ; i++ )
+ {
+ if( i == 0 )
+ {
+ ok = applications.get( 0 ).getComputingClients().get( i ).getRestartOk() ;
+ } else {
+ ok = ok & applications.get( 0 ).getComputingClients().get( i ).getRestartOk() ;
+ }
+
+ if( ! ok )
+ {
+ break ;
+ }
+ }
+
+ if( ok )
+ {
+ applications.get( 0 ).setLastSaveDate( System.currentTimeMillis() ) ;
+
+ for( int i = 0 ; i < applications.get( 0 ).getComputingClients().size() ; i++ )
+ {
+ applications.get( 0 ).getComputingClients().get( i ).setRestartOk( false ) ;
+ }
+ }
+
+ }
+ }
+ }
+
@Override
public void endApplication()
ComputingClient cl = it.next() ;
try {
- cl.getClient().getStub().stopVM() ;
+ cl.getClient().getStub().emergencyStop() ;
} catch (RemoteException e) {
e.printStackTrace();
}
cl = null ;
}
+ applications.get( 0 ).setEndTime( System.currentTimeMillis() ) ;
+ applications.get( 0 ).setRunning( false ) ;
+ applications.get( 0 ).clear() ;
+
}
{
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 )
+ if( clients.get( i ).getStatus().equalsIgnoreCase( "connected" ) )
{
- 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++ ;
+ 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() ;
}
- String[] command = new String[]{ "/usr/bin/scp", working_directory + "/" + _archive,
+ // 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 )
+ if( ! error )
{
- 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 )
+ Process proc = Runtime.getRuntime().exec( command ) ;
+ proc.waitFor() ;
+
+ if( proc.exitValue() == 0 )
{
- System.err.println( l ) ;
+ System.out.println( "Initial VM archive successfully sent." ) ;
+ } else {
+ System.err.println( "Initial VM archive not sent!" ) ;
+ 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 ) {
- e.printStackTrace() ;
+ System.err.println( "Error during initial VM archive send command: " ) ;
+ e.printStackTrace() ;
+ error = true ;
+ pb++ ;
+ } catch( InterruptedException e ) {
+ e.printStackTrace() ;
+ error = true ;
+ pb++ ;
}
-
- 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 ;
- }
+ 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++ ;
+ // 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( ret == 0 )
+ {
+ System.out.println( "Initial VM archive successfully deployed on " + clients.get( i ).getName() + "." ) ;
+ nb++ ;
+ }
}
}
}
if( pb == 1 )
System.err.println( "** " + pb + " machine is not deployed!" ) ;
if( pb > 1 )
- System.err.println( "** " + pb + " machine(s) are not deployed!" ) ;
+ System.err.println( "** " + pb + " machines are not deployed!" ) ;
}
return nb ;
public void saveOk() throws RemoteException ;
+ public void responseSave( boolean _b ) throws RemoteException ;
+
public Integer deployVM( String _name, String _archive, String _directory ) throws RemoteException ;
public void changeSaveName( String _n1, String _n2, int _id ) throws RemoteException ;
- public void setSavingNeighbor( ServicesClient _sn ) throws RemoteException ;
+ public void setSaveNeighbor( SaveNeighbor _sn ) throws RemoteException ;
- public void setSavingNeighbors( ArrayList<ServicesClient> _sn ) throws RemoteException ;
+ public void setSaveNeighbors( ArrayList<SaveNeighbor> _sn ) throws RemoteException ;
- public void addSavingNeighbor( ServicesClient _sn ) throws RemoteException ;
+ public void addSaveNeighbor( SaveNeighbor _sn ) throws RemoteException ;
- public void addSavingNeighbors( ArrayList<ServicesClient> _sn ) throws RemoteException ;
+ public void addSaveNeighbors( ArrayList<SaveNeighbor> _sn ) throws RemoteException ;
- public void replaceSavingNeighbor( String _old, ServicesClient _new ) throws RemoteException ;
+ public void replaceSaveNeighbor( SaveNeighbor _old, SaveNeighbor _new ) throws RemoteException ;
public int retrieveSave( String _saveName ) throws RemoteException ;
public void stop() throws RemoteException ;
+ public void requestSave( String _ip ) throws RemoteException ;
+
public Integer deployVM( String _name, String _archive, String _directory ) throws RemoteException ;
public String getWorkingDirectory() throws RemoteException ;
+ public void restartOk( String _ip ) throws RemoteException ;
}
import java.util.ArrayList;
public class VirtualMachine
-{
+{
private String name ;
private String ip ;
private String initial_archive_name ;
private Status status ;
private int computation_id ;
private String working_directory ;
- private ArrayList<ServicesClient> save_neighbors ;
+ private ArrayList<SaveNeighbor> save_neighbors ;
private String clientInVM ;
private String vm_user ;
private String vm_user_passwd ;
status = new Status() ;
status.setStatus( "stopped" ) ;
computation_id = -1 ;
- save_neighbors = new ArrayList<ServicesClient>() ;
+ save_neighbors = new ArrayList<SaveNeighbor>() ;
clientInVM = "/home/mpi/InGuest" ;
vm_user = "mpi" ;
vm_user_passwd = "mpi" ;
}
- public ArrayList<ServicesClient> getSaveNeighbors() { return save_neighbors ; }
+ public ArrayList<SaveNeighbor> getSaveNeighbors() { return save_neighbors ; }
@SuppressWarnings("unchecked")
- public void setSaveNeighbors( ArrayList<ServicesClient> _sn )
+ public void setSaveNeighbors( ArrayList<SaveNeighbor> _sn )
{
if( _sn != null )
{
- save_neighbors = (ArrayList<ServicesClient>) _sn.clone() ;
+ save_neighbors = (ArrayList<SaveNeighbor>) _sn.clone() ;
}
}
- public void addSaveNeighbor( ServicesClient _sn )
+ public void addSaveNeighbor( SaveNeighbor _sn )
{
if( _sn != null )
{
public int checkVmx()
{
+ deploy = false ;
+ first = false ;
+ deployFault = false ;
+
// Initial deployment
File file = new File( working_directory + "/" + directory + "/initial.hpcvm" ) ;
file = null ;
+ // If nothing to do
+ if( ! deploy && ! first && ! deployFault )
+ {
+ return 0 ;
+ }
+
// Deployment of the VM
if( deploy )
if( p.exitValue() == 0 )
{
- System.out.println( "Successfully deletion of the deployment mark." ) ;
+ System.out.println( "Successful deletion of the deployment mark." ) ;
} else {
System.err.println( "Unsuccessful deletion of the deployment mark!" ) ;
printProcessError( p ) ;
if( p.exitValue() == 0 )
{
- System.out.println( "Successfully deletion of the first start mark." ) ;
+ System.out.println( "Successful deletion of the first start mark." ) ;
} else {
System.err.println( "Unsuccessful deletion of the first start mark!" ) ;
printProcessError( p ) ;
if( p.exitValue() == 0 )
{
- System.out.println( "Successfully deletion of the fault mark." ) ;
+ System.out.println( "Successful deletion of the fault mark." ) ;
} else {
System.err.println( "Unsuccessful deletion of the fault mark!" ) ;
printProcessError( p ) ;