Example usage for org.apache.hadoop.mapred Task getJobFile

List of usage examples for org.apache.hadoop.mapred Task getJobFile

Introduction

In this page you can find the example usage for org.apache.hadoop.mapred Task getJobFile.

Prototype

public String getJobFile() 

Source Link

Usage

From source file:com.mellanox.hadoop.mapred.MapOutputLocation.java

License:Apache License

protected void configureClasspath(JobConf conf) throws IOException {

    // get the task and the current classloader which will become the parent
    Task task = reduceTask;
    ClassLoader parent = conf.getClassLoader();

    // get the work directory which holds the elements we are dynamically
    // adding to the classpath
    File workDir = new File(task.getJobFile()).getParentFile();
    ArrayList<URL> urllist = new ArrayList<URL>();

    // add the jars and directories to the classpath
    String jar = conf.getJar();/*from w ww  . ja va2s.c om*/
    if (jar != null) {
        File jobCacheDir = new File(new Path(jar).getParent().toString());

        File[] libs = new File(jobCacheDir, "lib").listFiles();
        if (libs != null) {
            for (int i = 0; i < libs.length; i++) {
                urllist.add(libs[i].toURL());
            }
        }
        urllist.add(new File(jobCacheDir, "classes").toURL());
        urllist.add(jobCacheDir.toURL());

    }
    urllist.add(workDir.toURL());

    // create a new classloader with the old classloader as its parent
    // then set that classloader as the one used by the current jobconf
    URL[] urls = urllist.toArray(new URL[urllist.size()]);
    URLClassLoader loader = new URLClassLoader(urls, parent);
    conf.setClassLoader(loader);
}