示例#1
0
        /// <summary>
        /// IActiveContext handler. It will take the following actions based on the system state:
        /// Case WaitingForEvaluator:
        ///    Adds Active Context to Active Context Manager
        /// Case Fail:
        ///    Closes the ActiveContext
        /// Other cases - not expected
        /// </summary>
        /// <param name="activeContext"></param>
        public void OnNext(IActiveContext activeContext)
        {
            Logger.Log(Level.Info, "Received Active Context {0}, systemState {1}.", activeContext.Id, _systemState.CurrentState);
            lock (_lock)
            {
                using (Logger.LogFunction("IMRUDriver::IActiveContext"))
                {
                    switch (_systemState.CurrentState)
                    {
                    case SystemState.WaitingForEvaluator:
                        _contextManager.Add(activeContext);
                        break;

                    case SystemState.Fail:
                        Logger.Log(Level.Info,
                                   "Received IActiveContext event, but system is in FAIL state. Closing the context.");
                        activeContext.Dispose();
                        break;

                    default:
                        UnexpectedState(activeContext.Id, "IActiveContext");
                        break;
                    }
                }
            }
        }
        public void OnNext(IActiveContext activeContext)
        {
            IConfiguration taskConfiguration;

            if (_groupCommDriver.IsMasterTaskContext(activeContext))
            {
                // Configure Master Task
                taskConfiguration = TaskConfiguration.ConfigurationModule
                                    .Set(TaskConfiguration.Identifier, Constants.MasterTaskId)
                                    .Set(TaskConfiguration.Task, GenericType <KMeansMasterTask> .Class)
                                    .Build();

                _commGroup.AddTask(Constants.MasterTaskId);
            }
            else
            {
                string slaveTaskId = Constants.SlaveTaskIdPrefix + activeContext.Id;

                // Configure Slave Task
                taskConfiguration = TaskConfiguration.ConfigurationModule
                                    .Set(TaskConfiguration.Identifier, Constants.SlaveTaskIdPrefix + activeContext.Id)
                                    .Set(TaskConfiguration.Task, GenericType <KMeansSlaveTask> .Class)
                                    .Build();

                _commGroup.AddTask(slaveTaskId);
            }
            _groupCommTaskStarter.QueueTask(taskConfiguration, activeContext);
        }
示例#3
0
 /// <summary>
 /// Construct a TaskInfo that wraps task state, task configuration, and active context for submitting the task
 /// </summary>
 /// <param name="taskState"></param>
 /// <param name="config"></param>
 /// <param name="context"></param>
 internal TaskInfo(TaskStateMachine taskState, IConfiguration config, IActiveContext context)
 {
     _taskState         = taskState;
     _taskConfiguration = config;
     _activeContext     = context;
     TimeStateUpdated   = DateTime.Now;
 }
示例#4
0
        private void SubmitNextTask(IActiveContext activeContext)
        {
            Logger.Log(Level.Info, "SubmitNextTask with evaluator id: " + activeContext.EvaluatorId);
            IConfiguration finalConfiguration = GetNextTaskConfiguration();

            if (null != finalConfiguration)
            {
                Logger.Log(Level.Info, "Executing task id " + _taskContext.CurrentTaskId());
                Logger.Log(Level.Info, string.Format(CultureInfo.InvariantCulture, "Submitting Task {0}", _taskContext.CurrentTaskId()));

                activeContext.SubmitTask(finalConfiguration);
            }
            else
            {
                if (_taskContext.TaskCompleted == _taskContext.TotalTasks)
                {
                    Logger.Log(Level.Info, "All tasks submitted and completed, active context remains idle");
                    _driveStatus = DriverStatus.Idle;
                    if (!_isRetain)
                    {
                        activeContext.Dispose();
                    }
                }
            }
        }
        public void OnNext(ICompletedTask value)
        {
            IActiveContext activeContext = value.ActiveContext;

            LOGGER.Log(Level.Info, string.Format(CultureInfo.InvariantCulture, "Received CompletedTask: {0} :: CLOSING context: {1}", value.Id, activeContext.Id));
            activeContext.Dispose();
        }
