001    /* XrootdMinMaxSingleCopySelector.java
002     *
003     * Created on March 13, 2006, 10:52 AM
004     *
005     * This file is part of the STAR Scheduler.
006     * Copyright (c) 2002-2006 STAR Collaboration - Brookhaven National Laboratory
007     *
008     * STAR Scheduler is free software; you can redistribute it and/or modify
009     * it under the terms of the GNU General Public License as published by
010     * the Free Software Foundation; either version 2 of the License, or
011     * (at your option) any later version.
012     *
013     * STAR Scheduler is distributed in the hope that it will be useful,
014     * but WITHOUT ANY WARRANTY; without even the implied warranty of
015     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016     * GNU General Public License for more details.
017     *
018     * You should have received a copy of the GNU General Public License
019     * along with STAR Scheduler; if not, write to the Free Software
020     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
021     */
022    
023    
024    package gov.bnl.star.offline.scheduler.policy.copyselector;
025    
026    import gov.bnl.star.offline.scheduler.CatalogQuery;
027    import gov.bnl.star.offline.scheduler.catalog.QueryResult;
028    import gov.bnl.star.offline.scheduler.policy.FileAssignment;
029    import gov.bnl.star.offline.scheduler.policy.Location;
030    
031    import java.util.Iterator;
032    import java.util.List;
033    import java.util.Set;
034    
035    /**
036     * -----class comment-----
037     * This class is copy selector for xrootd syntax
038     *
039     * @author Pavel Jakl (pjakl@bnl.gov)
040     * @version $Id: XrootdMinMaxSingleCopySelector.java,v 1.3 2006/11/21 00:41:34 lbhajdu Exp $
041     */
042    public class XrootdMinMaxSingleCopySelector extends RootdMinMaxSingleCopySelector {
043    
044    //---------------------------------------------------------------------------------------------------------------------
045    // public methods/interface implementations
046    //---------------------------------------------------------------------------------------------------------------------
047        public int selectCopy(QueryResult list, CatalogQuery query, FileAssignment assignment) {
048            int nFiles = super.selectCopy(list, query, assignment);
049            // let's add files from HPSS as a last possibility
050            nFiles += assignHPSSFiles(list, assignment);
051    
052            return nFiles;
053        }
054    //---------------------------------------------------------------------------------------------------------------------
055    // protected methods
056    //---------------------------------------------------------------------------------------------------------------------
057        private int assignHPSSFiles(QueryResult list, FileAssignment assignment) {
058            int nFiles = 0;
059    
060            Set locations = assignment.getLocations();
061            Iterator iter = locations.iterator();
062            List files = list.getPhysicalOnLocation(Location.getHPSS());
063    
064            if (locations != null) {
065                while (iter.hasNext()) {
066                    Location location = (Location) iter.next();
067                    int nFilesToAssign = Math.min(assignment.canAdd(location),
068                            files.size());
069                    List filesToAssign = files.subList(0, nFilesToAssign);
070                    files = files.subList(nFilesToAssign, files.size());
071                    if (filesToAssign != null) {
072                        assignment.addAllPhysical(location, filesToAssign);
073                        list.removeAllLogicalOfPhysical(filesToAssign);
074                        nFiles += nFilesToAssign;
075                    }
076                }
077                if (files != null) {
078                    assignment.addAllPhysical(files);
079                    list.removeAllLogicalOfPhysical(files);
080                }
081            }
082            return files.size();
083        }
084    
085    }  // end of the XrootdMinMaxSingleCopySelector class