001    /*
002     * site.java
003     *
004     * Created on July 8, 2005, 1:42 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     */
025    
026    package gov.bnl.star.offline.scheduler;
027    
028    import java.util.List;
029    import java.util.ArrayList;
030    import java.util.Map;
031    
032    
033    import gov.bnl.star.offline.scheduler.BatchSystem;
034    import gov.bnl.star.offline.scheduler.Policy;
035    import gov.bnl.star.offline.scheduler.informationService.InformationService;
036    import gov.bnl.star.offline.scheduler.informationService.Proxy;
037    
038    
039    import gov.bnl.star.offline.scheduler.GateKeeperAccessPoint;
040    import gov.bnl.star.offline.scheduler.LocalAccessPoint;
041    
042    
043    /**
044     * This class defines a site used in the config. It holds a cluster list and gateway list as well as other site specific objects.
045     * @author  Levente Hajdu
046     */
047    public class Site {
048        
049        /** Creates a new instance of site */
050        public Site() {}
051        
052        
053        private String siteName;
054        private String canonicalName;
055        private List batchSystems = new ArrayList(); 
056        private List fileTransferGatekeepers = new ArrayList();
057        
058        
059        /**Returns the domain name of the site. Examples: nersc.gov, rcf.bnl.gov*/
060        public String getSiteName(){
061            //System.out.println("get site name =>" + siteName);
062            return siteName;}
063        /**Sets the domain name of the site. Examples: nersc.gov, rcf.bnl.gov*/
064        public void setSiteName(String siteName){
065            //System.out.println("set site name =>" + siteName);
066            this.siteName = siteName;}
067        /**Returns the domain name of the site. Examples: nersc.gov, rcf.bnl.gov*/
068        public String getCanonicalName(){return canonicalName;}
069        /**Sets the domain name of the site. Examples: nersc.gov, rcf.bnl.gov*/
070        public void setCanonicalName(String canonicalName){this.canonicalName = canonicalName;}
071        
072        /** Adds a batch system object to the site. This function is used primarily for configuration in the config file. 
073         *Note that this function can be called multiple time for add multiple objects.*/
074        public void AddBatchSystem(BatchSystem batchSystem){ 
075            batchSystem.setSite(this);
076            this.batchSystems.add(batchSystem); 
077        }
078        /** Returns the List of batch systems for this site. Only intended for use by serializer. */
079        public List getBatchSystems(){ return batchSystems; }
080        /** Sets the List of batch systems for this site. Only intended for use by serializer. */
081        public void setBatchSystems(List batchSystems){this.batchSystems = batchSystems;}
082        
083        
084        
085        private List accessList = new ArrayList();
086        /**This function replaces the list of access objects.
087         * Note:This function is -only- used by the framework and should not be called as it will reset the access list set by the config file**/
088        public void setAccessPointsList(List accessList){ this.accessList = accessList; }
089        /**Returns a list (ArrayList) of access object available from the site.**/
090        public List getAccessPointsList(){ return this.accessList; }
091        /**This function should be called from the config file, it adds an access object (GateKeeperAccess, LocalAccess) to a access list.*/
092        public void addAccessPoint(LocalAccessPoint accessPoint){ 
093            accessPoint.setSite(this);
094            accessList.add(accessPoint); 
095        }
096        /**Returns a list (ArrayList) of only the GateKeeperAccess objects on the access list.*/
097        public List getGateKeeperAccessPointList(){ return makeAccessPointsListof(new GateKeeperAccessPoint()); }
098        /**Returns a list (ArrayList) of only the LocalAccess objects on the access list.*/
099        public List getLocalAccessPointsList(){return makeAccessPointsListof(new LocalAccessPoint()); }
100        /**Return a list (ArrayList) of all the objects from the access list that are instances of the object argument.*/
101        private final List makeAccessPointsListof(Object object){
102            List objectList = new ArrayList();
103            objectList.clear();
104            for(int i = 0; i != accessList.size(); i++){
105                if(accessList.get(i).getClass().isInstance(object)) objectList.add(accessList.get(i));  
106            }   
107            return objectList;
108        }
109        
110        
111        
112        
113        List gatekeeperAccess = new ArrayList();
114        /**Used to add a gatekeeper to this site, to which jobs can be submitted
115         * Note: This function is called from the config file.**/
116        public void addGateKeeperAccess(GateKeeperAccessPoint gateKeeperAccessPoint){ 
117            this.gatekeeperAccess.add(gateKeeperAccessPoint);
118             gateKeeperAccessPoint.setSite(this);
119             accessList.add(gateKeeperAccessPoint);   
120        }
121        /**This function sets the pointer to the list of gatekeeper objects accessible through this site.
122         * Note: This function is used only by the frame work and should not be called, becuase it will clear all gatekeeps already setup by the config file.**/
123        public void setGateKeeperAccess(List gatekeeperAccess){this.gatekeeperAccess = gatekeeperAccess;}
124        /** This function returns a list of gatekeeper object, that a can be used to access this site.*/
125        public List getGateKeeperAccess(){return this.gatekeeperAccess; }
126        
127        List localAccess = new ArrayList();
128        /**Used to add a local access point to this site, from which jobs can be submitted
129          * Note: This function is called from the config file.**/
130        public void addLocalAccess(LocalAccessPoint localAccess){ this.localAccess.add(localAccess); }
131         /**This function sets the pointer to the localAccess object accessible through this site, for submitting jobs.
132         * Note: This function is used only by the frame work and should not be called, becuase it will clear all access objects already setup by the config file.**/
133        public void setLocalAccess(List localAccess){this.localAccess = localAccess; }
134        /** This function returns a list of local access objects, that a can be used to access this site.*/
135        public List getLocalAccess(){return this.localAccess; }
136        
137        
138        
139        /** Adds a file Transfer gatekeepers object to the site. This function is used primarily for configuration in the config file. 
140         *Note that this function can be called multiple time for add multiple objects.
141         */
142        public void AddFileTransferGatekeeper(GateKeeperAccessPoint gateKeeper){ this.fileTransferGatekeepers.add(gateKeeper); }
143        /** Returns the List of gatekeepers for this site. Only intended for use by serializer. */
144        public List getFileTransferGatekeepes(){ return fileTransferGatekeepers; }
145        /** Sets the List of gatekeepers for this site. This is intended be used in the config file */
146        public void setFileTransferGatekeepes(List fileTransferGatekeepers){this.fileTransferGatekeepers = fileTransferGatekeepers;}
147        /**Returns a gatekeeper object form this site that can be used for file transfers*/
148        public GateKeeperAccessPoint getFileTransferGatekeeper(){
149            //Todo: This will be made a little smarter after its up and working.
150            return (GateKeeperAccessPoint)fileTransferGatekeepers.get(0);
151        }
152        
153        
154        
155        
156        //add other objects needed at site level cshapp, stat, log ...
157        
158        private Map logConf = null;
159        /** Set the hashtable with the parameters needed for logging. The keys that need to be set inside this hashtable are "directory" and "level". */
160        public void setLogConf(Map logConf){this.logConf = logConf;}
161        /**This function is used by the system to recover parameters needed for logging in the format of a hastable.*/
162        public Map getLogConf(){return logConf;}
163        
164        private Map statisticsConf = null;
165        /** Set the hashtable with the parameters needed for statistics collection into a MySQL database. The keys that need to be set inside this hashtable are password, username, URL (exmaple: jdbc:mysql://duvall.star.bnl.gov/Scheduler_bnl).*/
166        public void setStatisticsConf(Map statisticsConf){this.statisticsConf = statisticsConf;}
167        /**This function is used by the system to recover parameters needed for statistics collection into a MySQL database.*/
168        public Map getStatisticsConf(){return statisticsConf;}
169        
170        private Map programLocations = null;
171        public void setProgramLocations(Map programLocations){this.programLocations = programLocations;}
172        public Map getProgramLocations(){return programLocations;}
173        
174        
175        private Policy defaultPolicy;
176        public void setDefaultPolicy(Policy defaultPolicy){this.defaultPolicy = defaultPolicy;}
177        public Policy getDefaultPolic(){return defaultPolicy;}
178        
179        
180        private InformationService informationService = null;
181        /** This is just temporary until such time as it can be moved to the batch system level in the new format. */
182        public void setInformationService(InformationService informationService){this.informationService = informationService; }
183        public InformationService getInformationService(){return informationService;}
184        
185        
186        private Proxy proxy  = null;
187        /**Sets the proxy fo rthe information service . This proxy me be used by other elements in it global to the JVM**/
188        public void setProxy(Proxy proxy){this.proxy = proxy; }
189        public Proxy getProxy(){return proxy;}
190        
191        
192    }