Skip to content

Commit

Permalink
Merge pull request #75 from SimCorp/develop
Browse files Browse the repository at this point in the history
Release 0.5.0
  • Loading branch information
EDBM authored May 11, 2021
2 parents c6ce882 + c43f063 commit c118791
Show file tree
Hide file tree
Showing 19 changed files with 536 additions and 227 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ node_modules


# local env files
env
.env
.env.local
.env.*.local
Expand Down
20 changes: 17 additions & 3 deletions backend/Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,31 @@ public ActionResult<String> GetTimeOfRequest()
return timeOfRequest;
}

[HttpGet("/iptoserverid")]
[ProducesResponseType(Status200OK)]
public ActionResult<Dictionary<string, string>> GetIpToServerId()
{
return _dataStorage.ipToServerId;
}

[HttpGet("/leaflinks")]
[ProducesResponseType(Status200OK)]
public ActionResult<List<LeafLink>> GetLeafLinks()
{
return _dataStorage.leafLinks;
}

[HttpGet("/gatewayLinks")]
[ProducesResponseType(Status200OK)]
public ActionResult<IEnumerable<Link>> GetGatewayLinks()
public ActionResult<IEnumerable<GatewayLink>> GetGatewayLinks()
{
var gatewayLinks = new List<Link>();
var gatewayLinks = new List<GatewayLink>();
foreach (var cluster in _dataStorage.clusterConnectionErrors)
{
var split = cluster.Key.Split(" NAMESPLIT ");
var source = split[0];
var target = split[1];
var link = new Link (source, target, cluster.Value.Count > 0);
var link = new GatewayLink (source, target, cluster.Value.Count > 0);
link.errors = cluster.Value;
foreach (var err in cluster.Value)
{
Expand Down
12 changes: 9 additions & 3 deletions backend/DataStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class DataStorage
public ConcurrentBag<backend.models.Connection> connections;
public ConcurrentBag<Route> routes;
public ConcurrentBag<Gateway> gateways;
public ConcurrentBag<Leaf> leafs;
public List<Leaf> leafs;
public List<Link> links;
public ConcurrentBag<ServerNode> processedServers;
public ConcurrentBag<ClusterNode> processedClusters;
Expand All @@ -24,7 +24,9 @@ public class DataStorage
public Dictionary<string, string> serverToCluster = new Dictionary<string, string>();
public Dictionary<string, List<string>> clusterConnectionErrors = new Dictionary<string, List<string>>();
public List<ClusterNode> errorClusters = new List<ClusterNode>();

public Dictionary<string, string> ipToServerId;
public List<LeafLink> leafLinks;
public HashSet<string> leafConnections;

public DataStorage() {

Expand All @@ -33,18 +35,22 @@ public DataStorage() {
connections = new ConcurrentBag<backend.models.Connection>();
routes = new ConcurrentBag<Route>();
gateways = new ConcurrentBag<Gateway>();
leafs = new ConcurrentBag<Leaf>();
leafs = new List<Leaf>();

links = new List<Link>();
processedServers = new ConcurrentBag<ServerNode>();
processedClusters = new ConcurrentBag<ClusterNode>();
serverToMissingServer = new Dictionary<string, List<string>>();
ipToServerId = new Dictionary<string, string>();
leafLinks = new List<LeafLink>();


missingServerIds = new HashSet<string>();
foundServers = new HashSet<string>();
serverToCluster = new Dictionary<string, string>();
clusterConnectionErrors = new Dictionary<string, List<string>>();
errorClusters = new List<ClusterNode>();
leafConnections = new HashSet<string>();
}
}
}
112 changes: 104 additions & 8 deletions backend/DrawablesProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public void ProcessData()
ProcessServers();
ProcessClusters();
ProcessLinks();
ProcessLeafs();

// Patch for a missing node from varz
// TODO dynamically handle these types of errors
Expand Down Expand Up @@ -58,6 +59,77 @@ public void ProcessData()
}
}