示例#6
0
        public void OnNext(IActiveContext activeContext)
        {
            if (_groupCommDriver.IsMasterTaskContext(activeContext))
            {
                // Configure Master Task
                IConfiguration partialTaskConf = TaskConfiguration.ConfigurationModule
                                                 .Set(TaskConfiguration.Identifier, GroupTestConstants.MasterTaskId)
                                                 .Set(TaskConfiguration.Task, GenericType <MasterTask> .Class)
                                                 .Build();

                _commGroup.AddTask(GroupTestConstants.MasterTaskId);
                _groupCommTaskStarter.QueueTask(partialTaskConf, activeContext);
            }
            else
            {
                // Configure Slave Task
                string slaveTaskId = GroupTestConstants.SlaveTaskId +
                                     _groupCommDriver.GetContextNum(activeContext);

                IConfiguration partialTaskConf = TaskConfiguration.ConfigurationModule
                                                 .Set(TaskConfiguration.Identifier, slaveTaskId)
                                                 .Set(TaskConfiguration.Task, GenericType <SlaveTask> .Class)
                                                 .Build();

                _commGroup.AddTask(slaveTaskId);
                _groupCommTaskStarter.QueueTask(partialTaskConf, activeContext);
            }
        }
示例#7
0
 public void OnNext(IActiveContext value)
 {
     value.SubmitTask(TaskConfiguration.ConfigurationModule
                      .Set(TaskConfiguration.Identifier, TaskId)
                      .Set(TaskConfiguration.Task, GenericType <SleepTask> .Class)
                      .Build());
 }
示例#8
0
        /// <summary>
        /// Create a mock IActiveContext
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        private static IActiveContext CreateMockActiveContext(int id)
        {
            IActiveContext mockActiveContext = Substitute.For <IActiveContext>();

            mockActiveContext.Id.Returns(ContextIdPrefix + id);
            mockActiveContext.EvaluatorId.Returns(EvaluatorIdPrefix + ContextIdPrefix + id);
            return(mockActiveContext);
        }
示例#9
0
 public void OnNext(IActiveContext value)
 {
     lock (_lock)
     {
         value.SubmitTask(GetTaskConfigurationForCloseTask(TaskId + _taskNumber));
         _taskContextMapping.Add(TaskId + _taskNumber, value.Id);
         _taskNumber++;
     }
 }
示例#10
0
        public void OnNext(IActiveContext value)
        {
            if (!_evaluators.ContainsKey(value.EvaluatorId))
            {
                throw new Exception("Received active context from unexpected Evaluator " + value.EvaluatorId);
            }

            Logger.Log(Level.Info, "{0} active context {1} from evaluator with ID [{2}].", _evaluators[value.EvaluatorId], value.Id, value.EvaluatorId);
        }
示例#11
0
        private void StartTask(
            string taskId,
            IConfiguration userPartialTaskConf,
            IActiveContext activeContext)
        {
            IConfiguration groupCommTaskConfiguration = _groupCommDriver.GetGroupCommTaskConfiguration(taskId);
            IConfiguration mergedTaskConf             = Configurations.Merge(userPartialTaskConf, groupCommTaskConfiguration);

            activeContext.SubmitTask(mergedTaskConf);
        }
示例#12
0
 public void OnNext(IActiveContext activeContext)
 {
     using (Logger.LogFunction("HelloSimpleEventHandlers::activeContext received"))
     {
         Logger.Log(Level.Info, string.Format(CultureInfo.InvariantCulture, "Received activeContext, EvaluatorId id: {0}", activeContext.EvaluatorId));
         _activeContexts.Add(activeContext);
         _driveStatus = DriverStatus.RunningTasks;
         SubmitNextTask(activeContext);
     }
 }
