public override object Evaluate(Expression expression, EvaluationContext context)
        {
            TaskRuntime runtime = context as TaskRuntime;

            int count = expression.Parameters.Count;

            if (count == 2)
            {
                // 两个输入参数
                string moduleID = expression.Parameters[0].ToString();
                string key      = expression.Parameters[1].ToString();

                IDictionary output;
                if (!runtime.TaskOutputs.TryGetValue(moduleID, out output))
                {
                    logger.ErrorFormat("没有找到模块{0}的输出参数");
                    return(null);
                }

                if (!output.Contains(key))
                {
                    logger.ErrorFormat("模块{0}的输出不存在参数:{1}", moduleID, key);
                    return(null);
                }

                return(output[key]);
            }

            return(null);
        }
예제 #2
0
        public override object Evaluate(Expression expression, EvaluationContext context)
        {
            TaskRuntime runtime     = context as TaskRuntime;
            string      source      = expression.Parameters[0].ToString();
            string      trim_string = expression.Parameters[1].ToString();

            return(source.TrimStart(trim_string.ToArray()));
        }
예제 #3
0
        public override object Evaluate(Expression expression, EvaluationContext context)
        {
            TaskRuntime runtime = context as TaskRuntime;
            object      key     = expression.Parameters[0];

            if (!runtime.ViewData.Contains(key))
            {
                logger.ErrorFormat("不存在ViewData:{0}", key);
                return(null);
            }

            return(runtime.ViewData[key]);
        }
예제 #4
0
        /// <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);
                }
            }
        }
예제 #5
0
        static public bool doTask(MarsTaskWrapperBase netScene)
        {
            lock (sObjLocker)
            {
                if (null == netScene || sMapSeqToTask.ContainsKey(netScene.mTaskId))
                {
                    return(false);
                }

                TaskRuntime task = netScene.getTask();
                if (null == task)
                {
                    return(false);
                }

                StnComponent.StartTask(task);

                sMapSeqToTask[netScene.mTaskId] = netScene;

                return(true);
            }
        }
예제 #6
0
        /// <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);
                }
            }
        }