Ejemplo n.º 1
0
 /// <summary>
 /// Clean up when job done.
 /// </summary>
 /// <param name="job">Job.</param>
 protected virtual void CleanUpJob(Job job)
 {
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Failure notification.
 /// </summary>
 /// <param name="job">Job.</param>
 protected virtual void OnJobFail(Job job)
 {
     string message = BuildXmlCommand(CommandType.JobDone.ToString(), job.Guid, FailFlag);
     SendToAll(message);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Dispatch job, and diterminate how to run this job.
 /// </summary>
 /// <param name="job">Job.</param>
 protected virtual void DispatchJob(Job job)
 {
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Process this job.
 /// </summary>
 /// <param name="job">Job.</param>
 /// <param name="exitEvent">Exiting event.</param>
 /// <returns>True if processed, otherwise false.</returns>
 protected virtual bool ProcessJob(Job job, ManualResetEvent exitEvent)
 {
     return false;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Enqueue a finished job.
        /// </summary>
        /// <param name="job">Job to enqueue.</param>
        public void EnqueueDoneJob(Job job)
        {
            if (job == null)
            {
                throw new ArgumentNullException("job");
            }

            lock (_schedulingJobs)
            {
                if (_schedulingJobs.ContainsValue(job))
                {
                    _schedulingJobs.Remove(job.Guid);
                }
            }

            lock (_localToDoJobs)
            {
                if (_localToDoJobs.ContainsValue(job))
                {
                    _localToDoJobs.Remove(job.Guid);
                }
            }

            lock (_doneJobs)
            {
                job.Status = JobStatus.Done;

                if (!_doneJobs.ContainsKey(job.Guid))
                {
                    _doneJobs.Add(job.Guid, job);
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Enqueue a job into scheduling.
        /// </summary>
        /// <param name="job">Job to enqueue.</param>
        public void EnqueueToScheduleJob(Job job)
        {
            if (job == null)
            {
                throw new ArgumentNullException("job");
            }

            lock (_schedulingJobs)
            {
                if (!_schedulingJobs.ContainsKey(job.Guid))
                {
                    _schedulingJobs.Add(job.Guid, job);
                }
            }
        }
        /// <summary>
        /// Submit job.
        /// </summary>
        /// <param name="taskName">Task name.</param>
        /// <param name="jobName">Job name.</param>
        /// <param name="command">Command.</param>
        /// <param name="arguments">Arguments.</param>
        /// <param name="doneFile">File path to indicate this job is done.</param>
        public void Submit(string taskName, string jobName,
            string command, string arguments, string doneFile)
        {
            if (string.IsNullOrEmpty(command))
            {
                throw new ArgumentNullException("command");
            }

            if (string.IsNullOrEmpty(jobName))
            {
                throw new ArgumentNullException("jobName");
            }

            if (string.IsNullOrEmpty(arguments))
            {
                throw new ArgumentNullException("arguments");
            }

            Job job = new Job(CommandLineServerWedge.WedgeName, taskName);
            job.Name = jobName;
            job.Command = command;
            job.Arguments = arguments;

            if (!string.IsNullOrEmpty(doneFile))
            {
                job.DoneFile = doneFile;
                job.Name = Path.GetFileName(doneFile);
            }

            Submit(job);
        }
        /// <summary>
        /// Submit job.
        /// </summary>
        /// <param name="job">Job to submit.</param>
        public void Submit(Job job)
        {
            if (job == null)
            {
                throw new ArgumentNullException("job");
            }

            XmlDocument dom = new XmlDocument();
            XmlElement ele = dom.CreateElement(MessageType.JobManage.ToString());
            ele.SetAttribute("command", CommandType.JobSubmit.ToString());

            string jobXml = job.ToXml();
            ele.InnerXml = jobXml;

            ProcessNode.SendMessage(_udpSender, ele.OuterXml, ServerIP, ServerPort);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Process this job.
 /// </summary>
 /// <param name="job">Job.</param>
 /// <param name="exitEvent">Exiting event.</param>
 /// <returns>True if processed, otherwise false.</returns>
 protected override bool ProcessJob(Job job, ManualResetEvent exitEvent)
 {
     IWedge wedge = FindSuitableWedge(job.WedgeName);
     if (wedge == null)
     {
         return false;
     }
     else
     {
         IClientWedge clientWedge = wedge as IClientWedge;
         if (clientWedge == null)
         {
             return false;
         }
         else
         {
             return clientWedge.ProcessJob(job, exitEvent);
         }
     }
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Clean up when job done.
 /// </summary>
 /// <param name="job">Job.</param>
 protected override void CleanUpJob(Job job)
 {
     string message = BuildXmlCommand(CommandType.JobDone.ToString(), job.Guid, SuccessFlag);
     SendToAll(message);
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Dispatch job, and diterminate how to run this job.
 /// </summary>
 /// <param name="job">Job.</param>
 protected override void DispatchJob(Job job)
 {
     job.Status = JobStatus.LocalRunning;
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Dispose job.
        /// </summary>
        /// <param name="job">Job to dispose.</param>
        protected override void DispatchJob(Job job)
        {
            // dead lock while _toScheduleJobs with ((IProcessNode)this).Nodes
            lock (((IProcessNode)this).Nodes)
            {
                NodeInfo ci = FindMaxCapabilityNode(((IProcessNode)this).Nodes, job);

                if (ci != null && !ci.Busy && ci.NodeType == NodeType.Execution)
                {
                    Console.WriteLine("{0} Dispatch job {1} out to {2}",
                        DateTime.Now.ToLongTimeString(), Path.GetFileName(job.Name),
                        ci.ToString());

                    string message = job.ToXml();
                    SendUdpMessage(message, ci.IP, ci.Port);
                    job.Status = JobStatus.Dispatched;
                    ci.Busy = true;
                }
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Handle job submittion.
        /// </summary>
        /// <param name="dom">XML message.</param>
        private void HandleJobSubmit(XmlDocument dom)
        {
            XmlElement jobEle = (XmlElement)dom.DocumentElement.SelectSingleNode(MessageType.Job.ToString());
            string taskName = jobEle.GetAttribute("taskName");
            string wedgeName = jobEle.GetAttribute("wedgeName");
            IServerWedge wedge = (IServerWedge)FindSuitableWedge(wedgeName);
            Job job = null;
            if (wedge == null)
            {
                job = new Job("default", taskName);
            }
            else
            {
                job = wedge.CreateJob();
            }

            job.ParseXml(jobEle);

            ((IProcessNode)this).EnqueueToScheduleJob(job);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Not thread safe.
        /// </summary>
        /// <param name="nodes">Node dictionary.</param>
        /// <param name="job">Job.</param>
        /// <returns>Node info.</returns>
        private static NodeInfo FindMaxCapabilityNode(Dictionary<string, NodeInfo> nodes, Job job)
        {
            NodeInfo foundMaxPowerNode = null;
            NodeInfo foundMatchNode = null;
            foreach (NodeInfo ci in nodes.Values)
            {
                if (!ci.Busy && ci.NodeType == NodeType.Execution)
                {
                    if (foundMaxPowerNode == null)
                    {
                        foundMaxPowerNode = ci;
                        continue;
                    }
                    else if (foundMaxPowerNode.DoneCount < ci.DoneCount)
                    {
                        foundMaxPowerNode = ci;
                    }

                    if (ci.LastDoneTaskName == job.TaskName)
                    {
                        if (foundMatchNode == null)
                        {
                            foundMatchNode = ci;
                        }
                        else if (foundMatchNode.DoneCount < ci.DoneCount)
                        {
                            foundMatchNode = ci;
                        }
                    }
                }
            }

            if (foundMatchNode != null)
            {
                return foundMatchNode;
            }
            else
            {
                return foundMaxPowerNode;
            }
        }
        /// <summary>
        /// Client to process a special job item.
        /// </summary>
        /// <param name="job">Job to process.</param>
        /// <param name="exitEvent">Existing event.</param>
        /// <returns>True if processed, otherwise false.</returns>
        public bool ProcessJob(Job job, WaitHandle exitEvent)
        {
            if (job == null)
            {
                throw new ArgumentNullException("job");
            }

            if (exitEvent == null)
            {
                throw new ArgumentNullException("exitEvent");
            }

            // deploy application to local machine
            Console.WriteLine("{0} Start running job {1}",
                DateTime.Now.ToShortTimeString(), job.Name);
            string newCommandPath = DeployLocal(job.Command);
            bool result = CommandLine.RunCommand(newCommandPath, job.Arguments,
                exitEvent, Environment.CurrentDirectory);
            if (!string.IsNullOrEmpty(job.DoneFile) &&
                !File.Exists(job.DoneFile))
            {
                // testing on the done file, which is a flag indicating the job is done
                result = false;
            }

            Console.WriteLine("{0} Job {1} was {2}",
                DateTime.Now.ToShortTimeString(), job.Name, result ? "successfully done" : "failed");
            return result;
        }