Search in sources :

Example 1 with ApplicationClassLoader

use of org.apache.hadoop.util.ApplicationClassLoader in project hadoop by apache.

the class TestEntityGroupFSTimelineStore method testPluginRead.

@Test
public void testPluginRead() throws Exception {
    // Verify precondition
    assertEquals(EntityGroupPlugInForTest.class.getName(), store.getConfig().get(YarnConfiguration.TIMELINE_SERVICE_ENTITY_GROUP_PLUGIN_CLASSES));
    List<TimelineEntityGroupPlugin> currPlugins = store.getPlugins();
    for (TimelineEntityGroupPlugin plugin : currPlugins) {
        ClassLoader pluginClassLoader = plugin.getClass().getClassLoader();
        assertTrue("Should set up ApplicationClassLoader", pluginClassLoader instanceof ApplicationClassLoader);
        URL[] paths = ((URLClassLoader) pluginClassLoader).getURLs();
        boolean foundJAR = false;
        for (URL path : paths) {
            if (path.toString().contains(testJar.getAbsolutePath())) {
                foundJAR = true;
            }
        }
        assertTrue("Not found path " + testJar.getAbsolutePath() + " for plugin " + plugin.getClass().getName(), foundJAR);
    }
    // Load data and cache item, prepare timeline store by making a cache item
    EntityGroupFSTimelineStore.AppLogs appLogs = store.new AppLogs(mainTestAppId, mainTestAppDirPath, AppState.COMPLETED);
    EntityCacheItem cacheItem = new EntityCacheItem(EntityGroupPlugInForTest.getStandardTimelineGroupId(mainTestAppId), config);
    cacheItem.setAppLogs(appLogs);
    store.setCachedLogs(EntityGroupPlugInForTest.getStandardTimelineGroupId(mainTestAppId), cacheItem);
    MutableCounterLong detailLogEntityRead = store.metrics.getGetEntityToDetailOps();
    MutableStat cacheRefresh = store.metrics.getCacheRefresh();
    long numEntityReadBefore = detailLogEntityRead.value();
    long cacheRefreshBefore = cacheRefresh.lastStat().numSamples();
    // Generate TDM
    TimelineDataManager tdm = PluginStoreTestUtils.getTdmWithStore(config, store);
    // Verify single entity read
    TimelineEntity entity3 = tdm.getEntity("type_3", mainTestAppId.toString(), EnumSet.allOf(TimelineReader.Field.class), UserGroupInformation.getLoginUser());
    assertNotNull(entity3);
    assertEquals(entityNew.getStartTime(), entity3.getStartTime());
    // Verify multiple entities read
    NameValuePair primaryFilter = new NameValuePair(EntityGroupPlugInForTest.APP_ID_FILTER_NAME, mainTestAppId.toString());
    TimelineEntities entities = tdm.getEntities("type_3", primaryFilter, null, null, null, null, null, null, EnumSet.allOf(TimelineReader.Field.class), UserGroupInformation.getLoginUser());
    assertEquals(1, entities.getEntities().size());
    for (TimelineEntity entity : entities.getEntities()) {
        assertEquals(entityNew.getStartTime(), entity.getStartTime());
    }
    // Verify metrics
    assertEquals(numEntityReadBefore + 2L, detailLogEntityRead.value());
    assertEquals(cacheRefreshBefore + 1L, cacheRefresh.lastStat().numSamples());
}
Also used : MutableCounterLong(org.apache.hadoop.metrics2.lib.MutableCounterLong) MutableStat(org.apache.hadoop.metrics2.lib.MutableStat) TimelineEntity(org.apache.hadoop.yarn.api.records.timeline.TimelineEntity) ApplicationClassLoader(org.apache.hadoop.util.ApplicationClassLoader) URL(java.net.URL) TimelineEntities(org.apache.hadoop.yarn.api.records.timeline.TimelineEntities) URLClassLoader(java.net.URLClassLoader) ApplicationClassLoader(org.apache.hadoop.util.ApplicationClassLoader) URLClassLoader(java.net.URLClassLoader) Test(org.junit.Test)

Example 2 with ApplicationClassLoader

use of org.apache.hadoop.util.ApplicationClassLoader in project hadoop by apache.

the class MRApps method createJobClassLoader.

/**
   * Creates a {@link ApplicationClassLoader} if
   * {@link MRJobConfig#MAPREDUCE_JOB_CLASSLOADER} is set to true, and
   * the APP_CLASSPATH environment variable is set.
   * @param conf
   * @return the created job classloader, or null if the job classloader is not
   * enabled or the APP_CLASSPATH environment variable is not set
   * @throws IOException
   */
public static ClassLoader createJobClassLoader(Configuration conf) throws IOException {
    ClassLoader jobClassLoader = null;
    if (conf.getBoolean(MRJobConfig.MAPREDUCE_JOB_CLASSLOADER, false)) {
        String appClasspath = System.getenv(Environment.APP_CLASSPATH.key());
        if (appClasspath == null) {
            LOG.warn("Not creating job classloader since APP_CLASSPATH is not set.");
        } else {
            LOG.info("Creating job classloader");
            if (LOG.isDebugEnabled()) {
                LOG.debug("APP_CLASSPATH=" + appClasspath);
            }
            String[] systemClasses = getSystemClasses(conf);
            jobClassLoader = createJobClassLoader(appClasspath, systemClasses);
        }
    }
    return jobClassLoader;
}
Also used : ApplicationClassLoader(org.apache.hadoop.util.ApplicationClassLoader)

Aggregations

ApplicationClassLoader (org.apache.hadoop.util.ApplicationClassLoader)2 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 MutableCounterLong (org.apache.hadoop.metrics2.lib.MutableCounterLong)1 MutableStat (org.apache.hadoop.metrics2.lib.MutableStat)1 TimelineEntities (org.apache.hadoop.yarn.api.records.timeline.TimelineEntities)1 TimelineEntity (org.apache.hadoop.yarn.api.records.timeline.TimelineEntity)1 Test (org.junit.Test)1