001 /* 002 * $RCSfile: SiteForwardPolicy.java,v $ 003 * 004 * Created on February 26, 2006, 11:21 AM 005 * 006 * This file is part of the STAR Scheduler. 007 * Copyright (c) 2002-2003 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 package gov.bnl.star.offline.scheduler.policy; 024 025 import gov.bnl.star.offline.scheduler.*; 026 import gov.bnl.star.offline.scheduler.Policy; 027 import gov.bnl.star.offline.scheduler.util.FilesystemToolkit; 028 import gov.bnl.star.offline.scheduler.request.Request; 029 030 import java.net.URL; 031 032 import java.text.DateFormat; 033 import java.text.SimpleDateFormat; 034 import java.util.*; 035 036 import java.util.Date; 037 import org.apache.log4j.Logger; 038 039 040 /** This policy prepares a star-submit job to be forwarded on a local cluster 041 * through the globus gatekeeper specified in the process target. 042 * 043 * @author Gabriele Carcassi 044 * @version $Revision: 1.13 $ $Date: 2006/11/21 00:41:32 $ 045 */ 046 public class SiteForwardPolicy implements Policy { 047 static private Logger log = Logger.getLogger(SiteForwardPolicy.class.getName()); 048 049 private String getNextJobID() { 050 DateFormat format = new SimpleDateFormat("yyMMddHHmmss"); 051 052 return format.format(new Date()); 053 } 054 055 /** Creates a star-submit process with the same xml description file as 056 * input. The target is the globus gatekeeper of the site to which the 057 * request is dispatched. 058 * @param request the request to be dispatched 059 */ 060 public List assignTargetMachine(Request request) { 061 log.info("Using SiteForwardPolicy"); 062 063 String jobID = getNextJobID(); 064 Job job = new Job(jobID); 065 Random rand = new Random(); 066 if (rand.nextBoolean()) { 067 job.setCommandline("/afs/rhic/star/packages/scripts/star-submit " + request.getRequestFileName()); 068 //job.setTarget("stargrid01.rcf.bnl.gov/jobmanager-lsf"); 069 System.out.println( 070 "The job request is being forwarded to RCF (BNL)."); 071 } else { 072 job.setCommandline("/auto/pdsfdv08/starprod/scheduler/star-submit " + request.getRequestFileName()); 073 //job.setTarget("pdsfgrid2.nersc.gov"); 074 System.out.println( 075 "The job request is being forwarded to PDSF (NERSC)."); 076 } 077 078 String filename = "sched" + jobID + ".condor.out"; 079 String urlString = "file:" + FilesystemToolkit.getCurrentDirectory() + 080 "/" + filename; 081 082 try { 083 URL stdout = new URL(urlString); 084 job.setStdout(stdout); 085 System.out.println( 086 "The output of the local scheduler will be avilable in " + 087 filename + " once the submission has ended."); 088 System.out.println( 089 "To wait for the local scheduler you can type \"tail -f " + 090 filename + "\"."); 091 } catch (Exception e) { 092 log.warn("Couldn't create URL for the output file: " + 093 urlString); 094 System.out.println( 095 "An error has occoured and the output of the site scheduler won't be available."); 096 } 097 098 List jobs = new ArrayList(); 099 jobs.add(job); 100 return jobs; 101 } 102 }