Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
e70bc43db1798444d4676d848432a3ff20918fe6
[hpcvm.git] / src / and / hpcvm / User.java
1 package and.hpcvm ;
2
3 import java.net.MalformedURLException;
4 import java.rmi.Naming;
5 import java.rmi.NotBoundException;
6 import java.rmi.RemoteException;
7 import java.util.ArrayList;
8
9
10 public class User 
11 {
12         private ServicesServer ss ;
13         
14         public User( String _serverIP, int _serverPort )
15         {
16                 System.out.println( "Connecting to server ..." ) ;
17                 /** Connection to server **/
18                 try {
19                         ss = (ServicesServer) Naming.lookup( "rmi://"
20                                         + _serverIP + ":" + _serverPort + "/Server" ) ;
21                 } catch( MalformedURLException e ) {
22                         e.printStackTrace() ;
23                 } catch( RemoteException e ) {
24                         e.printStackTrace() ;
25                 } catch( NotBoundException e ) {
26                         e.printStackTrace() ;
27                 }
28                 
29                 if( ss == null )
30                 {
31                         System.err.println( "Unable to connect to server!!" ) ;
32                         System.err.println( "Server IP: " + _serverIP + " -- server port: " + _serverPort ) ;
33                         
34                         System.exit( 1 ) ;
35                 }
36                 
37                 System.out.println( "Connected to server " + _serverIP + " on port " + _serverPort + "." ) ;
38         }
39         
40         public void reserveMachines( int _nb )
41         {
42                 ArrayList<ServicesClient> sc = null ;
43                 
44                 try {
45                         sc = ss.startApplication( _nb ) ;
46                 } catch( RemoteException e ) {
47                         System.err.println( "Unable to retrieve VMs!!" ) ;
48                         e.printStackTrace() ;
49                 }
50                 
51                 if( sc == null )
52                 {
53                         System.err.println( "There are not enough ressources!!" ) ;
54                         System.exit( 1 ) ;
55                 }
56                 
57                 System.out.println( "List of VMs: " ) ;
58                 for( int i = 0 ; i < sc.size() ; i++ )
59                 {
60                         try {
61                                 System.out.println( "  " + sc.get( i ).getName() + " (" + sc.get( i ).getIPVM() + ")" ) ;
62                         } catch( RemoteException e ) {
63                                 System.err.println( "Unable to retrieve VM informations!" ) ;
64                                 e.printStackTrace() ;
65                         }
66                 }
67         }
68         
69         
70         public void stopMachines() 
71         {
72                 try {
73                         ss.endApplication() ;
74                 } catch( RemoteException e ) {
75                         e.printStackTrace() ;
76                 }
77         }
78         
79         
80         public void stopAll()
81         {
82                 try {
83                         ss.stop() ;
84                 } catch (RemoteException e) {
85                         e.printStackTrace();
86                 }
87         }
88         
89 }
90
91
92 /** La programmation est un art, respectons ceux qui la pratiquent !! **/