ln.skyscanner/services/EntityService.cs

93 lines
3.0 KiB
C#

using System;
using ln.application;
using ln.application.service;
using System.Threading;
using System.IO;
using ln.types.odb;
using ln.types.odb.mapped;
using ln.skyscanner.entities;
using ln.skyscanner.crawl;
using ln.types.net;
using ln.skyscanner.checks;
using ln.logging;
namespace ln.skyscanner.services
{
public class EntityService : ApplicationServiceBase
{
public string BasePath { get; private set; }
public ODB ODB { get; private set; }
public ODBCollection<Node> NodeCollection { get; private set; }
public ODBCollection<Subnet> SubnetCollection { get; private set; }
public ODBCollection<PointOfPresence> PointOfPresenceCollection { get; private set; }
public ODBCollection<L2Segment> L2SegmentCollection { get; private set; }
public ODBCollection<CrawledHost> CrawledHosts { get; private set; }
public ODBCollection<CrawledSubnet> CrawledSubnets { get; private set; }
public ODBCollection<Network4> BlockedNetworks { get; private set; }
public ODBCollection<SkyCheckState> SkyCheckStates { get; private set; }
public EntityService()
:base("Entity Service")
{
}
public override void ServiceMain(IApplicationInterface applicationInterface)
{
BasePath = Path.Combine(
CurrentApplicationInterface.Arguments["base-path"].Value,
"entities"
);
Logging.Log(LogLevel.INFO, "Entity Service: Initializing");
ODB = new ODB(BasePath);
NodeCollection = ODB.GetCollection<Node>();
NodeCollection.EnableStrongCache(true);
NodeCollection.EnsureIndex("uniqueIdentity", true);
NodeCollection.EnsureIndeces(
"PrimaryIP",
"Interfaces[].ConfiguredIPs[].IP",
"Interfaces[].ConfiguredIPs[].Network"
);
SubnetCollection = ODB.GetCollection<Subnet>();
SubnetCollection.EnsureIndeces("Network");
PointOfPresenceCollection = ODB.GetCollection<PointOfPresence>();
PointOfPresenceCollection.EnsureIndeces("ForeignName");
L2SegmentCollection = ODB.GetCollection<L2Segment>();
L2SegmentCollection.EnsureIndeces("Network", "PoPs");
CrawledHosts = ODB.GetCollection<CrawledHost>();
CrawledHosts.EnsureIndeces("PrimaryIP", "IPAddresses[]");
CrawledSubnets = ODB.GetCollection<CrawledSubnet>();
BlockedNetworks = ODB.GetCollection<Network4>("blockedNetworks");
SkyCheckStates = ODB.GetCollection<SkyCheckState>();
SkyCheckStates.EnableStrongCache(true);
SkyCheckStates.EnsureIndeces("Node");
SkyCheckStates.EnsureUniqueness("Node", "CheckName");
lock (Thread.CurrentThread)
{
Monitor.Wait(Thread.CurrentThread);
}
BasePath = null;
}
}
}