コード例 #1
0
        /// <summary>
        /// cloneTask override method for PooledTaskBroker.
        /// </summary>
        /// <remarks></remarks>
        protected override RTask cloneTask(RTask genesis)
        {
            PooledTask source = (PooledTask)genesis;
            PooledTask clone  = null;

            if (source.code != "")
            {
                clone = new PooledTask(source.code,
                                       source.options);
            }
            else
            {
                clone = new PooledTask(source.filename,
                                       source.directory,
                                       source.author,
                                       source.version,
                                       source.options);
            }

            if (source.external != "")
            {
                clone.external = source.external;
            }
            clone.setToken(source.getToken());
            return(clone);
        }
コード例 #2
0
        static public void Execute()
        {
            try {
                /*
                 * 1. Create RBroker instance using RBrokerFactory.
                 *
                 * This example creates a DiscreteTaskBroker.
                 */

                DiscreteBrokerConfig brokerConfig = new DiscreteBrokerConfig(Program.DEPLOYR_ENDPOINT);
                RBroker rBroker = RBrokerFactory.discreteTaskBroker(brokerConfig);

                /*
                 * 2. Register RTaskListener for asynchronous
                 * notifications on RTask completion.
                 */

                SampleTaskBrokerListener sampleListeners = new SampleTaskBrokerListener(rBroker);

                rBroker.addTaskListener(sampleListeners);
                rBroker.addBrokerListener(sampleListeners);


                /*
                 * 3. Define RTask
                 *
                 * This example creates a DiscreteTask that will
                 * execute an R script, /testuser/tutorial-rbroker/5SecondNoOp.
                 */

                RTask rTask = RTaskFactory.discreteTask(Program.TUTORIAL_NOOP_SCRIPT,
                                                        Program.TUTORIAL_REPO_DIRECTORY,
                                                        Program.TUTORIAL_REPO_OWNER,
                                                        "",
                                                        null);

                /*
                 * 4. Submit RTask to RBroker for execution.
                 *
                 * The RTaskToken is returned immediately. You can
                 * use the token to track the progress of RTask
                 * and/or block while waiting for a result.
                 *
                 * However, in this example we are going to allow
                 * the RTaskListener handle the result so
                 * there is nothing further for us to do here after
                 * we submit the RTask.
                 */

                RTaskToken rTaskToken = rBroker.submit(rTask);

                Console.WriteLine("DiscreteProfiling: submitted " + rTask +
                                  " for execution on RBroker.");
            }
            catch (Exception tex)
            {
                Console.WriteLine("DiscreteProfiling: ex=" + tex.ToString());
            }
        }
コード例 #3
0
        /**
            * Prints {@link com.revo.deployr.client.broker.RTaskResult}
            * to console output.
            */
        public static void printRTaskResult(RTask task, RTaskResult result, String error)
        {
            Console.WriteLine("\nTask: " + task);

            if(error != null)
            {
                Console.WriteLine("Status[fail]: cause=" + error);
            }
            else
            {

                switch(result.getType())
                {

                    case RTaskType.DISCRETE:
                        if(result.isSuccess())
                        {
                            Console.WriteLine("Status[ok]: [ code : " +
                                    result.getTimeOnCode() + " , server : " +
                                    result.getTimeOnServer() + " , call : " +
                                    result.getTimeOnCall() + " ]");
                        }
                        else
                        {
                            Console.WriteLine("Status[fail]: cause=" + result.getFailure());
                        }
                        break;

                    case RTaskType.POOLED:
                        if(result.isSuccess())
                        {
                            Console.WriteLine("Status[ok]: [ code : " +
                                    result.getTimeOnCode() + " , server : " +
                                    result.getTimeOnServer() + " , call : " +
                                    result.getTimeOnCall() + " ]");
                        }
                        else
                        {
                            Console.WriteLine("Status[fail]: cause=" + result.getFailure());
                        }
                        break;

                    case RTaskType.BACKGROUND:
                        if(result.isSuccess())
                        {
                            Console.WriteLine("Status[ok]: [ server : " +
                                    result.getTimeOnServer() + " , call : " +
                                    result.getTimeOnCall() + " ]");
                        }
                        else
                        {
                            Console.WriteLine("Status[fail]: cause=" + result.getFailure());
                        }
                        break;

                }
            }
        }
コード例 #4
0
        public async Task UpdateTask(int id, RTask task)
        {
            RTask UpdatedTask = await taskRepository.UpdateTaskById(id, task);

            if (UpdatedTask != null)
            {
                await taskRepository.SaveChanges();
            }
        }
コード例 #5
0
            public void onTaskError(RTask rTask, String error)
            {
                Console.WriteLine("BackgroundBasics: onTaskError: " + rTask + ", error: " + error);

                if (m_rBroker != null)
                {
                    m_rBroker.shutdown();
                    Console.WriteLine("BackgroundBasics: rBroker has been shutdown.");
                }
            }