示例#13
0
 public void OnNext(IActiveContext value)
 {
     Logger.Log(Level.Info, "ActiveContext: " + value.Id);
     value.SubmitTask(TaskConfiguration.ConfigurationModule
                      .Set(TaskConfiguration.Identifier, TaskId + Interlocked.Increment(ref _taskNumber))
                      .Set(TaskConfiguration.Task, GenericType <FailEvaluatorTask> .Class)
                      .Set(TaskConfiguration.OnMessage, GenericType <FailEvaluatorTask> .Class)
                      .Set(TaskConfiguration.OnClose, GenericType <FailEvaluatorTask> .Class)
                      .Build());
 }
示例#14
0
 public void OnNext(ICompletedTask value)
 {
     using (LOGGER.LogFunction("HelloSimpleEventHandlers::CompletedTask received"))
     {
         LOGGER.Log(Level.Info, string.Format(CultureInfo.InvariantCulture, "Received CompletedTask: {0}, task id: {1}", value.Id, _taskContext.CurrentTaskId()));
         _activeContext = value.ActiveContext;
         _taskContext.UpdateTaskStatus(value.Id, TaskStatus.Completed);
         _taskContext.TaskCompleted++;
         SubmitNextTask(value.ActiveContext);
     }
 }
示例#15
0
        public void OnNext(IActiveContext activeContext)
        {
            Logger.Log(Level.Info, "Received IActiveContext");

            const string taskId            = "TaskID";
            var          taskConfiguration = TaskConfiguration.ConfigurationModule
                                             .Set(TaskConfiguration.Identifier, taskId)
                                             .Set(TaskConfiguration.Task, GenericType <MetricsTask> .Class)
                                             .Build();

            activeContext.SubmitTask(taskConfiguration);
        }
示例#16
0
 public BridgeClosedContext(
     string id,
     string evaluatorId,
     Optional <string> parentId,
     IEvaluatorDescriptor evaluatorDescriptor,
     IActiveContext parentContext)
 {
     Id                  = id;
     EvaluatorId         = evaluatorId;
     ParentId            = parentId;
     EvaluatorDescriptor = evaluatorDescriptor;
     ParentContext       = parentContext;
 }
示例#17
0
            public void OnNext(IActiveContext value)
            {
                Logger.Log(Level.Info, "ContextId: " + value.Id);
                if (value.Id != ContextId)
                {
                    throw new Exception("Unexpected ContextId: " + value.Id);
                }

                value.SubmitTask(
                    TaskConfiguration.ConfigurationModule.Set(TaskConfiguration.Identifier, "helloTaskId")
                    .Set(TaskConfiguration.Task, GenericType <HelloTask> .Class)
                    .Build());
            }
