Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        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();
        }