public void ProcessLeafs()
{

var leafIps = new HashSet<string>();
foreach (var entry in _dataStorage.leafs)
{
if (entry.leafs is null) continue;
foreach (var leaf in entry.leafs)
{
leafIps.Add(leaf.ip);
}
}

foreach (var entry in _dataStorage.routes)
{
foreach (var route in entry.routes)
{
if (_dataStorage.ipToServerId.ContainsKey(route.ip)) continue;
if (leafIps.Contains(route.ip))
{
_dataStorage.ipToServerId.Add(route.ip, route.remote_id);
}
}
}
ConstructSingleLeafConnections();
}

public void ConstructSingleLeafConnections()
{
// TODO functionality about bidirectionality is currently not being used. Should maybe be removed.
foreach (var server in _dataStorage.leafs)
{
if (server.leafs is null) continue;
foreach (var leaf in server.leafs)
{
// TODO leafs to unknown servers are not handled
if (!_dataStorage.ipToServerId.ContainsKey(leaf.ip)) continue;
var targetId = _dataStorage.ipToServerId[leaf.ip];

var oppositeLink = _dataStorage.leafLinks.Where(l =>
l.source == targetId &&
l.target == server.server_id
).Select(l => l).FirstOrDefault();

var identicalLink = _dataStorage.leafLinks.Where(l =>
l.target == targetId &&
l.source == server.server_id
).Select(l => l).FirstOrDefault();

if (identicalLink is not null)
{
identicalLink.connections.Add(leaf); // Add leafnode to be fetched when link is clicked
}
else if (oppositeLink is null)
{
var link = new LeafLink (
server.server_id,
targetId
);
link.connections.Add(leaf);
_dataStorage.leafLinks.Add(link);
}
else
{
oppositeLink.connections.Add(leaf);
}

}
}
}

public void ProcessClusters()
{
// TODO crashed node is not in cluster, decide whether it should be.
Expand Down Expand Up @@ -170,9 +242,9 @@ public void ProcessServers()
});
}

public string clusterTupleString(string cluster1, string cluster2)
public string tupleString(string id1, string id2)
{
return cluster1 + " NAMESPLIT " + cluster2;
return id1 + " NAMESPLIT " + id2;
}

public (string, string) stringToTuple (string input)
Expand All @@ -187,33 +259,57 @@ public void detectGatewaysToCrashedServers() {
if (gateway.name is null) continue;
foreach (var outbound in gateway.outbound_gateways)
{
if (!_dataStorage.clusterConnectionErrors.ContainsKey(clusterTupleString(gateway.name, outbound.Key)) && !_dataStorage.clusterConnectionErrors.ContainsKey(clusterTupleString(outbound.Key, gateway.name)))
if (!_dataStorage.clusterConnectionErrors.ContainsKey(tupleString(gateway.name, outbound.Key)) && !_dataStorage.clusterConnectionErrors.ContainsKey(tupleString(outbound.Key, gateway.name)))
{
_dataStorage.clusterConnectionErrors.Add(clusterTupleString(gateway.name, outbound.Key), new List<string>());
_dataStorage.clusterConnectionErrors.Add(tupleString(gateway.name, outbound.Key), new List<string>());
}
if (!_dataStorage.idToServer.ContainsKey(outbound.Value.connection.name))
{
_dataStorage.clusterConnectionErrors[clusterTupleString(gateway.name, outbound.Key)].Add("Outbound gateway to crashed server. From " + gateway.server_id + " to " + outbound.Value.connection.name);
_dataStorage.clusterConnectionErrors[tupleString(gateway.name, outbound.Key)].Add("Outbound gateway to crashed server. From " + gateway.server_id + " to " + outbound.Value.connection.name);
}
}
foreach (var inbound in gateway.inbound_gateways)
{
if (!_dataStorage.clusterConnectionErrors.ContainsKey(clusterTupleString(gateway.name, inbound.Key)) && !_dataStorage.clusterConnectionErrors.ContainsKey(clusterTupleString(inbound.Key, gateway.name)))
if (!_dataStorage.clusterConnectionErrors.ContainsKey(tupleString(gateway.name, inbound.Key)) && !_dataStorage.clusterConnectionErrors.ContainsKey(tupleString(inbound.Key, gateway.name)))
{
_dataStorage.clusterConnectionErrors.Add(clusterTupleString(gateway.name, inbound.Key), new List<string>());
_dataStorage.clusterConnectionErrors.Add(tupleString(gateway.name, inbound.Key), new List<string>());
}
foreach (var inboundEntry in inbound.Value)
{
if (!_dataStorage.idToServer.ContainsKey(inboundEntry.connection.name))
{
_dataStorage.clusterConnectionErrors[clusterTupleString(gateway.name, inbound.Key)].Add("Inbound gateway to crashed server. To " + gateway.server_id + " from " + inboundEntry.connection.name);
_dataStorage.clusterConnectionErrors[tupleString(gateway.name, inbound.Key)].Add("Inbound gateway to crashed server. To " + gateway.server_id + " from " + inboundEntry.connection.name);
}

}
}
}
}

