Beispiel #1
0
        public AutotDiagnostic(TaaConfCtl conf)
        {
            InitializeComponent();
            m_conf = conf;
            BrokerUnit bu = null;

            foreach (var ele in m_conf.m_confs)
            {
                if (ele.m_name == "broker")
                {
                    bu = new BrokerUnit(ele.m_value);
                }
            }
            m_items = new List <DiagnoseItem>();
            m_items.Add(new DiagnoseItem("auth", "look up /etc/license/IN-SEC.lic and TAAMaster.log", m_conf.m_icmd.IsAuthOkay));
            m_items.Add(new DiagnoseItem("kafka", "connect broker", m_conf.m_icmd.IsKfkaOkay, bu));
            DataContext = this;
            Task.Run(() => {
                foreach (var ele in m_items)
                {
                    ele.m_func(ele.m_result);
                }
            });
        }
Beispiel #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;
         }
     });
 }
Beispiel #3
0
        private void ProduceClick(object sender, RoutedEventArgs arg)
        {
            m_btnProduce.IsEnabled = false;
            m_btnStop.IsEnabled    = true;
            int        cntMax   = int.Parse(m_cnt);
            int        interval = int.Parse(m_interval);
            BrokerUnit bu       = new BrokerUnit(m_broker);

            try
            {
                Common.Net.TcpConnectionTest(bu.m_ip, bu.m_port, int.Parse(AppConfig.m_conf.AppSettings.Settings["operationTimeout"].Value));
            }
            catch (Exception ex)
            {
                m_btnProduce.IsEnabled = true;
                m_btnStop.IsEnabled    = false;
                MessageBox.Show(ex.Message);
                return;
            }
            m_cts = new CancellationTokenSource();
            Task.Run(() =>
            {
                int okayCnt             = 0;
                int errCnt              = 0;
                int sendCnt             = 0;
                HashSet <string> errSet = new HashSet <string>();
                Action <DeliveryReport <Null, string> > handler = new Action <DeliveryReport <Null, string> >((r) => {
                    if (r.Error.IsError)
                    {
                        errCnt++; errSet.Add(r.Error.Reason);
                    }
                    else
                    {
                        okayCnt++;
                    }
                });
                var config = new ProducerConfig
                {
                    BootstrapServers = bu.m_broker,
                    MessageTimeoutMs = 3000,
                };

                using (var p = new ProducerBuilder <Null, string>(config).Build())
                {
                    for (int i = 0; i < cntMax; i++)
                    {
                        p.Produce(m_topic, new Message <Null, string> {
                            Value = m_msg
                        }, handler);
                        sendCnt++;
                        if (interval > 0)
                        {
                            Thread.Sleep(interval);
                        }
                        if (m_cts.IsCancellationRequested)
                        {
                            break;
                        }
                    }
                    p.Flush(m_cts.Token);
                }
                int recvCnt   = okayCnt + errCnt;
                string retMsg = "send/recv/error:" + sendCnt + "/" + recvCnt + "/" + errCnt;
                if (errCnt > 0)
                {
                    foreach (var ele in errSet)
                    {
                        retMsg += "," + ele;
                    }
                }
                OnProduceCompleted?.Invoke(this, retMsg);
            });
            m_btnProduce.IsEnabled = true;
            m_btnStop.IsEnabled    = false;
        }
Beispiel #4
0
        private void ConsumeClick(object sender, RoutedEventArgs arg)
        {
            m_btnConsume.IsEnabled = false;
            m_btnStop.Dispatcher.Invoke(() => { m_btnStop.IsEnabled = true; });
            BrokerUnit bu = new BrokerUnit(m_broker);

            try
            {
                Common.Net.TcpConnectionTest(bu.m_ip, bu.m_port, int.Parse(AppConfig.m_conf.AppSettings.Settings["operationTimeout"].Value));
            }
            catch (Exception ex)
            {
                m_btnConsume.IsEnabled = true;
                m_btnStop.IsEnabled    = false;
                MessageBox.Show(ex.Message);
                return;
            }
            Task.Run(() =>
            {
                UInt32 cntMax       = UInt32.Parse(m_cnt);
                m_cts               = new CancellationTokenSource();
                StreamWriter writer = null;
                if (m_save2File)
                {
                    writer = new StreamWriter(Common.Dir.GetCacheDir() + bu.m_ip + "-" + m_topic + ".log");
                }
                string groupId = null;
                if (m_groupId == "")
                {
                    groupId = DateTime.Now.ToString();
                }
                else
                {
                    groupId = m_groupId;
                }
                var conf = new ConsumerConfig
                {
                    GroupId = groupId,
                    //AutoOffsetReset = AutoOffsetReset.Latest,
                    BootstrapServers = bu.m_broker,
                    //SocketTimeoutMs = 1000,
                    //SessionTimeoutMs = 1000,
                    //MetadataRequestTimeoutMs=1000,
                    ReconnectBackoffMs    = 1000,
                    ReconnectBackoffMaxMs = 3000,


                    // Note: The AutoOffsetReset property determines the start offset in the event
                    // there are not yet any committed offsets for the consumer group for the
                    // topic/partitions of interest. By default, offsets are committed
                    // automatically, so in this example, consumption will only start from the
                    // earliest message in the topic 'my-topic' the first time you run the program.
                    AutoOffsetReset = AutoOffsetReset.Latest
                };
                using (var c = new ConsumerBuilder <Ignore, string>(conf).Build())
                {
                    c.Subscribe(m_topic);
                    uint cnt = 0;
                    try
                    {
                        while (true)
                        {
                            try
                            {
                                var cr = c.Consume(m_cts.Token);
                                if (m_save2File)
                                {
                                    writer.Write(cr.Message.Value + System.Environment.NewLine);
                                }
                                OnConsumeMsg?.Invoke(this, cr.Message.Value);
                                cnt++;
                                if (cntMax != 0)
                                {
                                    if (cnt >= cntMax)
                                    {
                                        c.Close();
                                        break;
                                    }
                                }
                                Thread.Sleep(10);
                                //Console.WriteLine($"Consumed message '{cr.Value}' at: '{cr.TopicPartitionOffset}'.");
                            }
                            catch (ConsumeException ex)
                            {
                                MessageBox.Show(ex.Message);
                                //Log.LogErr(e.Error.Reason);
                                //Console.WriteLine($"Error occured: {e.Error.Reason}");
                            }
                        }
                    }
                    catch (OperationCanceledException)
                    {
                        // Ensure the consumer leaves the group cleanly and final offsets are committed.
                        c.Close();
                        //return;
                    }
                }
                if (m_save2File)
                {
                    writer.Close();
                }

                m_btnConsume.Dispatcher.Invoke(() => { m_btnConsume.IsEnabled = true; });
                m_btnStop.Dispatcher.Invoke(() => { m_btnStop.IsEnabled = false; });
            });
        }