예제 #1
0
        public void StartJob(int id)
        {
            lock (jsLock)
            {
                JobNode _node = null;
                Job     _job  = LGetJob(id, out _node);
                if (_job != null)
                {
                    if (_job.state == 0)
                    {
                        _job.state = 1;
                    }
                    else
                    {
                        throw new JobException("Job (ID='" + _job.id + "') already active.", null);
                    }
                }
                else
                {
                    throw new JobException("Job (ID='" + _job.id + "') does not exist.", null);
                }
            }

            if (OnJobStatusChange != null)
            {
                OnJobStatusChange.Invoke(null, null);
            }
        }
예제 #2
0
        public void AddJobToNode(int nodeId, Job job)
        {
            lock (jsLock)
            {
                JobNode _node = LGetNode(nodeId);
                if (_node != null)
                {
                    if (JobNode.MAXJOBS > _node.jobs.Count)
                    {
                        _node.jobs.Add(job);
                    }
                    else
                    {
                        throw new JobSystemException("Job limit reached.", null);
                    }
                }
                else
                {
                    throw new JobNodeException("Node (ID='" + _node.id + "') does not exist.", null);
                }
            }

            if (OnJobCountChange != null)
            {
                OnJobCountChange.Invoke(null, null);
            }
        }
예제 #3
0
        public SyncResult SyncNodes(List <ModelHost> currentHosts)
        {
            SyncResult _result = new SyncResult();

            lock (jsLock)
            {
                foreach (ModelHost _host in currentHosts)
                {
                    JobNode _node = null;
                    try
                    {
                        _node = LGetNode(_host.hostMac);
                        if (_node != null)
                        {
                            // Node does exist with this mac -> update IP and HOST
                            _node.name = _host.hostName;
                            _node.ip   = _host.hostIP;
                            _result.nodesUpdated++;
                        }
                        else
                        {
                            // Node with this mac does not exist -> make new node.
                            JobNode _newNode = new JobNode(_host.hostName, _host.hostMac, _host.hostIP, new List <Job>());
                            _nodes.Add(_newNode);
                            _result.nodesAdded++;
                        }
                    }
                    catch (Exception e)
                    {
                        Logger.Log("(JS) Sync-error: " + e.Message, Logger.MessageType.ERROR);
                    }
                }
            }
            return(_result);
        }
예제 #4
0
파일: JSSerializer.cs 프로젝트: onixion/MAD
 public static void SerializeNode(string fileName, JobNode node)
 {
     lock (_serializerLock)
     {
         JsonSerializerSettings _settings = new JsonSerializerSettings();
         _settings.Converters.Add(new IPAddressConverter());
         _settings.Converters.Add(new MailAddressConverter());
         _settings.Converters.Add(new MacAddressConverter());
         _settings.TypeNameHandling = TypeNameHandling.Auto;
         Serialize(fileName, node, _settings);
     }
 }
예제 #5
0
 public void SaveNode(string fileName, int id)
 {
     lock (jsLock)
     {
         JobNode _node = LGetNode(id);
         if (_node != null)
         {
             JSSerializer.SerializeNode(fileName, _node);
         }
         else
         {
             throw new JobNodeException("Node does not exist!", null);
         }
     }
 }
