diff --git a/Execution_UI/Execution_UI.Tests/IntegrationTests/ApplicationTests.cs b/Execution_UI/Execution_UI.Tests/IntegrationTests/ApplicationTests.cs index 92a51eb6..ad765fbb 100644 --- a/Execution_UI/Execution_UI.Tests/IntegrationTests/ApplicationTests.cs +++ b/Execution_UI/Execution_UI.Tests/IntegrationTests/ApplicationTests.cs @@ -47,7 +47,7 @@ public async Task Get_CastPage_ReturnsSuccessStatusCode() var client = _factory.CreateClient(); // Act - var response = await client.GetAsync("/cast"); + var response = await client.GetAsync("/cast_new"); // Assert // Note: May return 500 if RabbitMQ/MySQL are not configured, diff --git a/Execution_UI/Execution_UI/Pages/cast_new.cshtml b/Execution_UI/Execution_UI/Pages/cast_new.cshtml new file mode 100644 index 00000000..dad0121f --- /dev/null +++ b/Execution_UI/Execution_UI/Pages/cast_new.cshtml @@ -0,0 +1,763 @@ +@page +@model Cast_NewModel +@{ + ViewData["Title"] = "Execution Controller"; +} + + + + + + + + @ViewData["Title"] - CAST + + + + + + + + +
+
+ + +
+

CAST

+

Centralized Automation of Software Tools

+
+
+ +
+ + +
+
+ +
+

Service Health Check

+
+ + + + @for (int countMYSQLRecords = 0; countMYSQLRecords < Model.serviceName.Count; + countMYSQLRecords++) + { + + } + + + @for (int countMYSQLRecords = 0; countMYSQLRecords < Model.serviceName.Count; + countMYSQLRecords++) + { + @if (@Model.serviceState[countMYSQLRecords].ToUpper().Equals("ONLINE")) + { + + } + else if (@Model.serviceState[countMYSQLRecords].ToUpper().Equals("OFFLINE")) + { + + } + else if (@Model.serviceState[countMYSQLRecords].ToUpper().Equals("UNDER CONSTRUCTION")) + { + + } + else + { + + } + } + + +
@Model.serviceName[countMYSQLRecords]
@Model.serviceState[countMYSQLRecords]@Model.serviceState[countMYSQLRecords]@Model.serviceState[countMYSQLRecords]@Model.serviceState[countMYSQLRecords]
+
+ +

Client Frameworks

+
+

Filters