示例#18
0
        public void OnNext(IActiveContext activeContext)
        {
            if (_groupCommDriver.IsMasterTaskContext(activeContext))
            {
                Logger.Log(Level.Info, "******* Master ID " + activeContext.Id);

                // Configure Master Task
                var partialTaskConf = TangFactory.GetTang().NewConfigurationBuilder(
                    TaskConfiguration.ConfigurationModule
                    .Set(TaskConfiguration.Identifier, GroupTestConstants.MasterTaskId)
                    .Set(TaskConfiguration.Task, GenericType <PipelinedMasterTask> .Class)
                    .Build())
                                      .BindNamedParameter <GroupTestConfig.NumEvaluators, int>(
                    GenericType <GroupTestConfig.NumEvaluators> .Class,
                    _numEvaluators.ToString(CultureInfo.InvariantCulture))
                                      .BindNamedParameter <GroupTestConfig.NumIterations, int>(
                    GenericType <GroupTestConfig.NumIterations> .Class,
                    _numIterations.ToString(CultureInfo.InvariantCulture))
                                      .BindNamedParameter <GroupTestConfig.ArraySize, int>(
                    GenericType <GroupTestConfig.ArraySize> .Class,
                    _arraySize.ToString(CultureInfo.InvariantCulture))
                                      .Build();

                _commGroup.AddTask(GroupTestConstants.MasterTaskId);
                _groupCommTaskStarter.QueueTask(partialTaskConf, activeContext);
            }
            else
            {
                // Configure Slave Task
                var slaveTaskId     = "SlaveTask-" + activeContext.Id;
                var partialTaskConf = TangFactory.GetTang().NewConfigurationBuilder(
                    TaskConfiguration.ConfigurationModule
                    .Set(TaskConfiguration.Identifier, slaveTaskId)
                    .Set(TaskConfiguration.Task, GenericType <PipelinedSlaveTask> .Class)
                    .Build())
                                      .BindNamedParameter <GroupTestConfig.NumEvaluators, int>(
                    GenericType <GroupTestConfig.NumEvaluators> .Class,
                    _numEvaluators.ToString(CultureInfo.InvariantCulture))
                                      .BindNamedParameter <GroupTestConfig.NumIterations, int>(
                    GenericType <GroupTestConfig.NumIterations> .Class,
                    _numIterations.ToString(CultureInfo.InvariantCulture))
                                      .BindNamedParameter <GroupTestConfig.ArraySize, int>(
                    GenericType <GroupTestConfig.ArraySize> .Class,
                    _arraySize.ToString(CultureInfo.InvariantCulture))
                                      .Build();

                _commGroup.AddTask(slaveTaskId);
                _groupCommTaskStarter.QueueTask(partialTaskConf, activeContext);
            }
        }
示例#19
0
        /// <summary>
        /// Gets the context number associated with the Active Context id.
        /// </summary>
        /// <param name="activeContext">The active context to check</param>
        /// <returns>The context number associated with the active context id</returns>
        public int GetContextNum(IActiveContext activeContext)
        {
            if (activeContext.Id.Equals(MasterTaskContextName))
            {
                return(0);
            }

            string[] parts = activeContext.Id.Split('-');
            if (parts.Length != 2)
            {
                throw new ArgumentException("Invalid id in active context");
            }

            return(int.Parse(parts[1], CultureInfo.InvariantCulture));
        }
示例#20
0
        public void OnNext(IActiveContext activeContext)
        {
            const string taskId = "TaskID";

            Logger.Log(Level.Info, SendingMessageToContextLog);
            activeContext.SendMessage(ByteUtilities.StringToByteArrays(Message));

            var taskConfiguration = TaskConfiguration.ConfigurationModule
                                    .Set(TaskConfiguration.Identifier, taskId)
                                    .Set(TaskConfiguration.Task, GenericType <MessageTask> .Class)
                                    .Set(TaskConfiguration.OnMessage, GenericType <MessageTask> .Class)
                                    .Set(TaskConfiguration.OnSendMessage, GenericType <MessageTask> .Class)
                                    .Build();

            activeContext.SubmitTask(taskConfiguration);
        }
示例#21
0
        /// <summary>
        /// Queues the task into the TaskStarter.
        /// 
        /// Once the correct number of tasks have been queued, the final Configuration
        /// will be generated and run on the given Active Context.
        /// </summary>
        /// <param name="partialTaskConfig">The partial task configuration containing Task
        /// identifier and Task class</param>
        /// <param name="activeContext">The Active Context to run the Task on</param>
        public void QueueTask(IConfiguration partialTaskConfig, IActiveContext activeContext)
        {
            string taskId = Utils.GetTaskId(partialTaskConfig); 
            LOGGER.Log(Level.Verbose, "Adding context with identifier: " + taskId);
            
            lock (_lock)
            {
                _taskTuples.Add(
                    new Tuple<string, IConfiguration, IActiveContext>(taskId, partialTaskConfig, activeContext));

                if (Interlocked.Increment(ref _tasksAdded) == _numTasks)
                {
                    StartTasks();
                }
            }
        }
