public TaskRuntime(IInjector taskInjector, string contextId, string taskId, HeartBeatManager heartBeatManager) { _injector = taskInjector; var messageSources = Optional <ISet <ITaskMessageSource> > .Empty(); try { ITaskMessageSource taskMessageSource = _injector.GetInstance <ITaskMessageSource>(); messageSources = Optional <ISet <ITaskMessageSource> > .Of(new HashSet <ITaskMessageSource> { taskMessageSource }); } catch (Exception e) { Utilities.Diagnostics.Exceptions.Caught(e, Level.Warning, "Cannot inject task message source with error: " + e.StackTrace, Logger); // do not rethrow since this is benign } try { heartBeatManager.EvaluatorSettings.NameClient = _injector.GetInstance <INameClient>(); } catch (InjectionException) { // do not rethrow since user is not required to provide name client Logger.Log(Level.Warning, "Cannot inject name client from task configuration."); } _driverConnectionMessageHandler = new Lazy <IDriverConnectionMessageHandler>(() => { try { return(_injector.GetInstance <IDriverConnectionMessageHandler>()); } catch (InjectionException) { Logger.Log(Level.Info, "User did not implement IDriverConnectionMessageHandler."); } return(null); }); _driverMessageHandler = new Lazy <IDriverMessageHandler>(() => { try { return(_injector.GetInstance <IDriverMessageHandler>()); } catch (InjectionException ie) { Utilities.Diagnostics.Exceptions.CaughtAndThrow(ie, Level.Error, "Received Driver message, but unable to inject handler for driver message ", Logger); } return(null); }); Logger.Log(Level.Info, "task message source injected"); _currentStatus = new TaskStatus(heartBeatManager, contextId, taskId, messageSources); }
public ContextManager(HeartBeatManager heartBeatManager, Optional<ServiceConfiguration> rootServiceConfig, Optional<TaskConfiguration> rootTaskConfig) { using (LOGGER.LogFunction("ContextManager::ContextManager")) { _heartBeatManager = heartBeatManager; _rootContextLauncher = new RootContextLauncher(_heartBeatManager.EvaluatorSettings.RootContextConfig, rootServiceConfig, rootTaskConfig); } }
public ContextManager(HeartBeatManager heartBeatManager, Optional <ServiceConfiguration> rootServiceConfig, Optional <TaskConfiguration> rootTaskConfig) { using (LOGGER.LogFunction("ContextManager::ContextManager")) { _heartBeatManager = heartBeatManager; _rootContextLauncher = new RootContextLauncher(_heartBeatManager.EvaluatorSettings.RootContextConfig, rootServiceConfig, rootTaskConfig); } }
public TaskStatus(HeartBeatManager heartBeatManager, string contextId, string taskId, Optional<ISet<ITaskMessageSource>> evaluatorMessageSources) { _contextId = contextId; _taskId = taskId; _heartBeatManager = heartBeatManager; _taskLifeCycle = new TaskLifeCycle(); _evaluatorMessageSources = evaluatorMessageSources; State = TaskState.Init; }
public TaskStatus(HeartBeatManager heartBeatManager, string contextId, string taskId, Optional <ISet <ITaskMessageSource> > evaluatorMessageSources) { _contextId = contextId; _taskId = taskId; _heartBeatManager = heartBeatManager; _taskLifeCycle = new TaskLifeCycle(); _evaluatorMessageSources = evaluatorMessageSources; State = TaskState.Init; }
private ContextManager( HeartBeatManager heartBeatManager, EvaluatorSettings evaluatorSetting) { using (LOGGER.LogFunction("ContextManager::ContextManager")) { _heartBeatManager = heartBeatManager; _rootContextLauncher = new RootContextLauncher( evaluatorSetting.RootContextConfig, evaluatorSetting.RootServiceConfiguration, evaluatorSetting.RootTaskConfiguration); } }
/// <summary> /// Launches an Task on this context. /// </summary> /// <param name="taskConfiguration"></param> /// <param name="contextId"></param> /// <param name="heartBeatManager"></param> public void StartTask(TaskConfiguration taskConfiguration, string contextId, HeartBeatManager heartBeatManager) { lock (_contextLifeCycle) { bool taskPresent = _task.IsPresent(); bool taskEnded = taskPresent && _task.Value.HasEnded(); LOGGER.Log(Level.Info, "ContextRuntime::StartTask(TaskConfiguration)" + "task is present: " + taskPresent + " task has ended: " + taskEnded); if (taskPresent) { LOGGER.Log(Level.Info, "Task state: " + _task.Value.GetTaskState()); } if (taskEnded) { // clean up state _task = Optional <TaskRuntime> .Empty(); taskPresent = false; } if (taskPresent) { var e = new InvalidOperationException( string.Format(CultureInfo.InvariantCulture, "Attempting to spawn a child context when an Task with id '{0}' is running", _task.Value.TaskId)); // note: java code is putting thread id here Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER); } if (_childContext.IsPresent()) { var e = new InvalidOperationException("Attempting to instantiate a child context on a context that is not the topmost active context."); Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER); } try { IInjector taskInjector = _contextInjector.ForkInjector(taskConfiguration.TangConfig); LOGGER.Log(Level.Info, "Trying to inject task with configuration" + taskConfiguration.ToString()); TaskRuntime taskRuntime = new TaskRuntime(taskInjector, contextId, taskConfiguration.TaskId, heartBeatManager); // taskInjector.getInstance(TaskRuntime.class); taskRuntime.Initialize(); System.Threading.Tasks.Task.Run(new Action(taskRuntime.Start)); _task = Optional <TaskRuntime> .Of(taskRuntime); } catch (Exception e) { var ex = new TaskClientCodeException(taskConfiguration.TaskId, Id, "Unable to instantiate the new task", e); Org.Apache.REEF.Utilities.Diagnostics.Exceptions.CaughtAndThrow(ex, Level.Error, "Task start error.", LOGGER); } } }
public TaskRuntime(IInjector taskInjector, string contextId, string taskId, HeartBeatManager heartBeatManager, string memento = null) { _injector = taskInjector; _heartBeatManager = heartBeatManager; Optional <ISet <ITaskMessageSource> > messageSources = Optional <ISet <ITaskMessageSource> > .Empty(); try { _task = _injector.GetInstance <ITask>(); } catch (Exception e) { Org.Apache.REEF.Utilities.Diagnostics.Exceptions.CaughtAndThrow(new InvalidOperationException("Unable to inject task.", e), Level.Error, "Unable to inject task.", LOGGER); } try { ITaskMessageSource taskMessageSource = _injector.GetInstance <ITaskMessageSource>(); messageSources = Optional <ISet <ITaskMessageSource> > .Of(new HashSet <ITaskMessageSource>() { taskMessageSource }); } catch (Exception e) { Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Caught(e, Level.Warning, "Cannot inject task message source with error: " + e.StackTrace, LOGGER); // do not rethrow since this is benign } try { _nameClient = _injector.GetInstance <INameClient>(); _heartBeatManager.EvaluatorSettings.NameClient = _nameClient; } catch (InjectionException) { LOGGER.Log(Level.Warning, "Cannot inject name client from task configuration."); // do not rethrow since user is not required to provide name client } LOGGER.Log(Level.Info, "task message source injected"); _currentStatus = new TaskStatus(_heartBeatManager, contextId, taskId, messageSources); _memento = memento == null ? Optional <byte[]> .Empty() : Optional <byte[]> .Of(ByteUtilities.StringToByteArrays(memento)); }
/// <summary> /// Launches an Task on this context. /// </summary> /// <param name="taskConfiguration"></param> /// <param name="contextId"></param> /// <param name="heartBeatManager"></param> public void StartTask(TaskConfiguration taskConfiguration, string contextId, HeartBeatManager heartBeatManager) { lock (_contextLifeCycle) { bool taskPresent = _task.IsPresent(); bool taskEnded = taskPresent && _task.Value.HasEnded(); LOGGER.Log(Level.Info, "ContextRuntime::StartTask(TaskConfiguration)" + "task is present: " + taskPresent + " task has ended: " + taskEnded); if (taskPresent) { LOGGER.Log(Level.Info, "Task state: " + _task.Value.GetTaskState()); } if (taskEnded) { // clean up state _task = Optional<TaskRuntime>.Empty(); taskPresent = false; } if (taskPresent) { var e = new InvalidOperationException( string.Format(CultureInfo.InvariantCulture, "Attempting to spawn a child context when an Task with id '{0}' is running", _task.Value.TaskId)); // note: java code is putting thread id here Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER); } if (_childContext.IsPresent()) { var e = new InvalidOperationException("Attempting to instantiate a child context on a context that is not the topmost active context."); Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(e, LOGGER); } try { IInjector taskInjector = _contextInjector.ForkInjector(taskConfiguration.TangConfig); LOGGER.Log(Level.Info, "Trying to inject task with configuration" + taskConfiguration.ToString()); TaskRuntime taskRuntime = new TaskRuntime(taskInjector, contextId, taskConfiguration.TaskId, heartBeatManager); // taskInjector.getInstance(TaskRuntime.class); taskRuntime.Initialize(); System.Threading.Tasks.Task.Run(new Action(taskRuntime.Start)); _task = Optional<TaskRuntime>.Of(taskRuntime); } catch (Exception e) { var ex = new TaskClientCodeException(taskConfiguration.TaskId, Id, "Unable to instantiate the new task", e); Org.Apache.REEF.Utilities.Diagnostics.Exceptions.CaughtAndThrow(ex, Level.Error, "Task start error.", LOGGER); } } }
public static void Main(string[] args) { try { Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "START: {0} Evaluator::InitInjector.", DateTime.Now)); Stopwatch timer = new Stopwatch(); InitInjector(); SetCustomTraceListners(); // _logger is reset by this. timer.Stop(); Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "EXIT: {0} Evaluator::InitInjector. Duration: [{1}].", DateTime.Now, timer.Elapsed)); using (_logger.LogScope("Evaluator::Main")) { // Wait for the debugger, if enabled AttachDebuggerIfEnabled(); // Register our exception handler AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler; // Fetch some settings from the ConfigurationManager SetHeartbeatPeriod(); SetHeartbeatMaxRetry(); // Parse the command line if (args.Count() < 2) { var e = new InvalidOperationException("must supply at least the rId and evaluator config file"); Utilities.Diagnostics.Exceptions.Throw(e, _logger); } // remote driver Id string rId = args[0]; // evaluator configuraiton file string evaluatorConfigurationPath = args[1]; // Parse the evaluator configuration. _evaluatorConfig = new EvaluatorConfigurations(evaluatorConfigurationPath); ContextConfiguration rootContextConfiguration = _evaluatorConfig.RootContextConfiguration; Optional <TaskConfiguration> rootTaskConfig = _evaluatorConfig.TaskConfiguration; Optional <ServiceConfiguration> rootServiceConfig = _evaluatorConfig.RootServiceConfiguration; // remoteManager used as client-only in evaluator IRemoteManager <REEFMessage> remoteManager = _injector.GetInstance <IRemoteManagerFactory>().GetInstance(new REEFMessageCodec()); IRemoteIdentifier remoteId = new SocketRemoteIdentifier(NetUtilities.ParseIpEndpoint(rId)); RuntimeClock clock = InstantiateClock(); _logger.Log(Level.Info, "Application Id: " + _evaluatorConfig.ApplicationId); EvaluatorSettings evaluatorSettings = new EvaluatorSettings( _evaluatorConfig.ApplicationId, _evaluatorConfig.EvaluatorId, _heartbeatPeriodInMs, _heartbeatMaxRetry, rootContextConfiguration, clock, remoteManager, _injector); HeartBeatManager heartBeatManager = new HeartBeatManager(evaluatorSettings, remoteId); ContextManager contextManager = new ContextManager(heartBeatManager, rootServiceConfig, rootTaskConfig); EvaluatorRuntime evaluatorRuntime = new EvaluatorRuntime(contextManager, heartBeatManager); // TODO: replace with injectionFuture heartBeatManager._evaluatorRuntime = evaluatorRuntime; heartBeatManager._contextManager = contextManager; SetRuntimeHandlers(evaluatorRuntime, clock); Task evaluatorTask = Task.Run(new Action(clock.Run)); evaluatorTask.Wait(); } } catch (Exception e) { Fail(e); } }
public static void Main(string[] args) { Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "START: {0} Evaluator::InitInjector.", DateTime.Now)); Stopwatch timer = new Stopwatch(); InitInjector(); SetCustomTraceListners(); timer.Stop(); Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "EXIT: {0} Evaluator::InitInjector. Duration: [{1}].", DateTime.Now, timer.Elapsed)); RuntimeClock clock; using (_logger.LogScope("Evaluator::Main")) { string debugEnabledString = Environment.GetEnvironmentVariable("Org.Apache.Reef.EvaluatorDebug"); if (!string.IsNullOrWhiteSpace(debugEnabledString) && debugEnabledString.Equals("enabled", StringComparison.OrdinalIgnoreCase)) { while (true) { if (Debugger.IsAttached) { break; } else { _logger.Log(Level.Info, "Evaluator in debug mode, waiting for debugger to be attached..."); Thread.Sleep(2000); } } } AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler; string heartbeatPeriodFromConfig = ConfigurationManager.AppSettings["EvaluatorHeartbeatPeriodInMs"]; int heartbeatPeriod = 0; if (!string.IsNullOrWhiteSpace(heartbeatPeriodFromConfig) && int.TryParse(heartbeatPeriodFromConfig, out heartbeatPeriod)) { _heartbeatPeriodInMs = heartbeatPeriod; } _logger.Log(Level.Verbose, "Evaluator heartbeat period set to be " + _heartbeatPeriodInMs + " milliSeconds."); int maxHeartbeatRetry = 0; string heartbeatMaxRetryFromConfig = ConfigurationManager.AppSettings["EvaluatorHeartbeatRetryMaxTimes"]; if (!string.IsNullOrWhiteSpace(heartbeatMaxRetryFromConfig) && int.TryParse(heartbeatMaxRetryFromConfig, out maxHeartbeatRetry)) { _heartbeatMaxRetry = maxHeartbeatRetry; } _logger.Log(Level.Verbose, "Evaluator heatrbeat max retry set to be " + _heartbeatMaxRetry + " times."); if (args.Count() < 2) { var e = new InvalidOperationException("must supply at least the rId and evaluator config file"); Exceptions.Throw(e, _logger); } // remote driver Id string rId = args[0]; // evaluator configuraiton file string evaluatorConfigurationPath = args[1]; ICodec <REEFMessage> reefMessageCodec = new REEFMessageCodec(); _evaluatorConfig = new EvaluatorConfigurations(evaluatorConfigurationPath); string rootContextConfigString = _evaluatorConfig.RootContextConfiguration; if (string.IsNullOrWhiteSpace(rootContextConfigString)) { Exceptions.Throw(new ArgumentException("empty or null rootContextConfigString"), _logger); } ContextConfiguration rootContextConfiguration = new ContextConfiguration(rootContextConfigString); string taskConfig = _evaluatorConfig.TaskConfiguration; Optional <TaskConfiguration> rootTaskConfig = string.IsNullOrEmpty(taskConfig) ? Optional <TaskConfiguration> .Empty() : Optional <TaskConfiguration> .Of( new TaskConfiguration(taskConfig)); string rootServiceConfigString = _evaluatorConfig.RootServiceConfiguration; Optional <ServiceConfiguration> rootServiceConfig = string.IsNullOrEmpty(rootServiceConfigString) ? Optional <ServiceConfiguration> .Empty() : Optional <ServiceConfiguration> .Of( new ServiceConfiguration( rootServiceConfigString)); // remoteManager used as client-only in evaluator IRemoteManager <REEFMessage> remoteManager = new DefaultRemoteManager <REEFMessage>(reefMessageCodec); IRemoteIdentifier remoteId = new SocketRemoteIdentifier(NetUtilities.ParseIpEndpoint(rId)); ConfigurationModule module = new ConfigurationModuleBuilder().Build(); IConfiguration clockConfiguraiton = module.Build(); clock = TangFactory.GetTang().NewInjector(clockConfiguraiton).GetInstance <RuntimeClock>(); _logger.Log(Level.Info, "Application Id: " + _evaluatorConfig.ApplicationId); EvaluatorSettings evaluatorSettings = new EvaluatorSettings( _evaluatorConfig.ApplicationId, _evaluatorConfig.EvaluatorId, _heartbeatPeriodInMs, _heartbeatMaxRetry, rootContextConfiguration, clock, remoteManager, _injector); HeartBeatManager heartBeatManager = new HeartBeatManager(evaluatorSettings, remoteId); ContextManager contextManager = new ContextManager(heartBeatManager, rootServiceConfig, rootTaskConfig); EvaluatorRuntime evaluatorRuntime = new EvaluatorRuntime(contextManager, heartBeatManager); // TODO: repalce with injectionFuture heartBeatManager._evaluatorRuntime = evaluatorRuntime; heartBeatManager._contextManager = contextManager; SetRuntimeHanlders(evaluatorRuntime, clock); } Task evaluatorTask = Task.Run(new Action(clock.Run)); evaluatorTask.Wait(); }