001    /*
002     * This file is part of the STAR Scheduler.
003     * Copyright (c) 2002-2006 STAR Collaboration - Brookhaven National Laboratory
004     *
005     * STAR Scheduler is free software; you can redistribute it and/or modify
006     * it under the terms of the GNU General Public License as published by
007     * the Free Software Foundation; either version 2 of the License, or
008     * (at your option) any later version.
009     *
010     * STAR Scheduler is distributed in the hope that it will be useful,
011     * but WITHOUT ANY WARRANTY; without even the implied warranty of
012     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013     * GNU General Public License for more details.
014     *
015     * You should have received a copy of the GNU General Public License
016     * along with STAR Scheduler; if not, write to the Free Software
017     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
018     */
019    
020    package gov.bnl.star.offline.scheduler.Dispatchers.condorg;
021    /*
022     * CondorNodePriorityStringGenerator.java
023     *
024     * Created on August 24, 2006, 4:10 PM
025     *
026     * To change this template, choose Tools | Template Manager
027     * and open the template in the editor.
028     */
029    
030    import gov.bnl.star.offline.scheduler.Job;
031    import gov.bnl.star.offline.scheduler.catalog.PhysicalFile;
032    import java.util.*;
033    
034    /**
035     *
036     * @author lbhajdu
037     */
038    public class CondorNodePriorityStringGenerator {
039        
040        /** Creates a new instance of CondorNodePriorityStringGenerator */
041        public CondorNodePriorityStringGenerator() {
042        }
043        
044        
045        private static Map nodes = new TreeMap(); 
046        
047       
048        public static String generateSyntax(Job job){
049            nodes.clear();
050            List filelist = job.getInput(); 
051            List nodeNames = new ArrayList();
052            String syntax = "";
053            String node = "";
054            String storage ="";
055            
056            for(int i = 0; i != filelist.size(); i++){
057                node = ((PhysicalFile) filelist.get(i)).getNode();
058                storage = ((PhysicalFile) filelist.get(i)).getStorage();
059                
060                if(node != null && storage != null){
061                    if(node != "" && storage != ""){
062                        if(storage.compareTo("HPSS")!=0 && storage.compareTo("NFS")!=0 && node.compareTo("localhost")!=0){ //The node is aso checked just in case
063                        
064                            if(nodes.containsKey(node)){ //pull the node out of the table ++ its value and put it back in
065                                int  n = ((Integer) nodes.get(node)).intValue();
066                                nodes.remove(node);
067                                n ++;
068                                nodes.put(node, new Integer(n)); 
069                            }
070                            else{
071    
072                                nodeNames.add(node);
073                                nodes.put(node, new Integer(2)); //it has to start with a priority of 2       
074                            }
075                        }    
076                    }
077                }    
078              }  
079                
080            Iterator iter = nodes.keySet().iterator();
081            
082            boolean first = true;
083            
084            while (iter.hasNext()) {
085                node = (String) iter.next();
086                //syntax = syntax + node + "+" + ((Integer) nodes.get(node)).toString() + " ";
087                int numberOfNodes = ((Integer) nodes.get(node)).intValue() + 1;
088                syntax = syntax + (first?"":" + ") + "((machine == \"" + node + "\")*" + numberOfNodes + ")";
089                first = false;
090            }
091            
092            nodes.clear();
093            return syntax;
094     
095        }
096          
097    }