示例#22
0
        public void OnNext(IRunningTask runningTask)
        {
            IActiveContext context = runningTask.ActiveContext;

            string messageStr = string.Format(
                CultureInfo.InvariantCulture,
                "HelloRunningTaskHandler: Task [{0}] is running. Evaluator id: [{1}].",
                runningTask.Id,
                context.EvaluatorId);

            Console.WriteLine(messageStr);

            byte[] message = ByteUtilities.StringToByteArrays(messageStr);

            runningTask.Send(message);
        }
示例#23
0
        /// <summary>
        /// Queues the task into the TaskStarter.
        ///
        /// Once the correct number of tasks have been queued, the final Configuration
        /// will be generated and run on the given Active Context.
        /// </summary>
        /// <param name="partialTaskConfig">The partial task configuration containing Task
        /// identifier and Task class</param>
        /// <param name="activeContext">The Active Context to run the Task on</param>
        public void QueueTask(IConfiguration partialTaskConfig, IActiveContext activeContext)
        {
            string taskId = Utils.GetTaskId(partialTaskConfig);

            LOGGER.Log(Level.Verbose, "Adding context with identifier: " + taskId);

            lock (_lock)
            {
                _taskTuples.Add(
                    new Tuple <string, IConfiguration, IActiveContext>(taskId, partialTaskConfig, activeContext));

                if (Interlocked.Increment(ref _tasksAdded) == _numTasks)
                {
                    StartTasks();
                }
            }
        }
        public void OnNext(IRunningTask runningTask)
        {
            IActiveContext context = runningTask.ActiveContext;

            Console.WriteLine(string.Format(
                CultureInfo.InvariantCulture,
                "HelloDriverRestartRunningTaskHandler: Task [{0}] is running after driver restart. Evaluator id: [{1}].",
                runningTask.Id,
                context.EvaluatorId));

            runningTask.Send(ByteUtilities.StringToByteArrays(
                string.Format(
                CultureInfo.InvariantCulture,
                "Hello, task {0}! Glad to know that you are still running in Evaluator {1} after driver restart!",
                runningTask.Id,
                context.EvaluatorId)));
        }
            /// <summary>
            /// Submits the failing Context config on the non-failing Context.
            /// </summary>
            public void OnNext(IActiveContext value)
            {
                lock (_lock)
                {
                    Logger.Log(Level.Info, ActiveContextReceived);
                    Assert.False(_shouldFailOnRootContext);

                    var ctxConf = ContextConfiguration.ConfigurationModule
                                  .Set(ContextConfiguration.Identifier, Context2)
                                  .Build();

                    var serviceConf = ServiceConfiguration.ConfigurationModule
                                      .Set(ServiceConfiguration.Services, GenericType <ServiceConstructorExceptionService> .Class)
                                      .Build();

                    value.SubmitContextAndService(ctxConf, serviceConf);
                }
            }
