Esempio n. 1
0
        /**
         * If the child has finished in failure or been terminated, return
         * {@link Status#SUCCESS}. Otherwise, {@link Status#RUNNING} is returned. If
         * the child has finished successfully, it is spawned again.
         *
         * @see jbt.execution.core.ExecutionTask#internalTick()
         */

        protected override Status InternalTick()
        {
            Status childStatus = child.Status;

            /*
             * If the child has finished in failure or been terminated, return
             * success.
             */
            if (childStatus == Status.Failure || childStatus == Status.Terminated)
            {
                return(Status.Success);
            }
            /* If the child has finished successfully, spawn it again. */
            if (childStatus == Status.Success)
            {
                child = ((ModelDecorator)ModelTask).getChild().CreateExecutor(
                    Executor, this);
                child.AddTaskListener(this);
                child.Spawn(Context);
            }

            /*
             * In case the child has not finished in failure, return
             * Status.RUNNING.
             */
            return(Status.Running);
        }
        /**
         * Checks the status of the currently active child. If it is running,
         * {@link Status#RUNNING} is returned. If it has successfully finished, it
         * returns {@link Status#SUCCESS}. If it has failed, it tries to spawn the
         * next child (returning {@link Status#RUNNING}). If it was the last child,
         * returns {@link Status#FAILURE}.
         *
         * @see jbt.execution.core.ExecutionTask#internalTick()
         */

        protected override Status InternalTick()
        {
            var childStatus = _activeChild.Status;

            if (childStatus == Status.Running)
            {
                return(Status.Running);
            }
            if (childStatus == Status.Success)
            {
                return(Status.Success);
            }

            /* If it was the last child of the list, return failure. */
            if (_activeChildIndex == _children.Count - 1)
            {
                return(Status.Failure);
            }

            _activeChildIndex++;
            _activeChild = _children[_order[_activeChildIndex]].CreateExecutor(Executor, this);
            _activeChild.AddTaskListener(this);
            _activeChild.Spawn(Context);
            return(Status.Running);
        }
        /**
         * Spawns the first task (randomly selected).
         *
         * @see jbt.execution.core.ExecutionTask#internalSpawn()
         */

        protected override void InternalSpawn()
        {
            _children = ModelTask.Children;

            /*
             * First we initialize the list with the order in which the list of
             * children will be evaluated.
             */
            _order = new List <int>();
            for (int i = 0; i < _children.Count; i++)
            {
                _order.Add(i);
            }

            var rnd = new Random();

            _order = _order.OrderBy(i => rnd.Next()).ToList();

            /*
             * Then we spawn the first child.
             */
            _activeChildIndex = 0;
            _activeChild      = _children[_order[_activeChildIndex]].CreateExecutor(Executor, this);
            _activeChild.AddTaskListener(this);
            _activeChild.Spawn(Context);
        }
        /**
         * This method first retrieve from the context the tree (ModelTask) that is
         * going to be emulated by this task. Then, it creates its corresponding
         * executor and finally spawns it. If the tree cannot be found in the
         * context, does nothing.
         *
         * @see jbt.execution.core.ExecutionTask#internalSpawn()
         */

        protected override void InternalSpawn()
        {
            /* Retrieve the tree to run from the context. */
            treeToRun = Context.GetBT(
                ((ModelSubtreeLookup)ModelTask).TreeName);

            if (treeToRun == null)
            {
                treeRetrieved = false;

                /*
                 * Must request to be inserted into the list of tickable nodes,
                 * since no tree has been retrieved and as a result it must be the
                 * task the one continuin the work.
                 */
                Executor.RequestInsertionIntoList(BTExecutor.BTExecutorList.Tickable, this);
                //			System.err.println("Could not retrieve tree "
                //					+ ((ModelSubtreeLookup) this.getModelTask()).getTreeName()
                //					+ " from the context. Check if the context has been properly initialized.");
            }
            else
            {
                treeRetrieved = true;
                /* Compute positions for the retrieved tree. */
                treeToRun.ComputePositions();

                executionTree = treeToRun.CreateExecutor(Executor, this);
                executionTree.AddTaskListener(this);
                executionTree.Spawn(Context);
            }
        }
