internal void Connect(String connectionName)
        {
            var connectString = System.Configuration.ConfigurationManager.ConnectionStrings[connectionName].ConnectionString;

            /*
             * if (this.connection != null)
             * {
             *  if (this.connection.State == System.Data.ConnectionState.Open)
             *  {
             *      this.connection.Close();
             *  }
             *
             * }
             */

            //      Logger.Debug(String.Format("Connecting with {0}", connectString));

            this.connection = new MySqlConnection
            {
                ConnectionString = connectString
            };

            this.connection.Open();

            var f = DbProviderFactories.GetFactory("MySql.Data.MySqlClient"); //your provider
            var b = f.CreateConnectionStringBuilder();

            b.ConnectionString = connectString;

            String hostname = b["server"].ToString();

            this.hostIp = HostUtil.HostnameToIp(hostname);
        }
Exemplo n.º 2
0
 private LogHost()
 {
     _hostInfo             = HostUtil.GetHostInfo();
     _appKey               = AppContext.AppKey;
     _writeLogBatchSize    = AppContext.LogMaxMessageCount;
     _writeLogCoolDownTime = AppContext.LogSendFrequency;
     _localQueueSize       = AppContext.LogMaxQueueSize;
     _isWriteLocalLog      = AppContext.WriteLocalFile;
     _localLogQueue        = new WorkerQueue <LogContent>(_writeLogBatchSize, _writeLogCoolDownTime, _localQueueSize, "LogSDKQueue");
     _localLogQueue.Flush += new Action <object, List <LogContent> >(WriteLog);
 }
Exemplo n.º 3
0
        /// <summary>Return the TaskLogsUrl of a particular TaskAttempt</summary>
        /// <param name="attempt"/>
        /// <returns>
        /// the taskLogsUrl. null if http-port or tracker-name or
        /// task-attempt-id are unavailable.
        /// </returns>
        public static string GetTaskLogsUrl(string scheme, JobHistoryParser.TaskAttemptInfo
                                            attempt)
        {
            if (attempt.GetHttpPort() == -1 || attempt.GetTrackerName().Equals(string.Empty) ||
                attempt.GetAttemptId() == null)
            {
                return(null);
            }
            string taskTrackerName = HostUtil.ConvertTrackerNameToHostName(attempt.GetTrackerName
                                                                               ());

            return(HostUtil.GetTaskLogUrl(scheme, taskTrackerName, Sharpen.Extensions.ToString
                                              (attempt.GetHttpPort()), attempt.GetAttemptId().ToString()));
        }
Exemplo n.º 4
0
 private bool SendTheMessageToRemoteHost(string logKey, string message)
 {
     MailUtil.SendEmail(new SendMail
     {
         Host              = this.Host,
         UserName          = this.UserName,
         Password          = this.Password,
         FromMailAddress   = this.From,
         DisplayName       = this.DisplayName ?? this.UserName,
         Subject           = string.Format("【{0}】{1}-{2}-告警", HostUtil.GetHostIp(), AppName, logKey),
         Body              = message,
         IsBodyHtml        = IsHtml,
         ToMailAddressList = To.Split(',').ToList()
     });
     return(true);
 }
        public TuDbConnection(String connectionName, Int32 id)
        {
            this.poolId = id;

            var connectString = System.Configuration.ConfigurationManager.ConnectionStrings[connectionName].ConnectionString;

            var f = DbProviderFactories.GetFactory("MySql.Data.MySqlClient"); //your provider
            var b = f.CreateConnectionStringBuilder();

            b.ConnectionString = connectString;

            String hostname = b["server"].ToString();

            this.hostIp = HostUtil.HostnameToIp(hostname);

            //  this.Connect(connectionName);
        }
Exemplo n.º 6
0
        public void Manifest_UpdatesWhenFileChanged()
        {
            ResponseUtil.SetContentTypeCacheManifest = () => {};
            RequestUtil.GetRootUrl = () => "test/testing";

            var controller = new OfflineController();

            var result        = controller.Manifest();
            var firstModified = ((Manifest)result.Model).LastModified;

            var onlineFile = HostUtil.MapPath("~/favicon.ico");

            File.SetLastWriteTimeUtc(onlineFile, DateTime.UtcNow);

            result = controller.Manifest();
            var newlyModified = ((Manifest)result.Model).LastModified;

            Assert.That(newlyModified, Is.GreaterThanOrEqualTo(firstModified));
        }
