Example usage for org.apache.hadoop.mapreduce.v2.util MRApps addToEnvironment

List of usage examples for org.apache.hadoop.mapreduce.v2.util MRApps addToEnvironment

Introduction

In this page you can find the example usage for org.apache.hadoop.mapreduce.v2.util MRApps addToEnvironment.

Prototype

@Public
    @Unstable
    public static void addToEnvironment(Map<String, String> environment, String variable, String value,
            Configuration conf) 

Source Link

Usage

From source file:org.apache.oozie.util.ClasspathUtils.java

License:Apache License

public static void setupClasspath(Map<String, String> env, Configuration conf) throws IOException {
    // Propagate the system classpath when using the mini cluster
    if (usingMiniYarnCluster) {
        MRApps.addToEnvironment(env, ApplicationConstants.Environment.CLASSPATH.name(),
                System.getProperty("java.class.path"), conf);
    }/*from   ww w .jav  a2s . co m*/

    for (String entry : CLASSPATH_ENTRIES) {
        MRApps.addToEnvironment(env, ApplicationConstants.Environment.CLASSPATH.name(), entry, conf);
    }

    // a * in the classpath will only find a .jar, so we need to filter out
    // all .jars and add everything else
    addToClasspathIfNotJar(org.apache.hadoop.mapreduce.filecache.DistributedCache.getFileClassPaths(conf),
            org.apache.hadoop.mapreduce.filecache.DistributedCache.getCacheFiles(conf), conf, env,
            ApplicationConstants.Environment.PWD.$());
    addToClasspathIfNotJar(org.apache.hadoop.mapreduce.filecache.DistributedCache.getArchiveClassPaths(conf),
            org.apache.hadoop.mapreduce.filecache.DistributedCache.getCacheArchives(conf), conf, env,
            ApplicationConstants.Environment.PWD.$());

    boolean crossPlatform = conf.getBoolean(MRConfig.MAPREDUCE_APP_SUBMISSION_CROSS_PLATFORM,
            MRConfig.DEFAULT_MAPREDUCE_APP_SUBMISSION_CROSS_PLATFORM);

    for (String c : conf.getStrings(YarnConfiguration.YARN_APPLICATION_CLASSPATH,
            crossPlatform ? YarnConfiguration.DEFAULT_YARN_CROSS_PLATFORM_APPLICATION_CLASSPATH
                    : YarnConfiguration.DEFAULT_YARN_APPLICATION_CLASSPATH)) {
        MRApps.addToEnvironment(env, ApplicationConstants.Environment.CLASSPATH.name(), c.trim(), conf);
    }
}

From source file:org.apache.oozie.util.ClasspathUtils.java

License:Apache License

public static void addMapReduceToClasspath(Map<String, String> env, Configuration conf) {
    boolean crossPlatform = conf.getBoolean(MRConfig.MAPREDUCE_APP_SUBMISSION_CROSS_PLATFORM,
            MRConfig.DEFAULT_MAPREDUCE_APP_SUBMISSION_CROSS_PLATFORM);

    for (String c : conf.getStrings(MRJobConfig.MAPREDUCE_APPLICATION_CLASSPATH,
            crossPlatform//from w  w w . j a  v  a 2 s.  co m
                    ? StringUtils.getStrings(MRJobConfig.DEFAULT_MAPREDUCE_CROSS_PLATFORM_APPLICATION_CLASSPATH)
                    : StringUtils.getStrings(MRJobConfig.DEFAULT_MAPREDUCE_APPLICATION_CLASSPATH))) {
        MRApps.addToEnvironment(env, ApplicationConstants.Environment.CLASSPATH.name(), c.trim(), conf);
    }
}

From source file:org.apache.oozie.util.ClasspathUtils.java

License:Apache License

private static void addToClasspathIfNotJar(Path[] paths, URI[] withLinks, Configuration conf,
        Map<String, String> environment, String classpathEnvVar) throws IOException {
    if (paths != null) {
        HashMap<Path, String> linkLookup = new HashMap<Path, String>();
        if (withLinks != null) {
            for (URI u : withLinks) {
                Path p = new Path(u);
                FileSystem remoteFS = p.getFileSystem(conf);
                p = remoteFS.resolvePath(p.makeQualified(remoteFS.getUri(), remoteFS.getWorkingDirectory()));
                String name = (null == u.getFragment()) ? p.getName() : u.getFragment();
                if (!name.toLowerCase(Locale.ENGLISH).endsWith(".jar")) {
                    linkLookup.put(p, name);
                }//from  w w w. j a  va  2s .c  o m
            }
        }

        for (Path p : paths) {
            FileSystem remoteFS = p.getFileSystem(conf);
            p = remoteFS.resolvePath(p.makeQualified(remoteFS.getUri(), remoteFS.getWorkingDirectory()));
            String name = linkLookup.get(p);
            if (name == null) {
                name = p.getName();
            }
            if (!name.toLowerCase(Locale.ENGLISH).endsWith(".jar")) {
                MRApps.addToEnvironment(environment, classpathEnvVar,
                        ApplicationConstants.Environment.PWD.$() + Path.SEPARATOR + name, conf);
            }
        }
    }
}