Esempio n. 5
0
        public override bool CheckAndEstimate(ExecutionTask task)
        {
            if (task.To.Files?.Count != 1)
            {
                return(false);
            }

            var template = task.To.Files[0].Value;

            var match = parameterDetection.Match(template);

            if (!match.Success)
            {
                return(false);
            }
            do
            {
                SupportedParameters par;
                var param      = match.Groups[1].Value;
                var paramValue = match.Groups[2].Value;
                if (!Enum.TryParse(paramValue, out par))
                {
                    return(false);
                }
                template = template.Replace(param, string.Empty);
                match    = parameterDetection.Match(template);
            } while (match.Success);

            task.Estimation = TimeSpan.FromSeconds(5);

            return(true);
        }
Esempio n. 6
0
        /**
         * Spawns the child task.
         *
         * @see jbt.execution.core.ExecutionTask#internalSpawn()
         */

        protected override void InternalSpawn()
        {
            child = ((ModelDecorator)ModelTask).getChild().CreateExecutor(
                Executor, this);
            child.AddTaskListener(this);
            child.Spawn(Context);
        }
Esempio n. 7
0
        public void Release(ExecutionTask task)
        {
            if (task == null)
            {
                throw new ArgumentNullException(nameof(task));
            }
            if (CurrentTask != null)
            {
                if (CurrentTask.Urn != task.Urn)
                {
                    throw new PluginException("taskUrn mismatch");
                }
                if (CurrentTask.State == ExecutionState.Running)
                {
                    throw new PluginException("Can not release running task.");
                }
                CurrentTask = null;
            }

            if (task.State == ExecutionState.Done &&
                task.Arguments.ContainsKey("TemporaryEssence") &&
                task.Arguments["TemporaryEssence"] == "From")
            {
                try
                {
                    DeleteFilesInEssence(task.From);
                }
                catch (Exception e)
                {
                    Logging.LogException(e, "Unable to clean up temp files.", task.Urn);
                }
            }

            task.EndTime = TimeProvider.GetUtcNow();
        }
        /**
         * Checks if the currently active child has finished. It it has not, it
         * returns {@link Status#RUNNING}. If it has finished successfully, it
         * returns {@link Status#SUCCESS}. If it has finished in failure, then:
         * <ul>
         * <li>If it was the last child of the selector, returns
         * {@link Status#FAILURE}.
         * <li>Otherwise, it spawns the next child of the selector and returns
         * {@link Status#RUNNING}.
         * </ul>
         *
         * @see jbt.execution.core.ExecutionTask#internalTick()
         */

        protected override Status InternalTick()
        {
            Status childStatus = _activeChild.Status;

            if (childStatus == Status.Running)
            {
                return(Status.Running);
            }
            if (childStatus == Status.Success)
            {
                return(Status.Success);
            }

            /*
             * If the current child has failed, and it was the last one, return
             * failure.
             */
            if (_activeChildIndex == _children.Count - 1)
            {
                return(Status.Failure);
            }

            /*
             * Otherwise, if it was not the last child, spawn the next
             * child.
             */
            _activeChildIndex++;
            _activeChild = _children[_activeChildIndex].CreateExecutor(Executor, this);
            _activeChild.AddTaskListener(this);
            _activeChild.Spawn(Context);
            return(Status.Running);
        }
Esempio n. 9
0
        /**
         * Checks if the currently active child has finished. If it has not
         * finished, returns {@link Status#SUCCESS}. If it has finished in failure,
         * returns {@link Status#FAILURE}. If it has finished successfully, it
         * checks if there is any remaining child. If so, it spawns it. Otherwise,
         * returns {@link Status#SUCCESS}.
         */
        protected override Status InternalTick()
        {
            Status childStatus = _activeChild.Status;

            if (childStatus == Status.Running)
            {
                return(Status.Running);
            }
            if (childStatus == Status.Failure || childStatus == Status.Terminated)
            {
                return(Status.Failure);
            }
            if (_activeChildIndex == _children.Count - 1)
            {
                /*
                 * If this was the last child, return success.
                 */
                return(Status.Success);
            }

            /*
             * If the current child has finished successfully, but it is not
             * the last one, spawn the next child.
             */
            _activeChildIndex++;
            _activeChild = _children[_activeChildIndex].CreateExecutor(Executor, this);
            _activeChild.AddTaskListener(this);
            _activeChild.Spawn(Context);
            return(Status.Running);
        }
