Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Refunding the restart/redeployment mechanisms.
[hpcvm.git] / src / and / hpcvm / VirtualMachine.java
1 package and.hpcvm ;
2
3 import java.io.BufferedReader;
4 import java.io.File;
5 import java.io.FileNotFoundException;
6 import java.io.FileReader;
7 import java.io.FileWriter;
8 import java.io.IOException;
9 import java.io.InputStreamReader;
10 import java.util.ArrayList;
11
12 public class VirtualMachine 
13 {
14         private String name ;
15         private String ip ;
16         private String initial_archive_name ;
17         private String directory ;
18         private String vmx_name ;
19         private String vmx_name_first ;
20         private String vmx_name_initial ;
21         private String save_current ;
22         private String save_last ;
23         private int no_save ;
24         private int no_save_last ;
25         private Status status ;
26         private int computation_id ;
27         private String working_directory ;
28         private ArrayList<ServicesClient> save_neighbors ;
29         private String clientInVM ;
30         private String vm_user ;
31         private String vm_user_passwd ;
32         private boolean deploy ;
33         private boolean first ;
34         private boolean deployFault ;
35         
36         public VirtualMachine()
37         {
38                 name = "VmTest" ;
39                 ip = "127.0.0.1" ;
40                 initial_archive_name = "VmTest.tgz" ;
41                 directory = "VmTest" ;
42                 vmx_name = "VmTest.vmx" ;
43                 vmx_name_first = "VmTest.vmx.first" ;
44                 vmx_name_initial = "VmTest.vmx.initial" ;
45                 save_current = "VmTest.tgz" ;
46                 save_last = "VmTest.tgz" ;
47                 working_directory = "/localhome/vmware" ;
48                 no_save = 0 ;
49                 no_save_last = 0 ;
50                 status = new Status() ;
51                 status.setStatus( "stopped" ) ;
52                 computation_id  = -1 ;
53                 save_neighbors = new ArrayList<ServicesClient>() ;
54                 clientInVM = "/home/mpi/InGuest" ;
55                 vm_user = "mpi" ;
56                 vm_user_passwd = "mpi" ;
57                 first = false ;
58                 deploy = false ;
59                 deployFault = false ;
60         }
61         
62         
63         public void setDeployFault( boolean _bool )
64         {
65                 deployFault = _bool ;
66         }
67         
68         
69         public ArrayList<ServicesClient> getSaveNeighbors() { return save_neighbors ; }
70         
71         @SuppressWarnings("unchecked")
72         public void setSaveNeighbors( ArrayList<ServicesClient> _sn )
73         {
74                 if( _sn != null ) 
75                 {
76                         save_neighbors = (ArrayList<ServicesClient>) _sn.clone() ;
77                 }
78         }
79         
80         public void addSaveNeighbor( ServicesClient _sn )
81         {
82                 if( _sn != null )
83                 {
84                         save_neighbors.add( _sn ) ;
85                 }
86         }
87         
88         
89         public String getVmUser()
90         {
91                 return vm_user ;
92         }
93         
94         
95         public void setVmUser( String _user )
96         {
97                 vm_user = _user ;
98         }
99         
100         
101         public String getVmUserPasswd()
102         {
103                 return vm_user_passwd ;
104         }
105         
106         
107         public void setVmUserPasswd( String _user_passwd )
108         {
109                 vm_user_passwd = _user_passwd ;
110         }
111         
112         
113         public String getClientInVM()
114         {
115                 return clientInVM ;
116         }
117         
118         
119         public void setClientInVM( String _civ )
120         {
121                 clientInVM = _civ ;
122         }
123         
124         
125         public String getStatus()
126         {
127                 return status.getStatus() ;
128         }
129         
130         
131         public void setStatus( String _status )
132         {
133                 status.setStatus( _status ) ;
134         }
135         
136         
137         public String getWorkingDirectory()
138         {
139                 return working_directory ;
140         }
141         
142         
143         public void setWorkingDirectory( String _wd )
144         {
145                 working_directory = _wd ;
146         }
147
148         public String getName() {
149                 return name;
150         }
151
152         
153         public void setName(String name) {
154                 this.name = name;
155         }
156
157         public String getIp() {
158                 return ip;
159         }
160
161         public void setIp(String ip) {
162                 this.ip = ip;
163         }
164
165         public String getInitial_archive_name() {
166                 return initial_archive_name;
167         }
168
169         public void setInitial_archive_name(String initial_archive_name) {
170                 this.initial_archive_name = initial_archive_name;
171         }
172
173         public String getDirectory() {
174                 return directory;
175         }
176
177         public void setDirectory(String directory) {
178                 this.directory = directory;
179         }
180
181         public String getVmx_name() {
182                 return vmx_name;
183         }
184
185         public void setVmx_name(String vmx_name) {
186                 this.vmx_name = vmx_name;
187         }
188
189 //      public String getVmx_name_normal() {
190 //              return vmx_name_normal;
191 //      }
192
193 //      public void setVmx_name_normal(String vmx_name_normal) {
194 //              this.vmx_name_normal = vmx_name_normal;
195 //      }
196
197 //      public String getVmx_name_crash() {
198 //              return vmx_name_crash;
199 //      }
200
201 //      public void setVmx_name_crash(String vmx_name_crash) {
202 //              this.vmx_name_crash = vmx_name_crash;
203 //      }
204
205         public String getSave_current() {
206                 return save_current;
207         }
208
209         public void setSave_current(String save_current) {
210                 this.save_current = save_current;
211         }
212
213         public String getSave_last() {
214                 return save_last;
215         }
216
217         public void setSave_last(String save_last) {
218                 System.out.println( "Save name: " + save_last ) ;
219                 this.save_last = save_last;
220         }
221
222         public int getNo_save() 
223         {
224                 return no_save ;
225         }
226
227         public void setNo_save( int no_save ) 
228         {
229                 this.no_save = no_save ;
230         }
231
232         public int getNo_save_last() 
233         {
234                 return no_save_last ;
235         }
236
237         public void setNo_save_last( int no_save_last ) 
238         {
239                 this.no_save_last = no_save_last ;
240         }
241         
242         public int getComputationId() { return computation_id ; }
243         
244         
245         public void setComputationId( int _id )
246         {
247                 computation_id = _id ;
248         }
249         
250         
251         public int deployLastSave()
252         {
253                 System.out.print( "Removing current VM ... " ) ;
254                 
255                 String[] command = new String[] { "/bin/rm", "-rf", 
256                                 working_directory + "/" + directory } ;
257                 Process pr = null ;
258                 try {
259                         pr = Runtime.getRuntime().exec( command ) ;
260 //                      synchronized( pr ){
261                         pr.waitFor() ; //;}
262                 } catch( IOException e ) {
263                         System.err.println( "Error while removing current VM!" ) ;
264                         e.printStackTrace() ;
265                         return 1 ;
266                 } catch( InterruptedException e ) {
267                         e.printStackTrace() ;
268                         return 1 ;
269                 }
270                 
271                 if( pr.exitValue() == 0 )
272                 {
273                         System.out.println( "Successful deletion of current VM." ) ;
274                 } else {
275                         System.err.println( "Unssuccessful deletion of current VM!" ) ;
276                         printProcessError( pr ) ;
277                 }
278                 
279                 System.out.print( "Deploying the last save ... " ) ;
280                 
281                 command = new String[] { "/bin/tar", "-xzf", 
282                                 working_directory + "/" + save_last,
283                                 "-C", working_directory } ;
284                 pr = null ;
285                 try {
286                         pr = Runtime.getRuntime().exec( command ) ;
287 //                      synchronized( pr ){
288                         pr.waitFor() ; //;}
289                 } catch( IOException e ) {
290                         System.err.println( "Error while deploying the last secure save!" ) ;
291                         e.printStackTrace() ;
292                         return 1 ;
293                 } catch( InterruptedException e ) {
294                         e.printStackTrace() ;
295                         return 1 ;
296                 }
297                         
298                 
299                 if( pr.exitValue() == 0 )
300                 {
301                         System.out.println( "Successful extraction of the save archive." ) ;
302                         return 0 ;
303                 } else {
304                         System.err.println( "unSuccessful extraction of the save archive!" ) ;
305                         printProcessError( pr ) ;
306                 }
307                 
308                 return 1 ;
309         }
310         
311         
312         public int deployInitialVM()
313         {
314                 System.out.print( "Removing current VM ... " ) ;
315                 
316                 String[] command = new String[] { "/bin/rm", "-rf", 
317                                 working_directory + "/" + directory } ;
318                 Process pr = null ;
319                 try {
320                         pr = Runtime.getRuntime().exec( command ) ;
321 //                      synchronized( pr ){
322                         pr.waitFor() ; //;}
323                 } catch( IOException e ) {
324                         System.err.println( "Error while removing current VM!" ) ;
325                         e.printStackTrace() ;
326                         return 1 ;
327                 } catch( InterruptedException e ) {
328                         e.printStackTrace() ;
329                         return 1 ;
330                 }
331                 
332                 if( pr.exitValue() == 0 )
333                 {
334                         System.out.println( "Successful deletion of current VM." ) ;
335                 } else {
336                         System.err.println( "Unsuccessful deletion of current VM!" ) ;
337                         printProcessError( pr ) ;
338                 }
339                 
340                 System.out.print( "Deploying the initial archive ... " ) ;
341                 
342                 command = new String[] { "/bin/tar", "-xzf", 
343                                 working_directory + "/" + save_last,
344                                 "-C", working_directory } ;
345                 pr = null ;
346                 try {
347                         pr = Runtime.getRuntime().exec( command ) ;
348 //                      synchronized( pr ){
349                         pr.waitFor() ; //;}
350                 } catch( IOException e ) {
351                         System.err.println( "Error while deploying the initial archive!" ) ;
352                         e.printStackTrace() ;
353                         return 1 ;
354                 } catch( InterruptedException e ) {
355                         e.printStackTrace() ;
356                         return 1 ;
357                 }
358                         
359                 
360                 if( pr.exitValue() == 0 )
361                 {
362                         System.out.println( "Successful extraction of the initial archive." ) ;
363                         deploy = true ;
364                 } else {
365                         System.err.println( "Unsuccessful extraction of the initial archive!" ) ;
366                         printProcessError( pr ) ;
367                         return 1 ;
368                 }
369                 
370                 try {
371                         FileWriter fw = new FileWriter( new File( working_directory + "/" + directory + "/initial.hpcvm" ) ) ;
372                         fw.write( "initial!" ) ;
373                         fw.flush() ;
374                         fw.close() ;
375                         fw = null ;
376                         return 0 ;
377                 } catch( IOException e1 ) {
378                         e1.printStackTrace() ;
379                         System.err.println( "Unable to mark the initial deployment!" ) ;
380                 }
381                 
382                 return 1 ;
383         }
384
385
386         public int checkVmx() 
387         {
388                 // Initial deployment
389                 File file = new File( working_directory + "/" + directory + "/initial.hpcvm" ) ;
390                 
391                 if( file.exists() )
392                 {
393                         deploy = true ;
394                 }
395                 
396                 // First execution
397                 file = null ;
398                 file = new File( working_directory + "/" + directory + "/first.hpcvm" ) ;
399                 
400                 if( file.exists() )
401                 {
402                         first = true ;
403                 }
404                 
405                 // Redeployment after a fault
406                 file = null ;
407                 file = new File( working_directory + "/" + directory + "/fault.hpcvm" ) ;
408                 
409                 if( file.exists() )
410                 {
411                         deploy = false ;
412                         first = false ;
413                         deployFault = true ;
414                 }
415                 
416                 file = null ;
417                 
418                 // Deployment of the VM
419                 
420                 if( deploy )
421                 {
422                         System.out.print( "Saving the initial VMX file ... " ) ;
423                         
424                         String[] command = new String[]{ "/bin/cp", 
425                                         working_directory + "/" + directory + "/" + vmx_name,
426                                         working_directory + "/" + directory + "/" + vmx_name_initial } ;
427                         
428                         try {
429                                 Process p = Runtime.getRuntime().exec( command ) ;
430                                 p.waitFor() ;
431                 
432                                 if( p.exitValue() == 0 )
433                                 {
434                                         System.out.println( "Successfully saved initial the VMX file." ) ;
435                                 } else {
436                                         System.err.println( "Unsuccessful save of the initial VMX file!" ) ;
437                                         printProcessError( p ) ;
438                                         return 1 ;
439                                 }
440                         } catch( IOException e ) {
441                                 System.err.println( "Error during initial VMX file save: " ) ;
442                                 e.printStackTrace() ;
443                                 return 1 ;
444                         } catch( InterruptedException e ) {
445                                 e.printStackTrace() ;
446                                 return 1 ;
447                         }
448                         
449                         System.out.print( "Rewritting WMX file ... " ) ;
450                         
451                         
452                         FileReader fin = null ;
453                         try {
454                                 fin = new FileReader( new File( working_directory + "/" + directory + "/" + vmx_name_initial ) );
455                         } catch( FileNotFoundException e ) {
456                                 System.err.println( "Unable to open the initial VMX file!" ) ;
457                                 e.printStackTrace() ;
458                                 return 1 ;
459                         }
460                                 
461                         BufferedReader bin = new BufferedReader( fin ) ;
462                         String line = "" ;
463                         FileWriter fout = null ;
464                         
465                         try {
466                                 fout = new FileWriter( new File( working_directory + "/" + directory + "/" + vmx_name ) ) ;
467                         } catch( IOException e ) {
468                                 System.err.println( "Unable to open the VMX file!" ) ;
469                                 e.printStackTrace() ;
470                                 return 1 ;
471                         }
472                                 
473                         // Keeping only some information
474                         // -- this force VmWare to generate new identifiers and MAC address
475                         while( line != null )
476                         {               
477                                 try {
478                                         line = bin.readLine() ;
479                                         if( line != null )
480                                         if(    ! line.contains( "ethernet0.addressType" ) 
481                                             && ! line.contains( "uuid.location " ) 
482                                             && ! line.contains( "uuid.bios " ) 
483                                             && ! line.contains( "ethernet0.generatedAddress " ) 
484                                             && ! line.contains( "ethernet0.generatedAddressOffset " ) 
485                                           )
486                                         {
487                                                 fout.write( line + "\n" ) ;
488                                         }
489                                 } catch( IOException e ) {}
490                         }
491                                 
492                         try {
493                                 bin.close() ;
494                         } catch (IOException e) {
495                                 System.err.println( "Unable to close the initial VMX file!" ) ;
496                                 e.printStackTrace() ;
497                         }
498                                 
499                         // Adding the copy information
500                         try
501                         {
502                                 fout.write( "msg.autoAnswer = \"TRUE\"\n" ) ;
503                                 fout.write( "answer.msg.checkpoint.cpufeaturecheck.fail = \"_Yes\"\n" ) ;
504                                 fout.write( "checkpoint.vmState = \"\"\n" ) ;
505                                 fout.write( "answer.msg.uuid.altered = \"I _copied it\"\n" ) ;
506                         } catch( IOException e ) {
507                                 System.err.println( "Unable to add infortion to VMX file!" ) ;
508                                 e.printStackTrace() ;
509                                 return 1 ;
510                         }
511                                 
512                         try {
513                                 fout.close() ;
514                         } catch( IOException e ) {
515                                 System.err.println( "Unable to close the VMX file!" ) ;
516                                 e.printStackTrace() ;
517                                 return 1 ;
518                         }
519                         
520                         System.out.println( "Successful rewrite of the VMX file." ) ;
521                         
522                         // Removing the initial mark
523                         System.out.print( "Removing the deployment mark ... " ) ;
524                         
525                         command = new String[]{ "/bin/rm", 
526                                         working_directory + "/" + directory + "/initial.hpcvm" } ;
527                         
528                         try {
529                                 Process p = Runtime.getRuntime().exec( command ) ;
530                                 p.waitFor() ;
531                 
532                                 if( p.exitValue() == 0 )
533                                 {
534                                         System.out.println( "Successfully deletion of the deployment mark." ) ;
535                                 } else {
536                                         System.err.println( "Unsuccessful deletion of the deployment mark!" ) ;
537                                         printProcessError( p ) ;
538                                         return 1 ;
539                                 }
540                         } catch( IOException e ) {
541                                 System.err.println( "Error during deletion of the deployment mark: " ) ;
542                                 e.printStackTrace() ;
543                                 return 1 ;
544                         } catch( InterruptedException e ) {
545                                 e.printStackTrace() ;
546                                 return 1 ;
547                         }
548                         
549                         deploy = false ;
550                         
551                         // Writing the first start mark
552                         try {
553                                 FileWriter fw = new FileWriter( new File( working_directory + "/" + directory + "/first.hpcvm" ) ) ;
554                                 fw.write( "first!\n" ) ;
555                                 fw.flush() ;
556                                 fw.close() ;
557                                 fw = null ;
558                                 return 0 ;
559                         } catch( IOException e1 ) {
560                                 e1.printStackTrace() ;
561                                 System.err.println( "Unable to mark the first run of the VM!" ) ;
562                         }       
563                 }
564                 
565                 
566                 // First start of the VM
567                 
568                 if( first )
569                 {
570                         System.out.print( "Saving the first start VMX file ... " ) ;
571                         
572                         String[] command = new String[]{ "/bin/cp", 
573                                         working_directory + "/" + directory + "/" + vmx_name,
574                                         working_directory + "/" + directory + "/" + vmx_name_first } ;
575                         
576                         try {
577                                 Process p = Runtime.getRuntime().exec( command ) ;
578                                 p.waitFor() ;
579                 
580                                 if( p.exitValue() == 0 )
581                                 {
582                                         System.out.println( "Successfully saved the first start VMX file." ) ;
583                                 } else {
584                                         System.err.println( "Unsuccessful save of the first start VMX file!" ) ;
585                                         printProcessError( p ) ;
586                                         return 1 ;
587                                 }
588                         } catch( IOException e ) {
589                                 System.err.println( "Error during first start VMX file save: " ) ;
590                                 e.printStackTrace() ;
591                                 return 1 ;
592                         } catch( InterruptedException e ) {
593                                 e.printStackTrace() ;
594                                 return 1 ;
595                         }
596                         
597                         System.out.print( "Rewritting WMX file ... " ) ;
598                         
599                         
600                         FileReader fin = null ;
601                         try {
602                                 fin = new FileReader( new File( working_directory + "/" + directory + "/" + vmx_name_first ) );
603                         } catch( FileNotFoundException e ) {
604                                 System.err.println( "Unable to open the first start VMX file!" ) ;
605                                 e.printStackTrace() ;
606                                 return 1 ;
607                         }
608                                 
609                         BufferedReader bin = new BufferedReader( fin ) ;
610                         String line = "" ;
611                         FileWriter fout = null ;
612                         
613                         try {
614                                 fout = new FileWriter( new File( working_directory + "/" + directory + "/" + vmx_name ) ) ;
615                         } catch( IOException e ) {
616                                 System.err.println( "Unable to open the VMX file!" ) ;
617                                 e.printStackTrace() ;
618                                 return 1 ;
619                         }
620                                 
621                         // Keeping all information
622                         // -- except copy information
623                         while( line != null )
624                         {               
625                                 try {
626                                         line = bin.readLine() ;
627                                         if( line != null )
628                                         if( ! line.contains( "answer.msg.uuid.altered " ) )
629                                         {
630                                                 fout.write( line + "\n" ) ;
631                                         }
632                                 } catch( IOException e ) {}
633                         }
634                                 
635                         try {
636                                 bin.close() ;
637                         } catch (IOException e) {
638                                 System.err.println( "Unable to close the first start VMX file!" ) ;
639                                 e.printStackTrace() ;
640                         }
641                                 
642                         try {
643                                 fout.close() ;
644                         } catch( IOException e ) {
645                                 System.err.println( "Unable to close the VMX file!" ) ;
646                                 e.printStackTrace() ;
647                                 return 1 ;
648                         }
649                         
650                         System.out.println( "Successful rewrite of the VMX file." ) ;
651                         
652                         // Removing the initial mark
653                         System.out.print( "Removing the first start mark ... " ) ;
654                         
655                         command = new String[]{ "/bin/rm", 
656                                         working_directory + "/" + directory + "/first.hpcvm" } ;
657                         
658                         try {
659                                 Process p = Runtime.getRuntime().exec( command ) ;
660                                 p.waitFor() ;
661                 
662                                 if( p.exitValue() == 0 )
663                                 {
664                                         System.out.println( "Successfully deletion of the first start mark." ) ;
665                                 } else {
666                                         System.err.println( "Unsuccessful deletion of the first start mark!" ) ;
667                                         printProcessError( p ) ;
668                                         return 1 ;
669                                 }
670                         } catch( IOException e ) {
671                                 System.err.println( "Error during deletion of the first start mark: " ) ;
672                                 e.printStackTrace() ;
673                                 return 1 ;
674                         } catch( InterruptedException e ) {
675                                 e.printStackTrace() ;
676                                 return 1 ;
677                         }
678                         
679                         first = false ;
680
681                         return 0 ;
682                 }
683                 
684                 
685                 // Redeployment after a fault of a VM
686                 
687                 if( deployFault )
688                 {
689                         System.out.print( "Saving the original VMX file ... " ) ;
690                         
691                         String[] command = new String[]{ "/bin/cp", 
692                                         working_directory + "/" + directory + "/" + vmx_name,
693                                         working_directory + "/" + directory + "/" + vmx_name_first } ;
694                         
695                         try {
696                                 Process p = Runtime.getRuntime().exec( command ) ;
697                                 p.waitFor() ;
698                 
699                                 if( p.exitValue() == 0 )
700                                 {
701                                         System.out.println( "Successfully saved the original VMX file." ) ;
702                                 } else {
703                                         System.err.println( "Unsuccessful save of the original VMX file!" ) ;
704                                         printProcessError( p ) ;
705                                         return 1 ;
706                                 }
707                         } catch( IOException e ) {
708                                 System.err.println( "Error during original VMX file save: " ) ;
709                                 e.printStackTrace() ;
710                                 return 1 ;
711                         } catch( InterruptedException e ) {
712                                 e.printStackTrace() ;
713                                 return 1 ;
714                         }
715                         
716                         System.out.print( "Rewritting WMX file ... " ) ;
717                         
718                         
719                         FileReader fin = null ;
720                         try {
721                                 fin = new FileReader( new File( working_directory + "/" + directory + "/" + vmx_name_first ) );
722                         } catch( FileNotFoundException e ) {
723                                 System.err.println( "Unable to open the original VMX file!" ) ;
724                                 e.printStackTrace() ;
725                                 return 1 ;
726                         }
727                                 
728                         BufferedReader bin = new BufferedReader( fin ) ;
729                         String line = "" ;
730                         FileWriter fout = null ;
731                         
732                         try {
733                                 fout = new FileWriter( new File( working_directory + "/" + directory + "/" + vmx_name ) ) ;
734                         } catch( IOException e ) {
735                                 System.err.println( "Unable to open the VMX file!" ) ;
736                                 e.printStackTrace() ;
737                                 return 1 ;
738                         }
739                                 
740                         // Keeping all information
741                         while( line != null )
742                         {               
743                                 try {
744                                         line = bin.readLine() ;
745                                         if( line != null )
746                                         if( ! line.contains( "answer.msg.uuid.altered " ) )
747                                         {
748                                                 fout.write( line + "\n" ) ;
749                                         }
750                                 } catch( IOException e ) {}
751                         }
752                                 
753                         try {
754                                 bin.close() ;
755                         } catch (IOException e) {
756                                 System.err.println( "Unable to close the original VMX file!" ) ;
757                                 e.printStackTrace() ;
758                         }
759                         
760                         // Writing information to indicate that the VM has been moved
761                         try {
762                                 fout.write( "answer.msg.uuid.altered = \"I _moved it\"\n" ) ;
763                         } catch (IOException e1) {
764                                 System.err.println( "Unable to indicate that the VM has been moved in the VMX file!" ) ;
765                                 e1.printStackTrace() ;
766                         }
767                                 
768                         try {
769                                 fout.close() ;
770                         } catch( IOException e ) {
771                                 System.err.println( "Unable to close the VMX file!" ) ;
772                                 e.printStackTrace() ;
773                                 return 1 ;
774                         }
775                         
776                         System.out.println( "Successful rewrite of the VMX file." ) ;
777                         
778                         // Removing lock files
779                         System.out.print( "Removing lock files ... " ) ;
780                 
781                         command = new String[]{ "/bin/rm", "-rf", 
782                                 working_directory + "/" + directory 
783                                 + "/" + vmx_name + ".lck" } ;
784                         
785                         try {
786                                 Process p = Runtime.getRuntime().exec( command ) ;
787                                 p.waitFor() ;
788                 
789                                 if( p.exitValue() == 0 )
790                                 {
791                                         System.out.println( "Successfully deleted lock files." ) ;
792                                 } else {
793                                         System.err.println( "Unsuccessful deletion of lock files!" ) ;
794 //                                      printProcessError( p.getErrorStream() ) ;
795                                         printProcessError( p ) ;
796                                         
797                                         return 1 ;
798                                 }
799                         } catch( IOException e ) {
800                                 System.err.println( "Error during lock files deletion: " ) ;
801                                 e.printStackTrace() ;
802                                 return 1 ;
803                         } catch( InterruptedException e ) {
804                                 e.printStackTrace() ;
805                                 return 1 ;
806                         }
807                         
808                         // Removing the initial mark
809                         System.out.print( "Removing the fault mark ... " ) ;
810                         
811                         command = new String[]{ "/bin/rm", 
812                                         working_directory + "/" + directory + "/fault.hpcvm" } ;
813                         
814                         try {
815                                 Process p = Runtime.getRuntime().exec( command ) ;
816                                 p.waitFor() ;
817                 
818                                 if( p.exitValue() == 0 )
819                                 {
820                                         System.out.println( "Successfully deletion of the fault mark." ) ;
821                                 } else {
822                                         System.err.println( "Unsuccessful deletion of the fault mark!" ) ;
823                                         printProcessError( p ) ;
824                                         return 1 ;
825                                 }
826                         } catch( IOException e ) {
827                                 System.err.println( "Error during deletion of the fault mark: " ) ;
828                                 e.printStackTrace() ;
829                                 return 1 ;
830                         } catch( InterruptedException e ) {
831                                 e.printStackTrace() ;
832                                 return 1 ;
833                         }
834                         
835                         deployFault = false ;
836                         
837                         // Writing the first start mark
838                         try {
839                                 FileWriter fw = new FileWriter( new File( working_directory + "/" + directory + "/first.hpcvm" ) ) ;
840                                 fw.write( "first!" ) ;
841                                 fw.flush() ;
842                                 fw.close() ;
843                                 fw = null ;
844                                 first = true ;
845                                 return 0 ;
846                         } catch( IOException e1 ) {
847                                 e1.printStackTrace() ;
848                                 System.err.println( "Unable to mark the first run of the VM!" ) ;
849                         }       
850                 }               
851                 
852                 return 1 ;
853         }
854         
855         
856         private void printProcessError( Process _p )
857         {
858                 if( _p != null )
859                 {
860                         System.err.println( "Error: " + _p.exitValue() ) ;
861                         BufferedReader br = new BufferedReader( new InputStreamReader( _p.getErrorStream() ) ) ;
862                         String line ;
863                         try {
864                                 while( (line = br.readLine()) != null )
865                                 {
866                                         System.err.println( line ) ;
867                                 }
868                         } catch( IOException e ) {
869                                 e.printStackTrace() ;
870                         }
871                 }
872         }
873
874         
875 }
876
877 /** La programmation est un art, respectons ceux qui la pratiquent !! **/