Exemplo n.º 7
0
        public ChunkBuilder()
        {
            this.chunk      = new Chunk();
            chunk.EnvGroup  = Configuration.GetEnvironmentGroup();
            chunk.Env       = Configuration.GetEnvironment();
            chunk.HostIp    = HostUtil.GetHostIp();
            chunk.HostName  = HostUtil.GetHostName();
            chunk.AppId     = Configuration.GetAppId();
            chunk.ProcessId = 0;

            List <LogEvent>    logEventList = new List <LogEvent>();
            List <Span>        spanList     = new List <Span>();
            List <MetricEvent> metricList   = new List <MetricEvent>();
            List <Event>       eventList    = new List <Event>();

            chunk.LogEvents = logEventList;
            chunk.Spans     = spanList;
            chunk.Metrics   = metricList;
            chunk.Events    = eventList;
        }
        public ConnectionManager(String connectionName, int poolSize)
        {
            this.connectionName = connectionName;

            this.connectionPool = new List <TuDbConnection>(poolSize);

            var connectString = System.Configuration.ConfigurationManager.ConnectionStrings[connectionName].ConnectionString;

            var f = DbProviderFactories.GetFactory("MySql.Data.MySqlClient"); //your provider
            var b = f.CreateConnectionStringBuilder();

            b.ConnectionString = connectString;

            String hostname = b["server"].ToString();

            this.currentHostIp = HostUtil.HostnameToIp(hostname);

            for (int i = 0; i < poolSize; i++)
            {
                TuDbConnection conn = new TuDbConnection(connectionName, i);

                this.connectionPool.Insert(i, conn);
            }
        }
        public TuDbConnection GetConnection()
        {
            connectionMutex.WaitOne();

            String                    connectString;
            DbProviderFactory         f;
            DbConnectionStringBuilder b;
            String                    hostname;
            String                    hostIp;

            try
            {
                connectString = System.Configuration.ConfigurationManager.ConnectionStrings[connectionName].ConnectionString;

                f = DbProviderFactories.GetFactory("MySql.Data.MySqlClient"); //your provider
                b = f.CreateConnectionStringBuilder();

                b.ConnectionString = connectString;

                hostname = b["server"].ToString();
                hostIp   = HostUtil.HostnameToIp(hostname);
            }
            catch (Exception ex)
            {
                Logging.Logger.Error("Internal error: " + ex.Message);
                return(null);
            }

            TuDbConnection conn = null;

            try
            {
                for (int i = 0; i < this.connectionPool.Count; i++)
                {
                    if (!this.connectionPool[i].InUse)
                    {
                        this.connectionPool[i].InUse = true;

                        if (hostIp != this.currentHostIp)
                        {
                            Logging.Logger.Debug("ConnectionManager: IP of host has changed");

                            Int32 hostsCleared   = 0;
                            Int32 hostsRemaining = 0;

                            for (int j = 0; j < this.connectionPool.Count; j++)
                            {
                                if (!this.connectionPool[j].InUse && this.connectionPool[j].HostIp != hostIp)
                                {
                                    hostsCleared++;
                                    Logging.Logger.Debug(String.Format("ConnectionManager: Clearing pool of connection {0}", j));

                                    connectionPool[j].ClearPool();

                                    this.connectionPool[j].HostIp = hostIp;
                                }
                                else if (this.connectionPool[j].InUse && this.connectionPool[j].HostIp != hostIp)
                                {
                                    Logging.Logger.Debug(String.Format("ConnectionManager: Remaining Poold Id {0}  Connection Id {1} Host Ip {2}", this.connectionPool[j].PoolId, this.connectionPool[j].ConnectionId, this.connectionPool[j].HostIp));

                                    hostsRemaining++;
                                }
                            }

                            if (hostsCleared == 0 && hostsRemaining == 0)
                            {
                                Logging.Logger.Debug("ConnectionManager: All connections have been switched over.  Setting hostIp");

                                this.currentHostIp = hostIp;
                            }
                            else
                            {
                                Logging.Logger.Debug(String.Format("ConnectionManager: {0} cleared {1} remaining", hostsCleared, hostsRemaining));
                            }
                        }

                        else
                        {
                            if (this.connectionPool[i].State == ConnectionState.Open)
                            {
                                this.connectionPool[i].Release();
                            }
                        }

                        this.connectionPool[i].Connect(this.connectionName);

                        conn = this.connectionPool[i];

                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Logging.Logger.Error(string.Format("ConnectionManager: Exception while trying to get connection from connection pool: {0}", ex.Message));
                connectionMutex.ReleaseMutex();
                return(null);
            }

            ConnectionManager.connectionMutex.ReleaseMutex();

            if (conn == null)
            {
                throw new DbNoConnections();
            }

            return(conn);
        }
Exemplo n.º 10
0
 public string Filename()
 {
     return(HostUtil.MapPath(File));
 }
        private static void Worker(object cm)
        {
            //    Logger.Debug("Inside worker thread....");

            SupportedEventProcessor eventProcessorInfo = (SupportedEventProcessor)cm;

            ulong thisEventId = eventProcessorInfo.EventId;
            ulong sleepTime   = thisEventId * 2;

            String   threadId = String.Format("{0}({1})", eventProcessorInfo.Name, eventProcessorInfo.EventId);
            Assembly asm      = null;

            try
            {
                asm = ReflectionManager.LoadAssembly(eventProcessorInfo.AssemblyFilename);
            }
            catch (Exception ex)
            {
                Logger.Debug(String.Format("Worker {0}: Exception in querying logic: {1}", threadId, ex.Message));
                Thread.Sleep(5000);
            }

            bool firstTime = true;

            while (true)
            {
                Logger.Debug("Worker Thread: " + Thread.CurrentThread.ManagedThreadId + "  Host Ip: " + HostUtil.GetLocalIPAddress() + "  Thread Id: " + threadId);

                if (firstTime)
                {
                    //  Logger.Debug(String.Format("{0} - Loading events from database table...", threadId));

                    try
                    {
                        eventsQueueManager.LoadEvents(threadId, thisEventId, connectionManager);
                    }
                    catch (Exception ex)
                    {
                        Logger.Error("Unable to load events: " + ex.Message);
                        continue;
                    }

                    firstTime = false;
                }

                //  Get next event for this event id.

                // Logger.Debug(String.Format("{0} - Getting next event...", threadId));

                ReportEvent evt;

                try
                {
                    evt = eventsQueueManager.GetEvent(thisEventId, connectionManager, threadId);
                }
                catch (Exception ex)
                {
                    Logger.Debug(String.Format("{0} - Error getting next event: {1}", threadId, ex.Message));
                    Thread.Sleep(2000);
                    continue;
                }

                if (evt == null)
                {
                    Logger.Debug(String.Format("{0} - No events to process", threadId));

                    Thread.Sleep(5000);

                    firstTime = true;

                    continue;
                }

                //  Received an event for this event id.  Process the event

                //      Logger.Debug(String.Format("{0} - Processing event {1}", threadId, evt.Id));

                try
                {
                    ReflectionManager.ProcessEvent(asm, eventProcessorInfo.ClassName, eventProcessorInfo.MethodName, evt, connectionManager, (int)sleepTime);
                }
                catch (EventProcessorClassNotFound)
                {
                    Logger.Debug("Internal error: Class SharedLibrary.MyClass not found");
                    return;
                }
                catch (EventProcessorClassEntryNotImplemented)
                {
                    Logger.Debug("Internal error: Start method in class SharedLibrary.MyClass not found");
                    return;
                }
                catch (Exception ex3)
                {
                    Logger.Debug("Error: " + ex3.Message);
                    return;
                }



                //   Logger.Debug(String.Format("{0}:  Id: {1}  Event Id: {2}  Event Date {3}  Event Data {4}",
                //                  threadId, evt.Id, evt.EventId, evt.EventDate, evt.EventData));
            } // END while(true)
        }     //  END Worker