Esempio n. 10
0
 /// <summary>
 /// Takes executiontasks to and form essence and converts it to executionessence with the corret type
 /// </summary>
 private static ICollection <execution_essence> ExecutionEssenceToEsscenlist(ExecutionTask executionTask, ICollection <execution_essence> destExecutionEssences)
 {
     if (destExecutionEssences.Any())
     {
         var fromEssence =
             destExecutionEssences.First(e => e.executionEssenceType == (int)ExecutionEssenceType.From).essence;
         Mapper.Map(executionTask.From, fromEssence);
         var toEssence =
             destExecutionEssences.First(e => e.executionEssenceType == (int)ExecutionEssenceType.To).essence;
         Mapper.Map(executionTask.To, toEssence);
     }
     else
     {
         destExecutionEssences.Add(
             new execution_essence
         {
             essence = Mapper.Map <essence>(executionTask.From),
             executionEssenceType = (int)ExecutionEssenceType.From
         });
         destExecutionEssences.Add(
             new execution_essence
         {
             essence = Mapper.Map <essence>(executionTask.To),
             executionEssenceType = (int)ExecutionEssenceType.To
         });
     }
     return(destExecutionEssences);
 }
        /**
         * Constructs an ExecutionRandomSelector to run a specific ModelRandomSelector.
         *
         * @param modelTask
         *            the ModelRandomSelector to run.
         * @param executor
         *            the BTExecutor that will manage this ExecutionRandomSelector.
         * @param parent
         *            the parent ExecutionTask of this task.
         */

        public ExecutionRandomSelector(ModelTask modelTask, BTExecutor executor, ExecutionTask parent)
            : base(modelTask, executor, parent)
        {
            if (!(modelTask is ModelRandomSelector))
            {
                throw new ArgumentException("The ModelTask must subclass ModelRandomSelector but it inherits from " + modelTask.GetType().Name);
            }
        }
Esempio n. 12
0
        /**
         * Constructs an ExecutionAction that knows how to run a ModelAction.
         *
         * @param modelTask
         *            the ModelAction to run.
         * @param executor
         *            the BTExecutor that will manage this ExecutionAction.
         * @param parent
         *            the parent ExecutionTask of this task.
         */

        protected ExecutionAction(ModelAction modelTask, BTExecutor executor, ExecutionTask parent)
            : base(modelTask, executor, parent)
        {
            if (modelTask == null)
            {
                throw new ArgumentException("The ModelTask must not be null");
            }
        }
 public void Execute(ExecutionTask task)
 {
     if (!active)
     {
         return;
     }
     Submit(task);
 }
 public void Submit(ExecutionTask task)
 {
     if (!active)
     {
         return;
     }
     queue.Enqueue(new QueuedTask(task, FreeId()));
 }
        /**
         * Spawns the only child.
         *
         * @see jbt.execution.core.ExecutionTask#internalSpawn()
         */

        protected override void InternalSpawn()
        {
            /* Just spawn the only child. */
            child = ((ModelInverter)ModelTask).getChild().CreateExecutor(
                Executor, this);
            child.AddTaskListener(this);
            child.Spawn(Context);
        }
Esempio n. 16
0
        /**
         * Constructs an ExecutionLeaf to run a specific ModelLeaf.
         *
         * @param modelTask
         *            the ModelLeaf to run.
         * @param executor
         *            the BTExecutor that will manage this ExecutionLeaf.
         * @param parent
         *            the parent ExecutionTask of this task.
         */

        protected ExecutionLeaf(ModelTask modelTask, BTExecutor executor, ExecutionTask parent)
            : base(modelTask, executor, parent)
        {
            if (!(modelTask is ModelLeaf))
            {
                throw new ArgumentException("The ModelTask must subclass ModelLeaf but it inherits from " + modelTask.GetType().Name);
            }
        }
 /**
  * Spawns the first child.
  *
  * @see jbt.execution.core.ExecutionTask#internalSpawn()
  */
 protected override void InternalSpawn()
 {
     _activeChildIndex = 0;
     _children         = ModelTask.Children;
     _activeChild      = _children[_activeChildIndex].CreateExecutor(Executor, this);
     _activeChild.AddTaskListener(this);
     _activeChild.Spawn(Context);
 }
