Exemplo n.º 1
0
        public CmnCmdResult RunCommand(string txt)
        {
            var          r   = m_ssh.RunCommand(txt);
            CmnCmdResult res = new CmnCmdResult(r.Result, r.Error, r.ExitStatus);

            return(res);
        }
Exemplo n.º 2
0
 public void PollTaaStatus()
 {
     m_tokenSource = new CancellationTokenSource();
     m_statusTask  = Task.Run(() =>
     {
         var ct = m_tokenSource.Token;
         try
         {
             while (true)
             {
                 if (ct.IsCancellationRequested)
                 {
                     ct.ThrowIfCancellationRequested();
                 }
                 string status;
                 try
                 {
                     status = this.m_icmd.GetCmnCmd().RunCommand("ps ajx | grep taa|grep -v grep").m_result;
                 }
                 catch (Exception ex)
                 {
                     MessageBox.Show(ex.Message);
                     throw ex;
                 }
                 int childTaa          = 0;
                 int mainTaa           = 0;
                 int dumpCap           = 0;
                 HashSet <string> infs = new HashSet <string>();
                 using (StringReader sr = new StringReader(status))
                 {
                     string line;
                     while ((line = sr.ReadLine()) != null)
                     {
                         if (line.Contains("/bin/TAA -C"))
                         {
                             childTaa++;
                         }
                         else if (line.Contains("/bin/TAA"))
                         {
                             mainTaa++;
                         }
                         else if (line.Contains("bin/dumpcap"))
                         {
                             dumpCap++;
                             string[] ary = line.Split(' ');
                             int len      = ary.Length;
                             for (int i = 0; i < len; i++)
                             {
                                 if (ary[i] == "-i")
                                 {
                                     if ((i + 1) < len)
                                     {
                                         infs.Add(ary[i + 1]);
                                     }
                                 }
                             }
                         }
                     }
                 } //end stringReader
                 string _status        = "";
                 string _infs          = "";
                 string _status_detail = "";
                 if (mainTaa != 0 && childTaa != 0 && infs.Count != 0) //running
                 {
                     _status = "running";
                     foreach (var ele in infs)
                     {
                         if (_infs.Length > 0)
                         {
                             _infs += ",";
                         }
                         _infs += ele;
                     }
                     _status_detail = "childTaa=" + childTaa.ToString();
                 }
                 else if (mainTaa != 0) //unhealthy
                 {
                     _status = "unknown";
                     if (infs.Count == 0)
                     {
                         _status_detail = "dumpcap stopped";
                     }
                     _status_detail += ",childTaa=" + childTaa.ToString();
                 }
                 else
                 {
                     _status        = "stop";
                     _status_detail = "stopped";
                 }
                 if (_status == "running") //look up kafka broker
                 {
                     BrokerUnit bu = null;
                     foreach (var ele in m_confs)
                     {
                         if (ele.m_name == "broker")
                         {
                             bu = new BrokerUnit(ele.m_value);
                         }
                     }
                     CmnCmdResult res = m_icmd.GetCmnCmd().RunCommand("ss -anp | grep " + bu.m_port.ToString() + " | grep TAA");
                     if (res.m_exitCode != 0)
                     {
                         _status = "unknown";
                     }
                     else
                     {
                         int TAACount   = Regex.Matches(res.m_result, "TAA").Count;
                         int ESTABCount = Regex.Matches(res.m_result, "ESTAB").Count;
                         if (TAACount != ESTABCount)
                         {
                             _status        = "unknown";
                             _status_detail = "unstable kafka broker";
                         }
                     }
                 }
                 if (_status != m_taaStatus)
                 {
                     m_taaStatus = _status;
                 }
                 if (_infs != m_taaInfs)
                 {
                     m_taaInfs = _infs;
                 }
                 if (_status_detail != m_statusDetail)
                 {
                     m_statusDetail = _status_detail;
                 }
                 Thread.Sleep(500);
             }
         }
         catch (Exception ex)
         {
             //MessageBox.Show(ex.Message);
             if (!m_tokenSource.IsCancellationRequested)
             {
                 m_tokenSource.Cancel();
             }
             LogoutClick(this, null);
             return;
         }
     });
 }