23 using System.Collections.Generic;
24 using System.Globalization;
48 namespace Ntp.Analyzer.Process
62 this.configFile = configFile;
64 this.pidFile = pidFile;
66 this.initlog = initlog;
67 Nodes =
new List<IRequest>();
68 Listeners =
new List<Listener>();
72 private static bool firstrun =
true;
75 private readonly
string name;
76 private readonly
int pid;
87 public List<IRequest> Nodes {
get; }
89 public List<Listener> Listeners {
get; }
91 public bool Ready {
get;
private set; }
99 Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
101 bool proceed = InitializeConfiguration();
104 proceed = InitializeSecurity();
107 proceed = InitializeLog();
111 InitializeApplication();
112 InitializeListeners();
114 InitializeScheduler();
115 proceed = InitializeDatabase();
161 var ip = IPAddress.Parse(node.Ip);
164 Log.ClusterReady(node);
169 initlog.ClusterError(e);
178 if (!
File.Exists(configFile))
180 initlog.NoConfig(configFile);
185 config = builder.Execute();
187 if (!builder.Errors.Any() && config != null)
190 initlog.AddErrors(builder.Errors);
204 foreach (var server
in config.
Servers)
212 ip = Dns.GetHostAddresses(server.ServerName)[0];
223 Log.KnownServer(orgId.Value, server.ServerName);
225 else if (!Equals(ip, IPAddress.None) &&
TimeServers.
List.ContainsKey(ip.ToString()))
228 Log.KnownServer(orgId.Value, ip.ToString());
231 host =
new Host(server.HostId, server.ServerName, ip.ToString(), orgId);
233 Log.NewHost(server, ip);
238 Log.KnownServer(host.OrgId.Value, host.Ip);
241 else if (host.OrgId == null &&
TimeServers.
List.ContainsKey(host.Name))
244 Log.KnownServer(host.OrgId.Value, host.Name);
254 foreach (var entry
in peerImporter.ToList())
256 var currentEntry = entry;
267 Log.KnownServer(orgId, entry.Remote);
270 var hostName = entry.Remote;
274 var hostEntry = Dns.GetHostEntry(entry.Remote);
275 hostName = hostEntry.HostName;
279 Log.HostNameNotFound(entry.Remote, e);
282 var peer =
new Peer(hostName, entry.Remote, timeServer);
289 var peer = peerList.First();
290 if (peer.Server != null && peer.Server.IsOrgServer)
295 Log.KnownServer(orgId, entry.Remote);
296 if (timeServer == null)
299 peer.Server = timeServer;
317 checker.CheckConnection();
319 if (Controller.Stopped)
329 return initializer.Execute();
333 initlog.DatabaseError(e);
346 foreach (var monitor
in config.
Monitors)
348 var listener =
new Listener(monitor.Ip, monitor.Port, Log);
350 Listeners.Add(listener);
351 initlog.ListenerReady(listener);
356 initlog.ListenerError(e);
372 initlog.InitializationError(e);
379 initlog.Starting(version);
381 initlog.ConfigFile(configFile);
382 initlog.ProcessId(pid);
383 initlog.InstanceName(name);
406 foreach (var bulk
in config.
Bulks)
410 foreach (var server
in config.
Servers)
418 foreach (var peerPage
in server.PeerPages)
421 foreach (var hostPage
in server.HostPages)
424 foreach (var hostGraph
in server.HostGraphs)
427 foreach (var trafficGraph
in server.TrafficGraphs)
430 foreach (var peerGraph
in server.PeerGraphs)
433 foreach (var peerSummaryPage
in server.PeerSummaryPages)
441 if (config.
Notify != null)
452 initlog.SchedulerError(e);
478 File.WriteAllText(pidFile, pid.ToString(CultureInfo.InvariantCulture));
482 initlog.PidFileError(e);
static LogBase CreateLog(ILogConfiguration config)
bool InitializeDatabase()
LogBase Log
Gets the log used by this Scheduler.
A scheduler performs scheduling of jobs according to job schedule descriptions.
bool InitializeConfiguration()
Initializes the configuration.
void Add(JobDescription description)
Add the specified job to the scheduler queue.
HostDatabaseMapper Hosts
Gets the host mapper.
void InitializeCluster()
Initializes the cluster nodes.
NotifyConfiguration Notify
bool InitializeSecurity()
Initializes the security settings.
Job which read statistics from an ntp drift file and saves the result to a database.
static Importer< AssociationEntry > CreatePeerImporter(string address, ServerType type, Host host, LogBase log)
TimeServerDatabaseMapper Servers
Gets the time server mapper.
static void Initialize(IDatabaseConfiguration factoryConfiguration)
void InitializeScheduler()
Initializes the scheduler.
Job which read statistics about an ntp host and saves the result to a database.
static Configuration Config
uint FileMode
The file mode to apply for created files.
bool InitializeLog()
Initializes the log.
ClusterConfiguration Cluster
void InitializeListeners()
Initializes the listeners.
IEnumerable< ListenerConfiguration > Monitors
static bool SetUserId(uint userId)
IEnumerable< ReadingBulkConfiguration > Bulks
IEnumerable< HostConfiguration > Servers
AssociationEntryMapper AssociationEntries
Gets the association entry mapper.
PeerDatabaseMapper Peers
Gets the peer mapper.
static void Initialize(LogBase log)
static void Initialize(bool enable)
static SqlDatabaseFactory Instance
IEnumerable< NodeConfiguration > Nodes
void Run()
Run the NTP Analyzer.
Singleton facade class used to access memory persistent data.
static DateTime StartupTime
void InitializeApplication()
Initializes the application and database state.
static readonly Dictionary< string, int > List
DatabaseConfiguration Database
readonly string configFile
HeartbeatConfiguration Heartbeat
Job which read statistics about peers and saves the result to a database.
static IScheduler Scheduler
static DataFace Instance
Gets the Singleton instance.
DateTime StartTime
Gets the start up time of this Scheduler.
abstract void Initialize()
readonly LogGroup initlog
PermissionConfiguration Permission
Initializer(string configFile, int pid, string pidFile, string name, LogGroup initlog)
Initializes a new instance of the Initializer class.
IEnumerable< LogConfiguration > Log