Esempio n. 18
0
        public override bool CheckAndEstimate(ExecutionTask task)
        {
            InternalTaskCheck(task);
            // Check from and to essence
            if (Enum.GetValues(typeof(StateFlags))
                .Cast <StateFlags>()
                .Where(value => value != StateFlags.Logo) // allow logo burn in
                .Any(value => task.To.Flags.HasFlag(value) != task.From.Flags.HasFlag(value)))
            {
                // unsupported task
                return(false);
            }

            if (!SupportedSourceFormats.Contains(task.From.Format))
            {
                return(false);
            }

            if (!SupportedDestinationFormats.Contains(task.To.Format))
            {
                return(false);
            }

            if (task.From.Files.Count != 1)
            {
                return(false);
            }

            if (task.To.Files?.Count > 0)
            {
                return(false);
            }

            if (string.IsNullOrEmpty(task.From.Path))
            {
                return(false);
            }

            if (string.IsNullOrEmpty(task.To.Path))
            {
                return(false);
            }

            // Set task estimation
            if (new [] { StateFormat.dv, StateFormat.dv5p, StateFormat.dvh5, StateFormat.dvhq, StateFormat.dvpp }
                .Contains(task.From.Format))
            {
                task.Estimation = TimeSpan.FromMilliseconds(task.From.Duration / 2.5);
            }
            else
            {
                task.Estimation = TimeSpan.FromMilliseconds(task.From.Duration / 1.3);
            }

            task.Estimation += TimeSpan.FromMinutes(1); //spin up time

            return(true);
        }
Esempio n. 19
0
        public void CompileAndExecute(string solutionId)
        {
            var task = new ExecutionTask {
                UserId = Context.User.Id(), Command = Command.CompileAndExecute, Data = solutionId
            };

            _taskQueue.Enqueue(task);
            _logger.LogInformation(Command.CompileAndExecute.ToString() + " request added to Background Task Queue");
        }
Esempio n. 20
0
        ///Spawns its child and registers itself into the list of interrupters of
        ///the BTExecutor.
        ///
        protected override void InternalSpawn()
        {
            _executionChild = ((ModelInterrupter)ModelTask).getChild().CreateExecutor(Executor, this);
            _executionChild.AddTaskListener(this);

            //Register the ExecutionInterrupter so that ExecutionPerformInterruption can find it.
            Executor.RegisterInterrupter(this);
            _executionChild.Spawn(Context);
        }
        /**
         * Creates an ExecutionComposite that is able to run a particular
         * ModelComposite task.
         *
         * @param modelTask
         *            the ModelComposite task to run.
         * @param executor
         *            the BTExecutor that will manage this ExecutionComposite.
         * @param parent
         *            the parent ExecutionTask of this task.
         */

        protected ExecutionComposite(ModelTask modelTask, IBTExecutor executor, ExecutionTask parent)
            : base(modelTask, executor, parent)
        {
            if (!(modelTask is ModelComposite))
            {
                throw new ArgumentException("The ModelTask must subclass " + typeof(ModelComposite).Name + " but it inherits from " +
                                            modelTask.GetType().Name);
            }
        }
Esempio n. 22
0
        /**
         * Constructs and ExecutionUntilFail that knows how to run a ModelUntilFail.
         *
         * @param modelTask
         *            the ModelUntilFail that this ExecutionUntilFail will run.
         * @param executor
         *            the BTExecutor that will manage this ExecutionUntilFail.
         * @param parent
         *            the parent ExecutionTask of this task.
         */

        public ExecutionUntilFail(ModelTask modelTask, BTExecutor executor, ExecutionTask parent)
            : base(modelTask, executor, parent)
        {
            if (!(modelTask is ModelUntilFail))
            {
                throw new ArgumentException("The ModelTask must subclass ModelUntilFail but it inherits from " +
                                            modelTask.GetType().Name);
            }
        }
        /**
         * Constructs an ExecutionSubtreeLookup that knows how to run a
         * ModelSubtreeLookup.
         *
         * @param modelTask
         *            the ModelSubtreeLookup to run.
         * @param executor
         *            the BTExecutor that will manage this ExecutionSubtreeLookup.
         * @param parent
         *            the parent ExecutionTask of this task.
         */

        public ExecutionSubtreeLookup(ModelTask modelTask, BTExecutor executor, ExecutionTask parent)
            : base(modelTask, executor, parent)
        {
            if (!(modelTask is ModelSubtreeLookup))
            {
                throw new ArgumentException("The ModelTask must subclass ModelSubtreeLookup but it inherits from " +
                                            modelTask.GetType().Name);
            }
        }
Esempio n. 24
0
        public static void LogTick(ExecutionTask task)
        {
            if (ActiveDebugger == null)
            {
                return;
            }

            ActiveDebugger.LogTick(task);
        }
        /**
         * Constructs an ExecutionSafeContextManager that knows how to run a
         * ModelSafeContextManager.
         *
         * @param modelTask
         *            the ModelSafeContextManager to run.
         * @param executor
         *            the BTExecutor that will manage this
         *            ExecutionSafeContextManager.
         * @param parent
         *            the parent ExecutionTask of this task.
         */

        public ExecutionSafeContextManager(ModelTask modelTask, BTExecutor executor, ExecutionTask parent)
            : base(modelTask, executor, parent)
        {
            if (!(modelTask is ModelSafeContextManager))
            {
                throw new ArgumentException("The ModelTask must subclass ModelSafeContextManager but it inherits from " +
                                            modelTask.GetType().Name);
            }
        }
