Example usage for org.apache.hadoop.conf Configuration getClassLoader

List of usage examples for org.apache.hadoop.conf Configuration getClassLoader

Introduction

In this page you can find the example usage for org.apache.hadoop.conf Configuration getClassLoader.

Prototype

public ClassLoader getClassLoader() 

Source Link

Document

Get the ClassLoader for this job.

Usage

From source file:org.elasticsearch.repositories.hdfs.HdfsRepository.java

License:Apache License

private void addConfigLocation(Configuration cfg, String confLocation) {
    URL cfgURL = null;//from  w w  w  .  j  a v a  2s  . c  o  m
    // it's an URL
    if (!confLocation.contains(":")) {
        cfgURL = cfg.getClassLoader().getResource(confLocation);

        // fall back to file
        if (cfgURL == null) {
            File file = new File(confLocation);
            if (!file.canRead()) {
                throw new ElasticsearchIllegalArgumentException(String.format(
                        "Cannot find classpath resource or file 'conf_location' [%s] defined for hdfs snapshot/restore",
                        confLocation));
            }
            String fileLocation = file.toURI().toString();
            logger.debug("Adding path [{}] as file [{}]", confLocation, fileLocation);
            confLocation = fileLocation;
        } else {
            logger.debug("Resolving path [{}] to classpath [{}]", confLocation, cfgURL);
        }
    } else {
        logger.debug("Adding path [{}] as URL", confLocation);
    }

    if (cfgURL == null) {
        try {
            cfgURL = new URL(confLocation);
        } catch (MalformedURLException ex) {
            throw new ElasticsearchIllegalArgumentException(String.format(
                    "Invalid 'conf_location' URL [%s] defined for hdfs snapshot/restore", confLocation), ex);
        }
    }

    cfg.addResource(cfgURL);
}

From source file:org.springframework.data.hadoop.mapreduce.ExecutionUtils.java

License:Apache License

static void earlyLeaseDaemonInit(Configuration config) throws IOException {
    ClassLoader cl = config.getClassLoader();
    if (cl instanceof ParentLastURLClassLoader) {
        if (log.isDebugEnabled()) {
            log.debug("Preventing DFS LeaseDaemon TCCL leak");
        }/*w ww.ja va  2 s  .  co m*/

        FileSystem fs = FileSystem.get(config);
        Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader());
        Path p = new Path("/tmp/shdp-lease-early-init-" + UUID.randomUUID().toString());
        // create/delete
        fs.create(p).close();
        fs.delete(p, false);
    }
}

From source file:org.springframework.data.hadoop.mapreduce.HadoopCodeExecutor.java

License:Apache License

protected int runCode() throws Exception {
    // merge configuration options
    final Configuration cfg = resolveConfiguration();

    // resolve target object
    final Class<T> type = resolveTargetClass(cfg);
    final T target = resolveTargetObject(type);

    // setup the invocation context
    Thread th = Thread.currentThread();
    ClassLoader oldTccl = th.getContextClassLoader();

    log.info("Invoking [" + (target != null ? target : type) + "] "
            + (jar != null ? "from jar [" + jar.getURI() + "]" : "") + " with args ["
            + Arrays.toString(arguments) + "]");

    ClassLoader newCL = cfg.getClassLoader();
    boolean isJarCL = newCL instanceof ParentLastURLClassLoader;
    try {//from   ww  w  .  ja v a2 s  . c o m
        ExecutionUtils.disableSystemExitCall();
        if (isJarCL) {
            ExecutionUtils.preventHadoopLeaks(beanClassLoader);
        }

        //ExecutionUtils.earlyLeaseDaemonInit(cfg);

        th.setContextClassLoader(newCL);

        if (StringUtils.hasText(user)) {
            UserGroupInformation ugi = UserGroupInformation.createProxyUser(user,
                    UserGroupInformation.getLoginUser());

            return ugi.doAs(new PrivilegedExceptionAction<Integer>() {
                @Override
                public Integer run() throws Exception {
                    return invokeTarget(cfg, target, type, arguments);
                }
            });
        } else {
            return invokeTarget(cfg, target, type, arguments);
        }
    } finally {
        ExecutionUtils.enableSystemExitCall();
        th.setContextClassLoader(oldTccl);

        if (isJarCL) {
            if (closeFs) {
                ExecutionUtils.shutdownFileSystem(cfg);
            }
            ExecutionUtils.patchLeakedClassLoader(newCL, oldTccl);
        }
    }
}

From source file:org.springframework.data.hadoop.mapreduce.JarTests.java

License:Apache License

@Test
public void testBadMainClassConfiguration() throws Exception {
    Configuration cfg = (Configuration) System.getProperties().get("org.springframework.data.hadoop.jar.cfg");
    assertNotNull(cfg);//w  ww.  j  a v a  2s .co m
    cfg.getClassLoader();

    // check inherited props
    assertEquals("main", hadoopConfiguration.get("cfg"));

    assertEquals("main", cfg.get("cfg"));
    // check nested props
    assertEquals("war", cfg.get("web"));
    assertNull(cfg.get("land"));

    // verify new config object
    Configuration freshConfig = new Configuration();

    // check inherited props
    assertNull(freshConfig.get("cfg"));
    // check nested props
    assertNull(freshConfig.get("web"));
    assertNull(freshConfig.get("land"));
}