001 /* 002 * DynamicConfigPolicy.java 003 * 004 * Created on November 15, 2006, 3:05 PM 005 * 006 * To change this template, choose Tools | Template Manager 007 * and open the template in the editor. 008 */ 009 010 package gov.bnl.star.offline.scheduler.policy; 011 012 import gov.bnl.star.offline.scheduler.ComponentLibrary; 013 import gov.bnl.star.offline.scheduler.Dispatcher; 014 import gov.bnl.star.offline.scheduler.Policy; 015 import gov.bnl.star.offline.scheduler.request.Request; 016 017 import gov.bnl.star.offline.scheduler.Site; 018 import gov.bnl.star.offline.scheduler.GateKeeperAccessPoint; 019 import gov.bnl.star.offline.scheduler.AccessMethod; 020 import gov.bnl.star.offline.scheduler.Queue; 021 import gov.bnl.star.offline.scheduler.Dispatchers.condorg.CondorGRSLDispatcher; 022 import gov.bnl.star.offline.scheduler.informationService.VORS; 023 import gov.bnl.star.offline.scheduler.util.ConfigToolkit; 024 import java.util.Collection; 025 import java.util.Hashtable; 026 027 import java.util.List; 028 import java.util.Map; 029 import java.util.Set; 030 031 /** 032 * 033 * @author lbhajdu 034 */ 035 public class DynamicConfigPolicy extends PassivePolicy implements Policy { 036 037 /** Creates a new instance of DynamicConfigPolicy */ 038 public DynamicConfigPolicy() { 039 } 040 041 private String service = null; 042 public void setService(String service){ this.service = service; } 043 public String getService(){return this.service; } 044 045 046 public List assignTargetMachine(Request request) { 047 048 049 System.out.print("Collecting site information."); 050 051 String siteID = (String) ConfigToolkit.getToolkit().getGlobalObject("DYNO_SITE_FLAG"); 052 //String siteID = "STAR-WSU"; 053 //service = "http://vors.grid.iu.edu"; 054 055 if(siteID == null){ 056 throw new RuntimeException("ERROR: \"siteID\" is not set."); 057 } 058 059 if(service == null){ 060 throw new RuntimeException("ERROR: Information service is not set."); 061 } 062 063 VORS vors = new VORS(); 064 vors.setSiteID(siteID); 065 System.out.print(".."); 066 vors.setService(service); 067 String exec_jm = vors.getSiteInfo(siteID,"exec_jm"); 068 System.out.println("..Done"); 069 070 String gateKeeperName = null; 071 String batchSystemName = null; 072 073 074 if(exec_jm != null){ 075 if(exec_jm.matches("^([A-Za-z0-9\\.]*)/jobmanager-[A-Za-z]*$")){ 076 gateKeeperName = exec_jm.replaceAll("^([A-Za-z0-9\\.]*)/jobmanager-[A-Za-z]*$", "$1"); 077 batchSystemName = exec_jm.replaceAll("^[A-Za-z0-9\\.]*/jobmanager-([A-Za-z]*)$", "$1"); 078 }else System.out.println("Error \" exec_jm \" string for site " + siteID + " does not match \"^([A-Za-z0-9\\.]*)/jobmanager-[A-Za-z]*$\""); 079 }else System.out.println("Error: Could not find \" exec_jm \" string for site " + siteID); 080 081 if( (gateKeeperName == null)||(batchSystemName == null) ){ 082 throw new RuntimeException("information service error: Data could not be recovered."); 083 } 084 085 086 System.out.print("Setting up site"); 087 Site site = new Site(); 088 site.setInformationService(vors); 089 site.setCanonicalName(siteID); 090 System.out.println("....done"); 091 092 093 Map programLocations = new Hashtable(); 094 site.setProgramLocations(programLocations); 095 096 System.out.println("Adding to program locations table:"); 097 String wntmp_loc = vors.getSiteInfo(siteID,"wntmp_loc"); 098 if(wntmp_loc.matches(".*/$")) wntmp_loc = wntmp_loc + "$USER/$JOBID"; 099 else wntmp_loc = wntmp_loc + "/$USER/$JOBID"; 100 System.out.println("$SCRATCH ->> " + wntmp_loc); 101 programLocations.put("$SCRATCH",wntmp_loc); 102 103 104 //Strip the gk host name off the URL and use it as the site name 105 if(gateKeeperName.matches(".+\\.[A-Za-z0-9]+\\.[A-Za-z]+") ){ site.setSiteName(gateKeeperName.replaceAll("[A-Za-z0-9]\\.(.+)","$1")); } 106 else site.setSiteName(gateKeeperName); 107 108 109 GateKeeperAccessPoint accessPoint = new GateKeeperAccessPoint(); 110 AccessMethod accessMethod = new AccessMethod(); 111 accessMethod.setBatchSystem(batchSystemName); 112 113 114 Queue queue = new Queue(); 115 queue.setCluster(site.getSiteName() ); 116 queue.setName(""); 117 queue.setTimeLimit(1000); 118 queue.setMaxMemory(500); 119 queue.setSearchOrderPriority(1); 120 queue.setSite("STAR"); 121 queue.setImplementation("grid"); 122 123 accessMethod.addQueue(queue); 124 125 Dispatcher defultGridDispatcher = (Dispatcher) ComponentLibrary.getInstance().getComponent("Defult_Grid_Dispatcher"); 126 accessMethod.setDispatcher(defultGridDispatcher); 127 128 if( (gateKeeperName == null)||(batchSystemName == null) ){ throw new RuntimeException("Could not find \"Defult_Grid_Dispatcher\" in config."); } 129 130 131 site.addGateKeeperAccess(accessPoint); 132 accessPoint.addAccessMethod(accessMethod); 133 accessPoint.setName(gateKeeperName); 134 135 136 this.addQueue(queue); 137 138 System.out.println(" ------- Passing to passive policy -------"); 139 140 return super.assignTargetMachine(request); 141 142 } 143 144 }