diff --git a/MWCore-AdHoc-E2E-Streams_1/MWCore-AdHoc-E2E-Streams_1.cs b/MWCore-AdHoc-E2E-Streams_1/MWCore-AdHoc-E2E-Streams_1.cs index 7ea62e4..b5da373 100644 --- a/MWCore-AdHoc-E2E-Streams_1/MWCore-AdHoc-E2E-Streams_1.cs +++ b/MWCore-AdHoc-E2E-Streams_1/MWCore-AdHoc-E2E-Streams_1.cs @@ -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() { @@ -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 rows = new List(); - 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 hops) + { + GQIRow[] data2retrieve; + List rows = new List(); + 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 @@ -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 @@ -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; } } diff --git a/MWCore-AdHoc-E2E-Streams_1/MWCore-AdHoc-E2E-Streams_1.csproj b/MWCore-AdHoc-E2E-Streams_1/MWCore-AdHoc-E2E-Streams_1.csproj index 1417d53..5cf7465 100644 --- a/MWCore-AdHoc-E2E-Streams_1/MWCore-AdHoc-E2E-Streams_1.csproj +++ b/MWCore-AdHoc-E2E-Streams_1/MWCore-AdHoc-E2E-Streams_1.csproj @@ -17,8 +17,7 @@ $(DefineConstants);DCFv1;DBInfo;ALARM_SQUASHING - - + diff --git a/MWCore-AdHoc-E2E-Streams_1/Misc/StreamsIO.cs b/MWCore-AdHoc-E2E-Streams_1/Misc/StreamsIO.cs index f699b20..814d86f 100644 --- a/MWCore-AdHoc-E2E-Streams_1/Misc/StreamsIO.cs +++ b/MWCore-AdHoc-E2E-Streams_1/Misc/StreamsIO.cs @@ -18,6 +18,7 @@ internal sealed class StreamsIO private static readonly object _padlock = new object(); private static Dictionary _instances = new Dictionary(); private readonly GQIDMS _dms; + private Dictionary> _hops; private StreamsIO(GQIDMS dms, string elementName) { @@ -49,6 +50,8 @@ private StreamsIO(GQIDMS dms, string elementName) } OutputsTable = outputsTable; + + _hops = new Dictionary>(); } public IEnumerable EdgesTable { get; } @@ -57,22 +60,44 @@ private StreamsIO(GQIDMS dms, string elementName) public IEnumerable 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(); + 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; + } + } } /// @@ -85,14 +110,23 @@ public static StreamsIO Instance(GQIDMS dms, string elementName) /// /// A list of objects, each representing a connection between inputs and outputs along with additional metadata. /// - public static HashSet GetHops(StreamsIO instance, string edgeName, string streamName) + public HashSet GetHops(string edgeName, string streamName) { - HashSet hops = new HashSet(); + HashSet hops; + string key = $"{edgeName}/{streamName}"; + if (_hops.TryGetValue(key, out hops)) + { + return hops; + } + else + { + hops = new HashSet(); + } - var inputs = new HashSet(instance.InputsTable.Where(input => + var inputs = new HashSet(InputsTable.Where(input => input.Stream == streamName && input.MWEdge == edgeName && !input.Protocol.Equals("2022-7"))); - var outputs = new HashSet(instance.OutputsTable.Where(output => + var outputs = new HashSet(OutputsTable.Where(output => output.Stream == streamName && output.MWEdge == edgeName && output.Port != "-1")); foreach (var input in inputs) @@ -104,10 +138,12 @@ public static HashSet 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; } diff --git a/MWCoreDownloadThumbnails_1/MWCoreDownloadThumbnails_1.csproj b/MWCoreDownloadThumbnails_1/MWCoreDownloadThumbnails_1.csproj index d81f452..9a3db53 100644 --- a/MWCoreDownloadThumbnails_1/MWCoreDownloadThumbnails_1.csproj +++ b/MWCoreDownloadThumbnails_1/MWCoreDownloadThumbnails_1.csproj @@ -17,8 +17,8 @@ $(DefineConstants);DCFv1;DBInfo;ALARM_SQUASHING - - + + diff --git a/MWCorePauseResume_1/MWCorePauseResume_1.cs b/MWCorePauseResume_1/MWCorePauseResume_1.cs index 3a71a7c..e81519a 100644 --- a/MWCorePauseResume_1/MWCorePauseResume_1.cs +++ b/MWCorePauseResume_1/MWCorePauseResume_1.cs @@ -51,6 +51,8 @@ DATE VERSION AUTHOR COMMENTS namespace MWCorePauseResume_1 { + using System.Collections.Generic; + using Newtonsoft.Json; using Skyline.DataMiner.Automation; /// @@ -64,53 +66,64 @@ public class Script /// Link with SLAutomation process. public void Run(IEngine engine) { - var elementName = engine.GetScriptParam("MWCore Element Name").Value.Replace("[\"", string.Empty).Replace("\"]", string.Empty); - var element = engine.FindElement(elementName); - - if (!element.IsActive) - { - engine.GenerateInformation("[Techex MWCore Pause/Resume] Techex MWCore element is not active."); - return; - } - - var iotype = engine.GetScriptParam("IO Type").Value.Replace("[\"", string.Empty).Replace("\"]", string.Empty); - - int paramId = -1; - if (iotype == "Source") + try { - paramId = 9721; + var elementName = engine.GetScriptParam("MWCore Element Name").Value.Replace("[\"", string.Empty).Replace("\"]", string.Empty); + var element = engine.FindElement(elementName); + + if (!element.IsActive) + { + engine.GenerateInformation("[Techex MWCore Pause/Resume] Techex MWCore element is not active."); + return; + } + + var iotype = engine.GetScriptParam("IO Type").Value.Replace("[\"", string.Empty).Replace("\"]", string.Empty); + + int paramId = -1; + if (iotype == "Source") + { + paramId = 9721; + } + else if (iotype == "Output") + { + paramId = 9003; + } + else + { + engine.GenerateInformation("[Techex MWCore Pause/Resume] Invalid IO Type (Source or Output)."); + } + + string statusToSet = string.Empty; + var status = engine.GetScriptParam("Status").Value.Replace("[\"", string.Empty).Replace("\"]", string.Empty); + if (status == "Pause") + { + statusToSet = "True"; + } + else if (status == "Resume") + { + statusToSet = "False"; + } + else + { + engine.GenerateInformation("[Techex MWCore Pause/Resume] Invalid Status (Pause or Resume)."); + } + + var jsonid = engine.GetScriptParam("IO ID").Value; + var iopk = JsonConvert.DeserializeObject>(jsonid)[0]; + + engine.GenerateInformation($"[Techex MWCore Pause/Resume] Set {iotype} to {statusToSet}={status} (PK: {iopk})."); + + engine.SetFlag(RunTimeFlags.NoCheckingSets); + element.SetParameterByPrimaryKey(paramId, iopk, statusToSet); // enable statistics + + engine.Sleep(3000); + element.SetParameter(200, 1); // refresh } - else if (iotype == "Output") + catch (System.Exception ex) { - paramId = 7003; + engine.Log($"Exception: {ex}"); + engine.ExitFail($"Error while updating port state."); } - else - { - engine.GenerateInformation("[Techex MWCore Pause/Resume] Invalid IO Type (Source or Output)."); - } - - string statusToSet = string.Empty; - var status = engine.GetScriptParam("Status").Value.Replace("[\"", string.Empty).Replace("\"]", string.Empty); - if (status == "Pause") - { - statusToSet = "True"; - } - else if (status == "Resume") - { - statusToSet = "False"; - } - else - { - engine.GenerateInformation("[Techex MWCore Pause/Resume] Invalid Status (Pause or Resume)."); - } - - var iopk = engine.GetScriptParam("IO ID").Value.Replace("[\"", string.Empty).Replace("\"]", string.Empty); - - engine.GenerateInformation($"[Techex MWCore Pause/Resume] Set {iotype} to {statusToSet}={status}."); - element.SetParameterByPrimaryKey(paramId, iopk, statusToSet); // enable statistics - - engine.Sleep(5000); - element.SetParameter(200, 1); //refresh } } } \ No newline at end of file diff --git a/MWCorePauseResume_1/MWCorePauseResume_1.csproj b/MWCorePauseResume_1/MWCorePauseResume_1.csproj index def0bfc..81a9442 100644 --- a/MWCorePauseResume_1/MWCorePauseResume_1.csproj +++ b/MWCorePauseResume_1/MWCorePauseResume_1.csproj @@ -17,7 +17,8 @@ $(DefineConstants);DCFv1;DBInfo;ALARM_SQUASHING - + + diff --git a/MWCoreProcessStreamAlarms_1/MWCoreProcessStreamAlarms_1.csproj b/MWCoreProcessStreamAlarms_1/MWCoreProcessStreamAlarms_1.csproj index 47a6100..778f6dd 100644 --- a/MWCoreProcessStreamAlarms_1/MWCoreProcessStreamAlarms_1.csproj +++ b/MWCoreProcessStreamAlarms_1/MWCoreProcessStreamAlarms_1.csproj @@ -17,8 +17,8 @@ $(DefineConstants);DCFv1;DBInfo;ALARM_SQUASHING - - + + diff --git a/MWCoreStatisticsEnable_1/MWCoreStatisticsEnable_1.csproj b/MWCoreStatisticsEnable_1/MWCoreStatisticsEnable_1.csproj index 402d885..3b698a5 100644 --- a/MWCoreStatisticsEnable_1/MWCoreStatisticsEnable_1.csproj +++ b/MWCoreStatisticsEnable_1/MWCoreStatisticsEnable_1.csproj @@ -17,7 +17,7 @@ $(DefineConstants);DCFv1;DBInfo;ALARM_SQUASHING - + diff --git a/TECHX-AS-TXCore_1/TECHX-AS-TXCore_1.csproj b/TECHX-AS-TXCore_1/TECHX-AS-TXCore_1.csproj index b4be813..fcd6602 100644 --- a/TECHX-AS-TXCore_1/TECHX-AS-TXCore_1.csproj +++ b/TECHX-AS-TXCore_1/TECHX-AS-TXCore_1.csproj @@ -17,7 +17,7 @@ $(DefineConstants);DCFv1;DBInfo;ALARM_SQUASHING - +