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.Path;
22 import org.apache.hadoop.mapred.JobConf;
23
24 import java.io.IOException;
25 import java.util.ArrayList;
26 import java.util.List;
27
28 /**
29 * Supports the cache in a fully distributed environment.
30 * @author Sascha Kohlmann
31 */
32 public class FullyDistributedCacheStrategy implements DistributedCacheStrategy {
33
34 /** The logging of this class. */
35 private static final Log LOG =
36 LogFactory.getLog(FullyDistributedCacheStrategy.class.getName());
37
38 /*
39 * @see net.sf.eos.hadoop.DistributedCacheStrategy#distributedCachePathes(org.apache.hadoop.mapred.JobConf)
40 */
41 @SuppressWarnings("nls")
42 public Path[] distributedCachePathes(final JobConf conf) throws IOException
43 {
44 final List<Path> pathes = new ArrayList<Path>();
45 final Path[] pathList = DistributedCache.getLocalCacheFiles(conf);
46
47 for (final Path path : pathList) {
48 final Path qualified = new Path("file", "", path.toString());
49 LOG.info("path: " + path + " - qualified path: " + qualified);
50 pathes.add(qualified);
51 }
52
53 return pathes.toArray(new Path[pathList.length]);
54 }
55 }