001    /*
002     * $RCSfile: CatalogManager.java,v $
003     *
004     * Created on August 19, 2002, 4:29 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    package gov.bnl.star.offline.scheduler.catalog;
024    
025    import gov.bnl.star.offline.scheduler.CatalogQuery;
026    import gov.bnl.star.offline.scheduler.LogFormatter;
027    import java.util.List;
028    
029    import java.io.BufferedReader;
030    import java.io.File;
031    import java.io.FileReader;
032    import java.io.InputStreamReader;
033    import java.io.Reader;
034    
035    import java.net.URL;
036    
037    import java.util.ArrayList;
038    import java.util.Collections;
039    import java.util.Iterator;
040    import java.util.Set;
041    import java.util.StringTokenizer;
042    import java.util.logging.Handler;
043    import java.util.logging.Level;
044    import org.apache.log4j.Logger;
045    
046    
047    /** @deprecated please see gov.bnl.star.offline.scheduler.dataset.* for replacements. 
048     * 
049     * This class is able to execute file catalog queries on the STAR file catalog
050     * implementation.
051     *
052     * @author  Gabriele Carcassi
053     * @version $Revision: 1.11 $ $Date: 2006/11/21 00:41:31 $
054     */
055    public class CatalogManager {
056        static private Logger log = Logger.getLogger(CatalogManager.class.getName());
057    
058        /** Executes a file catalog query and returns the output. To do this, an external
059         * process get_file_list script is executed, its output parsed and returned.
060         * @param query a file catalog query where the query part is the <CODE>-cond</CODE> parameter
061         * for the STAR file catalog.
062         * @return the list of files retrieved by the query
063         */
064        public static QueryResult executeQuery(CatalogQuery query) {
065            log.info("Resolving query with the STAR scheduler: " + 
066                     query.getQuery());
067            
068            FileCatalog fc = FileCatalog.getCatalog();
069            
070            //TODO This is a hack: didn't want to change the catalog interface without further thought.
071            attrList = query.getAttributes();
072            
073            QueryStrategy strategy = QueryStrategyFactory.createStrategy(query);
074            QueryResult result = strategy.resolveQuery(fc, query);
075            log.debug("Query resolved. Logical files: " + result.getLogicalCount() + " - Physical files: " + result.getPhysicalCount());
076            
077            //CopySelector selector = CopySelectorFactory.createCopySelector(query);
078            //URL[] urls = selector.selectCopy(result, query);
079    
080            return result;
081        }
082        
083        private static List attrList;
084        //TODO This is a hack: didn't want to change the catalog interface without further thought.
085        public static List getAttrList() {
086            return attrList;
087        }
088    
089        public static void main(String[] args) {
090            // Setting the log detail on the standard output
091            /*
092            Handler[] handlers = Logger.getLogger("").getHandlers();
093    
094            for (int index = 0; index < handlers.length; index++) {
095                handlers[index].setFormatter(new LogFormatter());
096                handlers[index].setLevel(Level.FINEST);
097            }
098    
099            Logger.getLogger("").setLevel(Level.FINEST);
100            */
101    
102            /*CatalogQuery query = new CatalogQuery(args[0]);
103            System.out.println(args[0]);
104    
105            URL[] out = executeQuery(query);*/
106            /*URL[] out = testOnOutputExample();
107            System.out.println("Found "+out.length+" files");
108            for (int n = 0; n < out.length; n++) {
109                System.out.println(out[n]);
110            }*/
111        }
112    }