Skip to content

Commit

Permalink
Add Dataplicity Absent status (#117)
Browse files Browse the repository at this point in the history
* Set Dataplicity status to Absent for a node that is not returned by
  dataplicity (addresses part of #114)
* Set Orcasound status to Absent for a node that is not returned by
  Orcasite (addresses part of #114)
* Update legend (fixes #113)
* Fix bug when a node is on dataplicity but not orcasite

Signed-off-by: Dave Thaler <[email protected]>
  • Loading branch information
dthaler authored Sep 5, 2024
1 parent d17bd31 commit fc09da5
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
42 changes: 42 additions & 0 deletions OrcanodeMonitor/Core/Fetcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ public async static Task UpdateDataplicityDataAsync(OrcanodeMonitorContext conte
jsonArray = await response.Content.ReadAsStringAsync();
}

// Create a list to track what nodes are no longer returned.
var unfoundList = context.Orcanodes.ToList();

dynamic deviceArray = JsonSerializer.Deserialize<JsonElement>(jsonArray);
if (deviceArray.ValueKind != JsonValueKind.Array)
{
Expand All @@ -301,6 +304,13 @@ public async static Task UpdateDataplicityDataAsync(OrcanodeMonitorContext conte
continue;
}

// Remove the found node from the unfound list.
Orcanode? oldListNode = unfoundList.Find(a => a.DataplicitySerial == serial.ToString());
if (oldListNode != null)
{
unfoundList.Remove(oldListNode);
}

Orcanode node = FindOrCreateOrcanodeByDataplicitySerial(context.Orcanodes, serial.ToString(), out OrcanodeOnlineStatus oldStatus);
OrcanodeUpgradeStatus oldAgentUpgradeStatus = node.DataplicityUpgradeStatus;
long oldDiskCapacityInGigs = node.DiskCapacityInGigs;
Expand Down Expand Up @@ -375,6 +385,16 @@ public async static Task UpdateDataplicityDataAsync(OrcanodeMonitorContext conte
}
}

// Mark any remaining unfound nodes as absent.
foreach (var unfoundNode in unfoundList)
{
var oldNode = FindOrcanodeByDataplicitySerial(context.Orcanodes, unfoundNode.DataplicitySerial, out OrcanodeOnlineStatus unfoundNodeStatus);
if (oldNode != null)
{
oldNode.DataplicityOnline = null;
}
}

MonitorState.GetFrom(context).LastUpdatedTimestampUtc = DateTime.UtcNow;
await context.SaveChangesAsync();
}
Expand Down Expand Up @@ -408,6 +428,10 @@ public async static Task UpdateOrcasoundDataAsync(OrcanodeMonitorContext context
{
return;
}

// Create a list to track what nodes are no longer returned.
var unfoundList = context.Orcanodes.ToList();

foreach (JsonElement feed in dataArray.EnumerateArray())
{
if (!feed.TryGetProperty("id", out var feedId))
Expand All @@ -434,6 +458,13 @@ public async static Task UpdateOrcasoundDataAsync(OrcanodeMonitorContext context
}
string dataplicitySerial = dataplicity_id.ToString();

// Remove the found node from the unfound list.
Orcanode? oldListNode = unfoundList.Find(a => a.OrcasoundFeedId == feedId.ToString());
if (oldListNode != null)
{
unfoundList.Remove(oldListNode);
}

Orcanode? node = null;
node = FindOrcanodeByOrcasoundFeedId(context.Orcanodes, feedId.ToString());
if (node == null)
Expand Down Expand Up @@ -512,6 +543,17 @@ public async static Task UpdateOrcasoundDataAsync(OrcanodeMonitorContext context
node.OrcasoundVisible = visible.GetBoolean();
}
}

// Mark any remaining unfound nodes as absent.
foreach (var unfoundNode in unfoundList)
{
var oldNode = FindOrcanodeByOrcasoundFeedId(context.Orcanodes, unfoundNode.OrcasoundFeedId);
if (oldNode != null)
{
oldNode.OrcasoundFeedId = String.Empty;
}
}

await context.SaveChangesAsync();
}
catch (Exception ex)
Expand Down
12 changes: 11 additions & 1 deletion OrcanodeMonitor/Models/Orcanode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public Orcanode()
// Initialize reference types.
OrcasoundName = string.Empty;
OrcasoundSlug = string.Empty;
OrcasoundFeedId = string.Empty;
S3Bucket = string.Empty;
S3NodeName = string.Empty;
AgentVersion = string.Empty;
Expand Down Expand Up @@ -231,7 +232,16 @@ private static double MinIntelligibleStreamDeviation
public long DiskCapacityInGigs => DiskCapacity / 1000000000;

public OrcanodeUpgradeStatus DataplicityUpgradeStatus => DataplicityUpgradeAvailable ?? false ? OrcanodeUpgradeStatus.UpgradeAvailable : OrcanodeUpgradeStatus.UpToDate;
public OrcanodeOnlineStatus DataplicityConnectionStatus => DataplicityOnline ?? false ? OrcanodeOnlineStatus.Online : OrcanodeOnlineStatus.Offline;
public OrcanodeOnlineStatus DataplicityConnectionStatus {
get
{
if (!DataplicityOnline.HasValue)
{
return OrcanodeOnlineStatus.Absent;
}
return (DataplicityOnline.Value) ? OrcanodeOnlineStatus.Online : OrcanodeOnlineStatus.Offline;
}
}

#if ORCAHELLO
public string OrcaHelloName
Expand Down
6 changes: 6 additions & 0 deletions OrcanodeMonitor/Pages/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@
<p/>
<h4 style="text-align: left;">Legend</h4>
<ul style="text-align: left;">
<li>
<b>Dataplicity Absent</b>: Dataplicity does not know about the node.
</li>
<li>
<b>Dataplicity Offline</b>: Dataplicity connection is down.
</li>
Expand All @@ -105,6 +108,9 @@
<li>
<b>Orcasound Absent</b>: live.orcasound.net does not know about the node.
</li>
<li>
<b>Orcasound Hidden</b>: live.orcasound.net knows about but does not display the node.
</li>
<li>
<b>Orcasound Online</b>: live.orcasound.net knows about the node.
</li>
Expand Down

0 comments on commit fc09da5

Please sign in to comment.