/** * 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; }
/** * @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); } }
try (final LaunchClass lc = injector.getInstance(LaunchClass.class)) { LOG.log(Level.FINE, "Launcher starting"); lc.run();
public static void main(final String[] args) throws Exception { setupLogging(); Tang.Factory.getTang() .newInjector(UnsafeHDInsightRuntimeConfiguration.fromEnvironment()) .getInstance(HDICLI.class).run(args); }
/** * 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); } }
/** * 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 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); } }
/** * 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 TaskRuntime taskRuntime = taskInjector.getInstance(TaskRuntime.class); taskRuntime.initialize(); this.taskRuntimeThread = new Thread(taskRuntime, taskRuntime.getId());
/** * 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(); }