/** * Extracts a task id from the given configuration. * * @param config * @return the task id in the given configuration. * @throws RuntimeException if the configuration can't be parsed. */ public static String getTaskId(final Configuration config) { try { return Tang.Factory.getTang().newInjector(config).getNamedInstance(TaskConfigurationOptions.Identifier.class); } catch (final InjectionException ex) { throw new RuntimeException("Unable to determine task identifier. Giving up.", ex); } } }
/** * Extracts a context id from the given configuration. * * @param c * @return the context id in the given configuration. * @throws RuntimeException if the configuration can't be parsed. */ public static String getIdentifier(final Configuration c) { try { return Tang.Factory.getTang().newInjector(c).getNamedInstance( ContextIdentifier.class); } catch (final InjectionException e) { throw new RuntimeException("Unable to determine context identifier. Giving up.", e); } } }
Injector injector = null; try { injector = Tang.Factory.getTang().newInjector(processCommandLine(args)); } catch (final BindException | IOException | InjectionException e) { fail("Error in parsing the command line", e);
/** * Get all evaluator ids and send it back to response as JSON. */ private void writeEvaluatorsJsonOutput(final HttpServletResponse response) throws IOException { LOG.log(Level.INFO, "HttpServerReefEventHandler getEvaluators is called"); try { final EvaluatorListSerializer serializer = Tang.Factory.getTang().newInjector().getInstance(EvaluatorListSerializer.class); final AvroEvaluatorList evaluatorList = serializer.toAvro( this.reefStateManager.getEvaluators(), this.reefStateManager.getEvaluators().size(), this.reefStateManager.getStartTime()); writeResponse(response, serializer.toString(evaluatorList)); } catch (final InjectionException e) { LOG.log(Level.SEVERE, "Error in injecting EvaluatorListSerializer.", e); writeResponse(response, "Error in injecting EvaluatorListSerializer: " + e); } }
public static void main(final String[] args) throws Exception { setupLogging(); Tang.Factory.getTang() .newInjector(UnsafeHDInsightRuntimeConfiguration.fromEnvironment()) .getInstance(HDICLI.class).run(args); }
/** * Write Evaluator info as JSON format to HTTP Response. */ private void writeEvaluatorInfoJsonOutput( final HttpServletResponse response, final List<String> ids) throws IOException { try { final EvaluatorInfoSerializer serializer = Tang.Factory.getTang().newInjector().getInstance(EvaluatorInfoSerializer.class); final AvroEvaluatorsInfo evaluatorsInfo = serializer.toAvro(ids, this.reefStateManager.getEvaluators()); writeResponse(response, serializer.toString(evaluatorsInfo)); } catch (final InjectionException e) { LOG.log(Level.SEVERE, "Error in injecting EvaluatorInfoSerializer.", e); writeResponse(response, "Error in injecting EvaluatorInfoSerializer: " + e); } }
/** * Instantiates the clock. * * @return a clock object. */ private Clock getClock() { try { final Injector clockInjector = Tang.Factory.getTang().newInjector(this.getClockConfiguration()); if (isProfilingEnabled) { clockInjector.bindAspect(profiler); } clockInjector.bindVolatileInstance(RemoteManager.class, this.remoteManager); return clockInjector.getInstance(Clock.class); } catch (final Throwable ex) { fail("Unable to instantiate the clock", ex); throw new RuntimeException("Unable to instantiate the clock", ex); } }
/** * Write Driver Info as JSON string to Response. */ private void writeDriverJsonInformation(final HttpServletResponse response) throws IOException { try { final DriverInfoSerializer serializer = Tang.Factory.getTang().newInjector().getInstance(DriverInfoSerializer.class); final AvroDriverInfo driverInfo = serializer.toAvro( this.reefStateManager.getDriverEndpointIdentifier(), this.reefStateManager.getStartTime(), this.reefStateManager.getServicesInfo()); writeResponse(response, serializer.toString(driverInfo)); } catch (final InjectionException e) { LOG.log(Level.SEVERE, "Error in injecting DriverInfoSerializer.", e); writeResponse(response, "Error in injecting DriverInfoSerializer: " + e); } }
/** * Instantiate a launcher for the given Configuration. * * @param runtimeConfiguration the resourcemanager configuration to be used * @return a DriverLauncher based on the given resourcemanager configuration * @throws BindException on configuration errors * @throws InjectionException on configuration errors */ public static DriverLauncher getLauncher( final Configuration runtimeConfiguration) throws BindException, InjectionException { final Configuration clientConfiguration = ClientConfiguration.CONF .set(ClientConfiguration.ON_JOB_RUNNING, RunningJobHandler.class) .set(ClientConfiguration.ON_JOB_COMPLETED, CompletedJobHandler.class) .set(ClientConfiguration.ON_JOB_FAILED, FailedJobHandler.class) .set(ClientConfiguration.ON_RUNTIME_ERROR, RuntimeErrorHandler.class) .build(); return Tang.Factory.getTang() .newInjector(runtimeConfiguration, clientConfiguration) .getInstance(DriverLauncher.class); }
final Injector injector = Tang.Factory.getTang().newInjector(driverConfiguration);