001    /*
002     * GridCat.java
003     *
004     * Created on January 12, 2006, 2:18 PM
005     */
006    
007    package gov.bnl.star.offline.scheduler;
008    
009    
010    import org.apache.xmlrpc.*;
011    import java.util.Vector;
012    
013    import java.util.logging.Level;
014    import org.apache.log4j.Logger;
015    
016    /** @deprecated Replaced by information service base classes.
017     *  @author  Levente Hajdu
018     */
019    public class GridCat {
020        
021        static private Logger log = Logger.getLogger(GridCat.class.getName());
022        
023        /** Creates a new instance of GridCat */
024        public GridCat() { }
025        
026        //The default setting if no other settings are configured
027        private static String proxyPort = "3128";
028        private static String proxyHost = "192.168.1.4";
029        private static String service = "http://osg-cat.grid.iu.edu/services.php";
030        private static boolean useProxy = true;
031        private static String SiteName = "none";
032        
033        
034        public static void setSiteName(String SiteName){ GridCat.SiteName = SiteName; }
035        public static String getSiteName(){return SiteName;}
036        
037    
038        public static String testfunc(String x){ return x + "blabla  ~~~"; };
039       // public String testfunc(String x){ return x + "blabla  ~~~"; };
040        
041    
042        /**
043         * @param args the command line arguments
044         */
045        public static void main(String[] args) {
046            
047        }
048       
049        
050          public static  String getAppDir(){ return getSiteInfo(SiteName, "appdir"); }
051          public static  String getDataDir(){ return getSiteInfo(SiteName, "datadir"); }
052          public static  String getWNTmpDir(){ return getSiteInfo(SiteName, "wntmpdir"); }
053        
054        
055        
056        /**    */
057        public  static   String getSiteInfo(String site, String info){ 
058         
059            Vector params = new Vector ();
060            params.add("site_info");
061            params.add(info);
062            params.add(site);
063            String appdir = callGridCat(params);
064            
065            if(appdir == null){
066                log.warn("Gidcat failed in recover the " + info + " for the site " + site );
067                appdir = "Could_not_get_value_from_GridCat"; 
068            }
069            
070            return appdir.replace('\n', ' ').trim();
071           
072        }
073        
074        
075       
076        /**Used to make the call over the network to gridcat*/
077        private  static  String callGridCat(Vector params){ 
078            
079            
080                if(useProxy){
081                    System.getProperties().put("proxySet","true");
082                    System.getProperties().put("proxyPort", proxyPort );
083                    System.getProperties().put("proxyHost", proxyHost );
084                }
085    
086            try {
087                
088                //This is the line that really makes the call to gridcat
089                XmlRpcClient xmlrpc = new XmlRpcClient (service);
090                return (String) xmlrpc.execute ("getsiteresult", params); 
091                
092            } catch (Exception ex){ 
093                log.warn(ex.getMessage());
094                return null; 
095            }
096            
097      
098       }
099        
100        
101        
102        
103    }