001    /*
002     * OutputCopyAction.java
003     *
004     * Created on February 11, 2004, 12:17 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;
025    
026    import java.net.URI;
027    import java.util.List;
028    
029    /** Description of how to register an output file.
030     *  @author  Carcassi & Hajdu
031     */
032    public class OutputRegisterAction extends OutputAction implements java.io.Serializable {
033        
034        //private String fileRef;
035        //private String storageService;
036        //private URI uri;
037        
038        /** Creates a new instance of OutputCopyAction */
039        public OutputRegisterAction(List actionList, String id, String referto, String to, int retries, int sleep) {
040            
041            this.SetActionList(actionList);
042            this.setID(id);
043            this.setReferTo(referto);
044            this.setTo(to);
045            this.setRetries(retries);
046            this.setSleep(sleep);
047        }
048        
049        /** Creates a new instance of OutputCopyAction. Note: This constructor is only for use by the XML serializer.  */
050        public OutputRegisterAction(){}
051        
052        /** Returns register, as register is the name for all register actions.
053         */
054    //    public String getName() {
055    //        return "register";
056    //    }
057        
058        /** Returns the reference indicating which copy of the file to register. If
059         * null the default reference is used.
060         */
061    //    public String getFileRef() {
062    //        return fileRef;
063           // System.out.println("The Register action can not be referenced as if it where a file.");
064           // return null;
065       // }
066        
067        
068    //    String to;
069    //    public String getTo() {
070    //        return to;
071    //    }
072    //    
073    //    public void setTo(String to){
074    //        this.to = to;
075    //   }
076        
077        /** Returns false, as all CopyActions do not generate references. Being a reference
078         * generator means that in the script they are able to determine the location
079         * of the target files. Register actions will not generate a reference, but
080         * will get either the default one, or one created by other actions, such as
081         * the Copy action.
082         */
083        //public boolean isReferenceGenerator() {
084        //    return false;
085        //}
086        
087        
088        public String getScriptName() { return "SUMSregister.pl"; }
089        
090        public String makeScriptString(String outputFile, String gateway) {
091            
092            setOutputFile(outputFile); 
093            
094            if(this.getReferTo() != null){ //resolve the referTo
095                outputFile = this.findReferTo(this.GetActionList(), getReferTo() );  
096            }
097            
098            String command = getScriptName() + " \"";
099            command = command.concat( gateway +"\" \""+ outputFile +"\" \""+ getTo());
100            
101            if(getRetries() > 0){
102                command = command.concat("\" " + String.valueOf(" " + getRetries()));
103                if(getSleep() > 0) command = command.concat(" " + String.valueOf(getSleep()));
104            }
105            
106            return command + "\n";
107        
108        }
109        
110    }