+
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+
+
+ + +
+ + + + + + + + + + + + + + + + + + @for (int countMYSQLRecords = 0; countMYSQLRecords < Model.displayNames.Count; + countMYSQLRecords++) + { + @if (!Model.currentState[countMYSQLRecords].ToUpper().StartsWith("OFFLINE")) + { + + + + + @if (Model.startRun[countMYSQLRecords] == "no") + { + + } + else + { + + } + @if (Model.stopRun[countMYSQLRecords] == "no") + { + + } + else + { + + } + @if (Model.pauseRun[countMYSQLRecords] == "no") + { + + } + else + { + + } + @if (Model.resumeRun[countMYSQLRecords] == "no") + { + + } + else + { + + } + @if (Model.abortRun[countMYSQLRecords] == "no") + { + + } + else + { + + } + @if (Model.restartRun[countMYSQLRecords] == "no") + { + + } + else + { + + } + + @if (Model.currentState[countMYSQLRecords].ToUpper().StartsWith("READY")) + { + + } + else + { + + } + + } + } + +
CleanupClient NameStateStartStopPauseResumeAbortRestartCustomSchedule
+ + @Model.displayNames[countMYSQLRecords] + @Model.currentState[countMYSQLRecords] + + + + + + + + + + + + + + + + + + + + + + + + + @for (int countCustomActions = 0; countCustomActions < @Model.customActionName.Count; + countCustomActions++) + { + @if + (@Model.customActionName[countCustomActions].StartsWith(@Model.originatorUUIDs[countMYSQLRecords]) + && (@Model.currentState[countMYSQLRecords].ToUpper().StartsWith("READY")) && + !@Model.customActionHideBeforeStart[countCustomActions]) + { + + } + else if + (@Model.customActionName[countCustomActions].StartsWith(@Model.originatorUUIDs[countMYSQLRecords]) + && !(@Model.currentState[countMYSQLRecords].ToUpper().StartsWith("READY")) && + !(@Model.currentState[countMYSQLRecords].ToUpper().StartsWith("COMPLETED")) + && !@Model.customActionHideAfterStart[countCustomActions]) + { + + } + else if + (@Model.customActionName[countCustomActions].StartsWith(@Model.originatorUUIDs[countMYSQLRecords]) + && (@Model.currentState[countMYSQLRecords].ToUpper().StartsWith("COMPLETED")) + && !@Model.customActionHideAfterComplete[countCustomActions]) + { + + } + else + { + + } + } + + + + +
+ +
+
+ + +
+ + + + + + \ No newline at end of file diff --git a/Execution_UI/Execution_UI/Pages/cast_new.cshtml.cs b/Execution_UI/Execution_UI/Pages/cast_new.cshtml.cs new file mode 100644 index 00000000..f1217eae --- /dev/null +++ b/Execution_UI/Execution_UI/Pages/cast_new.cshtml.cs @@ -0,0 +1,968 @@ +using System.Text; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.Extensions.Options; +using MySql.Data.MySqlClient; +using RabbitMQ.Client; +using Microsoft.Extensions.Configuration; +using Microsoft.AspNetCore.Connections; +using Mysqlx.Crud; +using System.Threading.Channels; +using System.Globalization; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.IO; +using System.Threading; +using System.Threading.Tasks; + +namespace Execution_UI.Pages; + +public class Cast_NewModel : PageModel +{ + private readonly ILogger _logger; + public Cast_NewModel(ILogger logger) + { + _logger = logger; + } + + public SelectList? Options { get; set; } + + [BindProperty] + public string? SelectedValue { get; set; } + + public string rootDir = @Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + ".." + Path.DirectorySeparatorChar + ".." + Path.DirectorySeparatorChar; + + /// + /// The RabbitMQ Server pulled from appsettings.json + /// + public static string? rabbitmq_home = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build().GetSection("AppSettings")["rabbitmq_home"]; + /// + /// The RabbitMQ Port pulled from appsettings.json + /// + public static string? rabbitmq_port = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build().GetSection("AppSettings")["rabbitmq_port"]; + /// + /// The RabbitMQ UI Account pulled from appsettings.json + /// + public string? rabbitmq_user = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build().GetSection("AppSettings")["rabbitmq_user"]; + /// + /// The RabbitMQ UI password pulled from appsettings.json + /// + public string? rabbitmq_pwd = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build().GetSection("AppSettings")["rabbitmq_pwd"]; + + /// + /// The MySQL Server pulled from appsettings.json + /// Note that database access here is only for SELECT statements to populate the UI + /// + public static string? mysql_Server = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build().GetSection("AppSettings")["mysql_Server"]; + /// + /// The MySQL Port pulled from appsettings.json + /// + public static string? mysql_Port = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build().GetSection("AppSettings")["mysql_Port"]; + /// + /// The MySQL Port pulled from appsettings.json + /// + public static string? mysql_Database = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build().GetSection("AppSettings")["mysql_Database"]; + /// + /// The MySQL Account pulled from appsettings.json + /// + public static string? mysql_User = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build().GetSection("AppSettings")["mysql_User"]; + /// + /// The MySQL password pulled from appsettings.json + /// + public static string? mysql_Password = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build().GetSection("AppSettings")["mysql_Password"]; + public static string connectString = "Server=" + mysql_Server + "; Database=" + mysql_Database + "; Uid=" + mysql_User + "; Pwd=" + mysql_Password + "; Port=" + mysql_Port; + + public List originatorUUIDs = new List(); + /// + /// The list of Client display names + /// + public List displayNames = new List(); + /// + /// The StartRun Action for each Client + /// + public List startRun = new List(); + /// + /// The StopRun Action for each Client + /// + public List stopRun = new List(); + /// + /// The PauseRun Action for each Client + /// + public List pauseRun = new List(); + /// + /// The ResumeRun Action for each Client + /// + public List resumeRun = new List(); + /// + /// The AbortRun Action for each Client + /// + public List abortRun = new List(); + /// + /// The RestartRun Action for each Client + /// + public List restartRun = new List(); + /// + /// The current state text for each Client (to display in the UI) + /// + public List currentState = new List(); + /// + /// The current state color for each Client (to colorize the state text in the UI) + /// + public List currentStateColor = new List(); + /// + /// The current Group filter + /// + public static string currentGroup = "All"; + /// + /// The current Owner filter + /// + public static string currentOwner = "All"; + /// + /// The current Location filter + /// + public static string currentLocation = "All"; + /// + /// The current Keyword filter + /// + public static string currentKeyword = "All"; + /// + /// The current Service State list + /// + public List serviceState = new List(); + /// + /// The current Service Name list + /// + public List serviceName = new List(); + /// + /// All custom action names + /// + public List customActionName = new List(); + /// + /// All custom action descriptions + /// + public List customActionDescription = new List(); + /// + /// All custom action icons + /// + public List customActionIcon = new List(); + /// + /// All custom action full names + /// + public List customActionFullName = new List(); + /// + /// Define when each custom action is displayed + /// + public List customActionHideBeforeStart = new List(); + /// + /// Define when each custom action is displayed + /// + public List customActionHideAfterStart = new List(); + /// + /// Define when each custom action is displayed + /// + public List customActionHideAfterComplete = new List(); + /// + /// The current list of all filters + /// + public List filterFrameworks = new List(); + /// + /// The current list of all Group filters + /// + public List filterFrameworksOnGroup = new List(); + /// + /// The current list of all Owner filters + /// + public List filterFrameworksOnOwner = new List(); + /// + /// The current list of all Location filters + /// + public List filterFrameworksOnLocation = new List(); + /// + /// The current list of all Keyword filters + /// + public List filterFrameworksOnKeyword = new List(); + /// + /// The current list of all scheduled runs + /// + public static List scheduleList = new List(); + + static string select_framework_info = "select reference_uuid, display_name from logger where message like 'Started Client Service%' and display_name NOT LIKE 'SETUP New Framework - IGNORE THIS ENTRY' and filter_on_group like '%' and filter_on_owner like '%' and filter_on_location like '%' and filter_on_keyword like '%' and virtual_delete = 0 order by order_in_system DESC"; + string pre_select_framework_info = "select reference_uuid, display_name from logger where message like 'Started Client Service%' and display_name NOT LIKE 'SETUP New Framework - IGNORE THIS ENTRY'"; + static string group_select_framework_info = " and filter_on_group like '%'"; + static string owner_select_framework_info = " and filter_on_owner like '%'"; + static string location_select_framework_info = " and filter_on_location like '%'"; + //filter_on_keyword format is |keyword1|keyword2|...|keyword#| + static string keyword_select_framework_info = " and filter_on_keyword like '%'"; + string post_select_framework_info = " and virtual_delete = 0 order by order_in_system DESC"; + bool updateSelectStatement = false; + + + /// + /// The RabbitMQ Connection Factory + /// + ConnectionFactory factory = new ConnectionFactory(); + + /// + /// Used to handle Schedule requests, filter requests and populate the variables for the UI + /// + /// IActionResult + public IActionResult? OnGet(string? param2) + { + if (param2 != null) + { + if (param2.StartsWith("schedule_") && !scheduleList.Contains(param2.Substring(9))) + { + string newParam2 = param2.Substring(9); + scheduleList.Add(newParam2); + Console.WriteLine(newParam2); + string referenceUUID = newParam2.Substring(0, newParam2.IndexOf(" ")); + string scheduledTime = newParam2.Substring(newParam2.IndexOf(" for ") + 5); + string format = "yyyy-MM-dd HH:mm:ss"; + scheduledTime = DateTime.ParseExact(scheduledTime, format, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal).ToString(format); + + Guid startmyuuid = Guid.NewGuid(); + string startmyuuidAsString = startmyuuid.ToString(); + string insertSchedule = "insert into state(uuid, reference_uuid, state, event_time_dt, scheduled_time) values('" + startmyuuidAsString + "', '" + referenceUUID + "', 'SCHEDULED for " + scheduledTime + "', NOW(), '" + scheduledTime + "')"; + submitSchedule(insertSchedule); + updateSelectStatement = false; + return RedirectToPage("./cast_new"); + } + else + { + if (param2.StartsWith("group_")) + { + updateSelectStatement = true; + string newParam2 = param2.Substring(6); + Console.WriteLine("Filter for group '" + newParam2 + "'"); + currentGroup = newParam2; + if (newParam2.Equals("All")) + { + group_select_framework_info = " and filter_on_group like '%'"; + } + else + { + group_select_framework_info = " and filter_on_group = '" + newParam2 + "'"; + } + } + else if (param2.StartsWith("owner_")) + { + updateSelectStatement = true; + string newParam2 = param2.Substring(6); + Console.WriteLine("Filter for owner '" + newParam2 + "'"); + currentOwner = newParam2; + if (newParam2.Equals("All")) + { + owner_select_framework_info = " and filter_on_owner like '%'"; + } + else + { + owner_select_framework_info = " and filter_on_owner = '" + newParam2 + "'"; + } + } + else if (param2.StartsWith("location_")) + { + updateSelectStatement = true; + string newParam2 = param2.Substring(9); + Console.WriteLine("Filter for location '" + newParam2 + "'"); + currentLocation = newParam2; + if (newParam2.Equals("All")) + { + location_select_framework_info = " and filter_on_location like '%'"; + } + else + { + location_select_framework_info = " and filter_on_location = '" + newParam2 + "'"; + } + } + else if (param2.StartsWith("keyword_")) + { + updateSelectStatement = true; + string newParam2 = param2.Substring(8); + Console.WriteLine("Filter for keyword '" + newParam2 + "'"); + currentKeyword = newParam2; + if (newParam2.Equals("All")) + { + keyword_select_framework_info = " and filter_on_keyword like '%'"; + } + else + { + keyword_select_framework_info = " and filter_on_keyword like '%|" + newParam2 + "|%'"; + } + } + select_framework_info = pre_select_framework_info + group_select_framework_info + owner_select_framework_info + location_select_framework_info + keyword_select_framework_info + post_select_framework_info; + return RedirectToPage("./cast_new"); + } + } + else + { + var mysqlDictionary = new Dictionary { }; + using (MySqlConnection conn = new MySqlConnection(connectString)) + { + conn.Open(); + + using (MySqlCommand command = new MySqlCommand(select_framework_info, conn)) + { + MySqlDataReader rdr = command.ExecuteReader(); + + while (rdr.Read()) + { + mysqlDictionary.Add((string)rdr[0], (string)rdr[1]); + } + rdr.Close(); + } + + string selectCastState = "select state, name from cast_state_tracker"; + serviceState.Clear(); + serviceName.Clear(); + using (MySqlCommand command = new MySqlCommand(selectCastState, conn)) + { + MySqlDataReader rdr = command.ExecuteReader(); + + while (rdr.Read()) + { + serviceState.Add((string)rdr[0]); + serviceName.Add((string)rdr[1]); + } + rdr.Close(); + } + string selectFrameworkNames = "select distinct(filter_on_group) from logger"; + filterFrameworksOnGroup.Clear(); + filterFrameworksOnGroup.Add("All"); + using (MySqlCommand command = new MySqlCommand(selectFrameworkNames, conn)) + { + MySqlDataReader rdr = command.ExecuteReader(); + + while (rdr.Read()) + { + if (rdr[0] != DBNull.Value) + { + filterFrameworksOnGroup.Add((string)rdr[0]); + } + } + rdr.Close(); + } + filterFrameworksOnGroup.RemoveAll(item => item == null); + filterFrameworksOnGroup.RemoveAll(item => item == ""); + + selectFrameworkNames = "select distinct(filter_on_owner) from logger"; + filterFrameworksOnOwner.Clear(); + filterFrameworksOnOwner.Add("All"); + using (MySqlCommand command = new MySqlCommand(selectFrameworkNames, conn)) + { + MySqlDataReader rdr = command.ExecuteReader(); + + while (rdr.Read()) + { + if (rdr[0] != DBNull.Value) + { + filterFrameworksOnOwner.Add((string)rdr[0]); + } + } + rdr.Close(); + } + filterFrameworksOnOwner.RemoveAll(item => item == null); + filterFrameworksOnOwner.RemoveAll(item => item == ""); + + selectFrameworkNames = "select distinct(filter_on_location) from logger"; + filterFrameworksOnLocation.Clear(); + filterFrameworksOnLocation.Add("All"); + using (MySqlCommand command = new MySqlCommand(selectFrameworkNames, conn)) + { + MySqlDataReader rdr = command.ExecuteReader(); + + while (rdr.Read()) + { + if (rdr[0] != DBNull.Value) + { + filterFrameworksOnLocation.Add((string)rdr[0]); + } + } + rdr.Close(); + } + filterFrameworksOnLocation.RemoveAll(item => item == null); + filterFrameworksOnLocation.RemoveAll(item => item == ""); + + //Reset sql statement when keyword table or row is available + selectFrameworkNames = "select distinct(filter_on_keyword) from logger"; + filterFrameworksOnKeyword.Clear(); + filterFrameworksOnKeyword.Add("All"); + using (MySqlCommand command = new MySqlCommand(selectFrameworkNames, conn)) + { + MySqlDataReader rdr = command.ExecuteReader(); + + while (rdr.Read()) + { + if (rdr[0] != DBNull.Value) + { + string allKeywords = (string)rdr[0]; + string[] arrayOfKeywords = allKeywords.Split('|'); + foreach (string currentKeyword in arrayOfKeywords) + { + filterFrameworksOnKeyword.Add(currentKeyword); + } + } + } + rdr.Close(); + } + filterFrameworksOnKeyword.RemoveAll(item => item == null); + filterFrameworksOnKeyword.RemoveAll(item => item == ""); + + + + + + string selectReferenceUUID = "select distinct(reference_uuid) from custom_actions"; + string selectCustomActions = "select name, description, icon from custom_actions"; + customActionName.Clear(); + customActionDescription.Clear(); + customActionIcon.Clear(); + customActionFullName.Clear(); + customActionHideBeforeStart.Clear(); + customActionHideAfterStart.Clear(); + customActionHideAfterComplete.Clear(); + + using (MySqlCommand command = new MySqlCommand(selectReferenceUUID, conn)) + { + MySqlDataReader rdr = command.ExecuteReader(); + + while (rdr.Read()) + { + if (rdr[0] != DBNull.Value) + { + customActionFullName.Add((string)rdr[0]); + } + } + rdr.Close(); + } + customActionFullName.RemoveAll(item => item == null); + customActionFullName.RemoveAll(item => item == ""); + foreach (string currentFullName in customActionFullName) + { + selectCustomActions = "select name, description, icon, hide_before_start, hide_after_start, hide_after_complete from custom_actions where reference_uuid = '" + currentFullName + "'"; + using (MySqlCommand command = new MySqlCommand(selectCustomActions, conn)) + { + MySqlDataReader rdr = command.ExecuteReader(); + + while (rdr.Read()) + { + if (rdr[0] != DBNull.Value) + { + customActionName.Add((string)rdr[0]); + customActionDescription.Add((string)rdr[1]); + customActionIcon.Add((string)rdr[2]); + customActionHideBeforeStart.Add((bool)rdr[3]); + customActionHideAfterStart.Add((bool)rdr[4]); + customActionHideAfterComplete.Add((bool)rdr[5]); + } + } + rdr.Close(); + } + } + customActionName.RemoveAll(item => item == null); + customActionName.RemoveAll(item => item == ""); + customActionDescription.RemoveAll(item => item == null); + customActionDescription.RemoveAll(item => item == ""); + customActionIcon.RemoveAll(item => item == null); + customActionIcon.RemoveAll(item => item == ""); + //customActionHideBeforeStart.RemoveAll(item => item == null); + //customActionHideAfterStart.RemoveAll(item => item == null); + //customActionHideAfterComplete.RemoveAll(item => item == null); + + + + + + + foreach (string originatorUUID in mysqlDictionary.Keys) + { + originatorUUIDs.Add(originatorUUID); + } + foreach (string displayName in mysqlDictionary.Values) + { + displayNames.Add(displayName); + } + foreach (string originator in mysqlDictionary.Keys) + { + string currentStateStr = ""; + string currentStateColorStr = "black"; + string startRunStr = "no"; + string stopRunStr = "no"; + string pauseRunStr = "no"; + string resumeRunStr = "no"; + string abortRunStr = "no"; + string restartRunStr = "no"; + bool startRunEnabled = false; + bool stopRunEnabled = false; + bool pauseRunEnabled = false; + bool resumeRunEnabled = false; + bool abortRunEnabled = false; + bool restartRunEnabled = false; + + string selectState = "select state, color from state where reference_uuid = '" + originator + "' and order_in_system = (select MAX(order_in_system) from state where reference_uuid = '" + originator + "' and virtual_delete = 0)"; + using (MySqlCommand command = new MySqlCommand(selectState, conn)) + { + MySqlDataReader rdr = command.ExecuteReader(); + + while (rdr.Read()) + { + currentStateStr = (string)rdr[0]; + currentStateColorStr = (string)rdr[1]; + } + rdr.Close(); + } + string selectFrameworkFunctionality = "select start_supported, stop_supported, pause_supported, resume_supported, abort_supported, restart_supported from client_functionality where reference_uuid = '" + originator + "'"; + using (MySqlCommand command = new MySqlCommand(selectFrameworkFunctionality, conn)) + { + MySqlDataReader rdr = command.ExecuteReader(); + + while (rdr.Read()) + { + startRunEnabled = (bool)rdr[0]; + stopRunEnabled = (bool)rdr[1]; + pauseRunEnabled = (bool)rdr[2]; + resumeRunEnabled = (bool)rdr[3]; + abortRunEnabled = (bool)rdr[4]; + restartRunEnabled = (bool)rdr[5]; + } + rdr.Close(); + } + + if (currentStateStr.ToUpper().StartsWith("RUNNING")) + { + startRunStr = "no"; + if (stopRunEnabled) + { + stopRunStr = "yes"; + } + if (pauseRunEnabled) + { + pauseRunStr = "yes"; + } + resumeRunStr = "no"; + if (abortRunEnabled) + { + abortRunStr = "yes"; + } + restartRunStr = "no"; + } + else if (currentStateStr.ToUpper().Equals("PAUSED")) + { + startRunStr = "no"; + if (stopRunEnabled) + { + stopRunStr = "yes"; + } + pauseRunStr = "no"; + if (resumeRunEnabled) + { + resumeRunStr = "yes"; + } + if (abortRunEnabled) + { + abortRunStr = "yes"; + } + restartRunStr = "no"; + } + else if (currentStateStr.ToUpper().Equals("RESUMED")) + { + startRunStr = "no"; + if (stopRunEnabled) + { + stopRunStr = "yes"; + } + if (pauseRunEnabled) + { + pauseRunStr = "yes"; + } + resumeRunStr = "no"; + if (abortRunEnabled) + { + abortRunStr = "yes"; + } + restartRunStr = "no"; + } + else if (currentStateStr.ToUpper().Equals("ABORTED")) + { + if (startRunEnabled) + { + startRunStr = "yes"; + } + if (stopRunEnabled) + { + stopRunStr = "yes"; + } + pauseRunStr = "no"; + resumeRunStr = "no"; + abortRunStr = "no"; + if (restartRunEnabled) + { + restartRunStr = "yes"; + } + } + else if (currentStateStr.ToUpper().Equals("RESTARTED")) + { + startRunStr = "no"; + if (stopRunEnabled) + { + stopRunStr = "yes"; + } + if (pauseRunEnabled) + { + pauseRunStr = "yes"; + } + resumeRunStr = "no"; + if (abortRunEnabled) + { + abortRunStr = "yes"; + } + restartRunStr = "no"; + } + else if (currentStateStr.ToUpper().Equals("STOPPED")) + { + if (startRunEnabled) + { + startRunStr = "yes"; + } + stopRunStr = "no"; + pauseRunStr = "no"; + resumeRunStr = "no"; + abortRunStr = "no"; + restartRunStr = "no"; + } + else if (currentStateStr.ToUpper().StartsWith("READY")) + { + if (startRunEnabled) + { + startRunStr = "yes"; + } + stopRunStr = "no"; + pauseRunStr = "no"; + resumeRunStr = "no"; + abortRunStr = "no"; + restartRunStr = "no"; + } + else if (currentStateStr.ToUpper().Equals("SCHEDULED")) + { + if (startRunEnabled) + { + startRunStr = "no"; + } + stopRunStr = "no"; + pauseRunStr = "no"; + resumeRunStr = "no"; + abortRunStr = "no"; + restartRunStr = "no"; + } + else if (currentStateStr.ToUpper().Equals("SHUTDOWN") || currentStateStr.ToUpper().StartsWith("OFFLINE")) + { + if (startRunEnabled) + { + startRunStr = "no"; + } + stopRunStr = "no"; + pauseRunStr = "no"; + resumeRunStr = "no"; + abortRunStr = "no"; + restartRunStr = "no"; + } + else if (currentStateStr.ToUpper().Equals("CLEANUP")) + { + if (startRunEnabled) + { + startRunStr = "no"; + } + stopRunStr = "no"; + pauseRunStr = "no"; + resumeRunStr = "no"; + abortRunStr = "no"; + restartRunStr = "no"; + } + else if (currentStateStr.ToUpper().StartsWith("COMPLETED ") || (currentStateStr.ToUpper().EndsWith(" WAS STOPPED")) || (currentStateStr.ToUpper().EndsWith(" WAS ABORTED"))) + { + if (restartRunEnabled) + { + startRunStr = "yes"; + } + else + { + startRunStr = "no"; + } + if (stopRunEnabled) + { + stopRunStr = "no"; + } + pauseRunStr = "no"; + if (resumeRunEnabled) + { + resumeRunStr = "no"; + } + if (abortRunEnabled) + { + abortRunStr = "no"; + } + restartRunStr = "no"; + } + currentState.Add(currentStateStr); + currentStateColor.Add(currentStateColorStr); + startRun.Add(startRunStr); + stopRun.Add(stopRunStr); + pauseRun.Add(pauseRunStr); + resumeRun.Add(resumeRunStr); + abortRun.Add(abortRunStr); + restartRun.Add(restartRunStr); + + } + } + } + return null!; + } + + /// + /// Deprecated. Was used to simulate test runs + /// + /// IActionResult + public async Task OnPostMyAction() + { + factory.HostName = rabbitmq_home ?? ""; + factory.Port = int.Parse(rabbitmq_port ?? "5672"); + factory.UserName = rabbitmq_user ?? ""; + factory.Password = rabbitmq_pwd ?? ""; + using var connection = await factory.CreateConnectionAsync(); + using var channel = await connection.CreateChannelAsync(); + + string clientUUID = SelectedValue ?? ""; + Console.WriteLine("clientUUID = " + clientUUID); + + //Create sample_test_script.txt in File_Storage_Service/temp/outbound_queue/UUID + string localDirectoryReference = rootDir + "File_Storage_Service" + Path.DirectorySeparatorChar + "temp" + Path.DirectorySeparatorChar + "outbound_queue" + Path.DirectorySeparatorChar + clientUUID + Path.DirectorySeparatorChar; + string localWorkingDirectoryReference = rootDir + "File_Storage_Service" + Path.DirectorySeparatorChar + "temp" + Path.DirectorySeparatorChar + "working_queue" + Path.DirectorySeparatorChar + clientUUID + Path.DirectorySeparatorChar; + string fileName = "sample_test_script.txt"; + Directory.CreateDirectory(localDirectoryReference); + Directory.CreateDirectory(localWorkingDirectoryReference); + System.IO.File.WriteAllText(localWorkingDirectoryReference + fileName, "This is a sample test script"); + //Zip file to represent script package + System.IO.Compression.ZipFile.CreateFromDirectory(localWorkingDirectoryReference, localDirectoryReference + "sample_test_script.zip"); + System.IO.File.Delete(localWorkingDirectoryReference + fileName); + Directory.Delete(localWorkingDirectoryReference); + + string firstMessage = "message for " + clientUUID + ": local: action: simulate test run with test script"; + string lastMessage = "message for " + clientUUID + ": local: action: simulate test run"; + + var body = Encoding.UTF8.GetBytes(firstMessage); + await channel.BasicPublishAsync(exchange: string.Empty, routingKey: "execution_service", body: body); + Thread.Sleep(5000); + + body = Encoding.UTF8.GetBytes(lastMessage); + await channel.BasicPublishAsync(exchange: string.Empty, routingKey: "execution_service", body: body); + + return RedirectToPage("./cast_new"); + } + + /// + /// Process Start Run Action and submit message to the Execution Service via RabbitMQ + /// + /// IActionResult + public async Task OnPostMyAction2(string id) + { + string originatorUUID = id; + Console.WriteLine("StartRun for clientUUID = " + originatorUUID); + factory.UserName = rabbitmq_user ?? ""; + factory.Password = rabbitmq_pwd ?? ""; + using var connection = await factory.CreateConnectionAsync(); + using var channel = await connection.CreateChannelAsync(); + + string clientUUID = originatorUUID; + string message = "message for client_service_" + clientUUID + ": local: action: start run"; + + var body = Encoding.UTF8.GetBytes(message); + await channel.BasicPublishAsync(exchange: string.Empty, routingKey: "execution_service", body: body); + + return RedirectToPage("./cast_new"); + } + + /// + /// Process Stop Run Action and submit message to the Execution Service via RabbitMQ + /// + /// IActionResult + public async Task OnPostMyAction3(string id) + { + string originatorUUID = id; + factory.UserName = rabbitmq_user ?? ""; + factory.Password = rabbitmq_pwd ?? ""; + using var connection = await factory.CreateConnectionAsync(); + using var channel = await connection.CreateChannelAsync(); + string clientUUID = originatorUUID; + Console.WriteLine("StopRun for clientUUID = " + clientUUID); + string message = "message for client_service_" + clientUUID + ": local: action: stop run"; + var body = Encoding.UTF8.GetBytes(message); + await channel.BasicPublishAsync(exchange: string.Empty, routingKey: "execution_service", body: body); + return RedirectToPage("./cast_new"); + } + + /// + /// Process Pause Run Action and submit message to the Execution Service via RabbitMQ + /// + /// IActionResult + public async Task OnPostMyAction4(string id) + { + string originatorUUID = id; + factory.UserName = rabbitmq_user ?? ""; + factory.Password = rabbitmq_pwd ?? ""; + using var connection = await factory.CreateConnectionAsync(); + using var channel = await connection.CreateChannelAsync(); + string clientUUID = originatorUUID; + Console.WriteLine("PauseRun for clientUUID = " + clientUUID); + string message = "message for client_service_" + clientUUID + ": local: action: pause run"; + var body = Encoding.UTF8.GetBytes(message); + await channel.BasicPublishAsync(exchange: string.Empty, routingKey: "execution_service", body: body); + return RedirectToPage("./cast_new"); + } + + /// + /// Process Resume Run Action and submit message to the Execution Service via RabbitMQ + /// + /// IActionResult + public async Task OnPostMyAction5(string id) + { + string originatorUUID = id; + factory.UserName = rabbitmq_user ?? ""; + factory.Password = rabbitmq_pwd ?? ""; + using var connection = await factory.CreateConnectionAsync(); + using var channel = await connection.CreateChannelAsync(); + string clientUUID = originatorUUID; + Console.WriteLine("ResumeRun for clientUUID = " + clientUUID); + string message = "message for client_service_" + clientUUID + ": local: action: resume run"; + var body = Encoding.UTF8.GetBytes(message); + await channel.BasicPublishAsync(exchange: string.Empty, routingKey: "execution_service", body: body); + return RedirectToPage("./cast_new"); + } + + /// + /// Process Abort Run Action and submit message to the Execution Service via RabbitMQ + /// + /// IActionResult + public async Task OnPostMyAction6(string id) + { + string originatorUUID = id; + factory.UserName = rabbitmq_user ?? ""; + factory.Password = rabbitmq_pwd ?? ""; + using var connection = await factory.CreateConnectionAsync(); + using var channel = await connection.CreateChannelAsync(); + string clientUUID = originatorUUID; + Console.WriteLine("AbortRun for clientUUID = " + clientUUID); + string message = "message for client_service_" + clientUUID + ": local: action: abort run"; + var body = Encoding.UTF8.GetBytes(message); + await channel.BasicPublishAsync(exchange: string.Empty, routingKey: "execution_service", body: body); + return RedirectToPage("./cast_new"); + } + + /// + /// Process Restart Run Action and submit message to the Execution Service via RabbitMQ + /// + /// IActionResult + public async Task OnPostMyAction7(string id) + { + string originatorUUID = id; + factory.UserName = rabbitmq_user ?? ""; + factory.Password = rabbitmq_pwd ?? ""; + using var connection = await factory.CreateConnectionAsync(); + using var channel = await connection.CreateChannelAsync(); + string clientUUID = originatorUUID; + Console.WriteLine("RestartRun for clientUUID = " + clientUUID); + string message = "message for client_service_" + clientUUID + ": local: action: restart run"; + var body = Encoding.UTF8.GetBytes(message); + await channel.BasicPublishAsync(exchange: string.Empty, routingKey: "execution_service", body: body); + return RedirectToPage("./cast_new"); + } + + /// + /// Debug command + /// + /// IActionResult + public async Task OnPostMyAction8([FromBody] string model) + { + Console.WriteLine(model); + + return RedirectToPage("./cast_new"); + } + + /// + /// Process Custom Action and submit message to the Execution Service via RabbitMQ + /// + /// IActionResult + public async Task OnPostMyAction9(string id) + { + Console.WriteLine("Action is " + id); + string originatorUUID = id.Substring(0, id.IndexOf("|")); + string action = id.Substring(id.IndexOf("|") + 1); + factory.UserName = rabbitmq_user ?? ""; + factory.Password = rabbitmq_pwd ?? ""; + using var connection = await factory.CreateConnectionAsync(); + using var channel = await connection.CreateChannelAsync(); + string clientUUID = originatorUUID; + Console.WriteLine("CustomAction for " + originatorUUID + " = " + action); + string message = "message for client_service_" + clientUUID + ": local: action: custom action " + action; + var body = Encoding.UTF8.GetBytes(message); + await channel.BasicPublishAsync(exchange: string.Empty, routingKey: "execution_service", body: body); + return RedirectToPage("./cast"); + } + + /// + /// Process Cleanup Action and submit message to the Execution Service via RabbitMQ + /// + /// IActionResult + public async Task OnPostMyAction10(string id) + { + string originatorUUID = id; + Console.WriteLine("Cleanup clientUUID = " + originatorUUID); + factory.UserName = rabbitmq_user ?? ""; + factory.Password = rabbitmq_pwd ?? ""; + using var connection = await factory.CreateConnectionAsync(); + using var channel = await connection.CreateChannelAsync(); + + string clientUUID = originatorUUID; + + Guid startmyuuid = Guid.NewGuid(); + string startmyuuidAsString = startmyuuid.ToString(); + string updateState = "insert into state(uuid, reference_uuid, state, event_time_dt) values('" + startmyuuidAsString + "', '" + id + "', 'OFFLINE', NOW())"; + cleanupClient(updateState); + updateSelectStatement = false; + return RedirectToPage("./cast"); + } + + /// + /// Submit a Schedule Request to the logger Service via RabbitMQ + /// + /// IActionResult + public async void submitSchedule(string insertSchedule) + { + var factory = new ConnectionFactory(); + factory.HostName = rabbitmq_home ?? ""; + factory.Port = int.Parse(rabbitmq_port ?? "5672"); + factory.UserName = rabbitmq_user ?? ""; + factory.Password = rabbitmq_pwd ?? ""; + using var connection = await factory.CreateConnectionAsync(); + using var channel = await connection.CreateChannelAsync(); + var body = Encoding.UTF8.GetBytes(insertSchedule); + await channel.BasicPublishAsync(exchange: string.Empty, routingKey: "logger_service", body: body); + } + + /// + /// Submit a Schedule Request to the logger Service via RabbitMQ + /// + /// IActionResult + public async void cleanupClient(string cleanupStatement) + { + var factory = new ConnectionFactory(); + factory.HostName = rabbitmq_home ?? ""; + factory.Port = int.Parse(rabbitmq_port ?? "5672"); + factory.UserName = rabbitmq_user ?? ""; + factory.Password = rabbitmq_pwd ?? ""; + using var connection = await factory.CreateConnectionAsync(); + using var channel = await connection.CreateChannelAsync(); + var body = Encoding.UTF8.GetBytes(cleanupStatement); + await channel.BasicPublishAsync(exchange: string.Empty, routingKey: "logger_service", body: body); + } +} diff --git a/Playwright_Demo/UnitTest1.cs b/Playwright_Demo/UnitTest1.cs index 6e555dbd..aa44dee3 100644 --- a/Playwright_Demo/UnitTest1.cs +++ b/Playwright_Demo/UnitTest1.cs @@ -63,7 +63,7 @@ public static async Task ClassInit(TestContext context) { System.IO.File.Delete(resultsDir + resultFile); } - updatedState = CAST_Client_Service.CAST_Client_Service.updateState("READY (" + CAST_Client_Service.CAST_Client_Service.startmyuuidAsString + ")", "green"); + updatedState = CAST_Client_Service.CAST_Client_Service.updateState("READY (" + CAST_Client_Service.CAST_Client_Service.startmyuuidAsString + ")", "#22c55e;"); updatedState.Wait(); CAST_Client_Service.CAST_Client_Service.updateResult("Playwright: Started test suite " + testsuiteName); } @@ -176,7 +176,7 @@ public async Task HasTitle() finally { ///Update the Test Execution Controller UI to indicate that the test has completed - updatedState = CAST_Client_Service.CAST_Client_Service.updateState("COMPLETED TEST " + testName + "()", "green"); + updatedState = CAST_Client_Service.CAST_Client_Service.updateState("COMPLETED TEST " + testName + "()", "#22c55e;"); updatedState.Wait(); } } @@ -230,7 +230,7 @@ public async Task GetStartedLink() } finally { - updatedState = CAST_Client_Service.CAST_Client_Service.updateState("COMPLETED TEST " + testName + "()", "green"); + updatedState = CAST_Client_Service.CAST_Client_Service.updateState("COMPLETED TEST " + testName + "()", "#22c55e;"); updatedState.Wait(); } } @@ -280,7 +280,7 @@ public async Task WrongTitle() } finally { - updatedState = CAST_Client_Service.CAST_Client_Service.updateState("COMPLETED TEST " + testName + "()", "green"); + updatedState = CAST_Client_Service.CAST_Client_Service.updateState("COMPLETED TEST " + testName + "()", "#22c55e;"); updatedState.Wait(); } } @@ -337,7 +337,7 @@ public async Task StopExample() } finally { - updatedState = CAST_Client_Service.CAST_Client_Service.updateState("COMPLETED TEST " + testName + "()", "green"); + updatedState = CAST_Client_Service.CAST_Client_Service.updateState("COMPLETED TEST " + testName + "()", "#22c55e;"); updatedState.Wait(); } } @@ -401,7 +401,7 @@ public async Task AbortExample() } finally { - updatedState = CAST_Client_Service.CAST_Client_Service.updateState("COMPLETED TEST " + testName + "()", "green"); + updatedState = CAST_Client_Service.CAST_Client_Service.updateState("COMPLETED TEST " + testName + "()", "#22c55e;"); updatedState.Wait(); } } @@ -456,7 +456,7 @@ public async Task PauseAndResumeExample() } finally { - updatedState = CAST_Client_Service.CAST_Client_Service.updateState("COMPLETED TEST " + testName + "()", "green"); + updatedState = CAST_Client_Service.CAST_Client_Service.updateState("COMPLETED TEST " + testName + "()", "#22c55e;"); updatedState.Wait(); } } @@ -489,7 +489,7 @@ public async void CheckTestState(string? testMethodName) { Thread.Sleep(5000); } - updatedState = CAST_Client_Service.CAST_Client_Service.updateState("RUNNING TEST " + testMethodName + "()", "green"); + updatedState = CAST_Client_Service.CAST_Client_Service.updateState("RUNNING TEST " + testMethodName + "()", "#22c55e;"); updatedState.Wait(); Thread.Sleep(20000); } @@ -514,7 +514,7 @@ public async void PauseTest(string? testMethodName) //Check every 5 seconds to see if Resume has been clicked Thread.Sleep(5000); } - updatedState = CAST_Client_Service.CAST_Client_Service.updateState("RESUMED", "green"); + updatedState = CAST_Client_Service.CAST_Client_Service.updateState("RESUMED", "#22c55e;"); updatedState.Wait(); //Hardcoded sleep just to provide opportunity to verify that RESUMED is displayed within the Test Execution Controller UI (for demo purposes) //Not recommended for Production