public static async Task BashAsync(this string cmd, ILogHandler handler, bool verboseLogging = false) { var escapedArgs = cmd.Replace("\"", "\\\""); var builder = new StringBuilder(); builder.AppendLine("------------------------------------------------"); builder.AppendLine($"Executing: {cmd} - at: {DateTime.Now.ToString()}"); builder.AppendLine("------------------------------------------------"); await handler.WriteLine(builder.ToString(), verboseLogging); builder.Clear(); var process = new Process() { StartInfo = new ProcessStartInfo { FileName = "/bin/bash", Arguments = $"-c \"{escapedArgs}\"", RedirectStandardOutput = true, UseShellExecute = false, CreateNoWindow = true } }; process.Start(); string result = process.StandardOutput.ReadToEnd(); process.WaitForExit(); builder.AppendLine(result); await handler.WriteLine(builder.ToString(), verboseLogging); }
public async Task DeployModule(IModuleManagerConfig config) { _logHandler.AttachTaskIdAndUpdateHandler(config.TaskId, config.UpdateCallback); await _logHandler.WriteCmd($"{nameof(ModuleManager)}.{nameof(DeployModule)}", verboseLogging); var response = await _kubectlHelper.InstallModule(KubectlHelper.CreateModuleDeployment( config.ImageName, config.ModuleName, config.ModuleReplicas), config.LoadBalancerConfig); if (response.IsSuccessful) { await config.SuccessCallback(config.TaskId, _logHandler); } else { await _logHandler.WriteLine(response.Message); await config.FailureCallback(config.TaskId, _logHandler); } }
private async Task Deploy(IRabbitDeploymentManagerConfiguration config, bool abortOnFailure = false) { // Check if statefulset is already deployed await _logHandler.WriteCmd($"{nameof(RabbitDeploymentManager)}.{nameof(Deploy)}", verboseLogging); await _logHandler.WriteLine("Validating statefulset is running...", verboseLogging); var rabbitStatefulSetIsRunning = _kubectlHelper.ValidateStatefulsetIsRunning(RABBIT_MQ_STATEFULSET); if (rabbitStatefulSetIsRunning) { await _logHandler.WriteLine($"Rabbit Statefulset is running -->", verboseLogging); await ValidateRabbitMQDeployment(config); } else { if (abortOnFailure) { await _logHandler.WriteLine("Failed to install rabbitMQ infrastructure", verboseLogging); await Cleanup(); await _logHandler.WriteLine($"CleanUp Complete --> config.FailureCallback()", verboseLogging); await config.FailureCallback(config.TaskId, _logHandler); return; } await InstallHelmAndRabbitMQ(config); // Once helm has installed and rabbitMQ has been provisioned to the cluster by helm retry the init call // else abort the process... await Deploy(config, true); } }