@Override public MapReduceTaskContextProvider create(CConfiguration cConf, Configuration hConf, MapReduceClassLoader mapReduceClassLoader) { return new MapReduceTaskContextProvider(injector, mapReduceClassLoader); } });
/** * Creates an instance with the given {@link Injector} that will be used for getting service instances. */ protected MapReduceTaskContextProvider(Injector injector, MapReduceClassLoader mapReduceClassLoader) { this.injector = injector; this.taskContexts = CacheBuilder.newBuilder().build(createCacheLoader(injector)); this.authorizationEnforcer = injector.getInstance(AuthorizationEnforcer.class); this.authenticationContext = injector.getInstance(AuthenticationContext.class); this.mapReduceClassLoader = mapReduceClassLoader; }
/** * Returns the {@link BasicMapReduceTaskContext} for the given task. */ public final <K, V> BasicMapReduceTaskContext<K, V> get(TaskAttemptContext taskAttemptContext) { return get(new ContextCacheKey(taskAttemptContext)); }
@Override public void close() { try { MapReduceTaskContextProvider provider; synchronized (this) { provider = taskContextProvider; } if (provider != null) { Service.State state = provider.state(); if (state == Service.State.STARTING || state == Service.State.RUNNING) { provider.stopAndWait(); } } } catch (Exception e) { // This is non-fatal, since the container is already done. LOG.warn("Exception while stopping MapReduceTaskContextProvider", e); } }
@Override public MapReduceTaskContextProvider create(CConfiguration cConf, Configuration hConf, MapReduceClassLoader mapReduceClassLoader) { Preconditions.checkState(!MapReduceTaskContextProvider.isLocal(hConf), "Expected to be in distributed mode."); return new DistributedMapReduceTaskContextProvider(cConf, hConf, mapReduceClassLoader); } });
MapReduceClassLoader classLoader = MapReduceClassLoader.getFromConfiguration(configuration); MapReduceTaskContextProvider taskContextProvider = classLoader.getTaskContextProvider(); Injector injector = taskContextProvider.getInjector(); taskContext = taskContextProvider.get(taskAttemptContext); this.outputs = Outputs.transform(contextConfig.getOutputs(), taskContext);
/** * Returns the {@link MapReduceTaskContextProvider} associated with this ClassLoader. */ public MapReduceTaskContextProvider getTaskContextProvider() { // Logging context needs to be set in main thread. LoggingContext loggingContext = createMapReduceLoggingContext(); LoggingContextAccessor.setLoggingContext(loggingContext); synchronized (this) { taskContextProvider = Optional.fromNullable(taskContextProvider).or(taskContextProviderSupplier); } taskContextProvider.startAndWait(); return taskContextProvider; }
@Override protected void startUp() throws Exception { super.startUp(); try { for (Service service : coreServices) { service.startAndWait(); } logAppenderInitializer.initialize(); ProgramOptions programOptions = mapReduceContextConfig.getProgramOptions(); SystemArguments.setLogLevel(programOptions.getUserArguments(), logAppenderInitializer); } catch (Exception e) { // Try our best to stop services. Chain stop guarantees it will stop everything, even some of them failed. try { shutDown(); } catch (Exception stopEx) { e.addSuppressed(stopEx); } throw e; } }
@Override protected void shutDown() throws Exception { super.shutDown(); Exception failure = null; try { logAppenderInitializer.close(); } catch (Exception e) { failure = e; } for (Service service : (Iterable<Service>) coreServices::descendingIterator) { try { service.stopAndWait(); } catch (Exception e) { if (failure != null) { failure.addSuppressed(e); } else { failure = e; } } } if (failure != null) { throw failure; } }
@Override public MapReduceTaskContextProvider create(CConfiguration cConf, Configuration hConf, MapReduceClassLoader mapReduceClassLoader) { Preconditions.checkState(!MapReduceTaskContextProvider.isLocal(hConf), "Expected to be in distributed mode."); return new DistributedMapReduceTaskContextProvider(cConf, hConf, mapReduceClassLoader); } });
@Override public void close() { try { MapReduceTaskContextProvider provider; synchronized (this) { provider = taskContextProvider; } if (provider != null) { Service.State state = provider.state(); if (state == Service.State.STARTING || state == Service.State.RUNNING) { provider.stopAndWait(); } } } catch (Exception e) { // This is non-fatal, since the container is already done. LOG.warn("Exception while stopping MapReduceTaskContextProvider", e); } }
MapReduceClassLoader classLoader = MapReduceClassLoader.getFromConfiguration(configuration); MapReduceTaskContextProvider taskContextProvider = classLoader.getTaskContextProvider(); Injector injector = taskContextProvider.getInjector(); taskContext = taskContextProvider.get(taskAttemptContext); this.outputs = Outputs.transform(contextConfig.getOutputs(), taskContext);
/** * Returns the {@link MapReduceTaskContextProvider} associated with this ClassLoader. */ public MapReduceTaskContextProvider getTaskContextProvider() { // Logging context needs to be set in main thread. LoggingContext loggingContext = createMapReduceLoggingContext(); LoggingContextAccessor.setLoggingContext(loggingContext); synchronized (this) { taskContextProvider = Optional.fromNullable(taskContextProvider).or(taskContextProviderSupplier); } taskContextProvider.startAndWait(); return taskContextProvider; }
@Override protected void startUp() throws Exception { super.startUp(); try { for (Service service : coreServices) { service.startAndWait(); } logAppenderInitializer.initialize(); ProgramOptions programOptions = mapReduceContextConfig.getProgramOptions(); SystemArguments.setLogLevel(programOptions.getUserArguments(), logAppenderInitializer); } catch (Exception e) { // Try our best to stop services. Chain stop guarantees it will stop everything, even some of them failed. try { shutDown(); } catch (Exception stopEx) { e.addSuppressed(stopEx); } throw e; } }
@Override protected void shutDown() throws Exception { super.shutDown(); Exception failure = null; try { logAppenderInitializer.close(); } catch (Exception e) { failure = e; } for (Service service : (Iterable<Service>) coreServices::descendingIterator) { try { service.stopAndWait(); } catch (Exception e) { if (failure != null) { failure.addSuppressed(e); } else { failure = e; } } } if (failure != null) { throw failure; } }
/** * Returns the {@link BasicMapReduceTaskContext} for the given configuration. Since TaskAttemptContext is not * provided, the returned MapReduceTaskContext will not have Metrics available. * */ public final <K, V> BasicMapReduceTaskContext<K, V> get(Configuration configuration) { return get(new ContextCacheKey(null, configuration)); }
String name = entry.getKey(); Configuration mapredConf = job.getConfiguration(); if (MapReduceTaskContextProvider.isLocal(mapredConf)) {
/** * Creates an instance with the given {@link Injector} that will be used for getting service instances. */ protected MapReduceTaskContextProvider(Injector injector, MapReduceClassLoader mapReduceClassLoader) { this.injector = injector; this.taskContexts = CacheBuilder.newBuilder().build(createCacheLoader(injector)); this.authorizationEnforcer = injector.getInstance(AuthorizationEnforcer.class); this.authenticationContext = injector.getInstance(AuthenticationContext.class); this.mapReduceClassLoader = mapReduceClassLoader; }
@Override public MapReduceTaskContextProvider create(CConfiguration cConf, Configuration hConf, MapReduceClassLoader mapReduceClassLoader) { return new MapReduceTaskContextProvider(injector, mapReduceClassLoader); } });
/** * Returns the {@link BasicMapReduceTaskContext} for the given task. */ public final <K, V> BasicMapReduceTaskContext<K, V> get(TaskAttemptContext taskAttemptContext) { return get(new ContextCacheKey(taskAttemptContext)); }