コード例 #6
0
        /**
         * Prints {@link com.revo.deployr.client.broker.RTaskResult}
         * to console output.
         */
        public static void printRTaskResult(RTask task, RTaskResult result, String error)
        {
            Console.WriteLine("\nTask: " + task);

            if (error != null)
            {
                Console.WriteLine("Status[fail]: cause=" + error);
            }
            else
            {
                switch (result.getType())
                {
                case RTaskType.DISCRETE:
                    if (result.isSuccess())
                    {
                        Console.WriteLine("Status[ok]: [ code : " +
                                          result.getTimeOnCode() + " , server : " +
                                          result.getTimeOnServer() + " , call : " +
                                          result.getTimeOnCall() + " ]");
                    }
                    else
                    {
                        Console.WriteLine("Status[fail]: cause=" + result.getFailure());
                    }
                    break;

                case RTaskType.POOLED:
                    if (result.isSuccess())
                    {
                        Console.WriteLine("Status[ok]: [ code : " +
                                          result.getTimeOnCode() + " , server : " +
                                          result.getTimeOnServer() + " , call : " +
                                          result.getTimeOnCall() + " ]");
                    }
                    else
                    {
                        Console.WriteLine("Status[fail]: cause=" + result.getFailure());
                    }
                    break;

                case RTaskType.BACKGROUND:
                    if (result.isSuccess())
                    {
                        Console.WriteLine("Status[ok]: [ server : " +
                                          result.getTimeOnServer() + " , call : " +
                                          result.getTimeOnCall() + " ]");
                    }
                    else
                    {
                        Console.WriteLine("Status[fail]: cause=" + result.getFailure());
                    }
                    break;
                }
            }
        }
コード例 #7
0
            public void onTaskCompleted(RTask rTask, RTaskResult rTaskResult)
            {
                Console.WriteLine("DiscreteAsynchronous: onTaskCompleted: " + rTask.ToString()
                                  + ", result: " + rTaskResult.getTimeOnCall());

                if (m_rBroker != null)
                {
                    m_rBroker.shutdown();
                    Console.WriteLine("DiscreteAsynchronous: rBroker has been shutdown.");
                }
            }
コード例 #8
0
        /// <summary>
        /// Implementation of the submit method on RBroker interface.
        /// Allows applications to submit a new Task for execution.
        /// </summary>
        /// <param name="task">RTask to be submitted for execution as a discrete task</param>
        /// <param name="priority">priority of task.  If TRUE, then task has a high priority</param>
        /// <returns>RTaskToken for this RTask</returns>
        /// <remarks></remarks>
        public new RTaskToken submit(RTask task, Boolean priority)
        {
            DiscreteTask discreteTask = (DiscreteTask)task;

            if (m_rUser == null && discreteTask.external != "")
            {
                throw new Exception("External script task execution not permitted on anonymous broker.");
            }

            return(submit(task, priority));
        }
コード例 #9
0
 /// <summary>
 /// createBrokerWorker override method for PooledTaskBroker.
 /// </summary>
 /// <remarks></remarks>
 protected override RBrokerWorker createBrokerWorker(RTask task,
                                                     long taskIndex,
                                                     Boolean isPriorityTask,
                                                     Object resourceToken,
                                                     RBrokerEngine brokerEngine)
 {
     return(new PooledTaskWorker((PooledTask)task,
                                 taskIndex,
                                 isPriorityTask,
                                 (RProject)resourceToken,
                                 brokerEngine));
 }
