Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Changing save mechanism.
[hpcvm.git] / src / and / hpcvm / VirtualMachine.java
index 1d7075d..1cba1f1 100644 (file)
@@ -21,7 +21,7 @@ public class VirtualMachine
        private Status status ;
        private int computation_id ;
        private String working_directory ;
-       private ArrayList<String> save_neighbors ;
+       private ArrayList<ServicesClient> save_neighbors ;
        private String clientInVM ;
        private String vm_user ;
        private String vm_user_passwd ;
@@ -43,28 +43,27 @@ public class VirtualMachine
                status = new Status() ;
                status.setStatus( "stopped" ) ;
                computation_id  = -1 ;
-               save_neighbors = new ArrayList<String>() ;
-               save_neighbors.add( "127.0.0.1" ) ;
+               save_neighbors = new ArrayList<ServicesClient>() ;
                clientInVM = "/home/mpi/InGuest" ;
                vm_user = "mpi" ;
                vm_user_passwd = "mpi" ;
        }
        
        
-       public ArrayList<String> getSaveNeighbors() { return save_neighbors ; }
+       public ArrayList<ServicesClient> getSaveNeighbors() { return save_neighbors ; }
        
        @SuppressWarnings("unchecked")
-       public void setSaveNeighbors( ArrayList<String> _sn )
+       public void setSaveNeighbors( ArrayList<ServicesClient> _sn )
        {
                if( _sn != null ) 
                {
-                       save_neighbors = (ArrayList<String>) _sn.clone() ;
+                       save_neighbors = (ArrayList<ServicesClient>) _sn.clone() ;
                }
        }
        
-       public void addSaveNeighbor( String _sn )
+       public void addSaveNeighbor( ServicesClient _sn )
        {
-               if( _sn != null && _sn.length() > 0 )
+               if( _sn != null )
                {
                        save_neighbors.add( _sn ) ;
                }
@@ -200,6 +199,7 @@ public class VirtualMachine
        }
 
        public void setSave_last(String save_last) {
+               System.out.println( "Save name: " + save_last ) ;
                this.save_last = save_last;
        }
 
@@ -234,12 +234,48 @@ public class VirtualMachine
        
        public int deployLastSave()
        {
-               System.out.print( "Deploying the last save ..." ) ;
+               System.out.print( "Removing current VM ... " ) ;
                
-               String[] command = new String[] { "/bin/tar", "-xzvf", 
+               String[] command = new String[] { "/bin/rm", "-rf", 
+                               working_directory + "/" + directory } ;
+               Process pr = null ;
+               try {
+                       pr = Runtime.getRuntime().exec( command ) ;
+//                     synchronized( pr ){
+                       pr.waitFor() ; //;}
+               } catch( IOException e ) {
+                       System.err.println( "Error while removing current VM!" ) ;
+                       e.printStackTrace() ;
+                       return 1 ;
+               } catch( InterruptedException e ) {
+                       e.printStackTrace() ;
+                       return 1 ;
+               }
+               
+               if( pr.exitValue() == 0 )
+               {
+                       System.out.println( "Successful deletion of current VM." ) ;
+               } else {
+                       System.err.println( "Error: " + pr.exitValue() ) ;
+                       BufferedReader b = new BufferedReader( new InputStreamReader( pr.getErrorStream() ) ) ;
+                       
+                       String l ;
+                       try {
+                               while( (l = b.readLine()) != null )
+                               {
+                                       System.err.println( l ) ;
+                               }
+                       } catch( IOException e ) {
+                                       e.printStackTrace() ;
+                       }
+               }
+               
+               System.out.print( "Deploying the last save ... " ) ;
+               
+               command = new String[] { "/bin/tar", "-xzf", 
                                working_directory + "/" + save_last,
                                "-C", working_directory } ;
-               Process pr = null ;
+               pr = null ;
                try {
                        pr = Runtime.getRuntime().exec( command ) ;
 //                     synchronized( pr ){
@@ -247,10 +283,13 @@ public class VirtualMachine
                } catch( IOException e ) {
                        System.err.println( "Error while deploying the last secure save!" ) ;
                        e.printStackTrace() ;
+                       return 1 ;
                } catch( InterruptedException e ) {
                        e.printStackTrace() ;
+                       return 1 ;
                }
                        
+               
                if( pr.exitValue() == 0 )
                {
                        System.out.println( "Successful extraction of the save archive." ) ;