示例#26
0
        public void OnNext(IActiveContext activeContext)
        {
            IConfiguration serviceConfig = _groupCommDriver.GetServiceConfiguration();

            if (_groupCommDriver.IsMasterTaskContext(activeContext))
            {
                // Configure Master Task
                IConfiguration partialTaskConf = TangFactory.GetTang().NewConfigurationBuilder(
                    TaskConfiguration.ConfigurationModule
                    .Set(TaskConfiguration.Identifier, GroupTestConstants.MasterTaskId)
                    .Set(TaskConfiguration.Task, GenericType <MasterTask> .Class)
                    .Build())
                                                 .BindNamedParameter <GroupTestConfig.NumEvaluators, int>(
                    GenericType <GroupTestConfig.NumEvaluators> .Class,
                    _numEvaluators.ToString(CultureInfo.InvariantCulture))
                                                 .BindNamedParameter <GroupTestConfig.NumIterations, int>(
                    GenericType <GroupTestConfig.NumIterations> .Class,
                    _numIterations.ToString(CultureInfo.InvariantCulture))
                                                 .Build();

                _commGroup.AddTask(GroupTestConstants.MasterTaskId);
                _groupCommTaskStarter.QueueTask(partialTaskConf, activeContext);
            }
            else
            {
                // Configure Slave Task
                string         slaveTaskId     = "SlaveTask-" + activeContext.Id;
                IConfiguration partialTaskConf = TangFactory.GetTang().NewConfigurationBuilder(
                    TaskConfiguration.ConfigurationModule
                    .Set(TaskConfiguration.Identifier, slaveTaskId)
                    .Set(TaskConfiguration.Task, GenericType <SlaveTask> .Class)
                    .Build())
                                                 .BindNamedParameter <GroupTestConfig.NumEvaluators, int>(
                    GenericType <GroupTestConfig.NumEvaluators> .Class,
                    _numEvaluators.ToString(CultureInfo.InvariantCulture))
                                                 .BindNamedParameter <GroupTestConfig.NumIterations, int>(
                    GenericType <GroupTestConfig.NumIterations> .Class,
                    _numIterations.ToString(CultureInfo.InvariantCulture))
                                                 .Build();

                _commGroup.AddTask(slaveTaskId);
                _groupCommTaskStarter.QueueTask(partialTaskConf, activeContext);
            }
        }
示例#27
0
        private async void CreateSession(ISessionContext context)
        {
            Settings.IValues settings = _settingsProvider.GetValues();

            Hub.Endpoint.IInstance endpoint = _endpointFactory.Create(settings.HarmonyHubAddress, context.SessionInfo);

            try
            {
                await endpoint.ConnectAsync();

                IActiveContext activeContext = context.Activate(context.SessionInfo, new Hub.Session.Instance(endpoint));

                _messageMediator.Publish(new TransitionToStateMessage <IActiveContext>(Name.Synchronizing, activeContext));
            }
            catch
            {
                _messageMediator.Publish(new TransitionToStateMessage <IContext>(Name.Stopped, context));
            }
        }
示例#28
0
文件: FailDriver.cs 项目: wonook/reef
 public void OnNext(IActiveContext context)
 {
     CheckMsgOrder(context);
     try
     {
         context.SubmitTask(TaskConfiguration.ConfigurationModule
                            .Set(TaskConfiguration.Identifier, "FailTask_" + context.Id)
                            .Set(TaskConfiguration.Task, GenericType <NoopTask> .Class)
                            .Set(TaskConfiguration.OnMessage, GenericType <NoopTask> .Class)
                            .Set(TaskConfiguration.OnSuspend, GenericType <NoopTask> .Class)
                            .Set(TaskConfiguration.OnClose, GenericType <NoopTask> .Class)
                            .Set(TaskConfiguration.OnTaskStop, GenericType <NoopTask> .Class)
                            .Set(TaskConfiguration.OnSendMessage, GenericType <NoopTask> .Class)
                            .Build());
     }
     catch (BindException ex)
     {
         Log.Log(Level.Warning, "Task configuration error", ex);
         throw new IllegalStateException("task configuration error", ex);
     }
 }