Esempio n. 26
0
        /**
         * Creates an ExecutionStaticPriorityList that is able to run a
         * ModelStaticPriorityList task and that is managed by a BTExecutor.
         *
         * @param modelTask
         *            the ModelStaticPriorityList that this
         *            ExecutionStaticPriorityList is going to run.
         * @param executor
         *            the BTExecutor in charge of running this
         *            ExecutionStaticPriorityList.
         * @param parent
         *            the parent ExecutionTask of this task.
         */

        public ExecutionStaticPriorityList(ModelTask modelTask, BTExecutor executor, ExecutionTask parent)
            : base(modelTask, executor, parent)
        {
            if (!(modelTask is ModelStaticPriorityList))
            {
                throw new ArgumentException("The ModelTask must subclass ModelStaticPriorityList but it inherits from " +
                                            modelTask.GetType().Name);
            }
        }
Esempio n. 27
0
        /**
         * Spawns the child task. This method creates a new HierarchicalContext,
         * sets its parent to the context of the ExecutionHierarchicalContextManager, and spawns
         * the child task using this HierarchicalContext.
         *
         * @see jbt.execution.core.ExecutionTask#internalSpawn()
         */

        protected override void InternalSpawn()
        {
            var newContext = new HierarchicalContext();

            newContext.SetParent(Context);
            _child = ((ModelDecorator)ModelTask).getChild().CreateExecutor(
                Executor, this);
            _child.AddTaskListener(this);
            _child.Spawn(newContext);
        }
        /**
         * Creates an ExecutionWait that is able to run a ModelWait task and that is
         * managed by a BTExecutor.
         *
         * @param modelTask
         *            the ModelWait that this ExecutionWait is going to run.
         * @param executor
         *            the BTExecutor in charge of running this ExecutionWait.
         * @param parent
         *            the parent ExecutionTask of this task.
         */

        public ExecutionWait(ModelTask modelTask, BTExecutor executor, ExecutionTask parent)
            : base(modelTask, executor, parent)
        {
            if (!(modelTask is ModelWait))
            {
                throw new ArgumentException("The ModelTask must subclass ModelWait but it inherits from " + modelTask.GetType().Name);
            }

            Initialize(modelTask);
        }
        /**
         * Spawns the child task. This method creates a new SafeOutputContext, and
         * spawns the child task using this SafeContext. The input context of the
         * SafeOutputContext is that of this ExecutionSafeOutputContextManager task.
         * The list of output variables of the SafeOutputContext is retrieved from
         * the ModelSafeOutputContextManager associated to this task.
         *
         * @see jbt.execution.core.ExecutionTask#internalSpawn()
         */

        protected override void InternalSpawn()
        {
            var newContext = new SafeOutputContext(Context,
                                                   ((ModelSafeOutputContextManager)ModelTask).getOutputVariables());

            child = ((ModelDecorator)ModelTask).getChild().CreateExecutor(
                Executor, this);
            child.AddTaskListener(this);
            child.Spawn(newContext);
        }
Esempio n. 30
0
        internal ExecutionTask GetTaskByID(int iTaskId)
        {
            ExecutionTask task = null;

            if (this.Tasks != null)
            {
                task = this.Tasks.First(s => s.Id == iTaskId);
            }
            return(task);
        }
Esempio n. 31
0
 public TaskEvent(ExecutionTask source, TaskStatus newStatus, TaskStatus oldStatus)
 {
     this.NewStatus = newStatus;
     this.PreviousStatus = oldStatus;
     this.Source = source;
 }
Esempio n. 32
0
 /**
  * Creates a TaskEvent with a particular ExcutionTask as source of the
  * event. The source (<code>source</code>) is the task whose status has
  * changed, and <code>newStatus</code> is the new status of the task.
  *
  * @param source
  *            the task whose status has changed.
  * @param newStatus
  *            the new status of the task.
  */
 public TaskEvent(ExecutionTask source, Status newStatus, Status previousStatus)
 {
     _source = source;
     _newStatus = newStatus;
     _previousStatus = previousStatus;
 }