Skip to content

Commit

Permalink
force refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
fsmeneses committed Jan 27, 2025
1 parent 74ac2c6 commit 7d20c62
Show file tree
Hide file tree
Showing 9 changed files with 250 additions and 104 deletions.
175 changes: 136 additions & 39 deletions MWCore-AdHoc-E2E-Streams_1/MWCore-AdHoc-E2E-Streams_1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,27 @@ namespace GQIIntegrationSPI
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

using MWCoreAdHocE2EStreams_1.Misc;

using Skyline.DataMiner.Analytics.GenericInterface;

//using Skyline.DataMiner.Utils.TXCore.Cache;
//using Skyline.DataMiner.Utils.TXCore.Cache.Misc.Enums;

[GQIMetaData(Name = "MWCore E2E Stream")]
public class GQIDataSourceAdHocE2EStreams : IGQIDataSource, IGQIInputArguments, IGQIOnInit
{
private readonly GQIStringArgument _argumentEdgeName = new GQIStringArgument("MWEdge Name") { IsRequired = true };
private readonly GQIStringArgument _argumentElementName = new GQIStringArgument("Element Name") { IsRequired = true };
private readonly GQIStringArgument _argumentStreamName = new GQIStringArgument("Stream Name") { IsRequired = true };
private readonly bool _debug = true;
private readonly string file = $"C:\\Users\\SamuelDT\\Downloads\\e2eLog-Parallel-{DateTime.Now.ToOADate()}.txt";
private readonly bool _debug = true; // C:\Skyline DataMiner\Logging\GQI\Ad hoc data sources

private GQIDMS _dms;
private string _edgeName;
private string _elementName;
private string _streamName;
private IGQILogger _logger;
private bool _hasnextpage;

public GQIColumn[] GetColumns()
{
Expand Down Expand Up @@ -107,32 +108,64 @@ public GQIArgument[] GetInputArguments()
public GQIPage GetNextPage(GetNextPageInputArgs args)
{
GQIRow[] data2retrieve;
if (_debug)
{
string text = $"--------{DateTime.Now}---------{Environment.NewLine}{_edgeName}/{_streamName}{Environment.NewLine}";
File.WriteAllText(file, text);
}

try
{
var streams = StreamsIO.Instance(_dms, _elementName);
if (_debug)
{
File.AppendAllText(file, $"Time: {DateTime.Now}\nEnded GetInstance!\n");
_logger.Debug($"{_edgeName}/{_streamName}");
}

StreamsIO streams;
streams = StreamsIO.Instance(_dms, _logger, _elementName);

if (streams == default)
{
return new GQIPage(new GQIRow[0]);
}

if (_debug)
{
_logger.Debug($"Ended GetInstance!");
}

var hops = StreamsIO.GetHops(streams, _edgeName, _streamName);
var hops = streams.GetHops(_edgeName, _streamName);

if (_debug)
{
File.AppendAllText(file, $"Time: {DateTime.Now}\nEnded GetHops loop!\n");
_logger.Debug($"Ended GetHops loop!");
}

data2retrieve = RetrieveToGqi(hops);
}
catch (Exception ex)
{
if (_debug)
{
_logger.Debug($"Exception: {ex}");
}

List<GQIRow> rows = new List<GQIRow>();
foreach (var hop in hops)
data2retrieve = new GQIRow[0];
}

if (_debug)
{
_logger.Debug($"Completed {_edgeName}/{_streamName}!");
}

return new GQIPage(data2retrieve)
{
HasNextPage = false,
};
}

private static GQIRow[] RetrieveToGqi(HashSet<Hop> hops)
{
GQIRow[] data2retrieve;
List<GQIRow> rows = new List<GQIRow>();
foreach (var hop in hops)
{
rows.Add(new GQIRow(new[]
{
rows.Add(new GQIRow(new[]
{
new GQICell { Value = hop.Id_Src}, // IO ID SRC
new GQICell { Value = hop.Name_Src}, // IO Name SRC
new GQICell { Value = hop.IOType == 0 ? "Source" : "Output" }, // IO SRC
Expand All @@ -152,15 +185,15 @@ public GQIPage GetNextPage(GetNextPageInputArgs args)
new GQICell { Value = hop.Hop_Number},
new GQICell { Value = hop.IsActive},
}));
}
}

// adding an extra line to facilitate the node-edge component
var lastOutputs = hops.Where(x => x.IOType == IOType.Input && x.Hop_Number == hops.Max(y => y.Hop_Number));
// adding an extra line to facilitate the node-edge component
var lastOutputs = hops.Where(x => x.IOType == IOType.Input && x.Hop_Number == hops.Max(y => y.Hop_Number));

foreach (var lastHop in lastOutputs)
foreach (var lastHop in lastOutputs)
{
rows.Add(new GQIRow(new[]
{
rows.Add(new GQIRow(new[]
{
new GQICell { Value = lastHop.Id_Dst }, // IO ID SRC
new GQICell { Value = lastHop.Name_Dst }, // IO Name SRC
new GQICell { Value = "Output" }, // IO Type SRC
Expand All @@ -180,42 +213,106 @@ public GQIPage GetNextPage(GetNextPageInputArgs args)
new GQICell { Value = lastHop.Hop_Number},
new GQICell { Value = lastHop.IsActive},
}));
}

data2retrieve = rows.ToArray();
}
catch (Exception ex)

data2retrieve = rows.ToArray();
return data2retrieve;
}

public OnArgumentsProcessedOutputArgs OnArgumentsProcessed(OnArgumentsProcessedInputArgs args)
{
_elementName = args.GetArgumentValue(_argumentElementName);
_edgeName = args.GetArgumentValue(_argumentEdgeName);
_streamName = args.GetArgumentValue(_argumentStreamName);
return new OnArgumentsProcessedOutputArgs();
}

public OnInitOutputArgs OnInit(OnInitInputArgs args)
{
_dms = args.DMS;
_logger = args.Logger;
_logger.MinimumLogLevel = GQILogLevel.Debug;
return default;
}
}

[GQIMetaData(Name = "MWCore E2E Stream - Cache Refresh")]
public class GQIDataSourceAdHocE2EStreamsCacheRefresh : IGQIDataSource, IGQIInputArguments, IGQIOnInit
{
private readonly bool _debug = true; // C:\Skyline DataMiner\Logging\GQI\Ad hoc data sources

private GQIDMS _dms;
private IGQILogger _logger;
private bool _hasnextpage;

public GQIColumn[] GetColumns()
{
return new GQIColumn[]
{
new GQIStringColumn("IO ID SRC"),
new GQIStringColumn("IO Name SRC"),
new GQIStringColumn("IO SRC"),
new GQIStringColumn("IO State SRC"),
new GQIStringColumn("IO Type SRC"),
new GQIDoubleColumn("Bitrate SRC"),
new GQIStringColumn("Stream Name SRC"),
new GQIStringColumn("Edge Name SRC"),
new GQIStringColumn("IO ID DST"),
new GQIStringColumn("IO Name DST"),
new GQIStringColumn("IO State DST"),
new GQIStringColumn("IO Type DST"),
new GQIDoubleColumn("Bitrate DST"),
new GQIStringColumn("Stream Name DST"),
new GQIStringColumn("Edge Name DST"),
new GQIBooleanColumn("Starting Point"),
new GQIIntColumn("Hop"),
new GQIBooleanColumn("Active"),
};
}

public GQIArgument[] GetInputArguments()
{
return new GQIArgument[] { };
}

public GQIPage GetNextPage(GetNextPageInputArgs args)
{
try
{
if (_debug)
{
File.AppendAllText(file, $"Exception: {ex}\n");
_logger.Debug($"Force refresh");
}

data2retrieve = new GQIRow[0];
}
StreamsIO.Instance(_dms, _logger, string.Empty, true);

if (_debug)
return new GQIPage(new GQIRow[0]);
}
catch (Exception ex)
{
File.AppendAllText(file, $"End Time: {DateTime.Now}\n");
if (_debug)
{
_logger.Debug($"Exception: {ex}");
}
}

return new GQIPage(data2retrieve)
_hasnextpage = !_hasnextpage;
return new GQIPage(new GQIRow[0])
{
HasNextPage = false,
HasNextPage = _hasnextpage,
};
}

public OnArgumentsProcessedOutputArgs OnArgumentsProcessed(OnArgumentsProcessedInputArgs args)
{
_elementName = args.GetArgumentValue(_argumentElementName);
_edgeName = args.GetArgumentValue(_argumentEdgeName);
_streamName = args.GetArgumentValue(_argumentStreamName);
return new OnArgumentsProcessedOutputArgs();
}

public OnInitOutputArgs OnInit(OnInitInputArgs args)
{
_dms = args.DMS;
_logger = args.Logger;
_logger.MinimumLogLevel = GQILogLevel.Debug;
return default;
}
}
Expand Down
3 changes: 1 addition & 2 deletions MWCore-AdHoc-E2E-Streams_1/MWCore-AdHoc-E2E-Streams_1.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
<DefineConstants>$(DefineConstants);DCFv1;DBInfo;ALARM_SQUASHING</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Skyline.DataMiner.Core.DataMinerSystem.Automation" Version="1.1.0.5" />
<PackageReference Include="Skyline.DataMiner.Dev.Automation" Version="10.3.6" />
<PackageReference Include="Skyline.DataMiner.Dev.Automation" Version="10.4.8" />
</ItemGroup>
<ProjectExtensions>
<VisualStudio>
Expand Down
62 changes: 49 additions & 13 deletions MWCore-AdHoc-E2E-Streams_1/Misc/StreamsIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ internal sealed class StreamsIO
private static readonly object _padlock = new object();
private static Dictionary<string, ElementCache> _instances = new Dictionary<string, ElementCache>();
private readonly GQIDMS _dms;
private Dictionary<string, HashSet<Hop>> _hops;

private StreamsIO(GQIDMS dms, string elementName)
{
Expand Down Expand Up @@ -49,6 +50,8 @@ private StreamsIO(GQIDMS dms, string elementName)
}

OutputsTable = outputsTable;

_hops = new Dictionary<string, HashSet<Hop>>();
}

public IEnumerable<EdgeTable> EdgesTable { get; }
Expand All @@ -57,22 +60,44 @@ private StreamsIO(GQIDMS dms, string elementName)

public IEnumerable<Iotable> OutputsTable { get; }

public static StreamsIO Instance(GQIDMS dms, string elementName)
public static StreamsIO Instance(GQIDMS dms, IGQILogger logger, string elementName = "", bool forceRefresh = false)
{
var now = DateTime.UtcNow;
ElementCache instance;
logger.Debug($"Element: {elementName}");

if (!_instances.TryGetValue(elementName, out instance) ||
(now - instance.LastRun) > TimeSpan.FromSeconds(_cachingTime))
if (forceRefresh /*&& !_instances.Keys.Any()*/)
{
var newInstances = new Dictionary<string, ElementCache>();
DMSMessage[] responseElement = dms.SendMessages(GetLiteElementInfo.ByProtocol("Techex MWCore", "Production"));// as LiteElementInfoEvent;
foreach (LiteElementInfoEvent item in responseElement)
{
logger.Debug($"Element: {item.Name}");
instance = new ElementCache(new StreamsIO(dms, item.Name), now);
newInstances[item.Name] = instance;
}

lock (_padlock)
{
instance = new ElementCache(new StreamsIO(dms, elementName), now);
_instances[elementName] = instance;
_instances = newInstances;
}
}

return instance.Instance;
return default;
}
else
{
lock (_padlock)
{
if (!_instances.TryGetValue(elementName, out instance) ||
(now - instance.LastRun) > TimeSpan.FromSeconds(_cachingTime))
{
instance = new ElementCache(new StreamsIO(dms, elementName), now);
_instances[elementName] = instance;
}

return instance.Instance;
}
}
}

/// <summary>
Expand All @@ -85,14 +110,23 @@ public static StreamsIO Instance(GQIDMS dms, string elementName)
/// <returns>
/// A list of <see cref="Hop"/> objects, each representing a connection between inputs and outputs along with additional metadata.
/// </returns>
public static HashSet<Hop> GetHops(StreamsIO instance, string edgeName, string streamName)
public HashSet<Hop> GetHops(string edgeName, string streamName)
{
HashSet<Hop> hops = new HashSet<Hop>();
HashSet<Hop> hops;
string key = $"{edgeName}/{streamName}";
if (_hops.TryGetValue(key, out hops))
{
return hops;
}
else
{
hops = new HashSet<Hop>();
}

var inputs = new HashSet<Iotable>(instance.InputsTable.Where(input =>
var inputs = new HashSet<Iotable>(InputsTable.Where(input =>
input.Stream == streamName && input.MWEdge == edgeName && !input.Protocol.Equals("2022-7")));

var outputs = new HashSet<Iotable>(instance.OutputsTable.Where(output =>
var outputs = new HashSet<Iotable>(OutputsTable.Where(output =>
output.Stream == streamName && output.MWEdge == edgeName && output.Port != "-1"));

foreach (var input in inputs)
Expand All @@ -104,10 +138,12 @@ public static HashSet<Hop> GetHops(StreamsIO instance, string edgeName, string s
}

// Get next hop - look for inputs that are connected to the started outputs.
FindNextHop(instance, hops, outputs, 0);
FindNextHop(this, hops, outputs, 0);

// Get previous hop - look for outputs connected to the started inputs.
FindPreviousHop(instance, hops, inputs, 0);
FindPreviousHop(this, hops, inputs, 0);

_hops[key] = hops;

return hops;
}
Expand Down
4 changes: 2 additions & 2 deletions MWCoreDownloadThumbnails_1/MWCoreDownloadThumbnails_1.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
<DefineConstants>$(DefineConstants);DCFv1;DBInfo;ALARM_SQUASHING</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Skyline.DataMiner.Core.DataMinerSystem.Common" Version="1.1.0.5" />
<PackageReference Include="Skyline.DataMiner.Dev.Automation" Version="10.1.11" />
<PackageReference Include="Skyline.DataMiner.Core.DataMinerSystem.Common" Version="1.1.2.2" />
<PackageReference Include="Skyline.DataMiner.Dev.Automation" Version="10.4.8" />
</ItemGroup>
<ProjectExtensions>
<VisualStudio>
Expand Down
Loading

0 comments on commit 7d20c62

Please sign in to comment.