示例#29
0
        /// <summary>
        /// Adds an IActiveContext to the ActiveContext collection
        /// Throws IMRUSystemException if the IActiveContext already exists or NumberOfActiveContexts has exceeded the total expected contexts
        /// </summary>
        /// <param name="activeContext"></param>
        internal void Add(IActiveContext activeContext)
        {
            if (_activeContexts.ContainsKey(activeContext.Id))
            {
                var msg = string.Format(CultureInfo.InvariantCulture, "The context [{0}] received already exists.", activeContext.Id);
                Exceptions.Throw(new IMRUSystemException(msg), Logger);
            }

            if (NumberOfActiveContexts >= _totalExpectedContexts)
            {
                var msg = string.Format(CultureInfo.InvariantCulture, "Trying to add an extra active context {0}. The total number of the active contexts has reached to the expected number {1}.", activeContext.Id, _totalExpectedContexts);
                Exceptions.Throw(new IMRUSystemException(msg), Logger);
            }

            _activeContexts.Add(activeContext.Id, activeContext);

            if (AreAllContextsReceived && _activeContextObserver != null)
            {
                _activeContextObserver.OnNext(_activeContexts);
            }
        }
 public void OnNext(IActiveContext value)
 {
     if (value.Id.Equals(FailEvaluatorContextId))
     {
         // Close context and trigger failure immediately.
         value.Dispose();
     }
     else
     {
         if (value.Id.Equals(ContextId0))
         {
             // Stack Context with ContextId1 on top of Context with ContextId0.
             value.SubmitContext(GetContextStopExceptionContextConfiguration(ContextId1));
         }
         else
         {
             // Verify the stacked Context and close it.
             Assert.Equal(ContextId1, value.Id);
             value.Dispose();
         }
     }
 }
示例#31
0
        /// <summary>
        /// Specifies the Map or Update task to run on the active context
        /// </summary>
        /// <param name="activeContext"></param>
        public void OnNext(IActiveContext activeContext)
        {
            Logger.Log(Level.Verbose, string.Format("Received Active Context {0}", activeContext.Id));

            if (_serviceAndContextConfigurationProvider.IsMasterEvaluatorId(activeContext.EvaluatorId))
            {
                Logger.Log(Level.Verbose, "Submitting master task");
                _commGroup.AddTask(IMRUConstants.UpdateTaskName);
                _groupCommTaskStarter.QueueTask(GetUpdateTaskConfiguration(), activeContext);
                RequestMapEvaluators(_totalMappers);
            }
            else
            {
                Logger.Log(Level.Verbose, "Submitting map task");
                _serviceAndContextConfigurationProvider.RecordActiveContextPerEvaluatorId(activeContext.EvaluatorId);
                string taskId = GetTaskIdByEvaluatorId(activeContext.EvaluatorId);
                _commGroup.AddTask(taskId);
                _groupCommTaskStarter.QueueTask(GetMapTaskConfiguration(activeContext, taskId), activeContext);
                Interlocked.Increment(ref _numberOfReadyTasks);
                Logger.Log(Level.Verbose, string.Format("{0} Tasks are ready for submission", _numberOfReadyTasks));
            }
        }
示例#32
0
        /// <summary>
        /// Adds an IActiveContext to the ActiveContext collection
        /// Throws IMRUSystemException if the IActiveContext already exists or NumberOfActiveContexts has exceeded the total expected contexts
        /// </summary>
        /// <param name="activeContext"></param>
        internal void Add(IActiveContext activeContext)
        {
            if (_activeContexts.ContainsKey(activeContext.Id))
            {
                var msg = string.Format(CultureInfo.InvariantCulture, "The context [{0}] received already exists.", activeContext.Id);
                Exceptions.Throw(new IMRUSystemException(msg), Logger);
            }

            if (NumberOfActiveContexts >= _totalExpectedContexts)
            {
                var msg = string.Format(CultureInfo.InvariantCulture, "Trying to add an extra active context {0}. The total number of the active contexts has reached to the expected number {1}.", activeContext.Id, _totalExpectedContexts);
                Exceptions.Throw(new IMRUSystemException(msg), Logger);
            }

            _activeContexts.Add(activeContext.Id, activeContext);

            if (AreAllContextsReceived && _activeContextObserver != null)
            {
                _activeContextObserver.OnNext(_activeContexts);
            }
        }
