/** * @param jobIdentifier * @param remoteIdentifier * @return * @throws BindException * @throws InjectionException */ private synchronized RunningJobImpl newRunningJob(final String jobIdentifier, final String remoteIdentifier) throws BindException, InjectionException { final Injector child = this.injector.forkInjector(); child.bindVolatileParameter(REEFImplementation.DriverRemoteIdentifier.class, remoteIdentifier); child.bindVolatileParameter(DriverIdentifier.class, jobIdentifier); return child.getInstance(RunningJobImpl.class); } }
/** * 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); } }
/** * 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); } } }
try (final LaunchClass lc = injector.getInstance(LaunchClass.class)) { LOG.log(Level.FINE, "Launcher starting"); lc.run();
/** * Create a new ContextRuntime. * * @param serviceInjector the serviceInjector to be used. * @param contextConfiguration the Configuration for this context. * @throws ContextClientCodeException if the context cannot be instantiated. */ ContextRuntime(final Injector serviceInjector, final Configuration contextConfiguration, final Optional<ContextRuntime> parentContext) throws ContextClientCodeException { this.serviceInjector = serviceInjector; this.parentContext = parentContext; // Trigger the instantiation of the services try { final Set<Object> services = serviceInjector.getNamedInstance(Services.class); this.contextInjector = serviceInjector.forkInjector(contextConfiguration); this.contextLifeCycle = this.contextInjector.getInstance(ContextLifeCycle.class); } catch (BindException | InjectionException e) { final Optional<String> parentID = this.getParentContext().isPresent() ? Optional.of(this.getParentContext().get().getIdentifier()) : Optional.<String>empty(); throw new ContextClientCodeException( ContextClientCodeException.getIdentifier(contextConfiguration), parentID, "Unable to spawn context", e); } // Trigger the context start events on contextInjector. this.contextLifeCycle.start(); }
final Injector taskInjector = this.contextInjector.forkInjector(taskConfig); final TaskRuntime taskRuntime = taskInjector.getInstance(TaskRuntime.class); taskRuntime.initialize(); this.taskRuntimeThread = new Thread(taskRuntime, taskRuntime.getId());
final Injector rootServiceInjector; try { rootServiceInjector = injector.forkInjector(rootServiceConfiguration.get()); } catch (final BindException e) { throw new ContextClientCodeException(ContextClientCodeException.getIdentifier(rootContextConfiguration), result = new ContextRuntime(injector.forkInjector(), rootContextConfiguration);
/** * 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); } }
final Injector childServiceInjector = this.serviceInjector.forkInjector(); final ContextRuntime childContext = new ContextRuntime(childServiceInjector, contextConfiguration, Optional.of(this));
public static void main(final String[] args) throws Exception { setupLogging(); Tang.Factory.getTang() .newInjector(UnsafeHDInsightRuntimeConfiguration.fromEnvironment()) .getInstance(HDICLI.class).run(args); }
/** * Helper method to create a new EvaluatorManager instance * * @param id identifier of the Evaluator * @param desc NodeDescriptor on which the Evaluator executes. * @return a new EvaluatorManager instance. */ private final EvaluatorManager getNewEvaluatorManagerInstance(final String id, final EvaluatorDescriptorImpl desc) { LOG.log(Level.FINEST, "Creating Evaluator Manager for Evaluator ID {0}", id); final Injector child = this.injector.forkInjector(); try { child.bindVolatileParameter(EvaluatorManager.EvaluatorIdentifier.class, id); child.bindVolatileParameter(EvaluatorManager.EvaluatorDescriptorName.class, desc); } catch (final BindException e) { throw new RuntimeException("Unable to bind evaluator identifier and name.", e); } final EvaluatorManager result; try { result = child.getInstance(EvaluatorManager.class); } catch (final InjectionException e) { throw new RuntimeException("Unable to instantiate a new EvaluatorManager for Evaluator ID: " + id, e); } return result; }
/** * 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); } } }
this.serviceInjector.forkInjector(serviceConfiguration);
/** * 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); } }
.setIdentifier(injector.getNamedInstance(DriverIdentifier.class)) .setDriverMemory(injector.getNamedInstance(DriverMemory.class)) .setUserName(System.getProperty("user.name")) .setConfiguration(configurationSerializer.toString(driverConfiguration)); for (final String globalFileName : injector.getNamedInstance(JobGlobalFiles.class)) { LOG.log(Level.FINEST, "Adding global file: {0}", globalFileName); jbuilder.addGlobalFile(getFileResourceProto(globalFileName, ReefServiceProtos.FileType.PLAIN)); for (final String globalLibraryName : injector.getNamedInstance(JobGlobalLibraries.class)) { LOG.log(Level.FINEST, "Adding global library: {0}", globalLibraryName); jbuilder.addGlobalFile(getFileResourceProto(globalLibraryName, ReefServiceProtos.FileType.LIB)); for (final String localFileName : injector.getNamedInstance(DriverLocalFiles.class)) { LOG.log(Level.FINEST, "Adding local file: {0}", localFileName); jbuilder.addLocalFile(getFileResourceProto(localFileName, ReefServiceProtos.FileType.PLAIN)); for (final String localLibraryName : injector.getNamedInstance(DriverLocalLibraries.class)) { LOG.log(Level.FINEST, "Adding local library: {0}", localLibraryName); jbuilder.addLocalFile(getFileResourceProto(localLibraryName, ReefServiceProtos.FileType.LIB));
/** * 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); }