예제 #6
0
 public bool NodeExist(int id)
 {
     lock (jsLock)
     {
         JobNode _node = LGetNode(id);
         if (_node != null)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
예제 #7
0
 public Job LGetJob(int id, out JobNode node)
 {
     for (int i = 0; i < _nodes.Count; i++)
     {
         for (int i2 = 0; i2 < _nodes[i].jobs.Count; i2++)
         {
             if (_nodes[i].jobs[i2].id == id)
             {
                 node = _nodes[i];
                 return(_nodes[i].jobs[i2]);
             }
         }
     }
     node = null;
     return(null);
 }
예제 #8
0
        public void LoadNode(string fileName)
        {
            JobNode _node = JSSerializer.DeserializeNode(fileName);

            lock (jsLock)
            {
                if (MAXNODES > _nodes.Count)
                {
                    _nodes.Add(_node);
                }
                else
                {
                    throw new JobSystemException("Nodes limit reached!", null);
                }
            }
        }
예제 #9
0
        public void AddNode(JobNode node)
        {
            lock (jsLock)
            {
                if (MAXNODES > _nodes.Count)
                {
                    _nodes.Add(node);
                }
                else
                {
                    throw new JobSystemException("Nodes limit reached!", null);
                }
            }

            if (OnNodeCountChange != null)
            {
                OnNodeCountChange.Invoke(null, null);
            }
        }
예제 #10
0
 public void StopNode(int id)
 {
     lock (jsLock)
     {
         JobNode _node = LGetNode(id);
         if (_node != null)
         {
             if (_node.state == 1)
             {
                 _node.state = 0;
             }
             else
             {
                 throw new JobNodeException("Node already inactive or has an exception!", null);
             }
         }
         else
         {
             throw new JobNodeException("Node does not exist!", null);
         }
     }
 }
예제 #11
0
파일: JobSchedule.cs 프로젝트: onixion/MAD
        private object JobInvoke(object holder)
        {
            JobHolder _holder = (JobHolder)holder;
            JobNode   _node   = _holder.node;
            Job       _job    = _holder.job;

            try
            {
                _job.tStart = DateTime.Now;

                try
                {
                    _job.Execute(_node.ip);
                }
                catch (Exception e)
                {
                    Logger.Log("(JOB-THREAD) Job threw a exception: " + e.Message, Logger.MessageType.ERROR);
                    _job.outp.outState = JobOutput.OutState.Exception;
                }

                _job.tStop = DateTime.Now;
                _job.tSpan = _job.tStop.Subtract(_job.tStart);

                // Global OutDescriptors
                _job.outp.outputs[0].dataObject = _job.outp.outState.ToString();
                _job.outp.outputs[1].dataObject = _job.tSpan.Milliseconds;

                _db.InsertJob(_node, _job);

                if (MadConf.conf.NOTI_ENABLE)
                {
                    if (_job.notiFlag)
                    {
                        List <JobRule> _bRules = GetBrokenRules(_job);
                        if (_bRules.Count != 0)
                        {
                            string _mailSubject = GenMailSubject(_job, "Job (target='" + _holder.node.ip.ToString()
                                                                 + "') finished with a not expected result!");

                            string _mailContent = "";
                            _mailContent += "JobNode-GUID: '" + _node.guid + "'\n";
                            _mailContent += "JobNode-ID:   '" + _node.id + "'\n";
                            _mailContent += "JobNode-IP:   '" + _node.ip.ToString() + "'\n";
                            _mailContent += "JobNode-MAC:  '" + _node.mac.ToString() + "'\n\n";
                            _mailContent += GenJobInfo(_job);
                            _mailContent += GenBrokenRulesText(_job.outp, _bRules);

                            if (_job.settings == null)
                            {
                                NotificationGetParams.SetSendMail(_mailSubject, _mailContent, 3);
                            }
                            else
                            {
                                if (_job.settings.login == null)
                                {
                                    NotificationGetParams.SetSendMail(_mailSubject, _mailContent, 3);
                                }
                                else
                                {
                                    if (_job.settings.login.smtpAddr == null || _job.settings.login.port == 0)
                                    {
                                        NotificationGetParams.SetSendMail(_mailSubject, _mailContent, 3);
                                    }
                                    else
                                    {
                                        NotificationGetParams.SetSendMail(_job.settings.mailAddr, _mailSubject,
                                                                          _mailContent, 3, _job.settings.login.smtpAddr, _job.settings.login.mail,
                                                                          _job.settings.login.password, _job.settings.login.port);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Log("(JobSchedule) JOB-THREAD-EXCEPTION: " + e.ToString() + "\n" + e.StackTrace, Logger.MessageType.ERROR);
            }
            finally
            {
                _job.state = 1;
                _node.uWorker--;
            }

            return(null);
        }
예제 #12
0
파일: JSEventArgs.cs 프로젝트: onixion/MAD
 public NodeEventArgs(JobNode node)
     : base()
 {
     this.node = node;
 }
예제 #13
0
파일: JSEventArgs.cs 프로젝트: onixion/MAD
 public JobAndNodeEventArgs(JobNode node, Job job)
     : base()
 {
     this.node = node;
     this.job  = job;
 }