示例#33
0
        /// <summary>
        /// Adds a Task to the task collection
        /// Throws IMRUSystemException in the following cases:
        ///   taskId is already added 
        ///   taskConfiguration is null
        ///   activeContext is null
        ///   trying to add extra tasks
        ///   No Master Task is added in the collection
        /// </summary>
        /// <param name="taskId"></param>
        /// <param name="taskConfiguration"></param>
        /// <param name="activeContext"></param>
        internal void AddTask(string taskId, IConfiguration taskConfiguration, IActiveContext activeContext)
        {
            if (taskId == null)
            {
                Exceptions.Throw(new IMRUSystemException("The taskId is null."), Logger);
            }

            if (_tasks.ContainsKey(taskId))
            {
                var msg = string.Format(CultureInfo.InvariantCulture, "The task [{0}] already exists.", taskId);
                Exceptions.Throw(new IMRUSystemException(msg), Logger);
            }

            if (taskConfiguration == null)
            {
                Exceptions.Throw(new IMRUSystemException("The task configuration is null."), Logger);
            }

            if (activeContext == null)
            {
                Exceptions.Throw(new IMRUSystemException("The context is null."), Logger);
            }

            if (NumberOfTasks >= _totalExpectedTasks)
            {
                string msg = string.Format("Trying to add an additional Task {0}, but the total expected Task number {1} has been reached.", taskId, _totalExpectedTasks);
                Exceptions.Throw(new IMRUSystemException(msg), Logger);
            }

            _tasks.Add(taskId, new TaskInfo(new TaskStateMachine(), taskConfiguration, activeContext));

            if (NumberOfTasks == _totalExpectedTasks && !MasterTaskExists())
            {
                Exceptions.Throw(new IMRUSystemException("There is no master task added."), Logger);
            }
        }
示例#34
0
 private void StartTask(
     string taskId,
     IConfiguration userPartialTaskConf,
     IActiveContext activeContext)
 {
     IConfiguration groupCommTaskConfiguration = _groupCommDriver.GetGroupCommTaskConfiguration(taskId);
     IConfiguration mergedTaskConf = Configurations.Merge(userPartialTaskConf, groupCommTaskConfiguration);
     activeContext.SubmitTask(mergedTaskConf);
 }
示例#35
0
 public PrivateContext(IActiveContext context, Hub.Session.IInfo sessionInfo, Hub.Session.IInstance session, Hub.Configuration.IValues harmonyConfiguration) : this((ISessionContext)context, context.SessionInfo, context.Session)
 {
     _harmonyConfiguration = harmonyConfiguration;
 }
示例#36
0
文件: TaskInfo.cs 项目: beomyeol/reef
 /// <summary>
 /// Construct a TaskInfo that wraps task state, task configuration, and active context for submitting the task 
 /// </summary>
 /// <param name="taskState"></param>
 /// <param name="config"></param>
 /// <param name="context"></param>
 internal TaskInfo(TaskStateMachine taskState, IConfiguration config, IActiveContext context)
 {
     _taskState = taskState;
     _taskConfiguration = config;
     _activeContext = context;
 }
示例#37
0
        /// <summary>
        /// Gets the context number associated with the Active Context id.
        /// </summary>
        /// <param name="activeContext">The active context to check</param>
        /// <returns>The context number associated with the active context id</returns>
        public int GetContextNum(IActiveContext activeContext)
        {
            if (activeContext.Id.Equals(MasterTaskContextName))
            {
                return 0;
            }

            string[] parts = activeContext.Id.Split('-');
            if (parts.Length != 2)
            {
                throw new ArgumentException("Invalid id in active context");
            }

            return int.Parse(parts[1], CultureInfo.InvariantCulture);
        }
示例#38
0
 /// <summary>
 /// Checks whether this active context can be used to run the Master Task.
 /// </summary>
 /// <param name="activeContext">The active context to check</param>
 /// <returns>True if the active context can run the Master task,
 /// otherwise false.</returns>
 public bool IsMasterTaskContext(IActiveContext activeContext)
 {
     return activeContext.Id.Equals(MasterTaskContextName);
 }