public void detectLeafConnections ()
{
foreach (var leafLink in _dataStorage.leafLinks)
{
if (! _dataStorage.leafConnections.Contains(tupleString(leafLink.source, leafLink.target)))
{
if (! _dataStorage.leafConnections.Contains(tupleString(leafLink.target, leafLink.source)))
{
_dataStorage.leafConnections.Add(tupleString(leafLink.source, leafLink.target)); //<-- only one leaf connection is shown
continue;
}
}

if (! _dataStorage.leafConnections.Contains(tupleString(leafLink.target, leafLink.source)))
{
if (! _dataStorage.leafConnections.Contains(tupleString(leafLink.source, leafLink.target)))
{
_dataStorage.leafConnections.Add(tupleString(leafLink.target, leafLink.source)); //<-- only one leaf connection is shown

continue;
}
}
}
}
public void constructClustersOfBrokenGateways()
{
foreach (var gateway in _dataStorage.gateways)
Expand Down
17 changes: 17 additions & 0 deletions backend/drawables/GatewayLink.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Collections.Generic;
using backend.models;

namespace backend.drawables
{
public class GatewayLink : Link
{
public List<string> errors { get; set; }
public string errorsAsString { get; set; }

public GatewayLink(string source, string target, bool ntv_error = false) : base(source, target, ntv_error)
{
errors = new List<string>();
errorsAsString = source + " to/from " + target;
}
}
}
14 changes: 14 additions & 0 deletions backend/drawables/LeafLink.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Collections.Generic;
using backend.models;

namespace backend.drawables
{
public class LeafLink : Link
{
public List<LeafNode> connections { get; set; }
public LeafLink(string source, string target) : base(source, target)
{
connections = new List<LeafNode>();
}
}
}
9 changes: 3 additions & 6 deletions backend/drawables/Link.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
using System.Collections.Generic;
using System;

namespace backend.drawables
{
public class Link
public class Link
{
public string source { get; }
public string target { get; }

public bool ntv_error { get; set; }
public List<string> errors { get; set; }
public string errorsAsString { get; set; }



public Link(string source, string target, bool ntv_error = false)
{
this.source = source;
this.target = target;
this.ntv_error = ntv_error;
errors = new List<string>();
errorsAsString = source + " to/from " + target;
}
}
}
1 change: 0 additions & 1 deletion backend/env

This file was deleted.

3 changes: 1 addition & 2 deletions backend/models/Leaf.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.Concurrent;

namespace backend
{
Expand All @@ -9,7 +8,7 @@ public class Leaf
public string server_id { get; set; }
public string now { get; set; }
public int leafnodes { get; set; }
public ConcurrentBag<LeafNode> leafs { get; set; }
public List<LeafNode> leafs { get; set; }
}


Expand Down
Loading

0 comments on commit c118791

Please sign in to comment.