コード例 #10
0
        public async Task <IActionResult> UpdateTask(int taskId, RTask task)
        {
            try
            {
                await taskService.UpdateTask(taskId, task);

                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
コード例 #11
0
 /// <summary>
 /// createBrokerWorker override method for BackgroundTaskBroker.
 /// </summary>
 /// <remarks></remarks>
 protected override RBrokerWorker createBrokerWorker(RTask task,
                                                     long taskIndex,
                                                     Boolean isPriorityTask,
                                                     Object resourceToken,
                                                     RBrokerEngine brokerEngine)
 {
     return(new BackgroundTaskWorker((BackgroundTask)task,
                                     taskIndex,
                                     isPriorityTask,
                                     m_rUser,
                                     (int)resourceToken,
                                     (RBroker)brokerEngine));
 }
コード例 #12
0
        /// <summary>
        /// Returns a resource token for the task back to the token pool.  
        /// /// </summary>
        /// <param name="task">RTask submitted for execution as a background task</param>
        /// <param name="result">RTaskResult containing the results of the completed task</param>
        /// <remarks></remarks>
        public override void callback(RTask task, RTaskResult result)
        {
            Object obj;
            m_taskResourceTokenMap.TryGetValue(task, out obj);
            int resourceToken = (int)obj;

            Boolean added = m_resourceTokenPool.TryAdd(resourceToken);

            if(!added)
            {
                throw new Exception("BackgroundTaskBroker: callback, project could not be added back to pool, ???????.");
            }
        }
コード例 #13
0
 /// <summary>
 /// createBrokerWorker override method for DiscreteTaskBroker.
 /// </summary>
 /// <remarks></remarks>
 protected override RBrokerWorker createBrokerWorker(RTask task,
                                                     long taskIndex,
                                                     Boolean isPriorityTask,
                                                     Object resourceToken,
                                                     RBrokerEngine brokerEngine)
 {
     return(new DiscreteTaskWorker((DiscreteTask)task,
                                   taskIndex,
                                   isPriorityTask,
                                   m_rClient,
                                   (int)resourceToken,
                                   (RBroker)brokerEngine));
 }
コード例 #14
0
        /// <summary>
        /// Returns a resource token for the task back to the token pool.
        /// /// </summary>
        /// <param name="task">RTask submitted for execution as a background task</param>
        /// <param name="result">RTaskResult containing the results of the completed task</param>
        /// <remarks></remarks>
        public override void callback(RTask task, RTaskResult result)
        {
            Object obj;

            m_taskResourceTokenMap.TryGetValue(task, out obj);
            int resourceToken = (int)obj;

            Boolean added = m_resourceTokenPool.TryAdd(resourceToken);

            if (!added)
            {
                throw new Exception("BackgroundTaskBroker: callback, project could not be added back to pool, ???????.");
            }
        }
コード例 #15
0
        public async Task <RTask> AddTaskInProject(string userId, int projectId, RTask newTask)
        {
            if (newTask != null)
            {
                newTask.CreatorId = userId;
                newTask.ProjectId = projectId;
                await taskRepository.SaveTask(newTask);

                await taskRepository.SaveChanges();

                return(newTask);
            }
            throw new NullReferenceException("task must be valid");
        }
コード例 #16
0
        // public async Task<bool> DeleteTask(int taskId)
        // {


        //     if (await IsTaskExist(taskId))
        //     {
        //         await checkPointService.DeleteCheckPointByParentTask(taskId);
        //         var task = await taskRepository.DeleteTaskById(taskId);
        //         await sessionService.DeleteSessionByTask(taskId);
        //         await attachmentService.DeleteAttachmentByTask(taskId);
        //         await commentService.DeleteCommentByTask(taskId);
        //         await taskRepository.RemoveUserTaksbyTask(taskId);
        //         return await taskRepository.SaveChanges();
        //     }



        //     return false;


        // }


        // public async Task<bool> DeleteTaskByTeam(int teamId)
        // {
        //   var Rtasks = await taskRepository.GetTasksByTeam(teamId);

        //     if(Rtasks.Count().Equals(0))
        //     {
        //         return false;
        //     }

        //     foreach(RTask rTask in Rtasks)
        //     {
        //         await DeleteTask(rTask.Id);
        //     }

        //     return true;
        // }

        public async Task <int> AddNewSubTask(string userId, int parentCheckpointId, RTask task)
        {
            if (!await checkpointRepository.IsCheckpointExist(parentCheckpointId))
            {
                throw new Exception("checkpoint not exist");
            }

            task.ParentCheckPointId = parentCheckpointId;
            task.CreatorId          = userId;
            await taskRepository.SaveTask(task);

            await taskRepository.SaveChanges();

            return(task.Id);
        }
コード例 #17
0
 public async Task <IActionResult> AddTaskInTeam(int teamId, RTask task)
 {
     try
     {
         return(Ok(await taskService.AddTaskInTeam(userService.GetUserId(), teamId, task)));
     }
     catch (NullReferenceException e)
     {
         return(BadRequest(e.Message));
     }
     catch (Exception e)
     {
         return(NotFound(e.Message));
     }
 }
コード例 #18
0
        public async Task <IActionResult> AddTaskInProject(int projectId, RTask task)
        {
            try
            {
                var newTask = await taskService.AddTaskInProject(userService.GetUserId(), projectId, task);

                return(Ok(newTask));
            }
            catch (NullReferenceException e)
            {
                return(BadRequest(e.Message));
            }
            catch (Exception e)
            {
                return(NotFound(e.Message));
            }
        }
コード例 #19
0
        /*
         * RTaskAppSimulator method.
         */

        public void simulateApp(RBroker rBroker)
        {
            /*
             * 1. Prepare RTask(s) for simulation.
             *
             * In the example we will simply simulate the execution
             * a fixed number of RTask.
             *
             * Note, this is a somewhat artificial demo as we are
             * executing the same RTask SIMULATE_TOTAL_TASK_COUNT
             * times. You can experiment by modifying the
             * implementation to execute a range of RTask of
             * your own choosing.
             */

            RTask rTask = RTaskFactory.discreteTask(Program.TUTORIAL_NOOP_SCRIPT,
                                                    Program.TUTORIAL_REPO_DIRECTORY,
                                                    Program.TUTORIAL_REPO_OWNER,
                                                    "",
                                                    null);

            /*
             * 2. Loop submitting SIMULATE_TOTAL_TASK_COUNT
             * task(s) to RBroker for execution.
             */

            simulationStartTime = System.Environment.TickCount;

            for (int tasksPushedToBroker = 0;
                 tasksPushedToBroker < SIMULATE_TOTAL_TASK_COUNT;
                 tasksPushedToBroker++)
            {
                try
                {
                    RTaskToken taskToken = rBroker.submit(rTask);
                    Console.WriteLine("simulateApp: submitted task " +
                                      rTask + " for execution on RBroker.");
                }
                catch (Exception ex)
                {
                    Console.WriteLine("simulateApp: ex=" + ex.ToString());
                }
            }
        }
コード例 #20
0
        //not completed
        public async Task <RTask> DeleteTaskById(int taskId)
        {
            RTask task = await context.Tasks.Include(t => t.DependantTasks)
                         .Where(t => t.Id == taskId)
                         .FirstOrDefaultAsync();



            foreach (var dependantTask in task.DependantTasks)
            {
                await DeleteTaskById(dependantTask.Id);
            }
            if (task != null)
            {
                context.Tasks.Remove(task);
            }

            return(task);
        }
コード例 #21
0
        public async Task <int> AddTaskInTeam(string userId, int teamId, RTask newTask)
        {
            if (!await teamRepository.IsTeamExist(teamId))
            {
                throw new Exception("team not exist");
            }
            if (newTask != null)
            {
                if (DateTime.Compare(newTask.PlannedStartDate, newTask.PlannedEndDate) >= 0)
                {
                    throw new DateTimeException(newTask.PlannedStartDate.Date.ToString(), newTask.PlannedEndDate.Date.ToString());
                }
                newTask.CreatorId = userId;
                newTask.TeamId    = teamId;
                await taskRepository.SaveTask(newTask);

                await taskRepository.SaveChanges();
            }

            return(newTask.Id);
        }
コード例 #22
0
        /// <summary>
        /// cloneTask override method for DiscreteTaskBroker.
        /// </summary>
        /// <remarks></remarks>
        protected override RTask cloneTask(RTask genesis)
        {
            DiscreteTask source = (DiscreteTask)genesis;
            DiscreteTask clone  = null;

            if (source.external != "")
            {
                String externalURL = source.external;

                clone = new DiscreteTask(externalURL,
                                         source.options);
            }
            else
            {
                clone = new DiscreteTask(source.filename,
                                         source.directory,
                                         source.author,
                                         source.version,
                                         source.options);
            }
            clone.setToken(source.getToken());

            return(clone);
        }
コード例 #23
0
        /// <summary>
        /// Returns a resource token for the task back to the token pool.  
        /// </summary>
        /// <param name="task">RTask submitted for execution as a background task</param>
        /// <param name="result">RTaskResult containing the results of the completed task</param>
        /// <remarks></remarks>
        public override void callback(RTask task, RTaskResult result)
        {
            Object obj;
            m_taskResourceTokenMap.TryGetValue(task, out obj);
            RProject rProject = (RProject)obj;

            /*
            * Check for Grid Exception
            */
            Boolean bGridException = false;

            Exception failure = result.getFailure();
            if (failure != null)
            {
                if (failure.GetType() == typeof(HTTPRestException))
                {
                    HTTPRestException ex = (HTTPRestException)failure;
                    if (ex.errorCode >= 910 || ex.errorCode ==403)
                    {
                        bGridException = true;
                    }
                }
            }

            if (bGridException == true)
            {

                /*
                * On detection of an RGridException drop the RProject from
                * the pool so further tasks are not directed to that RProject.
                * We achieve this by simply not adding the RProject back to the
                * resourceTokenPool on this callback.
                *
                * We then need to adjust the parallelTaskLimit so the RBroker
                * will report the new (smaller) pool size on
                * RBroker.maxConcurrency() calls.
                */

                if (m_taskListener != null)
                {
                    /*
                    * When asynchronous listener in use, failed task
                    * executions due to slot or grid failures can be
                    * automatically resubmitted for execution by the RBroker.
                    *
                    * When RTaskResult.repeatTask is enabled the
                    * RBrokerEngine.RBrokerListenerManager will skip
                    * calling taskListener.onTaskCompleted(task, result).
                    * This prevents a client application from seeing
                    * (or having to handle) temporary slot or grid related
                    * failures on RTasks.
                    */
                    RTaskResultImpl resultImpl = (RTaskResultImpl)result;
                    resultImpl.repeatTask = true;

                    /*
                    * Now re-submit for execution using the priority
                    * queue to expedite processing.
                    */

                    try
                    {
                        submit(task, true);
                    }
                    catch (Exception tex)
                    {
                        throw new Exception("PooledTaskBroker: callback, task re-submission ex=" + tex.ToString());
                    }
                }

                int resizedPoolSize = (int)Interlocked.Decrement(ref m_parallelTaskLimit);
                if (m_brokerListener != null)
                {
                    Exception rbex;
                    if (resizedPoolSize == 0)
                    {
                        rbex = new Exception("DeployR grid failure detected, pool no longer operational, advise RBroker shutdown.");

                    }
                    else
                    {
                        rbex = new Exception("DeployR grid failure detected, pool size auto-adjusted, max concurrency now " + resizedPoolSize + ".");
                    }
                    m_brokerListener.onRuntimeError(rbex.Message);
                }
            }
            else
            {
                if (rProject != null)
                {
                    Boolean added = m_resourceTokenPool.TryAdd(rProject);

                    if (!added)
                    {
                        throw new Exception("PooledTaskBroker: callback, project could not be added back to pool?");
                    }

                }
                else
                {
                    throw new Exception("PooledTaskBroker: callback, task does not have matching project?");
                }
            }
        }
コード例 #24
0
 /*
  * RBrokerAsyncListener methods.
  */
 public void onTaskCompleted(RTask rTask, RTaskResult rTaskResult)
 {
     RBrokerStatsHelper.printRTaskResult(rTask, rTaskResult, null);
     Console.WriteLine("onTaskCompleted: " + rTask + ", score " +
         ((RNumeric)rTaskResult.getGeneratedObjects()[0]).Value);
 }
コード例 #25
0
 /// <summary>
 /// createBrokerWorker override method for BackgroundTaskBroker.
 /// </summary>
 /// <remarks></remarks>
 protected override RBrokerWorker createBrokerWorker(RTask task,
                                            long taskIndex,
                                            Boolean isPriorityTask,
                                            Object resourceToken,
                                            RBrokerEngine brokerEngine)
 {
     return new BackgroundTaskWorker((BackgroundTask) task,
                                 taskIndex,
                                 isPriorityTask,
                                 m_rUser,
                                 (int) resourceToken,
                                 (RBroker) brokerEngine);
 }
コード例 #26
0
 /// <summary>
 /// Implementation of the submit method on RBroker interface.  
 /// Allows applications to submit a new Task for execution.
 /// </summary>
 /// <param name="task">RTask to be submitted for execution as a background task</param>
 /// <param name="priority">priority of task.  If TRUE, then task has a high priority</param>
 /// <returns>RTaskToken for this RTask</returns>
 /// <remarks></remarks>
 public new RTaskToken submit(RTask task, Boolean priority)
 {
     return submit(task, priority);
 }
コード例 #27
0
 /// <summary>
 /// Implementation of RBroker Interface 'submit' method
 /// </summary>
 /// <param name="task">RTask submitted to the RBroker for execution</param>
 /// <returns>RTaskToken reference</returns>
 /// <remarks></remarks>
 public RTaskToken submit(RTask task)
 {
     return submit(task, false);
 }
コード例 #28
0
 public void onTaskError(RTask rTask, String error)
 {
     Console.WriteLine("DiscreteProfiling: onTaskError: " + rTask + ", error: " + error);
     RBrokerStatsHelper.printRTaskResult(rTask, null, error);
 }
コード例 #29
0
 /// <summary>
 /// Asynchronous callback notification when a TaskToken is returned to the pool.
 /// </summary>
 /// <param name="task">The RTask instance</param>
 /// <param name="future">The Operating System task reference</param>
 /// <remarks></remarks>
 public void onTask(RTask task, Task<RTaskResult> future)
 {
     m_future = future;
 }
コード例 #30
0
 public void onTaskError(RTask rTask, String error)
 {
     Console.WriteLine("DiscreteAsynchronous: onTaskError: " + rTask + ", error: " + error);
 }
コード例 #31
0
            public void onTaskCompleted(RTask rTask, RTaskResult rTaskResult)
            {
                Console.WriteLine("DiscreteAsynchronous: onTaskCompleted: " + rTask.ToString()
                    + ", result: " + rTaskResult.getTimeOnCall());

                if (m_rBroker != null)
                {
                    m_rBroker.shutdown();
                    Console.WriteLine("DiscreteAsynchronous: rBroker has been shutdown.");
                }
            }
コード例 #32
0
 internal RTaskTokenImpl(RTask task)
 {
     m_task = task;
 }
コード例 #33
0
 /// <summary>
 /// Asynchronous callback notification when a TaskToken is returned to the pool.
 /// </summary>
 /// <param name="task">The RTask instance</param>
 /// <param name="future">The Operating System task reference</param>
 /// <remarks></remarks>
 public void onTask(RTask task, Task <RTaskResult> future)
 {
     m_future = future;
 }
コード例 #34
0
 internal RTaskTokenImpl(RTask task, Task <RTaskResult> future)
 {
     m_task   = task;
     m_future = future;
 }
コード例 #35
0
            public void onTaskCompleted(RTask rTask, RTaskResult rTaskResult)
            {
                Console.WriteLine("onTaskCompleted: " + rTask + ", result: " + rTaskResult);

                /*
                 * Retrieve Job identifier from RTaskResult.
                 */
                String jobID = rTaskResult.getID();

                Console.WriteLine("onTaskCompleted: " + rTask + ", background Job ID: " + jobID);

                if(m_rBroker != null)
                {

                    /*
                     * Important:
                     *
                     * To handle the results of a Background RTask you
                     * must transition from using the RBroker Framework
                     * API to using the .NET Client Library API.
                     */
                    RUser rUser = m_rBroker.owner();

                    if(rUser != null)
                    {
                        try
                        {

                            RJob rJob = rUser.queryJob(jobID);

                            Console.WriteLine("onTaskCompleted: " +rTask + ", rJob: " + rJob);

                            /*
                             * Next handle the result of the RJob as appropriate.
                             * In this example, simly cancel and delete the job.
                             */

                            try
                            {
                                rJob.cancel();
                            }
                            catch(Exception cex)
                            {
                                Console.WriteLine("rJob.cancel ex=" + cex.ToString());
                            }
                            try
                            {
                                rJob.delete();
                            }
                            catch(Exception dex)
                            {
                                Console.WriteLine("rJob.delete ex=" + dex.ToString());
                            }

                        }
                        catch(Exception jex)
                        {
                            Console.WriteLine("rUser.queryJob ex=" + jex.ToString());
                        }
                    }

                    m_rBroker.shutdown();
                    Console.WriteLine("BackgroundBasics: rBroker has been shutdown.");
                }
            }
コード例 #36
0
 /// <summary>
 /// cloneTask method that must be implemented by
 /// concrete implementation of RBrokerEngine.
 /// 
 /// Responsible for cloning an RTask.
 /// </summary>
 /// <remarks></remarks>
 protected abstract RTask cloneTask(RTask genesis);
コード例 #37
0
            public void onTaskError(RTask rTask, String error)
            {
                Console.WriteLine("BackgroundBasics: onTaskError: " + rTask + ", error: " + error);

                if(m_rBroker != null)
                {
                    m_rBroker.shutdown();
                    Console.WriteLine("BackgroundBasics: rBroker has been shutdown.");
                }
            }
コード例 #38
0
        // not working
        public async Task <RTask> UpdateTaskById(int taskId, RTask task)
        {
            var newTask = await context.Tasks
                          .Include(t => t.ChildCheckPoints)
                          .Where(t => t.Id == taskId).SingleOrDefaultAsync();

            if (newTask != null)
            {
                if (task.Name != null)
                {
                    newTask.Name = task.Name;
                }

                if (task.Description != null)
                {
                    newTask.Description = task.Description;
                }

                if (!(DateTime.Compare(task.PlannedStartDate, new DateTime(1, 1, 1)) == 0))
                {
                    Console.WriteLine("planned start date ==============>" + task.PlannedStartDate);
                    newTask.PlannedStartDate = task.PlannedStartDate;
                }

                if (!(DateTime.Compare(task.PlannedEndDate, new DateTime(1, 1, 1)) == 0))
                {
                    Console.WriteLine("planned end date ==============>" + task.PlannedEndDate);
                    newTask.PlannedEndDate = task.PlannedEndDate;
                }


                if (task.ChildCheckPoints != null)
                {
                    foreach (var c in task.ChildCheckPoints)
                    {
                        if (c.Id == 0)
                        {
                            c.ParentRTaskId = taskId;
                            await context.CheckPoints.AddAsync(c);
                        }
                        else
                        {
                            var checkpointNeededToUpdate = await context
                                                           .CheckPoints
                                                           .Where(checkpoint => checkpoint.Id == c.Id)
                                                           .SingleOrDefaultAsync();


                            if (checkpointNeededToUpdate == null)
                            {
                                throw new Exception(" checkpoints not exist");
                            }

                            if (c.CheckpointText != null)
                            {
                                checkpointNeededToUpdate.CheckpointText = c.CheckpointText;
                            }

                            if (c.Description != null)
                            {
                                checkpointNeededToUpdate.Description = c.Description;
                            }

                            if (c.Percentage != 0)
                            {
                                checkpointNeededToUpdate.Percentage = c.Percentage;
                            }
                        }
                    }
                }
                return(newTask);
            }
            return(null);
        }
コード例 #39
0
 /// <summary>
 /// createBrokerWorker override method for PooledTaskBroker.
 /// </summary>
 /// <remarks></remarks>
 protected override RBrokerWorker createBrokerWorker(RTask task,
                                            long taskIndex,
                                            Boolean isPriorityTask,
                                            Object resourceToken,
                                            RBrokerEngine brokerEngine)
 {
     return new PooledTaskWorker((PooledTask) task,
                                 taskIndex,
                                 isPriorityTask,
                                 (RProject) resourceToken,
                                 brokerEngine);
 }
コード例 #40
0
        /// <summary>
        /// cloneTask override method for BackgroundTaskBroker.
        /// </summary>
        /// <remarks></remarks>
        protected override RTask cloneTask(RTask genesis)
        {
            BackgroundTask source  = (BackgroundTask) genesis;
            BackgroundTask clone = null;
            if(source.code != "")
            {
                clone = new BackgroundTask(source.name,
                                           source.description,
                                           source.code,
                                           source.options);
            }
            else
            {
                clone = new BackgroundTask(source.name,
                                           source.description,
                                           source.filename,
                                           source.directory,
                                           source.author,
                                           source.version,
                                           source.options);
            }

            if(source.external != "")
            {
                clone.external = source.external;
            }
            clone.setToken(source.getToken());
            return clone;
        }
コード例 #41
0
 public void onTaskCompleted(RTask rTask, RTaskResult rTaskResult)
 {
     Console.WriteLine("DiscreteProfiling: onTaskCompleted: " + rTask + ", result: " + rTaskResult.getTimeOnCall());
     RBrokerStatsHelper.printRTaskResult(rTask, rTaskResult, null);
 }
コード例 #42
0
 /*
  * RBrokerAsyncListener methods.
  */
 public void onTaskCompleted(RTask rTask, RTaskResult rTaskResult)
 {
     RBrokerStatsHelper.printRTaskResult(rTask, rTaskResult, null);
 }
コード例 #43
0
 /// <summary>
 /// createBrokerWorker override method for DiscreteTaskBroker.
 /// </summary>
 /// <remarks></remarks>
 protected override RBrokerWorker createBrokerWorker(RTask task,
                                            long taskIndex,
                                            Boolean isPriorityTask,
                                            Object resourceToken,
                                            RBrokerEngine brokerEngine)
 {
     return new DiscreteTaskWorker((DiscreteTask) task,
                                 taskIndex,
                                 isPriorityTask,
                                 m_rClient,
                                 (int) resourceToken,
                                 (RBroker) brokerEngine);
 }
コード例 #44
0
 public void onTaskError(RTask rTask, String error)
 {
     RBrokerStatsHelper.printRTaskResult(rTask, null, error);
 }
コード例 #45
0
        static public void Execute()
        {
            RBroker rBroker = null;

            try
            {
                /*
                 * 1. Create RBroker instance using RBrokerFactory.
                 *
                 * This example creates a DiscreteTaskBroker.
                 */

                DiscreteBrokerConfig brokerConfig = new DiscreteBrokerConfig(Program.DEPLOYR_ENDPOINT);
                rBroker = RBrokerFactory.discreteTaskBroker(brokerConfig);


                /*
                 * 2. Define RTask
                 *
                 * This example creates a DiscreteTask that will
                 * execute an R script, /testuser/tutorial-rbroker/5SecondNoOp.
                 */

                RTask rTask = RTaskFactory.discreteTask(Program.TUTORIAL_NOOP_SCRIPT,
                                                        Program.TUTORIAL_REPO_DIRECTORY,
                                                        Program.TUTORIAL_REPO_OWNER,
                                                        "",
                                                        null);


                /*
                 * 3. Submit RTask to RBroker for execution.
                 *
                 * Note, unlike an RClient.executeScript call or
                 * an RProject.executeScript call the RBroker.submit
                 * call is non-blocking.
                 *
                 * The RTaskToken is returned immediately. You can
                 * use the token to track the progress of RTask
                 * and/or block while waiting for a result.
                 */

                RTaskToken rTaskToken = rBroker.submit(rTask);

                Console.WriteLine("DiscreteBlocking: submitted " + rTask + " for execution on RBroker.");

                /*
                 * 4. Demonstrate blocking for an RTask result.
                 *
                 * The call to getResult() will either return
                 * an RTaskResult or raise an Exception. An Exception
                 * indicates the RTask failed to complete and why.
                 */

                RTaskResult rTaskResult = rTaskToken.getResult();

                Console.WriteLine("DiscreteBlocking: " + rTask + " completed, result=" + rTaskResult.getTimeOnCall());
            } catch (Exception tex)
            {
                Console.WriteLine("DiscreteBlocking: error=" + tex.ToString());
            }
            finally
            {
                /*
                 * Final Step: Shutdown RBroker to release
                 * all associated resources, connections.
                 */
                if (rBroker != null)
                {
                    rBroker.shutdown();
                    Console.WriteLine("DiscreteBlocking: rBroker has been shutdown.");
                }
            }
        }
コード例 #46
0
            public void onTaskCompleted(RTask rTask, RTaskResult rTaskResult)
            {
                Console.WriteLine("onTaskCompleted: " + rTask + ", result: " + rTaskResult);

                /*
                 * Retrieve Job identifier from RTaskResult.
                 */
                String jobID = rTaskResult.getID();

                Console.WriteLine("onTaskCompleted: " + rTask + ", background Job ID: " + jobID);

                if (m_rBroker != null)
                {
                    /*
                     * Important:
                     *
                     * To handle the results of a Background RTask you
                     * must transition from using the RBroker Framework
                     * API to using the .NET Client Library API.
                     */
                    RUser rUser = m_rBroker.owner();

                    if (rUser != null)
                    {
                        try
                        {
                            RJob rJob = rUser.queryJob(jobID);

                            Console.WriteLine("onTaskCompleted: " + rTask + ", rJob: " + rJob);

                            /*
                             * Next handle the result of the RJob as appropriate.
                             * In this example, simly cancel and delete the job.
                             */

                            try
                            {
                                rJob.cancel();
                            }
                            catch (Exception cex)
                            {
                                Console.WriteLine("rJob.cancel ex=" + cex.ToString());
                            }
                            try
                            {
                                rJob.delete();
                            }
                            catch (Exception dex)
                            {
                                Console.WriteLine("rJob.delete ex=" + dex.ToString());
                            }
                        }
                        catch (Exception jex)
                        {
                            Console.WriteLine("rUser.queryJob ex=" + jex.ToString());
                        }
                    }

                    m_rBroker.shutdown();
                    Console.WriteLine("BackgroundBasics: rBroker has been shutdown.");
                }
            }
コード例 #47
0
 public void onTaskCompleted(RTask rTask, RTaskResult rTaskResult)
 {
     Console.WriteLine("DiscreteProfiling: onTaskCompleted: " + rTask + ", result: " + rTaskResult.getTimeOnCall());
     RBrokerStatsHelper.printRTaskResult(rTask, rTaskResult, null);
 }
コード例 #48
0
        static public void Execute()
        {
            try
            {
                /*
                 * 1. Create RBroker instance using RBrokerFactory.
                 *
                 * This example creates a BackgroundTaskBroker.
                 */

                RAuthentication rAuth = new RBasicAuthentication(Program.AUTH_USER_NAME, Program.AUTH_PASSWORD);

                BackgroundBrokerConfig brokerConfig = new BackgroundBrokerConfig(Program.DEPLOYR_ENDPOINT, rAuth);
                RBroker rBroker = RBrokerFactory.backgroundTaskBroker(brokerConfig);

                /*
                 * 2. Register RTaskListener for asynchronous
                 * notifications on RTask completion.
                 */

                BackgroundTaskListener myTaskListener = new BackgroundTaskListener(rBroker);

                rBroker.addTaskListener(myTaskListener);


                /*
                 * 3. Define RTask
                 *
                 * This example creates a BackgroundTask that will
                 * execute an artibrary block of R code.
                 */

                String rCode = "x <- rnorm(100)";
                RTask  rTask = RTaskFactory.backgroundTask("Example Background RTask",
                                                           "Example background RTask.",
                                                           rCode,
                                                           null);

                /*
                 * 4. Submit RTask to RBroker for execution.
                 *
                 * The RTaskToken is returned immediately. You can
                 * use the token to track the progress of RTask
                 * and/or block while waiting for a result.
                 *
                 * However, in this example we are going to allow
                 * the RTaskListener handle the result so
                 * there is nothing further for us to do here after
                 * we submit the RTask.
                 */

                RTaskToken rTaskToken = rBroker.submit(rTask);

                Console.WriteLine("Submitted " + rTask + " for execution on RBroker.");

                /*
                 * 4. Block until all tasks are complete, and shutdown has been called
                 */
                rBroker.waitUntilShutdown();
            }
            catch (Exception tex)
            {
                Console.WriteLine("Runtime exception=" + tex.ToString());
            }
        }
コード例 #49
0
 public void onTaskError(RTask rTask, String error)
 {
     Console.WriteLine("DiscreteProfiling: onTaskError: " + rTask + ", error: " + error);
     RBrokerStatsHelper.printRTaskResult(rTask, null, error);
 }
コード例 #50
0
 internal RTaskTokenImpl(RTask task)
 {
     m_task = task;
 }
コード例 #51
0
        /// <summary>
        /// cloneTask override method for DiscreteTaskBroker.
        /// </summary>
        /// <remarks></remarks>
        protected override RTask cloneTask(RTask genesis)
        {
            DiscreteTask source  = (DiscreteTask) genesis;
            DiscreteTask clone = null;
            if(source.external != "")
            {
                String externalURL = source.external;

                clone = new DiscreteTask(externalURL,
                                       source.options);
            }
            else
            {
                clone = new DiscreteTask(source.filename,
                                       source.directory,
                                       source.author,
                                       source.version,
                                       source.options);
            }
            clone.setToken(source.getToken());

            return clone;
        }
コード例 #52
0
 /// <summary>
 /// Callback for RBrokerWorker. Must be implemented by
 /// concrete implementation of RBrokerEngine.
 /// 
 /// Responsible for adding an engineResourceToken
 /// back into the RBrokerEngine resourceTokenPool, 
 /// making the token available for use by another
 /// RTask.
 /// </summary>
 /// <param name="task">RTask reference</param>
 /// <param name="result">RTaskResult reference</param>
 /// <remarks></remarks>
 public abstract void callback(RTask task, RTaskResult result);
コード例 #53
0
        /// <summary>
        /// Implementation of the submit method on RBroker interface.  
        /// Allows applications to submit a new Task for execution.
        /// </summary>
        /// <param name="task">RTask to be submitted for execution as a discrete task</param>
        /// <param name="priority">priority of task.  If TRUE, then task has a high priority</param>
        /// <returns>RTaskToken for this RTask</returns>
        /// <remarks></remarks>
        public new RTaskToken submit(RTask task, Boolean priority)
        {
            DiscreteTask discreteTask = (DiscreteTask) task;

            if(m_rUser == null && discreteTask.external != "")
            {
                throw new Exception("External script task execution not permitted on anonymous broker.");
            }

            return submit(task, priority);
        }
コード例 #54
0
        /// <summary>
        /// Implementation of RBroker Interface 'submit' method
        /// </summary>
        /// <param name="task">RTask submitted to the RBroker for execution</param>
        /// <param name="priority">Boolean indicating this is a high priority task</param>
        /// <returns>RTaskToken reference</returns>
        /// <remarks></remarks>
        public RTaskToken submit(RTask task, Boolean priority)
        {
            if(Interlocked.Read(ref m_refreshingConfig) == 1)
            {
                Console.WriteLine("RTask submissions temporarily disabled while RBroker configuration refreshes.");
            }

            try
            {

                /*
                 * We clone the incoming RTask into a new instance of
                 * RTask to ensure RTask is unique so it can be used
                 * as a key inside the taskTokenListenerMap.
                 *
                 * How could the value of RTask param not be unique?
                 *
                 * For example, RBrokerAppSimulator apps frequently
                 * create a single RTask instance and submit it many times
                 * to simulate load.
                 */
                RTask clonedTask = cloneTask(task);

                Boolean added = false;
                if(priority)
                {
                    added = m_pendingHighPriorityQueue.TryAdd(clonedTask);
                }
                else
                {
                    added = m_pendingLowPriorityQueue.TryAdd(clonedTask);
                }

                if(!added)
                {
                    throw new Exception("Broker at capacity ( " + MAX_TASK_QUEUE_SIZE + " ), rejecting task " + clonedTask);
                }

                RTaskToken rTaskToken = new RTaskTokenImpl(task);

                /*
                 * RTask now on pending[High,Low]PriorityQueue,
                 * appending associated RTaskToken to end of
                 * liveTaskTokens.
                 */
                m_liveTaskTokens.Add(rTaskToken);

                /*
                 * Register RTask and associated RTaskToken here.
                 * Once RTask has been submitted to Executor and
                 * Future for task exists, we will make an
                 * RTaskToken.onTask callback to register Future
                 * on token.
                 */
                m_taskTokenListenerMap.TryAdd(clonedTask, rTaskToken);

                return rTaskToken;

            }
            catch(Exception rex)
            {
                throw new Exception("RBroker: submit failed, cause: " + rex.ToString());
            }
        }
コード例 #55
0
 public async Task SaveTask(RTask task)
 {
     await context.Tasks.AddAsync(task);
 }
コード例 #56
0
 /// <summary>
 /// createBrokerWorker method that must be implemented by
 /// concrete implementation of RBrokerEngine.
 /// 
 /// Responsible for creating a RBrokerWorker for a task.
 /// </summary>
 /// <remarks></remarks>
 protected abstract RBrokerWorker createBrokerWorker(RTask task,
                                                 long taskIndex,
                                                 Boolean isPriorityTask,
                                                 Object resourceToken,
                                                 RBrokerEngine brokerEngine);
コード例 #57
0
 internal RTaskTokenImpl(RTask task, Task<RTaskResult> future)
 {
     m_task = task;
     m_future = future;
 }