1
0
mirror of https://bitbucket.org/anguist/ntpa synced 2025-11-23 20:09:20 +00:00
Files
ntpa/Ntp.Analyzer.Process/Description/HostStatJob.cs

84 lines
2.9 KiB
C#
Raw Normal View History

2016-08-06 16:19:35 +02:00
//
// Copyright (c) 2013-2016 Carsten Sonne Larsen <cs@innolan.dk>
//
2016-04-02 11:22:42 +02:00
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
2016-08-06 16:19:35 +02:00
//
2016-04-02 11:22:42 +02:00
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
2016-08-06 16:19:35 +02:00
//
2016-04-02 11:22:42 +02:00
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
2016-04-10 11:50:35 +02:00
2016-04-02 11:22:42 +02:00
using System;
using System.Linq;
2016-08-06 16:19:35 +02:00
using Ntp.Analyzer.Config.Node;
2016-04-02 11:22:42 +02:00
using Ntp.Analyzer.Data;
2016-05-22 23:40:47 +02:00
using Ntp.Analyzer.Import;
2016-04-02 11:22:42 +02:00
using Ntp.Analyzer.Objects;
2016-08-27 13:28:21 +02:00
using Ntp.Analyzer.Process.Log;
2016-08-18 19:18:52 +02:00
using Ntp.Common.Log;
using Ntp.Common.Process;
2016-04-02 11:22:42 +02:00
namespace Ntp.Analyzer.Process.Description
{
/// <summary>
/// Job which read statistics about an ntp host and saves the result to a database.
/// </summary>
public sealed class HostStatJob : JobDescription
{
2016-08-06 16:19:35 +02:00
public HostStatJob(StatConfiguration config, LogBase log)
2016-04-02 11:22:42 +02:00
: base(config, log)
{
this.config = config;
}
2016-08-06 16:19:35 +02:00
private readonly StatConfiguration config;
2016-05-22 23:40:47 +02:00
2016-08-06 16:19:35 +02:00
public override ThreadType ThreadType => ThreadType.MultiThreaded;
2016-04-02 11:22:42 +02:00
2016-08-06 16:19:35 +02:00
public override string JobType => "Host statistics";
2016-04-02 11:22:42 +02:00
2016-08-06 16:19:35 +02:00
public override int Priority => 2;
2016-04-02 11:22:42 +02:00
2016-05-22 23:40:47 +02:00
protected override void InternalExecute()
2016-04-02 11:22:42 +02:00
{
2016-08-27 13:28:21 +02:00
var host = DataFace.Instance.Hosts.SingleOrDefault(h => h.Id == config.HostId);
2016-05-22 23:40:47 +02:00
if (host == null)
{
2016-08-27 13:28:21 +02:00
Log.HostNotFound(config.HostId);
2016-04-02 11:22:42 +02:00
return;
}
2016-08-27 13:28:21 +02:00
var bulk = config.Bulk == null
? new ReadingBulk(host.Name, config.TimeStamp)
: DataFace.Instance.ReadingBulks.Single(b => b.Name == config.Bulk.Name);
2016-05-22 23:40:47 +02:00
2016-08-27 13:28:21 +02:00
var importer = ImportFactory.CreateHostImporter(config.ServerName, config.ServerType, host, bulk, Log);
2016-05-22 23:40:47 +02:00
try
{
importer.Execute();
}
catch (Exception e)
{
2016-08-27 13:28:21 +02:00
Log.HostImportError(e);
2016-04-02 11:22:42 +02:00
return;
}
2016-08-27 13:28:21 +02:00
foreach (var reading in importer)
2016-05-22 23:40:47 +02:00
{
DataFace.Instance.HostReadings.Save(reading);
2016-04-02 11:22:42 +02:00
}
}
}
2016-03-05 15:25:01 +01:00
}