001 /* 002 * GridCat.java 003 * 004 * Created on June 16, 2006, 2:12 PM 005 * 006 * This file is part of the STAR Scheduler. 007 * Copyright (c) 2002-2006 STAR Collaboration - Brookhaven National Laboratory 008 * 009 * STAR Scheduler is free software; you can redistribute it and/or modify 010 * it under the terms of the GNU General Public License as published by 011 * the Free Software Foundation; either version 2 of the License, or 012 * (at your option) any later version. 013 * 014 * STAR Scheduler is distributed in the hope that it will be useful, 015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 017 * GNU General Public License for more details. 018 * 019 * You should have received a copy of the GNU General Public License 020 * along with STAR Scheduler; if not, write to the Free Software 021 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 022 */ 023 024 package gov.bnl.star.offline.scheduler.informationService; 025 026 import org.apache.xmlrpc.*; 027 import java.util.Vector; 028 import java.util.Map; 029 import java.util.HashMap; 030 031 032 import java.util.logging.Level; 033 import org.apache.log4j.Logger; 034 035 /** 036 * This class is an information service that recovers data from gridcat via XmlRpc. 037 * @author Levente B. Hajdu 038 */ 039 public class GridCat implements gov.bnl.star.offline.scheduler.informationService.InformationService { 040 041 static private Logger log = Logger.getLogger(GridCat.class.getName()); 042 043 /** Creates a new instance of GridCat */ 044 public GridCat() { 045 } 046 047 048 049 String service = null; 050 /** sets the url to the service. Example: http://osg-cat.grid.iu.edu/services.php 051 * @param service A string holding the URL of the service **/ 052 public void setService(String service){ this.service = service; } 053 /**@return A string holding the URL of the service**/ 054 public String getService(){ return service; } 055 056 057 private String siteID = null; 058 /**@param siteID A string holding the gridcat site name for with the data will be recoved **/ 059 public void setSiteID(String siteID){this.siteID = siteID;} 060 /**@return A string holding the gridcat site name for with the data will be recoved **/ 061 public String getSiteID(){return siteID;} 062 063 064 // boolean useProxy = false; 065 // public void setUseProxy(boolean useProxy){this.useProxy = useProxy; } 066 // public boolean getUseProxy(){ return useProxy; } 067 // 068 // String proxyHost = null; 069 // public void setProxyHost(String proxyHost){ this.proxyHost = proxyHost; } 070 // public String getProxyHost(){return proxyHost;} 071 // 072 // String proxyPort = null; 073 // public void setProxyPort(String proxyPort){this.proxyPort = proxyPort;}; 074 // public String getProxyPort(){return proxyPort;} 075 076 077 private Map cache = new HashMap(); //Holds collected values, so all calls only have to be made on time. 078 private String makeKey(String a, String b, String c){return a + "-" + b + "-" + c;} 079 080 081 public String getSiteInfo(String site, String info){ 082 083 084 try { 085 086 String key = makeKey("site_info",site,info ); 087 if( cache.containsKey(key)){ 088 String cachedValue = (String) cache.get(key); 089 log.debug("Value \"" + key + "\" already in cache:" + cachedValue); 090 return cachedValue; //if the value is in cache, get it from cache 091 } 092 else{ 093 log.debug(">>>>>>>>>>>>>>> Value not in local cache: \"" + key ); 094 } 095 096 Vector params = new Vector (); 097 params.add("site_info"); 098 params.add(site); 099 params.add(info); 100 101 XmlRpcClient xmlrpc = new XmlRpcClient (service); 102 String output = (String) xmlrpc.execute ("getsiteresult", params); //This is the line that really makes the call to gridcat 103 if(output != null) output = output.replace('\n',' ').trim(); 104 cache.put(key, output); //cache this value just in case it is needed later 105 log.warn("GridCat returned value of : \"" + ((output != null) ? output : "null" ) + "\" for parms: " + key); 106 107 return output; 108 109 } catch (Exception ex){ //If there is an error print out information about the error and log it 110 String error = 111 "Could not get get back value from gridcat." + 112 "\n service : " + ((service != null) ? service : "null" ) + 113 "\n-------------------- params ---------------------" + 114 "\n p1: site_info" + 115 "\n p2 (site): " + ((site != null) ? site : "null" ) + 116 "\n p3 (info): " + ((info != null) ? info : "null" ) + 117 "\n------------------ proxy info -------------------" + 118 "\n proxySet : " + ((System.getProperties().getProperty("proxySet") != null) ? System.getProperties().getProperty("proxySet") : "null" ) + 119 "\n proxyHost : " + ((System.getProperties().getProperty("proxyPort") != null) ? System.getProperties().getProperty("proxyPort") : "null" ) + 120 "\n proxyPort : " + ((System.getProperties().getProperty("proxyHost") != null) ? System.getProperties().getProperty("proxyHost") : "null" ) + 121 "\n--------------------- error ---------------------\n" + 122 ex.getMessage(); 123 log.warn(error); 124 System.out.println(error); 125 } 126 127 return null; 128 129 } 130 131 132 public String getAppDir(){ return getSiteInfo("appdir", siteID); } 133 public String getDataDir(){ return getSiteInfo("datadir", siteID); } 134 public String getWNTmpDir(){ return getSiteInfo("wntmpdir", siteID); } 135 public String getGKGlobusDir(){ return getSiteInfo("grid3dir", siteID); } 136 public String getWNClient(){return "Not_available_via_grid_cat"; } 137 138 139 140 }