View Javadoc

1   /* Copyright (c) 2008 Sascha Kohlmann
2    *
3    * This program is free software: you can redistribute it and/or modify
4    * it under the terms of the GNU Affero General Public License as published by
5    * the Free Software Foundation, either version 3 of the License, or
6    * (at your option) any later version.
7    *
8    * This program is distributed in the hope that it will be useful,
9    * but WITHOUT ANY WARRANTY; without even the implied warranty of
10   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11   * GNU Affero General Public License for more details.
12   *
13   * You should have received a copy of the GNU Affero General Public License
14   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15   */
16  package net.sf.eos.hadoop;
17  
18  import org.apache.commons.logging.Log;
19  import org.apache.commons.logging.LogFactory;
20  import org.apache.hadoop.filecache.DistributedCache;
21  import org.apache.hadoop.fs.FileSystem;
22  import org.apache.hadoop.fs.Path;
23  import org.apache.hadoop.mapred.JobConf;
24  
25  import java.io.IOException;
26  import java.net.URI;
27  import java.util.ArrayList;
28  import java.util.List;
29  
30  /**
31   * Supports the cache in a test environment.
32   * @author Sascha Kohlmann
33   */
34  public class TestDistributedCacheStrategy implements DistributedCacheStrategy {
35  
36      /** The logging of this class. */
37      private static final Log LOG =
38          LogFactory.getLog(TestDistributedCacheStrategy.class.getName());
39  
40      /*
41       * @see net.sf.eos.hadoop.DistributedCacheStrategy#distributedCachePathes(org.apache.hadoop.mapred.JobConf)
42       */
43      @SuppressWarnings("nls")
44      public Path[] distributedCachePathes(final JobConf conf) throws IOException
45      {
46  
47        final URI[] uris = DistributedCache.getCacheFiles(conf);
48        final List<Path> pathes = new ArrayList<Path>();
49  
50        for (final URI uri : uris) {
51            final Path p = new Path(uri.toASCIIString());
52            final FileSystem fs = p.getFileSystem(conf);
53            final Path qualified = p.makeQualified(fs);
54            LOG.info("uri: " + uri + " - qualified path: " + qualified);
55            pathes.add(qualified);
56        }
57  
58        return pathes.toArray(new Path[uris.length]);
59      }
60  }