ln.skyscanner/SkyEntities.cs

132 lines
4.5 KiB
C#
Raw Normal View History

2019-03-26 12:53:42 +01:00
// /**
// * File: SkyEntities.cs
// * Author: haraldwolff
// *
// * This file and it's content is copyrighted by the Author and / or copyright holder.
// * Any use wihtout proper permission is illegal and may lead to legal actions.
// *
// *
// **/
using System;
using ln.types.odb;
using ln.skyscanner.entities;
using System.IO;
2019-04-05 00:59:04 +02:00
using ln.http.resources;
using System.Linq;
2019-04-08 08:47:12 +02:00
using ln.types.odb.mapped;
2019-04-11 08:30:13 +02:00
using ln.types.net;
using ln.skyscanner.crawl;
using ln.skyscanner.checks;
using ln.logging;
2019-04-16 18:23:05 +02:00
using System.Collections.Generic;
2019-03-26 12:53:42 +01:00
namespace ln.skyscanner
{
public class SkyEntities
{
public SkyScanner SkyScanner { get; }
public string BasePath => Path.Combine(SkyScanner.BasePath, "entities");
public GlobalNetwork GlobalNetwork { get; private set; }
2019-04-11 08:30:13 +02:00
public ODB ODB { get; private set; }
public ODBCollection<Node> NodeCollection { get; private set; }
public ODBCollection<Subnet> SubnetCollection { get; private set; }
2019-06-28 10:01:30 +02:00
2019-04-11 08:30:13 +02:00
public ODBCollection<PointOfPresence> PointOfPresenceCollection { get; private set; }
2019-06-28 10:01:30 +02:00
public ODBCollection<L2Segment> L2SegmentCollection { get; private set; }
2019-04-11 08:30:13 +02:00
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; }
2019-03-26 12:53:42 +01:00
public SkyEntities(SkyScanner skyScanner)
{
SkyScanner = skyScanner;
2019-04-11 08:30:13 +02:00
Logging.Log(LogLevel.INFO, "SkyEntities: initializing");
ODB = new ODB(BasePath);
NodeCollection = ODB.GetCollection<Node>();
NodeCollection.EnableStrongCache(true);
2019-04-16 18:23:05 +02:00
NodeCollection.EnsureIndex("uniqueIdentity", true);
2019-04-12 00:52:55 +02:00
NodeCollection.EnsureIndeces(
"PrimaryIP",
"Interfaces[].ConfiguredIPs[].IP",
2019-04-16 18:23:05 +02:00
"Interfaces[].ConfiguredIPs[].Network"
2019-04-12 00:52:55 +02:00
);
2019-04-12 14:19:30 +02:00
Network4 n192 = Network4.Parse("192.168.0.0/16");
2019-04-12 00:52:55 +02:00
/* Preload all nodes to increase load speed*/
2019-04-12 14:19:30 +02:00
foreach (Node node in NodeCollection.ToArray())
2019-04-12 00:52:55 +02:00
{
2019-04-15 09:18:41 +02:00
//if (n192.Contains(node.PrimaryIP))
//NodeCollection.Delete(node);
2019-04-12 00:52:55 +02:00
}
2019-04-11 08:30:13 +02:00
SubnetCollection = ODB.GetCollection<Subnet>();
2019-04-12 00:52:55 +02:00
SubnetCollection.EnsureIndeces("Network");
2019-04-11 08:30:13 +02:00
PointOfPresenceCollection = ODB.GetCollection<PointOfPresence>();
2019-04-12 00:52:55 +02:00
PointOfPresenceCollection.EnsureIndeces("ForeignName");
2019-04-11 08:30:13 +02:00
2019-06-28 10:01:30 +02:00
L2SegmentCollection = ODB.GetCollection<L2Segment>();
L2SegmentCollection.EnsureIndeces("Network","PoPs");
2019-04-11 08:30:13 +02:00
CrawledHosts = ODB.GetCollection<CrawledHost>();
2019-04-12 00:52:55 +02:00
CrawledHosts.EnsureIndeces("PrimaryIP","IPAddresses[]");
2019-03-26 12:53:42 +01:00
2019-04-11 08:30:13 +02:00
CrawledSubnets = ODB.GetCollection<CrawledSubnet>();
BlockedNetworks = ODB.GetCollection<Network4>("blockedNetworks");
2019-04-02 13:00:15 +02:00
2019-04-11 08:30:13 +02:00
SkyCheckStates = ODB.GetCollection<SkyCheckState>();
SkyCheckStates.EnableStrongCache(true);
2019-04-12 14:19:30 +02:00
SkyCheckStates.EnsureIndeces("Node");
2019-04-16 18:23:05 +02:00
SkyCheckStates.EnsureUniqueness("Node", "CheckName");
2019-04-12 14:19:30 +02:00
2019-04-15 09:18:41 +02:00
//foreach (SkyCheckState checkState in SkyCheckStates.ToArray())
//{
// if (object.ReferenceEquals(checkState.Node, null))
// SkyCheckStates.Delete(checkState);
//}
2019-03-29 08:55:09 +01:00
2019-04-11 08:30:13 +02:00
Logging.Log(LogLevel.INFO, "SkyEntities: initialized");
2019-04-08 08:47:12 +02:00
2019-04-11 08:30:13 +02:00
GlobalNetwork = new GlobalNetwork();
2019-03-26 12:53:42 +01:00
}
2019-04-16 18:23:05 +02:00
public PerformanceValue LookupPerformanceValue(String perfName)
{
string[] resourcePath = perfName.Split('/');
Node node = NodeCollection.Query("uniqueIdentity", resourcePath[0]).FirstOrDefault();
if (node == null)
throw new KeyNotFoundException();
SkyCheckState skyCheckState = SkyCheckStates.Query(
Query.AND(
Query.Equals<SkyCheckState>("Node", node.ID),
Query.Equals<SkyCheckState>("CheckName", resourcePath[1])
)
).FirstOrDefault();
if (skyCheckState == null)
throw new KeyNotFoundException();
foreach (PerformanceValue performanceValue in skyCheckState.PerformanceValues)
if (performanceValue.PerfName.Equals(perfName))
return performanceValue;
throw new KeyNotFoundException();
}
2019-03-26 12:53:42 +01:00
}
}